Chromium Code Reviews| 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 66f47e34cc3d94f3072e321ba40e986cb35eb3e3..20103780cd386bcf0a944db80e9e474d4e9bbfad 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 |
| @@ -351,6 +351,69 @@ public class WebappRegistryTest { |
| } |
| @Test |
| + @Feature({"WebApk"}) |
| + public void testCleanupRemovesUninstalledWebApks() throws Exception { |
| + String webappId = "webapk:uninstalledWebApk"; |
| + String webApkPackage = "uninstalledWebApk"; |
| + FetchStorageCallback storageCallback = new FetchStorageCallback( |
| + createWebApkIntent(webappId, webApkPackage)); |
| + WebappRegistry.registerWebapp(Robolectric.application, webappId, storageCallback); |
| + BackgroundShadowAsyncTask.runBackgroundTasks(); |
| + Robolectric.runUiThreadTasks(); |
| + assertTrue(storageCallback.getCallbackCalled()); |
| + |
| + // Put the current time such that the task runs. |
|
pkotwicz
2016/06/29 21:26:18
Nit: Put -> Set
Xi Han
2016/06/29 21:58:13
Done.
|
| + long currentTime = System.currentTimeMillis() + WebappRegistry.FULL_CLEANUP_DURATION; |
| + // Because the time is just inside the window, there should be a cleanup of |
| + // uninstalled WebAPKs and the last cleaned up time should be set to the |
| + // current time. |
| + WebappRegistry.unregisterOldWebapps(Robolectric.application, currentTime); |
| + BackgroundShadowAsyncTask.runBackgroundTasks(); |
| + Robolectric.runUiThreadTasks(); |
| + |
| + Set<String> actual = mSharedPreferences.getStringSet( |
| + WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); |
| + assertTrue(actual.isEmpty()); |
| + |
| + long lastCleanup = mSharedPreferences.getLong( |
| + WebappRegistry.KEY_LAST_CLEANUP, -1); |
| + assertEquals(currentTime, lastCleanup); |
| + } |
| + |
| + @Test |
| + @Feature({"WebApk"}) |
| + public void testCleanupDoNotRemovesInstalledWebApks() throws Exception { |
| + String webappId = "webapk:installedWebApk"; |
| + String webApkPackage = "installedWebApk"; |
| + FetchStorageCallback storageCallback = new FetchStorageCallback( |
| + createWebApkIntent(webappId, webApkPackage)); |
| + WebappRegistry.registerWebapp(Robolectric.application, webappId, storageCallback); |
| + BackgroundShadowAsyncTask.runBackgroundTasks(); |
| + Robolectric.runUiThreadTasks(); |
| + assertTrue(storageCallback.getCallbackCalled()); |
| + |
| + Robolectric.packageManager.addPackage(webApkPackage); |
| + |
| + // Put the current time such that the task runs. |
|
pkotwicz
2016/06/29 21:26:18
Nit: Put -> Set
Xi Han
2016/06/29 21:58:13
Done.
|
| + long currentTime = System.currentTimeMillis() + WebappRegistry.FULL_CLEANUP_DURATION; |
| + // Because the time is just inside the window, there should be a cleanup of |
| + // uninstalled WebAPKs and the last cleaned up time should be set to the |
| + // current time. |
| + WebappRegistry.unregisterOldWebapps(Robolectric.application, currentTime); |
| + BackgroundShadowAsyncTask.runBackgroundTasks(); |
| + Robolectric.runUiThreadTasks(); |
| + |
| + Set<String> actual = mSharedPreferences.getStringSet( |
| + WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); |
| + assertEquals(1, actual.size()); |
| + assertTrue(actual.contains(webappId)); |
| + |
| + long lastCleanup = mSharedPreferences.getLong( |
| + WebappRegistry.KEY_LAST_CLEANUP, -1); |
| + assertEquals(currentTime, lastCleanup); |
| + } |
| + |
| + @Test |
| @Feature({"Webapp"}) |
| public void testClearWebappHistoryRunsCallback() throws Exception { |
| CallbackRunner callback = new CallbackRunner(); |
| @@ -606,4 +669,12 @@ public class WebappRegistryTest { |
| ShortcutHelper.getScopeFromUrl(url), "name", "shortName", null, |
| ShortcutHelper.WEBAPP_SHORTCUT_VERSION, WebDisplayMode.Standalone, 0, 0, 0, false); |
| } |
| + |
| + private Intent createWebApkIntent(String webappId, String webApkPackage) { |
| + Intent intent = new Intent(); |
| + intent.putExtra(ShortcutHelper.EXTRA_ID, webappId) |
| + .putExtra(ShortcutHelper.EXTRA_URL, "https://foo.com") |
| + .putExtra(ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackage); |
| + return intent; |
| + } |
| } |