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

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

Issue 2950483002: Revert "Redirects _blank and window.open() off-origin navigation from PWA to CCT." (Closed)
Patch Set: Created 3 years, 6 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
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 6d234b88004f0f0f985fb0cad01612564b120652..25c476d3e882f4f5b40a3162092de4336ed36f44 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,12 +4,8 @@
package org.chromium.chrome.browser.webapps;
-import android.app.ActivityManager;
-import android.app.ActivityManager.AppTask;
-import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
-import android.os.Build;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
@@ -21,6 +17,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.ApiCompatibilityUtils;
+import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
@@ -31,7 +28,7 @@ import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.firstrun.FirstRunStatus;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils;
-import org.chromium.content.browser.test.util.DOMUtils;
+import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.ui.base.PageTransition;
@@ -67,12 +64,18 @@ public class WebappNavigationTest {
@Test
@SmallTest
@Feature({"Webapps"})
- public void testRegularLinkOffOriginInCctNoWebappThemeColor() throws Exception {
+ public void testOffOriginNavigationUsingLinkAndNoWebappThemeColor() throws Exception {
runWebappActivityAndWaitForIdle(mActivityTestRule.createIntent());
- assertNumberOfTasksInRecents("We should start with one Android task", 1);
- addAnchor("testId", OFF_ORIGIN_URL, "_self");
- DOMUtils.clickNode(
- mActivityTestRule.getActivity().getActivityTab().getContentViewCore(), "testId");
+
+ // Not using #loadUrl, as it expects the URL to load in the activity under test,
+ // which is not happening here.
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ mActivityTestRule.getActivity().getActivityTab().loadUrl(
+ new LoadUrlParams(OFF_ORIGIN_URL, PageTransition.LINK));
+ }
+ });
CustomTabActivity customTab = assertCustomTabActivityLaunchedForOffOriginUrl();
@@ -81,17 +84,14 @@ public class WebappNavigationTest {
ApiCompatibilityUtils.getColor(
customTab.getResources(), R.color.default_primary_color),
customTab.getToolbarManager().getPrimaryColor());
- assertNumberOfTasksInRecents(
- "Link with target=\"_self\" should stay in the same Android task.", 1);
}
@Test
@SmallTest
@Feature({"Webapps"})
- public void testWindowTopLocationOffOriginInCctAndWebappThemeColor() throws Exception {
+ public void testOffOriginNavigationUsingJavaScriptAndWebappThemeColor() throws Exception {
runWebappActivityAndWaitForIdle(mActivityTestRule.createIntent().putExtra(
ShortcutHelper.EXTRA_THEME_COLOR, (long) Color.CYAN));
- assertNumberOfTasksInRecents("We should start with one Android task", 1);
mActivityTestRule.runJavaScriptCodeInCurrentTab(
String.format("window.top.location = '%s'", OFF_ORIGIN_URL));
@@ -100,58 +100,16 @@ public class WebappNavigationTest {
Assert.assertEquals("CCT Toolbar should use the theme color of a webapp", Color.CYAN,
customTab.getToolbarManager().getPrimaryColor());
- assertNumberOfTasksInRecents(
- "Executing window.top.location = url; should stay in the same Android task.", 1);
}
- @Test
- @SmallTest
- @Feature({"Webapps"})
- public void testNewTabLinkOpensInCct() throws Exception {
- runWebappActivityAndWaitForIdle(mActivityTestRule.createIntent().putExtra(
- ShortcutHelper.EXTRA_THEME_COLOR, (long) Color.CYAN));
- assertNumberOfTasksInRecents("We should start with one Android task", 1);
- addAnchor("testId", OFF_ORIGIN_URL, "_blank");
- DOMUtils.clickNode(
- mActivityTestRule.getActivity().getActivityTab().getContentViewCore(), "testId");
- CustomTabActivity customTab = assertCustomTabActivityLaunchedForOffOriginUrl();
- Assert.assertEquals(
- "CCT Toolbar should use default primary color even if webapp has theme color",
- ApiCompatibilityUtils.getColor(
- customTab.getResources(), R.color.default_primary_color),
- customTab.getToolbarManager().getPrimaryColor());
- assertNumberOfTasksInRecents(
- "Link with target=\"_blank\" should open in a new Android task.", 2);
- }
+ private CustomTabActivity assertCustomTabActivityLaunchedForOffOriginUrl() {
+ CustomTabActivity customTab = activityListener.waitFor(CustomTabActivity.class);
- @Test
- @SmallTest
- @Feature({"Webapps"})
- public void testWindowOpenInCct() throws Exception {
- runWebappActivityAndWaitForIdle(mActivityTestRule.createIntent());
- assertNumberOfTasksInRecents("We should start with one Android task", 1);
- // Executing window.open() through a click on a link,
- // as it needs user gesture to avoid Chrome blocking it as a popup.
- mActivityTestRule.runJavaScriptCodeInCurrentTab(
- String.format("var aTag = document.createElement('testId');"
- + "aTag.id = 'testId';"
- + "aTag.innerHTML = 'Click Me!';"
- + "aTag.onclick = function() {"
- + " window.open('%s');"
- + " return false;"
- + "};"
- + "document.body.appendChild(aTag);",
- OFF_ORIGIN_URL));
- DOMUtils.clickNode(
- mActivityTestRule.getActivity().getActivityTab().getContentViewCore(), "testId");
+ mActivityTestRule.waitUntilIdle(customTab);
+ // Dropping the TLD as Google can redirect to a local site, so this could fail outside US.
+ Assert.assertTrue(customTab.getActivityTab().getUrl().startsWith("https://www.google."));
- CustomTabActivity customTab = assertCustomTabActivityLaunchedForOffOriginUrl();
- Assert.assertEquals("CCT Toolbar should use default primary color",
- ApiCompatibilityUtils.getColor(
- customTab.getResources(), R.color.default_primary_color),
- customTab.getToolbarManager().getPrimaryColor());
- assertNumberOfTasksInRecents(
- "Executing window.open(url) should open a new Android task.", 2);
+ return customTab;
}
@Test
@@ -180,7 +138,11 @@ public class WebappNavigationTest {
FirstRunStatus.setFirstRunFlowComplete(true);
runWebappActivityAndWaitForIdle(mActivityTestRule.createIntent());
- addAnchor("myTestAnchorId", OFF_ORIGIN_URL, "_self");
+ mActivityTestRule.runJavaScriptCodeInCurrentTab("var aTag = document.createElement('a');"
+ + "aTag.id = 'myTestAnchorId';"
+ + "aTag.setAttribute('href','https://www.google.com/');"
+ + "aTag.innerHTML = 'Click Me!';"
+ + "document.body.appendChild(aTag);");
ContextMenuUtils.selectContextMenuItem(InstrumentationRegistry.getInstrumentation(),
null /* activity to check for focus after click */,
@@ -201,45 +163,4 @@ public class WebappNavigationTest {
mActivityTestRule.waitUntilSplashscreenHides();
mActivityTestRule.waitUntilIdle();
}
-
- private CustomTabActivity assertCustomTabActivityLaunchedForOffOriginUrl() {
- CustomTabActivity customTab = activityListener.waitFor(CustomTabActivity.class);
-
- mActivityTestRule.waitUntilIdle(customTab);
- // Dropping the TLD as Google can redirect to a local site, so this could fail outside US.
- Assert.assertTrue(customTab.getActivityTab().getUrl().contains("https://www.google."));
-
- return customTab;
- }
-
- private void addAnchor(String id, String url, String target) throws Exception {
- mActivityTestRule.runJavaScriptCodeInCurrentTab(
- String.format("var aTag = document.createElement('a');"
- + "aTag.id = '%s';"
- + "aTag.setAttribute('href','%s');"
- + "aTag.setAttribute('target','%s');"
- + "aTag.innerHTML = 'Click Me!';"
- + "document.body.appendChild(aTag);",
- id, url, target));
- }
-
- private void assertNumberOfTasksInRecents(String message, int expectedNumberOfTasks) {
- // We only have API to check this since Lollipop.
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;
-
- ActivityManager activityManager =
- (ActivityManager) mActivityTestRule.getActivity().getSystemService(
- Context.ACTIVITY_SERVICE);
-
- int count = 0;
- for (AppTask task : activityManager.getAppTasks()) {
- if ((task.getTaskInfo().baseIntent.getFlags()
- & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
- == 0) {
- count++;
- }
- }
-
- Assert.assertEquals(message, expectedNumberOfTasks, count);
- }
}

Powered by Google App Engine
This is Rietveld 408576698