| Index: chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappDataStorageTest.java
|
| diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappDataStorageTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappDataStorageTest.java
|
| index e96eff558d06d1dc21a7d505306c0734daecb1e5..b4a689441575d9004921025762315986ecb8ecae 100644
|
| --- a/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappDataStorageTest.java
|
| +++ b/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappDataStorageTest.java
|
| @@ -75,10 +75,10 @@
|
| public void setUp() throws Exception {
|
| ContextUtils.initApplicationContextForTests(RuntimeEnvironment.application);
|
| mSharedPreferences = ContextUtils.getApplicationContext().getSharedPreferences(
|
| - WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "test", Context.MODE_PRIVATE);
|
| + "webapp_test", Context.MODE_PRIVATE);
|
|
|
| // Set the last_used as if the web app had been registered by WebappRegistry.
|
| - mSharedPreferences.edit().putLong(WebappDataStorage.KEY_LAST_USED, 0).apply();
|
| + mSharedPreferences.edit().putLong("last_used", 0).apply();
|
|
|
| mCallbackCalled = false;
|
| }
|
| @@ -111,9 +111,13 @@
|
| @Test
|
| @Feature({"Webapp"})
|
| public void testLastUsedRetrieval() throws Exception {
|
| - long lastUsed = 100;
|
| - mSharedPreferences.edit().putLong(WebappDataStorage.KEY_LAST_USED, lastUsed).apply();
|
| - assertEquals(lastUsed, new WebappDataStorage("test").getLastUsedTime());
|
| + mSharedPreferences.edit().putLong(WebappDataStorage.KEY_LAST_USED, 100L).apply();
|
| +
|
| + WebappDataStorage.getLastUsedTime("test", new FetchCallback<Long>(new Long(100L)));
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| + ShadowLooper.runUiThreadTasks();
|
| +
|
| + assertTrue(mCallbackCalled);
|
| }
|
|
|
| @Test
|
| @@ -123,9 +127,9 @@
|
| mSharedPreferences.edit()
|
| .putString(WebappDataStorage.KEY_SPLASH_ICON,
|
| ShortcutHelper.encodeBitmapAsString(expected))
|
| - .apply();
|
| - WebappDataStorage.open("test").getSplashScreenImage(
|
| - new WebappDataStorage.FetchCallback<Bitmap>() {
|
| + .commit();
|
| + WebappDataStorage.open("test")
|
| + .getSplashScreenImage(new WebappDataStorage.FetchCallback<Bitmap>() {
|
| @Override
|
| public void onDataRetrieved(Bitmap actual) {
|
| mCallbackCalled = true;
|
| @@ -148,7 +152,6 @@
|
| final Bitmap expectedImage = createBitmap();
|
| WebappDataStorage.open("test").updateSplashScreenImage(expectedImage);
|
| BackgroundShadowAsyncTask.runBackgroundTasks();
|
| - ShadowLooper.runUiThreadTasks();
|
|
|
| assertEquals(ShortcutHelper.encodeBitmapAsString(expectedImage),
|
| mSharedPreferences.getString(WebappDataStorage.KEY_SPLASH_ICON, null));
|
| @@ -157,17 +160,27 @@
|
| @Test
|
| @Feature({"Webapp"})
|
| public void testScopeRetrieval() throws Exception {
|
| - String scope = "http://drive.google.com";
|
| + final String scope = "http://drive.google.com";
|
| mSharedPreferences.edit().putString(WebappDataStorage.KEY_SCOPE, scope).apply();
|
| - assertEquals(scope, new WebappDataStorage("test").getScope());
|
| +
|
| + WebappDataStorage.getScope("test", new FetchCallback<String>(scope));
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| + ShadowLooper.runUiThreadTasks();
|
| +
|
| + assertTrue(mCallbackCalled);
|
| }
|
|
|
| @Test
|
| @Feature({"Webapp"})
|
| public void testUrlRetrieval() throws Exception {
|
| - String url = "https://www.google.com";
|
| + final String url = "https://www.google.com";
|
| mSharedPreferences.edit().putString(WebappDataStorage.KEY_URL, url).apply();
|
| - assertEquals(url, new WebappDataStorage("test").getUrl());
|
| +
|
| + WebappDataStorage.getUrl("test", new FetchCallback<String>(url));
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| + ShadowLooper.runUiThreadTasks();
|
| +
|
| + assertTrue(mCallbackCalled);
|
| }
|
|
|
| @Test
|
| @@ -178,10 +191,14 @@
|
|
|
| // Opening a data storage doesn't count as a launch.
|
| WebappDataStorage storage = WebappDataStorage.open("test");
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| + ShadowLooper.runUiThreadTasks();
|
| assertTrue(!storage.wasLaunchedRecently());
|
|
|
| // When the last used time is updated, then it is a launch.
|
| storage.updateLastUsedTime();
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| + ShadowLooper.runUiThreadTasks();
|
| assertTrue(storage.wasLaunchedRecently());
|
|
|
| long lastUsedTime = mSharedPreferences.getLong(WebappDataStorage.KEY_LAST_USED,
|
| @@ -246,6 +263,8 @@
|
|
|
| WebappDataStorage storage = WebappDataStorage.open("test");
|
| storage.updateFromShortcutIntent(shortcutIntent);
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| + ShadowLooper.runUiThreadTasks();
|
|
|
| assertEquals(action, mSharedPreferences.getString(WebappDataStorage.KEY_ACTION, null));
|
| assertEquals(url, mSharedPreferences.getString(WebappDataStorage.KEY_URL, null));
|
| @@ -293,6 +312,8 @@
|
|
|
| // Update again from the intent and ensure that the data is restored.
|
| storage.updateFromShortcutIntent(shortcutIntent);
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| + ShadowLooper.runUiThreadTasks();
|
|
|
| assertEquals(action, mSharedPreferences.getString(WebappDataStorage.KEY_ACTION, null));
|
| assertEquals(url, mSharedPreferences.getString(WebappDataStorage.KEY_URL, null));
|
|
|