OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.webapps; | 5 package org.chromium.chrome.browser.webapps; |
6 | 6 |
7 import android.content.Intent; | 7 import android.content.Intent; |
8 import android.support.test.InstrumentationRegistry; | 8 import android.support.test.InstrumentationRegistry; |
9 import android.support.test.filters.LargeTest; | 9 import android.support.test.filters.LargeTest; |
10 | 10 |
11 import org.junit.After; | 11 import org.junit.After; |
12 import org.junit.Before; | 12 import org.junit.Before; |
13 import org.junit.Rule; | 13 import org.junit.Rule; |
14 import org.junit.Test; | 14 import org.junit.Test; |
15 import org.junit.runner.RunWith; | 15 import org.junit.runner.RunWith; |
16 | 16 |
17 import org.chromium.base.test.util.CommandLineFlags; | 17 import org.chromium.base.test.util.CommandLineFlags; |
18 import org.chromium.base.test.util.Feature; | 18 import org.chromium.base.test.util.Feature; |
19 import org.chromium.base.test.util.RetryOnFailure; | 19 import org.chromium.base.test.util.RetryOnFailure; |
20 import org.chromium.base.test.util.ScalableTimeout; | 20 import org.chromium.base.test.util.ScalableTimeout; |
| 21 import org.chromium.chrome.browser.ChromeActivity; |
21 import org.chromium.chrome.browser.ChromeSwitches; | 22 import org.chromium.chrome.browser.ChromeSwitches; |
22 import org.chromium.chrome.browser.ShortcutHelper; | 23 import org.chromium.chrome.browser.ShortcutHelper; |
| 24 import org.chromium.chrome.browser.customtabs.CustomTabActivity; |
23 import org.chromium.chrome.test.ChromeActivityTestRule; | 25 import org.chromium.chrome.test.ChromeActivityTestRule; |
24 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; | 26 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
25 import org.chromium.chrome.test.util.ChromeTabUtils; | 27 import org.chromium.chrome.test.util.ChromeTabUtils; |
26 import org.chromium.content.browser.test.util.Criteria; | 28 import org.chromium.content.browser.test.util.Criteria; |
27 import org.chromium.content.browser.test.util.CriteriaHelper; | 29 import org.chromium.content.browser.test.util.CriteriaHelper; |
28 import org.chromium.net.test.EmbeddedTestServer; | 30 import org.chromium.net.test.EmbeddedTestServer; |
29 import org.chromium.webapk.lib.common.WebApkConstants; | 31 import org.chromium.webapk.lib.common.WebApkConstants; |
30 | 32 |
31 /** Integration tests for WebAPK feature. */ | 33 /** Integration tests for WebAPK feature. */ |
32 @RunWith(ChromeJUnit4ClassRunner.class) | 34 @RunWith(ChromeJUnit4ClassRunner.class) |
33 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, | 35 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
34 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) | 36 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
35 public class WebApkIntegrationTest { | 37 public class WebApkIntegrationTest { |
36 @Rule | 38 @Rule |
37 public final ChromeActivityTestRule<WebApkActivity> mActivityTestRule = | 39 public final ChromeActivityTestRule<WebApkActivity> mActivityTestRule = |
38 new ChromeActivityTestRule<>(WebApkActivity.class); | 40 new ChromeActivityTestRule<>(WebApkActivity.class); |
39 | 41 |
| 42 @Rule |
| 43 public final TopActivityListener activityListener = new TopActivityListener(
); |
| 44 |
40 private static final long STARTUP_TIMEOUT = ScalableTimeout.scaleTimeout(100
00); | 45 private static final long STARTUP_TIMEOUT = ScalableTimeout.scaleTimeout(100
00); |
41 | 46 |
42 private EmbeddedTestServer mTestServer; | 47 private EmbeddedTestServer mTestServer; |
43 | 48 |
44 public void startWebApkActivity(String webApkPackageName, final String start
Url) | 49 public void startWebApkActivity(String webApkPackageName, final String start
Url) |
45 throws InterruptedException { | 50 throws InterruptedException { |
46 Intent intent = | 51 Intent intent = |
47 new Intent(InstrumentationRegistry.getTargetContext(), WebApkAct
ivity.class); | 52 new Intent(InstrumentationRegistry.getTargetContext(), WebApkAct
ivity.class); |
48 intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackage
Name); | 53 intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackage
Name); |
49 intent.putExtra(ShortcutHelper.EXTRA_URL, startUrl); | 54 intent.putExtra(ShortcutHelper.EXTRA_URL, startUrl); |
50 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 55 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
51 mActivityTestRule.setActivity( | 56 |
| 57 WebApkActivity webApkActivity = |
52 (WebApkActivity) InstrumentationRegistry.getInstrumentation().st
artActivitySync( | 58 (WebApkActivity) InstrumentationRegistry.getInstrumentation().st
artActivitySync( |
53 intent)); | 59 intent); |
| 60 mActivityTestRule.setActivity(webApkActivity); |
54 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); | 61 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
55 | 62 |
56 CriteriaHelper.pollInstrumentationThread(new Criteria() { | 63 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
57 @Override | 64 @Override |
58 public boolean isSatisfied() { | 65 public boolean isSatisfied() { |
59 return mActivityTestRule.getActivity().getActivityTab() != null; | 66 return mActivityTestRule.getActivity().getActivityTab() != null; |
60 } | 67 } |
61 }, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL); | 68 }, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL); |
62 | 69 |
63 ChromeTabUtils.waitForTabPageLoaded( | 70 ChromeTabUtils.waitForTabPageLoaded( |
(...skipping 23 matching lines...) Expand all Loading... |
87 } | 94 } |
88 | 95 |
89 /** | 96 /** |
90 * Test launching a WebAPK. Test that loading the start page works and that
the splashscreen | 97 * Test launching a WebAPK. Test that loading the start page works and that
the splashscreen |
91 * eventually hides. | 98 * eventually hides. |
92 */ | 99 */ |
93 @Test | 100 @Test |
94 @LargeTest | 101 @LargeTest |
95 @Feature({"WebApk"}) | 102 @Feature({"WebApk"}) |
96 @RetryOnFailure | 103 @RetryOnFailure |
97 public void testLaunch() throws InterruptedException { | 104 public void testLaunchAndNavigateOffOrigin() throws Exception { |
98 startWebApkActivity("org.chromium.webapk.test", | 105 startWebApkActivity("org.chromium.webapk.test", |
99 mTestServer.getURL("/chrome/test/data/android/test.html")); | 106 mTestServer.getURL("/chrome/test/data/android/test.html")); |
100 waitUntilSplashscreenHides(); | 107 waitUntilSplashscreenHides(); |
| 108 |
| 109 // We navigate outside origin and expect Custom Tab to open on top of We
bApkActivity. |
| 110 mActivityTestRule.runJavaScriptCodeInCurrentTab( |
| 111 "window.top.location = 'https://www.google.com/'"); |
| 112 |
| 113 CriteriaHelper.pollUiThread(new Criteria() { |
| 114 @Override |
| 115 public boolean isSatisfied() { |
| 116 ChromeActivity activity = (ChromeActivity) activityListener.getM
ostRecentActivity(); |
| 117 return activity instanceof CustomTabActivity |
| 118 && activity.getActivityTab() != null |
| 119 // Dropping the TLD as Google can redirect to a local si
te. |
| 120 && activity.getActivityTab().getUrl().startsWith("https:
//www.google."); |
| 121 } |
| 122 }); |
101 } | 123 } |
102 } | 124 } |
OLD | NEW |