OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #if defined(OS_POSIX) | 5 #if defined(OS_POSIX) |
6 #include <signal.h> | 6 #include <signal.h> |
7 #endif | 7 #endif |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 void ClickModalDialogButton(bool accept) { | 197 void ClickModalDialogButton(bool accept) { |
198 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); | 198 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); |
199 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); | 199 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); |
200 app_modal::JavaScriptAppModalDialog* js_dialog = | 200 app_modal::JavaScriptAppModalDialog* js_dialog = |
201 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); | 201 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); |
202 if (accept) | 202 if (accept) |
203 js_dialog->native_dialog()->AcceptAppModalDialog(); | 203 js_dialog->native_dialog()->AcceptAppModalDialog(); |
204 else | 204 else |
205 js_dialog->native_dialog()->CancelAppModalDialog(); | 205 js_dialog->native_dialog()->CancelAppModalDialog(); |
206 } | 206 } |
| 207 |
| 208 // Prepares a WebContents or Browser for a beforeunload dialog. |
| 209 // |
| 210 // This comprises two things. First, it makes sure that the beforeunload hang |
| 211 // monitor will not trigger, otherwise timeout might prevent the dialog from |
| 212 // appearing. See https://crbug.com/519646 . |
| 213 // |
| 214 // Second, beforeunload dialogs require a user gesture, so it makes one. |
| 215 void PrepareForDialog(content::WebContents* web_contents) { |
| 216 web_contents->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting(); |
| 217 for (auto* frame : web_contents->GetAllFrames()) |
| 218 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16()); |
| 219 } |
| 220 |
| 221 void PrepareForDialog(Browser* browser) { |
| 222 for (int i = 0; i < browser->tab_strip_model()->count(); i++) |
| 223 PrepareForDialog(browser->tab_strip_model()->GetWebContentsAt(i)); |
| 224 } |
207 }; | 225 }; |
208 | 226 |
209 // Navigate to a page with an infinite unload handler. | 227 // Navigate to a page with an infinite unload handler. |
210 // Then two async crosssite requests to ensure | 228 // Then two async crosssite requests to ensure |
211 // we don't get confused and think we're closing the tab. | 229 // we don't get confused and think we're closing the tab. |
212 // | 230 // |
213 // This test is flaky on the valgrind UI bots. http://crbug.com/39057 | 231 // This test is flaky on the valgrind UI bots. http://crbug.com/39057 |
214 IN_PROC_BROWSER_TEST_F(UnloadTest, CrossSiteInfiniteUnloadAsync) { | 232 IN_PROC_BROWSER_TEST_F(UnloadTest, CrossSiteInfiniteUnloadAsync) { |
215 // Tests makes no sense in single-process mode since the renderer is hung. | 233 // Tests makes no sense in single-process mode since the renderer is hung. |
216 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 234 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 // Tests closing the browser on a page with an unload listener registered. | 293 // Tests closing the browser on a page with an unload listener registered. |
276 // Test marked as flaky in http://crbug.com/51698 | 294 // Test marked as flaky in http://crbug.com/51698 |
277 IN_PROC_BROWSER_TEST_F(UnloadTest, DISABLED_BrowserCloseUnload) { | 295 IN_PROC_BROWSER_TEST_F(UnloadTest, DISABLED_BrowserCloseUnload) { |
278 LoadUrlAndQuitBrowser(UNLOAD_HTML, "unload"); | 296 LoadUrlAndQuitBrowser(UNLOAD_HTML, "unload"); |
279 } | 297 } |
280 | 298 |
281 // Tests closing the browser with a beforeunload handler and clicking | 299 // Tests closing the browser with a beforeunload handler and clicking |
282 // OK in the beforeunload confirm dialog. | 300 // OK in the beforeunload confirm dialog. |
283 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) { | 301 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) { |
284 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); | 302 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); |
285 // Disable the hang monitor, otherwise there will be a race between the | 303 PrepareForDialog(browser()); |
286 // beforeunload dialog and the beforeunload hang timer. | |
287 browser() | |
288 ->tab_strip_model() | |
289 ->GetActiveWebContents() | |
290 ->GetMainFrame() | |
291 ->DisableBeforeUnloadHangMonitorForTesting(); | |
292 | 304 |
293 content::WindowedNotificationObserver window_observer( | 305 content::WindowedNotificationObserver window_observer( |
294 chrome::NOTIFICATION_BROWSER_CLOSED, | 306 chrome::NOTIFICATION_BROWSER_CLOSED, |
295 content::NotificationService::AllSources()); | 307 content::NotificationService::AllSources()); |
296 chrome::CloseWindow(browser()); | 308 chrome::CloseWindow(browser()); |
297 ClickModalDialogButton(true); | 309 ClickModalDialogButton(true); |
298 window_observer.Wait(); | 310 window_observer.Wait(); |
299 } | 311 } |
300 | 312 |
301 // Tests closing the browser with a beforeunload handler and clicking | 313 // Tests closing the browser with a beforeunload handler and clicking |
302 // CANCEL in the beforeunload confirm dialog. | 314 // CANCEL in the beforeunload confirm dialog. |
303 // If this test flakes, reopen http://crbug.com/123110 | 315 // If this test flakes, reopen http://crbug.com/123110 |
304 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { | 316 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { |
305 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); | 317 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); |
306 // Disable the hang monitor, otherwise there will be a race between the | 318 PrepareForDialog(browser()); |
307 // beforeunload dialog and the beforeunload hang timer. | |
308 browser() | |
309 ->tab_strip_model() | |
310 ->GetActiveWebContents() | |
311 ->GetMainFrame() | |
312 ->DisableBeforeUnloadHangMonitorForTesting(); | |
313 | |
314 chrome::CloseWindow(browser()); | 319 chrome::CloseWindow(browser()); |
315 | 320 |
316 // We wait for the title to change after cancelling the closure of browser | 321 // We wait for the title to change after cancelling the closure of browser |
317 // window, to ensure that in-flight IPCs from the renderer reach the browser. | 322 // window, to ensure that in-flight IPCs from the renderer reach the browser. |
318 // Otherwise the browser won't put up the beforeunload dialog because it's | 323 // Otherwise the browser won't put up the beforeunload dialog because it's |
319 // waiting for an ack from the renderer. | 324 // waiting for an ack from the renderer. |
320 base::string16 expected_title = base::ASCIIToUTF16("cancelled"); | 325 base::string16 expected_title = base::ASCIIToUTF16("cancelled"); |
321 content::TitleWatcher title_watcher( | 326 content::TitleWatcher title_watcher( |
322 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | 327 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); |
323 ClickModalDialogButton(false); | 328 ClickModalDialogButton(false); |
(...skipping 25 matching lines...) Expand all Loading... |
349 false); | 354 false); |
350 window_observer.Wait(); | 355 window_observer.Wait(); |
351 EXPECT_EQ(1, unload_results.get_successes()); | 356 EXPECT_EQ(1, unload_results.get_successes()); |
352 EXPECT_EQ(0, unload_results.get_aborts()); | 357 EXPECT_EQ(0, unload_results.get_aborts()); |
353 } | 358 } |
354 | 359 |
355 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a | 360 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a |
356 // beforeunload handler and clicking Leave in the beforeunload confirm dialog. | 361 // beforeunload handler and clicking Leave in the beforeunload confirm dialog. |
357 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadOK) { | 362 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadOK) { |
358 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); | 363 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); |
359 // Disable the hang monitor, otherwise there will be a race between the | 364 PrepareForDialog(browser()); |
360 // beforeunload dialog and the beforeunload hang timer. | |
361 browser() | |
362 ->tab_strip_model() | |
363 ->GetActiveWebContents() | |
364 ->GetMainFrame() | |
365 ->DisableBeforeUnloadHangMonitorForTesting(); | |
366 | 365 |
367 content::WindowedNotificationObserver window_observer( | 366 content::WindowedNotificationObserver window_observer( |
368 chrome::NOTIFICATION_BROWSER_CLOSED, | 367 chrome::NOTIFICATION_BROWSER_CLOSED, |
369 content::NotificationService::AllSources()); | 368 content::NotificationService::AllSources()); |
370 UnloadResults unload_results; | 369 UnloadResults unload_results; |
371 BrowserList::CloseAllBrowsersWithProfile( | 370 BrowserList::CloseAllBrowsersWithProfile( |
372 browser()->profile(), | 371 browser()->profile(), |
373 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), | 372 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), |
374 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), | 373 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), |
375 false); | 374 false); |
376 ClickModalDialogButton(true); | 375 ClickModalDialogButton(true); |
377 window_observer.Wait(); | 376 window_observer.Wait(); |
378 EXPECT_EQ(1, unload_results.get_successes()); | 377 EXPECT_EQ(1, unload_results.get_successes()); |
379 EXPECT_EQ(0, unload_results.get_aborts()); | 378 EXPECT_EQ(0, unload_results.get_aborts()); |
380 } | 379 } |
381 | 380 |
382 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a | 381 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a |
383 // beforeunload handler and clicking Stay in the beforeunload confirm dialog. | 382 // beforeunload handler and clicking Stay in the beforeunload confirm dialog. |
384 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadCancel) { | 383 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadCancel) { |
385 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); | 384 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); |
386 // Disable the hang monitor, otherwise there will be a race between the | 385 PrepareForDialog(browser()); |
387 // beforeunload dialog and the beforeunload hang timer. | |
388 browser() | |
389 ->tab_strip_model() | |
390 ->GetActiveWebContents() | |
391 ->GetMainFrame() | |
392 ->DisableBeforeUnloadHangMonitorForTesting(); | |
393 | 386 |
394 UnloadResults unload_results; | 387 UnloadResults unload_results; |
395 BrowserList::CloseAllBrowsersWithProfile( | 388 BrowserList::CloseAllBrowsersWithProfile( |
396 browser()->profile(), | 389 browser()->profile(), |
397 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), | 390 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), |
398 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), | 391 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), |
399 false); | 392 false); |
400 | 393 |
401 // We wait for the title to change after cancelling the closure of browser | 394 // We wait for the title to change after cancelling the closure of browser |
402 // window, to ensure that in-flight IPCs from the renderer reach the browser. | 395 // window, to ensure that in-flight IPCs from the renderer reach the browser. |
(...skipping 15 matching lines...) Expand all Loading... |
418 content::NotificationService::AllSources()); | 411 content::NotificationService::AllSources()); |
419 chrome::CloseWindow(browser()); | 412 chrome::CloseWindow(browser()); |
420 ClickModalDialogButton(true); | 413 ClickModalDialogButton(true); |
421 window_observer.Wait(); | 414 window_observer.Wait(); |
422 } | 415 } |
423 | 416 |
424 // Tests double calls to BrowserList::CloseAllBrowsersWithProfile, with a | 417 // Tests double calls to BrowserList::CloseAllBrowsersWithProfile, with a |
425 // beforeunload handler and clicking Leave in the beforeunload confirm dialog. | 418 // beforeunload handler and clicking Leave in the beforeunload confirm dialog. |
426 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadOK) { | 419 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadOK) { |
427 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); | 420 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); |
428 // Disable the hang monitor, otherwise there will be a race between the | 421 PrepareForDialog(browser()); |
429 // beforeunload dialog and the beforeunload hang timer. | |
430 browser() | |
431 ->tab_strip_model() | |
432 ->GetActiveWebContents() | |
433 ->GetMainFrame() | |
434 ->DisableBeforeUnloadHangMonitorForTesting(); | |
435 | 422 |
436 content::WindowedNotificationObserver window_observer( | 423 content::WindowedNotificationObserver window_observer( |
437 chrome::NOTIFICATION_BROWSER_CLOSED, | 424 chrome::NOTIFICATION_BROWSER_CLOSED, |
438 content::NotificationService::AllSources()); | 425 content::NotificationService::AllSources()); |
439 UnloadResults unload_results; | 426 UnloadResults unload_results; |
440 BrowserList::CloseAllBrowsersWithProfile( | 427 BrowserList::CloseAllBrowsersWithProfile( |
441 browser()->profile(), | 428 browser()->profile(), |
442 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), | 429 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), |
443 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), | 430 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), |
444 false); | 431 false); |
445 BrowserList::CloseAllBrowsersWithProfile( | 432 BrowserList::CloseAllBrowsersWithProfile( |
446 browser()->profile(), | 433 browser()->profile(), |
447 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), | 434 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), |
448 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), | 435 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), |
449 false); | 436 false); |
450 ClickModalDialogButton(true); | 437 ClickModalDialogButton(true); |
451 window_observer.Wait(); | 438 window_observer.Wait(); |
452 EXPECT_EQ(1, unload_results.get_successes()); | 439 EXPECT_EQ(1, unload_results.get_successes()); |
453 EXPECT_EQ(0, unload_results.get_aborts()); | 440 EXPECT_EQ(0, unload_results.get_aborts()); |
454 } | 441 } |
455 | 442 |
456 // Tests double calls to BrowserList::CloseAllBrowsersWithProfile, with a | 443 // Tests double calls to BrowserList::CloseAllBrowsersWithProfile, with a |
457 // beforeunload handler and clicking Stay in the beforeunload confirm dialog. | 444 // beforeunload handler and clicking Stay in the beforeunload confirm dialog. |
458 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadCancel) { | 445 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadCancel) { |
459 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); | 446 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); |
460 // Disable the hang monitor, otherwise there will be a race between the | 447 PrepareForDialog(browser()); |
461 // beforeunload dialog and the beforeunload hang timer. | |
462 browser() | |
463 ->tab_strip_model() | |
464 ->GetActiveWebContents() | |
465 ->GetMainFrame() | |
466 ->DisableBeforeUnloadHangMonitorForTesting(); | |
467 | 448 |
468 UnloadResults unload_results; | 449 UnloadResults unload_results; |
469 BrowserList::CloseAllBrowsersWithProfile( | 450 BrowserList::CloseAllBrowsersWithProfile( |
470 browser()->profile(), | 451 browser()->profile(), |
471 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), | 452 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), |
472 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), | 453 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), |
473 false); | 454 false); |
474 BrowserList::CloseAllBrowsersWithProfile( | 455 BrowserList::CloseAllBrowsersWithProfile( |
475 browser()->profile(), | 456 browser()->profile(), |
476 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), | 457 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), |
(...skipping 30 matching lines...) Expand all Loading... |
507 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); | 488 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); |
508 EXPECT_EQ(kill(base::GetCurrentProcessHandle(), SIGTERM), 0); | 489 EXPECT_EQ(kill(base::GetCurrentProcessHandle(), SIGTERM), 0); |
509 } | 490 } |
510 #endif | 491 #endif |
511 | 492 |
512 // Tests closing the browser and clicking OK in the beforeunload confirm dialog | 493 // Tests closing the browser and clicking OK in the beforeunload confirm dialog |
513 // if an inner frame has the focus. | 494 // if an inner frame has the focus. |
514 // If this flakes, use http://crbug.com/32615 and http://crbug.com/45675 | 495 // If this flakes, use http://crbug.com/32615 and http://crbug.com/45675 |
515 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseWithInnerFocusedFrame) { | 496 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseWithInnerFocusedFrame) { |
516 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, "innerframewithfocus"); | 497 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, "innerframewithfocus"); |
517 // Disable the hang monitor, otherwise there will be a race between the | 498 PrepareForDialog(browser()); |
518 // beforeunload dialog and the beforeunload hang timer. | |
519 browser() | |
520 ->tab_strip_model() | |
521 ->GetActiveWebContents() | |
522 ->GetMainFrame() | |
523 ->DisableBeforeUnloadHangMonitorForTesting(); | |
524 | 499 |
525 content::WindowedNotificationObserver window_observer( | 500 content::WindowedNotificationObserver window_observer( |
526 chrome::NOTIFICATION_BROWSER_CLOSED, | 501 chrome::NOTIFICATION_BROWSER_CLOSED, |
527 content::NotificationService::AllSources()); | 502 content::NotificationService::AllSources()); |
528 chrome::CloseWindow(browser()); | 503 chrome::CloseWindow(browser()); |
529 ClickModalDialogButton(true); | 504 ClickModalDialogButton(true); |
530 window_observer.Wait(); | 505 window_observer.Wait(); |
531 } | 506 } |
532 | 507 |
533 // Tests closing the browser with a beforeunload handler that takes forever | 508 // Tests closing the browser with a beforeunload handler that takes forever |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 WindowCloseAfterBeforeUnloadCrash | 863 WindowCloseAfterBeforeUnloadCrash |
889 #endif | 864 #endif |
890 IN_PROC_BROWSER_TEST_F(FastUnloadTest, | 865 IN_PROC_BROWSER_TEST_F(FastUnloadTest, |
891 MAYBE_WindowCloseAfterBeforeUnloadCrash) { | 866 MAYBE_WindowCloseAfterBeforeUnloadCrash) { |
892 // Tests makes no sense in single-process mode since the renderer is hung. | 867 // Tests makes no sense in single-process mode since the renderer is hung. |
893 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 868 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
894 switches::kSingleProcess)) | 869 switches::kSingleProcess)) |
895 return; | 870 return; |
896 | 871 |
897 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); | 872 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); |
| 873 PrepareForDialog(browser()); |
898 content::WebContents* beforeunload_contents = | 874 content::WebContents* beforeunload_contents = |
899 browser()->tab_strip_model()->GetActiveWebContents(); | 875 browser()->tab_strip_model()->GetActiveWebContents(); |
900 | 876 |
901 content::WindowedNotificationObserver window_observer( | 877 content::WindowedNotificationObserver window_observer( |
902 chrome::NOTIFICATION_BROWSER_CLOSED, | 878 chrome::NOTIFICATION_BROWSER_CLOSED, |
903 content::NotificationService::AllSources()); | 879 content::NotificationService::AllSources()); |
904 chrome::CloseWindow(browser()); | 880 chrome::CloseWindow(browser()); |
905 CrashTab(beforeunload_contents); | 881 CrashTab(beforeunload_contents); |
906 window_observer.Wait(); | 882 window_observer.Wait(); |
907 } | 883 } |
(...skipping 12 matching lines...) Expand all Loading... |
920 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), | 896 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), |
921 true); | 897 true); |
922 window_observer.Wait(); | 898 window_observer.Wait(); |
923 EXPECT_EQ(1, unload_results.get_successes()); | 899 EXPECT_EQ(1, unload_results.get_successes()); |
924 EXPECT_EQ(0, unload_results.get_aborts()); | 900 EXPECT_EQ(0, unload_results.get_aborts()); |
925 } | 901 } |
926 | 902 |
927 IN_PROC_BROWSER_TEST_F(FastUnloadTest, | 903 IN_PROC_BROWSER_TEST_F(FastUnloadTest, |
928 BrowserListForceCloseWithBeforeUnloadWithFastUnload) { | 904 BrowserListForceCloseWithBeforeUnloadWithFastUnload) { |
929 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); | 905 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); |
| 906 PrepareForDialog(browser()); |
930 | 907 |
931 content::WindowedNotificationObserver window_observer( | 908 content::WindowedNotificationObserver window_observer( |
932 chrome::NOTIFICATION_BROWSER_CLOSED, | 909 chrome::NOTIFICATION_BROWSER_CLOSED, |
933 content::NotificationService::AllSources()); | 910 content::NotificationService::AllSources()); |
934 UnloadResults unload_results; | 911 UnloadResults unload_results; |
935 BrowserList::CloseAllBrowsersWithProfile( | 912 BrowserList::CloseAllBrowsersWithProfile( |
936 browser()->profile(), | 913 browser()->profile(), |
937 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), | 914 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), |
938 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), | 915 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), |
939 true); | 916 true); |
940 window_observer.Wait(); | 917 window_observer.Wait(); |
941 EXPECT_EQ(1, unload_results.get_successes()); | 918 EXPECT_EQ(1, unload_results.get_successes()); |
942 EXPECT_EQ(0, unload_results.get_aborts()); | 919 EXPECT_EQ(0, unload_results.get_aborts()); |
943 } | 920 } |
944 | 921 |
945 IN_PROC_BROWSER_TEST_F(FastUnloadTest, | 922 IN_PROC_BROWSER_TEST_F(FastUnloadTest, |
946 BrowserListForceCloseAfterNormalCloseWithFastUnload) { | 923 BrowserListForceCloseAfterNormalCloseWithFastUnload) { |
947 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); | 924 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); |
| 925 PrepareForDialog(browser()); |
948 | 926 |
949 content::WindowedNotificationObserver window_observer( | 927 content::WindowedNotificationObserver window_observer( |
950 chrome::NOTIFICATION_BROWSER_CLOSED, | 928 chrome::NOTIFICATION_BROWSER_CLOSED, |
951 content::NotificationService::AllSources()); | 929 content::NotificationService::AllSources()); |
952 UnloadResults unload_results; | 930 UnloadResults unload_results; |
953 BrowserList::CloseAllBrowsersWithProfile( | 931 BrowserList::CloseAllBrowsersWithProfile( |
954 browser()->profile(), | 932 browser()->profile(), |
955 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), | 933 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), |
956 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), | 934 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), |
957 false); | 935 false); |
958 BrowserList::CloseAllBrowsersWithProfile( | 936 BrowserList::CloseAllBrowsersWithProfile( |
959 browser()->profile(), | 937 browser()->profile(), |
960 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), | 938 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), |
961 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), | 939 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), |
962 true); | 940 true); |
963 window_observer.Wait(); | 941 window_observer.Wait(); |
964 EXPECT_EQ(1, unload_results.get_successes()); | 942 EXPECT_EQ(1, unload_results.get_successes()); |
965 EXPECT_EQ(0, unload_results.get_aborts()); | 943 EXPECT_EQ(0, unload_results.get_aborts()); |
966 } | 944 } |
967 | 945 |
968 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs | 946 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs |
969 // and multiple windows. | 947 // and multiple windows. |
OLD | NEW |