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

Side by Side 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, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.webapk.shell_apk;
6
7 import android.content.Intent;
8 import android.content.pm.ActivityInfo;
9 import android.content.pm.ResolveInfo;
10 import android.net.Uri;
11 import android.os.Bundle;
12
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.robolectric.Robolectric;
17 import org.robolectric.RuntimeEnvironment;
18 import org.robolectric.annotation.Config;
19 import org.robolectric.shadows.ShadowApplication;
20
21 import org.chromium.testing.local.LocalRobolectricTestRunner;
22 import org.chromium.webapk.lib.common.WebApkConstants;
23 import org.chromium.webapk.lib.common.WebApkMetaDataKeys;
24 import org.chromium.webapk.test.WebApkTestHelper;
25
26 /** Unit tests for {@link MainActivity}. */
27 @RunWith(LocalRobolectricTestRunner.class)
28 @Config(manifest = Config.NONE, packageName = WebApkUtilsTest.WEBAPK_PACKAGE_NAM E)
29 public final class MainActivityTest {
30 /**
31 * Test that MainActivity rewrites the start URL when the start URL from the intent is outside
32 * the scope specified in the Android Manifest.
33 */
34 @Test
35 public void testRewriteStartUrlSchemeAndHost() {
36 final String intentStartUrl = "http://www.google.ca/search_results?q=eh# cr=countryCA";
37 final String expectedRewrittenStartUrl =
38 "https://www.google.com/search_results?q=eh#cr=countryCA";
39 final String manifestStartUrl = "https://www.google.com/";
40 final String manifestScope = "https://www.google.com/";
41 final String browserPackageName = "com.android.chrome";
42
43 Bundle bundle = new Bundle();
44 bundle.putString(WebApkMetaDataKeys.START_URL, manifestStartUrl);
45 bundle.putString(WebApkMetaDataKeys.SCOPE, manifestScope);
46 bundle.putString(WebApkMetaDataKeys.RUNTIME_HOST, browserPackageName);
47 WebApkTestHelper.registerWebApkWithMetaData(WebApkUtilsTest.WEBAPK_PACKA GE_NAME, bundle);
48
49 installBrowser(browserPackageName);
50
51 Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(intentSta rtUrl));
52 Robolectric.buildActivity(MainActivity.class).withIntent(launchIntent).c reate();
53
54 Intent startActivityIntent = ShadowApplication.getInstance().getNextStar tedActivity();
55 Assert.assertEquals(MainActivity.ACTION_START_WEBAPK, startActivityInten t.getAction());
56 Assert.assertEquals(expectedRewrittenStartUrl,
57 startActivityIntent.getStringExtra(WebApkConstants.EXTRA_URL));
58 }
59
60 /**
61 * Test that MainActivity rewrites the start URL host so that it matches exa ctly the scope URL
62 * host. In particular, MainActivity should not escape unicode characters.
63 */
64 @Test
65 public void testRewriteUnicodeHost() {
66 final String intentStartUrl = "https://www.google.com/";
67 final String expectedStartUrl = "https://www.☺.com/";
68 final String manifestStartUrl = "https://www.☺.com/";
69 final String scope = "https://www.☺.com/";
70 final String browserPackageName = "com.android.chrome";
71
72 Bundle bundle = new Bundle();
73 bundle.putString(WebApkMetaDataKeys.START_URL, manifestStartUrl);
74 bundle.putString(WebApkMetaDataKeys.SCOPE, scope);
75 bundle.putString(WebApkMetaDataKeys.RUNTIME_HOST, browserPackageName);
76 WebApkTestHelper.registerWebApkWithMetaData(WebApkUtilsTest.WEBAPK_PACKA GE_NAME, bundle);
77
78 installBrowser(browserPackageName);
79
80 Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(intentSta rtUrl));
81 Robolectric.buildActivity(MainActivity.class).withIntent(launchIntent).c reate();
82
83 Intent startActivityIntent = ShadowApplication.getInstance().getNextStar tedActivity();
84 Assert.assertEquals(MainActivity.ACTION_START_WEBAPK, startActivityInten t.getAction());
85 Assert.assertEquals(
86 expectedStartUrl, startActivityIntent.getStringExtra(WebApkConst ants.EXTRA_URL));
87 }
88
89 private void installBrowser(String browserPackageName) {
90 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"));
91 RuntimeEnvironment.getRobolectricPackageManager().addResolveInfoForInten t(
92 intent, newResolveInfo(browserPackageName));
93 }
94
95 private static ResolveInfo newResolveInfo(String packageName) {
96 ActivityInfo activityInfo = new ActivityInfo();
97 activityInfo.packageName = packageName;
98 ResolveInfo resolveInfo = new ResolveInfo();
99 resolveInfo.activityInfo = activityInfo;
100 return resolveInfo;
101 }
102 }
OLDNEW
« 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