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

Unified Diff: chrome/android/webapk/shell_apk/junit/src/org/chromium/webapk/shell_apk/MainActivityTest.java

Issue 2956193002: [Android] Enable WebAPK to have multiple intent filters (Closed)
Patch Set: Merge branch 'master' into rewriting Created 3 years, 5 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/webapk/shell_apk/junit/src/org/chromium/webapk/shell_apk/MainActivityTest.java
diff --git a/chrome/android/webapk/shell_apk/junit/src/org/chromium/webapk/shell_apk/MainActivityTest.java b/chrome/android/webapk/shell_apk/junit/src/org/chromium/webapk/shell_apk/MainActivityTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..8f961e188a5538d5e3b840a41d2bd11ac69eeb9e
--- /dev/null
+++ b/chrome/android/webapk/shell_apk/junit/src/org/chromium/webapk/shell_apk/MainActivityTest.java
@@ -0,0 +1,102 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.webapk.shell_apk;
+
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ResolveInfo;
+import android.net.Uri;
+import android.os.Bundle;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+import org.chromium.testing.local.LocalRobolectricTestRunner;
+import org.chromium.webapk.lib.common.WebApkConstants;
+import org.chromium.webapk.lib.common.WebApkMetaDataKeys;
+import org.chromium.webapk.test.WebApkTestHelper;
+
+/** Unit tests for {@link MainActivity}. */
+@RunWith(LocalRobolectricTestRunner.class)
+@Config(manifest = Config.NONE, packageName = WebApkUtilsTest.WEBAPK_PACKAGE_NAME)
+public final class MainActivityTest {
+ /**
+ * Test that MainActivity rewrites the start URL when the start URL from the intent is outside
+ * the scope specified in the Android Manifest.
+ */
+ @Test
+ public void testRewriteStartUrlSchemeAndHost() {
+ final String intentStartUrl = "http://www.google.ca/search_results?q=eh#cr=countryCA";
+ final String expectedRewrittenStartUrl =
+ "https://www.google.com/search_results?q=eh#cr=countryCA";
+ final String manifestStartUrl = "https://www.google.com/";
+ final String manifestScope = "https://www.google.com/";
+ final String browserPackageName = "com.android.chrome";
+
+ Bundle bundle = new Bundle();
+ bundle.putString(WebApkMetaDataKeys.START_URL, manifestStartUrl);
+ bundle.putString(WebApkMetaDataKeys.SCOPE, manifestScope);
+ bundle.putString(WebApkMetaDataKeys.RUNTIME_HOST, browserPackageName);
+ WebApkTestHelper.registerWebApkWithMetaData(WebApkUtilsTest.WEBAPK_PACKAGE_NAME, bundle);
+
+ installBrowser(browserPackageName);
+
+ Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(intentStartUrl));
+ Robolectric.buildActivity(MainActivity.class).withIntent(launchIntent).create();
+
+ Intent startActivityIntent = ShadowApplication.getInstance().getNextStartedActivity();
+ Assert.assertEquals(MainActivity.ACTION_START_WEBAPK, startActivityIntent.getAction());
+ Assert.assertEquals(expectedRewrittenStartUrl,
+ startActivityIntent.getStringExtra(WebApkConstants.EXTRA_URL));
+ }
+
+ /**
+ * Test that MainActivity rewrites the start URL host so that it matches exactly the scope URL
+ * host. In particular, MainActivity should not escape unicode characters.
+ */
+ @Test
+ public void testRewriteUnicodeHost() {
+ final String intentStartUrl = "https://www.google.com/";
+ final String expectedStartUrl = "https://www.☺.com/";
+ final String manifestStartUrl = "https://www.☺.com/";
+ final String scope = "https://www.☺.com/";
+ final String browserPackageName = "com.android.chrome";
+
+ Bundle bundle = new Bundle();
+ bundle.putString(WebApkMetaDataKeys.START_URL, manifestStartUrl);
+ bundle.putString(WebApkMetaDataKeys.SCOPE, scope);
+ bundle.putString(WebApkMetaDataKeys.RUNTIME_HOST, browserPackageName);
+ WebApkTestHelper.registerWebApkWithMetaData(WebApkUtilsTest.WEBAPK_PACKAGE_NAME, bundle);
+
+ installBrowser(browserPackageName);
+
+ Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(intentStartUrl));
+ Robolectric.buildActivity(MainActivity.class).withIntent(launchIntent).create();
+
+ Intent startActivityIntent = ShadowApplication.getInstance().getNextStartedActivity();
+ Assert.assertEquals(MainActivity.ACTION_START_WEBAPK, startActivityIntent.getAction());
+ Assert.assertEquals(
+ expectedStartUrl, startActivityIntent.getStringExtra(WebApkConstants.EXTRA_URL));
+ }
+
+ private void installBrowser(String browserPackageName) {
+ Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"));
+ RuntimeEnvironment.getRobolectricPackageManager().addResolveInfoForIntent(
+ intent, newResolveInfo(browserPackageName));
+ }
+
+ private static ResolveInfo newResolveInfo(String packageName) {
+ ActivityInfo activityInfo = new ActivityInfo();
+ activityInfo.packageName = packageName;
+ ResolveInfo resolveInfo = new ResolveInfo();
+ resolveInfo.activityInfo = activityInfo;
+ return resolveInfo;
+ }
+}
« no previous file with comments | « chrome/android/webapk/shell_apk/javatest_manifest_config.json ('k') | chrome/android/webapk/shell_apk/manifest_processor.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698