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

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

Issue 2969143002: Fixes redirects to external apps when navigating from PWA. (Closed)
Patch Set: Merge 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.graphics.Color; 8 import android.graphics.Color;
9 import android.support.test.InstrumentationRegistry; 9 import android.support.test.InstrumentationRegistry;
10 import android.support.test.filters.SmallTest; 10 import android.support.test.filters.SmallTest;
11 11
12 import org.junit.After; 12 import org.junit.After;
13 import org.junit.Assert; 13 import org.junit.Assert;
14 import org.junit.Before; 14 import org.junit.Before;
15 import org.junit.Rule; 15 import org.junit.Rule;
16 import org.junit.Test; 16 import org.junit.Test;
17 import org.junit.runner.RunWith; 17 import org.junit.runner.RunWith;
18 18
19 import org.chromium.base.ApiCompatibilityUtils; 19 import org.chromium.base.ApiCompatibilityUtils;
20 import org.chromium.base.test.util.CommandLineFlags; 20 import org.chromium.base.test.util.CommandLineFlags;
21 import org.chromium.base.test.util.Feature; 21 import org.chromium.base.test.util.Feature;
22 import org.chromium.chrome.R; 22 import org.chromium.chrome.R;
23 import org.chromium.chrome.browser.ChromeSwitches; 23 import org.chromium.chrome.browser.ChromeSwitches;
24 import org.chromium.chrome.browser.ChromeTabbedActivity; 24 import org.chromium.chrome.browser.ChromeTabbedActivity;
25 import org.chromium.chrome.browser.ShortcutHelper; 25 import org.chromium.chrome.browser.ShortcutHelper;
26 import org.chromium.chrome.browser.customtabs.CustomTabActivity; 26 import org.chromium.chrome.browser.customtabs.CustomTabActivity;
27 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid eUrlLoadingResult;
27 import org.chromium.chrome.browser.firstrun.FirstRunStatus; 28 import org.chromium.chrome.browser.firstrun.FirstRunStatus;
29 import org.chromium.chrome.browser.tab.InterceptNavigationDelegateImpl;
28 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; 30 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
29 import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils; 31 import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils;
30 import org.chromium.content.browser.test.util.DOMUtils; 32 import org.chromium.content.browser.test.util.DOMUtils;
31 import org.chromium.net.test.EmbeddedTestServer; 33 import org.chromium.net.test.EmbeddedTestServer;
32 import org.chromium.ui.base.PageTransition; 34 import org.chromium.ui.base.PageTransition;
33 35
34 /** 36 /**
35 * Tests web navigations originating from a WebappActivity. 37 * Tests web navigations originating from a WebappActivity.
36 */ 38 */
37 @RunWith(ChromeJUnit4ClassRunner.class) 39 @RunWith(ChromeJUnit4ClassRunner.class)
38 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) 40 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
39 public class WebappNavigationTest { 41 public class WebappNavigationTest {
42 private static final String YOUTUBE_URL = "https://www.youtube.com/watch?v=E YmjoW4vIX8";
40 private static final String OFF_ORIGIN_URL = "https://www.google.com/"; 43 private static final String OFF_ORIGIN_URL = "https://www.google.com/";
41 private static final String WEB_APP_PATH = "/chrome/test/data/banners/manife st_test_page.html"; 44 private static final String WEB_APP_PATH = "/chrome/test/data/banners/manife st_test_page.html";
42 private static final String IN_SCOPE_PAGE_PATH = 45 private static final String IN_SCOPE_PAGE_PATH =
43 "/chrome/test/data/banners/manifest_no_service_worker.html"; 46 "/chrome/test/data/banners/manifest_no_service_worker.html";
44 47
45 @Rule 48 @Rule
46 public final WebappActivityTestRule mActivityTestRule = new WebappActivityTe stRule(); 49 public final WebappActivityTestRule mActivityTestRule = new WebappActivityTe stRule();
47 50
48 @Rule 51 @Rule
49 public final TopActivityListener activityListener = new TopActivityListener( ); 52 public final TopActivityListener activityListener = new TopActivityListener( );
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 mActivityTestRule.getActivity().getActivityTab(), "myTestAnchorI d", 190 mActivityTestRule.getActivity().getActivityTab(), "myTestAnchorI d",
188 R.id.menu_id_open_in_chrome); 191 R.id.menu_id_open_in_chrome);
189 192
190 ChromeTabbedActivity tabbedChrome = activityListener.waitFor(ChromeTabbe dActivity.class); 193 ChromeTabbedActivity tabbedChrome = activityListener.waitFor(ChromeTabbe dActivity.class);
191 194
192 mActivityTestRule.waitUntilIdle(tabbedChrome); 195 mActivityTestRule.waitUntilIdle(tabbedChrome);
193 // Dropping the TLD as Google can redirect to a local site, so this coul d fail outside US. 196 // Dropping the TLD as Google can redirect to a local site, so this coul d fail outside US.
194 Assert.assertTrue(tabbedChrome.getActivityTab().getUrl().startsWith("htt ps://www.google.")); 197 Assert.assertTrue(tabbedChrome.getActivityTab().getUrl().startsWith("htt ps://www.google."));
195 } 198 }
196 199
200 @Test
201 @SmallTest
202 @Feature({"Webapps"})
203 public void testRegularLinkToExternalApp() throws Exception {
204 runWebappActivityAndWaitForIdle(mActivityTestRule.createIntent());
205
206 InterceptNavigationDelegateImpl navigationDelegate =
207 mActivityTestRule.getActivity().getActivityTab().getInterceptNav igationDelegate();
208
209 addAnchor("testLink", YOUTUBE_URL, "_self");
210 DOMUtils.clickNode(
211 mActivityTestRule.getActivity().getActivityTab().getContentViewC ore(), "testLink");
212
213 activityListener.waitForExternalApp();
214 Assert.assertEquals(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTE NT,
215 navigationDelegate.getLastOverrideUrlLoadingResultForTests());
216 }
217
218 @Test
219 @SmallTest
220 @Feature({"Webapps"})
221 public void testNewTabLinkToExternalApp() throws Exception {
222 runWebappActivityAndWaitForIdle(mActivityTestRule.createIntent());
223
224 addAnchor("testLink", YOUTUBE_URL, "_blank");
225 DOMUtils.clickNode(
226 mActivityTestRule.getActivity().getActivityTab().getContentViewC ore(), "testLink");
227
228 // For _blank anchors, we open the CustomTab which does the redirecting if necessary.
229 CustomTabActivity customTab = activityListener.waitFor(CustomTabActivity .class);
230
231 activityListener.waitForExternalApp();
232
233 InterceptNavigationDelegateImpl navigationDelegate =
234 customTab.getActivityTab().getInterceptNavigationDelegate();
235 Assert.assertEquals(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTE NT,
236 navigationDelegate.getLastOverrideUrlLoadingResultForTests());
237 }
238
197 private void runWebappActivityAndWaitForIdle(Intent intent) throws Exception { 239 private void runWebappActivityAndWaitForIdle(Intent intent) throws Exception {
198 mActivityTestRule.startWebappActivity( 240 mActivityTestRule.startWebappActivity(
199 intent.putExtra(ShortcutHelper.EXTRA_URL, mTestServer.getURL(WEB _APP_PATH))); 241 intent.putExtra(ShortcutHelper.EXTRA_URL, mTestServer.getURL(WEB _APP_PATH)));
200 242
201 mActivityTestRule.waitUntilSplashscreenHides(); 243 mActivityTestRule.waitUntilSplashscreenHides();
202 mActivityTestRule.waitUntilIdle(); 244 mActivityTestRule.waitUntilIdle();
203 } 245 }
204 246
205 private CustomTabActivity assertCustomTabActivityLaunchedForOffOriginUrl() { 247 private CustomTabActivity assertCustomTabActivityLaunchedForOffOriginUrl() {
206 CustomTabActivity customTab = activityListener.waitFor(CustomTabActivity .class); 248 CustomTabActivity customTab = activityListener.waitFor(CustomTabActivity .class);
207 249
208 mActivityTestRule.waitUntilIdle(customTab); 250 mActivityTestRule.waitUntilIdle(customTab);
209 // Dropping the TLD as Google can redirect to a local site, so this coul d fail outside US. 251 // Dropping the TLD as Google can redirect to a local site, so this coul d fail outside US.
210 Assert.assertTrue(customTab.getActivityTab().getUrl().contains("https:// www.google.")); 252 Assert.assertTrue(customTab.getActivityTab().getUrl().contains("https:// www.google."));
211 253
212 return customTab; 254 return customTab;
213 } 255 }
214 256
215 private void addAnchor(String id, String url, String target) throws Exceptio n { 257 private void addAnchor(String id, String url, String target) throws Exceptio n {
216 mActivityTestRule.runJavaScriptCodeInCurrentTab( 258 mActivityTestRule.runJavaScriptCodeInCurrentTab(
217 String.format("var aTag = document.createElement('a');" 259 String.format("var aTag = document.createElement('a');"
218 + "aTag.id = '%s';" 260 + "aTag.id = '%s';"
219 + "aTag.setAttribute('href','%s');" 261 + "aTag.setAttribute('href','%s');"
220 + "aTag.setAttribute('target','%s');" 262 + "aTag.setAttribute('target','%s');"
221 + "aTag.innerHTML = 'Click Me!';" 263 + "aTag.innerHTML = 'Click Me!';"
222 + "document.body.appendChild(aTag);", 264 + "document.body.appendChild(aTag);",
223 id, url, target)); 265 id, url, target));
224 } 266 }
225 } 267 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698