Commit fd82926d authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[WebLayer] Check URL change behavior in external navigation tests

This CL adds verification of the behavior of the URL display to the
tests of WebLayer's external intent launching:

- When a normal navigation occurs, the displayed URL should be updated
  accordingly.
- When an intent is blocked from launching, the displayed URL should
  remain that of the previous navigation.
- When an intent is launched, the displayed URL should remain that of
  the previous navigation.

This CL also changes the tests so that the navigations to intents are
not the initial navigations in the Tab. The reason is that intent
launching on initial navigations is a special case; we will add
specific tests for that case in a followup. As preparation for those
tests, this CL also moves the launching of the shell into each test
so that the tests explicitly specify whether the shell should be
launched with an initial URL (and hence navigation).

Bug: 1029710, 1031465
Change-Id: I7a5fe59dd3010f3f1d7eceaa7294e121d88cd99e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2120302
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMugdha Lakhani <nator@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753618}
parent 77f34e23
......@@ -11,7 +11,6 @@ import android.support.test.filters.SmallTest;
import android.support.v4.app.Fragment;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -31,6 +30,7 @@ public class ExternalNavigationTest {
public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule();
private static final String ABOUT_BLANK_URL = "about:blank";
private static final String INTENT_TO_CHROME_URL =
"intent://play.google.com/store/apps/details?id=com.facebook.katana/#Intent;scheme=https;action=android.intent.action.VIEW;package=com.android.chrome;end";
......@@ -54,14 +54,6 @@ public class ExternalNavigationTest {
}
}
private IntentInterceptor mIntentInterceptor = new IntentInterceptor();
@Before
public void setUp() throws Exception {
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(null);
activity.setIntentInterceptor(mIntentInterceptor);
}
/**
* Verifies that for a navigation to a URI that WebLayer can handle internally, there
* is no external intent triggered.
......@@ -69,8 +61,17 @@ public class ExternalNavigationTest {
@Test
@SmallTest
public void testBrowserNavigation() throws Throwable {
mActivityTestRule.navigateAndWait("about:blank");
Assert.assertNull(mIntentInterceptor.mLastIntent);
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(ABOUT_BLANK_URL);
IntentInterceptor intentInterceptor = new IntentInterceptor();
activity.setIntentInterceptor(intentInterceptor);
// The test server handles "echo" with a response containing "Echo" :).
String testServerSiteUrl = mActivityTestRule.getTestServer().getURL("/echo");
mActivityTestRule.navigateAndWait(testServerSiteUrl);
Assert.assertNull(intentInterceptor.mLastIntent);
Assert.assertEquals(testServerSiteUrl, mActivityTestRule.getCurrentDisplayUrl());
}
/**
......@@ -80,13 +81,20 @@ public class ExternalNavigationTest {
@Test
@SmallTest
public void testExternalIntentWithNoRedirectBlocked() throws Throwable {
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(ABOUT_BLANK_URL);
IntentInterceptor intentInterceptor = new IntentInterceptor();
activity.setIntentInterceptor(intentInterceptor);
Tab tab = mActivityTestRule.getActivity().getTab();
// Note that this navigation will not result in a paint.
mActivityTestRule.navigateAndWaitForFailure(
tab, INTENT_TO_CHROME_URL, /*waitForPaint=*/false);
Assert.assertNull(mIntentInterceptor.mLastIntent);
Assert.assertNull(intentInterceptor.mLastIntent);
// The current URL should not have changed.
Assert.assertEquals(ABOUT_BLANK_URL, mActivityTestRule.getCurrentDisplayUrl());
}
/**
......@@ -96,6 +104,10 @@ public class ExternalNavigationTest {
@Test
@SmallTest
public void testExternalIntentAfterRedirectLaunched() throws Throwable {
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(ABOUT_BLANK_URL);
IntentInterceptor intentInterceptor = new IntentInterceptor();
activity.setIntentInterceptor(intentInterceptor);
String url = mActivityTestRule.getTestServer().getURL(
"/server-redirect?" + INTENT_TO_CHROME_URL);
......@@ -103,9 +115,11 @@ public class ExternalNavigationTest {
TestThreadUtils.runOnUiThreadBlocking(
() -> { tab.getNavigationController().navigate(Uri.parse(url)); });
mIntentInterceptor.waitForIntent();
intentInterceptor.waitForIntent();
Intent intent = mIntentInterceptor.mLastIntent;
// The current URL should not have changed, and the intent should have been launched.
Assert.assertEquals(ABOUT_BLANK_URL, mActivityTestRule.getCurrentDisplayUrl());
Intent intent = intentInterceptor.mLastIntent;
Assert.assertNotNull(intent);
Assert.assertEquals("com.android.chrome", intent.getPackage());
Assert.assertEquals("android.intent.action.VIEW", intent.getAction());
......
......@@ -28,6 +28,7 @@ import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.net.test.EmbeddedTestServerRule;
import org.chromium.weblayer.NavigationController;
import org.chromium.weblayer.Tab;
import org.chromium.weblayer.WebLayer;
import org.chromium.weblayer.shell.InstrumentationActivity;
......@@ -259,6 +260,15 @@ public class InstrumentationActivityTestRule extends ActivityTestRule<Instrument
return getTestServer().getURL("/weblayer/test/data/" + path);
}
public String getCurrentDisplayUrl() {
return TestThreadUtils.runOnUiThreadBlockingNoException(() -> {
NavigationController navController = getActivity().getTab().getNavigationController();
return navController
.getNavigationEntryDisplayUri(navController.getNavigationListCurrentIndex())
.toString();
});
}
public void setRetainInstance(boolean retain) {
TestThreadUtils.runOnUiThreadBlocking(() -> getActivity().setRetainInstance(retain));
}
......
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