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

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

Issue 2453423002: Send all of the icon URLs listed in Web Manifest to WebAPK Server. (Closed)
Patch Set: Remove best_icon_url and best_icon_hash from metadata, but add all icon urls and icon hashs in. Created 4 years, 1 month 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/ManifestUpgradeDetectorTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorTest.java
index 442fffe290e716e6a790ead556310628c4e22d49..89320a55534b96fdf45114a8e5e7741c44b3b563 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorTest.java
@@ -30,6 +30,9 @@ import org.chromium.chrome.browser.tab.Tab;
import org.chromium.content_public.common.ScreenOrientationValues;
import org.chromium.testing.local.LocalRobolectricTestRunner;
+import java.util.HashMap;
+import java.util.HashSet;
+
/**
* Tests the ManifestUpgradeDetector.
*/
@@ -69,7 +72,7 @@ public class ManifestUpgradeDetectorTest {
* The WebappInfoCreationData is the data extracted from a WebAPK. It is used to create a
* WebappInfo for WebAPKs.
*/
- private static class WebappInfoCreationData extends FetchedManifestData {}
+ private static class WebappInfoCreationData extends WebApkMetaData {}
/**
* ManifestUpgradeDetector subclass which:
@@ -97,8 +100,9 @@ public class ManifestUpgradeDetectorTest {
ManifestUpgradeDetectorFetcher.Callback callback =
(ManifestUpgradeDetectorFetcher.Callback) invocation.getArguments()[0];
callback.onGotManifestData(mFetchedData.startUrl, mFetchedData.scopeUrl,
- mFetchedData.name, mFetchedData.shortName, mFetchedData.iconUrl,
- mFetchedData.iconMurmur2Hash, mFetchedData.icon,
+ mFetchedData.name, mFetchedData.shortName, mFetchedData.bestIconUrl,
+ mFetchedData.bestIconMurmur2Hash, mFetchedData.bestIcon,
+ mFetchedData.iconUrls.toArray(new String[0]),
mFetchedData.displayMode, mFetchedData.orientation,
mFetchedData.themeColor, mFetchedData.backgroundColor);
return null;
@@ -138,7 +142,19 @@ public class ManifestUpgradeDetectorTest {
*/
private FetchedManifestData createDefaultFetchedManifestData() {
FetchedManifestData data = new FetchedManifestData();
- populateDataWithDefaults(data);
+ data.startUrl = WEBAPK_START_URL;
+ data.scopeUrl = WEBAPK_SCOPE_URL;
+ data.name = WEBAPK_NAME;
+ data.shortName = WEBAPK_SHORT_NAME;
+ data.bestIconUrl = WEBAPK_ICON_URL;
+ data.bestIconMurmur2Hash = WEBAPK_ICON_MURMUR2_HASH;
+ data.bestIcon = createBitmap(Color.GREEN);
+ data.iconUrls = new HashSet<String>();
+ data.iconUrls.add(data.bestIconUrl);
+ data.displayMode = WEBAPK_DISPLAY_MODE;
+ data.orientation = WEBAPK_ORIENTATION;
+ data.themeColor = WEBAPK_THEME_COLOR;
+ data.backgroundColor = WEBAPK_BACKGROUND_COLOR;
return data;
}
@@ -148,22 +164,17 @@ public class ManifestUpgradeDetectorTest {
*/
private WebappInfoCreationData createDefaultWebappInfoCreationData() {
WebappInfoCreationData data = new WebappInfoCreationData();
- populateDataWithDefaults(data);
- return data;
- }
-
- private void populateDataWithDefaults(FetchedManifestData data) {
data.startUrl = WEBAPK_START_URL;
- data.scopeUrl = WEBAPK_SCOPE_URL;
+ data.scope = WEBAPK_SCOPE_URL;
data.name = WEBAPK_NAME;
data.shortName = WEBAPK_SHORT_NAME;
- data.iconUrl = WEBAPK_ICON_URL;
- data.iconMurmur2Hash = WEBAPK_ICON_MURMUR2_HASH;
- data.icon = createBitmap(Color.GREEN);
data.displayMode = WEBAPK_DISPLAY_MODE;
data.orientation = WEBAPK_ORIENTATION;
data.themeColor = WEBAPK_THEME_COLOR;
data.backgroundColor = WEBAPK_BACKGROUND_COLOR;
+ data.iconURLAndHashMap = new HashMap<String, String>();
+ data.iconURLAndHashMap.put(WEBAPK_ICON_URL, WEBAPK_ICON_MURMUR2_HASH);
+ return data;
}
private TestManifestUpgradeDetector createDetectorWithFetchedData(
@@ -183,15 +194,14 @@ public class ManifestUpgradeDetectorTest {
WebApkMetaData metaData = new WebApkMetaData();
metaData.manifestUrl = WEBAPK_MANIFEST_URL;
metaData.startUrl = oldData.startUrl;
- metaData.scope = oldData.scopeUrl;
+ metaData.scope = oldData.scope;
metaData.name = oldData.name;
metaData.shortName = oldData.shortName;
metaData.displayMode = oldData.displayMode;
metaData.orientation = oldData.orientation;
metaData.themeColor = oldData.themeColor;
metaData.backgroundColor = oldData.backgroundColor;
- metaData.iconUrl = oldData.iconUrl;
- metaData.iconMurmur2Hash = oldData.iconMurmur2Hash;
+ metaData.iconURLAndHashMap = new HashMap<String, String>(oldData.iconURLAndHashMap);
return new TestManifestUpgradeDetector(null, metaData, fetchedData, callback);
}
@@ -224,10 +234,10 @@ public class ManifestUpgradeDetectorTest {
public void testManifestEmptyScopeShouldNotUpgrade() {
WebappInfoCreationData oldData = createDefaultWebappInfoCreationData();
// webapk_installer.cc sets the scope to the default scope if the scope is empty.
- oldData.scopeUrl = ShortcutHelper.getScopeFromUrl(oldData.startUrl);
+ oldData.scope = ShortcutHelper.getScopeFromUrl(oldData.startUrl);
FetchedManifestData fetchedData = createDefaultFetchedManifestData();
fetchedData.scopeUrl = "";
- Assert.assertTrue(!oldData.scopeUrl.equals(fetchedData.scopeUrl));
+ Assert.assertTrue(!oldData.scope.equals(fetchedData.scopeUrl));
TestCallback callback = new TestCallback();
TestManifestUpgradeDetector detector = createDetector(oldData, fetchedData, callback);
@@ -244,9 +254,9 @@ public class ManifestUpgradeDetectorTest {
public void testManifestNonEmptyScopeToEmptyScopeShouldUpgrade() {
WebappInfoCreationData oldData = createDefaultWebappInfoCreationData();
oldData.startUrl = "/fancy/scope/special/snowflake.html";
- oldData.scopeUrl = "/fancy/scope/";
+ oldData.scope = "/fancy/scope/";
Assert.assertTrue(
- !oldData.scopeUrl.equals(ShortcutHelper.getScopeFromUrl(oldData.startUrl)));
+ !oldData.scope.equals(ShortcutHelper.getScopeFromUrl(oldData.startUrl)));
FetchedManifestData fetchedData = createDefaultFetchedManifestData();
fetchedData.startUrl = "/fancy/scope/special/snowflake.html";
fetchedData.scopeUrl = "";
@@ -266,8 +276,8 @@ public class ManifestUpgradeDetectorTest {
@Test
public void testHomescreenIconChangeShouldUpgrade() {
FetchedManifestData fetchedData = createDefaultFetchedManifestData();
- fetchedData.iconMurmur2Hash = WEBAPK_ICON_MURMUR2_HASH + "1";
- fetchedData.icon = createBitmap(Color.BLUE);
+ fetchedData.bestIconMurmur2Hash = WEBAPK_ICON_MURMUR2_HASH + "1";
+ fetchedData.bestIcon = createBitmap(Color.BLUE);
TestCallback callback = new TestCallback();
TestManifestUpgradeDetector detector = createDetectorWithFetchedData(fetchedData, callback);
@@ -284,7 +294,22 @@ public class ManifestUpgradeDetectorTest {
@Test
public void testHomescreenIconUrlChangeShouldUpgrade() {
FetchedManifestData fetchedData = createDefaultFetchedManifestData();
- fetchedData.iconUrl = "/icon2.png";
+ fetchedData.bestIconUrl = "/icon2.png";
+
+ TestCallback callback = new TestCallback();
+ TestManifestUpgradeDetector detector = createDetectorWithFetchedData(fetchedData, callback);
+ detector.start();
+ Assert.assertTrue(callback.mWasCalled);
+ Assert.assertTrue(callback.mIsUpgraded);
+ }
+
+ /**
+ * Test that an upgrade is requested when a new icon URL is added to the Web Manifest.
+ */
pkotwicz 2016/11/11 21:04:19 Nit: Make this a single line comment like this: /*
Xi Han 2016/11/14 19:36:10 Done.
+ @Test
+ public void testIconUrlsChangeShouleUpgrade() {
+ FetchedManifestData fetchedData = createDefaultFetchedManifestData();
+ fetchedData.iconUrls.add("/icon2.png");
TestCallback callback = new TestCallback();
TestManifestUpgradeDetector detector = createDetectorWithFetchedData(fetchedData, callback);

Powered by Google App Engine
This is Rietveld 408576698