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

Unified 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: Fix 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebApkIntegrationTest.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappNavigationTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappNavigationTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappNavigationTest.java
index e7e96e3981a3be8c16abb453cbc2043f0370ddd9..dd530aee05ff64093f3c7901e092116bc08c382c 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappNavigationTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappNavigationTest.java
@@ -4,6 +4,11 @@
package org.chromium.chrome.browser.webapps;
+import static org.chromium.base.ApplicationState.HAS_DESTROYED_ACTIVITIES;
+import static org.chromium.base.ApplicationState.HAS_PAUSED_ACTIVITIES;
+import static org.chromium.base.ApplicationState.HAS_STOPPED_ACTIVITIES;
+
+import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.support.test.InstrumentationRegistry;
@@ -17,6 +22,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.ApiCompatibilityUtils;
+import org.chromium.base.ApplicationStatus;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
@@ -24,9 +30,13 @@ import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
+import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.OverrideUrlLoadingResult;
import org.chromium.chrome.browser.firstrun.FirstRunStatus;
+import org.chromium.chrome.browser.tab.InterceptNavigationDelegateImpl;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils;
+import org.chromium.content.browser.test.util.Criteria;
+import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.DOMUtils;
import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.ui.base.PageTransition;
@@ -37,6 +47,7 @@ import org.chromium.ui.base.PageTransition;
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class WebappNavigationTest {
+ private static final String YOUTUBE_URL = "https://www.youtube.com/watch?v=EYmjoW4vIX8";
private static final String OFF_ORIGIN_URL = "https://www.google.com/";
private static final String WEB_APP_PATH = "/chrome/test/data/banners/manifest_test_page.html";
private static final String IN_SCOPE_PAGE_PATH =
@@ -45,9 +56,6 @@ public class WebappNavigationTest {
@Rule
public final WebappActivityTestRule mActivityTestRule = new WebappActivityTestRule();
- @Rule
- public final TopActivityListener activityListener = new TopActivityListener();
-
private EmbeddedTestServer mTestServer;
@Before
@@ -120,7 +128,7 @@ public class WebappNavigationTest {
addAnchor("testId", mTestServer.getURL(IN_SCOPE_PAGE_PATH), "_blank");
DOMUtils.clickNode(
mActivityTestRule.getActivity().getActivityTab().getContentViewCore(), "testId");
- CustomTabActivity customTab = activityListener.waitFor(CustomTabActivity.class);
+ CustomTabActivity customTab = waitFor(CustomTabActivity.class);
mActivityTestRule.waitUntilIdle(customTab);
Assert.assertTrue(
mActivityTestRule.runJavaScriptCodeInCurrentTab("document.body.textContent")
@@ -169,7 +177,7 @@ public class WebappNavigationTest {
otherPageUrl, mActivityTestRule.getActivity().getActivityTab().getUrl());
Assert.assertSame(
- mActivityTestRule.getActivity(), activityListener.getMostRecentActivity());
+ mActivityTestRule.getActivity(), ApplicationStatus.getLastTrackedFocusedActivity());
}
@Test
@@ -187,13 +195,44 @@ public class WebappNavigationTest {
mActivityTestRule.getActivity().getActivityTab(), "myTestAnchorId",
R.id.menu_id_open_in_chrome);
- ChromeTabbedActivity tabbedChrome = activityListener.waitFor(ChromeTabbedActivity.class);
+ ChromeTabbedActivity tabbedChrome = waitFor(ChromeTabbedActivity.class);
mActivityTestRule.waitUntilIdle(tabbedChrome);
// Dropping the TLD as Google can redirect to a local site, so this could fail outside US.
Assert.assertTrue(tabbedChrome.getActivityTab().getUrl().startsWith("https://www.google."));
}
+ @Test
+ @SmallTest
+ @Feature({"Webapps"})
+ public void testRegularLinkToExternalApp() throws Exception {
+ runWebappActivityAndWaitForIdle(mActivityTestRule.createIntent());
+
+ InterceptNavigationDelegateImpl navigationDelegate =
+ mActivityTestRule.getActivity().getActivityTab().getInterceptNavigationDelegate();
+
+ addAnchor("testLink", YOUTUBE_URL, "_self");
+ DOMUtils.clickNode(
+ mActivityTestRule.getActivity().getActivityTab().getContentViewCore(), "testLink");
+
+ waitForExternalAppOrIntentPicker();
+ Assert.assertEquals(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT,
+ navigationDelegate.getLastOverrideUrlLoadingResultForTests());
+ }
+
+ @Test
+ @SmallTest
+ @Feature({"Webapps"})
+ public void testNewTabLinkToExternalApp() throws Exception {
+ runWebappActivityAndWaitForIdle(mActivityTestRule.createIntent());
+
+ addAnchor("testLink", YOUTUBE_URL, "_blank");
+ DOMUtils.clickNode(
+ mActivityTestRule.getActivity().getActivityTab().getContentViewCore(), "testLink");
+
+ waitForExternalAppOrIntentPicker();
+ }
+
private void runWebappActivityAndWaitForIdle(Intent intent) throws Exception {
mActivityTestRule.startWebappActivity(
intent.putExtra(ShortcutHelper.EXTRA_URL, mTestServer.getURL(WEB_APP_PATH)));
@@ -203,7 +242,7 @@ public class WebappNavigationTest {
}
private CustomTabActivity assertCustomTabActivityLaunchedForOffOriginUrl() {
- CustomTabActivity customTab = activityListener.waitFor(CustomTabActivity.class);
+ CustomTabActivity customTab = waitFor(CustomTabActivity.class);
mActivityTestRule.waitUntilIdle(customTab);
// Dropping the TLD as Google can redirect to a local site, so this could fail outside US.
@@ -222,4 +261,28 @@ public class WebappNavigationTest {
+ "document.body.appendChild(aTag);",
id, url, target));
}
+
+ @SuppressWarnings("unchecked")
+ private <T extends Activity> T waitFor(final Class<T> expectedClass) {
+ final Activity[] holder = new Activity[1];
+ CriteriaHelper.pollUiThread(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ holder[0] = ApplicationStatus.getLastTrackedFocusedActivity();
+ return holder[0] != null && expectedClass.isAssignableFrom(holder[0].getClass());
+ }
+ });
+ return (T) holder[0];
+ }
+
+ private void waitForExternalAppOrIntentPicker() {
+ CriteriaHelper.pollUiThread(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return ApplicationStatus.getStateForApplication() == HAS_PAUSED_ACTIVITIES
+ || ApplicationStatus.getStateForApplication() == HAS_STOPPED_ACTIVITIES
+ || ApplicationStatus.getStateForApplication() == HAS_DESTROYED_ACTIVITIES;
+ }
+ });
+ }
}
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebApkIntegrationTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698