summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPeter Visontay <pvisontay@google.com>2011-01-28 12:13:29 +0000
committerPeter Visontay <pvisontay@google.com>2011-01-28 14:40:22 +0000
commit48ab62821a8486010822812e0f3fdb77e84385ff (patch)
tree92e9171684b7bed3048f0fe52ef4b7a7c8e5ee50 /tests
parentff17b687846cef0e48085d27d08e122eed60ca0b (diff)
downloadApplicationsProvider-48ab62821a8486010822812e0f3fdb77e84385ff.tar.gz
Only rank by launch count if called from global search.
Without this any application could use the provider to get information about user behavior. Change-Id: I8eb4bccc9e6a9886f5af194ac132da423e725ce9
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/providers/applications/ApplicationsProviderForTesting.java13
-rw-r--r--tests/src/com/android/providers/applications/ApplicationsProviderTest.java27
2 files changed, 38 insertions, 2 deletions
diff --git a/tests/src/com/android/providers/applications/ApplicationsProviderForTesting.java b/tests/src/com/android/providers/applications/ApplicationsProviderForTesting.java
index 0ecb6fb..ea91fd0 100644
--- a/tests/src/com/android/providers/applications/ApplicationsProviderForTesting.java
+++ b/tests/src/com/android/providers/applications/ApplicationsProviderForTesting.java
@@ -25,17 +25,28 @@ public class ApplicationsProviderForTesting extends ApplicationsProvider {
private PackageManager mMockPackageManager;
+ private boolean mCanRankByLaunchCount;
+
@Override
protected PackageManager getPackageManager() {
return mMockPackageManager;
}
protected void setMockPackageManager(PackageManager mockPackageManager) {
- this.mMockPackageManager = mockPackageManager;
+ mMockPackageManager = mockPackageManager;
}
@Override
protected void enforcePermissionForLaunchCountIncrease() {
// Tests are allowed to do this.
}
+
+ protected void setCanRankByLaunchCount(boolean canRankByLaunchCount) {
+ mCanRankByLaunchCount = canRankByLaunchCount;
+ }
+
+ @Override
+ protected boolean canRankByLaunchCount() {
+ return mCanRankByLaunchCount;
+ }
}
diff --git a/tests/src/com/android/providers/applications/ApplicationsProviderTest.java b/tests/src/com/android/providers/applications/ApplicationsProviderTest.java
index 5010096..9d07bb2 100644
--- a/tests/src/com/android/providers/applications/ApplicationsProviderTest.java
+++ b/tests/src/com/android/providers/applications/ApplicationsProviderTest.java
@@ -118,7 +118,9 @@ public class ApplicationsProviderTest extends ProviderTestCase2<ApplicationsProv
"Ebay", "Email", "Fakeapp");
}
- public void testSearch_appsAreRankedByLaunchCount() throws Exception {
+ public void testSearch_appsAreRankedByLaunchCount() {
+ mProvider.setCanRankByLaunchCount(true);
+
// Original ranking: A, B, C, D (alphabetic; all launch counts are 0
// by default).
increaseLaunchCount(new ComponentName("b", "b.BView"));
@@ -131,10 +133,32 @@ public class ApplicationsProviderTest extends ProviderTestCase2<ApplicationsProv
}
/**
+ * The ApplicationsProvider must only rank by launch count if the caller
+ * is a privileged application - ordering apps by launch count when asked
+ * by a regular application would leak information about user behavior.
+ */
+ public void testSearch_notAllowedToRankByLaunchCount() {
+ // Simulate non-privileged calling application.
+ mProvider.setCanRankByLaunchCount(false);
+
+ // Original ranking: A, B, C, D (alphabetic; all launch counts are 0
+ // by default).
+ increaseLaunchCount(new ComponentName("b", "b.BView"));
+ increaseLaunchCount(new ComponentName("d", "d.DView"));
+ increaseLaunchCount(new ComponentName("d", "d.DView"));
+
+ // Launch count information mustn't be leaked - ranking is still
+ // alphabetic.
+ testSearch("alphabetic", "AlphabeticA", "AlphabeticB", "AlphabeticC", "AlphabeticD");
+ }
+
+ /**
* Tests that the launch count values are persisted even if the
* ApplicationsProvider is restarted.
*/
public void testSearch_launchCountInformationIsPersistent() throws Exception {
+ mProvider.setCanRankByLaunchCount(true);
+
// Original ranking: A, B, C, D (alphabetic; all launch counts are 0
// by default).
increaseLaunchCount(new ComponentName("b", "b.BView"));
@@ -150,6 +174,7 @@ public class ApplicationsProviderTest extends ProviderTestCase2<ApplicationsProv
// to the same launch count information as the original provider instance.
// The new instance will use the same IsolatedContext as the previous one.
ApplicationsProviderForTesting newProviderInstance = createNewProvider(mProvider.getContext());
+ newProviderInstance.setCanRankByLaunchCount(true);
assertNotSame(newProviderInstance, mProvider);
// Override the previous provider with the new instance in the