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

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

Issue 1359383002: webapps: Add cleanup task when opening up WebappActivity to clean old web apps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webapp-cleanup
Patch Set: Address review comments 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 073e24bcb7e0eacededf84b348b0c6670987dd01..e336c4ef3df7979ccfc8c02ce43ce943b63a84ab 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
@@ -184,6 +184,84 @@ public class WebappRegistryTest {
assertTrue(actual.isEmpty());
}
+ @Test
+ @Feature({"Webapp"})
+ public void testCleanupDoesNotRunTooOften() throws Exception {
+ addWebappsToRegistry("oldWebapp");
+ SharedPreferences webAppPrefs = Robolectric.application.getSharedPreferences(
+ WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "oldWebapp", Context.MODE_PRIVATE);
+ webAppPrefs.edit()
+ .putLong(WebappDataStorage.KEY_LAST_USED, Long.MIN_VALUE)
+ .commit();
+
+ // Time just before the task should run.
+ WebappRegistry.unregisterOldWebapps(Robolectric.application,
+ WebappRegistry.FULL_CLEANUP_DURATION - 1);
+ BackgroundShadowAsyncTask.runBackgroundTasks();
+
+ Set<String> actual = mSharedPreferences.getStringSet(
+ WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet());
+ assertEquals(new HashSet<String>(Arrays.asList("test")), actual);
gone 2015/09/24 12:45:10 teeeeeeeeeeeeeeeeest?
Lalit Maganti 2015/09/24 12:49:25 Done.
+
+ long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USED,
+ WebappDataStorage.INVALID_LAST_USED);
+ assertEquals(Long.MIN_VALUE, actualLastUsed);
+ }
+
+ @Test
+ @Feature({"Webapp"})
+ public void testCleanupDoesNotRemoveRecentApps() throws Exception {
+ long currentTime = WebappRegistry.FULL_CLEANUP_DURATION;
+
+ addWebappsToRegistry("recentWebapp");
+ SharedPreferences webAppPrefs = Robolectric.application.getSharedPreferences(
+ WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "recentWebapp", Context.MODE_PRIVATE);
+
+ // Put the last used time just inside the no-cleanup window.
+ long lastUsed = currentTime - WebappRegistry.WEBAPP_UNOPENED_CLEANUP_DURATION + 1;
+ webAppPrefs.edit()
+ .putLong(WebappDataStorage.KEY_LAST_USED, lastUsed)
+ .commit();
+
+ WebappRegistry.unregisterOldWebapps(Robolectric.application, currentTime);
+ BackgroundShadowAsyncTask.runBackgroundTasks();
+
+ Set<String> actual = mSharedPreferences.getStringSet(
+ WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet());
+ assertEquals(new HashSet<String>(Arrays.asList("test")), actual);
gone 2015/09/24 12:45:10 "test"?
Lalit Maganti 2015/09/24 12:49:25 Done.
+
+ long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USED,
+ WebappDataStorage.INVALID_LAST_USED);
+ assertEquals(lastUsed, actualLastUsed);
+ }
+
+ @Test
+ @Feature({"Webapp"})
+ public void testCleanupRemovesOldApps() throws Exception {
+ long currentTime = WebappRegistry.FULL_CLEANUP_DURATION;
+
+ addWebappsToRegistry("oldWebapp");
+ SharedPreferences webAppPrefs = Robolectric.application.getSharedPreferences(
+ WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "oldWebapp", Context.MODE_PRIVATE);
+
+ // Put the last used time just outside the no-cleanup window.
+ long lastUsed = currentTime - WebappRegistry.WEBAPP_UNOPENED_CLEANUP_DURATION;
gone 2015/09/24 12:45:10 any reason why this doesn't +1 but the one above d
Lalit Maganti 2015/09/24 12:49:25 The one above is just outside the cleanup window a
+ webAppPrefs.edit()
+ .putLong(WebappDataStorage.KEY_LAST_USED, lastUsed)
+ .commit();
+
+ WebappRegistry.unregisterOldWebapps(Robolectric.application, currentTime);
+ BackgroundShadowAsyncTask.runBackgroundTasks();
+
+ Set<String> actual = mSharedPreferences.getStringSet(
+ WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet());
+ assertTrue(actual.isEmpty());
+
+ long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USED,
+ WebappDataStorage.INVALID_LAST_USED);
+ assertEquals(WebappDataStorage.INVALID_LAST_USED, actualLastUsed);
+ }
+
private Set<String> addWebappsToRegistry(String... webapps) {
final Set<String> expected = new HashSet<String>(Arrays.asList(webapps));
mSharedPreferences.edit()

Powered by Google App Engine
This is Rietveld 408576698