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

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

Powered by Google App Engine
This is Rietveld 408576698