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

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

Issue 1845233002: Store standalone web app data in WebappDataStorage as well as the homescreen intent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@notification-deep-linking
Patch Set: Improve comments Created 4 years, 9 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 5ff97d69a6e9b10db149b5510472399790faf711..12cb35474ff20962633b04e62190d3208a5d0c74 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
@@ -8,8 +8,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
+import android.os.AsyncTask;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.ShortcutHelper;
@@ -63,7 +65,17 @@ public class WebappDataStorageTest {
assertEquals("webapp_", WebappDataStorage.SHARED_PREFS_FILE_PREFIX);
assertEquals("splash_icon", WebappDataStorage.KEY_SPLASH_ICON);
assertEquals("last_used", WebappDataStorage.KEY_LAST_USED);
+ assertEquals("url", WebappDataStorage.KEY_URL);
assertEquals("scope", WebappDataStorage.KEY_SCOPE);
+ assertEquals("icon", WebappDataStorage.KEY_ICON);
+ assertEquals("name", WebappDataStorage.KEY_NAME);
+ assertEquals("short_name", WebappDataStorage.KEY_SHORT_NAME);
+ assertEquals("orientation", WebappDataStorage.KEY_ORIENTATION);
+ assertEquals("theme_color", WebappDataStorage.KEY_THEME_COLOR);
+ assertEquals("background_color", WebappDataStorage.KEY_BACKGROUND_COLOR);
+ assertEquals("source", WebappDataStorage.KEY_SOURCE);
+ assertEquals("action", WebappDataStorage.KEY_ACTION);
+ assertEquals("is_icon_generated", WebappDataStorage.KEY_IS_ICON_GENERATED);
}
@Test
@@ -124,35 +136,21 @@ public class WebappDataStorageTest {
@Feature({"Webapp"})
public void testSplashImageUpdate() throws Exception {
final Bitmap expectedImage = createBitmap();
- WebappDataStorage.open(Robolectric.application, "test")
- .updateSplashScreenImage(expectedImage);
+ final WebappDataStorage storage = WebappDataStorage.open(Robolectric.application, "test");
+ new AsyncTask<Void, Void, Void>() {
+ @Override
+ protected final Void doInBackground(Void... nothing) {
+ storage.updateSplashScreenImage(expectedImage);
+ return null;
+ }
+ }.execute();
+
BackgroundShadowAsyncTask.runBackgroundTasks();
assertEquals(ShortcutHelper.encodeBitmapAsString(expectedImage),
mSharedPreferences.getString(WebappDataStorage.KEY_SPLASH_ICON, null));
}
- // TODO(lalitm) - There seems to be a bug in Robolectric where a Bitmap
- // produced from a byte stream is hardcoded to be a 100x100 bitmap with
- // ARGB_8888 pixel format. Because of this, we need to work around the
- // equality check of bitmaps. Remove this once the bug is fixed.
- private static boolean bitmapEquals(Bitmap expected, Bitmap actual) {
- if (actual.getWidth() != 100) return false;
- if (actual.getHeight() != 100) return false;
- if (!actual.getConfig().equals(Bitmap.Config.ARGB_8888)) return false;
-
- for (int i = 0; i < actual.getWidth(); i++) {
- for (int j = 0; j < actual.getHeight(); j++) {
- if (actual.getPixel(i, j) != 0) return false;
- }
- }
- return true;
- }
-
- private static Bitmap createBitmap() {
- return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
- }
-
@Test
@Feature({"Webapp"})
public void testScopeRetrieval() throws Exception {
@@ -171,22 +169,121 @@ public class WebappDataStorageTest {
@Test
@Feature({"Webapp"})
- public void testScopeUpdate() throws Exception {
- final String scope1 = "http://maps.google.com";
- final String scope2 = "http://drive.google.com";
+ public void testURLRetrieval() throws Exception {
+ final String url = "https://www.google.com";
+ mSharedPreferences.edit()
+ .putString(WebappDataStorage.KEY_URL, url)
+ .commit();
+
+ WebappDataStorage.getURL(Robolectric.application, "test",
+ new FetchCallback<String>(url));
+ BackgroundShadowAsyncTask.runBackgroundTasks();
+ Robolectric.runUiThreadTasks();
+
+ assertTrue(mCallbackCalled);
+ }
- WebappDataStorage.setScope(Robolectric.application, "test", scope1);
+ @Test
+ @Feature({"Webapp"})
+ public void testIntentUpdate() throws Exception {
+ final String id = "id";
+ final String action = "action";
+ final String url = "url";
+ final String name = "name";
+ final String shortName = "shortName";
+ final Bitmap icon = createBitmap();
+ final int orientation = 1;
+ final long themeColor = 2;
+ final long backgroundColor = 3;
+ final boolean isIconGenerated = false;
+ Intent shortcutIntent = ShortcutHelper.createWebappShortcutIntent(id, action, url, name,
+ shortName, icon, orientation, themeColor, backgroundColor, isIconGenerated);
+
+ WebappDataStorage storage = WebappDataStorage.open(Robolectric.application, "test");
+ storage.updateFromShortcutIntent(shortcutIntent);
BackgroundShadowAsyncTask.runBackgroundTasks();
Robolectric.runUiThreadTasks();
- assertEquals(scope1, mSharedPreferences.getString(WebappDataStorage.KEY_SCOPE, null));
+ assertEquals(action, mSharedPreferences.getString(WebappDataStorage.KEY_ACTION, null));
+ assertEquals(url, mSharedPreferences.getString(WebappDataStorage.KEY_URL, null));
+ // SCOPE is set by default to URL until the manifest scope member is available.
+ assertEquals(url, mSharedPreferences.getString(WebappDataStorage.KEY_SCOPE, null));
+ assertEquals(name, mSharedPreferences.getString(WebappDataStorage.KEY_NAME, null));
+ assertEquals(shortName,
+ mSharedPreferences.getString(WebappDataStorage.KEY_SHORT_NAME, null));
+ assertEquals(ShortcutHelper.encodeBitmapAsString(icon),
+ mSharedPreferences.getString(WebappDataStorage.KEY_ICON, null));
+ assertEquals(orientation, mSharedPreferences.getInt(WebappDataStorage.KEY_ORIENTATION, 0));
+ assertEquals(themeColor, mSharedPreferences.getLong(WebappDataStorage.KEY_THEME_COLOR, 0));
+ assertEquals(backgroundColor,
+ mSharedPreferences.getLong(WebappDataStorage.KEY_BACKGROUND_COLOR, 0));
+ assertEquals(isIconGenerated,
+ mSharedPreferences.getBoolean(WebappDataStorage.KEY_IS_ICON_GENERATED, true));
+
+ // Wipe out the data and ensure that it is all gone.
+ mSharedPreferences.edit().remove(WebappDataStorage.KEY_ACTION)
+ .remove(WebappDataStorage.KEY_URL)
+ .remove(WebappDataStorage.KEY_SCOPE)
+ .remove(WebappDataStorage.KEY_NAME)
+ .remove(WebappDataStorage.KEY_SHORT_NAME)
+ .remove(WebappDataStorage.KEY_ICON)
+ .remove(WebappDataStorage.KEY_ORIENTATION)
+ .remove(WebappDataStorage.KEY_THEME_COLOR)
+ .remove(WebappDataStorage.KEY_BACKGROUND_COLOR)
+ .remove(WebappDataStorage.KEY_IS_ICON_GENERATED)
+ .commit();
- // Ensure that calling setScope with a different URL after it has been set
- // doesn't change the scope stored.
- WebappDataStorage.setScope(Robolectric.application, "test", scope2);
+ assertEquals(null, mSharedPreferences.getString(WebappDataStorage.KEY_ACTION, null));
+ assertEquals(null, mSharedPreferences.getString(WebappDataStorage.KEY_URL, null));
+ assertEquals(null, mSharedPreferences.getString(WebappDataStorage.KEY_SCOPE, null));
+ assertEquals(null, mSharedPreferences.getString(WebappDataStorage.KEY_NAME, null));
+ assertEquals(null, mSharedPreferences.getString(WebappDataStorage.KEY_SHORT_NAME, null));
+ assertEquals(null, mSharedPreferences.getString(WebappDataStorage.KEY_ICON, null));
+ assertEquals(0, mSharedPreferences.getInt(WebappDataStorage.KEY_ORIENTATION, 0));
+ assertEquals(0, mSharedPreferences.getLong(WebappDataStorage.KEY_THEME_COLOR, 0));
+ assertEquals(0, mSharedPreferences.getLong(WebappDataStorage.KEY_BACKGROUND_COLOR, 0));
+ assertEquals(true,
+ mSharedPreferences.getBoolean(WebappDataStorage.KEY_IS_ICON_GENERATED, true));
+
+ // Update again from the intent and ensure that the data is restored.
+ storage.updateFromShortcutIntent(shortcutIntent);
BackgroundShadowAsyncTask.runBackgroundTasks();
Robolectric.runUiThreadTasks();
- assertEquals(scope1, mSharedPreferences.getString(WebappDataStorage.KEY_SCOPE, null));
+ assertEquals(action, mSharedPreferences.getString(WebappDataStorage.KEY_ACTION, null));
+ assertEquals(url, mSharedPreferences.getString(WebappDataStorage.KEY_URL, null));
+ assertEquals(url, mSharedPreferences.getString(WebappDataStorage.KEY_SCOPE, null));
+ assertEquals(name, mSharedPreferences.getString(WebappDataStorage.KEY_NAME, null));
+ assertEquals(shortName,
+ mSharedPreferences.getString(WebappDataStorage.KEY_SHORT_NAME, null));
+ assertEquals(ShortcutHelper.encodeBitmapAsString(icon),
+ mSharedPreferences.getString(WebappDataStorage.KEY_ICON, null));
+ assertEquals(orientation, mSharedPreferences.getInt(WebappDataStorage.KEY_ORIENTATION, 0));
+ assertEquals(themeColor, mSharedPreferences.getLong(WebappDataStorage.KEY_THEME_COLOR, 0));
+ assertEquals(backgroundColor,
+ mSharedPreferences.getLong(WebappDataStorage.KEY_BACKGROUND_COLOR, 0));
+ assertEquals(isIconGenerated,
+ mSharedPreferences.getBoolean(WebappDataStorage.KEY_IS_ICON_GENERATED, true));
+ }
+
+ // TODO(lalitm) - There seems to be a bug in Robolectric where a Bitmap
+ // produced from a byte stream is hardcoded to be a 100x100 bitmap with
+ // ARGB_8888 pixel format. Because of this, we need to work around the
+ // equality check of bitmaps. Remove this once the bug is fixed.
+ private static boolean bitmapEquals(Bitmap expected, Bitmap actual) {
+ if (actual.getWidth() != 100) return false;
+ if (actual.getHeight() != 100) return false;
+ if (!actual.getConfig().equals(Bitmap.Config.ARGB_8888)) return false;
+
+ for (int i = 0; i < actual.getWidth(); i++) {
+ for (int j = 0; j < actual.getHeight(); j++) {
+ if (actual.getPixel(i, j) != 0) return false;
+ }
+ }
+ return true;
+ }
+
+ private static Bitmap createBitmap() {
+ return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
}
}

Powered by Google App Engine
This is Rietveld 408576698