Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.webapps; | 5 package org.chromium.chrome.browser.webapps; |
| 6 | 6 |
| 7 import static org.junit.Assert.assertEquals; | 7 import static org.junit.Assert.assertEquals; |
| 8 import static org.junit.Assert.assertTrue; | 8 import static org.junit.Assert.assertTrue; |
| 9 | 9 |
| 10 import android.content.Context; | 10 import android.content.Context; |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 | 344 |
| 345 long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USE D, | 345 long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USE D, |
| 346 WebappDataStorage.LAST_USED_INVALID); | 346 WebappDataStorage.LAST_USED_INVALID); |
| 347 assertEquals(WebappDataStorage.LAST_USED_INVALID, actualLastUsed); | 347 assertEquals(WebappDataStorage.LAST_USED_INVALID, actualLastUsed); |
| 348 | 348 |
| 349 long lastCleanup = mSharedPreferences.getLong(WebappRegistry.KEY_LAST_CL EANUP, -1); | 349 long lastCleanup = mSharedPreferences.getLong(WebappRegistry.KEY_LAST_CL EANUP, -1); |
| 350 assertEquals(currentTime, lastCleanup); | 350 assertEquals(currentTime, lastCleanup); |
| 351 } | 351 } |
| 352 | 352 |
| 353 @Test | 353 @Test |
| 354 @Feature({"WebApk"}) | |
| 355 public void testCleanupRemovesUninstalledWebApks() throws Exception { | |
| 356 String webappId = "webapk:uninstalledWebApk"; | |
| 357 String webApkPackage = "uninstalledWebApk"; | |
| 358 FetchStorageCallback storageCallback = new FetchStorageCallback( | |
| 359 createWebApkIntent(webappId, webApkPackage)); | |
| 360 WebappRegistry.registerWebapp(Robolectric.application, webappId, storage Callback); | |
| 361 BackgroundShadowAsyncTask.runBackgroundTasks(); | |
| 362 Robolectric.runUiThreadTasks(); | |
| 363 assertTrue(storageCallback.getCallbackCalled()); | |
| 364 | |
| 365 // 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.
| |
| 366 long currentTime = System.currentTimeMillis() + WebappRegistry.FULL_CLEA NUP_DURATION; | |
| 367 // Because the time is just inside the window, there should be a cleanup of | |
| 368 // uninstalled WebAPKs and the last cleaned up time should be set to the | |
| 369 // current time. | |
| 370 WebappRegistry.unregisterOldWebapps(Robolectric.application, currentTime ); | |
| 371 BackgroundShadowAsyncTask.runBackgroundTasks(); | |
| 372 Robolectric.runUiThreadTasks(); | |
| 373 | |
| 374 Set<String> actual = mSharedPreferences.getStringSet( | |
| 375 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | |
| 376 assertTrue(actual.isEmpty()); | |
| 377 | |
| 378 long lastCleanup = mSharedPreferences.getLong( | |
| 379 WebappRegistry.KEY_LAST_CLEANUP, -1); | |
| 380 assertEquals(currentTime, lastCleanup); | |
| 381 } | |
| 382 | |
| 383 @Test | |
| 384 @Feature({"WebApk"}) | |
| 385 public void testCleanupDoNotRemovesInstalledWebApks() throws Exception { | |
| 386 String webappId = "webapk:installedWebApk"; | |
| 387 String webApkPackage = "installedWebApk"; | |
| 388 FetchStorageCallback storageCallback = new FetchStorageCallback( | |
| 389 createWebApkIntent(webappId, webApkPackage)); | |
| 390 WebappRegistry.registerWebapp(Robolectric.application, webappId, storage Callback); | |
| 391 BackgroundShadowAsyncTask.runBackgroundTasks(); | |
| 392 Robolectric.runUiThreadTasks(); | |
| 393 assertTrue(storageCallback.getCallbackCalled()); | |
| 394 | |
| 395 Robolectric.packageManager.addPackage(webApkPackage); | |
| 396 | |
| 397 // 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.
| |
| 398 long currentTime = System.currentTimeMillis() + WebappRegistry.FULL_CLEA NUP_DURATION; | |
| 399 // Because the time is just inside the window, there should be a cleanup of | |
| 400 // uninstalled WebAPKs and the last cleaned up time should be set to the | |
| 401 // current time. | |
| 402 WebappRegistry.unregisterOldWebapps(Robolectric.application, currentTime ); | |
| 403 BackgroundShadowAsyncTask.runBackgroundTasks(); | |
| 404 Robolectric.runUiThreadTasks(); | |
| 405 | |
| 406 Set<String> actual = mSharedPreferences.getStringSet( | |
| 407 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | |
| 408 assertEquals(1, actual.size()); | |
| 409 assertTrue(actual.contains(webappId)); | |
| 410 | |
| 411 long lastCleanup = mSharedPreferences.getLong( | |
| 412 WebappRegistry.KEY_LAST_CLEANUP, -1); | |
| 413 assertEquals(currentTime, lastCleanup); | |
| 414 } | |
| 415 | |
| 416 @Test | |
| 354 @Feature({"Webapp"}) | 417 @Feature({"Webapp"}) |
| 355 public void testClearWebappHistoryRunsCallback() throws Exception { | 418 public void testClearWebappHistoryRunsCallback() throws Exception { |
| 356 CallbackRunner callback = new CallbackRunner(); | 419 CallbackRunner callback = new CallbackRunner(); |
| 357 WebappRegistry.clearWebappHistory(Robolectric.application, callback); | 420 WebappRegistry.clearWebappHistory(Robolectric.application, callback); |
| 358 BackgroundShadowAsyncTask.runBackgroundTasks(); | 421 BackgroundShadowAsyncTask.runBackgroundTasks(); |
| 359 Robolectric.runUiThreadTasks(); | 422 Robolectric.runUiThreadTasks(); |
| 360 | 423 |
| 361 assertTrue(callback.getCallbackCalled()); | 424 assertTrue(callback.getCallbackCalled()); |
| 362 } | 425 } |
| 363 | 426 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 private Set<String> getRegisteredWebapps() { | 662 private Set<String> getRegisteredWebapps() { |
| 600 return mSharedPreferences.getStringSet( | 663 return mSharedPreferences.getStringSet( |
| 601 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | 664 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); |
| 602 } | 665 } |
| 603 | 666 |
| 604 private Intent createShortcutIntent(String url) { | 667 private Intent createShortcutIntent(String url) { |
| 605 return ShortcutHelper.createWebappShortcutIntent("id", "action", url, | 668 return ShortcutHelper.createWebappShortcutIntent("id", "action", url, |
| 606 ShortcutHelper.getScopeFromUrl(url), "name", "shortName", null, | 669 ShortcutHelper.getScopeFromUrl(url), "name", "shortName", null, |
| 607 ShortcutHelper.WEBAPP_SHORTCUT_VERSION, WebDisplayMode.Standalon e, 0, 0, 0, false); | 670 ShortcutHelper.WEBAPP_SHORTCUT_VERSION, WebDisplayMode.Standalon e, 0, 0, 0, false); |
| 608 } | 671 } |
| 672 | |
| 673 private Intent createWebApkIntent(String webappId, String webApkPackage) { | |
| 674 Intent intent = new Intent(); | |
| 675 intent.putExtra(ShortcutHelper.EXTRA_ID, webappId) | |
| 676 .putExtra(ShortcutHelper.EXTRA_URL, "https://foo.com") | |
| 677 .putExtra(ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackage) ; | |
| 678 return intent; | |
| 679 } | |
| 609 } | 680 } |
| OLD | NEW |