Index: chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebApkIntegrationTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebApkIntegrationTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebApkIntegrationTest.java |
index afa5078c503317197ce212e0abd4d253d9f32af9..e74b1e38a0600a49143309eb79778644c5ba83bc 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebApkIntegrationTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebApkIntegrationTest.java |
@@ -9,6 +9,7 @@ import android.support.test.InstrumentationRegistry; |
import android.support.test.filters.LargeTest; |
import org.junit.After; |
+import org.junit.Assert; |
import org.junit.Before; |
import org.junit.Rule; |
import org.junit.Test; |
@@ -18,8 +19,10 @@ import org.chromium.base.test.util.CommandLineFlags; |
import org.chromium.base.test.util.Feature; |
import org.chromium.base.test.util.RetryOnFailure; |
import org.chromium.base.test.util.ScalableTimeout; |
+import org.chromium.chrome.browser.ChromeActivity; |
import org.chromium.chrome.browser.ChromeSwitches; |
import org.chromium.chrome.browser.ShortcutHelper; |
+import org.chromium.chrome.browser.customtabs.CustomTabActivity; |
import org.chromium.chrome.test.ChromeActivityTestRule; |
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
import org.chromium.chrome.test.util.ChromeTabUtils; |
@@ -37,6 +40,9 @@ public class WebApkIntegrationTest { |
public final ChromeActivityTestRule<WebApkActivity> mActivityTestRule = |
new ChromeActivityTestRule<>(WebApkActivity.class); |
+ @Rule |
+ public final TopActivityListener activityListener = new TopActivityListener(); |
+ |
private static final long STARTUP_TIMEOUT = ScalableTimeout.scaleTimeout(10000); |
private EmbeddedTestServer mTestServer; |
@@ -48,9 +54,13 @@ public class WebApkIntegrationTest { |
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackageName); |
intent.putExtra(ShortcutHelper.EXTRA_URL, startUrl); |
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
- mActivityTestRule.setActivity( |
+ |
+ WebApkActivity webApkActivity = |
(WebApkActivity) InstrumentationRegistry.getInstrumentation().startActivitySync( |
- intent)); |
+ intent); |
+ webApkActivity.mWebappInfo.setScopeForTest( |
+ startUrl.substring(0, startUrl.lastIndexOf('/') + 1)); |
+ mActivityTestRule.setActivity(webApkActivity); |
InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
CriteriaHelper.pollInstrumentationThread(new Criteria() { |
@@ -94,9 +104,41 @@ public class WebApkIntegrationTest { |
@LargeTest |
@Feature({"WebApk"}) |
@RetryOnFailure |
- public void testLaunch() throws InterruptedException { |
+ public void testLaunchAndNavigateOffOrigin() throws Exception { |
startWebApkActivity("org.chromium.webapk.test", |
mTestServer.getURL("/chrome/test/data/android/test.html")); |
waitUntilSplashscreenHides(); |
+ |
+ WebApkActivity webApkActivity = mActivityTestRule.getActivity(); |
+ waitForFinishLoading(webApkActivity); |
+ |
+ Assert.assertSame(webApkActivity, activityListener.getMostRecentActivity()); |
+ Assert.assertEquals(mTestServer.getURL("/chrome/test/data/android/test.html"), |
+ webApkActivity.getActivityTab().getUrl()); |
+ |
+ // We navigate outside origin and expect Custom Tab to open on top of WebApkActivity. |
+ mActivityTestRule.runJavaScriptCodeInCurrentTab( |
+ "window.top.location = 'https://www.google.com/'"); |
+ |
+ activityListener.waitFor(CustomTabActivity.class); |
+ |
+ final CustomTabActivity customTab = |
+ (CustomTabActivity) activityListener.getMostRecentActivity(); |
+ |
+ waitForFinishLoading(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.")); |
+ } |
+ |
+ private void waitForFinishLoading(final ChromeActivity chromeActivity) { |
+ CriteriaHelper.pollInstrumentationThread(new Criteria() { |
+ @Override |
+ public boolean isSatisfied() { |
+ return chromeActivity.getActivityTab() != null |
+ && !chromeActivity.getActivityTab().isLoading(); |
+ } |
+ }, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL); |
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
} |
} |