194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng/* 294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Copyright (C) 2011 The Android Open Source Project 394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Licensed under the Apache License, Version 2.0 (the "License"); 594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * you may not use this file except in compliance with the License. 694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * You may obtain a copy of the License at 794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * http://www.apache.org/licenses/LICENSE-2.0 994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 1094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Unless required by applicable law or agreed to in writing, software 1194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * distributed under the License is distributed on an "AS IS" BASIS, 1294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * See the License for the specific language governing permissions and 1494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * limitations under the License. 1594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 1694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 1794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengpackage com.android.dialer.calllog; 1894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 1994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.content.Context; 2094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.content.res.Resources; 2194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.provider.CallLog.Calls; 2294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.test.AndroidTestCase; 23e1071ace724a561dc3738b48a2d3d233aea4ff53Yorke Leeimport android.test.suitebuilder.annotation.MediumTest; 2494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.view.View; 2594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 267026b17269d014e7b4146446c139f63e15de7a33Yorke Leeimport com.android.contacts.common.CallUtil; 2794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport com.android.dialer.PhoneCallDetails; 2845ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunnimport com.android.dialer.R; 29fdb93b7079d522d688ec0ebe58c92d45aee48786Nancy Chenimport com.android.dialer.calllog.calllogcache.TestTelecomCallLogCache; 30838988bf34229b33ed39bb7dc7109427da264c81Andrew Leeimport com.android.dialer.util.AppCompatConstants; 3194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 3294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng/** 3394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Unit tests for {@link CallLogListItemHelper}. 3494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 35e1071ace724a561dc3738b48a2d3d233aea4ff53Yorke Lee@MediumTest 3694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengpublic class CallLogListItemHelperTest extends AndroidTestCase { 3794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** A test phone number for phone calls. */ 3894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private static final String TEST_NUMBER = "14125555555"; 3994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** The formatted version of {@link #TEST_NUMBER}. */ 4094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private static final String TEST_FORMATTED_NUMBER = "1-412-255-5555"; 4194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** A test date value for phone calls. */ 4294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private static final long TEST_DATE = 1300000000; 4394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** A test duration value for phone calls. */ 4494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private static final long TEST_DURATION = 62300; 4594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** A test voicemail number. */ 4694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private static final String TEST_VOICEMAIL_NUMBER = "123"; 4794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** The country ISO name used in the tests. */ 4894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private static final String TEST_COUNTRY_ISO = "US"; 4994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** The geocoded location used in the tests. */ 5094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private static final String TEST_GEOCODE = "United States"; 5194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 5294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** The object under test. */ 5394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private CallLogListItemHelper mHelper; 5494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 5594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** The views used in the tests. */ 56c1b7d0ae8cdfc0f0dddb5c2bb45c8239ffc6a264Andrew Lee private CallLogListItemViewHolder mViewHolder; 5794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 5849efd91e50a11dc7bdef8382a0ceac01bc060f77Andrew Lee private Context mContext; 5945ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn private Resources mResources; 6045ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn 6194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 6294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng protected void setUp() throws Exception { 6394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng super.setUp(); 6449efd91e50a11dc7bdef8382a0ceac01bc060f77Andrew Lee mContext = getContext(); 6549efd91e50a11dc7bdef8382a0ceac01bc060f77Andrew Lee mResources = mContext.getResources(); 66d3f6a6c56dec7d47bae1121ed1030f67c26736feAndrew Lee final TestTelecomCallLogCache phoneUtils = 67a46ed83a7ccba16bbfd791a3a6588d5f0add9526Brad Ebinger new TestTelecomCallLogCache(mContext, TEST_VOICEMAIL_NUMBER, ""); 68e80d62229bb11a92f0db8d4e4bac6533bbed9b66Nancy Chen PhoneCallDetailsHelper phoneCallDetailsHelper = 6949efd91e50a11dc7bdef8382a0ceac01bc060f77Andrew Lee new PhoneCallDetailsHelper(mContext, mResources, phoneUtils); 70d3f6a6c56dec7d47bae1121ed1030f67c26736feAndrew Lee mHelper = new CallLogListItemHelper(phoneCallDetailsHelper, mResources, phoneUtils); 7149efd91e50a11dc7bdef8382a0ceac01bc060f77Andrew Lee mViewHolder = CallLogListItemViewHolder.createForTest(mContext); 72d3f6a6c56dec7d47bae1121ed1030f67c26736feAndrew Lee 7394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 7494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 7594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 7694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng protected void tearDown() throws Exception { 7794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng mHelper = null; 78c1b7d0ae8cdfc0f0dddb5c2bb45c8239ffc6a264Andrew Lee mViewHolder = null; 7994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng super.tearDown(); 8094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 8194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 8294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void testSetPhoneCallDetails() { 83719a7adde25e0a717816b00668c16c3a1e3c5518Jay Shrauner setPhoneCallDetailsWithNumber("12125551234", Calls.PRESENTATION_ALLOWED, 84719a7adde25e0a717816b00668c16c3a1e3c5518Jay Shrauner "1-212-555-1234"); 85b0b57a10fbb9bec5c80d7adad8f65750a2f96e1bAndrew Lee assertEquals(View.VISIBLE, mViewHolder.primaryActionButtonView.getVisibility()); 867030a12a15e565521ffb220c00a0251e47bd3a93Christine Chen } 877030a12a15e565521ffb220c00a0251e47bd3a93Christine Chen 8894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void testSetPhoneCallDetails_Unknown() { 89719a7adde25e0a717816b00668c16c3a1e3c5518Jay Shrauner setPhoneCallDetailsWithNumber("", Calls.PRESENTATION_UNKNOWN, ""); 9045ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn assertNoCallIntent(); 9194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 9294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 9394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void testSetPhoneCallDetails_Private() { 94719a7adde25e0a717816b00668c16c3a1e3c5518Jay Shrauner setPhoneCallDetailsWithNumber("", Calls.PRESENTATION_RESTRICTED, ""); 9545ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn assertNoCallIntent(); 9694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 9794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 9894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void testSetPhoneCallDetails_Payphone() { 99719a7adde25e0a717816b00668c16c3a1e3c5518Jay Shrauner setPhoneCallDetailsWithNumber("", Calls.PRESENTATION_PAYPHONE, ""); 10045ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn assertNoCallIntent(); 10194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 10294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 10394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void testSetPhoneCallDetails_VoicemailNumber() { 104719a7adde25e0a717816b00668c16c3a1e3c5518Jay Shrauner setPhoneCallDetailsWithNumber(TEST_VOICEMAIL_NUMBER, 105719a7adde25e0a717816b00668c16c3a1e3c5518Jay Shrauner Calls.PRESENTATION_ALLOWED, TEST_VOICEMAIL_NUMBER); 106267e9ebd056ec4973c4b37c38f949e863de4f24cAndrew Lee assertEquals(View.VISIBLE, mViewHolder.voicemailPlaybackView.getVisibility()); 10794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 10894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 10994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void testSetPhoneCallDetails_ReadVoicemail() { 110838988bf34229b33ed39bb7dc7109427da264c81Andrew Lee PhoneCallDetails details = 111838988bf34229b33ed39bb7dc7109427da264c81Andrew Lee getPhoneCallDetailsWithTypes(AppCompatConstants.CALLS_VOICEMAIL_TYPE); 112d3f6a6c56dec7d47bae1121ed1030f67c26736feAndrew Lee mHelper.setPhoneCallDetails(mViewHolder, details); 113267e9ebd056ec4973c4b37c38f949e863de4f24cAndrew Lee assertEquals(View.VISIBLE, mViewHolder.voicemailPlaybackView.getVisibility()); 11494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 11594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 11694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void testSetPhoneCallDetails_UnreadVoicemail() { 117838988bf34229b33ed39bb7dc7109427da264c81Andrew Lee PhoneCallDetails details = 118838988bf34229b33ed39bb7dc7109427da264c81Andrew Lee getPhoneCallDetailsWithTypes(AppCompatConstants.CALLS_VOICEMAIL_TYPE); 119d3f6a6c56dec7d47bae1121ed1030f67c26736feAndrew Lee mHelper.setPhoneCallDetails(mViewHolder, details); 120267e9ebd056ec4973c4b37c38f949e863de4f24cAndrew Lee assertEquals(View.VISIBLE, mViewHolder.voicemailPlaybackView.getVisibility()); 12194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 12294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 12394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void testSetPhoneCallDetails_VoicemailFromUnknown() { 124719a7adde25e0a717816b00668c16c3a1e3c5518Jay Shrauner setPhoneCallDetailsWithNumberAndType("", Calls.PRESENTATION_UNKNOWN, 125838988bf34229b33ed39bb7dc7109427da264c81Andrew Lee "", AppCompatConstants.CALLS_VOICEMAIL_TYPE); 126267e9ebd056ec4973c4b37c38f949e863de4f24cAndrew Lee assertEquals(View.VISIBLE, mViewHolder.voicemailPlaybackView.getVisibility()); 12745ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn } 12845ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn 12945ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn /** 13045ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn * Test getCallDescriptionID method used to get the accessibility description for calls. 13145ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn */ 132edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee public void testGetCallDescriptionID_Answered() { 1339e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen int[] callTypes = new int[] {AppCompatConstants.CALLS_INCOMING_TYPE}; 134146a4cdf57f0d4d0cd85e808f1df2bdea639b24cTyler Gunn assertEquals(R.string.description_incoming_answered_call, 1359e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen mHelper.getCallDescriptionStringID(callTypes, true)); 13645ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn } 13745ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn 13845ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn /** 13945ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn * Test getCallDescriptionID method used to get the accessibility description for calls. 14045ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn */ 141edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee public void testGetCallDescriptionID_Missed() { 1429e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen int[] callTypes = new int[] {AppCompatConstants.CALLS_MISSED_TYPE}; 143146a4cdf57f0d4d0cd85e808f1df2bdea639b24cTyler Gunn assertEquals(R.string.description_incoming_missed_call, 1449e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen mHelper.getCallDescriptionStringID(callTypes, true)); 14545ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn } 14645ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn 14745ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn /** 14845ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn * Test getCallDescriptionID method used to get the accessibility description for calls. 14945ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn * Test case where an outgoing call is made to a known number and there is a history of 15045ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn * only a single call for this caller. 15145ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn */ 15245ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn public void testGetCallDescriptionID_OutgoingSingle() { 1539e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen int[] callTypes = new int[] {AppCompatConstants.CALLS_OUTGOING_TYPE}; 154146a4cdf57f0d4d0cd85e808f1df2bdea639b24cTyler Gunn assertEquals(R.string.description_outgoing_call, 1559e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen mHelper.getCallDescriptionStringID(callTypes, true)); 15645ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn } 15745ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn 15845ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn /** 15945ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn * Test getCallDescriptionID method used to get the accessibility description for calls. 16045ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn * Test case where an outgoing call is made to a known number and there is a history of 16145ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn * many calls for this caller. 16245ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn */ 16345ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn public void testGetCallDescriptionID_OutgoingMultiple() { 1649e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen int[] callTypes = new int[] { 165838988bf34229b33ed39bb7dc7109427da264c81Andrew Lee AppCompatConstants.CALLS_OUTGOING_TYPE, 166838988bf34229b33ed39bb7dc7109427da264c81Andrew Lee AppCompatConstants.CALLS_OUTGOING_TYPE 167838988bf34229b33ed39bb7dc7109427da264c81Andrew Lee }; 168146a4cdf57f0d4d0cd85e808f1df2bdea639b24cTyler Gunn assertEquals(R.string.description_outgoing_call, 1699e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen mHelper.getCallDescriptionStringID(callTypes, true)); 17045ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn } 17145ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn 17245ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn /** 17345ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn * Test getCallDescription method used to get the accessibility description for calls. 1749e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen * For read voicemail calls, we should have "Voicemail" in the description. 17545ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn */ 1769e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen public void testGetCallDescriptionID_Voicemail() { 1779e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen int[] callTypes = new int[] {AppCompatConstants.CALLS_VOICEMAIL_TYPE}; 1789e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen assertEquals(R.string.description_read_voicemail, 1799e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen mHelper.getCallDescriptionStringID(callTypes, true)); 18045ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn } 18145ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn 18245ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn /** 18345ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn * Test getCallDescription method used to get the accessibility description for calls. 1849e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen * For unread voicemail calls, we should have "Unread voicemail" in the description. 18545ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn */ 1869e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen public void testGetCallDescriptionID_UnreadVoicemail() { 1879e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen int[] callTypes = new int[] {AppCompatConstants.CALLS_VOICEMAIL_TYPE}; 1889e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen assertEquals(R.string.description_unread_voicemail, 1899e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen mHelper.getCallDescriptionStringID(callTypes, false)); 19045ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn } 19145ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn 19245ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn /** 19345ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn * Test getCallDescription method used to get the accessibility description for calls. 19445ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn * Test that the "X calls" message is not present if there is only a single call. 19545ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn */ 19645ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn public void testGetCallDescription_NumCallsSingle() { 197838988bf34229b33ed39bb7dc7109427da264c81Andrew Lee PhoneCallDetails details = 198838988bf34229b33ed39bb7dc7109427da264c81Andrew Lee getPhoneCallDetailsWithTypes(AppCompatConstants.CALLS_VOICEMAIL_TYPE); 199d3f6a6c56dec7d47bae1121ed1030f67c26736feAndrew Lee CharSequence description = mHelper.getCallDescription(details); 20045ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn 20145ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn // Rather than hard coding the "X calls" string message, we'll generate it with an empty 20245ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn // number of calls, and trim the resulting string. This gets us just the word "calls", 20345ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn // and ensures any trivial changes to that string resource won't unnecessarily break 20445ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn // the unit test. 20545ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn assertFalse(description.toString() 20645ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn .contains(this.mResources.getString(R.string.description_num_calls, "").trim())); 20745ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn } 20845ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn 20945ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn /** 21045ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn * Test getCallDescription method used to get the accessibility description for calls. 21145ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn * Test that the "X calls" message is present if there are many calls. 21245ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn */ 21345ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn public void testGetCallDescription_NumCallsMultiple() { 214838988bf34229b33ed39bb7dc7109427da264c81Andrew Lee PhoneCallDetails details = getPhoneCallDetailsWithTypes( 215838988bf34229b33ed39bb7dc7109427da264c81Andrew Lee AppCompatConstants.CALLS_VOICEMAIL_TYPE, AppCompatConstants.CALLS_INCOMING_TYPE); 216d3f6a6c56dec7d47bae1121ed1030f67c26736feAndrew Lee CharSequence description = mHelper.getCallDescription(details); 21745ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn assertTrue(description.toString() 21845ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn .contains(this.mResources.getString(R.string.description_num_calls, 2))); 2197030a12a15e565521ffb220c00a0251e47bd3a93Christine Chen } 2207030a12a15e565521ffb220c00a0251e47bd3a93Christine Chen 2215619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn /** 2225619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn * Test getCallDescription method used to get the accessibility description for calls. 2235619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn * Test that the "Video call." message is present if the call had video capability. 2245619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn */ 2255619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn public void testGetCallDescription_Video() { 226838988bf34229b33ed39bb7dc7109427da264c81Andrew Lee PhoneCallDetails details = getPhoneCallDetailsWithTypes( 227838988bf34229b33ed39bb7dc7109427da264c81Andrew Lee AppCompatConstants.CALLS_INCOMING_TYPE, AppCompatConstants.CALLS_INCOMING_TYPE); 228edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee details.features = Calls.FEATURES_VIDEO; 229c2756debb05846b1be1d77ebfb8650dcea9f1c9cTyler Gunn 230d3f6a6c56dec7d47bae1121ed1030f67c26736feAndrew Lee CharSequence description = mHelper.getCallDescription(details); 2317026b17269d014e7b4146446c139f63e15de7a33Yorke Lee final boolean isVideoEnabled = CallUtil.isVideoEnabled(getContext()); 2325619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn assertTrue(description.toString() 2337026b17269d014e7b4146446c139f63e15de7a33Yorke Lee .contains(this.mResources.getString( 2347026b17269d014e7b4146446c139f63e15de7a33Yorke Lee isVideoEnabled 2357026b17269d014e7b4146446c139f63e15de7a33Yorke Lee ? R.string.description_video_call 2367026b17269d014e7b4146446c139f63e15de7a33Yorke Lee : R.string.description_num_calls, 2377026b17269d014e7b4146446c139f63e15de7a33Yorke Lee 2))); 2385619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn } 2395619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn 24045ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn /** Asserts that the primary action view does not have a call intent. */ 24145ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn private void assertNoCallIntent() { 242e1071ace724a561dc3738b48a2d3d233aea4ff53Yorke Lee Object intentProvider = mViewHolder.primaryActionView.getTag(); 24345ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn // The intent provider should be null as there is no ability to make a call. 24445ed3b5932ed590b45235d7b2befa736a95e7f75Tyler Gunn assertNull(intentProvider); 24594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 24694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 24794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** Sets the details of a phone call using the specified phone number. */ 248719a7adde25e0a717816b00668c16c3a1e3c5518Jay Shrauner private void setPhoneCallDetailsWithNumber(String number, 249719a7adde25e0a717816b00668c16c3a1e3c5518Jay Shrauner int presentation, String formattedNumber) { 25035e44d4b757427a240e8764467bdd220e2124473Hall Liu setPhoneCallDetailsWithNumberTypeAndPostDialDigits(number, "", presentation, 251719a7adde25e0a717816b00668c16c3a1e3c5518Jay Shrauner formattedNumber, Calls.INCOMING_TYPE); 25294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 25394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 25494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** Sets the details of a phone call using the specified phone number. */ 255719a7adde25e0a717816b00668c16c3a1e3c5518Jay Shrauner private void setPhoneCallDetailsWithNumberAndType(String number, 256719a7adde25e0a717816b00668c16c3a1e3c5518Jay Shrauner int presentation, String formattedNumber, int callType) { 25735e44d4b757427a240e8764467bdd220e2124473Hall Liu setPhoneCallDetailsWithNumberTypeAndPostDialDigits(number, "", presentation, 25835e44d4b757427a240e8764467bdd220e2124473Hall Liu formattedNumber, callType); 25935e44d4b757427a240e8764467bdd220e2124473Hall Liu } 26035e44d4b757427a240e8764467bdd220e2124473Hall Liu 26135e44d4b757427a240e8764467bdd220e2124473Hall Liu /** Sets the details of a phone call using the specified phone number and post-dial digits. */ 26235e44d4b757427a240e8764467bdd220e2124473Hall Liu private void setPhoneCallDetailsWithNumberTypeAndPostDialDigits(String number, 26335e44d4b757427a240e8764467bdd220e2124473Hall Liu String postDialDigits, int presentation, String formattedNumber, int callType) { 264edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee PhoneCallDetails details = getPhoneCallDetails( 26535e44d4b757427a240e8764467bdd220e2124473Hall Liu number, postDialDigits, presentation, formattedNumber); 2669e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen details.callTypes = new int[] {callType}; 267d3f6a6c56dec7d47bae1121ed1030f67c26736feAndrew Lee mHelper.setPhoneCallDetails(mViewHolder, details); 268edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee } 269edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee 270edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee private PhoneCallDetails getPhoneCallDetails( 27135e44d4b757427a240e8764467bdd220e2124473Hall Liu String number, String postDialDigits, int presentation, String formattedNumber) { 272edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee PhoneCallDetails details = new PhoneCallDetails( 273edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee mContext, 274edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee number, 275edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee presentation, 276edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee formattedNumber, 27735e44d4b757427a240e8764467bdd220e2124473Hall Liu postDialDigits, 278edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee false /* isVoicemail */); 279edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee setDefaultDetails(details); 280edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee return details; 28194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 28294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 283edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee /** Returns the details of a phone call using the specified call type. */ 284edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee private PhoneCallDetails getPhoneCallDetailsWithTypes(int... types) { 285edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee PhoneCallDetails details = new PhoneCallDetails( 286edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee mContext, 287edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee TEST_NUMBER, 288edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee Calls.PRESENTATION_ALLOWED, 289edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee TEST_FORMATTED_NUMBER, 29035e44d4b757427a240e8764467bdd220e2124473Hall Liu "", 291edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee false /* isVoicemail */); 292edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee setDefaultDetails(details); 293edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee details.callTypes = types; 294edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee return details; 2957030a12a15e565521ffb220c00a0251e47bd3a93Christine Chen } 2967030a12a15e565521ffb220c00a0251e47bd3a93Christine Chen 297edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee private void setDefaultDetails(PhoneCallDetails details) { 2989e40502d2b5685b6996ecee7b3b3c812d5b06ec8Nancy Chen details.callTypes = new int[] {Calls.INCOMING_TYPE}; 299edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee details.countryIso = TEST_COUNTRY_ISO; 300edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee details.date = TEST_DATE; 301edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee details.duration = TEST_DURATION; 302edb22da2b40549631a08150cbfc205e6ad243c20Andrew Lee details.geocode = TEST_GEOCODE; 30394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 30494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng} 305