Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2943)

Unified Diff: chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappRegistryTest.java

Issue 1329083002: Clear webapp storage when site data is cleared (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rework to use AsyncTask rather than IO thread Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappRegistryTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappRegistryTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappRegistryTest.java
index a903f58a38c2e9711b946acb5515f98888d52061..3e90d7551f203d15c49fd82d957e422b716d0a00 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappRegistryTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappRegistryTest.java
@@ -21,6 +21,7 @@ import org.robolectric.annotation.Config;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
/**
@@ -82,13 +83,7 @@ public class WebappRegistryTest {
@Test
@Feature({"Webapp"})
public void testWebappIdsRetrieval() throws Exception {
- final Set<String> expected = new HashSet<String>();
- expected.add("first");
- expected.add("second");
-
- mSharedPreferences.edit()
- .putStringSet(WebappRegistry.KEY_WEBAPP_SET, expected)
- .commit();
+ final Set<String> expected = addWebappsToRegistry("first", "second");
WebappRegistry.getRegisteredWebappIds(Robolectric.application,
new WebappRegistry.FetchCallback() {
@@ -107,12 +102,7 @@ public class WebappRegistryTest {
@Test
@Feature({"Webapp"})
public void testWebappIdsRetrievalRegisterRetrival() throws Exception {
- final Set<String> expected = new HashSet<String>();
- expected.add("first");
-
- mSharedPreferences.edit()
- .putStringSet(WebappRegistry.KEY_WEBAPP_SET, expected)
- .commit();
+ final Set<String> expected = addWebappsToRegistry("first");
WebappRegistry.getRegisteredWebappIds(Robolectric.application,
new WebappRegistry.FetchCallback() {
@@ -149,4 +139,42 @@ public class WebappRegistryTest {
assertTrue(mCallbackCalled);
}
+
+ @Test
+ @Feature({"Webapp"})
+ public void testUnregisterClearsRegistry() throws Exception {
+ addWebappsToRegistry("test");
+
+ WebappRegistry.unregisterAllWebapps(Robolectric.application);
+ BackgroundShadowAsyncTask.runBackgroundTasks();
+
+ assertTrue(getRegisteredWebapps().isEmpty());
+ }
+
+ @Test
+ @Feature({"Webapp"})
+ public void testUnregisterClearsWebappDataStorage() throws Exception {
+ addWebappsToRegistry("test");
+
gone 2015/09/09 23:30:40 You should actually check if the file exists befor
Lalit Maganti 2015/09/10 09:41:57 Yeah this test is sort of broken. Fixed.
+ WebappRegistry.unregisterAllWebapps(Robolectric.application);
+ BackgroundShadowAsyncTask.runBackgroundTasks();
+
+ SharedPreferences webAppPrefs = Robolectric.application.getSharedPreferences(
+ WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "test", Context.MODE_PRIVATE);
+ Map<String, ?> actual = webAppPrefs.getAll();
+ assertTrue(actual.isEmpty());
+ }
+
+ private Set<String> addWebappsToRegistry(String... webapps) {
+ final Set<String> expected = new HashSet<String>(Arrays.asList(webapps));
+ mSharedPreferences.edit()
+ .putStringSet(WebappRegistry.KEY_WEBAPP_SET, expected)
+ .commit();
+ return expected;
+ }
+
+ private Set<String> getRegisteredWebapps() {
+ return mSharedPreferences.getStringSet(
+ WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet());
+ }
}

Powered by Google App Engine
This is Rietveld 408576698