summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2015-05-20 13:05:17 -0700
committerYorke Lee <yorkelee@google.com>2015-06-04 13:11:48 -0700
commit47fc56dd40613fae565d0c4d630f5f0b5fc310ff (patch)
tree2e796fe141d5aa19a26e8cdda20e3349d43c496e /tests
parentcabd7cf832f5b160c30bff9c7b975bbf21a95d8e (diff)
downloadpackages_providers_ContactsProvider-47fc56dd40613fae565d0c4d630f5f0b5fc310ff.zip
packages_providers_ContactsProvider-47fc56dd40613fae565d0c4d630f5f0b5fc310ff.tar.gz
packages_providers_ContactsProvider-47fc56dd40613fae565d0c4d630f5f0b5fc310ff.tar.bz2
Fix broken CP2 unit tests and voicemail cleanup
* Delete voicemails when VoicemailCleanupService runs by checking whether delete is called internally. * Delete unnecessary MockPackageManager class, and consolidate all logic into ContactsMockPackageManager * Separate permissions tests and delete logic tests in VoicemailProviderTest * Correct the number of exposed Call columns in CallLogProviderTest Bug: 20669398 Change-Id: I695b82b639b93f3ce85bf6e20000279f19e4a14a
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/providers/contacts/BaseVoicemailProviderTest.java8
-rw-r--r--tests/src/com/android/providers/contacts/CallLogProviderTest.java4
-rw-r--r--tests/src/com/android/providers/contacts/ContactsMockPackageManager.java25
-rw-r--r--tests/src/com/android/providers/contacts/MockPackageManager.java59
-rw-r--r--tests/src/com/android/providers/contacts/VoicemailProviderTest.java42
5 files changed, 61 insertions, 77 deletions
diff --git a/tests/src/com/android/providers/contacts/BaseVoicemailProviderTest.java b/tests/src/com/android/providers/contacts/BaseVoicemailProviderTest.java
index 8e4121d..afb9980 100644
--- a/tests/src/com/android/providers/contacts/BaseVoicemailProviderTest.java
+++ b/tests/src/com/android/providers/contacts/BaseVoicemailProviderTest.java
@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.pm.PackageManager;
+import android.os.Process;
import android.provider.CallLog.Calls;
import android.provider.VoicemailContract;
@@ -37,12 +38,17 @@ public abstract class BaseVoicemailProviderTest extends BaseContactsProvider2Tes
protected boolean mUseSourceUri = false;
private File mTestDirectory;
+ ContactsMockPackageManager mPackageManager;
@Override
protected void setUp() throws Exception {
super.setUp();
addProvider(TestVoicemailProvider.class, VoicemailContract.AUTHORITY);
TestVoicemailProvider.setVvmProviderCallDelegate(createMockProviderCalls());
+
+ mPackageManager = (ContactsMockPackageManager) getProvider()
+ .getContext().getPackageManager();
+ mPackageManager.addPackage(Process.myUid(), mActor.packageName);
}
@Override
@@ -101,7 +107,7 @@ public abstract class BaseVoicemailProviderTest extends BaseContactsProvider2Tes
@Override
public PackageManager getPackageManager() {
- return new MockPackageManager(mActor.getProviderContext().getPackageName());
+ return mActor.getProviderContext().getPackageManager();
}
};
}
diff --git a/tests/src/com/android/providers/contacts/CallLogProviderTest.java b/tests/src/com/android/providers/contacts/CallLogProviderTest.java
index ea436d8..32e0988 100644
--- a/tests/src/com/android/providers/contacts/CallLogProviderTest.java
+++ b/tests/src/com/android/providers/contacts/CallLogProviderTest.java
@@ -64,7 +64,7 @@ public class CallLogProviderTest extends BaseContactsProvider2Test {
Voicemails.DIRTY,
Voicemails.DELETED};
/** Total number of columns exposed by call_log provider. */
- private static final int NUM_CALLLOG_FIELDS = 25;
+ private static final int NUM_CALLLOG_FIELDS = 26;
private CallLogProvider mCallLogProvider;
@@ -481,7 +481,7 @@ public class CallLogProviderTest extends BaseContactsProvider2Test {
return new ContextWrapper(super.context()) {
@Override
public PackageManager getPackageManager() {
- return new MockPackageManager("com.test.package1", "com.test.package2");
+ return super.getPackageManager();
}
@Override
diff --git a/tests/src/com/android/providers/contacts/ContactsMockPackageManager.java b/tests/src/com/android/providers/contacts/ContactsMockPackageManager.java
index a5aa7c7..1f3f52e 100644
--- a/tests/src/com/android/providers/contacts/ContactsMockPackageManager.java
+++ b/tests/src/com/android/providers/contacts/ContactsMockPackageManager.java
@@ -16,16 +16,16 @@
package com.android.providers.contacts;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
-import android.content.pm.ProviderInfo;
+import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.os.Binder;
import android.test.mock.MockPackageManager;
-import com.google.android.collect.Lists;
-
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -51,6 +51,13 @@ public class ContactsMockPackageManager extends MockPackageManager {
mReverse.put(packageName, packageUid);
}
+ public void removePackage(int packageUid) {
+ final String packageName = mForward.remove(packageUid);
+ if (packageName != null) {
+ mReverse.remove(packageName);
+ }
+ }
+
@Override
public String getNameForUid(int uid) {
return "name-for-uid";
@@ -58,10 +65,13 @@ public class ContactsMockPackageManager extends MockPackageManager {
@Override
public String[] getPackagesForUid(int uid) {
- if (mPackages != null) {
+ final String packageName = mForward.get(uid);
+ if (packageName != null) {
+ return new String[] {packageName};
+ } else if (mPackages != null) {
return new String[] { mPackages.get(0).packageName };
} else {
- return new String[] { ContactsActor.sCallingPackage };
+ return new String[] {};
}
}
@@ -93,6 +103,11 @@ public class ContactsMockPackageManager extends MockPackageManager {
}
@Override
+ public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
+ return new ArrayList<ResolveInfo>();
+ }
+
+ @Override
public Resources getResourcesForApplication(String appPackageName) {
return new ContactsMockResources();
}
diff --git a/tests/src/com/android/providers/contacts/MockPackageManager.java b/tests/src/com/android/providers/contacts/MockPackageManager.java
deleted file mode 100644
index 7c2d4df..0000000
--- a/tests/src/com/android/providers/contacts/MockPackageManager.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2011 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
- */
-
-package com.android.providers.contacts;
-
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.ResolveInfo;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class MockPackageManager extends android.test.mock.MockPackageManager {
- private final String[] mPackages;
- public MockPackageManager(String... packages) {
- mPackages = packages;
- }
-
- @Override
- public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
- List<ResolveInfo> resolveInfos = new ArrayList<ResolveInfo>();
- for (String pkg : mPackages) {
- resolveInfos.add(createResolveInfo(pkg));
- }
- return resolveInfos;
- }
-
- private ResolveInfo createResolveInfo(String packageName) {
- ActivityInfo activityInfo = new ActivityInfo();
- activityInfo.packageName = packageName;
- activityInfo.name = "FooClass";
- ResolveInfo resolveInfo = new ResolveInfo();
- resolveInfo.activityInfo = activityInfo;
- return resolveInfo;
- }
-
- @Override
- public String[] getPackagesForUid(int uid) {
- return new String[] {mPackages[0]};
- }
-
- @Override
- public int checkPermission(String permName, String pkgName) {
- return PERMISSION_GRANTED;
- }
-}
diff --git a/tests/src/com/android/providers/contacts/VoicemailProviderTest.java b/tests/src/com/android/providers/contacts/VoicemailProviderTest.java
index 4f79837..dc4335c 100644
--- a/tests/src/com/android/providers/contacts/VoicemailProviderTest.java
+++ b/tests/src/com/android/providers/contacts/VoicemailProviderTest.java
@@ -21,6 +21,7 @@ import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
+import android.os.Process;
import android.provider.CallLog.Calls;
import android.provider.VoicemailContract;
import android.provider.VoicemailContract.Status;
@@ -144,6 +145,33 @@ public class VoicemailProviderTest extends BaseVoicemailProviderTest {
assertStoredValues(uri, newValues);
}
+ public void testDeleteOwnPackageVoicemail_DeletesRow() {
+ setUpForFullPermission();
+ final Uri ownVoicemail = insertVoicemail();
+ assertEquals(1, getCount(voicemailUri(), null, null));
+
+ mResolver.delete(ownVoicemail, null, null);
+
+ assertEquals(0, getCount(ownVoicemail, null, null));
+ }
+
+ public void testDeleteOtherPackageVoicemail_SetsDirtyStatus() {
+ setUpForFullPermission();
+ final Uri anotherVoicemail = insertVoicemailForSourcePackage("another-package");
+ assertEquals(1, getCount(voicemailUri(), null, null));
+
+ // Clear the mapping for our own UID so that this doesn't look like an internal transaction.
+ mPackageManager.removePackage(Process.myUid());
+ mResolver.delete(anotherVoicemail, null, null);
+
+ ContentValues values = getTestVoicemailValues();
+ values.put(Voicemails.DIRTY, "1");
+ values.put(Voicemails.DELETED, "1");
+
+ assertEquals(1, getCount(anotherVoicemail, null, null));
+ assertStoredValues(anotherVoicemail, values);
+ }
+
public void testDelete() {
Uri uri = insertVoicemail();
int count = mResolver.delete(voicemailUri(), Voicemails._ID + "="
@@ -265,9 +293,7 @@ public class VoicemailProviderTest extends BaseVoicemailProviderTest {
});
// If we have the manage voicemail permission, we should be able to both update voicemails
- // from all packages. However, when updating or deleting a voicemail from a different
- // package, the "dirty" flag must be set on updates and "dirty" and "delete" flags must be
- // set on deletion.
+ // from all packages.
setUpForNoPermission();
mActor.addPermissions(WRITE_VOICEMAIL_PERMISSION);
mResolver.update(anotherVoicemail, getTestVoicemailValues(), null, null);
@@ -280,15 +306,11 @@ public class VoicemailProviderTest extends BaseVoicemailProviderTest {
mResolver.delete(anotherVoicemail, null, null);
- // Now add the read voicemail permission temporarily to verify that the delete flag is set.
+ // Now add the read voicemail permission temporarily to verify that the voicemail is
+ // deleted.
mActor.addPermissions(READ_VOICEMAIL_PERMISSION);
- ContentValues values = getTestVoicemailValues();
- values.put(Voicemails.DIRTY, "1");
- values.put(Voicemails.DELETED, "1");
-
- assertEquals(1, getCount(anotherVoicemail, null, null));
- assertStoredValues(anotherVoicemail, values);
+ assertEquals(0, getCount(anotherVoicemail, null, null));
}
private Uri withSourcePackageParam(Uri uri) {