summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBrian Attwell <brianattwell@google.com>2015-01-28 12:12:10 -0800
committerBrian Attwell <brianattwell@google.com>2015-01-28 15:41:00 -0800
commit8ddd7038fb59c1b346ee8baa8fcef57cc3eebf0c (patch)
tree538fe54d2c7817105c77142a9f2d6f7cd8447824 /tests
parent2ffd05bbcf37129f2126b563e5185f429a9a9042 (diff)
downloadpackages_providers_ContactsProvider-8ddd7038fb59c1b346ee8baa8fcef57cc3eebf0c.zip
packages_providers_ContactsProvider-8ddd7038fb59c1b346ee8baa8fcef57cc3eebf0c.tar.gz
packages_providers_ContactsProvider-8ddd7038fb59c1b346ee8baa8fcef57cc3eebf0c.tar.bz2
Additional change to IS_SUPER_PRIMARY
UPDATE ----------------- This is being committed a second time, with two small changes from ag/619454: 1. This CL can be directly cherry-picked to MR1 because of the simpler unit test 2. Don't run a pointless update() call Original CL Comment ------------------ Noticed clearSuperPrimarySetting() sometimes clears all mimetypes's is_super_primary flag values sometimes, even mimetypes that aren't contained in both raw contacts. This doesn't appear to have been the intended behavior. Looks like a simple bug. Wrote a unit test and fixed the bug. Added a new method to DataUtil used inside the unit test. This method wasn't strictly necessary. But it is very useful in later CLs. (Part #2 or "Remove NAME_VERIFIED" series of CLs) Bug: 5080996 Bug: 18777272 Change-Id: I7944aae2ad4acb4df6560c5cd086242b7582fbf5
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java18
-rw-r--r--tests/src/com/android/providers/contacts/testutil/DataUtil.java14
2 files changed, 31 insertions, 1 deletions
diff --git a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
index 09ee207..c8e6810 100644
--- a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
+++ b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
@@ -1615,6 +1615,24 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test {
assertSuperPrimary(ContentUris.parseId(uri_org2), false);
}
+ public void testAggregation_clearSuperPrimarySingleMimetype() {
+ // Setup: two raw contacts, each has a single name. One of the names is super primary.
+ long rawContactId1 = RawContactUtil.createRawContact(mResolver, ACCOUNT_1);
+ long rawContactId2 = RawContactUtil.createRawContact(mResolver, ACCOUNT_1);
+ final Uri uri = DataUtil.insertStructuredName(mResolver, rawContactId1, "name1",
+ null, null, /* isSuperPrimary = */ true);
+
+ // Sanity check.
+ assertStoredValue(uri, Data.IS_SUPER_PRIMARY, 1);
+
+ // Action: aggregate
+ setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1,
+ rawContactId2);
+
+ // Verify: name is still super primary
+ assertStoredValue(uri, Data.IS_SUPER_PRIMARY, 1);
+ }
+
public void testNotAggregate_TooManyRawContactsInCandidate() {
long preId= 0;
for (int i = 0; i < ContactAggregator.AGGREGATION_CONTACT_SIZE_LIMIT; i++) {
diff --git a/tests/src/com/android/providers/contacts/testutil/DataUtil.java b/tests/src/com/android/providers/contacts/testutil/DataUtil.java
index 194e67d..1f4f35a 100644
--- a/tests/src/com/android/providers/contacts/testutil/DataUtil.java
+++ b/tests/src/com/android/providers/contacts/testutil/DataUtil.java
@@ -22,6 +22,7 @@ import android.content.ContentValues;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
+import android.provider.ContactsContract.Data;
import android.test.mock.MockContentResolver;
/**
@@ -59,6 +60,13 @@ public class DataUtil {
public static Uri insertStructuredName(
ContentResolver resolver, long rawContactId, String givenName, String familyName,
String phoneticGiven) {
+ return insertStructuredName(resolver, rawContactId, givenName, familyName, phoneticGiven,
+ /* isSuperPrimary = true */ false);
+ }
+
+ public static Uri insertStructuredName(
+ ContentResolver resolver, long rawContactId, String givenName, String familyName,
+ String phoneticGiven, boolean isSuperPrimary) {
ContentValues values = new ContentValues();
StringBuilder sb = new StringBuilder();
if (givenName != null) {
@@ -79,7 +87,11 @@ public class DataUtil {
if (phoneticGiven != null) {
values.put(StructuredName.PHONETIC_GIVEN_NAME, phoneticGiven);
}
+ if (isSuperPrimary) {
+ values.put(Data.IS_PRIMARY, 1);
+ values.put(Data.IS_SUPER_PRIMARY, 1);
+ }
return insertStructuredName(resolver, rawContactId, values);
}
-}
+} \ No newline at end of file