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

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

Issue 2969143002: Fixes redirects to external apps when navigating from PWA. (Closed)
Patch Set: Fix 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 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.app.Activity;
7 import android.content.Intent; 8 import android.content.Intent;
8 import android.support.test.InstrumentationRegistry; 9 import android.support.test.InstrumentationRegistry;
9 import android.support.test.filters.LargeTest; 10 import android.support.test.filters.LargeTest;
10 11
11 import org.junit.After; 12 import org.junit.After;
12 import org.junit.Assert; 13 import org.junit.Assert;
13 import org.junit.Before; 14 import org.junit.Before;
14 import org.junit.Rule; 15 import org.junit.Rule;
15 import org.junit.Test; 16 import org.junit.Test;
16 import org.junit.runner.RunWith; 17 import org.junit.runner.RunWith;
17 18
19 import org.chromium.base.ApplicationStatus;
18 import org.chromium.base.metrics.RecordHistogram; 20 import org.chromium.base.metrics.RecordHistogram;
19 import org.chromium.base.test.util.CommandLineFlags; 21 import org.chromium.base.test.util.CommandLineFlags;
20 import org.chromium.base.test.util.Feature; 22 import org.chromium.base.test.util.Feature;
21 import org.chromium.base.test.util.ScalableTimeout; 23 import org.chromium.base.test.util.ScalableTimeout;
22 import org.chromium.chrome.browser.ChromeActivity;
23 import org.chromium.chrome.browser.ChromeSwitches; 24 import org.chromium.chrome.browser.ChromeSwitches;
24 import org.chromium.chrome.browser.DeferredStartupHandler; 25 import org.chromium.chrome.browser.DeferredStartupHandler;
25 import org.chromium.chrome.browser.ShortcutHelper; 26 import org.chromium.chrome.browser.ShortcutHelper;
26 import org.chromium.chrome.browser.customtabs.CustomTabActivity; 27 import org.chromium.chrome.browser.customtabs.CustomTabActivity;
27 import org.chromium.chrome.test.ChromeActivityTestRule; 28 import org.chromium.chrome.test.ChromeActivityTestRule;
28 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; 29 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
29 import org.chromium.chrome.test.util.ChromeTabUtils; 30 import org.chromium.chrome.test.util.ChromeTabUtils;
30 import org.chromium.content.browser.test.NativeLibraryTestRule; 31 import org.chromium.content.browser.test.NativeLibraryTestRule;
31 import org.chromium.content.browser.test.util.Criteria; 32 import org.chromium.content.browser.test.util.Criteria;
32 import org.chromium.content.browser.test.util.CriteriaHelper; 33 import org.chromium.content.browser.test.util.CriteriaHelper;
33 import org.chromium.net.test.EmbeddedTestServer; 34 import org.chromium.net.test.EmbeddedTestServer;
34 import org.chromium.webapk.lib.common.WebApkConstants; 35 import org.chromium.webapk.lib.common.WebApkConstants;
35 36
36 /** Integration tests for WebAPK feature. */ 37 /** Integration tests for WebAPK feature. */
37 @RunWith(ChromeJUnit4ClassRunner.class) 38 @RunWith(ChromeJUnit4ClassRunner.class)
38 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, 39 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
39 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) 40 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
40 public class WebApkIntegrationTest { 41 public class WebApkIntegrationTest {
41 @Rule 42 @Rule
42 public final ChromeActivityTestRule<WebApkActivity> mActivityTestRule = 43 public final ChromeActivityTestRule<WebApkActivity> mActivityTestRule =
43 new ChromeActivityTestRule<>(WebApkActivity.class); 44 new ChromeActivityTestRule<>(WebApkActivity.class);
44 45
45 @Rule 46 @Rule
46 public final NativeLibraryTestRule mNativeLibraryTestRule = new NativeLibrar yTestRule(); 47 public final NativeLibraryTestRule mNativeLibraryTestRule = new NativeLibrar yTestRule();
47 48
48 @Rule
49 public final TopActivityListener activityListener = new TopActivityListener( );
50
51 private static final long STARTUP_TIMEOUT = ScalableTimeout.scaleTimeout(100 00); 49 private static final long STARTUP_TIMEOUT = ScalableTimeout.scaleTimeout(100 00);
52 50
53 private EmbeddedTestServer mTestServer; 51 private EmbeddedTestServer mTestServer;
54 52
55 public void startWebApkActivity(String webApkPackageName, final String start Url) 53 public void startWebApkActivity(String webApkPackageName, final String start Url)
56 throws InterruptedException { 54 throws InterruptedException {
57 Intent intent = 55 Intent intent =
58 new Intent(InstrumentationRegistry.getTargetContext(), WebApkAct ivity.class); 56 new Intent(InstrumentationRegistry.getTargetContext(), WebApkAct ivity.class);
59 intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackage Name); 57 intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackage Name);
60 intent.putExtra(ShortcutHelper.EXTRA_URL, startUrl); 58 intent.putExtra(ShortcutHelper.EXTRA_URL, startUrl);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 mTestServer.getURL("/chrome/test/data/android/test.html")); 117 mTestServer.getURL("/chrome/test/data/android/test.html"));
120 waitUntilSplashscreenHides(); 118 waitUntilSplashscreenHides();
121 119
122 // We navigate outside origin and expect Custom Tab to open on top of We bApkActivity. 120 // We navigate outside origin and expect Custom Tab to open on top of We bApkActivity.
123 mActivityTestRule.runJavaScriptCodeInCurrentTab( 121 mActivityTestRule.runJavaScriptCodeInCurrentTab(
124 "window.top.location = 'https://www.google.com/'"); 122 "window.top.location = 'https://www.google.com/'");
125 123
126 CriteriaHelper.pollUiThread(new Criteria() { 124 CriteriaHelper.pollUiThread(new Criteria() {
127 @Override 125 @Override
128 public boolean isSatisfied() { 126 public boolean isSatisfied() {
129 ChromeActivity activity = (ChromeActivity) activityListener.getM ostRecentActivity(); 127 Activity activity = ApplicationStatus.getLastTrackedFocusedActiv ity();
130 return activity instanceof CustomTabActivity 128 if (!(activity instanceof CustomTabActivity)) {
131 && activity.getActivityTab() != null 129 return false;
130 }
131 CustomTabActivity customTab = (CustomTabActivity) activity;
132 return customTab.getActivityTab() != null
132 // Dropping the TLD as Google can redirect to a local si te. 133 // Dropping the TLD as Google can redirect to a local si te.
133 && activity.getActivityTab().getUrl().startsWith("https: //www.google."); 134 && customTab.getActivityTab().getUrl().startsWith("https ://www.google.");
134 } 135 }
135 }); 136 });
136 } 137 }
137 138
138 /** 139 /**
139 * Test that on first launch: 140 * Test that on first launch:
140 * - the "WebApk.LaunchInterval" histogram is not recorded (because there is no prevous launch 141 * - the "WebApk.LaunchInterval" histogram is not recorded (because there is no prevous launch
141 * to compute the interval from). 142 * to compute the interval from).
142 * - the "last used" time is updated (to compute future "launch intervals"). 143 * - the "last used" time is updated (to compute future "launch intervals").
143 */ 144 */
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 CriteriaHelper.pollUiThread(new Criteria("Deferred startup never complet ed") { 183 CriteriaHelper.pollUiThread(new Criteria("Deferred startup never complet ed") {
183 @Override 184 @Override
184 public boolean isSatisfied() { 185 public boolean isSatisfied() {
185 return DeferredStartupHandler.getInstance().isDeferredStartupCom pleteForApp(); 186 return DeferredStartupHandler.getInstance().isDeferredStartupCom pleteForApp();
186 } 187 }
187 }); 188 });
188 189
189 Assert.assertEquals(1, RecordHistogram.getHistogramTotalCountForTesting( histogramName)); 190 Assert.assertEquals(1, RecordHistogram.getHistogramTotalCountForTesting( histogramName));
190 } 191 }
191 } 192 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698