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; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.support.test.InstrumentationRegistry; | |
9 import android.support.test.filters.LargeTest; | 8 import android.support.test.filters.LargeTest; |
10 import android.test.MoreAsserts; | 9 import android.test.MoreAsserts; |
11 import android.util.SparseArray; | 10 import android.util.SparseArray; |
12 import android.util.SparseBooleanArray; | 11 import android.util.SparseBooleanArray; |
13 | 12 |
14 import org.junit.After; | |
15 import org.junit.Assert; | |
16 import org.junit.Before; | |
17 import org.junit.Rule; | |
18 import org.junit.Test; | |
19 import org.junit.runner.RunWith; | |
20 | |
21 import org.chromium.base.ThreadUtils; | 13 import org.chromium.base.ThreadUtils; |
22 import org.chromium.base.test.util.CommandLineFlags; | |
23 import org.chromium.base.test.util.DisabledTest; | 14 import org.chromium.base.test.util.DisabledTest; |
24 import org.chromium.base.test.util.Feature; | 15 import org.chromium.base.test.util.Feature; |
25 import org.chromium.base.test.util.Restriction; | 16 import org.chromium.base.test.util.Restriction; |
26 import org.chromium.base.test.util.RetryOnFailure; | 17 import org.chromium.base.test.util.RetryOnFailure; |
27 import org.chromium.chrome.browser.compositor.layouts.Layout; | 18 import org.chromium.chrome.browser.compositor.layouts.Layout; |
28 import org.chromium.chrome.browser.tab.Tab; | 19 import org.chromium.chrome.browser.tab.Tab; |
29 import org.chromium.chrome.browser.tabmodel.TabCreatorManager.TabCreator; | 20 import org.chromium.chrome.browser.tabmodel.TabCreatorManager.TabCreator; |
30 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 21 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
31 import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; | 22 import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; |
32 import org.chromium.chrome.browser.tabmodel.TabModelUtils; | 23 import org.chromium.chrome.browser.tabmodel.TabModelUtils; |
33 import org.chromium.chrome.test.ChromeActivityTestRule; | 24 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
34 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; | |
35 import org.chromium.chrome.test.util.ChromeRestriction; | 25 import org.chromium.chrome.test.util.ChromeRestriction; |
36 import org.chromium.chrome.test.util.ChromeTabUtils; | 26 import org.chromium.chrome.test.util.ChromeTabUtils; |
37 import org.chromium.chrome.test.util.PrerenderTestHelper; | 27 import org.chromium.chrome.test.util.PrerenderTestHelper; |
38 import org.chromium.content.browser.BindingManager; | 28 import org.chromium.content.browser.BindingManager; |
39 import org.chromium.content.browser.ChildProcessLauncher; | 29 import org.chromium.content.browser.ChildProcessLauncher; |
40 import org.chromium.content.browser.ManagedChildProcessConnection; | 30 import org.chromium.content.browser.ManagedChildProcessConnection; |
41 import org.chromium.content.browser.test.ChildProcessAllocatorSettings; | 31 import org.chromium.content.browser.test.ChildProcessAllocatorSettings; |
42 import org.chromium.content.browser.test.util.Criteria; | 32 import org.chromium.content.browser.test.util.Criteria; |
43 import org.chromium.content.browser.test.util.CriteriaHelper; | 33 import org.chromium.content.browser.test.util.CriteriaHelper; |
44 import org.chromium.content.browser.test.util.TouchCommon; | |
45 import org.chromium.content_public.browser.LoadUrlParams; | 34 import org.chromium.content_public.browser.LoadUrlParams; |
46 import org.chromium.net.test.EmbeddedTestServer; | 35 import org.chromium.net.test.EmbeddedTestServer; |
47 import org.chromium.ui.base.DeviceFormFactor; | 36 import org.chromium.ui.base.DeviceFormFactor; |
48 import org.chromium.ui.base.PageTransition; | 37 import org.chromium.ui.base.PageTransition; |
49 | 38 |
50 import java.util.concurrent.Callable; | 39 import java.util.concurrent.Callable; |
51 | 40 |
52 /** | 41 /** |
53 * Integration tests for the BindingManager API. This test plants a mock Binding
Manager | 42 * Integration tests for the BindingManager API. This test plants a mock Binding
Manager |
54 * implementation and verifies that the signals it relies on are correctly deliv
ered. | 43 * implementation and verifies that the signals it relies on are correctly deliv
ered. |
55 */ | 44 */ |
56 @RunWith(ChromeJUnit4ClassRunner.class) | |
57 @RetryOnFailure | 45 @RetryOnFailure |
58 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, | 46 public class BindingManagerIntegrationTest extends ChromeActivityTestCaseBase<Ch
romeActivity> { |
59 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) | |
60 public class BindingManagerIntegrationTest { | |
61 @Rule | |
62 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = | |
63 new ChromeActivityTestRule<>(ChromeActivity.class); | |
64 | 47 |
65 private static class MockBindingManager implements BindingManager { | 48 private static class MockBindingManager implements BindingManager { |
66 // Maps pid to the last received visibility state of the renderer. | 49 // Maps pid to the last received visibility state of the renderer. |
67 private final SparseBooleanArray mProcessInForegroundMap = new SparseBoo
leanArray(); | 50 private final SparseBooleanArray mProcessInForegroundMap = new SparseBoo
leanArray(); |
68 // Maps pid to a string recording calls to setInForeground() and visibil
ityDetermined(). | 51 // Maps pid to a string recording calls to setInForeground() and visibil
ityDetermined(). |
69 private final SparseArray<String> mVisibilityCallsMap = new SparseArray<
String>(); | 52 private final SparseArray<String> mVisibilityCallsMap = new SparseArray<
String>(); |
70 private boolean mIsReleaseAllModerateBindingsCalled; | 53 private boolean mIsReleaseAllModerateBindingsCalled; |
71 | 54 |
72 void assertIsInForeground(final int pid) { | 55 void assertIsInForeground(final int pid) { |
73 CriteriaHelper.pollInstrumentationThread(new Criteria() { | 56 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 148 |
166 private static final String FILE_PATH = "/chrome/test/data/android/test.html
"; | 149 private static final String FILE_PATH = "/chrome/test/data/android/test.html
"; |
167 private static final String FILE_PATH2 = "/chrome/test/data/android/simple.h
tml"; | 150 private static final String FILE_PATH2 = "/chrome/test/data/android/simple.h
tml"; |
168 // about:version will always be handled by a different renderer than a local
file. | 151 // about:version will always be handled by a different renderer than a local
file. |
169 private static final String ABOUT_VERSION_PATH = "chrome://version/"; | 152 private static final String ABOUT_VERSION_PATH = "chrome://version/"; |
170 private static final String SHARED_RENDERER_PAGE_PATH = | 153 private static final String SHARED_RENDERER_PAGE_PATH = |
171 "/chrome/test/data/android/bindingmanager/shared_renderer1.html"; | 154 "/chrome/test/data/android/bindingmanager/shared_renderer1.html"; |
172 private static final String SHARED_RENDERER_PAGE2_PATH = | 155 private static final String SHARED_RENDERER_PAGE2_PATH = |
173 "/chrome/test/data/android/bindingmanager/shared_renderer2.html"; | 156 "/chrome/test/data/android/bindingmanager/shared_renderer2.html"; |
174 | 157 |
| 158 public BindingManagerIntegrationTest() { |
| 159 super(ChromeActivity.class); |
| 160 } |
| 161 |
175 /** | 162 /** |
176 * Verifies that the .setProcessInForeground() signal is called correctly as
the tabs are | 163 * Verifies that the .setProcessInForeground() signal is called correctly as
the tabs are |
177 * created and switched. | 164 * created and switched. |
178 */ | 165 */ |
179 @Test | |
180 @LargeTest | 166 @LargeTest |
181 @Feature({"ProcessManagement"}) | 167 @Feature({"ProcessManagement"}) |
182 public void testTabSwitching() throws InterruptedException { | 168 public void testTabSwitching() throws InterruptedException { |
183 // Create two tabs and wait until they are loaded, so that their rendere
rs are around. | 169 // Create two tabs and wait until they are loaded, so that their rendere
rs are around. |
184 final Tab[] tabs = new Tab[2]; | 170 final Tab[] tabs = new Tab[2]; |
185 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 171 getInstrumentation().runOnMainSync(new Runnable() { |
186 @Override | 172 @Override |
187 public void run() { | 173 public void run() { |
188 // Foreground tab. | 174 // Foreground tab. |
189 TabCreator tabCreator = mActivityTestRule.getActivity().getCurre
ntTabCreator(); | 175 TabCreator tabCreator = getActivity().getCurrentTabCreator(); |
190 tabs[0] = tabCreator.createNewTab( | 176 tabs[0] = tabCreator.createNewTab( |
191 new LoadUrlParams(mTestServer.getURL(FILE_PATH)), | 177 new LoadUrlParams(mTestServer.getURL(FILE_PATH)), |
192 TabLaunchType.FROM_CHROME_UI, null); | 178 TabLaunchType.FROM_CHROME_UI, null); |
193 // Background tab. | 179 // Background tab. |
194 tabs[1] = tabCreator.createNewTab( | 180 tabs[1] = tabCreator.createNewTab( |
195 new LoadUrlParams(mTestServer.getURL(FILE_PATH)), | 181 new LoadUrlParams(mTestServer.getURL(FILE_PATH)), |
196 TabLaunchType.FROM_LONGPRESS_BACKGROUND, null); | 182 TabLaunchType.FROM_LONGPRESS_BACKGROUND, null); |
197 // On Svelte devices the background tab would not be loaded auto
matically, so | 183 // On Svelte devices the background tab would not be loaded auto
matically, so |
198 // trigger the load manually. | 184 // trigger the load manually. |
199 tabs[1].show(TabSelectionType.FROM_USER); | 185 tabs[1].show(TabSelectionType.FROM_USER); |
200 tabs[1].hide(); | 186 tabs[1].hide(); |
201 } | 187 } |
202 }); | 188 }); |
203 ChromeTabUtils.waitForTabPageLoaded(tabs[0], mTestServer.getURL(FILE_PAT
H)); | 189 ChromeTabUtils.waitForTabPageLoaded(tabs[0], mTestServer.getURL(FILE_PAT
H)); |
204 ChromeTabUtils.waitForTabPageLoaded(tabs[1], mTestServer.getURL(FILE_PAT
H)); | 190 ChromeTabUtils.waitForTabPageLoaded(tabs[1], mTestServer.getURL(FILE_PAT
H)); |
205 | 191 |
206 // Wait for the new tab animations on phones to finish. | 192 // Wait for the new tab animations on phones to finish. |
207 if (!DeviceFormFactor.isTablet(mActivityTestRule.getActivity())) { | 193 if (!DeviceFormFactor.isTablet(getActivity())) { |
208 final ChromeActivity activity = mActivityTestRule.getActivity(); | 194 final ChromeActivity activity = getActivity(); |
209 CriteriaHelper.pollUiThread(new Criteria("Did not finish animation")
{ | 195 CriteriaHelper.pollUiThread(new Criteria("Did not finish animation")
{ |
210 @Override | 196 @Override |
211 public boolean isSatisfied() { | 197 public boolean isSatisfied() { |
212 Layout layout = activity.getCompositorViewHolder() | 198 Layout layout = activity.getCompositorViewHolder() |
213 .getLayoutManager().getActiveLayout(); | 199 .getLayoutManager().getActiveLayout(); |
214 return !layout.isLayoutAnimating(); | 200 return !layout.isLayoutAnimating(); |
215 } | 201 } |
216 }); | 202 }); |
217 } | 203 } |
218 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); | 204 getInstrumentation().waitForIdleSync(); |
219 | 205 |
220 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 206 getInstrumentation().runOnMainSync(new Runnable() { |
221 @Override | 207 @Override |
222 public void run() { | 208 public void run() { |
223 // Make sure that the renderers were spawned. | 209 // Make sure that the renderers were spawned. |
224 Assert.assertTrue(tabs[0].getContentViewCore().getCurrentRenderP
rocessId() > 0); | 210 assertTrue(tabs[0].getContentViewCore().getCurrentRenderProcessI
d() > 0); |
225 Assert.assertTrue(tabs[1].getContentViewCore().getCurrentRenderP
rocessId() > 0); | 211 assertTrue(tabs[1].getContentViewCore().getCurrentRenderProcessI
d() > 0); |
226 | 212 |
227 // Verify that the renderer of the foreground tab was signalled
as visible. | 213 // Verify that the renderer of the foreground tab was signalled
as visible. |
228 mBindingManager.assertIsInForeground( | 214 mBindingManager.assertIsInForeground( |
229 tabs[0].getContentViewCore().getCurrentRenderProcessId()
); | 215 tabs[0].getContentViewCore().getCurrentRenderProcessId()
); |
230 // Verify that the renderer of the tab loaded in background was
signalled as not | 216 // Verify that the renderer of the tab loaded in background was
signalled as not |
231 // visible. | 217 // visible. |
232 mBindingManager.assertIsInBackground( | 218 mBindingManager.assertIsInBackground( |
233 tabs[1].getContentViewCore().getCurrentRenderProcessId()
); | 219 tabs[1].getContentViewCore().getCurrentRenderProcessId()
); |
234 | 220 |
235 // Select tabs[1] and verify that the renderer visibility was fl
ipped. | 221 // Select tabs[1] and verify that the renderer visibility was fl
ipped. |
236 TabModelUtils.setIndex( | 222 TabModelUtils.setIndex(getActivity().getCurrentTabModel(), index
Of(tabs[1])); |
237 mActivityTestRule.getActivity().getCurrentTabModel(), in
dexOf(tabs[1])); | |
238 mBindingManager.assertIsInBackground( | 223 mBindingManager.assertIsInBackground( |
239 tabs[0].getContentViewCore().getCurrentRenderProcessId()
); | 224 tabs[0].getContentViewCore().getCurrentRenderProcessId()
); |
240 mBindingManager.assertIsInForeground( | 225 mBindingManager.assertIsInForeground( |
241 tabs[1].getContentViewCore().getCurrentRenderProcessId()
); | 226 tabs[1].getContentViewCore().getCurrentRenderProcessId()
); |
242 } | 227 } |
243 }); | 228 }); |
244 } | 229 } |
245 | 230 |
246 /** | 231 /** |
247 * Verifies that the .setProcessInForeground() signal is called correctly wh
en a tab that | 232 * Verifies that the .setProcessInForeground() signal is called correctly wh
en a tab that |
248 * crashed in background is restored in foreground. This is a regression tes
t for | 233 * crashed in background is restored in foreground. This is a regression tes
t for |
249 * http://crbug.com/399521. | 234 * http://crbug.com/399521. |
250 */ | 235 */ |
251 @Test | |
252 @DisabledTest(message = "crbug.com/543153") | 236 @DisabledTest(message = "crbug.com/543153") |
253 @LargeTest | 237 @LargeTest |
254 @Feature({"ProcessManagement"}) | 238 @Feature({"ProcessManagement"}) |
255 public void testCrashInBackground() throws InterruptedException { | 239 public void testCrashInBackground() throws InterruptedException { |
256 // Create two tabs and wait until they are loaded, so that their rendere
rs are around. | 240 // Create two tabs and wait until they are loaded, so that their rendere
rs are around. |
257 final Tab[] tabs = new Tab[2]; | 241 final Tab[] tabs = new Tab[2]; |
258 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 242 getInstrumentation().runOnMainSync(new Runnable() { |
259 @Override | 243 @Override |
260 public void run() { | 244 public void run() { |
261 // Foreground tab. | 245 // Foreground tab. |
262 TabCreator tabCreator = mActivityTestRule.getActivity().getCurre
ntTabCreator(); | 246 TabCreator tabCreator = getActivity().getCurrentTabCreator(); |
263 tabs[0] = tabCreator.createNewTab( | 247 tabs[0] = tabCreator.createNewTab( |
264 new LoadUrlParams(mTestServer.getURL(FILE_PATH)), | 248 new LoadUrlParams(mTestServer.getURL(FILE_PATH)), |
265 TabLaunchType.FROM_CHROME_UI, null); | 249 TabLaunchType.FROM_CHROME_UI, null); |
266 // Background tab. | 250 // Background tab. |
267 tabs[1] = tabCreator.createNewTab( | 251 tabs[1] = tabCreator.createNewTab( |
268 new LoadUrlParams(mTestServer.getURL(FILE_PATH)), | 252 new LoadUrlParams(mTestServer.getURL(FILE_PATH)), |
269 TabLaunchType.FROM_LONGPRESS_BACKGROUND, null); | 253 TabLaunchType.FROM_LONGPRESS_BACKGROUND, null); |
270 // On Svelte devices the background tab would not be loaded auto
matically, so | 254 // On Svelte devices the background tab would not be loaded auto
matically, so |
271 // trigger the load manually. | 255 // trigger the load manually. |
272 tabs[1].show(TabSelectionType.FROM_USER); | 256 tabs[1].show(TabSelectionType.FROM_USER); |
273 tabs[1].hide(); | 257 tabs[1].hide(); |
274 } | 258 } |
275 }); | 259 }); |
276 ChromeTabUtils.waitForTabPageLoaded(tabs[0], mTestServer.getURL(FILE_PAT
H)); | 260 ChromeTabUtils.waitForTabPageLoaded(tabs[0], mTestServer.getURL(FILE_PAT
H)); |
277 ChromeTabUtils.waitForTabPageLoaded(tabs[1], mTestServer.getURL(FILE_PAT
H)); | 261 ChromeTabUtils.waitForTabPageLoaded(tabs[1], mTestServer.getURL(FILE_PAT
H)); |
278 | 262 |
279 // Wait for the new tab animations on phones to finish. | 263 // Wait for the new tab animations on phones to finish. |
280 if (!DeviceFormFactor.isTablet(mActivityTestRule.getActivity())) { | 264 if (!DeviceFormFactor.isTablet(getActivity())) { |
281 final ChromeActivity activity = mActivityTestRule.getActivity(); | 265 final ChromeActivity activity = getActivity(); |
282 CriteriaHelper.pollUiThread(new Criteria("Did not finish animation")
{ | 266 CriteriaHelper.pollUiThread(new Criteria("Did not finish animation")
{ |
283 @Override | 267 @Override |
284 public boolean isSatisfied() { | 268 public boolean isSatisfied() { |
285 Layout layout = activity.getCompositorViewHolder() | 269 Layout layout = activity.getCompositorViewHolder() |
286 .getLayoutManager().getActiveLayout(); | 270 .getLayoutManager().getActiveLayout(); |
287 return !layout.isLayoutAnimating(); | 271 return !layout.isLayoutAnimating(); |
288 } | 272 } |
289 }); | 273 }); |
290 } | 274 } |
291 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); | 275 getInstrumentation().waitForIdleSync(); |
292 | 276 |
293 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 277 getInstrumentation().runOnMainSync(new Runnable() { |
294 @Override | 278 @Override |
295 public void run() { | 279 public void run() { |
296 // Make sure that the renderers were spawned. | 280 // Make sure that the renderers were spawned. |
297 Assert.assertTrue(tabs[0].getContentViewCore().getCurrentRenderP
rocessId() > 0); | 281 assertTrue(tabs[0].getContentViewCore().getCurrentRenderProcessI
d() > 0); |
298 Assert.assertTrue(tabs[1].getContentViewCore().getCurrentRenderP
rocessId() > 0); | 282 assertTrue(tabs[1].getContentViewCore().getCurrentRenderProcessI
d() > 0); |
299 | 283 |
300 // Verify that the renderer of the foreground tab was signalled
as visible. | 284 // Verify that the renderer of the foreground tab was signalled
as visible. |
301 mBindingManager.assertIsInForeground( | 285 mBindingManager.assertIsInForeground( |
302 tabs[0].getContentViewCore().getCurrentRenderProcessId()
); | 286 tabs[0].getContentViewCore().getCurrentRenderProcessId()
); |
303 // Verify that the renderer of the tab loaded in background was
signalled as not | 287 // Verify that the renderer of the tab loaded in background was
signalled as not |
304 // visible. | 288 // visible. |
305 mBindingManager.assertIsInBackground( | 289 mBindingManager.assertIsInBackground( |
306 tabs[1].getContentViewCore().getCurrentRenderProcessId()
); | 290 tabs[1].getContentViewCore().getCurrentRenderProcessId()
); |
307 } | 291 } |
308 }); | 292 }); |
309 | 293 |
310 // Kill the renderer and wait for the crash to be noted by the browser p
rocess. | 294 // Kill the renderer and wait for the crash to be noted by the browser p
rocess. |
311 Assert.assertTrue(ChildProcessLauncher.crashProcessForTesting( | 295 assertTrue(ChildProcessLauncher.crashProcessForTesting( |
312 tabs[1].getContentViewCore().getCurrentRenderProcessId())); | 296 tabs[1].getContentViewCore().getCurrentRenderProcessId())); |
313 | 297 |
314 CriteriaHelper.pollInstrumentationThread( | 298 CriteriaHelper.pollInstrumentationThread( |
315 new Criteria("Renderer crash wasn't noticed by the browser.") { | 299 new Criteria("Renderer crash wasn't noticed by the browser.") { |
316 @Override | 300 @Override |
317 public boolean isSatisfied() { | 301 public boolean isSatisfied() { |
318 return tabs[1].getContentViewCore().getCurrentRenderProc
essId() == 0; | 302 return tabs[1].getContentViewCore().getCurrentRenderProc
essId() == 0; |
319 } | 303 } |
320 }); | 304 }); |
321 | 305 |
322 // Switch to the tab that crashed in background. | 306 // Switch to the tab that crashed in background. |
323 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 307 getInstrumentation().runOnMainSync(new Runnable() { |
324 @Override | 308 @Override |
325 public void run() { | 309 public void run() { |
326 TabModelUtils.setIndex( | 310 TabModelUtils.setIndex(getActivity().getCurrentTabModel(), index
Of(tabs[1])); |
327 mActivityTestRule.getActivity().getCurrentTabModel(), in
dexOf(tabs[1])); | |
328 } | 311 } |
329 }); | 312 }); |
330 | 313 |
331 // Wait until the process is spawned and its visibility is determined. | 314 // Wait until the process is spawned and its visibility is determined. |
332 CriteriaHelper.pollInstrumentationThread( | 315 CriteriaHelper.pollInstrumentationThread( |
333 new Criteria("Process for the crashed tab was not respawned.") { | 316 new Criteria("Process for the crashed tab was not respawned.") { |
334 @Override | 317 @Override |
335 public boolean isSatisfied() { | 318 public boolean isSatisfied() { |
336 return tabs[1].getContentViewCore().getCurrentRenderProc
essId() != 0; | 319 return tabs[1].getContentViewCore().getCurrentRenderProc
essId() != 0; |
337 } | 320 } |
338 }); | 321 }); |
339 | 322 |
340 mBindingManager.assertSetInForegroundWasCalled( | 323 mBindingManager.assertSetInForegroundWasCalled( |
341 "isInForeground() was not called for the process.", | 324 "isInForeground() was not called for the process.", |
342 tabs[1].getContentViewCore().getCurrentRenderProcessId()); | 325 tabs[1].getContentViewCore().getCurrentRenderProcessId()); |
343 | 326 |
344 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 327 getInstrumentation().runOnMainSync(new Runnable() { |
345 @Override | 328 @Override |
346 public void run() { | 329 public void run() { |
347 // Verify the visibility of the renderers. | 330 // Verify the visibility of the renderers. |
348 mBindingManager.assertIsInBackground( | 331 mBindingManager.assertIsInBackground( |
349 tabs[0].getContentViewCore().getCurrentRenderProcessId()
); | 332 tabs[0].getContentViewCore().getCurrentRenderProcessId()
); |
350 mBindingManager.assertIsInForeground( | 333 mBindingManager.assertIsInForeground( |
351 tabs[1].getContentViewCore().getCurrentRenderProcessId()
); | 334 tabs[1].getContentViewCore().getCurrentRenderProcessId()
); |
352 } | 335 } |
353 }); | 336 }); |
354 } | 337 } |
355 | 338 |
356 /** | 339 /** |
357 * Verifies that a renderer that crashes in foreground has the correct visib
ility when | 340 * Verifies that a renderer that crashes in foreground has the correct visib
ility when |
358 * recreated. | 341 * recreated. |
359 */ | 342 */ |
360 @Test | |
361 @LargeTest | 343 @LargeTest |
362 @Feature({"ProcessManagement"}) | 344 @Feature({"ProcessManagement"}) |
363 public void testCrashInForeground() throws InterruptedException { | 345 public void testCrashInForeground() throws InterruptedException { |
364 // Create a tab in foreground and wait until it is loaded. | 346 // Create a tab in foreground and wait until it is loaded. |
365 final String testUrl = mTestServer.getURL(FILE_PATH); | 347 final String testUrl = mTestServer.getURL(FILE_PATH); |
366 final Tab tab = ThreadUtils.runOnUiThreadBlockingNoException( | 348 final Tab tab = ThreadUtils.runOnUiThreadBlockingNoException( |
367 new Callable<Tab>() { | 349 new Callable<Tab>() { |
368 @Override | 350 @Override |
369 public Tab call() throws Exception { | 351 public Tab call() throws Exception { |
370 TabCreator tabCreator = | 352 TabCreator tabCreator = getActivity().getCurrentTabCreat
or(); |
371 mActivityTestRule.getActivity().getCurrentTabCre
ator(); | |
372 return tabCreator.createNewTab( | 353 return tabCreator.createNewTab( |
373 new LoadUrlParams(testUrl), TabLaunchType.FROM_C
HROME_UI, null); | 354 new LoadUrlParams(testUrl), TabLaunchType.FROM_C
HROME_UI, null); |
374 } | 355 } |
375 }); | 356 }); |
376 ChromeTabUtils.waitForTabPageLoaded(tab, testUrl); | 357 ChromeTabUtils.waitForTabPageLoaded(tab, testUrl); |
377 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); | 358 getInstrumentation().waitForIdleSync(); |
378 | 359 |
379 // Kill the renderer and wait for the crash to be noted by the browser p
rocess. | 360 // Kill the renderer and wait for the crash to be noted by the browser p
rocess. |
380 Assert.assertTrue(ChildProcessLauncher.crashProcessForTesting( | 361 assertTrue(ChildProcessLauncher.crashProcessForTesting( |
381 tab.getContentViewCore().getCurrentRenderProcessId())); | 362 tab.getContentViewCore().getCurrentRenderProcessId())); |
382 | 363 |
383 CriteriaHelper.pollInstrumentationThread( | 364 CriteriaHelper.pollInstrumentationThread( |
384 new Criteria("Renderer crash wasn't noticed by the browser.") { | 365 new Criteria("Renderer crash wasn't noticed by the browser.") { |
385 @Override | 366 @Override |
386 public boolean isSatisfied() { | 367 public boolean isSatisfied() { |
387 return tab.getContentViewCore().getCurrentRenderProcessI
d() == 0; | 368 return tab.getContentViewCore().getCurrentRenderProcessI
d() == 0; |
388 } | 369 } |
389 }); | 370 }); |
390 | 371 |
391 // Reload the tab, respawning the renderer. | 372 // Reload the tab, respawning the renderer. |
392 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 373 getInstrumentation().runOnMainSync(new Runnable() { |
393 @Override | 374 @Override |
394 public void run() { | 375 public void run() { |
395 tab.reload(); | 376 tab.reload(); |
396 } | 377 } |
397 }); | 378 }); |
398 | 379 |
399 ChromeTabUtils.waitForTabPageLoaded(tab, testUrl); | 380 ChromeTabUtils.waitForTabPageLoaded(tab, testUrl); |
400 | 381 |
401 // Wait until the process is spawned and its visibility is determined. | 382 // Wait until the process is spawned and its visibility is determined. |
402 CriteriaHelper.pollInstrumentationThread( | 383 CriteriaHelper.pollInstrumentationThread( |
403 new Criteria("Process for the crashed tab was not respawned.") { | 384 new Criteria("Process for the crashed tab was not respawned.") { |
404 @Override | 385 @Override |
405 public boolean isSatisfied() { | 386 public boolean isSatisfied() { |
406 return tab.getContentViewCore().getCurrentRenderProcessI
d() != 0; | 387 return tab.getContentViewCore().getCurrentRenderProcessI
d() != 0; |
407 } | 388 } |
408 }); | 389 }); |
409 | 390 |
410 mBindingManager.assertSetInForegroundWasCalled( | 391 mBindingManager.assertSetInForegroundWasCalled( |
411 "isInForeground() was not called for the process.", | 392 "isInForeground() was not called for the process.", |
412 tab.getContentViewCore().getCurrentRenderProcessId()); | 393 tab.getContentViewCore().getCurrentRenderProcessId()); |
413 | 394 |
414 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 395 getInstrumentation().runOnMainSync(new Runnable() { |
415 @Override | 396 @Override |
416 public void run() { | 397 public void run() { |
417 // Verify the visibility of the renderer. | 398 // Verify the visibility of the renderer. |
418 mBindingManager.assertIsInForeground( | 399 mBindingManager.assertIsInForeground( |
419 tab.getContentViewCore().getCurrentRenderProcessId()); | 400 tab.getContentViewCore().getCurrentRenderProcessId()); |
420 } | 401 } |
421 }); | 402 }); |
422 } | 403 } |
423 | 404 |
424 private int getRenderProcessId(final Tab tab) { | 405 private int getRenderProcessId(final Tab tab) { |
425 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Integer
>() { | 406 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Integer
>() { |
426 @Override | 407 @Override |
427 public Integer call() throws Exception { | 408 public Integer call() throws Exception { |
428 return tab.getContentViewCore().getCurrentRenderProcessId(); | 409 return tab.getContentViewCore().getCurrentRenderProcessId(); |
429 } | 410 } |
430 }); | 411 }); |
431 } | 412 } |
432 | 413 |
433 /** | 414 /** |
434 * Ensures correctness of the visibilityDetermined() calls, that would be ge
nerally preceded by | 415 * Ensures correctness of the visibilityDetermined() calls, that would be ge
nerally preceded by |
435 * setInForeground(), but it can't be guaranteed because they are triggered
from different | 416 * setInForeground(), but it can't be guaranteed because they are triggered
from different |
436 * threads. | 417 * threads. |
437 */ | 418 */ |
438 @Test | |
439 @LargeTest | 419 @LargeTest |
440 @Feature({"ProcessManagement"}) | 420 @Feature({"ProcessManagement"}) |
441 public void testVisibilityDetermined() throws InterruptedException { | 421 public void testVisibilityDetermined() throws InterruptedException { |
442 // Create a tab in foreground and wait until it is loaded. | 422 // Create a tab in foreground and wait until it is loaded. |
443 final Tab fgTab = ThreadUtils.runOnUiThreadBlockingNoException( | 423 final Tab fgTab = ThreadUtils.runOnUiThreadBlockingNoException( |
444 new Callable<Tab>() { | 424 new Callable<Tab>() { |
445 @Override | 425 @Override |
446 public Tab call() { | 426 public Tab call() { |
447 TabCreator tabCreator = | 427 TabCreator tabCreator = getActivity().getCurrentTabCreat
or(); |
448 mActivityTestRule.getActivity().getCurrentTabCre
ator(); | |
449 return tabCreator.createNewTab( | 428 return tabCreator.createNewTab( |
450 new LoadUrlParams(mTestServer.getURL(FILE_PATH))
, | 429 new LoadUrlParams(mTestServer.getURL(FILE_PATH))
, |
451 TabLaunchType.FROM_CHROME_UI, null); | 430 TabLaunchType.FROM_CHROME_UI, null); |
452 }}); | 431 }}); |
453 ChromeTabUtils.waitForTabPageLoaded(fgTab, mTestServer.getURL(FILE_PATH)
); | 432 ChromeTabUtils.waitForTabPageLoaded(fgTab, mTestServer.getURL(FILE_PATH)
); |
454 int initialNavigationPid = getRenderProcessId(fgTab); | 433 int initialNavigationPid = getRenderProcessId(fgTab); |
455 // Ensure the following calls happened: | 434 // Ensure the following calls happened: |
456 // - FG - setInForeground(true) - when the tab is created in the foregr
ound | 435 // - FG - setInForeground(true) - when the tab is created in the foregr
ound |
457 // - DETERMINED - visibilityDetermined() - after the initial navigation
is committed | 436 // - DETERMINED - visibilityDetermined() - after the initial navigation
is committed |
458 Assert.assertEquals( | 437 assertEquals("FG;DETERMINED;", mBindingManager.getVisibilityCalls(initia
lNavigationPid)); |
459 "FG;DETERMINED;", mBindingManager.getVisibilityCalls(initialNavi
gationPid)); | |
460 | 438 |
461 // Navigate to about:version which requires a different renderer. | 439 // Navigate to about:version which requires a different renderer. |
462 mActivityTestRule.loadUrlInTab(ABOUT_VERSION_PATH, PageTransition.LINK,
fgTab); | 440 loadUrlInTab(ABOUT_VERSION_PATH, PageTransition.LINK, fgTab); |
463 int secondNavigationPid = getRenderProcessId(fgTab); | 441 int secondNavigationPid = getRenderProcessId(fgTab); |
464 MoreAsserts.assertNotEqual(secondNavigationPid, initialNavigationPid); | 442 MoreAsserts.assertNotEqual(secondNavigationPid, initialNavigationPid); |
465 // Ensure the following calls happened: | 443 // Ensure the following calls happened: |
466 // - BG - setInForeground(false) - when the renderer is created for unc
ommited frame | 444 // - BG - setInForeground(false) - when the renderer is created for unc
ommited frame |
467 // - FG - setInForeground(true) - when the frame is swapped in on commi
t | 445 // - FG - setInForeground(true) - when the frame is swapped in on commi
t |
468 // - DETERMINED - visibilityDetermined() - after the navigation is comm
itted | 446 // - DETERMINED - visibilityDetermined() - after the navigation is comm
itted |
469 // Or BG -> DETERMINED -> FG is also possible because setInForeground()
and | 447 // Or BG -> DETERMINED -> FG is also possible because setInForeground()
and |
470 // visibilityDetermined() are triggered from different threads. | 448 // visibilityDetermined() are triggered from different threads. |
471 mBindingManager.assertIsInForeground(secondNavigationPid); | 449 mBindingManager.assertIsInForeground(secondNavigationPid); |
472 String visibilityCalls = mBindingManager.getVisibilityCalls(secondNaviga
tionPid); | 450 String visibilityCalls = mBindingManager.getVisibilityCalls(secondNaviga
tionPid); |
473 Assert.assertTrue(visibilityCalls, | 451 assertTrue(visibilityCalls, "BG;FG;DETERMINED;".equals(visibilityCalls) |
474 "BG;FG;DETERMINED;".equals(visibilityCalls) | 452 || "BG;DETERMINED;FG;".equals(visibilityCalls)); |
475 || "BG;DETERMINED;FG;".equals(visibilityCalls)); | |
476 | 453 |
477 // Open a tab in the background and load it. | 454 // Open a tab in the background and load it. |
478 final Tab bgTab = ThreadUtils.runOnUiThreadBlockingNoException( | 455 final Tab bgTab = ThreadUtils.runOnUiThreadBlockingNoException( |
479 new Callable<Tab>() { | 456 new Callable<Tab>() { |
480 @Override | 457 @Override |
481 public Tab call() { | 458 public Tab call() { |
482 TabCreator tabCreator = | 459 TabCreator tabCreator = getActivity().getCurrentTabCreat
or(); |
483 mActivityTestRule.getActivity().getCurrentTabCre
ator(); | |
484 Tab tab = tabCreator.createNewTab( | 460 Tab tab = tabCreator.createNewTab( |
485 new LoadUrlParams(mTestServer.getURL(FILE_PATH))
, | 461 new LoadUrlParams(mTestServer.getURL(FILE_PATH))
, |
486 TabLaunchType.FROM_LONGPRESS_BACKGROUND,
null); | 462 TabLaunchType.FROM_LONGPRESS_BACKGROUND,
null); |
487 // On Svelte devices the background tab would not be loa
ded automatically, | 463 // On Svelte devices the background tab would not be loa
ded automatically, |
488 // so trigger the load manually. | 464 // so trigger the load manually. |
489 tab.show(TabSelectionType.FROM_USER); | 465 tab.show(TabSelectionType.FROM_USER); |
490 tab.hide(); | 466 tab.hide(); |
491 return tab; | 467 return tab; |
492 }}); | 468 }}); |
493 ChromeTabUtils.waitForTabPageLoaded(bgTab, mTestServer.getURL(FILE_PATH)
); | 469 ChromeTabUtils.waitForTabPageLoaded(bgTab, mTestServer.getURL(FILE_PATH)
); |
494 int bgNavigationPid = getRenderProcessId(bgTab); | 470 int bgNavigationPid = getRenderProcessId(bgTab); |
495 // Ensure the following calls happened: | 471 // Ensure the following calls happened: |
496 // - BG - setInForeground(false) - when tab is created in the backgroun
d | 472 // - BG - setInForeground(false) - when tab is created in the backgroun
d |
497 // - DETERMINED - visibilityDetermined() - after the navigation is comm
itted | 473 // - DETERMINED - visibilityDetermined() - after the navigation is comm
itted |
498 Assert.assertEquals("BG;DETERMINED;", mBindingManager.getVisibilityCalls
(bgNavigationPid)); | 474 assertEquals("BG;DETERMINED;", mBindingManager.getVisibilityCalls(bgNavi
gationPid)); |
499 } | 475 } |
500 | 476 |
501 /** | 477 /** |
502 * When a user navigates to a prererendered URL, the tab swaps in the preren
der's render | 478 * When a user navigates to a prererendered URL, the tab swaps in the preren
der's render |
503 * process and discards its old render process. Test that visibilityDetermin
ed() is called for | 479 * process and discards its old render process. Test that visibilityDetermin
ed() is called for |
504 * the swapped in render process. | 480 * the swapped in render process. |
505 */ | 481 */ |
506 @Test | |
507 @LargeTest | 482 @LargeTest |
508 @Restriction({Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE}) | 483 @Restriction({Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE}) |
509 @Feature({"ProcessManagement"}) | 484 @Feature({"ProcessManagement"}) |
510 public void testVisibilityDeterminedNavigateToPrerenderedPage() throws Inter
ruptedException { | 485 public void testVisibilityDeterminedNavigateToPrerenderedPage() throws Inter
ruptedException { |
511 mActivityTestRule.loadUrl(mTestServer.getURL(FILE_PATH)); | 486 loadUrl(mTestServer.getURL(FILE_PATH)); |
512 Tab tab = mActivityTestRule.getActivity().getActivityTab(); | 487 Tab tab = getActivity().getActivityTab(); |
513 int pid1 = getRenderProcessId(tab); | 488 int pid1 = getRenderProcessId(tab); |
514 | 489 |
515 String prerenderUrl = mTestServer.getURL(FILE_PATH2); | 490 String prerenderUrl = mTestServer.getURL(FILE_PATH2); |
516 PrerenderTestHelper.prerenderUrl(prerenderUrl, tab); | 491 PrerenderTestHelper.prerenderUrl(prerenderUrl, tab); |
517 Assert.assertEquals( | 492 assertEquals(TabLoadStatus.FULL_PRERENDERED_PAGE_LOAD, loadUrl(prerender
Url)); |
518 TabLoadStatus.FULL_PRERENDERED_PAGE_LOAD, mActivityTestRule.load
Url(prerenderUrl)); | |
519 | 493 |
520 int pid2 = getRenderProcessId(tab); | 494 int pid2 = getRenderProcessId(tab); |
521 MoreAsserts.assertNotEqual(pid1, pid2); | 495 MoreAsserts.assertNotEqual(pid1, pid2); |
522 | 496 |
523 Assert.assertTrue(mBindingManager.getVisibilityCalls(pid1).contains("DET
ERMINED;")); | 497 assertTrue(mBindingManager.getVisibilityCalls(pid1).contains("DETERMINED
;")); |
524 Assert.assertTrue(mBindingManager.getVisibilityCalls(pid2).contains("DET
ERMINED;")); | 498 assertTrue(mBindingManager.getVisibilityCalls(pid2).contains("DETERMINED
;")); |
525 } | 499 } |
526 | 500 |
527 /** | 501 /** |
528 * Verifies that BindingManager.releaseAllModerateBindings() is called once
all the sandboxed | 502 * Verifies that BindingManager.releaseAllModerateBindings() is called once
all the sandboxed |
529 * services are allocated. | 503 * services are allocated. |
530 */ | 504 */ |
531 @Test | |
532 @ChildProcessAllocatorSettings(sandboxedServiceCount = 4) | 505 @ChildProcessAllocatorSettings(sandboxedServiceCount = 4) |
533 @LargeTest | 506 @LargeTest |
534 @Feature({"ProcessManagement"}) | 507 @Feature({"ProcessManagement"}) |
535 public void testReleaseAllModerateBindings() throws InterruptedException { | 508 public void testReleaseAllModerateBindings() throws InterruptedException { |
536 final TabCreator tabCreator = mActivityTestRule.getActivity().getCurrent
TabCreator(); | 509 final TabCreator tabCreator = getActivity().getCurrentTabCreator(); |
537 final Tab[] tabs = new Tab[3]; | 510 final Tab[] tabs = new Tab[3]; |
538 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 511 getInstrumentation().runOnMainSync(new Runnable() { |
539 @Override | 512 @Override |
540 public void run() { | 513 public void run() { |
541 // Foreground tab. | 514 // Foreground tab. |
542 tabs[0] = tabCreator.createNewTab( | 515 tabs[0] = tabCreator.createNewTab( |
543 new LoadUrlParams("about:blank"), TabLaunchType.FROM_CHR
OME_UI, null); | 516 new LoadUrlParams("about:blank"), TabLaunchType.FROM_CHR
OME_UI, null); |
544 // Background tab. | 517 // Background tab. |
545 tabs[1] = tabCreator.createNewTab( | 518 tabs[1] = tabCreator.createNewTab( |
546 new LoadUrlParams("about:blank"), TabLaunchType.FROM_CHR
OME_UI, null); | 519 new LoadUrlParams("about:blank"), TabLaunchType.FROM_CHR
OME_UI, null); |
547 } | 520 } |
548 }); | 521 }); |
549 ChromeTabUtils.waitForTabPageLoaded(tabs[0], "about:blank"); | 522 ChromeTabUtils.waitForTabPageLoaded(tabs[0], "about:blank"); |
550 ChromeTabUtils.waitForTabPageLoaded(tabs[1], "about:blank"); | 523 ChromeTabUtils.waitForTabPageLoaded(tabs[1], "about:blank"); |
551 // At this point 3 sanboxed services are allocated; the initial one + 2
new tabs. | 524 // At this point 3 sanboxed services are allocated; the initial one + 2
new tabs. |
552 Assert.assertFalse(mBindingManager.isReleaseAllModerateBindingsCalled())
; | 525 assertFalse(mBindingManager.isReleaseAllModerateBindingsCalled()); |
553 | 526 |
554 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 527 getInstrumentation().runOnMainSync(new Runnable() { |
555 @Override | 528 @Override |
556 public void run() { | 529 public void run() { |
557 // Foreground tab. | 530 // Foreground tab. |
558 tabs[2] = tabCreator.createNewTab( | 531 tabs[2] = tabCreator.createNewTab( |
559 new LoadUrlParams("about:blank"), TabLaunchType.FROM_CHR
OME_UI, null); | 532 new LoadUrlParams("about:blank"), TabLaunchType.FROM_CHR
OME_UI, null); |
560 } | 533 } |
561 }); | 534 }); |
562 ChromeTabUtils.waitForTabPageLoaded(tabs[2], "about:blank"); | 535 ChromeTabUtils.waitForTabPageLoaded(tabs[2], "about:blank"); |
563 // At this point all the sanboxed services are allocated. | 536 // At this point all the sanboxed services are allocated. |
564 mBindingManager.assertIsReleaseAllModerateBindingsCalled(); | 537 mBindingManager.assertIsReleaseAllModerateBindingsCalled(); |
565 } | 538 } |
566 | 539 |
567 // Test crashes on tablets. See crbug.com/594407 | 540 // Test crashes on tablets. See crbug.com/594407 |
568 @Test | |
569 @LargeTest | 541 @LargeTest |
570 @Feature({"ProcessManagement"}) | 542 @Feature({"ProcessManagement"}) |
571 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 543 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
572 public void testRestoreSharedRenderer() throws Exception { | 544 public void testRestoreSharedRenderer() throws Exception { |
573 mActivityTestRule.loadUrl(mTestServer.getURL(SHARED_RENDERER_PAGE_PATH))
; | 545 loadUrl(mTestServer.getURL(SHARED_RENDERER_PAGE_PATH)); |
574 | 546 |
575 final Tab[] tabs = new Tab[2]; | 547 final Tab[] tabs = new Tab[2]; |
576 tabs[0] = mActivityTestRule.getActivity().getActivityTab(); | 548 tabs[0] = getActivity().getActivityTab(); |
577 TouchCommon.singleClickView(tabs[0].getView()); | 549 singleClickView(tabs[0].getView()); |
578 | 550 |
579 CriteriaHelper.pollInstrumentationThread(new Criteria("Child tab isn't o
pened.") { | 551 CriteriaHelper.pollInstrumentationThread(new Criteria("Child tab isn't o
pened.") { |
580 @Override | 552 @Override |
581 public boolean isSatisfied() { | 553 public boolean isSatisfied() { |
582 return mActivityTestRule.getActivity().getCurrentTabModel().getC
ount() == 2 | 554 return getActivity().getCurrentTabModel().getCount() == 2 |
583 && tabs[0] != mActivityTestRule.getActivity().getActivit
yTab() | 555 && tabs[0] != getActivity().getActivityTab() |
584 && mActivityTestRule.getActivity() | 556 && getActivity() |
585 .getActivityTab() | 557 .getActivityTab() |
586 .getContentViewCore() | 558 .getContentViewCore() |
587 .getCurrentRenderProcessId() | 559 .getCurrentRenderProcessId() |
588 != 0; | 560 != 0; |
589 } | 561 } |
590 }); | 562 }); |
591 tabs[1] = mActivityTestRule.getActivity().getActivityTab(); | 563 tabs[1] = getActivity().getActivityTab(); |
592 Assert.assertEquals(tabs[0].getContentViewCore().getCurrentRenderProcess
Id(), | 564 assertEquals(tabs[0].getContentViewCore().getCurrentRenderProcessId(), |
593 tabs[1].getContentViewCore().getCurrentRenderProcessId()); | 565 tabs[1].getContentViewCore().getCurrentRenderProcessId()); |
594 | 566 |
595 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 567 getInstrumentation().runOnMainSync(new Runnable() { |
596 @Override | 568 @Override |
597 public void run() { | 569 public void run() { |
598 // Verify the visibility of the renderer. | 570 // Verify the visibility of the renderer. |
599 mBindingManager.assertIsInForeground( | 571 mBindingManager.assertIsInForeground( |
600 tabs[0].getContentViewCore().getCurrentRenderProcessId()
); | 572 tabs[0].getContentViewCore().getCurrentRenderProcessId()
); |
601 } | 573 } |
602 }); | 574 }); |
603 | 575 |
604 Assert.assertTrue(ChildProcessLauncher.crashProcessForTesting( | 576 assertTrue(ChildProcessLauncher.crashProcessForTesting( |
605 tabs[1].getContentViewCore().getCurrentRenderProcessId())); | 577 tabs[1].getContentViewCore().getCurrentRenderProcessId())); |
606 | 578 |
607 CriteriaHelper.pollInstrumentationThread( | 579 CriteriaHelper.pollInstrumentationThread( |
608 new Criteria("Renderer crash wasn't noticed by the browser.") { | 580 new Criteria("Renderer crash wasn't noticed by the browser.") { |
609 @Override | 581 @Override |
610 public boolean isSatisfied() { | 582 public boolean isSatisfied() { |
611 return tabs[1].getContentViewCore().getCurrentRenderProc
essId() == 0; | 583 return tabs[1].getContentViewCore().getCurrentRenderProc
essId() == 0; |
612 } | 584 } |
613 }); | 585 }); |
614 // Reload the tab, respawning the renderer. | 586 // Reload the tab, respawning the renderer. |
615 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 587 getInstrumentation().runOnMainSync(new Runnable() { |
616 @Override | 588 @Override |
617 public void run() { | 589 public void run() { |
618 tabs[1].reload(); | 590 tabs[1].reload(); |
619 } | 591 } |
620 }); | 592 }); |
621 | 593 |
622 ChromeTabUtils.waitForTabPageLoaded( | 594 ChromeTabUtils.waitForTabPageLoaded( |
623 tabs[1], mTestServer.getURL(SHARED_RENDERER_PAGE2_PATH)); | 595 tabs[1], mTestServer.getURL(SHARED_RENDERER_PAGE2_PATH)); |
624 | 596 |
625 // Wait until the process is spawned and its visibility is determined. | 597 // Wait until the process is spawned and its visibility is determined. |
626 CriteriaHelper.pollInstrumentationThread( | 598 CriteriaHelper.pollInstrumentationThread( |
627 new Criteria("Process for the crashed tab was not respawned.") { | 599 new Criteria("Process for the crashed tab was not respawned.") { |
628 @Override | 600 @Override |
629 public boolean isSatisfied() { | 601 public boolean isSatisfied() { |
630 return tabs[1].getContentViewCore().getCurrentRenderProc
essId() != 0; | 602 return tabs[1].getContentViewCore().getCurrentRenderProc
essId() != 0; |
631 } | 603 } |
632 }); | 604 }); |
633 | 605 |
634 mBindingManager.assertSetInForegroundWasCalled( | 606 mBindingManager.assertSetInForegroundWasCalled( |
635 "setInForeground() was not called for the process.", | 607 "setInForeground() was not called for the process.", |
636 tabs[1].getContentViewCore().getCurrentRenderProcessId()); | 608 tabs[1].getContentViewCore().getCurrentRenderProcessId()); |
637 | 609 |
638 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { | 610 getInstrumentation().runOnMainSync(new Runnable() { |
639 @Override | 611 @Override |
640 public void run() { | 612 public void run() { |
641 // Verify the visibility of the renderer. | 613 // Verify the visibility of the renderer. |
642 mBindingManager.assertIsInForeground( | 614 mBindingManager.assertIsInForeground( |
643 tabs[1].getContentViewCore().getCurrentRenderProcessId()
); | 615 tabs[1].getContentViewCore().getCurrentRenderProcessId()
); |
644 tabs[1].hide(); | 616 tabs[1].hide(); |
645 mBindingManager.assertIsInBackground( | 617 mBindingManager.assertIsInBackground( |
646 tabs[1].getContentViewCore().getCurrentRenderProcessId()
); | 618 tabs[1].getContentViewCore().getCurrentRenderProcessId()
); |
647 } | 619 } |
648 }); | 620 }); |
649 } | 621 } |
650 | 622 |
651 @Before | 623 @Override |
652 public void setUp() throws Exception { | 624 public void startMainActivity() throws InterruptedException { |
| 625 startMainActivityOnBlankPage(); |
| 626 } |
| 627 |
| 628 @Override |
| 629 protected void setUp() throws Exception { |
653 // Hook in the test binding manager. | 630 // Hook in the test binding manager. |
654 mBindingManager = new MockBindingManager(); | 631 mBindingManager = new MockBindingManager(); |
655 ChildProcessLauncher.setBindingManagerForTesting(mBindingManager); | 632 ChildProcessLauncher.setBindingManagerForTesting(mBindingManager); |
656 | 633 |
657 mActivityTestRule.startMainActivityOnBlankPage(); | 634 super.setUp(); |
658 | 635 |
659 mTestServer = EmbeddedTestServer.createAndStartServer( | 636 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation
().getContext()); |
660 InstrumentationRegistry.getInstrumentation().getContext()); | |
661 } | 637 } |
662 | 638 |
663 @After | 639 @Override |
664 public void tearDown() throws Exception { | 640 protected void tearDown() throws Exception { |
665 mTestServer.stopAndDestroyServer(); | 641 mTestServer.stopAndDestroyServer(); |
| 642 super.tearDown(); |
666 } | 643 } |
667 | 644 |
668 /** | 645 /** |
669 * @return the index of the given tab in the current tab model | 646 * @return the index of the given tab in the current tab model |
670 */ | 647 */ |
671 private int indexOf(Tab tab) { | 648 private int indexOf(Tab tab) { |
672 return mActivityTestRule.getActivity().getCurrentTabModel().indexOf(tab)
; | 649 return getActivity().getCurrentTabModel().indexOf(tab); |
673 } | 650 } |
674 } | 651 } |
OLD | NEW |