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

Unified Diff: chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappDataStorageTest.java

Issue 2351113005: [Reland] Refactor WebappRegistry into a singleton instance. (Closed)
Patch Set: Checkstyle import order has changed overnight argh Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
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 b4a689441575d9004921025762315986ecb8ecae..435b48d88d237ea6c821b3713a28fa35f75424dd 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
@@ -13,20 +13,22 @@ import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.AsyncTask;
-import org.chromium.base.ContextUtils;
-import org.chromium.base.test.util.Feature;
-import org.chromium.blink_public.platform.WebDisplayMode;
-import org.chromium.chrome.browser.ShortcutHelper;
-import org.chromium.testing.local.BackgroundShadowAsyncTask;
-import org.chromium.testing.local.LocalRobolectricTestRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLooper;
+import org.chromium.base.ContextUtils;
+import org.chromium.base.test.util.Feature;
+import org.chromium.blink_public.platform.WebDisplayMode;
+import org.chromium.chrome.browser.ShortcutHelper;
+import org.chromium.testing.local.BackgroundShadowAsyncTask;
+import org.chromium.testing.local.LocalRobolectricTestRunner;
+
import java.util.concurrent.TimeUnit;
/**
@@ -75,10 +77,10 @@ public class WebappDataStorageTest {
public void setUp() throws Exception {
ContextUtils.initApplicationContextForTests(RuntimeEnvironment.application);
mSharedPreferences = ContextUtils.getApplicationContext().getSharedPreferences(
- "webapp_test", Context.MODE_PRIVATE);
+ WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "test", Context.MODE_PRIVATE);
// Set the last_used as if the web app had been registered by WebappRegistry.
- mSharedPreferences.edit().putLong("last_used", 0).apply();
+ mSharedPreferences.edit().putLong(WebappDataStorage.KEY_LAST_USED, 0).apply();
mCallbackCalled = false;
}
@@ -111,13 +113,9 @@ public class WebappDataStorageTest {
@Test
@Feature({"Webapp"})
public void testLastUsedRetrieval() throws Exception {
- mSharedPreferences.edit().putLong(WebappDataStorage.KEY_LAST_USED, 100L).apply();
-
- WebappDataStorage.getLastUsedTime("test", new FetchCallback<Long>(new Long(100L)));
- BackgroundShadowAsyncTask.runBackgroundTasks();
- ShadowLooper.runUiThreadTasks();
-
- assertTrue(mCallbackCalled);
+ long lastUsed = 100;
+ mSharedPreferences.edit().putLong(WebappDataStorage.KEY_LAST_USED, lastUsed).apply();
+ assertEquals(lastUsed, new WebappDataStorage("test").getLastUsedTime());
}
@Test
@@ -127,9 +125,9 @@ public class WebappDataStorageTest {
mSharedPreferences.edit()
.putString(WebappDataStorage.KEY_SPLASH_ICON,
ShortcutHelper.encodeBitmapAsString(expected))
- .commit();
- WebappDataStorage.open("test")
- .getSplashScreenImage(new WebappDataStorage.FetchCallback<Bitmap>() {
+ .apply();
+ WebappDataStorage.open("test").getSplashScreenImage(
+ new WebappDataStorage.FetchCallback<Bitmap>() {
@Override
public void onDataRetrieved(Bitmap actual) {
mCallbackCalled = true;
@@ -152,6 +150,7 @@ public class WebappDataStorageTest {
final Bitmap expectedImage = createBitmap();
WebappDataStorage.open("test").updateSplashScreenImage(expectedImage);
BackgroundShadowAsyncTask.runBackgroundTasks();
+ ShadowLooper.runUiThreadTasks();
assertEquals(ShortcutHelper.encodeBitmapAsString(expectedImage),
mSharedPreferences.getString(WebappDataStorage.KEY_SPLASH_ICON, null));
@@ -160,27 +159,17 @@ public class WebappDataStorageTest {
@Test
@Feature({"Webapp"})
public void testScopeRetrieval() throws Exception {
- final String scope = "http://drive.google.com";
+ String scope = "http://drive.google.com";
mSharedPreferences.edit().putString(WebappDataStorage.KEY_SCOPE, scope).apply();
-
- WebappDataStorage.getScope("test", new FetchCallback<String>(scope));
- BackgroundShadowAsyncTask.runBackgroundTasks();
- ShadowLooper.runUiThreadTasks();
-
- assertTrue(mCallbackCalled);
+ assertEquals(scope, new WebappDataStorage("test").getScope());
}
@Test
@Feature({"Webapp"})
public void testUrlRetrieval() throws Exception {
- final String url = "https://www.google.com";
+ String url = "https://www.google.com";
mSharedPreferences.edit().putString(WebappDataStorage.KEY_URL, url).apply();
-
- WebappDataStorage.getUrl("test", new FetchCallback<String>(url));
- BackgroundShadowAsyncTask.runBackgroundTasks();
- ShadowLooper.runUiThreadTasks();
-
- assertTrue(mCallbackCalled);
+ assertEquals(url, new WebappDataStorage("test").getUrl());
}
@Test
@@ -191,14 +180,10 @@ public class WebappDataStorageTest {
// 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,
@@ -263,8 +248,6 @@ public class WebappDataStorageTest {
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));
@@ -312,8 +295,6 @@ public class WebappDataStorageTest {
// 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));

Powered by Google App Engine
This is Rietveld 408576698