Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(694)

Side by Side Diff: chrome/browser/unload_browsertest.cc

Issue 2801813005: Only show a beforeunload dialog if a frame has had a user gesture since its load. (Closed)
Patch Set: one last bit Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 void PrepareForDialog(Browser* browser) {
209 for (int i = 0; i < browser->tab_strip_model()->count(); i++) {
210 content::PrepContentsForBeforeUnloadTest(
211 browser->tab_strip_model()->GetWebContentsAt(i));
212 }
213 }
207 }; 214 };
208 215
209 // Navigate to a page with an infinite unload handler. 216 // Navigate to a page with an infinite unload handler.
210 // Then two async crosssite requests to ensure 217 // Then two async crosssite requests to ensure
211 // we don't get confused and think we're closing the tab. 218 // we don't get confused and think we're closing the tab.
212 // 219 //
213 // This test is flaky on the valgrind UI bots. http://crbug.com/39057 220 // This test is flaky on the valgrind UI bots. http://crbug.com/39057
214 IN_PROC_BROWSER_TEST_F(UnloadTest, CrossSiteInfiniteUnloadAsync) { 221 IN_PROC_BROWSER_TEST_F(UnloadTest, CrossSiteInfiniteUnloadAsync) {
215 // Tests makes no sense in single-process mode since the renderer is hung. 222 // Tests makes no sense in single-process mode since the renderer is hung.
216 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 223 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // Tests closing the browser on a page with an unload listener registered. 282 // Tests closing the browser on a page with an unload listener registered.
276 // Test marked as flaky in http://crbug.com/51698 283 // Test marked as flaky in http://crbug.com/51698
277 IN_PROC_BROWSER_TEST_F(UnloadTest, DISABLED_BrowserCloseUnload) { 284 IN_PROC_BROWSER_TEST_F(UnloadTest, DISABLED_BrowserCloseUnload) {
278 LoadUrlAndQuitBrowser(UNLOAD_HTML, "unload"); 285 LoadUrlAndQuitBrowser(UNLOAD_HTML, "unload");
279 } 286 }
280 287
281 // Tests closing the browser with a beforeunload handler and clicking 288 // Tests closing the browser with a beforeunload handler and clicking
282 // OK in the beforeunload confirm dialog. 289 // OK in the beforeunload confirm dialog.
283 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) { 290 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) {
284 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 291 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
285 // Disable the hang monitor, otherwise there will be a race between the 292 PrepareForDialog(browser());
286 // beforeunload dialog and the beforeunload hang timer.
287 browser()
288 ->tab_strip_model()
289 ->GetActiveWebContents()
290 ->GetMainFrame()
291 ->DisableBeforeUnloadHangMonitorForTesting();
292 293
293 content::WindowedNotificationObserver window_observer( 294 content::WindowedNotificationObserver window_observer(
294 chrome::NOTIFICATION_BROWSER_CLOSED, 295 chrome::NOTIFICATION_BROWSER_CLOSED,
295 content::NotificationService::AllSources()); 296 content::NotificationService::AllSources());
296 chrome::CloseWindow(browser()); 297 chrome::CloseWindow(browser());
297 ClickModalDialogButton(true); 298 ClickModalDialogButton(true);
298 window_observer.Wait(); 299 window_observer.Wait();
299 } 300 }
300 301
301 // Tests closing the browser with a beforeunload handler and clicking 302 // Tests closing the browser with a beforeunload handler and clicking
302 // CANCEL in the beforeunload confirm dialog. 303 // CANCEL in the beforeunload confirm dialog.
303 // If this test flakes, reopen http://crbug.com/123110 304 // If this test flakes, reopen http://crbug.com/123110
304 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { 305 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) {
305 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 306 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
306 // Disable the hang monitor, otherwise there will be a race between the 307 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()); 308 chrome::CloseWindow(browser());
315 309
316 // We wait for the title to change after cancelling the closure of browser 310 // 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. 311 // 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 312 // Otherwise the browser won't put up the beforeunload dialog because it's
319 // waiting for an ack from the renderer. 313 // waiting for an ack from the renderer.
320 base::string16 expected_title = base::ASCIIToUTF16("cancelled"); 314 base::string16 expected_title = base::ASCIIToUTF16("cancelled");
321 content::TitleWatcher title_watcher( 315 content::TitleWatcher title_watcher(
322 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); 316 browser()->tab_strip_model()->GetActiveWebContents(), expected_title);
323 ClickModalDialogButton(false); 317 ClickModalDialogButton(false);
(...skipping 25 matching lines...) Expand all
349 false); 343 false);
350 window_observer.Wait(); 344 window_observer.Wait();
351 EXPECT_EQ(1, unload_results.get_successes()); 345 EXPECT_EQ(1, unload_results.get_successes());
352 EXPECT_EQ(0, unload_results.get_aborts()); 346 EXPECT_EQ(0, unload_results.get_aborts());
353 } 347 }
354 348
355 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a 349 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a
356 // beforeunload handler and clicking Leave in the beforeunload confirm dialog. 350 // beforeunload handler and clicking Leave in the beforeunload confirm dialog.
357 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadOK) { 351 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadOK) {
358 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 352 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
359 // Disable the hang monitor, otherwise there will be a race between the 353 PrepareForDialog(browser());
360 // beforeunload dialog and the beforeunload hang timer.
361 browser()
362 ->tab_strip_model()
363 ->GetActiveWebContents()
364 ->GetMainFrame()
365 ->DisableBeforeUnloadHangMonitorForTesting();
366 354
367 content::WindowedNotificationObserver window_observer( 355 content::WindowedNotificationObserver window_observer(
368 chrome::NOTIFICATION_BROWSER_CLOSED, 356 chrome::NOTIFICATION_BROWSER_CLOSED,
369 content::NotificationService::AllSources()); 357 content::NotificationService::AllSources());
370 UnloadResults unload_results; 358 UnloadResults unload_results;
371 BrowserList::CloseAllBrowsersWithProfile( 359 BrowserList::CloseAllBrowsersWithProfile(
372 browser()->profile(), 360 browser()->profile(),
373 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 361 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
374 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 362 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
375 false); 363 false);
376 ClickModalDialogButton(true); 364 ClickModalDialogButton(true);
377 window_observer.Wait(); 365 window_observer.Wait();
378 EXPECT_EQ(1, unload_results.get_successes()); 366 EXPECT_EQ(1, unload_results.get_successes());
379 EXPECT_EQ(0, unload_results.get_aborts()); 367 EXPECT_EQ(0, unload_results.get_aborts());
380 } 368 }
381 369
382 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a 370 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a
383 // beforeunload handler and clicking Stay in the beforeunload confirm dialog. 371 // beforeunload handler and clicking Stay in the beforeunload confirm dialog.
384 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadCancel) { 372 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadCancel) {
385 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 373 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
386 // Disable the hang monitor, otherwise there will be a race between the 374 PrepareForDialog(browser());
387 // beforeunload dialog and the beforeunload hang timer.
388 browser()
389 ->tab_strip_model()
390 ->GetActiveWebContents()
391 ->GetMainFrame()
392 ->DisableBeforeUnloadHangMonitorForTesting();
393 375
394 UnloadResults unload_results; 376 UnloadResults unload_results;
395 BrowserList::CloseAllBrowsersWithProfile( 377 BrowserList::CloseAllBrowsersWithProfile(
396 browser()->profile(), 378 browser()->profile(),
397 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 379 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
398 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 380 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
399 false); 381 false);
400 382
401 // We wait for the title to change after cancelling the closure of browser 383 // 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. 384 // window, to ensure that in-flight IPCs from the renderer reach the browser.
(...skipping 15 matching lines...) Expand all
418 content::NotificationService::AllSources()); 400 content::NotificationService::AllSources());
419 chrome::CloseWindow(browser()); 401 chrome::CloseWindow(browser());
420 ClickModalDialogButton(true); 402 ClickModalDialogButton(true);
421 window_observer.Wait(); 403 window_observer.Wait();
422 } 404 }
423 405
424 // Tests double calls to BrowserList::CloseAllBrowsersWithProfile, with a 406 // Tests double calls to BrowserList::CloseAllBrowsersWithProfile, with a
425 // beforeunload handler and clicking Leave in the beforeunload confirm dialog. 407 // beforeunload handler and clicking Leave in the beforeunload confirm dialog.
426 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadOK) { 408 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadOK) {
427 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 409 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
428 // Disable the hang monitor, otherwise there will be a race between the 410 PrepareForDialog(browser());
429 // beforeunload dialog and the beforeunload hang timer.
430 browser()
431 ->tab_strip_model()
432 ->GetActiveWebContents()
433 ->GetMainFrame()
434 ->DisableBeforeUnloadHangMonitorForTesting();
435 411
436 content::WindowedNotificationObserver window_observer( 412 content::WindowedNotificationObserver window_observer(
437 chrome::NOTIFICATION_BROWSER_CLOSED, 413 chrome::NOTIFICATION_BROWSER_CLOSED,
438 content::NotificationService::AllSources()); 414 content::NotificationService::AllSources());
439 UnloadResults unload_results; 415 UnloadResults unload_results;
440 BrowserList::CloseAllBrowsersWithProfile( 416 BrowserList::CloseAllBrowsersWithProfile(
441 browser()->profile(), 417 browser()->profile(),
442 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 418 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
443 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 419 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
444 false); 420 false);
445 BrowserList::CloseAllBrowsersWithProfile( 421 BrowserList::CloseAllBrowsersWithProfile(
446 browser()->profile(), 422 browser()->profile(),
447 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 423 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
448 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 424 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
449 false); 425 false);
450 ClickModalDialogButton(true); 426 ClickModalDialogButton(true);
451 window_observer.Wait(); 427 window_observer.Wait();
452 EXPECT_EQ(1, unload_results.get_successes()); 428 EXPECT_EQ(1, unload_results.get_successes());
453 EXPECT_EQ(0, unload_results.get_aborts()); 429 EXPECT_EQ(0, unload_results.get_aborts());
454 } 430 }
455 431
456 // Tests double calls to BrowserList::CloseAllBrowsersWithProfile, with a 432 // Tests double calls to BrowserList::CloseAllBrowsersWithProfile, with a
457 // beforeunload handler and clicking Stay in the beforeunload confirm dialog. 433 // beforeunload handler and clicking Stay in the beforeunload confirm dialog.
458 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadCancel) { 434 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadCancel) {
459 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 435 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
460 // Disable the hang monitor, otherwise there will be a race between the 436 PrepareForDialog(browser());
461 // beforeunload dialog and the beforeunload hang timer.
462 browser()
463 ->tab_strip_model()
464 ->GetActiveWebContents()
465 ->GetMainFrame()
466 ->DisableBeforeUnloadHangMonitorForTesting();
467 437
468 UnloadResults unload_results; 438 UnloadResults unload_results;
469 BrowserList::CloseAllBrowsersWithProfile( 439 BrowserList::CloseAllBrowsersWithProfile(
470 browser()->profile(), 440 browser()->profile(),
471 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 441 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
472 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 442 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
473 false); 443 false);
474 BrowserList::CloseAllBrowsersWithProfile( 444 BrowserList::CloseAllBrowsersWithProfile(
475 browser()->profile(), 445 browser()->profile(),
476 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 446 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
(...skipping 30 matching lines...) Expand all
507 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 477 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
508 EXPECT_EQ(kill(base::GetCurrentProcessHandle(), SIGTERM), 0); 478 EXPECT_EQ(kill(base::GetCurrentProcessHandle(), SIGTERM), 0);
509 } 479 }
510 #endif 480 #endif
511 481
512 // Tests closing the browser and clicking OK in the beforeunload confirm dialog 482 // Tests closing the browser and clicking OK in the beforeunload confirm dialog
513 // if an inner frame has the focus. 483 // if an inner frame has the focus.
514 // If this flakes, use http://crbug.com/32615 and http://crbug.com/45675 484 // If this flakes, use http://crbug.com/32615 and http://crbug.com/45675
515 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseWithInnerFocusedFrame) { 485 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseWithInnerFocusedFrame) {
516 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, "innerframewithfocus"); 486 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, "innerframewithfocus");
517 // Disable the hang monitor, otherwise there will be a race between the 487 PrepareForDialog(browser());
518 // beforeunload dialog and the beforeunload hang timer.
519 browser()
520 ->tab_strip_model()
521 ->GetActiveWebContents()
522 ->GetMainFrame()
523 ->DisableBeforeUnloadHangMonitorForTesting();
524 488
525 content::WindowedNotificationObserver window_observer( 489 content::WindowedNotificationObserver window_observer(
526 chrome::NOTIFICATION_BROWSER_CLOSED, 490 chrome::NOTIFICATION_BROWSER_CLOSED,
527 content::NotificationService::AllSources()); 491 content::NotificationService::AllSources());
528 chrome::CloseWindow(browser()); 492 chrome::CloseWindow(browser());
529 ClickModalDialogButton(true); 493 ClickModalDialogButton(true);
530 window_observer.Wait(); 494 window_observer.Wait();
531 } 495 }
532 496
533 // Tests closing the browser with a beforeunload handler that takes forever 497 // Tests closing the browser with a beforeunload handler that takes forever
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 WindowCloseAfterBeforeUnloadCrash 852 WindowCloseAfterBeforeUnloadCrash
889 #endif 853 #endif
890 IN_PROC_BROWSER_TEST_F(FastUnloadTest, 854 IN_PROC_BROWSER_TEST_F(FastUnloadTest,
891 MAYBE_WindowCloseAfterBeforeUnloadCrash) { 855 MAYBE_WindowCloseAfterBeforeUnloadCrash) {
892 // Tests makes no sense in single-process mode since the renderer is hung. 856 // Tests makes no sense in single-process mode since the renderer is hung.
893 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 857 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
894 switches::kSingleProcess)) 858 switches::kSingleProcess))
895 return; 859 return;
896 860
897 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 861 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
862 PrepareForDialog(browser());
898 content::WebContents* beforeunload_contents = 863 content::WebContents* beforeunload_contents =
899 browser()->tab_strip_model()->GetActiveWebContents(); 864 browser()->tab_strip_model()->GetActiveWebContents();
900 865
901 content::WindowedNotificationObserver window_observer( 866 content::WindowedNotificationObserver window_observer(
902 chrome::NOTIFICATION_BROWSER_CLOSED, 867 chrome::NOTIFICATION_BROWSER_CLOSED,
903 content::NotificationService::AllSources()); 868 content::NotificationService::AllSources());
904 chrome::CloseWindow(browser()); 869 chrome::CloseWindow(browser());
905 CrashTab(beforeunload_contents); 870 CrashTab(beforeunload_contents);
906 window_observer.Wait(); 871 window_observer.Wait();
907 } 872 }
(...skipping 12 matching lines...) Expand all
920 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 885 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
921 true); 886 true);
922 window_observer.Wait(); 887 window_observer.Wait();
923 EXPECT_EQ(1, unload_results.get_successes()); 888 EXPECT_EQ(1, unload_results.get_successes());
924 EXPECT_EQ(0, unload_results.get_aborts()); 889 EXPECT_EQ(0, unload_results.get_aborts());
925 } 890 }
926 891
927 IN_PROC_BROWSER_TEST_F(FastUnloadTest, 892 IN_PROC_BROWSER_TEST_F(FastUnloadTest,
928 BrowserListForceCloseWithBeforeUnloadWithFastUnload) { 893 BrowserListForceCloseWithBeforeUnloadWithFastUnload) {
929 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 894 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
895 PrepareForDialog(browser());
930 896
931 content::WindowedNotificationObserver window_observer( 897 content::WindowedNotificationObserver window_observer(
932 chrome::NOTIFICATION_BROWSER_CLOSED, 898 chrome::NOTIFICATION_BROWSER_CLOSED,
933 content::NotificationService::AllSources()); 899 content::NotificationService::AllSources());
934 UnloadResults unload_results; 900 UnloadResults unload_results;
935 BrowserList::CloseAllBrowsersWithProfile( 901 BrowserList::CloseAllBrowsersWithProfile(
936 browser()->profile(), 902 browser()->profile(),
937 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 903 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
938 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 904 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
939 true); 905 true);
940 window_observer.Wait(); 906 window_observer.Wait();
941 EXPECT_EQ(1, unload_results.get_successes()); 907 EXPECT_EQ(1, unload_results.get_successes());
942 EXPECT_EQ(0, unload_results.get_aborts()); 908 EXPECT_EQ(0, unload_results.get_aborts());
943 } 909 }
944 910
945 IN_PROC_BROWSER_TEST_F(FastUnloadTest, 911 IN_PROC_BROWSER_TEST_F(FastUnloadTest,
946 BrowserListForceCloseAfterNormalCloseWithFastUnload) { 912 BrowserListForceCloseAfterNormalCloseWithFastUnload) {
947 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 913 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
914 PrepareForDialog(browser());
948 915
949 content::WindowedNotificationObserver window_observer( 916 content::WindowedNotificationObserver window_observer(
950 chrome::NOTIFICATION_BROWSER_CLOSED, 917 chrome::NOTIFICATION_BROWSER_CLOSED,
951 content::NotificationService::AllSources()); 918 content::NotificationService::AllSources());
952 UnloadResults unload_results; 919 UnloadResults unload_results;
953 BrowserList::CloseAllBrowsersWithProfile( 920 BrowserList::CloseAllBrowsersWithProfile(
954 browser()->profile(), 921 browser()->profile(),
955 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 922 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
956 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 923 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
957 false); 924 false);
958 BrowserList::CloseAllBrowsersWithProfile( 925 BrowserList::CloseAllBrowsersWithProfile(
959 browser()->profile(), 926 browser()->profile(),
960 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 927 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
961 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 928 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
962 true); 929 true);
963 window_observer.Wait(); 930 window_observer.Wait();
964 EXPECT_EQ(1, unload_results.get_successes()); 931 EXPECT_EQ(1, unload_results.get_successes());
965 EXPECT_EQ(0, unload_results.get_aborts()); 932 EXPECT_EQ(0, unload_results.get_aborts());
966 } 933 }
967 934
968 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs 935 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
969 // and multiple windows. 936 // and multiple windows.
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_browsertest.cc ('k') | content/browser/frame_host/render_frame_host_impl_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698