| 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 2d07c7afc6018b61bf11668a17315ad1f00fa8a9..f7bbfb6417c2d962528310340995a8e5d560ada2 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
|
| @@ -63,7 +63,7 @@ public class WebappRegistryTest {
|
| @Test
|
| @Feature({"Webapp"})
|
| public void testWebappRegistrationAddsToSharedPrefs() throws Exception {
|
| - WebappRegistry.registerWebapp(Robolectric.application, "test");
|
| + WebappRegistry.registerWebapp(Robolectric.application, "test", "https://www.google.com");
|
| BackgroundShadowAsyncTask.runBackgroundTasks();
|
|
|
| Set<String> actual = mSharedPreferences.getStringSet(
|
| @@ -74,9 +74,11 @@ public class WebappRegistryTest {
|
|
|
| @Test
|
| @Feature({"Webapp"})
|
| - public void testWebappRegistrationUpdatesLastUsed() throws Exception {
|
| + public void testWebappRegistrationUpdatesLastUsedAndOrigin() throws Exception {
|
| long before = System.currentTimeMillis();
|
| - WebappRegistry.registerWebapp(Robolectric.application, "test");
|
| + final String origin = "http://drive.google.com";
|
| +
|
| + WebappRegistry.registerWebapp(Robolectric.application, "test", origin);
|
| BackgroundShadowAsyncTask.runBackgroundTasks();
|
| long after = System.currentTimeMillis();
|
|
|
| @@ -84,7 +86,10 @@ public class WebappRegistryTest {
|
| WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "test", Context.MODE_PRIVATE);
|
| long actual = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USED,
|
| WebappDataStorage.INVALID_LAST_USED);
|
| + String webAppOrigin = webAppPrefs.getString(WebappDataStorage.KEY_ORIGIN_URL,
|
| + WebappDataStorage.INVALID_ORIGIN_URL);
|
| assertTrue("Timestamp is out of range", before <= actual && actual <= after);
|
| + assertEquals(origin, webAppOrigin);
|
| }
|
|
|
| @Test
|
| @@ -125,7 +130,7 @@ public class WebappRegistryTest {
|
| assertTrue(mCallbackCalled);
|
| mCallbackCalled = false;
|
|
|
| - WebappRegistry.registerWebapp(Robolectric.application, "second");
|
| + WebappRegistry.registerWebapp(Robolectric.application, "second", "https://www.google.com");
|
| BackgroundShadowAsyncTask.runBackgroundTasks();
|
|
|
| // A copy of the expected set needs to be made as the SharedPreferences is using the copy
|
| @@ -284,6 +289,90 @@ public class WebappRegistryTest {
|
| assertEquals(currentTime, lastCleanup);
|
| }
|
|
|
| + @Test
|
| + @Feature({"Webapp"})
|
| + public void testClearWebappHistoryRunsCallback() throws Exception {
|
| + WebappRegistry.clearWebappHistory(Robolectric.application, new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + mCallbackCalled = true;
|
| + }
|
| + });
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| + Robolectric.runUiThreadTasks();
|
| +
|
| + assertTrue(mCallbackCalled);
|
| + }
|
| +
|
| + @Test
|
| + @Feature({"Webapp"})
|
| + public void testClearWebappHistory() throws Exception {
|
| + final String webappOrigin1 = "https://www.google.com";
|
| + final String webappOrigin2 = "https://drive.google.com";
|
| + WebappRegistry.registerWebapp(Robolectric.application, "webapp1", webappOrigin1);
|
| + WebappRegistry.registerWebapp(Robolectric.application, "webapp2", webappOrigin2);
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| +
|
| + SharedPreferences webapp1Prefs = Robolectric.application.getSharedPreferences(
|
| + WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp1", Context.MODE_PRIVATE);
|
| + SharedPreferences webapp2Prefs = Robolectric.application.getSharedPreferences(
|
| + WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp2", Context.MODE_PRIVATE);
|
| +
|
| + WebappRegistry.clearWebappHistory(Robolectric.application, null);
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| +
|
| + Set<String> actual = mSharedPreferences.getStringSet(
|
| + WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet());
|
| + assertEquals(2, actual.size());
|
| + assertTrue(actual.contains("webapp1"));
|
| + assertTrue(actual.contains("webapp2"));
|
| +
|
| + // Verify that the last used time for both web apps is WebappDataStorage.NULL_LAST_USED.
|
| + long actualLastUsed = webapp1Prefs.getLong(
|
| + WebappDataStorage.KEY_LAST_USED, WebappDataStorage.NULL_LAST_USED);
|
| + assertEquals(WebappDataStorage.NULL_LAST_USED, actualLastUsed);
|
| + actualLastUsed = webapp2Prefs.getLong(
|
| + WebappDataStorage.KEY_LAST_USED, WebappDataStorage.NULL_LAST_USED);
|
| + assertEquals(WebappDataStorage.NULL_LAST_USED, actualLastUsed);
|
| +
|
| + // Verify that the origin URL for both web apps is WebappDataStorage.INVALID_ORIGIN_URL.
|
| + String actualOriginUrl = webapp1Prefs.getString(
|
| + WebappDataStorage.KEY_ORIGIN_URL, WebappDataStorage.INVALID_ORIGIN_URL);
|
| + assertEquals(WebappDataStorage.INVALID_ORIGIN_URL, actualOriginUrl);
|
| + actualOriginUrl = webapp2Prefs.getString(
|
| + WebappDataStorage.KEY_ORIGIN_URL, WebappDataStorage.INVALID_ORIGIN_URL);
|
| + assertEquals(WebappDataStorage.INVALID_ORIGIN_URL, actualOriginUrl);
|
| + }
|
| +
|
| + @Test
|
| + @Feature({"Webapp"})
|
| + public void testOpenAfterClearWebappHistory() throws Exception {
|
| + final String webappOrigin = "https://www.google.com";
|
| + WebappRegistry.registerWebapp(Robolectric.application, "webapp", webappOrigin);
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| +
|
| + SharedPreferences webappPrefs = Robolectric.application.getSharedPreferences(
|
| + WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp", Context.MODE_PRIVATE);
|
| +
|
| + WebappRegistry.clearWebappHistory(Robolectric.application, null);
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| +
|
| + // Open the webapp up and set the origin.
|
| + WebappDataStorage.open(Robolectric.application, "webapp");
|
| + WebappDataStorage.updateOriginUrl(Robolectric.application, "webapp", webappOrigin);
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| +
|
| + // Verify that the last used time is valid and the origin URL is updated.
|
| + long actualLastUsed = webappPrefs.getLong(
|
| + WebappDataStorage.KEY_LAST_USED, WebappDataStorage.INVALID_LAST_USED);
|
| + assertTrue(WebappDataStorage.INVALID_LAST_USED != actualLastUsed);
|
| + assertTrue(WebappDataStorage.NULL_LAST_USED != actualLastUsed);
|
| + String actualOriginUrl = webappPrefs.getString(
|
| + WebappDataStorage.KEY_ORIGIN_URL, WebappDataStorage.INVALID_ORIGIN_URL);
|
| + assertEquals(webappOrigin, actualOriginUrl);
|
| + }
|
| +
|
| +
|
| private Set<String> addWebappsToRegistry(String... webapps) {
|
| final Set<String> expected = new HashSet<String>(Arrays.asList(webapps));
|
| mSharedPreferences.edit()
|
| @@ -296,4 +385,4 @@ public class WebappRegistryTest {
|
| return mSharedPreferences.getStringSet(
|
| WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet());
|
| }
|
| -}
|
| +}
|
|
|