diff options
author | Dmitri Plotnikov <dplotnikov@google.com> | 2010-08-10 15:07:32 -0700 |
---|---|---|
committer | Dmitri Plotnikov <dplotnikov@google.com> | 2010-08-10 15:07:32 -0700 |
commit | 09ae48b82b17e24016b14a1ab64706222ab1071f (patch) | |
tree | a156780c532c644a992f923ef09d85630ad0af1e /tests | |
parent | 2de8f38e6254921b4f1a012f3297d3e92ccdadf7 (diff) | |
download | packages_providers_ContactsProvider-09ae48b82b17e24016b14a1ab64706222ab1071f.zip packages_providers_ContactsProvider-09ae48b82b17e24016b14a1ab64706222ab1071f.tar.gz packages_providers_ContactsProvider-09ae48b82b17e24016b14a1ab64706222ab1071f.tar.bz2 |
Supplying a default projection to Directories
Change-Id: Ie0de59b99624252e4688113fcc6ff52ec75ac8e4
Diffstat (limited to 'tests')
3 files changed, 59 insertions, 18 deletions
diff --git a/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java b/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java index ee5da13..3f672e4 100644 --- a/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java @@ -18,6 +18,8 @@ package com.android.providers.contacts; import static com.android.providers.contacts.ContactsActor.PACKAGE_GREY; +import com.google.android.collect.Sets; + import android.accounts.Account; import android.content.ContentProvider; import android.content.ContentResolver; @@ -30,12 +32,6 @@ import android.database.Cursor; import android.net.Uri; import android.provider.ContactsContract; import android.provider.ContactsContract.AggregationExceptions; -import android.provider.ContactsContract.Contacts; -import android.provider.ContactsContract.Data; -import android.provider.ContactsContract.Groups; -import android.provider.ContactsContract.RawContacts; -import android.provider.ContactsContract.Settings; -import android.provider.ContactsContract.StatusUpdates; import android.provider.ContactsContract.CommonDataKinds.Email; import android.provider.ContactsContract.CommonDataKinds.GroupMembership; import android.provider.ContactsContract.CommonDataKinds.Im; @@ -45,7 +41,14 @@ import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.CommonDataKinds.Photo; import android.provider.ContactsContract.CommonDataKinds.StructuredName; import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; +import android.provider.ContactsContract.Contacts; +import android.provider.ContactsContract.Data; +import android.provider.ContactsContract.Groups; +import android.provider.ContactsContract.RawContacts; +import android.provider.ContactsContract.Settings; +import android.provider.ContactsContract.StatusUpdates; import android.test.AndroidTestCase; +import android.test.MoreAsserts; import android.test.mock.MockContentResolver; import android.util.Log; @@ -57,8 +60,8 @@ import java.util.Arrays; import java.util.Comparator; import java.util.Iterator; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; /** * A common superclass for {@link ContactsProvider2}-related tests. @@ -920,6 +923,14 @@ public abstract class BaseContactsProvider2Test extends AndroidTestCase { assertEquals(expected, ((SynchronousContactsProvider2)mActor.provider).isNetworkNotified()); } + protected void assertProjection(Uri uri, String[] expectedProjection) { + Cursor cursor = mResolver.query(uri, null, "0", null, null); + String[] actualProjection = cursor.getColumnNames(); + MoreAsserts.assertEquals("Incorrect projection for URI: " + uri, + Sets.newHashSet(expectedProjection), Sets.newHashSet(actualProjection)); + cursor.close(); + } + /** * A contact in the database, and the attributes used to create it. Construct using * {@link GoldenContactBuilder#build()}. diff --git a/tests/src/com/android/providers/contacts/ContactDirectoryManagerTest.java b/tests/src/com/android/providers/contacts/ContactDirectoryManagerTest.java index a608a4a..5880957 100644 --- a/tests/src/com/android/providers/contacts/ContactDirectoryManagerTest.java +++ b/tests/src/com/android/providers/contacts/ContactDirectoryManagerTest.java @@ -16,6 +16,7 @@ package com.android.providers.contacts; +import com.android.providers.contacts.ContactsDatabaseHelper.AggregationExceptionColumns; import com.google.android.collect.Lists; import android.accounts.Account; @@ -28,6 +29,7 @@ import android.database.MatrixCursor; import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract; +import android.provider.ContactsContract.AggregationExceptions; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Directory; import android.provider.ContactsContract.RawContacts; @@ -36,7 +38,10 @@ import android.test.suitebuilder.annotation.LargeTest; /** * Unit tests for {@link ContactDirectoryManager}. Run the test like this: - * <code>adb shell am instrument -e class com.android.providers.contacts.ContactsProvider2Test -w \ * com.android.providers.contacts.tests/android.test.InstrumentationTestRunner * </code> + * <code> + * adb shell am instrument -e class com.android.providers.contacts.ContactDirectoryManagerTest + * -w com.android.providers.contacts.tests/android.test.InstrumentationTestRunner + * </code> */ @LargeTest public class ContactDirectoryManagerTest extends BaseContactsProvider2Test { @@ -86,6 +91,9 @@ public class ContactDirectoryManagerTest extends BaseContactsProvider2Test { uri.getQueryParameter(RawContacts.ACCOUNT_TYPE), }); return cursor; + } else if (uri.toString().startsWith( + "content://" + mAuthority + "/aggregation_exceptions")) { + return new MatrixCursor(projection); } fail("Unexpected uri: " + uri); @@ -385,6 +393,38 @@ public class ContactDirectoryManagerTest extends BaseContactsProvider2Test { cursor.close(); } + public void testProjectionPopulated() throws Exception { + mPackageManager.setInstalledPackages( + Lists.newArrayList(createProviderPackage("test.package1", "authority1"))); + + MockContactDirectoryProvider provider1 = (MockContactDirectoryProvider) addProvider( + MockContactDirectoryProvider.class, "authority1"); + + MatrixCursor response1 = provider1.createResponseCursor(); + addDirectoryRow(response1, "account-name1", "account-type1", "display-name1", 1, + Directory.EXPORT_SUPPORT_NONE, Directory.SHORTCUT_SUPPORT_NONE); + + mDirectoryManager.scanAllPackages(); + + Cursor cursor = mResolver.query( + Directory.CONTENT_URI, new String[] { Directory._ID }, null, null, null); + cursor.moveToPosition(2); + long directoryId = cursor.getLong(0); + cursor.close(); + + Uri contentUri = AggregationExceptions.CONTENT_URI.buildUpon().appendQueryParameter( + ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId)).build(); + + // The request should be forwarded to TestProvider, which will return an empty cursor + // but the projection should be correctly populated by ContactProvider + assertProjection(contentUri, new String[]{ + AggregationExceptionColumns._ID, + AggregationExceptions.TYPE, + AggregationExceptions.RAW_CONTACT_ID1, + AggregationExceptions.RAW_CONTACT_ID2, + }); + } + protected PackageInfo createProviderPackage(String packageName, String authority) { PackageInfo providerPackage = new PackageInfo(); providerPackage.packageName = packageName; diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java index b5dc7a9..db1edf0 100644 --- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java @@ -20,7 +20,6 @@ import com.android.internal.util.ArrayUtils; import com.android.providers.contacts.ContactsDatabaseHelper.AggregationExceptionColumns; import com.android.providers.contacts.ContactsDatabaseHelper.PresenceColumns; import com.google.android.collect.Lists; -import com.google.android.collect.Sets; import android.accounts.Account; import android.content.ContentProviderOperation; @@ -31,7 +30,6 @@ import android.content.Entity; import android.content.EntityIterator; import android.content.res.AssetFileDescriptor; import android.database.Cursor; -import android.database.DatabaseUtils; import android.net.Uri; import android.provider.ContactsContract; import android.provider.ContactsContract.AggregationExceptions; @@ -572,14 +570,6 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { }); } - private void assertProjection(Uri uri, String[] expectedProjection) { - Cursor cursor = mResolver.query(uri, null, "0", null, null); - String[] actualProjection = cursor.getColumnNames(); - MoreAsserts.assertEquals("Incorrect projection for URI: " + uri, - Sets.newHashSet(expectedProjection), Sets.newHashSet(actualProjection)); - cursor.close(); - } - public void testRawContactsInsert() { ContentValues values = new ContentValues(); |