diff options
author | Dmitri Plotnikov <dplotnikov@google.com> | 2010-10-22 15:07:07 -0700 |
---|---|---|
committer | Dmitri Plotnikov <dplotnikov@google.com> | 2010-10-22 15:07:07 -0700 |
commit | f65b12455184bc69c45634586ab5fd3234ad98d7 (patch) | |
tree | 64beabae983bb7f7e9de09d1b6b443ad90a46503 /tests | |
parent | 6d65e5c7cc5308e96f31a12ace007ea439d5753b (diff) | |
parent | 47fd3881dfd2a21de29e917b6114974ff0a67b1b (diff) | |
download | packages_providers_ContactsProvider-f65b12455184bc69c45634586ab5fd3234ad98d7.zip packages_providers_ContactsProvider-f65b12455184bc69c45634586ab5fd3234ad98d7.tar.gz packages_providers_ContactsProvider-f65b12455184bc69c45634586ab5fd3234ad98d7.tar.bz2 |
resolved conflicts for merge of 47fd3881 to master
Change-Id: I35ea513b8f0c0694d9afa6095aa718e1624eab5f
Diffstat (limited to 'tests')
5 files changed, 76 insertions, 53 deletions
diff --git a/tests/src/com/android/providers/contacts/ContactLookupKeyTest.java b/tests/src/com/android/providers/contacts/ContactLookupKeyTest.java index c412865..ebadc55 100644 --- a/tests/src/com/android/providers/contacts/ContactLookupKeyTest.java +++ b/tests/src/com/android/providers/contacts/ContactLookupKeyTest.java @@ -42,8 +42,8 @@ public class ContactLookupKeyTest extends BaseContactsProvider2Test { public void testLookupKeyUsingDisplayNameAndNoAccount() { long rawContactId1 = createRawContactWithName("John", "Doe"); long rawContactId2 = createRawContactWithName("johndoe", null); - - assertAggregated(rawContactId1, rawContactId2); + setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1, rawContactId2); // Normalized display name String normalizedName = NameNormalizer.normalize("johndoe"); @@ -74,7 +74,8 @@ public class ContactLookupKeyTest extends BaseContactsProvider2Test { long rawContactId2 = createRawContactWithName("johndoe", null); storeValue(RawContacts.CONTENT_URI, rawContactId2, RawContacts.SOURCE_ID, "4.5.6"); - assertAggregated(rawContactId1, rawContactId2); + setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1, rawContactId2); // Two source ids, of them escaped String expectedLookupKey = "0i123.0e4..5..6"; @@ -127,6 +128,10 @@ public class ContactLookupKeyTest extends BaseContactsProvider2Test { long rawContactId3 = createRawContactWithName("John", "Doe"); storeValue(RawContacts.CONTENT_URI, rawContactId3, RawContacts.SOURCE_ID, "3"); + setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1, rawContactId2); + setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1, rawContactId3); String lookupKey = "0i1.0i2.0i3"; diff --git a/tests/src/com/android/providers/contacts/ContactsActor.java b/tests/src/com/android/providers/contacts/ContactsActor.java index 95b4a7d..e0703a4 100644 --- a/tests/src/com/android/providers/contacts/ContactsActor.java +++ b/tests/src/com/android/providers/contacts/ContactsActor.java @@ -31,6 +31,7 @@ import android.database.Cursor; import android.net.Uri; import android.provider.BaseColumns; import android.provider.ContactsContract; +import android.provider.ContactsContract.AggregationExceptions; import android.provider.ContactsContract.CommonDataKinds; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Data; @@ -232,27 +233,27 @@ public class ContactsActor { sCallingPackage = this.packageName; } - public long createContact(boolean isRestricted, String name) { + public long createRawContact(boolean isRestricted, String name) { ensureCallingPackage(); - long contactId = createContact(isRestricted); - createName(contactId, name); - return contactId; + long rawContactId = createRawContact(isRestricted); + createName(rawContactId, name); + return rawContactId; } - public long createContact(boolean isRestricted) { + public long createRawContact(boolean isRestricted) { ensureCallingPackage(); final ContentValues values = new ContentValues(); if (isRestricted) { values.put(RawContacts.IS_RESTRICTED, 1); } - Uri contactUri = resolver.insert(RawContacts.CONTENT_URI, values); - return ContentUris.parseId(contactUri); + Uri rawContactUri = resolver.insert(RawContacts.CONTENT_URI, values); + return ContentUris.parseId(rawContactUri); } - public long createContactWithStatus(boolean isRestricted, String name, String address, + public long createRawContactWithStatus(boolean isRestricted, String name, String address, String status) { - final long rawContactId = createContact(isRestricted, name); + final long rawContactId = createRawContact(isRestricted, name); final long dataId = createEmail(rawContactId, address); createStatus(dataId, status); return rawContactId; @@ -382,6 +383,14 @@ public class ContactsActor { return ContentUris.parseId(dataUri); } + protected void setAggregationException(int type, long rawContactId1, long rawContactId2) { + ContentValues values = new ContentValues(); + values.put(AggregationExceptions.RAW_CONTACT_ID1, rawContactId1); + values.put(AggregationExceptions.RAW_CONTACT_ID2, rawContactId2); + values.put(AggregationExceptions.TYPE, type); + resolver.update(AggregationExceptions.CONTENT_URI, values, null, null); + } + /** * Various internal database projections. */ diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java index cfcb937..18dec64 100644 --- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java @@ -81,6 +81,9 @@ import java.util.Locale; @LargeTest public class ContactsProvider2Test extends BaseContactsProvider2Test { + private static final Account ACCOUNT_1 = new Account("account_name_1", "account_type_1"); + private static final Account ACCOUNT_2 = new Account("account_name_2", "account_type_2"); + public void testContactsProjection() { assertProjection(Contacts.CONTENT_URI, new String[]{ Contacts._ID, @@ -859,11 +862,11 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { } public void testPhonesFilterQuery() { - long rawContactId1 = createRawContactWithName("Hot", "Tamale"); + long rawContactId1 = createRawContactWithName("Hot", "Tamale", ACCOUNT_1); insertPhoneNumber(rawContactId1, "18004664411"); insertPhoneNumber(rawContactId1, "1-800-466-4411"); - long rawContactId2 = createRawContactWithName("Hot", "Tamale"); + long rawContactId2 = createRawContactWithName("Hot", "Tamale", ACCOUNT_2); insertPhoneNumber(rawContactId2, "1-800-466-4411"); Uri filterUri1 = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, "tamale"); @@ -1073,11 +1076,11 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { } public void testEmailsFilterQuery() { - long rawContactId1 = createRawContactWithName("Hot", "Tamale"); + long rawContactId1 = createRawContactWithName("Hot", "Tamale", ACCOUNT_1); insertEmail(rawContactId1, "tamale@acme.com"); insertEmail(rawContactId1, "tamale@acme.com"); - long rawContactId2 = createRawContactWithName("Hot", "Tamale"); + long rawContactId2 = createRawContactWithName("Hot", "Tamale", ACCOUNT_2); insertEmail(rawContactId2, "tamale@acme.com"); Uri filterUri1 = Uri.withAppendedPath(Email.CONTENT_FILTER_URI, "tam"); @@ -2557,9 +2560,8 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { public void testRawContactDeletionKeepingAggregateContact() { long rawContactId1 = createRawContactWithName(mAccount); long rawContactId2 = createRawContactWithName(mAccount); - - // Same name - should be aggregated - assertAggregated(rawContactId1, rawContactId2); + setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1, rawContactId2); long contactId = queryContactId(rawContactId1); @@ -2673,8 +2675,8 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { } public void testContactDeletion() { - long rawContactId1 = createRawContactWithName("John", "Doe"); - long rawContactId2 = createRawContactWithName("John", "Doe"); + long rawContactId1 = createRawContactWithName("John", "Doe", ACCOUNT_1); + long rawContactId2 = createRawContactWithName("John", "Doe", ACCOUNT_2); long contactId = queryContactId(rawContactId1); @@ -2970,8 +2972,8 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { Uri rawContactUri1 = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId1); long rawContactId2 = createRawContactWithName(); Uri rawContactUri2 = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId2); - - assertAggregated(rawContactId1, rawContactId2); + setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1, rawContactId2); long contactId = queryContactId(rawContactId1); Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); diff --git a/tests/src/com/android/providers/contacts/GroupsTest.java b/tests/src/com/android/providers/contacts/GroupsTest.java index f244d4b..1846321 100644 --- a/tests/src/com/android/providers/contacts/GroupsTest.java +++ b/tests/src/com/android/providers/contacts/GroupsTest.java @@ -78,11 +78,13 @@ public class GroupsTest extends BaseContactsProvider2Test { long groupBlue = mActor.createGroup(GROUP_BLUE); // Create a handful of contacts - long contactAlpha = mActor.createContact(false, PERSON_ALPHA); - long contactBravo = mActor.createContact(false, PERSON_BRAVO); - long contactCharlie = mActor.createContact(false, PERSON_CHARLIE); - long contactCharlieDupe = mActor.createContact(false, PERSON_CHARLIE); - long contactDelta = mActor.createContact(false, PERSON_DELTA); + long contactAlpha = mActor.createRawContact(false, PERSON_ALPHA); + long contactBravo = mActor.createRawContact(false, PERSON_BRAVO); + long contactCharlie = mActor.createRawContact(false, PERSON_CHARLIE); + long contactCharlieDupe = mActor.createRawContact(false, PERSON_CHARLIE); + setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, contactCharlie, contactCharlieDupe); + long contactDelta = mActor.createRawContact(false, PERSON_DELTA); assertAggregated(contactCharlie, contactCharlieDupe); diff --git a/tests/src/com/android/providers/contacts/RestrictionExceptionsTest.java b/tests/src/com/android/providers/contacts/RestrictionExceptionsTest.java index 3fbf548..053f6e6 100644 --- a/tests/src/com/android/providers/contacts/RestrictionExceptionsTest.java +++ b/tests/src/com/android/providers/contacts/RestrictionExceptionsTest.java @@ -28,6 +28,7 @@ import android.content.res.AssetFileDescriptor; import android.database.Cursor; import android.net.Uri; import android.provider.ContactsContract; +import android.provider.ContactsContract.AggregationExceptions; import android.provider.LiveFolders; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Data; @@ -102,42 +103,44 @@ public class RestrictionExceptionsTest extends AndroidTestCase { public void testRestrictedInsertRestrictedQuery() { // Restricted query can read restricted data - final long rawContact = mGrey.createContact(true, GENERIC_NAME); + final long rawContact = mGrey.createRawContact(true, GENERIC_NAME); final int count = mGrey.getDataCountForRawContact(rawContact); assertEquals(1, count); } public void testRestrictedInsertGenericQuery() { // Generic query is denied restricted data - final long rawContact = mGrey.createContact(true, GENERIC_NAME); + final long rawContact = mGrey.createRawContact(true, GENERIC_NAME); final int count = mRed.getDataCountForRawContact(rawContact); assertEquals(0, count); } public void testGenericInsertRestrictedQuery() { // Restricted query can read generic data - final long rawContact = mRed.createContact(false, GENERIC_NAME); + final long rawContact = mRed.createRawContact(false, GENERIC_NAME); final int count = mGrey.getDataCountForRawContact(rawContact); assertEquals(1, count); } public void testGenericInsertGenericQuery() { // Generic query can read generic data - final long rawContact = mRed.createContact(false, GENERIC_NAME); + final long rawContact = mRed.createRawContact(false, GENERIC_NAME); final int count = mRed.getDataCountForRawContact(rawContact); assertEquals(1, count); } public void testMixedAggregateRestrictedQuery() { // Create mixed aggregate with a restricted phone number - final long greyContact = mGrey.createContact(true, GENERIC_NAME); - final long greyPhone = mGrey.createPhone(greyContact, PHONE_GREY); - final long redContact = mRed.createContact(false, GENERIC_NAME); - final long redPhone = mRed.createPhone(redContact, PHONE_RED); + final long greyRawContactId = mGrey.createRawContact(true, GENERIC_NAME); + mGrey.createPhone(greyRawContactId, PHONE_GREY); + final long redRawContactId = mRed.createRawContact(false, GENERIC_NAME); + mRed.createPhone(redRawContactId, PHONE_RED); + mGrey.setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, greyRawContactId, redRawContactId); // Make sure both aggregates were joined - final long greyAgg = mGrey.getContactForRawContact(greyContact); - final long redAgg = mRed.getContactForRawContact(redContact); + final long greyAgg = mGrey.getContactForRawContact(greyRawContactId); + final long redAgg = mRed.getContactForRawContact(redRawContactId); assertEquals(greyAgg, redAgg); // Restricted reader should have access to both numbers @@ -151,7 +154,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { public void testUpdateRestricted() { // Assert that we can't un-restrict something - final long greyContact = mGrey.createContact(true, GENERIC_NAME); + final long greyContact = mGrey.createRawContact(true, GENERIC_NAME); final long greyPhone = mGrey.createPhone(greyContact, PHONE_GREY); int count = mRed.getDataCountForRawContact(greyContact); @@ -170,14 +173,16 @@ public class RestrictionExceptionsTest extends AndroidTestCase { public void testExportVCard() throws Exception { // Create mixed aggregate with a restricted phone number - final long greyContact = mGrey.createContact(true, GENERIC_NAME); - final long greyPhone = mGrey.createPhone(greyContact, PHONE_GREY); - final long redContact = mRed.createContact(false, GENERIC_NAME); - final long redPhone = mRed.createPhone(redContact, PHONE_RED); + final long greyRawContactId = mGrey.createRawContact(true, GENERIC_NAME); + mGrey.createPhone(greyRawContactId, PHONE_GREY); + final long redRawContactId = mRed.createRawContact(false, GENERIC_NAME); + mRed.createPhone(redRawContactId, PHONE_RED); + mGrey.setAggregationException( + AggregationExceptions.TYPE_KEEP_TOGETHER, greyRawContactId, redRawContactId); // Make sure both aggregates were joined - final long greyAgg = mGrey.getContactForRawContact(greyContact); - final long redAgg = mRed.getContactForRawContact(redContact); + final long greyAgg = mGrey.getContactForRawContact(greyRawContactId); + final long redAgg = mRed.getContactForRawContact(redRawContactId); assertEquals(greyAgg, redAgg); // Exported vCard shouldn't contain restricted phone @@ -217,7 +222,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testContactsLiveFolder() { - final long greyContact = mGrey.createContact(true, GENERIC_NAME); + final long greyContact = mGrey.createRawContact(true, GENERIC_NAME); final long greyPhone = mGrey.createPhone(greyContact, PHONE_GREY); // Protected contact should be omitted from live folder @@ -237,7 +242,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testRestrictedQueryParam() throws Exception { - final long greyContact = mGrey.createContact(true, GENERIC_NAME); + final long greyContact = mGrey.createRawContact(true, GENERIC_NAME); final long greyPhone = mGrey.createPhone(greyContact, PHONE_GREY); Uri greyUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, greyContact); @@ -269,7 +274,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testRestrictedEmailLookupRestricted() { - final long greyContact = mGrey.createContact(true, GENERIC_NAME); + final long greyContact = mGrey.createRawContact(true, GENERIC_NAME); final long greyEmail = mGrey.createEmail(greyContact, EMAIL_GREY); // Restricted caller should see protected data @@ -288,7 +293,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testRestrictedEmailLookupGeneric() { - final long greyContact = mGrey.createContact(true, GENERIC_NAME); + final long greyContact = mGrey.createRawContact(true, GENERIC_NAME); final long greyEmail = mGrey.createEmail(greyContact, EMAIL_GREY); // Generic caller should never see protected data @@ -307,7 +312,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testStatusRestrictedInsertRestrictedQuery() { - final long rawContactId = mGrey.createContactWithStatus(true, + final long rawContactId = mGrey.createRawContactWithStatus(true, GENERIC_NAME, EMAIL_GREY, GENERIC_STATUS); final long aggId = mGrey.getContactForRawContact(rawContactId); @@ -316,7 +321,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testStatusRestrictedInsertGenericQuery() { - final long rawContactId = mGrey.createContactWithStatus(true, + final long rawContactId = mGrey.createRawContactWithStatus(true, GENERIC_NAME, EMAIL_GREY, GENERIC_STATUS); final long aggId = mGrey.getContactForRawContact(rawContactId); @@ -325,7 +330,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testStatusGenericInsertRestrictedQuery() { - final long rawContactId = mRed.createContactWithStatus(false, + final long rawContactId = mRed.createRawContactWithStatus(false, GENERIC_NAME, EMAIL_RED, GENERIC_STATUS); final long aggId = mRed.getContactForRawContact(rawContactId); @@ -334,7 +339,7 @@ public class RestrictionExceptionsTest extends AndroidTestCase { } public void testStatusGenericInsertGenericQuery() { - final long rawContactId = mRed.createContactWithStatus(false, + final long rawContactId = mRed.createRawContactWithStatus(false, GENERIC_NAME, EMAIL_RED, GENERIC_STATUS); final long aggId = mRed.getContactForRawContact(rawContactId); |