diff options
author | Makoto Onuki <omakoto@google.com> | 2015-05-15 13:44:20 -0700 |
---|---|---|
committer | Makoto Onuki <omakoto@google.com> | 2015-05-15 14:46:27 -0700 |
commit | c19d5519535bc05225eac5f7dfb830fda48497de (patch) | |
tree | ef5a4c9bc17cc0920dad9c62f5c9e389635fb6a5 /tests | |
parent | 2d66b50b00603e1b54da45aa1129e6bc659fd46d (diff) | |
download | packages_providers_ContactsProvider-c19d5519535bc05225eac5f7dfb830fda48497de.zip packages_providers_ContactsProvider-c19d5519535bc05225eac5f7dfb830fda48497de.tar.gz packages_providers_ContactsProvider-c19d5519535bc05225eac5f7dfb830fda48497de.tar.bz2 |
Fix unit tests
- PhotoPriorityResolverTest
Now the mock sync adapter needs an intent filter
- LegacyContactsProviderTest
The authority check in ContentProvider got tightened, which broke our test because
we didn't set up the multiple authorities correctly.
Change-Id: Iab1eed24434bd159a99f0b794a7756554dc02281
Diffstat (limited to 'tests')
6 files changed, 39 insertions, 11 deletions
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml index e08429a..15a90fa 100644 --- a/tests/AndroidManifest.xml +++ b/tests/AndroidManifest.xml @@ -26,6 +26,11 @@ <!-- Mock contacts sync adapter --> <service android:name=".MockSyncAdapter" android:exported="true"> + <intent-filter> + <action android:name="android.content.SyncAdapter" /> + </intent-filter> + <meta-data android:name="android.content.SyncAdapter" + android:resource="@xml/mock_syncadapter" /> <meta-data android:name="android.provider.CONTACTS_STRUCTURE" android:resource="@xml/contacts" /> </service> diff --git a/tests/res/xml/mock_syncadapter.xml b/tests/res/xml/mock_syncadapter.xml new file mode 100644 index 0000000..6f77a55 --- /dev/null +++ b/tests/res/xml/mock_syncadapter.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright (c) 2015, 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. + */ +--> +<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android" + android:contentAuthority="com.android.contacts" + android:accountType="com.android.providers.contacts.tests" +/> +<!-- The account type doesn't exist, but looks like that's okay for our purpose. --> + diff --git a/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java b/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java index 3778380..45206a3 100644 --- a/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java @@ -153,10 +153,6 @@ public abstract class BaseContactsProvider2Test extends PhotoLoadingTestCase { return mActor.context; } - public void addAuthority(String authority) { - mActor.addAuthority(authority); - } - public ContentProvider addProvider(Class<? extends ContentProvider> providerClass, String authority) throws Exception { return mActor.addProvider(providerClass, authority); diff --git a/tests/src/com/android/providers/contacts/ContactsActor.java b/tests/src/com/android/providers/contacts/ContactsActor.java index 3ff4086..0b91d4c 100644 --- a/tests/src/com/android/providers/contacts/ContactsActor.java +++ b/tests/src/com/android/providers/contacts/ContactsActor.java @@ -328,10 +328,6 @@ public class ContactsActor { return mProviderContext; } - public void addAuthority(String authority) { - resolver.addProvider(authority, provider); - } - public <T extends ContentProvider> T addProvider(Class<T> providerClass, String authority) throws Exception { return addProvider(providerClass, authority, mProviderContext); @@ -347,6 +343,12 @@ public class ContactsActor { info.authority = stripOutUserIdFromAuthority(authority); provider.attachInfoForTesting(providerContext, info); resolver.addProvider(authority, provider); + + // In case of LegacyTest, "authority" here is actually multiple authorities. + // Register all authority here. + for (String a : authority.split(";")) { + resolver.addProvider(a, provider); + } return provider; } diff --git a/tests/src/com/android/providers/contacts/LegacyContactsProviderTest.java b/tests/src/com/android/providers/contacts/LegacyContactsProviderTest.java index 6697ea6..378c9eb 100644 --- a/tests/src/com/android/providers/contacts/LegacyContactsProviderTest.java +++ b/tests/src/com/android/providers/contacts/LegacyContactsProviderTest.java @@ -61,7 +61,7 @@ public class LegacyContactsProviderTest extends BaseContactsProvider2Test { @Override protected String getAuthority() { - return Contacts.AUTHORITY; + return Contacts.AUTHORITY + ";" + ContactsContract.AUTHORITY; } public void testPeopleInsert() { @@ -857,8 +857,6 @@ public class LegacyContactsProviderTest extends BaseContactsProvider2Test { } public void testSettings() throws Exception { - mActor.addAuthority(ContactsContract.AUTHORITY); - ContentValues values = new ContentValues(); values.put(Settings._SYNC_ACCOUNT, "foo"); values.put(Settings._SYNC_ACCOUNT_TYPE, "bar"); diff --git a/tests/src/com/android/providers/contacts/MockSyncAdapter.java b/tests/src/com/android/providers/contacts/MockSyncAdapter.java index 9255d28..199c216 100644 --- a/tests/src/com/android/providers/contacts/MockSyncAdapter.java +++ b/tests/src/com/android/providers/contacts/MockSyncAdapter.java @@ -27,6 +27,9 @@ public class MockSyncAdapter extends Service { @Override public IBinder onBind(Intent intent) { + // Looks like returning null is okay here, probably because the account type doesn't exist. + // If the system complains about it, we need to return a real sync adapter class here, + // and in the syncMethod -1 to isSyncable. return null; } } |