diff options
author | weijiaxu <weijiaxu@google.com> | 2017-08-09 18:41:57 -0700 |
---|---|---|
committer | Eric Erfanian <erfanian@google.com> | 2017-08-10 07:50:20 -0700 |
commit | c863ddb53bd85b5d36ef74a8ba98537eb59844a8 (patch) | |
tree | 1ecaeb7cc0536a4337ec5a795e7a54e5e7b9ef22 /java/com | |
parent | 6c14d7739ac2b177035aa084060aaccdaa7a8ba7 (diff) |
Add scuba test for ui regression test. Covered cases: Speed Dial Tab, Contacts Tab, Call Log Tab, Call History UI.
Some code refactoring works for using database populating methods outside third party library and add new methods to clean contacts database and call log database.
Some golden images get uploaded.
Bug: 64022871
Test: Ran test cases on emulator and they got passed.
PiperOrigin-RevId: 164804270
Change-Id: I5ad86dda98fde9d9203414a0f14fe94b777afd8f
Diffstat (limited to 'java/com')
-rw-r--r-- | java/com/android/dialer/databasepopulator/AndroidManifest.xml | 18 | ||||
-rw-r--r-- | java/com/android/dialer/databasepopulator/CallLogPopulator.java (renamed from java/com/android/dialer/simulator/impl/SimulatorCallLog.java) | 24 | ||||
-rw-r--r-- | java/com/android/dialer/databasepopulator/ContactsPopulator.java (renamed from java/com/android/dialer/simulator/impl/SimulatorContacts.java) | 45 | ||||
-rw-r--r-- | java/com/android/dialer/databasepopulator/VoicemailPopulator.java (renamed from java/com/android/dialer/simulator/impl/SimulatorVoicemail.java) | 18 | ||||
-rw-r--r-- | java/com/android/dialer/simulator/impl/SimulatorActionProvider.java | 28 |
5 files changed, 117 insertions, 16 deletions
diff --git a/java/com/android/dialer/databasepopulator/AndroidManifest.xml b/java/com/android/dialer/databasepopulator/AndroidManifest.xml new file mode 100644 index 000000000..0a3728566 --- /dev/null +++ b/java/com/android/dialer/databasepopulator/AndroidManifest.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2017 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> +<manifest package="com.android.dialer.databasepopulator"> +</manifest>
\ No newline at end of file diff --git a/java/com/android/dialer/simulator/impl/SimulatorCallLog.java b/java/com/android/dialer/databasepopulator/CallLogPopulator.java index f127d5603..79b3fd6b6 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorCallLog.java +++ b/java/com/android/dialer/databasepopulator/CallLogPopulator.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.dialer.simulator.impl; +package com.android.dialer.databasepopulator; import android.content.ContentProviderOperation; import android.content.ContentValues; @@ -28,10 +28,11 @@ import android.support.annotation.WorkerThread; import com.android.dialer.common.Assert; import com.google.auto.value.AutoValue; import java.util.ArrayList; +import java.util.Arrays; import java.util.concurrent.TimeUnit; /** Populates the device database with call log entries. */ -final class SimulatorCallLog { +public final class CallLogPopulator { // Phone numbers from https://www.google.com/about/company/facts/locations/ private static final CallEntry.Builder[] SIMPLE_CALL_LOG = { CallEntry.builder().setType(Calls.MISSED_TYPE).setNumber("+1-302-6365454"), @@ -96,6 +97,21 @@ final class SimulatorCallLog { } } + @WorkerThread + public static void deleteAllCallLog(@NonNull Context context) { + Assert.isWorkerThread(); + try { + context + .getContentResolver() + .applyBatch( + CallLog.AUTHORITY, + new ArrayList<>( + Arrays.asList(ContentProviderOperation.newDelete(Calls.CONTENT_URI).build()))); + } catch (RemoteException | OperationApplicationException e) { + Assert.fail("failed to delete call log: " + e); + } + } + @AutoValue abstract static class CallEntry { @NonNull @@ -108,7 +124,7 @@ final class SimulatorCallLog { abstract long getTimeMillis(); static Builder builder() { - return new AutoValue_SimulatorCallLog_CallEntry.Builder() + return new AutoValue_CallLogPopulator_CallEntry.Builder() .setPresentation(Calls.PRESENTATION_ALLOWED); } @@ -135,5 +151,5 @@ final class SimulatorCallLog { } } - private SimulatorCallLog() {} + private CallLogPopulator() {} } diff --git a/java/com/android/dialer/simulator/impl/SimulatorContacts.java b/java/com/android/dialer/databasepopulator/ContactsPopulator.java index 5bd28986c..e93c5697a 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorContacts.java +++ b/java/com/android/dialer/databasepopulator/ContactsPopulator.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.dialer.simulator.impl; +package com.android.dialer.databasepopulator; import android.content.ContentProviderOperation; import android.content.Context; @@ -26,6 +26,7 @@ import android.graphics.Paint; import android.os.RemoteException; import android.provider.ContactsContract; import android.provider.ContactsContract.CommonDataKinds.Phone; +import android.provider.ContactsContract.RawContacts; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.WorkerThread; @@ -34,10 +35,11 @@ import com.android.dialer.common.Assert; import com.google.auto.value.AutoValue; import java.io.ByteArrayOutputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** Populates the device database with contacts. */ -public final class SimulatorContacts { +public final class ContactsPopulator { // Phone numbers from https://www.google.com/about/company/facts/locations/ private static final Contact[] SIMPLE_CONTACTS = { // US, contact with e164 number. @@ -46,6 +48,7 @@ public final class SimulatorContacts { .addPhoneNumber(new PhoneNumber("+1-302-6365454", Phone.TYPE_MOBILE)) .addEmail(new Email("m@example.com")) .setIsStarred(true) + .setPinned(1) .setOrangePhoto() .build(), // US, contact with a non-e164 number. @@ -54,6 +57,7 @@ public final class SimulatorContacts { .addPhoneNumber(new PhoneNumber("(425) 739-5600", Phone.TYPE_MOBILE)) .addEmail(new Email("l@example.com")) .setIsStarred(true) + .setPinned(2) .setBluePhoto() .build(), // UK, number where the (0) should be dropped. @@ -62,6 +66,7 @@ public final class SimulatorContacts { .addPhoneNumber(new PhoneNumber("+44 (0) 20 7031 3000", Phone.TYPE_MOBILE)) .addEmail(new Email("r@example.com")) .setIsStarred(true) + .setPinned(3) .setRedPhoto() .build(), // US and Australia, contact with a long name and multiple phone numbers. @@ -71,6 +76,7 @@ public final class SimulatorContacts { .addPhoneNumber(new PhoneNumber("+1 404-487-9000", Phone.TYPE_WORK)) .addPhoneNumber(new PhoneNumber("+61 2 9374 4001", Phone.TYPE_FAX_HOME)) .setIsStarred(true) + .setPinned(4) .setPurplePhoto() .build(), // US, phone number shared with another contact and 2nd phone number with wait and pause. @@ -78,25 +84,30 @@ public final class SimulatorContacts { .setName("Splinter") .addPhoneNumber(new PhoneNumber("+1-650-2530000", Phone.TYPE_HOME)) .addPhoneNumber(new PhoneNumber("+1 303-245-0086;123,456", Phone.TYPE_WORK)) + .setBluePhoto() .build(), // France, number with Japanese name. Contact.builder() .setName("スパイク・スピーゲル") .addPhoneNumber(new PhoneNumber("+33 (0)1 42 68 53 00", Phone.TYPE_MOBILE)) + .setBluePhoto() .build(), // Israel, RTL name and non-e164 number. Contact.builder() .setName("עקב אריה טברסק") .addPhoneNumber(new PhoneNumber("+33 (0)1 42 68 53 00", Phone.TYPE_MOBILE)) + .setBluePhoto() .build(), // UAE, RTL name. Contact.builder() .setName("سلام دنیا") .addPhoneNumber(new PhoneNumber("+971 4 4509500", Phone.TYPE_MOBILE)) + .setBluePhoto() .build(), // Brazil, contact with no name. Contact.builder() .addPhoneNumber(new PhoneNumber("+55-31-2128-6800", Phone.TYPE_MOBILE)) + .setBluePhoto() .build(), // Short number, contact with no name. Contact.builder().addPhoneNumber(new PhoneNumber("611", Phone.TYPE_MOBILE)).build(), @@ -104,12 +115,14 @@ public final class SimulatorContacts { Contact.builder() .setName("Anonymous") .addPhoneNumber(new PhoneNumber("*86 512-343-5283", Phone.TYPE_MOBILE)) + .setBluePhoto() .build(), // None, contact with no phone number. Contact.builder() .setName("No Phone Number") .addEmail(new Email("no@example.com")) .setIsStarred(true) + .setBluePhoto() .build(), }; @@ -127,6 +140,22 @@ public final class SimulatorContacts { } } + @WorkerThread + public static void deleteAllContacts(@NonNull Context context) { + Assert.isWorkerThread(); + try { + context + .getContentResolver() + .applyBatch( + ContactsContract.AUTHORITY, + new ArrayList<>( + Arrays.asList( + ContentProviderOperation.newDelete(RawContacts.CONTENT_URI).build()))); + } catch (RemoteException | OperationApplicationException e) { + Assert.fail("failed to delete contacts: " + e); + } + } + private static void addContact(Contact contact, List<ContentProviderOperation> operations) { int index = operations.size(); @@ -135,6 +164,9 @@ public final class SimulatorContacts { .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, contact.getAccountType()) .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, contact.getAccountName()) .withValue(ContactsContract.RawContacts.STARRED, contact.getIsStarred() ? 1 : 0) + .withValue( + ContactsContract.RawContacts.PINNED, + contact.getIsStarred() ? contact.getPinned() : 0) .withYieldAllowed(true) .build()); @@ -203,6 +235,8 @@ public final class SimulatorContacts { abstract boolean getIsStarred(); + abstract int getPinned(); + @Nullable abstract ByteArrayOutputStream getPhotoStream(); @@ -213,9 +247,10 @@ public final class SimulatorContacts { abstract List<Email> getEmails(); static Builder builder() { - return new AutoValue_SimulatorContacts_Contact.Builder() + return new AutoValue_ContactsPopulator_Contact.Builder() .setAccountType("com.google") .setAccountName("foo@example") + .setPinned(0) .setIsStarred(false) .setPhoneNumbers(new ArrayList<>()) .setEmails(new ArrayList<>()); @@ -234,6 +269,8 @@ public final class SimulatorContacts { abstract Builder setIsStarred(boolean isStarred); + abstract Builder setPinned(int position); + abstract Builder setPhotoStream(ByteArrayOutputStream photoStream); abstract Builder setPhoneNumbers(@NonNull List<PhoneNumber> phoneNumbers); @@ -315,5 +352,5 @@ public final class SimulatorContacts { } } - private SimulatorContacts() {} + private ContactsPopulator() {} } diff --git a/java/com/android/dialer/simulator/impl/SimulatorVoicemail.java b/java/com/android/dialer/databasepopulator/VoicemailPopulator.java index 04de201ae..581100f03 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorVoicemail.java +++ b/java/com/android/dialer/databasepopulator/VoicemailPopulator.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.dialer.simulator.impl; +package com.android.dialer.databasepopulator; import android.content.ComponentName; import android.content.ContentValues; @@ -30,7 +30,7 @@ import com.google.auto.value.AutoValue; import java.util.concurrent.TimeUnit; /** Populates the device database with voicemail entries. */ -final class SimulatorVoicemail { +public final class VoicemailPopulator { private static final String ACCOUNT_ID = "ACCOUNT_ID"; private static final Voicemail.Builder[] SIMPLE_VOICEMAILS = { @@ -90,9 +90,17 @@ final class SimulatorVoicemail { } } + @WorkerThread + public static void deleteAllVoicemail(@NonNull Context context) { + Assert.isWorkerThread(); + context + .getContentResolver() + .delete(Voicemails.buildSourceUri(context.getPackageName()), "", new String[] {}); + } + private static void enableVoicemail(@NonNull Context context) { PhoneAccountHandle handle = - new PhoneAccountHandle(new ComponentName(context, SimulatorVoicemail.class), ACCOUNT_ID); + new PhoneAccountHandle(new ComponentName(context, VoicemailPopulator.class), ACCOUNT_ID); ContentValues values = new ContentValues(); values.put(Status.SOURCE_PACKAGE, handle.getComponentName().getPackageName()); @@ -120,7 +128,7 @@ final class SimulatorVoicemail { abstract boolean getIsRead(); static Builder builder() { - return new AutoValue_SimulatorVoicemail_Voicemail.Builder(); + return new AutoValue_VoicemailPopulator_Voicemail.Builder(); } ContentValues getAsContentValues(Context context) { @@ -150,5 +158,5 @@ final class SimulatorVoicemail { } } - private SimulatorVoicemail() {} + private VoicemailPopulator() {} } diff --git a/java/com/android/dialer/simulator/impl/SimulatorActionProvider.java b/java/com/android/dialer/simulator/impl/SimulatorActionProvider.java index f2749b2c5..4efc0ee2d 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorActionProvider.java +++ b/java/com/android/dialer/simulator/impl/SimulatorActionProvider.java @@ -30,6 +30,9 @@ import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.DialerExecutor.Worker; import com.android.dialer.common.concurrent.DialerExecutors; +import com.android.dialer.databasepopulator.CallLogPopulator; +import com.android.dialer.databasepopulator.ContactsPopulator; +import com.android.dialer.databasepopulator.VoicemailPopulator; import com.android.dialer.enrichedcall.simulator.EnrichedCallSimulatorActivity; import com.android.dialer.persistentlog.PersistentLogger; @@ -89,6 +92,13 @@ final class SimulatorActionProvider extends ActionProvider { return true; }); subMenu + .add("Clean database") + .setOnMenuItemClickListener( + (itme) -> { + cleanDatabase(); + return true; + }); + subMenu .add("Sync Voicemail") .setOnMenuItemClickListener( (item) -> { @@ -128,9 +138,21 @@ final class SimulatorActionProvider extends ActionProvider { new AsyncTask<Void, Void, Void>() { @Override public Void doInBackground(Void... params) { - SimulatorContacts.populateContacts(context); - SimulatorCallLog.populateCallLog(context); - SimulatorVoicemail.populateVoicemail(context); + ContactsPopulator.populateContacts(context); + CallLogPopulator.populateCallLog(context); + VoicemailPopulator.populateVoicemail(context); + return null; + } + }.execute(); + } + + private void cleanDatabase() { + new AsyncTask<Void, Void, Void>() { + @Override + public Void doInBackground(Void... params) { + ContactsPopulator.deleteAllContacts(context); + CallLogPopulator.deleteAllCallLog(context); + VoicemailPopulator.deleteAllVoicemail(context); return null; } }.execute(); |