diff options
Diffstat (limited to 'tests/src/com')
3 files changed, 92 insertions, 12 deletions
diff --git a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java index 80dfe3578..e80131140 100644 --- a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java @@ -31,6 +31,7 @@ import android.view.View; import com.android.contacts.common.preference.ContactsPreferences; import com.android.dialer.contactinfo.ContactInfoCache; +import com.android.dialer.database.VoicemailArchiveContract; import com.android.dialer.util.AppCompatConstants; import com.android.dialer.util.TestConstants; import com.google.common.collect.Lists; @@ -49,6 +50,7 @@ import java.util.Random; public class CallLogAdapterTest extends AndroidTestCase { private static final String EMPTY_STRING = ""; private static final int NO_VALUE_SET = -1; + private static final int ARCHIVE_TYPE = -2; private static final String TEST_CACHED_NAME_PRIMARY = "Cached Name"; private static final String TEST_CACHED_NAME_ALTERNATIVE = "Name Cached"; @@ -74,12 +76,11 @@ public class CallLogAdapterTest extends AndroidTestCase { private View mView; private CallLogListItemViewHolder mViewHolder; - private Random mRandom; + private final Random mRandom = new Random(); @Override protected void setUp() throws Exception { super.setUp(); - mRandom = new Random(); // Use a call fetcher that does not do anything. CallLogAdapter.CallFetcher fakeCallFetcher = new CallLogAdapter.CallFetcher() { @@ -98,7 +99,8 @@ public class CallLogAdapterTest extends AndroidTestCase { } }; - mAdapter = new TestCallLogAdapter(getContext(), fakeCallFetcher, fakeContactInfoHelper); + mAdapter = new TestCallLogAdapter(getContext(), fakeCallFetcher, fakeContactInfoHelper, + CallLogAdapter.ACTIVITY_TYPE_DIALTACTS); // The cursor used in the tests to store the entries to display. mCursor = new MatrixCursor(CallLogQuery._PROJECTION); @@ -108,13 +110,6 @@ public class CallLogAdapterTest extends AndroidTestCase { mViewHolder = CallLogListItemViewHolder.createForTest(getContext()); } - @Override - protected void tearDown() throws Exception { - mAdapter = null; - mCursor = null; - super.tearDown(); - } - @MediumTest public void testBindView_NumberOnlyNoCache() { createCallLogEntry(); @@ -547,6 +542,19 @@ public class CallLogAdapterTest extends AndroidTestCase { assertEquals(TEST_NUMBER_3, mViewHolder.number); } + public void testVoicemailArchive() { + setUpArchiveAdapter(); + createVoicemailArchiveCallLogEntry(); + + mAdapter.changeCursorVoicemail(mCursor); + mAdapter.onBindViewHolder(mViewHolder, 0); + + assertEquals(Uri.parse(mViewHolder.voicemailUri), + ContentUris.withAppendedId( + VoicemailArchiveContract.VoicemailArchive.CONTENT_URI, 0)); + assertNull(mViewHolder.primaryActionButtonView.getTag()); + } + private void createCallLogEntry() { createCallLogEntry(TEST_NUMBER); } @@ -575,6 +583,10 @@ public class CallLogAdapterTest extends AndroidTestCase { createCallLogEntry(TEST_NUMBER, EMPTY_STRING, NO_VALUE_SET, Calls.VOICEMAIL_TYPE); } + private void createVoicemailArchiveCallLogEntry() { + createCallLogEntry(TEST_NUMBER, EMPTY_STRING, NO_VALUE_SET, ARCHIVE_TYPE); + } + private void createCallLogEntry(String number, String postDialDigits, int presentation, int type) { Object[] values = getValues(number, postDialDigits, presentation, type); mCursor.addRow(values); @@ -674,6 +686,10 @@ public class CallLogAdapterTest extends AndroidTestCase { values[CallLogQuery.VOICEMAIL_URI] = ContentUris.withAppendedId( VoicemailContract.Voicemails.CONTENT_URI, mCursor.getCount()); } + if (type == ARCHIVE_TYPE) { + values[CallLogQuery.VOICEMAIL_URI] = ContentUris.withAppendedId( + VoicemailArchiveContract.VoicemailArchive.CONTENT_URI, mCursor.getCount()); + } return values; } @@ -739,11 +755,34 @@ public class CallLogAdapterTest extends AndroidTestCase { return Phone.getTypeLabel(getContext().getResources(), phoneType, ""); } + private void setUpArchiveAdapter() { + // Use a call fetcher that does not do anything. + CallLogAdapter.CallFetcher fakeCallFetcher = new CallLogAdapter.CallFetcher() { + @Override + public void fetchCalls() {} + }; + + ContactInfoHelper fakeContactInfoHelper = + new ContactInfoHelper(getContext(), TEST_COUNTRY_ISO) { + @Override + public ContactInfo lookupNumber(String number, String countryIso) { + ContactInfo info = new ContactInfo(); + info.number = number; + info.formattedNumber = number; + return info; + } + }; + + mAdapter = new TestCallLogAdapter(getContext(), fakeCallFetcher, fakeContactInfoHelper, + CallLogAdapter.ACTIVITY_TYPE_ARCHIVE); + } + /// Subclass of {@link CallLogAdapter} used in tests to intercept certain calls. private static final class TestCallLogAdapter extends CallLogAdapter { public TestCallLogAdapter(Context context, CallFetcher callFetcher, - ContactInfoHelper contactInfoHelper) { - super(context, callFetcher, contactInfoHelper, null, false); + ContactInfoHelper contactInfoHelper, int mActivity) { + super(context, callFetcher, contactInfoHelper, null, + mActivity); mContactInfoCache = new TestContactInfoCache( contactInfoHelper, mOnContactInfoChangedListener); } diff --git a/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java b/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java index 04463c230..c31c38e1d 100644 --- a/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java @@ -129,6 +129,18 @@ public class CallLogGroupBuilderTest extends AndroidTestCase { AppCompatConstants.CALLS_VOICEMAIL_TYPE, AppCompatConstants.CALLS_OUTGOING_TYPE); } + public void testGrouping_VoicemailArchive() { + // Does not group with other types of calls, include voicemail themselves. + assertVoicemailsAreNotGrouped( + AppCompatConstants.CALLS_VOICEMAIL_TYPE, AppCompatConstants.CALLS_MISSED_TYPE); + assertVoicemailsAreNotGrouped( + AppCompatConstants.CALLS_VOICEMAIL_TYPE, AppCompatConstants.CALLS_VOICEMAIL_TYPE); + assertVoicemailsAreNotGrouped( + AppCompatConstants.CALLS_VOICEMAIL_TYPE, AppCompatConstants.CALLS_INCOMING_TYPE); + assertVoicemailsAreNotGrouped( + AppCompatConstants.CALLS_VOICEMAIL_TYPE, AppCompatConstants.CALLS_OUTGOING_TYPE); + } + public void testGrouping_Missed() { // Groups with one or more missed calls. assertCallsAreGrouped( @@ -198,6 +210,21 @@ public class CallLogGroupBuilderTest extends AndroidTestCase { } + public void testAddGroups_Separate() { + addMultipleCallLogEntries(TEST_NUMBER1, + AppCompatConstants.CALLS_VOICEMAIL_TYPE, // Group 1: 0 + AppCompatConstants.CALLS_INCOMING_TYPE, // Group 2: 1 + AppCompatConstants.CALLS_OUTGOING_TYPE, // Group 3: 2 + AppCompatConstants.CALLS_MISSED_TYPE); // Group 4: 3 + mBuilder.addVoicemailGroups(mCursor); + + assertEquals(4, mFakeGroupCreator.groups.size()); + assertGroupIs(0, 1, mFakeGroupCreator.groups.get(0)); + assertGroupIs(1, 1, mFakeGroupCreator.groups.get(1)); + assertGroupIs(2, 1, mFakeGroupCreator.groups.get(2)); + assertGroupIs(3, 1, mFakeGroupCreator.groups.get(3)); + } + public void testAddGroups_Mixed() { addMultipleCallLogEntries(TEST_NUMBER1, AppCompatConstants.CALLS_VOICEMAIL_TYPE, // Group 1: 0 @@ -326,6 +353,15 @@ public class CallLogGroupBuilderTest extends AndroidTestCase { assertEquals(types.length, mFakeGroupCreator.groups.size()); } + /** Asserts that voicemails are not grouped together with other types at all. */ + private void assertVoicemailsAreNotGrouped(int... types) { + createCursor(); + clearFakeGroupCreator(); + addMultipleCallLogEntries(TEST_NUMBER1, types); + mBuilder.addVoicemailGroups(mCursor); + assertEquals(types.length, mFakeGroupCreator.groups.size()); + } + /** Adds a set of calls with the given types, all from the same number, in the old section. */ private void addMultipleCallLogEntries(String number, int... types) { for (int type : types) { diff --git a/tests/src/com/android/dialer/calllog/GroupingListAdapterTests.java b/tests/src/com/android/dialer/calllog/GroupingListAdapterTests.java index 4d51f72ae..4d8cb9cc0 100644 --- a/tests/src/com/android/dialer/calllog/GroupingListAdapterTests.java +++ b/tests/src/com/android/dialer/calllog/GroupingListAdapterTests.java @@ -70,6 +70,11 @@ public class GroupingListAdapterTests extends AndroidTestCase { } @Override + protected void addVoicemailGroups(Cursor c) { + // Do nothing. + } + + @Override public void onContentChanged() { // Do nothing. } |