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

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

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

Powered by Google App Engine
This is Rietveld 408576698