| 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 b4b6564a18356665526b7a973bbf3f694cc92ad9..8f348474ed04eaa5621e093223d8a9f15de19348 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
|
| @@ -321,6 +321,93 @@ public class WebappDataStorageTest {
|
| mSharedPreferences.getBoolean(WebappDataStorage.KEY_IS_ICON_GENERATED, true));
|
| }
|
|
|
| + @Test
|
| + @Feature({"WebApk"})
|
| + public void testIntentVersionOfWebApkUpdate() throws Exception {
|
| + final String id = "webapk:id";
|
| + final String url = "url";
|
| + String webApkPackageName = "org.webapk.com";
|
| + int version = 111;
|
| +
|
| + Intent shortcutIntent = new Intent();
|
| + shortcutIntent.putExtra(ShortcutHelper.EXTRA_ID, id)
|
| + .putExtra(ShortcutHelper.EXTRA_URL, url)
|
| + .putExtra(ShortcutHelper.EXTRA_VERSION, version)
|
| + .putExtra(ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackageName);
|
| +
|
| + WebappDataStorage storage = WebappDataStorage.open(Robolectric.application, "test");
|
| + storage.updateFromShortcutIntent(shortcutIntent);
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| + Robolectric.runUiThreadTasks();
|
| +
|
| + assertEquals(webApkPackageName,
|
| + mSharedPreferences.getString(WebappDataStorage.KEY_WEBAPK_PACKAGE_NAME, null));
|
| + assertEquals(version, mSharedPreferences.getInt(WebappDataStorage.KEY_VERSION, -1));
|
| +
|
| + // Wipe out the data and ensure that it is all gone.
|
| + mSharedPreferences.edit().remove(WebappDataStorage.KEY_URL)
|
| + .remove(WebappDataStorage.KEY_VERSION)
|
| + .remove(WebappDataStorage.KEY_WEBAPK_PACKAGE_NAME)
|
| + .apply();
|
| +
|
| + assertEquals(-1, mSharedPreferences.getInt(WebappDataStorage.KEY_VERSION, -1));
|
| + assertEquals(null, mSharedPreferences.getString(WebappDataStorage.KEY_WEBAPK_PACKAGE_NAME,
|
| + null));
|
| +
|
| + // Update again from the intent and ensure that the data is restored.
|
| + storage.updateFromShortcutIntent(shortcutIntent);
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| + Robolectric.runUiThreadTasks();
|
| +
|
| + assertEquals(webApkPackageName,
|
| + mSharedPreferences.getString(WebappDataStorage.KEY_WEBAPK_PACKAGE_NAME, null));
|
| + assertEquals(version, mSharedPreferences.getInt(WebappDataStorage.KEY_VERSION, -1));
|
| +
|
| + }
|
| +
|
| + @Test
|
| + @Feature({"WebApk"})
|
| + public void testEmptyIntentVersionOfWebApkUpdateFallbackToVersionInvalid() throws Exception {
|
| + final String id = "webapk:id";
|
| + final String url = "url";
|
| + String webApkPackageName = "org.webapk.com";
|
| +
|
| + Intent shortcutIntent = new Intent();
|
| + shortcutIntent.putExtra(ShortcutHelper.EXTRA_ID, id)
|
| + .putExtra(ShortcutHelper.EXTRA_URL, url)
|
| + .putExtra(ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackageName);
|
| +
|
| + WebappDataStorage storage = WebappDataStorage.open(Robolectric.application, "test");
|
| + storage.updateFromShortcutIntent(shortcutIntent);
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| + Robolectric.runUiThreadTasks();
|
| +
|
| + assertEquals(webApkPackageName,
|
| + mSharedPreferences.getString(WebappDataStorage.KEY_WEBAPK_PACKAGE_NAME, null));
|
| + assertEquals(WebappDataStorage.VERSION_INVALID,
|
| + mSharedPreferences.getInt(WebappDataStorage.KEY_VERSION, -1));
|
| +
|
| + // Wipe out the data and ensure that it is all gone.
|
| + mSharedPreferences.edit().remove(WebappDataStorage.KEY_URL)
|
| + .remove(WebappDataStorage.KEY_VERSION)
|
| + .remove(WebappDataStorage.KEY_WEBAPK_PACKAGE_NAME)
|
| + .apply();
|
| +
|
| + assertEquals(-1, mSharedPreferences.getInt(WebappDataStorage.KEY_VERSION, -1));
|
| + assertEquals(null, mSharedPreferences.getString(WebappDataStorage.KEY_WEBAPK_PACKAGE_NAME,
|
| + null));
|
| +
|
| + // Update again from the intent and ensure that the data is restored.
|
| + storage.updateFromShortcutIntent(shortcutIntent);
|
| + BackgroundShadowAsyncTask.runBackgroundTasks();
|
| + Robolectric.runUiThreadTasks();
|
| +
|
| + assertEquals(webApkPackageName,
|
| + mSharedPreferences.getString(WebappDataStorage.KEY_WEBAPK_PACKAGE_NAME, null));
|
| + assertEquals(WebappDataStorage.VERSION_INVALID,
|
| + mSharedPreferences.getInt(WebappDataStorage.KEY_VERSION, -1));
|
| + }
|
| +
|
| // 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
|
|
|