OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.app.Activity; | 7 import android.app.Activity; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.SharedPreferences; | 10 import android.content.SharedPreferences; |
| 11 import android.support.test.InstrumentationRegistry; |
11 import android.support.test.filters.MediumTest; | 12 import android.support.test.filters.MediumTest; |
12 import android.view.View; | 13 import android.view.View; |
13 | 14 |
| 15 import org.junit.After; |
| 16 import org.junit.Assert; |
| 17 import org.junit.Before; |
| 18 import org.junit.Rule; |
| 19 import org.junit.Test; |
| 20 import org.junit.runner.RunWith; |
| 21 |
14 import org.chromium.base.ApplicationStatus; | 22 import org.chromium.base.ApplicationStatus; |
15 import org.chromium.base.ContextUtils; | 23 import org.chromium.base.ContextUtils; |
16 import org.chromium.base.ThreadUtils; | 24 import org.chromium.base.ThreadUtils; |
| 25 import org.chromium.base.test.util.CommandLineFlags; |
17 import org.chromium.base.test.util.Feature; | 26 import org.chromium.base.test.util.Feature; |
18 import org.chromium.base.test.util.RetryOnFailure; | 27 import org.chromium.base.test.util.RetryOnFailure; |
19 import org.chromium.base.test.util.UrlUtils; | 28 import org.chromium.base.test.util.UrlUtils; |
20 import org.chromium.blink_public.platform.WebDisplayMode; | 29 import org.chromium.blink_public.platform.WebDisplayMode; |
21 import org.chromium.chrome.browser.ChromeActivity; | 30 import org.chromium.chrome.browser.ChromeActivity; |
| 31 import org.chromium.chrome.browser.ChromeSwitches; |
22 import org.chromium.chrome.browser.ChromeTabbedActivity; | 32 import org.chromium.chrome.browser.ChromeTabbedActivity; |
23 import org.chromium.chrome.browser.ShortcutHelper; | 33 import org.chromium.chrome.browser.ShortcutHelper; |
24 import org.chromium.chrome.browser.ShortcutSource; | 34 import org.chromium.chrome.browser.ShortcutSource; |
25 import org.chromium.chrome.browser.tab.Tab; | 35 import org.chromium.chrome.browser.tab.Tab; |
26 import org.chromium.chrome.browser.tab.TabIdManager; | 36 import org.chromium.chrome.browser.tab.TabIdManager; |
27 import org.chromium.chrome.test.MultiActivityTestBase; | 37 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| 38 import org.chromium.chrome.test.MultiActivityTestRule; |
28 import org.chromium.chrome.test.util.ActivityUtils; | 39 import org.chromium.chrome.test.util.ActivityUtils; |
29 import org.chromium.chrome.test.util.ApplicationTestUtils; | 40 import org.chromium.chrome.test.util.ApplicationTestUtils; |
30 import org.chromium.chrome.test.util.browser.TabLoadObserver; | 41 import org.chromium.chrome.test.util.browser.TabLoadObserver; |
31 import org.chromium.content.browser.test.util.Criteria; | 42 import org.chromium.content.browser.test.util.Criteria; |
32 import org.chromium.content.browser.test.util.CriteriaHelper; | 43 import org.chromium.content.browser.test.util.CriteriaHelper; |
33 import org.chromium.content.browser.test.util.JavaScriptUtils; | 44 import org.chromium.content.browser.test.util.JavaScriptUtils; |
34 import org.chromium.content.browser.test.util.TouchCommon; | 45 import org.chromium.content.browser.test.util.TouchCommon; |
35 import org.chromium.content_public.common.ScreenOrientationValues; | 46 import org.chromium.content_public.common.ScreenOrientationValues; |
36 import org.chromium.net.test.EmbeddedTestServer; | 47 import org.chromium.net.test.EmbeddedTestServer; |
37 | 48 |
38 /** | 49 /** |
39 * Tests that WebappActivities are launched correctly. | 50 * Tests that WebappActivities are launched correctly. |
40 * | 51 * |
41 * This test seems a little wonky because WebappActivities launched differently,
depending on what | 52 * This test seems a little wonky because WebappActivities launched differently,
depending on what |
42 * OS the user is on. Pre-L, WebappActivities were manually instanced and assig
ned by the | 53 * OS the user is on. Pre-L, WebappActivities were manually instanced and assig
ned by the |
43 * WebappManager. On L and above, WebappActivities are automatically instanced
by Android and the | 54 * WebappManager. On L and above, WebappActivities are automatically instanced
by Android and the |
44 * FLAG_ACTIVITY_NEW_DOCUMENT mechanism. Moreover, we don't have access to the
task list pre-L so | 55 * FLAG_ACTIVITY_NEW_DOCUMENT mechanism. Moreover, we don't have access to the
task list pre-L so |
45 * we have to assume that any non-running WebappActivities are not listed in And
roid's Overview. | 56 * we have to assume that any non-running WebappActivities are not listed in And
roid's Overview. |
46 */ | 57 */ |
| 58 @RunWith(ChromeJUnit4ClassRunner.class) |
| 59 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) |
47 @RetryOnFailure | 60 @RetryOnFailure |
48 public class WebappModeTest extends MultiActivityTestBase { | 61 public class WebappModeTest { |
| 62 @Rule |
| 63 public MultiActivityTestRule mTestRule = new MultiActivityTestRule(); |
| 64 |
49 private static final String WEBAPP_1_ID = "webapp_id_1"; | 65 private static final String WEBAPP_1_ID = "webapp_id_1"; |
50 private static final String WEBAPP_1_URL = UrlUtils.encodeHtmlDataUri( | 66 private static final String WEBAPP_1_URL = UrlUtils.encodeHtmlDataUri( |
51 "<html><head><title>Web app #1</title><meta name='viewport' " | 67 "<html><head><title>Web app #1</title><meta name='viewport' " |
52 + "content='width=device-width initial-scale=0.5, maximum-scale=0.5'
></head>" | 68 + "content='width=device-width initial-scale=0.5, maximum-scale=0.5'
></head>" |
53 + "<body bgcolor='#011684'>Webapp 1</body></html>"); | 69 + "<body bgcolor='#011684'>Webapp 1</body></html>"); |
54 private static final String WEBAPP_1_TITLE = "Web app #1"; | 70 private static final String WEBAPP_1_TITLE = "Web app #1"; |
55 | 71 |
56 private static final String WEBAPP_2_ID = "webapp_id_2"; | 72 private static final String WEBAPP_2_ID = "webapp_id_2"; |
57 private static final String WEBAPP_2_URL = | 73 private static final String WEBAPP_2_URL = |
58 UrlUtils.encodeHtmlDataUri("<html><body bgcolor='#840116'>Webapp 2</
body></html>"); | 74 UrlUtils.encodeHtmlDataUri("<html><body bgcolor='#840116'>Webapp 2</
body></html>"); |
59 private static final String WEBAPP_2_TITLE = "Web app #2"; | 75 private static final String WEBAPP_2_TITLE = "Web app #2"; |
60 | 76 |
61 private static final String WEBAPP_ICON = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABC
AIAAACQd1PeAAAACXB" | 77 private static final String WEBAPP_ICON = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABC
AIAAACQd1PeAAAACXB" |
62 + "IWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wQIFB4cxOfiSQAAABl0RVh0Q29tbWVu
dABDcmVhdGVkIHdpdG" | 78 + "IWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wQIFB4cxOfiSQAAABl0RVh0Q29tbWVu
dABDcmVhdGVkIHdpdG" |
63 + "ggR0lNUFeBDhcAAAAMSURBVAjXY2AUawEAALcAnI/TkI8AAAAASUVORK5CYII="; | 79 + "ggR0lNUFeBDhcAAAAMSURBVAjXY2AUawEAALcAnI/TkI8AAAAASUVORK5CYII="; |
64 | 80 |
65 private EmbeddedTestServer mTestServer; | 81 private EmbeddedTestServer mTestServer; |
66 | 82 |
67 private Intent createIntent(String id, String url, String title, String icon
, boolean addMac) { | 83 private Intent createIntent(String id, String url, String title, String icon
, boolean addMac) { |
68 Intent intent = new Intent(); | 84 Intent intent = new Intent(); |
69 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 85 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
70 intent.setPackage(getInstrumentation().getTargetContext().getPackageName
()); | 86 intent.setPackage( |
| 87 InstrumentationRegistry.getInstrumentation().getTargetContext().
getPackageName()); |
71 intent.setAction(WebappLauncherActivity.ACTION_START_WEBAPP); | 88 intent.setAction(WebappLauncherActivity.ACTION_START_WEBAPP); |
72 if (addMac) { | 89 if (addMac) { |
73 // Needed for security reasons. If the MAC is excluded, the URL of
the webapp is opened | 90 // Needed for security reasons. If the MAC is excluded, the URL of
the webapp is opened |
74 // in a browser window, instead. | 91 // in a browser window, instead. |
75 String mac = ShortcutHelper.getEncodedMac(getInstrumentation().getTa
rgetContext(), url); | 92 String mac = ShortcutHelper.getEncodedMac( |
| 93 InstrumentationRegistry.getInstrumentation().getTargetContex
t(), url); |
76 intent.putExtra(ShortcutHelper.EXTRA_MAC, mac); | 94 intent.putExtra(ShortcutHelper.EXTRA_MAC, mac); |
77 } | 95 } |
78 | 96 |
79 WebappInfo webappInfo = WebappInfo.create(id, url, null, new WebappInfo.
Icon(icon), title, | 97 WebappInfo webappInfo = WebappInfo.create(id, url, null, new WebappInfo.
Icon(icon), title, |
80 null, WebDisplayMode.STANDALONE, ScreenOrientationValues.PORTRAI
T, | 98 null, WebDisplayMode.STANDALONE, ScreenOrientationValues.PORTRAI
T, |
81 ShortcutSource.UNKNOWN, ShortcutHelper.MANIFEST_COLOR_INVALID_OR
_MISSING, | 99 ShortcutSource.UNKNOWN, ShortcutHelper.MANIFEST_COLOR_INVALID_OR
_MISSING, |
82 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false); | 100 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false); |
83 webappInfo.setWebappIntentExtras(intent); | 101 webappInfo.setWebappIntentExtras(intent); |
84 | 102 |
85 return intent; | 103 return intent; |
86 } | 104 } |
87 | 105 |
88 private void fireWebappIntent(String id, String url, String title, String ic
on, | 106 private void fireWebappIntent(String id, String url, String title, String ic
on, |
89 boolean addMac) { | 107 boolean addMac) { |
90 Intent intent = createIntent(id, url, title, icon, addMac); | 108 Intent intent = createIntent(id, url, title, icon, addMac); |
91 | 109 |
92 getInstrumentation().getTargetContext().startActivity(intent); | 110 InstrumentationRegistry.getInstrumentation().getTargetContext().startAct
ivity(intent); |
93 getInstrumentation().waitForIdleSync(); | 111 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
94 ApplicationTestUtils.waitUntilChromeInForeground(); | 112 ApplicationTestUtils.waitUntilChromeInForeground(); |
95 } | 113 } |
96 | 114 |
97 @Override | 115 @Before |
98 public void setUp() throws Exception { | 116 public void setUp() throws Exception { |
99 super.setUp(); | |
100 WebappRegistry.refreshSharedPrefsForTesting(); | 117 WebappRegistry.refreshSharedPrefsForTesting(); |
101 | 118 |
102 // Register the webapps so when the data storage is opened, the test doe
sn't crash. There is | 119 // Register the webapps so when the data storage is opened, the test doe
sn't crash. There is |
103 // no race condition with the retrieval as AsyncTasks are run sequential
ly on the background | 120 // no race condition with the retrieval as AsyncTasks are run sequential
ly on the background |
104 // thread. | 121 // thread. |
105 WebappRegistry.getInstance().register( | 122 WebappRegistry.getInstance().register( |
106 WEBAPP_1_ID, new WebappRegistry.FetchWebappDataStorageCallback()
{ | 123 WEBAPP_1_ID, new WebappRegistry.FetchWebappDataStorageCallback()
{ |
107 @Override | 124 @Override |
108 public void onWebappDataStorageRetrieved(WebappDataStorage s
torage) { | 125 public void onWebappDataStorageRetrieved(WebappDataStorage s
torage) { |
109 storage.updateFromShortcutIntent(createIntent( | 126 storage.updateFromShortcutIntent(createIntent( |
110 WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAP
P_ICON, true)); | 127 WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAP
P_ICON, true)); |
111 } | 128 } |
112 }); | 129 }); |
113 WebappRegistry.getInstance().register( | 130 WebappRegistry.getInstance().register( |
114 WEBAPP_2_ID, new WebappRegistry.FetchWebappDataStorageCallback()
{ | 131 WEBAPP_2_ID, new WebappRegistry.FetchWebappDataStorageCallback()
{ |
115 @Override | 132 @Override |
116 public void onWebappDataStorageRetrieved(WebappDataStorage s
torage) { | 133 public void onWebappDataStorageRetrieved(WebappDataStorage s
torage) { |
117 storage.updateFromShortcutIntent(createIntent( | 134 storage.updateFromShortcutIntent(createIntent( |
118 WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAP
P_ICON, true)); | 135 WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAP
P_ICON, true)); |
119 } | 136 } |
120 }); | 137 }); |
121 | 138 |
122 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation
().getContext()); | 139 mTestServer = EmbeddedTestServer.createAndStartServer( |
| 140 InstrumentationRegistry.getInstrumentation().getContext()); |
123 } | 141 } |
124 | 142 |
125 @Override | 143 @After |
126 public void tearDown() throws Exception { | 144 public void tearDown() throws Exception { |
127 mTestServer.stopAndDestroyServer(); | 145 mTestServer.stopAndDestroyServer(); |
128 super.tearDown(); | |
129 } | 146 } |
130 | 147 |
131 /** | 148 /** |
132 * Tests that WebappActivities are started properly. | 149 * Tests that WebappActivities are started properly. |
133 */ | 150 */ |
| 151 @Test |
134 @MediumTest | 152 @MediumTest |
135 @Feature({"Webapps"}) | 153 @Feature({"Webapps"}) |
136 public void testWebappLaunches() { | 154 public void testWebappLaunches() { |
137 final WebappActivity firstActivity = | 155 final WebappActivity firstActivity = |
138 startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, W
EBAPP_ICON); | 156 startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, W
EBAPP_ICON); |
139 final int firstTabId = firstActivity.getActivityTab().getId(); | 157 final int firstTabId = firstActivity.getActivityTab().getId(); |
140 | 158 |
141 // Firing a different Intent should start a new WebappActivity instance. | 159 // Firing a different Intent should start a new WebappActivity instance. |
142 fireWebappIntent(WEBAPP_2_ID, WEBAPP_2_URL, WEBAPP_2_TITLE, WEBAPP_ICON,
true); | 160 fireWebappIntent(WEBAPP_2_ID, WEBAPP_2_URL, WEBAPP_2_TITLE, WEBAPP_ICON,
true); |
143 CriteriaHelper.pollUiThread(new Criteria() { | 161 CriteriaHelper.pollUiThread(new Criteria() { |
(...skipping 18 matching lines...) Expand all Loading... |
162 | 180 |
163 WebappActivity lastWebappActivity = (WebappActivity) lastActivit
y; | 181 WebappActivity lastWebappActivity = (WebappActivity) lastActivit
y; |
164 return lastWebappActivity.getActivityTab().getId() == firstTabId
; | 182 return lastWebappActivity.getActivityTab().getId() == firstTabId
; |
165 } | 183 } |
166 }); | 184 }); |
167 } | 185 } |
168 | 186 |
169 /** | 187 /** |
170 * Tests that the WebappActivity gets the next available Tab ID instead of 0
. | 188 * Tests that the WebappActivity gets the next available Tab ID instead of 0
. |
171 */ | 189 */ |
| 190 @Test |
172 @MediumTest | 191 @MediumTest |
173 @Feature({"Webapps"}) | 192 @Feature({"Webapps"}) |
174 public void testWebappTabIdsProperlyAssigned() { | 193 public void testWebappTabIdsProperlyAssigned() { |
175 SharedPreferences prefs = ContextUtils.getAppSharedPreferences(); | 194 SharedPreferences prefs = ContextUtils.getAppSharedPreferences(); |
176 SharedPreferences.Editor editor = prefs.edit(); | 195 SharedPreferences.Editor editor = prefs.edit(); |
177 editor.putInt(TabIdManager.PREF_NEXT_ID, 11684); | 196 editor.putInt(TabIdManager.PREF_NEXT_ID, 11684); |
178 editor.apply(); | 197 editor.apply(); |
179 | 198 |
180 final WebappActivity webappActivity = | 199 final WebappActivity webappActivity = |
181 startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, W
EBAPP_ICON); | 200 startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, W
EBAPP_ICON); |
182 assertEquals("Wrong Tab ID was used", 11684, webappActivity.getActivityT
ab().getId()); | 201 Assert.assertEquals( |
| 202 "Wrong Tab ID was used", 11684, webappActivity.getActivityTab().
getId()); |
183 } | 203 } |
184 | 204 |
185 /** | 205 /** |
186 * Tests that a WebappActivity can be brought forward by firing an Intent wi
th | 206 * Tests that a WebappActivity can be brought forward by firing an Intent wi
th |
187 * TabOpenType.BRING_TAB_TO_FRONT. | 207 * TabOpenType.BRING_TAB_TO_FRONT. |
188 */ | 208 */ |
| 209 @Test |
189 @MediumTest | 210 @MediumTest |
190 @Feature({"Webapps"}) | 211 @Feature({"Webapps"}) |
191 public void testBringTabToFront() throws Exception { | 212 public void testBringTabToFront() throws Exception { |
192 // Start the WebappActivity. | 213 // Start the WebappActivity. |
193 final WebappActivity firstActivity = | 214 final WebappActivity firstActivity = |
194 startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, W
EBAPP_ICON); | 215 startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, W
EBAPP_ICON); |
195 final int webappTabId = firstActivity.getActivityTab().getId(); | 216 final int webappTabId = firstActivity.getActivityTab().getId(); |
196 | 217 |
197 // Return home. | 218 // Return home. |
198 final Context context = getInstrumentation().getTargetContext(); | 219 final Context context = InstrumentationRegistry.getInstrumentation().get
TargetContext(); |
199 ApplicationTestUtils.fireHomeScreenIntent(context); | 220 ApplicationTestUtils.fireHomeScreenIntent(context); |
200 getInstrumentation().waitForIdleSync(); | 221 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
201 | 222 |
202 // Bring the WebappActivity back via an Intent. | 223 // Bring the WebappActivity back via an Intent. |
203 Intent intent = Tab.createBringTabToFrontIntent(webappTabId); | 224 Intent intent = Tab.createBringTabToFrontIntent(webappTabId); |
204 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 225 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
205 context.startActivity(intent); | 226 context.startActivity(intent); |
206 | 227 |
207 // When Chrome is back in the foreground, confirm that the correct Activ
ity was restored. | 228 // When Chrome is back in the foreground, confirm that the correct Activ
ity was restored. |
208 // Because of Android killing Activities willy-nilly, it may not be the
same Activity, but | 229 // Because of Android killing Activities willy-nilly, it may not be the
same Activity, but |
209 // it should have the same Tab ID. | 230 // it should have the same Tab ID. |
210 getInstrumentation().waitForIdleSync(); | 231 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
211 ApplicationTestUtils.waitUntilChromeInForeground(); | 232 ApplicationTestUtils.waitUntilChromeInForeground(); |
212 CriteriaHelper.pollInstrumentationThread(new Criteria() { | 233 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
213 @Override | 234 @Override |
214 public boolean isSatisfied() { | 235 public boolean isSatisfied() { |
215 Activity lastActivity = ApplicationStatus.getLastTrackedFocusedA
ctivity(); | 236 Activity lastActivity = ApplicationStatus.getLastTrackedFocusedA
ctivity(); |
216 if (!isWebappActivityReady(lastActivity)) return false; | 237 if (!isWebappActivityReady(lastActivity)) return false; |
217 | 238 |
218 WebappActivity webappActivity = (WebappActivity) lastActivity; | 239 WebappActivity webappActivity = (WebappActivity) lastActivity; |
219 return webappActivity.getActivityTab().getId() == webappTabId; | 240 return webappActivity.getActivityTab().getId() == webappTabId; |
220 } | 241 } |
221 }); | 242 }); |
222 } | 243 } |
223 | 244 |
224 /** | 245 /** |
225 * Ensure WebappActivities can't be launched without proper security checks. | 246 * Ensure WebappActivities can't be launched without proper security checks. |
226 */ | 247 */ |
| 248 @Test |
227 @MediumTest | 249 @MediumTest |
228 @Feature({"Webapps"}) | 250 @Feature({"Webapps"}) |
229 public void testWebappRequiresValidMac() { | 251 public void testWebappRequiresValidMac() { |
230 // Try to start a WebappActivity. Fail because the Intent is insecure. | 252 // Try to start a WebappActivity. Fail because the Intent is insecure. |
231 fireWebappIntent(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAPP_ICON,
false); | 253 fireWebappIntent(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAPP_ICON,
false); |
232 CriteriaHelper.pollUiThread(new Criteria() { | 254 CriteriaHelper.pollUiThread(new Criteria() { |
233 @Override | 255 @Override |
234 public boolean isSatisfied() { | 256 public boolean isSatisfied() { |
235 Activity lastActivity = ApplicationStatus.getLastTrackedFocusedA
ctivity(); | 257 Activity lastActivity = ApplicationStatus.getLastTrackedFocusedA
ctivity(); |
236 return lastActivity instanceof ChromeTabbedActivity; | 258 return lastActivity instanceof ChromeTabbedActivity; |
237 } | 259 } |
238 }); | 260 }); |
239 ChromeActivity chromeActivity = | 261 ChromeActivity chromeActivity = |
240 (ChromeActivity) ApplicationStatus.getLastTrackedFocusedActivity
(); | 262 (ChromeActivity) ApplicationStatus.getLastTrackedFocusedActivity
(); |
241 waitForFullLoad(chromeActivity, WEBAPP_1_TITLE); | 263 mTestRule.waitForFullLoad(chromeActivity, WEBAPP_1_TITLE); |
242 | 264 |
243 // Firing a correct Intent should start a WebappActivity instance instea
d of the browser. | 265 // Firing a correct Intent should start a WebappActivity instance instea
d of the browser. |
244 fireWebappIntent(WEBAPP_2_ID, WEBAPP_2_URL, WEBAPP_2_TITLE, WEBAPP_ICON,
true); | 266 fireWebappIntent(WEBAPP_2_ID, WEBAPP_2_URL, WEBAPP_2_TITLE, WEBAPP_ICON,
true); |
245 CriteriaHelper.pollUiThread(new Criteria() { | 267 CriteriaHelper.pollUiThread(new Criteria() { |
246 @Override | 268 @Override |
247 public boolean isSatisfied() { | 269 public boolean isSatisfied() { |
248 return isWebappActivityReady(ApplicationStatus.getLastTrackedFoc
usedActivity()); | 270 return isWebappActivityReady(ApplicationStatus.getLastTrackedFoc
usedActivity()); |
249 } | 271 } |
250 }); | 272 }); |
251 } | 273 } |
252 | 274 |
253 /** | 275 /** |
254 * Tests that WebappActivities handle window.open() properly in tabbed mode. | 276 * Tests that WebappActivities handle window.open() properly in tabbed mode. |
255 */ | 277 */ |
| 278 @Test |
256 @MediumTest | 279 @MediumTest |
257 @Feature({"Webapps"}) | 280 @Feature({"Webapps"}) |
258 public void testWebappHandlesWindowOpenInTabbedMode() throws Exception { | 281 public void testWebappHandlesWindowOpenInTabbedMode() throws Exception { |
259 triggerWindowOpenAndWaitForLoad(ChromeTabbedActivity.class, getOnClickLi
nkUrl(), true); | 282 triggerWindowOpenAndWaitForLoad(ChromeTabbedActivity.class, getOnClickLi
nkUrl(), true); |
260 } | 283 } |
261 | 284 |
262 /** | 285 /** |
263 * Tests that WebappActivities handle suppressed window.open() properly in t
abbed mode. | 286 * Tests that WebappActivities handle suppressed window.open() properly in t
abbed mode. |
264 */ | 287 */ |
| 288 @Test |
265 @MediumTest | 289 @MediumTest |
266 @Feature({"Webapps"}) | 290 @Feature({"Webapps"}) |
267 public void testWebappHandlesSuppressedWindowOpenInTabbedMode() throws Excep
tion { | 291 public void testWebappHandlesSuppressedWindowOpenInTabbedMode() throws Excep
tion { |
268 triggerWindowOpenAndWaitForLoad( | 292 triggerWindowOpenAndWaitForLoad( |
269 ChromeTabbedActivity.class, getHrefNoReferrerLinkUrl(), false); | 293 ChromeTabbedActivity.class, getHrefNoReferrerLinkUrl(), false); |
270 } | 294 } |
271 | 295 |
272 private <T extends ChromeActivity> void triggerWindowOpenAndWaitForLoad( | 296 private <T extends ChromeActivity> void triggerWindowOpenAndWaitForLoad( |
273 Class<T> classToWaitFor, String linkHtml, boolean checkContents) thr
ows Exception { | 297 Class<T> classToWaitFor, String linkHtml, boolean checkContents) thr
ows Exception { |
274 final WebappActivity firstActivity = | 298 final WebappActivity firstActivity = |
(...skipping 12 matching lines...) Expand all Loading... |
287 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 311 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
288 @Override | 312 @Override |
289 public void run() { | 313 public void run() { |
290 View view = firstActivity.findViewById(android.R.id.cont
ent).getRootView(); | 314 View view = firstActivity.findViewById(android.R.id.cont
ent).getRootView(); |
291 TouchCommon.singleClickView(view); | 315 TouchCommon.singleClickView(view); |
292 } | 316 } |
293 }); | 317 }); |
294 } | 318 } |
295 }; | 319 }; |
296 ChromeActivity secondActivity = ActivityUtils.waitForActivity( | 320 ChromeActivity secondActivity = ActivityUtils.waitForActivity( |
297 getInstrumentation(), classToWaitFor, fgTrigger); | 321 InstrumentationRegistry.getInstrumentation(), classToWaitFor, fg
Trigger); |
298 waitForFullLoad(secondActivity, "The Google"); | 322 mTestRule.waitForFullLoad(secondActivity, "The Google"); |
299 if (checkContents) { | 323 if (checkContents) { |
300 assertEquals("New WebContents was not created", "SUCCESS", | 324 Assert.assertEquals("New WebContents was not created", "SUCCESS", |
301 firstActivity.getActivityTab().getTitle()); | 325 firstActivity.getActivityTab().getTitle()); |
302 } | 326 } |
303 assertNotSame("Wrong Activity in foreground", | 327 Assert.assertNotSame("Wrong Activity in foreground", firstActivity, |
304 firstActivity, ApplicationStatus.getLastTrackedFocusedActivity()
); | 328 ApplicationStatus.getLastTrackedFocusedActivity()); |
305 | 329 |
306 // Close the child window to kick the user back to the WebappActivity. | 330 // Close the child window to kick the user back to the WebappActivity. |
307 JavaScriptUtils.executeJavaScript( | 331 JavaScriptUtils.executeJavaScript( |
308 secondActivity.getActivityTab().getWebContents(), "window.close(
)"); | 332 secondActivity.getActivityTab().getWebContents(), "window.close(
)"); |
309 CriteriaHelper.pollUiThread(new Criteria() { | 333 CriteriaHelper.pollUiThread(new Criteria() { |
310 @Override | 334 @Override |
311 public boolean isSatisfied() { | 335 public boolean isSatisfied() { |
312 Activity lastActivity = ApplicationStatus.getLastTrackedFocusedA
ctivity(); | 336 Activity lastActivity = ApplicationStatus.getLastTrackedFocusedA
ctivity(); |
313 if (!isWebappActivityReady(lastActivity)) return false; | 337 if (!isWebappActivityReady(lastActivity)) return false; |
314 | 338 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 + " document.title = site ? 'SUCCESS' : 'FAILURE';" | 411 + " document.title = site ? 'SUCCESS' : 'FAILURE';" |
388 + " }" | 412 + " }" |
389 + " </script>" | 413 + " </script>" |
390 + " </head>" | 414 + " </head>" |
391 + " <body id='body'>" | 415 + " <body id='body'>" |
392 + " <div onclick='openNewWindow()'></div>" | 416 + " <div onclick='openNewWindow()'></div>" |
393 + " </body>" | 417 + " </body>" |
394 + "</html>"); | 418 + "</html>"); |
395 } | 419 } |
396 } | 420 } |
OLD | NEW |