summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorZheng Fu <zhengfu@google.com>2014-09-04 16:26:29 -0700
committerZheng Fu <zhengfu@google.com>2014-09-15 21:22:49 +0000
commit84e66f5469168132e0ef8efc5e6f08f21608b383 (patch)
treeb8d78c89a5f02f56861d37060bce453c364ec7ea /tests
parentc00a5e2d1d1820e11d7f3961e6e809a6954e5154 (diff)
downloadpackages_providers_ContactsProvider-84e66f5469168132e0ef8efc5e6f08f21608b383.zip
packages_providers_ContactsProvider-84e66f5469168132e0ef8efc5e6f08f21608b383.tar.gz
packages_providers_ContactsProvider-84e66f5469168132e0ef8efc5e6f08f21608b383.tar.bz2
DO NOT MERGE Remove default settings during contacts aggregation.
Set is_super_primary to 0 for all the shared mime-types's data between aggregated contacts. Bug:5080996 Change-Id: Ie65259c11d719b343f234e5fccf883491e7992a7 (cherry picked from commit 96ddeddc52c85710a10cd8266c054ff1b1c5a52b)
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java39
-rw-r--r--tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java40
2 files changed, 77 insertions, 2 deletions
diff --git a/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java b/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java
index b90e88b..ed0c06d 100644
--- a/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java
+++ b/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java
@@ -232,16 +232,24 @@ public abstract class BaseContactsProvider2Test extends PhotoLoadingTestCase {
}
protected Uri insertOrganization(long rawContactId, ContentValues values) {
- return insertOrganization(rawContactId, values, false);
+ return insertOrganization(rawContactId, values, false, false);
}
protected Uri insertOrganization(long rawContactId, ContentValues values, boolean primary) {
+ return insertOrganization(rawContactId, values, primary, false);
+ }
+
+ protected Uri insertOrganization(long rawContactId, ContentValues values, boolean primary,
+ boolean superPrimary) {
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE);
values.put(Organization.TYPE, Organization.TYPE_WORK);
if (primary) {
values.put(Data.IS_PRIMARY, 1);
}
+ if (superPrimary) {
+ values.put(Data.IS_SUPER_PRIMARY, 1);
+ }
Uri resultUri = mResolver.insert(Data.CONTENT_URI, values);
return resultUri;
@@ -252,11 +260,21 @@ public abstract class BaseContactsProvider2Test extends PhotoLoadingTestCase {
}
protected Uri insertPhoneNumber(long rawContactId, String phoneNumber, boolean primary) {
- return insertPhoneNumber(rawContactId, phoneNumber, primary, Phone.TYPE_HOME);
+ return insertPhoneNumber(rawContactId, phoneNumber, primary, false, Phone.TYPE_HOME);
+ }
+
+ protected Uri insertPhoneNumber(long rawContactId, String phoneNumber, boolean primary,
+ boolean superPrimary) {
+ return insertPhoneNumber(rawContactId, phoneNumber, primary, superPrimary, Phone.TYPE_HOME);
}
protected Uri insertPhoneNumber(long rawContactId, String phoneNumber, boolean primary,
int type) {
+ return insertPhoneNumber(rawContactId, phoneNumber, primary, false, type);
+ }
+
+ protected Uri insertPhoneNumber(long rawContactId, String phoneNumber, boolean primary,
+ boolean superPrimary, int type) {
ContentValues values = new ContentValues();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
@@ -265,6 +283,9 @@ public abstract class BaseContactsProvider2Test extends PhotoLoadingTestCase {
if (primary) {
values.put(Data.IS_PRIMARY, 1);
}
+ if (superPrimary) {
+ values.put(Data.IS_SUPER_PRIMARY, 1);
+ }
Uri resultUri = mResolver.insert(Data.CONTENT_URI, values);
return resultUri;
@@ -712,6 +733,20 @@ public abstract class BaseContactsProvider2Test extends PhotoLoadingTestCase {
}
}
+ protected void assertSuperPrimary(Long dataId, boolean isSuperPrimary) {
+ final String[] projection = new String[]{Data.MIMETYPE, Data._ID, Data.IS_SUPER_PRIMARY};
+ Cursor c = mResolver.query(ContentUris.withAppendedId(Data.CONTENT_URI, dataId),
+ projection, null, null, null);
+
+ c.moveToFirst();
+ if (isSuperPrimary) {
+ assertEquals(1, c.getInt(c.getColumnIndexOrThrow(Data.IS_SUPER_PRIMARY)));
+ } else {
+ assertEquals(0, c.getInt(c.getColumnIndexOrThrow(Data.IS_SUPER_PRIMARY)));
+ }
+
+ }
+
protected void assertDataRow(ContentValues actual, String expectedMimetype,
Object... expectedArguments) {
assertEquals(actual.toString(), expectedMimetype, actual.getAsString(Data.MIMETYPE));
diff --git a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
index cb0766e..6ce98a7 100644
--- a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
+++ b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
@@ -1486,6 +1486,46 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test {
cursor.close();
}
+ public void testAggregation_clearSuperPrimary() {
+ // Three types of mime-type super primary merging are tested here
+ // 1. both raw contacts have super primary phone numbers
+ // 2. both raw contacts have emails, but only one has super primary email
+ // 3. only raw contact1 has organizations and it has set the super primary organization
+ ContentValues values = new ContentValues();
+ long rawContactId1 = RawContactUtil.createRawContact(mResolver, ACCOUNT_1);
+ Uri uri_phone1 = insertPhoneNumber(rawContactId1, "(222)222-2222", false, false);
+ Uri uri_email1 = insertEmail(rawContactId1, "one@gmail.com", true, true);
+ values.clear();
+ values.put(Organization.COMPANY, "Monsters Inc");
+ Uri uri_org1 = insertOrganization(rawContactId1, values, true, true);
+ values.clear();
+ values.put(Organization.TITLE, "CEO");
+ Uri uri_org2 = insertOrganization(rawContactId1, values, false, false);
+
+ long rawContactId2 = RawContactUtil.createRawContact(mResolver, ACCOUNT_2);
+ Uri uri_phone2 = insertPhoneNumber(rawContactId2, "(333)333-3333", false, false);
+ Uri uri_email2 = insertEmail(rawContactId2, "two@gmail.com", false, false);
+
+ // Two raw contacts with same phone number will trigger the aggregation
+ Uri uri_phone3 = insertPhoneNumber(rawContactId1, "(111)111-1111", true, true);
+ Uri uri_phone4 = insertPhoneNumber(rawContactId2, "1(111)111-1111", true, true);
+
+ // After aggregation, the super primary flag should be cleared for both case 1 and case 2,
+ // i.e., phone and email mime-types. Only case 3, i.e. organization mime-type, has the
+ // super primary flag unchanged.
+ assertAggregated(rawContactId1, rawContactId2);
+ assertSuperPrimary(ContentUris.parseId(uri_phone1), false);
+ assertSuperPrimary(ContentUris.parseId(uri_phone2), false);
+ assertSuperPrimary(ContentUris.parseId(uri_phone3), false);
+ assertSuperPrimary(ContentUris.parseId(uri_phone4), false);
+
+ assertSuperPrimary(ContentUris.parseId(uri_email1), false);
+ assertSuperPrimary(ContentUris.parseId(uri_email2), false);
+
+ assertSuperPrimary(ContentUris.parseId(uri_org1), true);
+ assertSuperPrimary(ContentUris.parseId(uri_org2), false);
+ }
+
private void assertSuggestions(long contactId, long... suggestions) {
final Uri aggregateUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
Uri uri = Uri.withAppendedPath(aggregateUri,