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

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

Issue 2457663002: Merge WebappInfo and WebApkMetaData part 1/2 (Closed)
Patch Set: Merge branch 'master' into update_fail_refactor00 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/WebApkInfoTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebApkMetaDataUtilsTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebApkInfoTest.java
similarity index 54%
copy from chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebApkMetaDataUtilsTest.java
copy to chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebApkInfoTest.java
index 96174bd0be718756510d1c6eb70da76974259a16..f102bdd0d0b4254e0679e8c3816e97e483f5bf94 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebApkMetaDataUtilsTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebApkInfoTest.java
@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.webapps;
+import android.content.Intent;
import android.os.Bundle;
import org.junit.Assert;
@@ -15,6 +16,7 @@ import org.robolectric.annotation.Config;
import org.chromium.base.ContextUtils;
import org.chromium.blink_public.platform.WebDisplayMode;
+import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.content_public.common.ScreenOrientationValues;
import org.chromium.testing.local.LocalRobolectricTestRunner;
import org.chromium.webapk.lib.common.WebApkConstants;
@@ -22,11 +24,11 @@ import org.chromium.webapk.lib.common.WebApkMetaDataKeys;
import org.chromium.webapk.test.WebApkTestHelper;
/**
- * Tests WebApkMetaDataUtils.
+ * Tests WebApkInfo.
*/
@RunWith(LocalRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
-public class WebApkMetaDataUtilsTest {
+public class WebApkInfoTest {
// Android Manifest meta data for {@link PACKAGE_NAME}.
private static final String START_URL = "https://www.google.com/scope/a_is_for_apple";
@@ -55,53 +57,47 @@ public class WebApkMetaDataUtilsTest {
bundle.putString(WebApkMetaDataKeys.BACKGROUND_COLOR, BACKGROUND_COLOR);
WebApkTestHelper.registerWebApkWithMetaData(bundle);
- WebappInfo webappInfo = WebApkMetaDataUtils.extractWebappInfoFromWebApk(
- WebApkTestHelper.WEBAPK_PACKAGE_NAME, START_URL, 0);
+ Intent intent = new Intent();
+ intent.putExtra(
+ ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAPK_PACKAGE_NAME);
+ intent.putExtra(ShortcutHelper.EXTRA_URL, START_URL);
+
+ WebApkInfo info = WebApkInfo.create(intent);
Assert.assertEquals(WebApkConstants.WEBAPK_ID_PREFIX + WebApkTestHelper.WEBAPK_PACKAGE_NAME,
- webappInfo.id());
- Assert.assertEquals(SCOPE, webappInfo.scopeUri().toString());
- Assert.assertEquals(NAME, webappInfo.name());
- Assert.assertEquals(SHORT_NAME, webappInfo.shortName());
- Assert.assertEquals(WebDisplayMode.MinimalUi, webappInfo.displayMode());
- Assert.assertEquals(ScreenOrientationValues.PORTRAIT, webappInfo.orientation());
- Assert.assertTrue(webappInfo.hasValidThemeColor());
- Assert.assertEquals(1L, webappInfo.themeColor());
- Assert.assertTrue(webappInfo.hasValidBackgroundColor());
- Assert.assertEquals(2L, webappInfo.backgroundColor());
- Assert.assertEquals(WebApkTestHelper.WEBAPK_PACKAGE_NAME, webappInfo.webApkPackageName());
+ info.id());
+ Assert.assertEquals(SCOPE, info.scopeUri().toString());
+ Assert.assertEquals(NAME, info.name());
+ Assert.assertEquals(SHORT_NAME, info.shortName());
+ Assert.assertEquals(WebDisplayMode.MinimalUi, info.displayMode());
+ Assert.assertEquals(ScreenOrientationValues.PORTRAIT, info.orientation());
+ Assert.assertTrue(info.hasValidThemeColor());
+ Assert.assertEquals(1L, info.themeColor());
+ Assert.assertTrue(info.hasValidBackgroundColor());
+ Assert.assertEquals(2L, info.backgroundColor());
+ Assert.assertEquals(WebApkTestHelper.WEBAPK_PACKAGE_NAME, info.webApkPackageName());
}
/**
- * Test that WebappInfo are populated with the start URL passed to
- * {@link extractWebappInfoFromWebApk()} not the start URL in the WebAPK's meta data. When a
- * WebAPK is launched via a deep link from a URL within the WebAPK's scope, the WebAPK should
- * open at the URL it was deep linked from not the WebAPK's start URL.
+ * Test that {@link WebApkInfo#create()} populates WebApkInfo with the start URL from the intent
+ * not the start URL in the WebAPK's meta data. When a WebAPK is launched via a deep link from a
+ * URL within the WebAPK's scope, the WebAPK should open at the URL it was deep linked from not
+ * the WebAPK's start URL.
*/
@Test
public void testUseStartUrlOverride() {
- String passedInStartUrl = "https://www.google.com/master_override";
+ String intentStartUrl = "https://www.google.com/master_override";
Bundle bundle = new Bundle();
bundle.putString(WebApkMetaDataKeys.START_URL, START_URL);
WebApkTestHelper.registerWebApkWithMetaData(bundle);
- WebappInfo webappInfo = WebApkMetaDataUtils.extractWebappInfoFromWebApk(
- WebApkTestHelper.WEBAPK_PACKAGE_NAME, passedInStartUrl, 0);
- Assert.assertEquals(passedInStartUrl, webappInfo.uri().toString());
- }
+ Intent intent = new Intent();
+ intent.putExtra(
+ ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAPK_PACKAGE_NAME);
+ intent.putExtra(ShortcutHelper.EXTRA_URL, intentStartUrl);
- /**
- * WebApkIconHasher generates hashes with values [0, 2^64-1]. 2^64-1 is greater than
- * {@link Long#MAX_VALUE}. Test that {@link #getIconMurmur2HashFromMetaData()} can read a hash
- * with value 2^64 - 1.
- */
- @Test
- public void testGetIconMurmur2HashFromMetaData() {
- String hash = "18446744073709551615"; // 2^64 - 1
- Bundle bundle = new Bundle();
- bundle.putString(WebApkMetaDataKeys.ICON_MURMUR2_HASH, hash + "L");
- String extractedHash = WebApkMetaDataUtils.getIconMurmur2HashFromMetaData(bundle);
- Assert.assertEquals(hash, extractedHash);
+ WebApkInfo info = WebApkInfo.create(intent);
+ Assert.assertEquals(intentStartUrl, info.uri().toString());
}
}

Powered by Google App Engine
This is Rietveld 408576698