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

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

Issue 2122813002: Revert of Use metadata when launching WebAPKs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappInfoTest.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 assertTrue(actual.isEmpty()); 343 assertTrue(actual.isEmpty());
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
354 @Feature({"WebApk"})
355 public void testCleanupRemovesUninstalledWebApks() throws Exception {
356 String webappId1 = "webapk:uninstalledWebApk1";
357 String webApkPackage1 = "uninstalledWebApk1";
358 String webappId2 = "webapk:uninstalledWebApk2";
359 String webApkPackage2 = "uninstalledWebApk2";
360
361 FetchStorageCallback storageCallback1 = new FetchStorageCallback(
362 createWebApkIntent(webappId1, webApkPackage1));
363 WebappRegistry.registerWebapp(Robolectric.application, webappId1, storag eCallback1);
364 BackgroundShadowAsyncTask.runBackgroundTasks();
365 Robolectric.runUiThreadTasks();
366 assertTrue(storageCallback1.getCallbackCalled());
367
368 FetchStorageCallback storageCallback2 = new FetchStorageCallback(
369 createWebApkIntent(webappId1, webApkPackage2));
370 WebappRegistry.registerWebapp(Robolectric.application, webappId2, storag eCallback2);
371 BackgroundShadowAsyncTask.runBackgroundTasks();
372 Robolectric.runUiThreadTasks();
373 assertTrue(storageCallback2.getCallbackCalled());
374
375 // Verify that both WebAPKs are registered.
376 Set<String> actual = mSharedPreferences.getStringSet(
377 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet());
378 assertEquals(2, actual.size());
379 assertTrue(actual.contains(webappId1));
380 assertTrue(actual.contains(webappId2));
381
382 // Set the current time such that the task runs.
383 long currentTime = System.currentTimeMillis() + WebappRegistry.FULL_CLEA NUP_DURATION;
384 // Because the time is just inside the window, there should be a cleanup of
385 // uninstalled WebAPKs and the last cleaned up time should be set to the
386 // current time.
387 WebappRegistry.unregisterOldWebapps(Robolectric.application, currentTime );
388 BackgroundShadowAsyncTask.runBackgroundTasks();
389 Robolectric.runUiThreadTasks();
390
391 actual = mSharedPreferences.getStringSet(
392 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet());
393 assertTrue(actual.isEmpty());
394
395 long lastCleanup = mSharedPreferences.getLong(
396 WebappRegistry.KEY_LAST_CLEANUP, -1);
397 assertEquals(currentTime, lastCleanup);
398 }
399
400 @Test
401 @Feature({"WebApk"})
402 public void testCleanupDoesNotRemoveInstalledWebApks() throws Exception {
403 String webappId = "webapk:installedWebApk";
404 String webApkPackage = "installedWebApk";
405 String uninstalledWebappId = "webapk:uninstalledWebApk";
406 String uninstalledWebApkPackage = "uninstalledWebApk";
407
408 FetchStorageCallback storageCallback = new FetchStorageCallback(
409 createWebApkIntent(webappId, webApkPackage));
410 WebappRegistry.registerWebapp(Robolectric.application, webappId, storage Callback);
411 BackgroundShadowAsyncTask.runBackgroundTasks();
412 Robolectric.runUiThreadTasks();
413 assertTrue(storageCallback.getCallbackCalled());
414
415 FetchStorageCallback storageCallback2 = new FetchStorageCallback(
416 createWebApkIntent(uninstalledWebappId, uninstalledWebApkPackage ));
417 WebappRegistry.registerWebapp(Robolectric.application, uninstalledWebapp Id,
418 storageCallback2);
419 BackgroundShadowAsyncTask.runBackgroundTasks();
420 Robolectric.runUiThreadTasks();
421 assertTrue(storageCallback2.getCallbackCalled());
422
423 // Verify that both WebAPKs are registered.
424 Set<String> actual = mSharedPreferences.getStringSet(
425 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet());
426 assertEquals(2, actual.size());
427 assertTrue(actual.contains(webappId));
428 assertTrue(actual.contains(uninstalledWebappId));
429
430 Robolectric.packageManager.addPackage(webApkPackage);
431
432 // Set the current time such that the task runs.
433 long currentTime = System.currentTimeMillis() + WebappRegistry.FULL_CLEA NUP_DURATION;
434 // Because the time is just inside the window, there should be a cleanup of
435 // uninstalled WebAPKs and the last cleaned up time should be set to the
436 // current time.
437 WebappRegistry.unregisterOldWebapps(Robolectric.application, currentTime );
438 BackgroundShadowAsyncTask.runBackgroundTasks();
439 Robolectric.runUiThreadTasks();
440
441 actual = mSharedPreferences.getStringSet(
442 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet());
443 assertEquals(1, actual.size());
444 assertTrue(actual.contains(webappId));
445
446 long lastCleanup = mSharedPreferences.getLong(
447 WebappRegistry.KEY_LAST_CLEANUP, -1);
448 assertEquals(currentTime, lastCleanup);
449 }
450
451 @Test 353 @Test
452 @Feature({"Webapp"}) 354 @Feature({"Webapp"})
453 public void testClearWebappHistoryRunsCallback() throws Exception { 355 public void testClearWebappHistoryRunsCallback() throws Exception {
454 CallbackRunner callback = new CallbackRunner(); 356 CallbackRunner callback = new CallbackRunner();
455 WebappRegistry.clearWebappHistory(Robolectric.application, callback); 357 WebappRegistry.clearWebappHistory(Robolectric.application, callback);
456 BackgroundShadowAsyncTask.runBackgroundTasks(); 358 BackgroundShadowAsyncTask.runBackgroundTasks();
457 Robolectric.runUiThreadTasks(); 359 Robolectric.runUiThreadTasks();
458 360
459 assertTrue(callback.getCallbackCalled()); 361 assertTrue(callback.getCallbackCalled());
460 } 362 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 private Set<String> getRegisteredWebapps() { 599 private Set<String> getRegisteredWebapps() {
698 return mSharedPreferences.getStringSet( 600 return mSharedPreferences.getStringSet(
699 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); 601 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet());
700 } 602 }
701 603
702 private Intent createShortcutIntent(String url) { 604 private Intent createShortcutIntent(String url) {
703 return ShortcutHelper.createWebappShortcutIntent("id", "action", url, 605 return ShortcutHelper.createWebappShortcutIntent("id", "action", url,
704 ShortcutHelper.getScopeFromUrl(url), "name", "shortName", null, 606 ShortcutHelper.getScopeFromUrl(url), "name", "shortName", null,
705 ShortcutHelper.WEBAPP_SHORTCUT_VERSION, WebDisplayMode.Standalon e, 0, 0, 0, false); 607 ShortcutHelper.WEBAPP_SHORTCUT_VERSION, WebDisplayMode.Standalon e, 0, 0, 0, false);
706 } 608 }
707
708 private Intent createWebApkIntent(String webappId, String webApkPackage) {
709 Intent intent = new Intent();
710 intent.putExtra(ShortcutHelper.EXTRA_ID, webappId)
711 .putExtra(ShortcutHelper.EXTRA_URL, "https://foo.com")
712 .putExtra(ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackage) ;
713 return intent;
714 }
715 } 609 }
OLDNEW
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappInfoTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698