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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebApkIntegrationTest.java

Issue 2905073002: Revert of Redirecting off-origin navigations in PWAs to CCT. (Closed)
Patch Set: Created 3 years, 7 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.webapps; 5 package org.chromium.chrome.browser.webapps;
6 6
7 import android.content.Intent; 7 import android.content.Intent;
8 import android.support.test.InstrumentationRegistry; 8 import android.support.test.InstrumentationRegistry;
9 import android.support.test.filters.LargeTest; 9 import android.support.test.filters.LargeTest;
10 10
11 import org.junit.After; 11 import org.junit.After;
12 import org.junit.Assert;
13 import org.junit.Before; 12 import org.junit.Before;
14 import org.junit.Rule; 13 import org.junit.Rule;
15 import org.junit.Test; 14 import org.junit.Test;
16 import org.junit.runner.RunWith; 15 import org.junit.runner.RunWith;
17 16
18 import org.chromium.base.test.util.CommandLineFlags; 17 import org.chromium.base.test.util.CommandLineFlags;
19 import org.chromium.base.test.util.Feature; 18 import org.chromium.base.test.util.Feature;
20 import org.chromium.base.test.util.RetryOnFailure; 19 import org.chromium.base.test.util.RetryOnFailure;
21 import org.chromium.base.test.util.ScalableTimeout; 20 import org.chromium.base.test.util.ScalableTimeout;
22 import org.chromium.chrome.browser.ChromeActivity;
23 import org.chromium.chrome.browser.ChromeSwitches; 21 import org.chromium.chrome.browser.ChromeSwitches;
24 import org.chromium.chrome.browser.ShortcutHelper; 22 import org.chromium.chrome.browser.ShortcutHelper;
25 import org.chromium.chrome.browser.customtabs.CustomTabActivity;
26 import org.chromium.chrome.test.ChromeActivityTestRule; 23 import org.chromium.chrome.test.ChromeActivityTestRule;
27 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; 24 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
28 import org.chromium.chrome.test.util.ChromeTabUtils; 25 import org.chromium.chrome.test.util.ChromeTabUtils;
29 import org.chromium.content.browser.test.util.Criteria; 26 import org.chromium.content.browser.test.util.Criteria;
30 import org.chromium.content.browser.test.util.CriteriaHelper; 27 import org.chromium.content.browser.test.util.CriteriaHelper;
31 import org.chromium.net.test.EmbeddedTestServer; 28 import org.chromium.net.test.EmbeddedTestServer;
32 import org.chromium.webapk.lib.common.WebApkConstants; 29 import org.chromium.webapk.lib.common.WebApkConstants;
33 30
34 /** Integration tests for WebAPK feature. */ 31 /** Integration tests for WebAPK feature. */
35 @RunWith(ChromeJUnit4ClassRunner.class) 32 @RunWith(ChromeJUnit4ClassRunner.class)
36 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, 33 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
37 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) 34 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
38 public class WebApkIntegrationTest { 35 public class WebApkIntegrationTest {
39 @Rule 36 @Rule
40 public final ChromeActivityTestRule<WebApkActivity> mActivityTestRule = 37 public final ChromeActivityTestRule<WebApkActivity> mActivityTestRule =
41 new ChromeActivityTestRule<>(WebApkActivity.class); 38 new ChromeActivityTestRule<>(WebApkActivity.class);
42 39
43 @Rule
44 public final TopActivityListener activityListener = new TopActivityListener( );
45
46 private static final long STARTUP_TIMEOUT = ScalableTimeout.scaleTimeout(100 00); 40 private static final long STARTUP_TIMEOUT = ScalableTimeout.scaleTimeout(100 00);
47 41
48 private EmbeddedTestServer mTestServer; 42 private EmbeddedTestServer mTestServer;
49 43
50 public void startWebApkActivity(String webApkPackageName, final String start Url) 44 public void startWebApkActivity(String webApkPackageName, final String start Url)
51 throws InterruptedException { 45 throws InterruptedException {
52 Intent intent = 46 Intent intent =
53 new Intent(InstrumentationRegistry.getTargetContext(), WebApkAct ivity.class); 47 new Intent(InstrumentationRegistry.getTargetContext(), WebApkAct ivity.class);
54 intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackage Name); 48 intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackage Name);
55 intent.putExtra(ShortcutHelper.EXTRA_URL, startUrl); 49 intent.putExtra(ShortcutHelper.EXTRA_URL, startUrl);
56 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 50 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
57 51 mActivityTestRule.setActivity(
58 WebApkActivity webApkActivity =
59 (WebApkActivity) InstrumentationRegistry.getInstrumentation().st artActivitySync( 52 (WebApkActivity) InstrumentationRegistry.getInstrumentation().st artActivitySync(
60 intent); 53 intent));
61 webApkActivity.mWebappInfo.setScopeForTest(
62 startUrl.substring(0, startUrl.lastIndexOf('/') + 1));
63 mActivityTestRule.setActivity(webApkActivity);
64 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); 54 InstrumentationRegistry.getInstrumentation().waitForIdleSync();
65 55
66 CriteriaHelper.pollInstrumentationThread(new Criteria() { 56 CriteriaHelper.pollInstrumentationThread(new Criteria() {
67 @Override 57 @Override
68 public boolean isSatisfied() { 58 public boolean isSatisfied() {
69 return mActivityTestRule.getActivity().getActivityTab() != null; 59 return mActivityTestRule.getActivity().getActivityTab() != null;
70 } 60 }
71 }, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL); 61 }, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
72 62
73 ChromeTabUtils.waitForTabPageLoaded( 63 ChromeTabUtils.waitForTabPageLoaded(
(...skipping 23 matching lines...) Expand all
97 } 87 }
98 88
99 /** 89 /**
100 * Test launching a WebAPK. Test that loading the start page works and that the splashscreen 90 * Test launching a WebAPK. Test that loading the start page works and that the splashscreen
101 * eventually hides. 91 * eventually hides.
102 */ 92 */
103 @Test 93 @Test
104 @LargeTest 94 @LargeTest
105 @Feature({"WebApk"}) 95 @Feature({"WebApk"})
106 @RetryOnFailure 96 @RetryOnFailure
107 public void testLaunchAndNavigateOffOrigin() throws Exception { 97 public void testLaunch() throws InterruptedException {
108 startWebApkActivity("org.chromium.webapk.test", 98 startWebApkActivity("org.chromium.webapk.test",
109 mTestServer.getURL("/chrome/test/data/android/test.html")); 99 mTestServer.getURL("/chrome/test/data/android/test.html"));
110 waitUntilSplashscreenHides(); 100 waitUntilSplashscreenHides();
111
112 WebApkActivity webApkActivity = mActivityTestRule.getActivity();
113 waitForFinishLoading(webApkActivity);
114
115 Assert.assertSame(webApkActivity, activityListener.getMostRecentActivity ());
116 Assert.assertEquals(mTestServer.getURL("/chrome/test/data/android/test.h tml"),
117 webApkActivity.getActivityTab().getUrl());
118
119 // We navigate outside origin and expect Custom Tab to open on top of We bApkActivity.
120 mActivityTestRule.runJavaScriptCodeInCurrentTab(
121 "window.top.location = 'https://www.google.com/'");
122
123 activityListener.waitFor(CustomTabActivity.class);
124
125 final CustomTabActivity customTab =
126 (CustomTabActivity) activityListener.getMostRecentActivity();
127
128 waitForFinishLoading(customTab);
129
130 // Dropping the TLD as Google can redirect to a local site, so this coul d fail outside US.
131 Assert.assertTrue(customTab.getActivityTab().getUrl().startsWith("https: //www.google."));
132 }
133
134 private void waitForFinishLoading(final ChromeActivity chromeActivity) {
135 CriteriaHelper.pollInstrumentationThread(new Criteria() {
136 @Override
137 public boolean isSatisfied() {
138 return chromeActivity.getActivityTab() != null
139 && !chromeActivity.getActivityTab().isLoading();
140 }
141 }, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
142 InstrumentationRegistry.getInstrumentation().waitForIdleSync();
143 } 101 }
144 } 102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698