Chromium Code Reviews| 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 ad887864e0ce81c650bf7bae2cd2fd045300ca56..4f7ccc0e611b94f9f7ef4b39268eb5af39969867 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 |
| @@ -15,6 +15,7 @@ import org.chromium.base.ContextUtils; |
| import org.chromium.blink_public.platform.WebDisplayMode; |
| import org.chromium.chrome.browser.ShortcutHelper; |
| import org.chromium.chrome.browser.tab.Tab; |
| +import org.chromium.chrome.browser.webapps.ManifestUpgradeDetector.FetchedManifestData; |
| import org.chromium.content_public.common.ScreenOrientationValues; |
| import org.chromium.testing.local.LocalRobolectricTestRunner; |
| @@ -52,31 +53,11 @@ public class ManifestUpgradeDetectorTest { |
| private RobolectricPackageManager mPackageManager; |
| - /** |
| - * Used to represent either: |
| - * - Data that the WebAPK was created with. |
| - * OR |
| - * - Data fetched by ManifestUpgradeDetector. |
| - */ |
| - private static class Data { |
| - public String startUrl = WEBAPK_START_URL; |
| - public String scopeUrl = WEBAPK_SCOPE_URL; |
| - public String name = WEBAPK_NAME; |
| - public String shortName = WEBAPK_SHORT_NAME; |
| - public String iconUrl = WEBAPK_ICON_URL; |
| - public long iconMurmur2Hash = WEBAPK_ICON_MURMUR2_HASH; |
| - public Bitmap icon = createBitmap(Color.GREEN); |
| - public int displayMode = WEBAPK_DISPLAY_MODE; |
| - public int orientation = WEBAPK_ORIENTATION; |
| - public long themeColor = WEBAPK_THEME_COLOR; |
| - public long backgroundColor = WEBAPK_BACKGROUND_COLOR; |
| - } |
| - |
| private static class TestCallback implements ManifestUpgradeDetector.Callback { |
| public boolean mIsUpgraded; |
| public boolean mWasCalled; |
| @Override |
| - public void onUpgradeNeededCheckFinished(boolean isUpgraded, WebappInfo newInfo) { |
| + public void onUpgradeNeededCheckFinished(boolean isUpgraded, FetchedManifestData data) { |
| mIsUpgraded = isUpgraded; |
| mWasCalled = true; |
| } |
| @@ -90,10 +71,10 @@ public class ManifestUpgradeDetectorTest { |
| * - Tracks whether "upgrade needed checking logic" has terminated. |
| */ |
| private static class TestManifestUpgradeDetector extends ManifestUpgradeDetector { |
| - private Data mFetchedData; |
| + private FetchedManifestData mFetchedData; |
| - public TestManifestUpgradeDetector(Tab tab, WebappInfo info, Data fetchedData, |
| - ManifestUpgradeDetector.Callback callback) { |
| + public TestManifestUpgradeDetector(Tab tab, WebappInfo info, |
| + FetchedManifestData fetchedData, ManifestUpgradeDetector.Callback callback) { |
| super(tab, info, callback); |
| mFetchedData = fetchedData; |
| } |
| @@ -137,9 +118,31 @@ public class ManifestUpgradeDetectorTest { |
| mPackageManager = (RobolectricPackageManager) context.getPackageManager(); |
| } |
| - private TestManifestUpgradeDetector createDetectorWithFetchedData(Data fetchedData, |
| - TestCallback callback) { |
| - return createDetector(new Data(), fetchedData, callback); |
| + /** |
| + * Create a default data. The FetchedManifestData is used to represent either: |
| + * - Data that the WebAPK was created with. |
| + * OR |
| + * - Data fetched by ManifestUpgradeDetector. |
| + */ |
| + private FetchedManifestData createDefaultData() { |
| + FetchedManifestData data = new FetchedManifestData(); |
| + data.startUrl = WEBAPK_START_URL; |
| + data.scopeUrl = 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; |
| + return data; |
| + } |
| + |
| + private TestManifestUpgradeDetector createDetectorWithFetchedData( |
| + FetchedManifestData fetchedData, TestCallback callback) { |
| + return createDetector(createDefaultData(), fetchedData, callback); |
| } |
| /** |
| @@ -149,8 +152,8 @@ public class ManifestUpgradeDetectorTest { |
| * @param fetchedData Data fetched by ManifestUpgradeDetector. |
| * @param callback Callback to call when the upgrade check is complete. |
| */ |
| - private TestManifestUpgradeDetector createDetector(Data oldData, Data fetchedData, |
| - TestCallback callback) { |
| + private TestManifestUpgradeDetector createDetector(FetchedManifestData oldData, |
| + FetchedManifestData fetchedData, TestCallback callback) { |
| setMetaData( |
| WEBAPK_MANIFEST_URL, oldData.startUrl, oldData.iconUrl, oldData.iconMurmur2Hash); |
| WebappInfo webappInfo = WebappInfo.create("", oldData.startUrl, oldData.scopeUrl, null, |
| @@ -180,7 +183,8 @@ public class ManifestUpgradeDetectorTest { |
| @Test |
| public void testManifestDoesNotUpgrade() { |
| TestCallback callback = new TestCallback(); |
| - TestManifestUpgradeDetector detector = createDetectorWithFetchedData(new Data(), callback); |
| + TestManifestUpgradeDetector detector = createDetectorWithFetchedData( |
| + createDefaultData(), callback); |
| detector.start(); |
| Assert.assertTrue(callback.mWasCalled); |
| Assert.assertFalse(callback.mIsUpgraded); |
| @@ -188,7 +192,7 @@ public class ManifestUpgradeDetectorTest { |
| @Test |
| public void testStartUrlChangeShouldUpgrade() { |
| - Data fetchedData = new Data(); |
| + FetchedManifestData fetchedData = createDefaultData(); |
| fetchedData.startUrl = "/changed.html"; |
| TestCallback callback = new TestCallback(); |
| TestManifestUpgradeDetector detector = createDetectorWithFetchedData(fetchedData, callback); |
| @@ -203,10 +207,10 @@ public class ManifestUpgradeDetectorTest { |
| */ |
| @Test |
| public void testManifestEmptyScopeShouldNotUpgrade() { |
| - Data oldData = new Data(); |
| + FetchedManifestData oldData = createDefaultData(); |
| // webapk_installer.cc sets the scope to the default scope if the scope is empty. |
| oldData.scopeUrl = ShortcutHelper.getScopeFromUrl(oldData.startUrl); |
| - Data fetchedData = new Data(); |
| + FetchedManifestData fetchedData = createDefaultData(); |
| fetchedData.scopeUrl = ""; |
| Assert.assertTrue(!oldData.scopeUrl.equals(fetchedData.scopeUrl)); |
| @@ -223,12 +227,12 @@ public class ManifestUpgradeDetectorTest { |
| */ |
| @Test |
| public void testManifestNonEmptyScopeToEmptyScopeShouldUpgrade() { |
| - Data oldData = new Data(); |
| + FetchedManifestData oldData = createDefaultData(); |
|
pkotwicz
2016/08/19 23:38:17
It feels a bit weird to use FetchedManifestData fo
Xi Han
2016/08/26 17:54:08
I add a WebappInfoCreationData to represent the "t
|
| oldData.startUrl = "/fancy/scope/special/snowflake.html"; |
| oldData.scopeUrl = "/fancy/scope/"; |
| Assert.assertTrue( |
| !oldData.scopeUrl.equals(ShortcutHelper.getScopeFromUrl(oldData.startUrl))); |
| - Data fetchedData = new Data(); |
| + FetchedManifestData fetchedData = createDefaultData(); |
| fetchedData.startUrl = "/fancy/scope/special/snowflake.html"; |
| fetchedData.scopeUrl = ""; |
| @@ -246,7 +250,7 @@ public class ManifestUpgradeDetectorTest { |
| */ |
| @Test |
| public void testHomescreenIconChangeShouldUpgrade() { |
| - Data fetchedData = new Data(); |
| + FetchedManifestData fetchedData = createDefaultData(); |
| fetchedData.iconMurmur2Hash = WEBAPK_ICON_MURMUR2_HASH + 1; |
| fetchedData.icon = createBitmap(Color.BLUE); |
| TestCallback callback = new TestCallback(); |
| @@ -264,7 +268,7 @@ public class ManifestUpgradeDetectorTest { |
| */ |
| @Test |
| public void testHomescreenIconUrlChangeShouldUpgrade() { |
| - Data fetchedData = new Data(); |
| + FetchedManifestData fetchedData = createDefaultData(); |
| fetchedData.iconUrl = "/icon2.png"; |
| TestCallback callback = new TestCallback(); |
| @@ -281,7 +285,7 @@ public class ManifestUpgradeDetectorTest { |
| */ |
| @Test |
| public void testHomescreenIconUrlsRemovedShouldNotUpgrade() { |
| - Data fetchedData = new Data(); |
| + FetchedManifestData fetchedData = createDefaultData(); |
| fetchedData.iconUrl = ""; |
| fetchedData.iconMurmur2Hash = 0L; |
| fetchedData.icon = null; |