diff options
Diffstat (limited to 'tests/src')
5 files changed, 104 insertions, 19 deletions
diff --git a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java index a5a61ad46..13ca0fd76 100644 --- a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java @@ -64,6 +64,7 @@ public class CallLogAdapterTest extends AndroidTestCase { 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_FORMATTED_NUMBER = "1 212-555-1000"; // The object under test. @@ -233,6 +234,16 @@ public class CallLogAdapterTest extends AndroidTestCase { } @MediumTest + public void testBindView_CallButtonWithPostDialDigits() { + createCallLogEntry(TEST_NUMBER, TEST_POST_DIAL_DIGITS, NO_VALUE_SET, NO_VALUE_SET); + + mAdapter.changeCursor(mCursor); + mAdapter.onBindViewHolder(mViewHolder, 0); + + assertHasCallActionToGivenNumber(mViewHolder, TEST_NUMBER + TEST_POST_DIAL_DIGITS); + } + + @MediumTest public void testBindView_VoicemailUri() { createVoicemailCallLogEntry(); @@ -245,6 +256,28 @@ public class CallLogAdapterTest extends AndroidTestCase { } @MediumTest + public void testBindView_NumberWithPostDialDigits() { + createCallLogEntry(TEST_NUMBER, TEST_POST_DIAL_DIGITS, NO_VALUE_SET, NO_VALUE_SET); + + mAdapter.changeCursor(mCursor); + mAdapter.onBindViewHolder(mViewHolder, 0); + + assertNameIs(mViewHolder, TEST_NUMBER + TEST_POST_DIAL_DIGITS); + } + + @MediumTest + public void testBindView_ContactWithPrefix() { + createCallLogEntry(TEST_NUMBER, TEST_POST_DIAL_DIGITS, NO_VALUE_SET, NO_VALUE_SET); + mAdapter.injectContactInfoForTest(TEST_NUMBER + TEST_POST_DIAL_DIGITS, TEST_COUNTRY_ISO, + createContactInfo()); + + mAdapter.changeCursor(mCursor); + mAdapter.onBindViewHolder(mViewHolder, 0); + + assertNameIs(mViewHolder, TEST_CACHED_NAME); + } + + @MediumTest public void testPresentationAfterRebindingViewHolders() { final int increment = 10; final int size = increment * 4; @@ -513,12 +546,13 @@ public class CallLogAdapterTest extends AndroidTestCase { } private void createCallLogEntry(String testNumber) { - createCallLogEntry(testNumber, NO_VALUE_SET, NO_VALUE_SET); + createCallLogEntry(testNumber, EMPTY_STRING, NO_VALUE_SET, NO_VALUE_SET); } private void createPrivateCallLogEntry() { createCallLogEntry( EMPTY_STRING, + EMPTY_STRING, Calls.PRESENTATION_RESTRICTED, AppCompatConstants.CALLS_INCOMING_TYPE); } @@ -526,16 +560,17 @@ public class CallLogAdapterTest extends AndroidTestCase { private void createUnknownCallLogEntry() { createCallLogEntry( EMPTY_STRING, + EMPTY_STRING, Calls.PRESENTATION_UNKNOWN, AppCompatConstants.CALLS_INCOMING_TYPE); } private void createVoicemailCallLogEntry() { - createCallLogEntry(TEST_NUMBER, NO_VALUE_SET, Calls.VOICEMAIL_TYPE); + createCallLogEntry(TEST_NUMBER, EMPTY_STRING, NO_VALUE_SET, Calls.VOICEMAIL_TYPE); } - private void createCallLogEntry(String number, int presentation, int type) { - Object[] values = getValues(number, presentation, type); + private void createCallLogEntry(String number, String postDialDigits, int presentation, int type) { + Object[] values = getValues(number, postDialDigits, presentation, type); mCursor.addRow(values); } @@ -583,7 +618,7 @@ public class CallLogAdapterTest extends AndroidTestCase { String cachedNumberLabel, String cachedFormattedNumber, boolean inject) { - Object[] values = getValues(number, NO_VALUE_SET, type); + Object[] values = getValues(number, EMPTY_STRING, NO_VALUE_SET, type); values[CallLogQuery.CACHED_NAME] = cachedName; values[CallLogQuery.CACHED_NUMBER_TYPE] = cachedNumberType; values[CallLogQuery.CACHED_NUMBER_LABEL] = cachedNumberLabel; @@ -600,12 +635,14 @@ public class CallLogAdapterTest extends AndroidTestCase { /** * @param number The phone number. + * @param postDialDigits The post dial digits dialed (if any) * @param presentation Number representing display rules for "allowed", * "payphone", "restricted", or "unknown". - * @param date In millisec since epoch. Use NOW to use the current time. + * @param type The type of the call (outgoing/ingoing) */ private Object[] getValues( String number, + String postDialDigits, int presentation, int type) { Object[] values = CallLogQueryTestUtils.createTestValues(); @@ -618,6 +655,9 @@ public class CallLogAdapterTest extends AndroidTestCase { if (!TextUtils.isEmpty(number)) { values[CallLogQuery.NUMBER] = number; } + if (!TextUtils.isEmpty(postDialDigits)) { + values[CallLogQuery.POST_DIAL_DIGITS] = postDialDigits; + } if (presentation != NO_VALUE_SET) { values[CallLogQuery.NUMBER_PRESENTATION] = presentation; } @@ -676,14 +716,16 @@ public class CallLogAdapterTest extends AndroidTestCase { } private void assertHasCallAction(CallLogListItemViewHolder viewHolder) { - // The primaryActionView tag is set when the ViewHolder is binded. If it is possible - // to place a call to the phone number, a call intent will have been created which - // starts a phone call to the entry's number. + assertHasCallActionToGivenNumber(viewHolder, TEST_NUMBER); + } + + private void assertHasCallActionToGivenNumber(CallLogListItemViewHolder viewHolder, + String number) { IntentProvider intentProvider = (IntentProvider) viewHolder.primaryActionButtonView.getTag(); Intent intent = intentProvider.getIntent(getContext()); assertEquals(TestConstants.CALL_INTENT_ACTION, intent.getAction()); - assertEquals(Uri.parse("tel:" + TEST_NUMBER), intent.getData()); + assertEquals(Uri.parse("tel:" + Uri.encode(number)), intent.getData()); } /** Returns the label associated with a given phone type. */ diff --git a/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java b/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java index 5d0b6bebb..fa18afff5 100644 --- a/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java @@ -35,6 +35,8 @@ public class CallLogGroupBuilderTest extends AndroidTestCase { private static final String TEST_NUMBER1 = "14125551234"; /** A phone number for testing. */ private static final String TEST_NUMBER2 = "14125555555"; + /** A post-dial string for testing */ + private static final String TEST_POST_DIAL_DIGITS = ";12435;0987"; /** The object under test. */ private CallLogGroupBuilder mBuilder; @@ -86,6 +88,21 @@ public class CallLogGroupBuilderTest extends AndroidTestCase { assertGroupIs(0, 3, mFakeGroupCreator.groups.get(0)); } + public void testAddGroups_WithPostDialMatching() { + addCallLogEntryWithPostDialDigits(TEST_NUMBER1, TEST_POST_DIAL_DIGITS, + AppCompatConstants.CALLS_OUTGOING_TYPE); + addCallLogEntryWithPostDialDigits(TEST_NUMBER1, TEST_POST_DIAL_DIGITS, + AppCompatConstants.CALLS_OUTGOING_TYPE); + addCallLogEntryWithPostDialDigits(TEST_NUMBER1, "", + AppCompatConstants.CALLS_OUTGOING_TYPE); + + mBuilder.addGroups(mCursor); + + assertEquals(2, mFakeGroupCreator.groups.size()); + assertGroupIs(0, 2, mFakeGroupCreator.groups.get(0)); + assertGroupIs(2, 1, mFakeGroupCreator.groups.get(1)); + } + public void testAddGroups_MatchingIncomingAndOutgoing() { addCallLogEntry(TEST_NUMBER1, AppCompatConstants.CALLS_INCOMING_TYPE); addCallLogEntry(TEST_NUMBER1, AppCompatConstants.CALLS_OUTGOING_TYPE); @@ -312,11 +329,17 @@ public class CallLogGroupBuilderTest extends AndroidTestCase { } /** Adds a call log entry with the given number and type to the cursor. */ private void addCallLogEntry(String number, int type) { + addCallLogEntryWithPostDialDigits(number, "", type); + } + + /** Adds a call log entry with the given number, post-dial digits, and type to the cursor. */ + private void addCallLogEntryWithPostDialDigits(String number, String postDialDigits, int type) { mCursor.moveToNext(); Object[] values = CallLogQueryTestUtils.createTestValues(); values[CallLogQuery.ID] = mCursor.getPosition(); values[CallLogQuery.NUMBER] = number; values[CallLogQuery.CALL_TYPE] = type; + values[CallLogQuery.POST_DIAL_DIGITS] = postDialDigits; mCursor.addRow(values); } diff --git a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java index c9d826473..a97fce3f7 100644 --- a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java @@ -246,26 +246,34 @@ public class CallLogListItemHelperTest extends AndroidTestCase { /** Sets the details of a phone call using the specified phone number. */ private void setPhoneCallDetailsWithNumber(String number, int presentation, String formattedNumber) { - setPhoneCallDetailsWithNumberAndType(number, presentation, + setPhoneCallDetailsWithNumberTypeAndPostDialDigits(number, "", presentation, formattedNumber, Calls.INCOMING_TYPE); } /** Sets the details of a phone call using the specified phone number. */ private void setPhoneCallDetailsWithNumberAndType(String number, int presentation, String formattedNumber, int callType) { + setPhoneCallDetailsWithNumberTypeAndPostDialDigits(number, "", presentation, + formattedNumber, callType); + } + + /** Sets the details of a phone call using the specified phone number and post-dial digits. */ + private void setPhoneCallDetailsWithNumberTypeAndPostDialDigits(String number, + String postDialDigits, int presentation, String formattedNumber, int callType) { PhoneCallDetails details = getPhoneCallDetails( - number, presentation, formattedNumber); + number, postDialDigits, presentation, formattedNumber); details.callTypes = new int[] {callType}; mHelper.setPhoneCallDetails(mViewHolder, details); } private PhoneCallDetails getPhoneCallDetails( - String number, int presentation, String formattedNumber) { + String number, String postDialDigits, int presentation, String formattedNumber) { PhoneCallDetails details = new PhoneCallDetails( mContext, number, presentation, formattedNumber, + postDialDigits, false /* isVoicemail */); setDefaultDetails(details); return details; @@ -278,6 +286,7 @@ public class CallLogListItemHelperTest extends AndroidTestCase { TEST_NUMBER, Calls.PRESENTATION_ALLOWED, TEST_FORMATTED_NUMBER, + "", false /* isVoicemail */); setDefaultDetails(details); details.callTypes = types; diff --git a/tests/src/com/android/dialer/calllog/CallLogQueryTestUtils.java b/tests/src/com/android/dialer/calllog/CallLogQueryTestUtils.java index 5b4629318..1e4a00000 100644 --- a/tests/src/com/android/dialer/calllog/CallLogQueryTestUtils.java +++ b/tests/src/com/android/dialer/calllog/CallLogQueryTestUtils.java @@ -20,17 +20,24 @@ import static junit.framework.Assert.assertEquals; import android.provider.CallLog.Calls; -import junit.framework.Assert; - /** * Helper class to create test values for {@link CallLogQuery}. */ public class CallLogQueryTestUtils { public static Object[] createTestValues() { - Object[] 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 - }; + Object[] values; + if (PhoneNumberDisplayUtil.canShowPostDial()) { + 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, "" + }; + } else { + 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 + }; + } assertEquals(CallLogQuery._PROJECTION.length, values.length); return values; } diff --git a/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java b/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java index c30861c8e..23ee7b311 100644 --- a/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java +++ b/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java @@ -58,6 +58,8 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase { private static final String TEST_GEOCODE = "United States"; /** Empty geocode label */ private static final String EMPTY_GEOCODE = ""; + /** Empty post-dial digits label */ + private static final String EMPTY_POSTDIAL = ""; /** The object under test. */ private PhoneCallDetailsHelper mHelper; @@ -428,6 +430,7 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase { TEST_NUMBER, Calls.PRESENTATION_ALLOWED, TEST_FORMATTED_NUMBER, + EMPTY_POSTDIAL, false /* isVoicemail */); setDefaultDetails(details); return details; @@ -440,6 +443,7 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase { number, presentation, formattedNumber, + EMPTY_POSTDIAL, isVoicemail(number)); setDefaultDetails(details); return details; |