diff options
author | Jay Shrauner <shrauner@google.com> | 2015-08-27 16:24:40 -0700 |
---|---|---|
committer | Jay Shrauner <shrauner@google.com> | 2015-08-29 18:20:43 +0000 |
commit | 16b68491261362737752e6babc95f89e2b468f49 (patch) | |
tree | 8155be80aab8cfb971e83427663fc61c0372447b /tests/src/com | |
parent | 2576d8e416f2bc0b0e1d2a76b21ae9673058aea3 (diff) |
Unbundled build fixes for tests
Build tests against current SDK. Use android-support-test instead of
android.test.runner. Temporarily disable ContextMenuBuilder tests.
Use internal copy of LaunchPerformanceBase. Use reflection to call
CursorLoader.waitForLoader. Make local copy of
android.provider.CallLog.addCall.
Bug:23642167
Change-Id: I6b5901f60cd28cdee4857d9e66696a5c66efcd20
(cherry picked from commit 81b66b8ef878e6209e6f7dfc011e41fe806ec099)
Diffstat (limited to 'tests/src/com')
5 files changed, 99 insertions, 14 deletions
diff --git a/tests/src/com/android/dialer/CallDetailActivityTest.java b/tests/src/com/android/dialer/CallDetailActivityTest.java index 3b6b61141..c87424482 100644 --- a/tests/src/com/android/dialer/CallDetailActivityTest.java +++ b/tests/src/com/android/dialer/CallDetailActivityTest.java @@ -34,7 +34,7 @@ import android.widget.TextView; import com.android.dialer.calllog.CallLogAsyncTaskUtil; import com.android.dialer.util.AsyncTaskExecutors; import com.android.dialer.util.FakeAsyncTaskExecutor; -import com.android.internal.view.menu.ContextMenuBuilder; +// import com.android.internal.view.menu.ContextMenuBuilder; /** * Unit tests for the {@link CallDetailActivity}. NOTE: The screen needs to be on for the @@ -86,7 +86,6 @@ public class CallDetailActivityTest extends ActivityInstrumentationTestCase2<Cal * Test for bug where voicemails should not have remove-from-call-log entry. * <p> * See http://b/5054103. - */ public void testVoicemailDoesNotHaveRemoveFromCallLog() throws Throwable { setActivityIntentForTestVoicemailEntry(); startActivityUnderTest(); @@ -98,10 +97,10 @@ public class CallDetailActivityTest extends ActivityInstrumentationTestCase2<Cal assertFalse(menu.findItem(R.id.menu_remove_from_call_log).isVisible()); assertTrue(menu.findItem(R.id.menu_trash).isVisible()); } + */ /** * Test to check that I haven't broken the remove-from-call-log entry from regular calls. - */ public void testRegularCallDoesHaveRemoveFromCallLog() throws Throwable { setActivityIntentForTestCallEntry(); startActivityUnderTest(); @@ -113,6 +112,7 @@ public class CallDetailActivityTest extends ActivityInstrumentationTestCase2<Cal assertTrue(menu.findItem(R.id.menu_remove_from_call_log).isVisible()); assertFalse(menu.findItem(R.id.menu_trash).isVisible()); } + */ private void setActivityIntentForTestCallEntry() { assertNull(mVoicemailUri); @@ -132,7 +132,8 @@ public class CallDetailActivityTest extends ActivityInstrumentationTestCase2<Cal ContentValues values = new ContentValues(); values.put(VoicemailContract.Voicemails.NUMBER, CONTACT_NUMBER); values.put(VoicemailContract.Voicemails.HAS_CONTENT, 1); - values.put(VoicemailContract.Voicemails._DATA, VOICEMAIL_FILE_LOCATION); + // VoicemailContract.Voicemails._DATA + values.put("_data", VOICEMAIL_FILE_LOCATION); mVoicemailUri = contentResolver.insert(VoicemailContract.Voicemails.CONTENT_URI, values); Uri callLogUri = ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI_WITH_VOICEMAIL, diff --git a/tests/src/com/android/dialer/DialerLaunchPerformance.java b/tests/src/com/android/dialer/DialerLaunchPerformance.java index cf64f9449..c409cc60b 100644 --- a/tests/src/com/android/dialer/DialerLaunchPerformance.java +++ b/tests/src/com/android/dialer/DialerLaunchPerformance.java @@ -20,7 +20,8 @@ import android.app.Activity; import android.content.ComponentName; import android.content.Intent; import android.os.Bundle; -import android.test.LaunchPerformanceBase; + +import com.android.contacts.common.test.LaunchPerformanceBase; /** * Instrumentation class for Address Book launch performance testing. diff --git a/tests/src/com/android/dialer/interactions/PhoneNumberInteractionTest.java b/tests/src/com/android/dialer/interactions/PhoneNumberInteractionTest.java index 8d5b53eb2..54a07cc3a 100644 --- a/tests/src/com/android/dialer/interactions/PhoneNumberInteractionTest.java +++ b/tests/src/com/android/dialer/interactions/PhoneNumberInteractionTest.java @@ -18,6 +18,7 @@ package com.android.dialer.interactions; import android.content.ContentUris; import android.content.Context; +import android.content.CursorLoader; import android.content.DialogInterface.OnDismissListener; import android.content.Intent; import android.net.Uri; @@ -36,6 +37,7 @@ import com.android.contacts.common.util.ContactDisplayUtils; import com.android.dialer.interactions.PhoneNumberInteraction.PhoneItem; import com.android.dialer.util.TestConstants; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; @@ -59,6 +61,16 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { void showDisambiguationDialog(ArrayList<PhoneItem> phoneList) { this.mPhoneList = phoneList; } + + public void waitForLoader() { + final CursorLoader loader = getLoader(); + try { + final Method waitMethod = CursorLoader.class.getMethod("waitForLoader"); + waitMethod.invoke(loader, null); + } catch(Exception e) { + // ignore + } + } } private ContactsMockContext mContext; @@ -87,7 +99,7 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { mContext, ContactDisplayUtils.INTERACTION_SMS, null); interaction.startInteraction(contactUri); - interaction.getLoader().waitForLoader(); + interaction.waitForLoader(); Intent intent = mContext.getIntentForStartActivity(); assertNotNull(intent); @@ -106,7 +118,7 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { mContext, ContactDisplayUtils.INTERACTION_SMS, null); interaction.startInteraction(dataUri); - interaction.getLoader().waitForLoader(); + interaction.waitForLoader(); Intent intent = mContext.getIntentForStartActivity(); assertNotNull(intent); @@ -127,7 +139,7 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { mContext, ContactDisplayUtils.INTERACTION_SMS, null); interaction.startInteraction(contactUri); - interaction.getLoader().waitForLoader(); + interaction.waitForLoader(); Intent intent = mContext.getIntentForStartActivity(); assertNotNull(intent); @@ -168,7 +180,7 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { mContext, ContactDisplayUtils.INTERACTION_CALL, null); interaction.startInteraction(contactUri); - interaction.getLoader().waitForLoader(); + interaction.waitForLoader(); Intent intent = mContext.getIntentForStartActivity(); assertNotNull(intent); @@ -186,7 +198,7 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { mContext, ContactDisplayUtils.INTERACTION_CALL, null); interaction.startInteraction(contactUri); - interaction.getLoader().waitForLoader(); + interaction.waitForLoader(); Intent intent = mContext.getIntentForStartActivity(); assertNotNull(intent); @@ -207,7 +219,7 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { mContext, ContactDisplayUtils.INTERACTION_CALL, null); interaction.startInteraction(contactUri); - interaction.getLoader().waitForLoader(); + interaction.waitForLoader(); List<PhoneItem> items = interaction.mPhoneList; assertNotNull(items); diff --git a/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java b/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java index 71571549f..1cfdc2833 100644 --- a/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java +++ b/tests/src/com/android/dialer/tests/calllog/FillCallLogTestActivity.java @@ -25,6 +25,7 @@ import android.app.TimePickerDialog; import android.content.ContentProviderClient; import android.content.ContentResolver; import android.content.ContentValues; +import android.content.Context; import android.content.CursorLoader; import android.content.Loader; import android.database.Cursor; @@ -36,6 +37,7 @@ import android.provider.CallLog.Calls; import android.provider.VoicemailContract; import android.provider.VoicemailContract.Status; import android.provider.VoicemailContract.Voicemails; +import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; import android.text.format.DateFormat; @@ -407,7 +409,8 @@ public class FillCallLogTestActivity extends Activity { } private PhoneAccountHandle getManualAccount() { - TelecomManager telecomManager = TelecomManager.from(this); + TelecomManager telecomManager = + (TelecomManager) getSystemService(Context.TELECOM_SERVICE); List <PhoneAccountHandle> accountHandles = telecomManager.getCallCapablePhoneAccounts(); if (mAccount0.isChecked()) { return accountHandles.get(0); @@ -509,7 +512,7 @@ public class FillCallLogTestActivity extends Activity { if (getManualCallType() == Calls.VOICEMAIL_TYPE) { addManualVoicemail(dateTime.getTimeInMillis()); } else { - Calls.addCall(null, this, mPhoneNumber.getText().toString(), getManualPresentation(), + addCall(mPhoneNumber.getText().toString(), getManualPresentation(), getManualCallType(), features, getManualAccount(), dateTime.getTimeInMillis(), RNG.nextInt(60 * 60), dataUsage); } @@ -527,6 +530,73 @@ public class FillCallLogTestActivity extends Activity { setDisplayTime(); } + // Copied and modified to compile unbundled from android.provider.CallLog + public Uri addCall(String number, + int presentation, int callType, int features, PhoneAccountHandle accountHandle, + long start, int duration, Long dataUsage) { + final ContentResolver resolver = getContentResolver(); + int numberPresentation = Calls.PRESENTATION_ALLOWED; + + TelecomManager tm = (TelecomManager) getSystemService(Context.TELECOM_SERVICE); + + String accountAddress = null; + if (tm != null && accountHandle != null) { + PhoneAccount account = tm.getPhoneAccount(accountHandle); + if (account != null) { + Uri address = account.getSubscriptionAddress(); + if (address != null) { + accountAddress = address.getSchemeSpecificPart(); + } + } + } + + if (numberPresentation != Calls.PRESENTATION_ALLOWED) { + number = ""; + } + + // accountHandle information + String accountComponentString = null; + String accountId = null; + if (accountHandle != null) { + accountComponentString = accountHandle.getComponentName().flattenToString(); + accountId = accountHandle.getId(); + } + + ContentValues values = new ContentValues(6); + + values.put(Calls.NUMBER, number); + values.put(Calls.NUMBER_PRESENTATION, Integer.valueOf(numberPresentation)); + values.put(Calls.TYPE, Integer.valueOf(callType)); + values.put(Calls.FEATURES, features); + values.put(Calls.DATE, Long.valueOf(start)); + values.put(Calls.DURATION, Long.valueOf(duration)); + if (dataUsage != null) { + values.put(Calls.DATA_USAGE, dataUsage); + } + values.put(Calls.PHONE_ACCOUNT_COMPONENT_NAME, accountComponentString); + values.put(Calls.PHONE_ACCOUNT_ID, accountId); + // Calls.PHONE_ACCOUNT_ADDRESS + values.put("phone_account_address", accountAddress); + values.put(Calls.NEW, Integer.valueOf(1)); + + if (callType == Calls.MISSED_TYPE) { + values.put(Calls.IS_READ, 0); + } + + return addEntryAndRemoveExpiredEntries(this, Calls.CONTENT_URI, values); + } + + // Copied from android.provider.CallLog + private static Uri addEntryAndRemoveExpiredEntries(Context context, Uri uri, + ContentValues values) { + final ContentResolver resolver = context.getContentResolver(); + Uri result = resolver.insert(uri, values); + resolver.delete(uri, "_id IN " + + "(SELECT _id FROM calls ORDER BY " + Calls.DEFAULT_SORT_ORDER + + " LIMIT -1 OFFSET 500)", null); + return result; + } + private void addManualVoicemail(Long time) { final ContentValues contentValues = new ContentValues(); contentValues.put(Voicemails.DATE, time); diff --git a/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java b/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java index 58b4f558d..b9c70d38f 100644 --- a/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java +++ b/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java @@ -183,7 +183,8 @@ public class VoicemailPlaybackTest extends ActivityInstrumentationTestCase2<Call ContentValues values = new ContentValues(); values.put(VoicemailContract.Voicemails.NUMBER, CONTACT_NUMBER); values.put(VoicemailContract.Voicemails.HAS_CONTENT, 1); - values.put(VoicemailContract.Voicemails._DATA, VOICEMAIL_FILE_LOCATION); + // VoicemailContract.Voicemails._DATA + values.put("_data", VOICEMAIL_FILE_LOCATION); mVoicemailUri = contentResolver.insert(VoicemailContract.Voicemails.CONTENT_URI, values); } |