Commit 955b7118 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[WebLayer] Add test of link click to page that launches intent

This CL adds another test of WebLayer's external intent launching:

When the user clicks a link to navigate to a page that then launches an
intent without a user gesture (e.g., via onLoad()), the intent is
launched. This case differs from that of the user navigating to said
page directly via typing; once Weblayer incorporates //chrome's
TabRedirectHandler the latter will be blocked by policy, but the former
(the behavior being tested in this CL) is supported by Chrome and should
be supported by WebLayer as well.

Bug: 1031465
Change-Id: I58e1fc7bbde9fc6235606523f06797a7877bb108
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2132385
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMugdha Lakhani <nator@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756183}
parent 6f1472c4
...@@ -48,7 +48,7 @@ public class ExternalNavigationHandler { ...@@ -48,7 +48,7 @@ public class ExternalNavigationHandler {
private static final String TAG = "UrlHandler"; private static final String TAG = "UrlHandler";
// Enables debug logging on a local build. // Enables debug logging on a local build.
private static final boolean DEBUG = false; private static final boolean DEBUG = true;
private static final String WTAI_URL_PREFIX = "wtai://wp/"; private static final String WTAI_URL_PREFIX = "wtai://wp/";
private static final String WTAI_MC_URL_PREFIX = "wtai://wp/mc;"; private static final String WTAI_MC_URL_PREFIX = "wtai://wp/mc;";
......
...@@ -61,6 +61,8 @@ public class ExternalNavigationTest { ...@@ -61,6 +61,8 @@ public class ExternalNavigationTest {
"link_with_intent_to_chrome_in_new_tab.html"; "link_with_intent_to_chrome_in_new_tab.html";
private static final String PAGE_THAT_INTENTS_TO_CHROME_ON_LOAD_FILE = private static final String PAGE_THAT_INTENTS_TO_CHROME_ON_LOAD_FILE =
"page_that_intents_to_chrome_on_load.html"; "page_that_intents_to_chrome_on_load.html";
private static final String LINK_TO_PAGE_THAT_INTENTS_TO_CHROME_ON_LOAD_FILE =
"link_to_page_that_intents_to_chrome_on_load.html";
// The test server handles "echo" with a response containing "Echo" :). // The test server handles "echo" with a response containing "Echo" :).
private final String mTestServerSiteUrl = mActivityTestRule.getTestServer().getURL("/echo"); private final String mTestServerSiteUrl = mActivityTestRule.getTestServer().getURL("/echo");
...@@ -395,4 +397,50 @@ public class ExternalNavigationTest { ...@@ -395,4 +397,50 @@ public class ExternalNavigationTest {
Assert.assertEquals(INTENT_TO_CHROME_ACTION, intent.getAction()); Assert.assertEquals(INTENT_TO_CHROME_ACTION, intent.getAction());
Assert.assertEquals(INTENT_TO_CHROME_DATA_STRING, intent.getDataString()); Assert.assertEquals(INTENT_TO_CHROME_DATA_STRING, intent.getDataString());
} }
/**
* Tests the following flow:
* - The user clicks on a link
* - This link goes to a page that loads a handleable intent in onload()
* This flow should result in the external intent being launched rather than blocked,
* because the initial navigation to the page did not occur via user typing.
*/
@Test
@SmallTest
public void testUserClicksLinkToPageWithExternalIntentLaunchedViaOnLoad() throws Throwable {
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(ABOUT_BLANK_URL);
IntentInterceptor intentInterceptor = new IntentInterceptor();
activity.setIntentInterceptor(intentInterceptor);
String url =
mActivityTestRule.getTestDataURL(LINK_TO_PAGE_THAT_INTENTS_TO_CHROME_ON_LOAD_FILE);
mActivityTestRule.navigateAndWait(url);
// Clicking on the link on this page should result in a navigation to the page that loads an
// intent in onLoad(), followed by a launching of that intent.
Tab tab = mActivityTestRule.getActivity().getTab();
String finalUrl =
mActivityTestRule.getTestDataURL(PAGE_THAT_INTENTS_TO_CHROME_ON_LOAD_FILE);
NavigationWaiter waiter =
new NavigationWaiter(finalUrl, tab, /*expectFailure=*/false, /*waitForPaint=*/true);
mActivityTestRule.executeScriptSync(
"document.onclick = function() {document.getElementById('link').click()}",
true /* useSeparateIsolate */);
EventUtils.simulateTouchCenterOfView(
mActivityTestRule.getActivity().getWindow().getDecorView());
waiter.waitForNavigation();
intentInterceptor.waitForIntent();
// The current URL should not have changed, and the intent should have been launched.
Assert.assertEquals(finalUrl, mActivityTestRule.getCurrentDisplayUrl());
Intent intent = intentInterceptor.mLastIntent;
Assert.assertNotNull(intent);
Assert.assertEquals(INTENT_TO_CHROME_PACKAGE, intent.getPackage());
Assert.assertEquals(INTENT_TO_CHROME_ACTION, intent.getAction());
Assert.assertEquals(INTENT_TO_CHROME_DATA_STRING, intent.getDataString());
}
} }
<!DOCTYPE html>
<html>
<head>
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
</head>
<body>
<a id='link' href='/weblayer/test/data/page_that_intents_to_chrome_on_load.html'>
Click to go to page that intents to Chrome on load
</a>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment