diff options
author | Brad Ebinger <breadley@google.com> | 2016-04-07 17:19:18 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-04-07 17:19:18 +0000 |
commit | fae70b9521bfc61ef06afc6eb787987d26acbdad (patch) | |
tree | 5c6d02b0287f778586b8eecb35935748ee35cee6 /tests | |
parent | f5cef690b6df32e31fe7b412c7329749a9eb4ad0 (diff) | |
parent | 8607dfb43c2707ca534d68f2dcf728fece01c82b (diff) |
Merge "Add via number to CallLog Account entry" into nyc-dev am: 87b9abf
am: 8607dfb
* commit '8607dfb43c2707ca534d68f2dcf728fece01c82b':
Add via number to CallLog Account entry
Change-Id: I55e9f40fb5497a4edeec31fc0abeb2efd459f1a2
Diffstat (limited to 'tests')
8 files changed, 262 insertions, 15 deletions
diff --git a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java index f6ef7ef22..3b1dd2c7d 100644 --- a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java @@ -21,11 +21,13 @@ import com.google.common.collect.Lists; import android.content.ContentUris; import android.content.Context; import android.content.Intent; +import android.content.res.Resources; import android.database.MatrixCursor; import android.net.Uri; import android.provider.CallLog.Calls; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.VoicemailContract; +import android.telephony.PhoneNumberUtils; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.MediumTest; import android.text.TextUtils; @@ -37,6 +39,7 @@ 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.android.dialer.R; import java.util.Date; import java.util.List; @@ -63,26 +66,30 @@ public class CallLogAdapterTest extends AndroidTestCase { private static final String TEST_COUNTRY_ISO = "US"; private static final String TEST_DEFAULT_CUSTOM_LABEL = "myLabel"; private static final Uri TEST_LOOKUP_URI = Uri.parse("content://contacts/2"); + private static final String TEST_ACCOUNT_ID_LABEL = "label"; private static final String TEST_NUMBER = "12125551000"; private static final String TEST_NUMBER_1 = "12345678"; private static final String TEST_NUMBER_2 = "87654321"; private static final String TEST_NUMBER_3 = "18273645"; private static final String TEST_POST_DIAL_DIGITS = ";12345"; + private static final String TEST_VIA_NUMBER = "+16505551234"; private static final String TEST_FORMATTED_NUMBER = "1 212-555-1000"; // The object under test. private TestCallLogAdapter mAdapter; private MatrixCursor mCursor; + private Resources mResources; - private View mView; private CallLogListItemViewHolder mViewHolder; private final Random mRandom = new Random(); @Override protected void setUp() throws Exception { super.setUp(); + mContext = getContext(); + mResources = mContext.getResources(); // Use a call fetcher that does not do anything. CallLogAdapter.CallFetcher fakeCallFetcher = new CallLogAdapter.CallFetcher() { @@ -281,6 +288,36 @@ public class CallLogAdapterTest extends AndroidTestCase { } @MediumTest + public void testBindView_CallLogWithViaNumber() { + createCallLogEntry(TEST_NUMBER, EMPTY_STRING, TEST_VIA_NUMBER, NO_VALUE_SET, NO_VALUE_SET); + + mAdapter.changeCursor(mCursor); + mAdapter.onBindViewHolder(mViewHolder, 0); + + // Copy format of Resource String + String formattedNumber = mResources.getString(R.string.description_via_number, + TEST_VIA_NUMBER); + + if (CompatUtils.isNCompatible()) { + assertEquals(formattedNumber, + mViewHolder.phoneCallDetailsViews.callAccountLabel.getText()); + } + } + + @MediumTest + public void testBindView_CallLogWithoutViaNumber() { + createCallLogEntry(TEST_NUMBER, EMPTY_STRING, EMPTY_STRING, NO_VALUE_SET, NO_VALUE_SET); + + mAdapter.changeCursor(mCursor); + mAdapter.onBindViewHolder(mViewHolder, 0); + + if (CompatUtils.isNCompatible()) { + assertEquals(View.GONE, + mViewHolder.phoneCallDetailsViews.callAccountLabel.getVisibility()); + } + } + + @MediumTest public void testPresentationAfterRebindingViewHolders() { final int increment = 10; final int size = increment * 4; @@ -589,11 +626,18 @@ public class CallLogAdapterTest extends AndroidTestCase { createCallLogEntry(TEST_NUMBER, EMPTY_STRING, NO_VALUE_SET, ARCHIVE_TYPE); } - private void createCallLogEntry(String number, String postDialDigits, int presentation, int type) { + private void createCallLogEntry(String number, String postDialDigits, int presentation, + int type) { Object[] values = getValues(number, postDialDigits, presentation, type); mCursor.addRow(values); } + private void createCallLogEntry(String number, String postDialDigits, String viaNumber, + int presentation, int type) { + Object[] values = getValues(number, postDialDigits, viaNumber, presentation, type); + mCursor.addRow(values); + } + private void createCallLogEntryWithCachedValues(boolean inject) { createCallLogEntryWithCachedValues( TEST_NUMBER, @@ -665,6 +709,23 @@ public class CallLogAdapterTest extends AndroidTestCase { String postDialDigits, int presentation, int type) { + return getValues(number, postDialDigits, "", presentation, type); + } + + /** + * @param number The phone number. + * @param postDialDigits The post dial digits dialed (if any) + * @param viaNumber The secondary number that the call was placed via + * @param presentation Number representing display rules for "allowed", + * "payphone", "restricted", or "unknown". + * @param type The type of the call (outgoing/ingoing) + */ + private Object[] getValues( + String number, + String postDialDigits, + String viaNumber, + int presentation, + int type) { Object[] values = CallLogQueryTestUtils.createTestValues(); values[CallLogQuery.ID] = mCursor.getCount(); @@ -678,6 +739,9 @@ public class CallLogAdapterTest extends AndroidTestCase { if (!TextUtils.isEmpty(postDialDigits) && CompatUtils.isNCompatible()) { values[CallLogQuery.POST_DIAL_DIGITS] = postDialDigits; } + if (!TextUtils.isEmpty(viaNumber) && CompatUtils.isNCompatible()) { + values[CallLogQuery.VIA_NUMBER] = viaNumber; + } if (presentation != NO_VALUE_SET) { values[CallLogQuery.NUMBER_PRESENTATION] = presentation; } diff --git a/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java b/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java index 107cf7562..beb83b1ad 100644 --- a/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java @@ -109,6 +109,26 @@ public class CallLogGroupBuilderTest extends AndroidTestCase { } } + public void testAddGroups_WithViaNumberMatching() { + addCallLogEntryWithViaNumber(TEST_NUMBER1, TEST_NUMBER2, + AppCompatConstants.CALLS_OUTGOING_TYPE); + addCallLogEntryWithViaNumber(TEST_NUMBER1, TEST_NUMBER2, + AppCompatConstants.CALLS_OUTGOING_TYPE); + addCallLogEntryWithViaNumber(TEST_NUMBER1, "", + AppCompatConstants.CALLS_OUTGOING_TYPE); + + mBuilder.addGroups(mCursor); + + if (CompatUtils.isNCompatible()) { + assertEquals(2, mFakeGroupCreator.groups.size()); + assertGroupIs(0, 2, mFakeGroupCreator.groups.get(0)); + assertGroupIs(2, 1, mFakeGroupCreator.groups.get(1)); + } else { + assertEquals(1, mFakeGroupCreator.groups.size()); + assertGroupIs(0, 3, mFakeGroupCreator.groups.get(0)); + } + } + public void testAddGroups_MatchingIncomingAndOutgoing() { addCallLogEntry(TEST_NUMBER1, AppCompatConstants.CALLS_INCOMING_TYPE); addCallLogEntry(TEST_NUMBER1, AppCompatConstants.CALLS_OUTGOING_TYPE); @@ -387,6 +407,19 @@ public class CallLogGroupBuilderTest extends AndroidTestCase { mCursor.addRow(values); } + /** Adds a call log entry with the given number, post-dial digits, and type to the cursor. */ + private void addCallLogEntryWithViaNumber(String number, String viaNumber, int type) { + mCursor.moveToNext(); + Object[] values = CallLogQueryTestUtils.createTestValues(); + values[CallLogQuery.ID] = mCursor.getPosition(); + values[CallLogQuery.NUMBER] = number; + values[CallLogQuery.CALL_TYPE] = type; + if (CompatUtils.isNCompatible()) { + values[CallLogQuery.VIA_NUMBER] = viaNumber; + } + mCursor.addRow(values); + } + /** Adds a call log entry with a header to the cursor. */ private void addCallLogHeader(int section) { mCursor.moveToNext(); diff --git a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java index 28caed469..daba42857 100644 --- a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java @@ -64,7 +64,7 @@ public class CallLogListItemHelperTest extends AndroidTestCase { mContext = getContext(); mResources = mContext.getResources(); final TestTelecomCallLogCache phoneUtils = - new TestTelecomCallLogCache(mContext, TEST_VOICEMAIL_NUMBER); + new TestTelecomCallLogCache(mContext, TEST_VOICEMAIL_NUMBER, ""); PhoneCallDetailsHelper phoneCallDetailsHelper = new PhoneCallDetailsHelper(mContext, mResources, phoneUtils); mHelper = new CallLogListItemHelper(phoneCallDetailsHelper, mResources, phoneUtils); diff --git a/tests/src/com/android/dialer/calllog/CallLogQueryTestUtils.java b/tests/src/com/android/dialer/calllog/CallLogQueryTestUtils.java index f1b1a9ab9..c2cfedbac 100644 --- a/tests/src/com/android/dialer/calllog/CallLogQueryTestUtils.java +++ b/tests/src/com/android/dialer/calllog/CallLogQueryTestUtils.java @@ -32,7 +32,7 @@ public class CallLogQueryTestUtils { values = new Object[]{ 0L, "", 0L, 0L, Calls.INCOMING_TYPE, "", "", "", null, 0, null, null, null, null, 0L, null, 0, Calls.PRESENTATION_ALLOWED, null, null, 0, null, null, - null, "" + null, "", "" }; } else { values = new Object[]{ diff --git a/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java b/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java index c0d1203d9..0c57fde3c 100644 --- a/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java +++ b/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java @@ -16,9 +16,11 @@ package com.android.dialer.calllog; +import android.content.ComponentName; import android.content.Context; import android.content.res.Resources; import android.provider.CallLog.Calls; +import android.telecom.PhoneAccountHandle; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.MediumTest; import android.text.Html; @@ -63,6 +65,10 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase { private static final String EMPTY_GEOCODE = ""; /** Empty post-dial digits label */ private static final String EMPTY_POSTDIAL = ""; + /** The number that the call was received via */ + private static final String TEST_VIA_NUMBER = "+16505551234"; + /** The Phone Account name that the Call was received on */ + private static final String TEST_ACCOUNT_LABEL = "T-Stationary"; /** The object under test. */ private PhoneCallDetailsHelper mHelper; @@ -79,10 +85,9 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase { super.setUp(); mContext = getContext(); Resources resources = mContext.getResources(); - mPhoneUtils = new TestTelecomCallLogCache(mContext, TEST_VOICEMAIL_NUMBER); - final TestTelecomCallLogCache phoneUtils = new TestTelecomCallLogCache( - mContext, TEST_VOICEMAIL_NUMBER); - mHelper = new PhoneCallDetailsHelper(mContext, resources, phoneUtils); + mPhoneUtils = new TestTelecomCallLogCache(mContext, TEST_VOICEMAIL_NUMBER, + TEST_ACCOUNT_LABEL); + mHelper = new PhoneCallDetailsHelper(mContext, resources, mPhoneUtils); mHelper.setCurrentTimeForTest(INJECTED_CURRENT_DATE); mViews = PhoneCallDetailsViews.createForTest(mContext); mNameView = new TextView(mContext); @@ -120,6 +125,26 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase { assertNameEqualsResource(R.string.voicemail); } + public void testSetPhoneCallDetails_ViaNumber() { + setPhoneCallDetailsWithViaNumber(TEST_VIA_NUMBER); + assertViaNumberEquals(TEST_VIA_NUMBER); + } + + public void testSetPhoneCallDetails_NoViaNumber() { + setDefaultPhoneCallDetailsNoViaNumber(); + assertCallAccountInvisible(); + } + + public void testSetPhoneCallDetails_AccountLabel() { + setPhoneCallDetailsWithAccountHandle(); + assertAccountLabelEquals(TEST_ACCOUNT_LABEL); + } + + public void testSetPhoneCallDetails_AccountHandleViaNumber() { + setPhoneCallDetailsWithAccountLabelViaNumber(TEST_VIA_NUMBER); + assertAccountLabelEquals(TEST_VIA_NUMBER, TEST_ACCOUNT_LABEL); + } + // Voicemail date string has 3 different formats depending on how long ago the call was placed public void testSetVoicemailPhoneCallDetails_Today() { setVoicemailPhoneCallDetailsWithDate(System.currentTimeMillis()); @@ -368,6 +393,30 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase { assertEquals(text, mViews.callLocationAndDate.getText()); } + /** Asserts that the via number is correct. */ + private void assertViaNumberEquals(String text) { + final String callAccountText = + mContext.getResources().getString(R.string.description_via_number, text); + assertEquals(callAccountText, mViews.callAccountLabel.getText()); + } + + /** Asserts that the account label is correct. */ + private void assertAccountLabelEquals(String text) { + assertEquals(text, mViews.callAccountLabel.getText()); + } + + /** Asserts that the account label is correct when also showing the via number. */ + private void assertAccountLabelEquals(String viaNumber, String accountLabel) { + final String viaNumberText = + mContext.getResources().getString(R.string.description_via_number, viaNumber); + assertEquals(accountLabel + " " + viaNumberText, mViews.callAccountLabel.getText()); + } + + /** Asserts that the call account label is invisible. */ + private void assertCallAccountInvisible() { + assertEquals(mViews.callAccountLabel.getVisibility(), View.GONE); + } + /** Asserts that the duration is exactly as included in the location and date text field. */ private void assertDurationExactEquals(String text) { Matcher matcher = Pattern.compile("(.*) (\\u2022) (\\d{2}:\\d{2})").matcher( @@ -414,6 +463,36 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase { mHelper.setPhoneCallDetails(mViews, details); } + /** Sets the phone call details with default values and the given via number. */ + private void setPhoneCallDetailsWithViaNumber(String viaNumber) { + PhoneCallDetails details = getPhoneCallDetails(); + mPhoneUtils.setAccountLabel(""); + details.viaNumber = viaNumber; + mHelper.setPhoneCallDetails(mViews, details); + } + + /** Sets the phone call details with an account handle. */ + private void setPhoneCallDetailsWithAccountHandle() { + PhoneCallDetails details = getPhoneCallDetails(); + details.accountHandle = new PhoneAccountHandle(new ComponentName("",""), ""); + mHelper.setPhoneCallDetails(mViews, details); + } + + /** Sets the phone call details with an account handle and via number */ + private void setPhoneCallDetailsWithAccountLabelViaNumber(String viaNumber) { + PhoneCallDetails details = getPhoneCallDetails(); + details.viaNumber = viaNumber; + details.accountHandle = new PhoneAccountHandle(new ComponentName("",""), ""); + mHelper.setPhoneCallDetails(mViews, details); + } + + /** Populates the phone call details with the Defaults. */ + private void setDefaultPhoneCallDetailsNoViaNumber() { + PhoneCallDetails details = getPhoneCallDetails(); + mPhoneUtils.setAccountLabel(""); + mHelper.setPhoneCallDetails(mViews, details); + } + /** Sets the phone call details with default values and the given number. */ private void setPhoneCallDetailsWithNumberAndGeocode( String number, String formattedNumber, String geocodedLocation) { diff --git a/tests/src/com/android/dialer/calllog/PhoneCallDetailsTest.java b/tests/src/com/android/dialer/calllog/PhoneCallDetailsTest.java new file mode 100644 index 000000000..5c500d8bb --- /dev/null +++ b/tests/src/com/android/dialer/calllog/PhoneCallDetailsTest.java @@ -0,0 +1,63 @@ +package com.android.dialer.calllog; + +import android.content.res.Resources; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; +import android.text.SpannableString; +import android.text.TextUtils; +import android.text.style.TtsSpan; + +import com.android.dialer.PhoneCallDetails; +import com.android.dialer.R; +import com.android.contacts.common.util.ContactDisplayUtils; + +/** + * Unit tests for {@link PhoneCallDetails}. + */ +public class PhoneCallDetailsTest extends AndroidTestCase { + private static final String VIA_NUMBER = "+16505551212"; + private static final String PHONE_ACCOUNT_LABEL = "TEST"; + + private Resources mResources; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mResources = mContext.getResources(); + } + + @SmallTest + public void testCreateAccountLabelDescription_NoViaNumberNoAccountLabel() { + CharSequence result = PhoneCallDetails.createAccountLabelDescription(mResources, "",""); + assertEquals("", result); + } + + @SmallTest + public void testCreateAccountLabelDescription_ViaNumberAccountLabel() { + String msg = mResources.getString(R.string.description_via_number_phone_account, + PHONE_ACCOUNT_LABEL, VIA_NUMBER); + CharSequence accountNumberLabel = ContactDisplayUtils.getTelephoneTtsSpannable(msg, + VIA_NUMBER); + CharSequence result = PhoneCallDetails.createAccountLabelDescription(mResources, VIA_NUMBER, + PHONE_ACCOUNT_LABEL); + assertEquals(accountNumberLabel.toString(), result.toString()); + } + + @SmallTest + public void testCreateAccountLabelDescription_ViaNumber() { + CharSequence viaNumberLabel = ContactDisplayUtils.getTtsSpannedPhoneNumber(mResources, + R.string.description_via_number, VIA_NUMBER); + CharSequence result = PhoneCallDetails.createAccountLabelDescription(mResources, VIA_NUMBER, + ""); + assertEquals(viaNumberLabel.toString(), result.toString()); + } + + @SmallTest + public void testCreateAccountLabelDescription_AccountLabel() { + CharSequence accountLabel = TextUtils.expandTemplate( + mResources.getString(R.string.description_phone_account), PHONE_ACCOUNT_LABEL); + CharSequence result = PhoneCallDetails.createAccountLabelDescription(mResources, "", + PHONE_ACCOUNT_LABEL); + assertEquals(accountLabel, result); + } +} diff --git a/tests/src/com/android/dialer/calllog/calllogcache/TestTelecomCallLogCache.java b/tests/src/com/android/dialer/calllog/calllogcache/TestTelecomCallLogCache.java index 077a498c9..270019afd 100644 --- a/tests/src/com/android/dialer/calllog/calllogcache/TestTelecomCallLogCache.java +++ b/tests/src/com/android/dialer/calllog/calllogcache/TestTelecomCallLogCache.java @@ -28,12 +28,15 @@ import android.telecom.PhoneAccountHandle; * but... * TODO: write tests to test multi-SIM functionality in TelecomCallLogCache. */ -public final class TestTelecomCallLogCache extends CallLogCache { +public class TestTelecomCallLogCache extends CallLogCache { private CharSequence mVoicemailNumber; + private String mAccountLabel; - public TestTelecomCallLogCache(Context context, CharSequence voicemailNumber) { + public TestTelecomCallLogCache(Context context, CharSequence voicemailNumber, + String accountLabel) { super(context); mVoicemailNumber = voicemailNumber; + mAccountLabel = accountLabel; } @Override @@ -43,7 +46,11 @@ public final class TestTelecomCallLogCache extends CallLogCache { @Override public String getAccountLabel(PhoneAccountHandle accountHandle) { - return null; + return mAccountLabel; + } + + public void setAccountLabel(String accountLabel) { + mAccountLabel = accountLabel; } @Override diff --git a/tests/src/com/android/dialer/database/DatabaseTestUtils.java b/tests/src/com/android/dialer/database/DatabaseTestUtils.java index 03b493895..19fff7f89 100644 --- a/tests/src/com/android/dialer/database/DatabaseTestUtils.java +++ b/tests/src/com/android/dialer/database/DatabaseTestUtils.java @@ -47,20 +47,21 @@ public class DatabaseTestUtils { Contacts.STARRED, // 10 Data.IS_SUPER_PRIMARY, // 11 Contacts.IN_VISIBLE_GROUP, // 12 - Data.IS_PRIMARY}); // 13 + Data.IS_PRIMARY, // 13 + Data.CARRIER_PRESENCE}); // 14 return cursor; } public static ContactNumber constructNewContactWithDummyIds(MatrixCursor contactCursor, MatrixCursor nameCursor, String number, int id, String displayName) { return constructNewContact(contactCursor, nameCursor, id, number, id, String.valueOf(id), - displayName, 0, 0, 0, 0, 0, 0, 0); + displayName, 0, 0, 0, 0, 0, 0, 0, 0); } public static ContactNumber constructNewContact(MatrixCursor contactCursor, MatrixCursor nameCursor, int id, String number, int contactId, String lookupKey, String displayName, int photoId, int lastTimeUsed, int timesUsed, int starred, - int isSuperPrimary, int inVisibleGroup, int isPrimary) { + int isSuperPrimary, int inVisibleGroup, int isPrimary, int carrierPresence) { if (contactCursor == null || nameCursor == null) { throw new IllegalArgumentException("Provided MatrixCursors cannot be null"); } @@ -73,7 +74,7 @@ public class DatabaseTestUtils { contactCursor.addRow(new Object[]{id, "", "", number, contactId, lookupKey, displayName, photoId, lastTimeUsed, timesUsed, starred, isSuperPrimary, inVisibleGroup, - isPrimary}); + isPrimary, carrierPresence}); nameCursor.addRow(new Object[]{displayName, contactId}); return new ContactNumber(contactId, id, displayName, number, lookupKey, 0, 0); |