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

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: Removed TopActivityListener 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.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; 12 import org.junit.Assert;
13 import org.junit.Before; 13 import org.junit.Before;
14 import org.junit.Rule; 14 import org.junit.Rule;
15 import org.junit.Test; 15 import org.junit.Test;
16 import org.junit.runner.RunWith; 16 import org.junit.runner.RunWith;
17 17
18 import org.chromium.base.ApplicationStatus;
18 import org.chromium.base.metrics.RecordHistogram; 19 import org.chromium.base.metrics.RecordHistogram;
19 import org.chromium.base.test.util.CommandLineFlags; 20 import org.chromium.base.test.util.CommandLineFlags;
20 import org.chromium.base.test.util.Feature; 21 import org.chromium.base.test.util.Feature;
21 import org.chromium.base.test.util.ScalableTimeout; 22 import org.chromium.base.test.util.ScalableTimeout;
22 import org.chromium.chrome.browser.ChromeActivity; 23 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;
(...skipping 10 matching lines...) Expand all
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 ChromeActivity activity =
128 (ChromeActivity) ApplicationStatus.getLastTrackedFocused Activity();
130 return activity instanceof CustomTabActivity 129 return activity instanceof CustomTabActivity
131 && activity.getActivityTab() != null 130 && activity.getActivityTab() != null
132 // Dropping the TLD as Google can redirect to a local si te. 131 // Dropping the TLD as Google can redirect to a local si te.
133 && activity.getActivityTab().getUrl().startsWith("https: //www.google."); 132 && activity.getActivityTab().getUrl().startsWith("https: //www.google.");
134 } 133 }
135 }); 134 });
136 } 135 }
137 136
138 /** 137 /**
139 * Test that on first launch: 138 * Test that on first launch:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 CriteriaHelper.pollUiThread(new Criteria("Deferred startup never complet ed") { 181 CriteriaHelper.pollUiThread(new Criteria("Deferred startup never complet ed") {
183 @Override 182 @Override
184 public boolean isSatisfied() { 183 public boolean isSatisfied() {
185 return DeferredStartupHandler.getInstance().isDeferredStartupCom pleteForApp(); 184 return DeferredStartupHandler.getInstance().isDeferredStartupCom pleteForApp();
186 } 185 }
187 }); 186 });
188 187
189 Assert.assertEquals(1, RecordHistogram.getHistogramTotalCountForTesting( histogramName)); 188 Assert.assertEquals(1, RecordHistogram.getHistogramTotalCountForTesting( histogramName));
190 } 189 }
191 } 190 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698