From 6b0056f348e1f9ecf0f91b53b51d240961bc8313 Mon Sep 17 00:00:00 2001 From: Sarmad Hashmi Date: Wed, 17 Feb 2016 17:20:36 -0800 Subject: Update call log adapter and related files for archived voicemails. + Populate CallLogAdapter items with different data depending on whether it is in the voicemail archive activity or not + Added addVoicemailGroups method to CallLogGroupBuilder so that every voicemail is put into an individual group + Voicemails grouped differently than regular calls, so added changeCursorVoicemail in GroupingListAdapter +Fix CallLogAdapter tests and add test for archive adapter BUG=22797391 Change-Id: Ib8387c5b3ab8c5e39876cfaf20fde5a44295f152 --- .../android/dialer/calllog/CallLogAdapterTest.java | 63 +++++++++++++++++----- .../dialer/calllog/CallLogGroupBuilderTest.java | 36 +++++++++++++ .../dialer/calllog/GroupingListAdapterTests.java | 5 ++ 3 files changed, 92 insertions(+), 12 deletions(-) (limited to 'tests') 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 @@ -69,6 +69,11 @@ public class GroupingListAdapterTests extends AndroidTestCase { addGroup(count - groupItemCount, groupItemCount); } + @Override + protected void addVoicemailGroups(Cursor c) { + // Do nothing. + } + @Override public void onContentChanged() { // Do nothing. -- cgit v1.2.3