| 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; |
| 11 import android.content.Intent; | 11 import android.content.Intent; |
| 12 import android.content.SharedPreferences; | 12 import android.content.SharedPreferences; |
| 13 import android.os.AsyncTask; | 13 import android.os.AsyncTask; |
| 14 import android.text.TextUtils; | 14 import android.text.TextUtils; |
| 15 | 15 |
| 16 import org.junit.After; | 16 import org.junit.After; |
| 17 import org.junit.Before; | 17 import org.junit.Before; |
| 18 import org.junit.Test; | 18 import org.junit.Test; |
| 19 import org.junit.runner.RunWith; | 19 import org.junit.runner.RunWith; |
| 20 | |
| 21 import org.robolectric.RuntimeEnvironment; | 20 import org.robolectric.RuntimeEnvironment; |
| 22 import org.robolectric.annotation.Config; | 21 import org.robolectric.annotation.Config; |
| 23 import org.robolectric.shadows.ShadowLooper; | 22 import org.robolectric.shadows.ShadowLooper; |
| 24 | 23 |
| 25 import org.chromium.base.ContextUtils; | 24 import org.chromium.base.ContextUtils; |
| 26 import org.chromium.base.test.util.Feature; | 25 import org.chromium.base.test.util.Feature; |
| 27 import org.chromium.chrome.browser.ShortcutHelper; | 26 import org.chromium.chrome.browser.ShortcutHelper; |
| 28 import org.chromium.chrome.browser.browsing_data.UrlFilters; | 27 import org.chromium.chrome.browser.browsing_data.UrlFilters; |
| 29 import org.chromium.testing.local.BackgroundShadowAsyncTask; | 28 import org.chromium.testing.local.BackgroundShadowAsyncTask; |
| 30 import org.chromium.testing.local.LocalRobolectricTestRunner; | 29 import org.chromium.testing.local.LocalRobolectricTestRunner; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 119 } |
| 121 | 120 |
| 122 @Test | 121 @Test |
| 123 @Feature({"Webapp"}) | 122 @Feature({"Webapp"}) |
| 124 public void testWebappRegistrationUpdatesLastUsed() throws Exception { | 123 public void testWebappRegistrationUpdatesLastUsed() throws Exception { |
| 125 registerWebapp("test", null); | 124 registerWebapp("test", null); |
| 126 | 125 |
| 127 long after = System.currentTimeMillis(); | 126 long after = System.currentTimeMillis(); |
| 128 SharedPreferences webAppPrefs = ContextUtils.getApplicationContext().get
SharedPreferences( | 127 SharedPreferences webAppPrefs = ContextUtils.getApplicationContext().get
SharedPreferences( |
| 129 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "test", Context.MOD
E_PRIVATE); | 128 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "test", Context.MOD
E_PRIVATE); |
| 130 long actual = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USED, | 129 long actual = webAppPrefs.getLong( |
| 131 WebappDataStorage.LAST_USED_INVALID); | 130 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.TIMESTAMP_INV
ALID); |
| 132 assertTrue("Timestamp is out of range", actual <= after); | 131 assertTrue("Timestamp is out of range", actual <= after); |
| 133 } | 132 } |
| 134 | 133 |
| 135 @Test | 134 @Test |
| 136 @Feature({"Webapp"}) | 135 @Feature({"Webapp"}) |
| 137 public void testWebappIdsRetrieval() throws Exception { | 136 public void testWebappIdsRetrieval() throws Exception { |
| 138 final Set<String> expected = addWebappsToRegistry("first", "second"); | 137 final Set<String> expected = addWebappsToRegistry("first", "second"); |
| 139 assertEquals(expected, WebappRegistry.getRegisteredWebappIdsForTesting()
); | 138 assertEquals(expected, WebappRegistry.getRegisteredWebappIdsForTesting()
); |
| 140 } | 139 } |
| 141 | 140 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "oldWebapp", Contex
t.MODE_PRIVATE); | 239 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "oldWebapp", Contex
t.MODE_PRIVATE); |
| 241 webAppPrefs.edit().putLong(WebappDataStorage.KEY_LAST_USED, Long.MIN_VAL
UE).apply(); | 240 webAppPrefs.edit().putLong(WebappDataStorage.KEY_LAST_USED, Long.MIN_VAL
UE).apply(); |
| 242 | 241 |
| 243 // Force a re-read of the preferences from disk. | 242 // Force a re-read of the preferences from disk. |
| 244 WebappRegistry.refreshSharedPrefsForTesting(); | 243 WebappRegistry.refreshSharedPrefsForTesting(); |
| 245 WebappRegistry.getInstance().unregisterOldWebapps(currentTime); | 244 WebappRegistry.getInstance().unregisterOldWebapps(currentTime); |
| 246 | 245 |
| 247 Set<String> actual = getRegisteredWebapps(); | 246 Set<String> actual = getRegisteredWebapps(); |
| 248 assertEquals(new HashSet<>(Arrays.asList("oldWebapp")), actual); | 247 assertEquals(new HashSet<>(Arrays.asList("oldWebapp")), actual); |
| 249 | 248 |
| 250 long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USE
D, | 249 long actualLastUsed = webAppPrefs.getLong( |
| 251 WebappDataStorage.LAST_USED_INVALID); | 250 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.TIMESTAMP_INV
ALID); |
| 252 assertEquals(Long.MIN_VALUE, actualLastUsed); | 251 assertEquals(Long.MIN_VALUE, actualLastUsed); |
| 253 | 252 |
| 254 // The last cleanup time was set to 0 in setUp() so check that this hasn
't changed. | 253 // The last cleanup time was set to 0 in setUp() so check that this hasn
't changed. |
| 255 long lastCleanup = mSharedPreferences.getLong(WebappRegistry.KEY_LAST_CL
EANUP, -1); | 254 long lastCleanup = mSharedPreferences.getLong(WebappRegistry.KEY_LAST_CL
EANUP, -1); |
| 256 assertEquals(INITIAL_TIME, lastCleanup); | 255 assertEquals(INITIAL_TIME, lastCleanup); |
| 257 } | 256 } |
| 258 | 257 |
| 259 @Test | 258 @Test |
| 260 @Feature({"Webapp"}) | 259 @Feature({"Webapp"}) |
| 261 public void testCleanupDoesNotRemoveRecentApps() throws Exception { | 260 public void testCleanupDoesNotRemoveRecentApps() throws Exception { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 273 WebappRegistry.refreshSharedPrefsForTesting(); | 272 WebappRegistry.refreshSharedPrefsForTesting(); |
| 274 | 273 |
| 275 // Because the time is just inside the window, there should be a cleanup
but the web app | 274 // Because the time is just inside the window, there should be a cleanup
but the web app |
| 276 // should not be deleted as it was used recently. The last cleanup time
should also be | 275 // should not be deleted as it was used recently. The last cleanup time
should also be |
| 277 // set to the current time. | 276 // set to the current time. |
| 278 WebappRegistry.getInstance().unregisterOldWebapps(currentTime); | 277 WebappRegistry.getInstance().unregisterOldWebapps(currentTime); |
| 279 | 278 |
| 280 Set<String> actual = getRegisteredWebapps(); | 279 Set<String> actual = getRegisteredWebapps(); |
| 281 assertEquals(new HashSet<>(Arrays.asList("recentWebapp")), actual); | 280 assertEquals(new HashSet<>(Arrays.asList("recentWebapp")), actual); |
| 282 | 281 |
| 283 long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USE
D, | 282 long actualLastUsed = webAppPrefs.getLong( |
| 284 WebappDataStorage.LAST_USED_INVALID); | 283 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.TIMESTAMP_INV
ALID); |
| 285 assertEquals(lastUsed, actualLastUsed); | 284 assertEquals(lastUsed, actualLastUsed); |
| 286 | 285 |
| 287 long lastCleanup = mSharedPreferences.getLong(WebappRegistry.KEY_LAST_CL
EANUP, -1); | 286 long lastCleanup = mSharedPreferences.getLong(WebappRegistry.KEY_LAST_CL
EANUP, -1); |
| 288 assertEquals(currentTime, lastCleanup); | 287 assertEquals(currentTime, lastCleanup); |
| 289 } | 288 } |
| 290 | 289 |
| 291 @Test | 290 @Test |
| 292 @Feature({"Webapp"}) | 291 @Feature({"Webapp"}) |
| 293 public void testCleanupRemovesOldApps() throws Exception { | 292 public void testCleanupRemovesOldApps() throws Exception { |
| 294 // Put the current time such that the task runs. | 293 // Put the current time such that the task runs. |
| 295 long currentTime = INITIAL_TIME + WebappRegistry.FULL_CLEANUP_DURATION; | 294 long currentTime = INITIAL_TIME + WebappRegistry.FULL_CLEANUP_DURATION; |
| 296 | 295 |
| 297 // Put the last used time just outside the no-cleanup window. | 296 // Put the last used time just outside the no-cleanup window. |
| 298 addWebappsToRegistry("oldWebapp"); | 297 addWebappsToRegistry("oldWebapp"); |
| 299 SharedPreferences webAppPrefs = ContextUtils.getApplicationContext().get
SharedPreferences( | 298 SharedPreferences webAppPrefs = ContextUtils.getApplicationContext().get
SharedPreferences( |
| 300 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "oldWebapp", Contex
t.MODE_PRIVATE); | 299 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "oldWebapp", Contex
t.MODE_PRIVATE); |
| 301 long lastUsed = currentTime - WebappRegistry.WEBAPP_UNOPENED_CLEANUP_DUR
ATION; | 300 long lastUsed = currentTime - WebappRegistry.WEBAPP_UNOPENED_CLEANUP_DUR
ATION; |
| 302 webAppPrefs.edit().putLong(WebappDataStorage.KEY_LAST_USED, lastUsed).ap
ply(); | 301 webAppPrefs.edit().putLong(WebappDataStorage.KEY_LAST_USED, lastUsed).ap
ply(); |
| 303 | 302 |
| 304 // Force a re-read of the preferences from disk. | 303 // Force a re-read of the preferences from disk. |
| 305 WebappRegistry.refreshSharedPrefsForTesting(); | 304 WebappRegistry.refreshSharedPrefsForTesting(); |
| 306 | 305 |
| 307 // Because the time is just inside the window, there should be a cleanup
of old web apps and | 306 // Because the time is just inside the window, there should be a cleanup
of old web apps and |
| 308 // the last cleaned up time should be set to the current time. | 307 // the last cleaned up time should be set to the current time. |
| 309 WebappRegistry.getInstance().unregisterOldWebapps(currentTime); | 308 WebappRegistry.getInstance().unregisterOldWebapps(currentTime); |
| 310 | 309 |
| 311 Set<String> actual = getRegisteredWebapps(); | 310 Set<String> actual = getRegisteredWebapps(); |
| 312 assertTrue(actual.isEmpty()); | 311 assertTrue(actual.isEmpty()); |
| 313 | 312 |
| 314 long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USE
D, | 313 long actualLastUsed = webAppPrefs.getLong( |
| 315 WebappDataStorage.LAST_USED_INVALID); | 314 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.TIMESTAMP_INV
ALID); |
| 316 assertEquals(WebappDataStorage.LAST_USED_INVALID, actualLastUsed); | 315 assertEquals(WebappDataStorage.TIMESTAMP_INVALID, actualLastUsed); |
| 317 | 316 |
| 318 long lastCleanup = mSharedPreferences.getLong(WebappRegistry.KEY_LAST_CL
EANUP, -1); | 317 long lastCleanup = mSharedPreferences.getLong(WebappRegistry.KEY_LAST_CL
EANUP, -1); |
| 319 assertEquals(currentTime, lastCleanup); | 318 assertEquals(currentTime, lastCleanup); |
| 320 } | 319 } |
| 321 | 320 |
| 322 @Test | 321 @Test |
| 323 @Feature({"WebApk"}) | 322 @Feature({"WebApk"}) |
| 324 public void testCleanupRemovesUninstalledWebApks() throws Exception { | 323 public void testCleanupRemovesUninstalledWebApks() throws Exception { |
| 325 String webappId1 = "webapk:uninstalledWebApk1"; | 324 String webappId1 = "webapk:uninstalledWebApk1"; |
| 326 String webApkPackage1 = "uninstalledWebApk1"; | 325 String webApkPackage1 = "uninstalledWebApk1"; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 FetchStorageCallback storageCallback2 = new FetchStorageCallback(shortcu
tIntent2); | 413 FetchStorageCallback storageCallback2 = new FetchStorageCallback(shortcu
tIntent2); |
| 415 registerWebapp("webapp2", storageCallback2); | 414 registerWebapp("webapp2", storageCallback2); |
| 416 assertTrue(storageCallback2.getCallbackCalled()); | 415 assertTrue(storageCallback2.getCallbackCalled()); |
| 417 | 416 |
| 418 SharedPreferences webapp1Prefs = ContextUtils.getApplicationContext().ge
tSharedPreferences( | 417 SharedPreferences webapp1Prefs = ContextUtils.getApplicationContext().ge
tSharedPreferences( |
| 419 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp1", Context.
MODE_PRIVATE); | 418 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp1", Context.
MODE_PRIVATE); |
| 420 SharedPreferences webapp2Prefs = ContextUtils.getApplicationContext().ge
tSharedPreferences( | 419 SharedPreferences webapp2Prefs = ContextUtils.getApplicationContext().ge
tSharedPreferences( |
| 421 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp2", Context.
MODE_PRIVATE); | 420 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp2", Context.
MODE_PRIVATE); |
| 422 | 421 |
| 423 long webapp1OriginalLastUsed = webapp2Prefs.getLong( | 422 long webapp1OriginalLastUsed = webapp2Prefs.getLong( |
| 424 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.LAST_USED_UNS
ET); | 423 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.TIMESTAMP_INV
ALID); |
| 425 long webapp2OriginalLastUsed = webapp2Prefs.getLong( | 424 long webapp2OriginalLastUsed = webapp2Prefs.getLong( |
| 426 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.LAST_USED_UNS
ET); | 425 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.TIMESTAMP_INV
ALID); |
| 427 assertTrue(webapp1OriginalLastUsed != WebappDataStorage.LAST_USED_UNSET)
; | 426 assertTrue(webapp1OriginalLastUsed != WebappDataStorage.TIMESTAMP_INVALI
D); |
| 428 assertTrue(webapp2OriginalLastUsed != WebappDataStorage.LAST_USED_UNSET)
; | 427 assertTrue(webapp2OriginalLastUsed != WebappDataStorage.TIMESTAMP_INVALI
D); |
| 429 | 428 |
| 430 // Clear data for |webapp1Url|. | 429 // Clear data for |webapp1Url|. |
| 431 WebappRegistry.getInstance().clearWebappHistoryForUrlsImpl( | 430 WebappRegistry.getInstance().clearWebappHistoryForUrlsImpl( |
| 432 new UrlFilters.OneUrl(webapp1Url)); | 431 new UrlFilters.OneUrl(webapp1Url)); |
| 433 | 432 |
| 434 Set<String> actual = getRegisteredWebapps(); | 433 Set<String> actual = getRegisteredWebapps(); |
| 435 assertEquals(2, actual.size()); | 434 assertEquals(2, actual.size()); |
| 436 assertTrue(actual.contains("webapp1")); | 435 assertTrue(actual.contains("webapp1")); |
| 437 assertTrue(actual.contains("webapp2")); | 436 assertTrue(actual.contains("webapp2")); |
| 438 | 437 |
| 439 // Verify that the last used time for the first web app is | 438 // Verify that the last used time for the first web app is |
| 440 // WebappDataStorage.LAST_USED_UNSET, while for the second one it's unch
anged. | 439 // WebappDataStorage.TIMESTAMP_INVALID, while for the second one it's un
changed. |
| 441 long actualLastUsed = webapp1Prefs.getLong( | 440 long actualLastUsed = webapp1Prefs.getLong( |
| 442 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.LAST_USED_UNS
ET); | 441 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.TIMESTAMP_INV
ALID); |
| 443 assertEquals(WebappDataStorage.LAST_USED_UNSET, actualLastUsed); | 442 assertEquals(WebappDataStorage.TIMESTAMP_INVALID, actualLastUsed); |
| 444 actualLastUsed = webapp2Prefs.getLong( | 443 actualLastUsed = webapp2Prefs.getLong( |
| 445 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.LAST_USED_UNS
ET); | 444 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.TIMESTAMP_INV
ALID); |
| 446 assertEquals(webapp2OriginalLastUsed, actualLastUsed); | 445 assertEquals(webapp2OriginalLastUsed, actualLastUsed); |
| 447 | 446 |
| 448 // Verify that the URL and scope for the first web app is WebappDataStor
age.URL_INVALID, | 447 // Verify that the URL and scope for the first web app is WebappDataStor
age.URL_INVALID, |
| 449 // while for the second one it's unchanged. | 448 // while for the second one it's unchanged. |
| 450 String actualScope = webapp1Prefs.getString( | 449 String actualScope = webapp1Prefs.getString( |
| 451 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); | 450 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); |
| 452 assertEquals(WebappDataStorage.URL_INVALID, actualScope); | 451 assertEquals(WebappDataStorage.URL_INVALID, actualScope); |
| 453 String actualUrl = webapp1Prefs.getString( | 452 String actualUrl = webapp1Prefs.getString( |
| 454 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID); | 453 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID); |
| 455 assertEquals(WebappDataStorage.URL_INVALID, actualUrl); | 454 assertEquals(WebappDataStorage.URL_INVALID, actualUrl); |
| 456 actualScope = webapp2Prefs.getString( | 455 actualScope = webapp2Prefs.getString( |
| 457 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); | 456 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); |
| 458 assertEquals(webapp2Url + "/", actualScope); | 457 assertEquals(webapp2Url + "/", actualScope); |
| 459 actualUrl = webapp2Prefs.getString( | 458 actualUrl = webapp2Prefs.getString( |
| 460 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID); | 459 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID); |
| 461 assertEquals(webapp2Url, actualUrl); | 460 assertEquals(webapp2Url, actualUrl); |
| 462 | 461 |
| 463 // Clear data for all urls. | 462 // Clear data for all urls. |
| 464 WebappRegistry.getInstance().clearWebappHistoryForUrlsImpl(new UrlFilter
s.AllUrls()); | 463 WebappRegistry.getInstance().clearWebappHistoryForUrlsImpl(new UrlFilter
s.AllUrls()); |
| 465 | 464 |
| 466 // Verify that the last used time for both web apps is WebappDataStorage
.LAST_USED_UNSET. | 465 // Verify that the last used time for both web apps is WebappDataStorage
.TIMESTAMP_INVALID. |
| 467 actualLastUsed = webapp1Prefs.getLong( | 466 actualLastUsed = webapp1Prefs.getLong( |
| 468 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.LAST_USED_UNS
ET); | 467 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.TIMESTAMP_INV
ALID); |
| 469 assertEquals(WebappDataStorage.LAST_USED_UNSET, actualLastUsed); | 468 assertEquals(WebappDataStorage.TIMESTAMP_INVALID, actualLastUsed); |
| 470 actualLastUsed = webapp2Prefs.getLong( | 469 actualLastUsed = webapp2Prefs.getLong( |
| 471 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.LAST_USED_UNS
ET); | 470 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.TIMESTAMP_INV
ALID); |
| 472 assertEquals(WebappDataStorage.LAST_USED_UNSET, actualLastUsed); | 471 assertEquals(WebappDataStorage.TIMESTAMP_INVALID, actualLastUsed); |
| 473 | 472 |
| 474 // Verify that the URL and scope for both web apps is WebappDataStorage.
URL_INVALID. | 473 // Verify that the URL and scope for both web apps is WebappDataStorage.
URL_INVALID. |
| 475 actualScope = webapp1Prefs.getString( | 474 actualScope = webapp1Prefs.getString( |
| 476 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); | 475 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); |
| 477 assertEquals(WebappDataStorage.URL_INVALID, actualScope); | 476 assertEquals(WebappDataStorage.URL_INVALID, actualScope); |
| 478 actualUrl = webapp1Prefs.getString( | 477 actualUrl = webapp1Prefs.getString( |
| 479 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID); | 478 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID); |
| 480 assertEquals(WebappDataStorage.URL_INVALID, actualUrl); | 479 assertEquals(WebappDataStorage.URL_INVALID, actualUrl); |
| 481 actualScope = webapp2Prefs.getString( | 480 actualScope = webapp2Prefs.getString( |
| 482 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); | 481 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 493 | 492 |
| 494 SharedPreferences webappPrefs = ContextUtils.getApplicationContext().get
SharedPreferences( | 493 SharedPreferences webappPrefs = ContextUtils.getApplicationContext().get
SharedPreferences( |
| 495 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp", Context.M
ODE_PRIVATE); | 494 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp", Context.M
ODE_PRIVATE); |
| 496 WebappRegistry.getInstance().clearWebappHistoryForUrlsImpl(new UrlFilter
s.AllUrls()); | 495 WebappRegistry.getInstance().clearWebappHistoryForUrlsImpl(new UrlFilter
s.AllUrls()); |
| 497 | 496 |
| 498 // Open the webapp up and set the last used time. | 497 // Open the webapp up and set the last used time. |
| 499 WebappRegistry.getInstance().getWebappDataStorage("webapp").updateLastUs
edTime(); | 498 WebappRegistry.getInstance().getWebappDataStorage("webapp").updateLastUs
edTime(); |
| 500 | 499 |
| 501 // Verify that the last used time is valid. | 500 // Verify that the last used time is valid. |
| 502 long actualLastUsed = webappPrefs.getLong( | 501 long actualLastUsed = webappPrefs.getLong( |
| 503 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.LAST_USED_INV
ALID); | 502 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.TIMESTAMP_INV
ALID); |
| 504 assertTrue(WebappDataStorage.LAST_USED_INVALID != actualLastUsed); | 503 assertTrue(WebappDataStorage.TIMESTAMP_INVALID != actualLastUsed); |
| 505 assertTrue(WebappDataStorage.LAST_USED_UNSET != actualLastUsed); | |
| 506 } | 504 } |
| 507 | 505 |
| 508 @Test | 506 @Test |
| 509 @Feature({"Webapp"}) | 507 @Feature({"Webapp"}) |
| 510 public void testUpdateAfterClearWebappHistory() throws Exception { | 508 public void testUpdateAfterClearWebappHistory() throws Exception { |
| 511 final String webappUrl = "http://www.google.com"; | 509 final String webappUrl = "http://www.google.com"; |
| 512 final String webappScope = "http://www.google.com/"; | 510 final String webappScope = "http://www.google.com/"; |
| 513 final Intent shortcutIntent = createShortcutIntent(webappUrl); | 511 final Intent shortcutIntent = createShortcutIntent(webappUrl); |
| 514 registerWebapp("webapp", new FetchStorageCallback(shortcutIntent)); | 512 registerWebapp("webapp", new FetchStorageCallback(shortcutIntent)); |
| 515 | 513 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 } | 625 } |
| 628 | 626 |
| 629 private Intent createWebApkIntent(String webappId, String webApkPackage) { | 627 private Intent createWebApkIntent(String webappId, String webApkPackage) { |
| 630 Intent intent = new Intent(); | 628 Intent intent = new Intent(); |
| 631 intent.putExtra(ShortcutHelper.EXTRA_ID, webappId) | 629 intent.putExtra(ShortcutHelper.EXTRA_ID, webappId) |
| 632 .putExtra(ShortcutHelper.EXTRA_URL, "https://foo.com") | 630 .putExtra(ShortcutHelper.EXTRA_URL, "https://foo.com") |
| 633 .putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPacka
ge); | 631 .putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPacka
ge); |
| 634 return intent; | 632 return intent; |
| 635 } | 633 } |
| 636 } | 634 } |
| OLD | NEW |