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

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

Issue 2750483007: Only show a beforeunload dialog if a frame has been interacted with. (Closed)
Patch Set: rev Created 3 years, 8 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/net/url_request_mock_util.h" 15 #include "chrome/browser/net/url_request_mock_util.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_commands.h" 17 #include "chrome/browser/ui/browser_commands.h"
18 #include "chrome/browser/ui/browser_list.h" 18 #include "chrome/browser/ui/browser_list.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/test/base/in_process_browser_test.h" 21 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/ui_test_utils.h" 22 #include "chrome/test/base/ui_test_utils.h"
23 #include "components/app_modal/javascript_app_modal_dialog.h" 23 #include "components/app_modal/javascript_app_modal_dialog.h"
24 #include "components/app_modal/native_app_modal_dialog.h" 24 #include "components/app_modal/native_app_modal_dialog.h"
25 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/render_frame_host.h"
27 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
28 #include "content/public/common/content_switches.h" 29 #include "content/public/common/content_switches.h"
29 #include "content/public/test/browser_test_utils.h" 30 #include "content/public/test/browser_test_utils.h"
30 #include "net/test/embedded_test_server/embedded_test_server.h" 31 #include "net/test/embedded_test_server/embedded_test_server.h"
31 #include "net/test/url_request/url_request_mock_http_job.h" 32 #include "net/test/url_request/url_request_mock_http_job.h"
32 #include "net/url_request/url_request_test_util.h" 33 #include "net/url_request/url_request_test_util.h"
33 34
34 #if defined(OS_WIN) 35 #if defined(OS_WIN)
35 // For version specific disabled tests below (http://crbug.com/267597). 36 // For version specific disabled tests below (http://crbug.com/267597).
36 #include "base/win/windows_version.h" 37 #include "base/win/windows_version.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // Tests closing the browser on a page with an unload listener registered. 272 // Tests closing the browser on a page with an unload listener registered.
272 // Test marked as flaky in http://crbug.com/51698 273 // Test marked as flaky in http://crbug.com/51698
273 IN_PROC_BROWSER_TEST_F(UnloadTest, DISABLED_BrowserCloseUnload) { 274 IN_PROC_BROWSER_TEST_F(UnloadTest, DISABLED_BrowserCloseUnload) {
274 LoadUrlAndQuitBrowser(UNLOAD_HTML, "unload"); 275 LoadUrlAndQuitBrowser(UNLOAD_HTML, "unload");
275 } 276 }
276 277
277 // Tests closing the browser with a beforeunload handler and clicking 278 // Tests closing the browser with a beforeunload handler and clicking
278 // OK in the beforeunload confirm dialog. 279 // OK in the beforeunload confirm dialog.
279 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) { 280 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) {
280 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 281 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
282 // JavaScript onbeforeunload dialogs require a user gesture.
283 for (auto* frame :
284 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) {
285 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16());
286 }
281 287
282 content::WindowedNotificationObserver window_observer( 288 content::WindowedNotificationObserver window_observer(
283 chrome::NOTIFICATION_BROWSER_CLOSED, 289 chrome::NOTIFICATION_BROWSER_CLOSED,
284 content::NotificationService::AllSources()); 290 content::NotificationService::AllSources());
285 chrome::CloseWindow(browser()); 291 chrome::CloseWindow(browser());
286 ClickModalDialogButton(true); 292 ClickModalDialogButton(true);
287 window_observer.Wait(); 293 window_observer.Wait();
288 } 294 }
289 295
290 // Tests closing the browser with a beforeunload handler and clicking 296 // Tests closing the browser with a beforeunload handler and clicking
291 // CANCEL in the beforeunload confirm dialog. 297 // CANCEL in the beforeunload confirm dialog.
292 // If this test flakes, reopen http://crbug.com/123110 298 // If this test flakes, reopen http://crbug.com/123110
293 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { 299 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) {
294 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 300 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
301 // JavaScript onbeforeunload dialogs require a user gesture.
302 for (auto* frame :
303 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) {
304 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16());
305 }
295 chrome::CloseWindow(browser()); 306 chrome::CloseWindow(browser());
296 307
297 // We wait for the title to change after cancelling the closure of browser 308 // We wait for the title to change after cancelling the closure of browser
298 // window, to ensure that in-flight IPCs from the renderer reach the browser. 309 // window, to ensure that in-flight IPCs from the renderer reach the browser.
299 // Otherwise the browser won't put up the beforeunload dialog because it's 310 // Otherwise the browser won't put up the beforeunload dialog because it's
300 // waiting for an ack from the renderer. 311 // waiting for an ack from the renderer.
301 base::string16 expected_title = base::ASCIIToUTF16("cancelled"); 312 base::string16 expected_title = base::ASCIIToUTF16("cancelled");
302 content::TitleWatcher title_watcher( 313 content::TitleWatcher title_watcher(
303 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); 314 browser()->tab_strip_model()->GetActiveWebContents(), expected_title);
304 ClickModalDialogButton(false); 315 ClickModalDialogButton(false);
(...skipping 25 matching lines...) Expand all
330 false); 341 false);
331 window_observer.Wait(); 342 window_observer.Wait();
332 EXPECT_EQ(1, unload_results.get_successes()); 343 EXPECT_EQ(1, unload_results.get_successes());
333 EXPECT_EQ(0, unload_results.get_aborts()); 344 EXPECT_EQ(0, unload_results.get_aborts());
334 } 345 }
335 346
336 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a 347 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a
337 // beforeunload handler and clicking Leave in the beforeunload confirm dialog. 348 // beforeunload handler and clicking Leave in the beforeunload confirm dialog.
338 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadOK) { 349 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadOK) {
339 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 350 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
351 // JavaScript onbeforeunload dialogs require a user gesture.
352 for (auto* frame :
353 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) {
354 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16());
355 }
340 356
341 content::WindowedNotificationObserver window_observer( 357 content::WindowedNotificationObserver window_observer(
342 chrome::NOTIFICATION_BROWSER_CLOSED, 358 chrome::NOTIFICATION_BROWSER_CLOSED,
343 content::NotificationService::AllSources()); 359 content::NotificationService::AllSources());
344 UnloadResults unload_results; 360 UnloadResults unload_results;
345 BrowserList::CloseAllBrowsersWithProfile( 361 BrowserList::CloseAllBrowsersWithProfile(
346 browser()->profile(), 362 browser()->profile(),
347 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 363 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
348 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 364 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
349 false); 365 false);
350 ClickModalDialogButton(true); 366 ClickModalDialogButton(true);
351 window_observer.Wait(); 367 window_observer.Wait();
352 EXPECT_EQ(1, unload_results.get_successes()); 368 EXPECT_EQ(1, unload_results.get_successes());
353 EXPECT_EQ(0, unload_results.get_aborts()); 369 EXPECT_EQ(0, unload_results.get_aborts());
354 } 370 }
355 371
356 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a 372 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a
357 // beforeunload handler and clicking Stay in the beforeunload confirm dialog. 373 // beforeunload handler and clicking Stay in the beforeunload confirm dialog.
358 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadCancel) { 374 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadCancel) {
359 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 375 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
376 // JavaScript onbeforeunload dialogs require a user gesture.
377 for (auto* frame :
378 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) {
379 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16());
380 }
360 381
361 UnloadResults unload_results; 382 UnloadResults unload_results;
362 BrowserList::CloseAllBrowsersWithProfile( 383 BrowserList::CloseAllBrowsersWithProfile(
363 browser()->profile(), 384 browser()->profile(),
364 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 385 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
365 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 386 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
366 false); 387 false);
367 388
368 // We wait for the title to change after cancelling the closure of browser 389 // We wait for the title to change after cancelling the closure of browser
369 // window, to ensure that in-flight IPCs from the renderer reach the browser. 390 // window, to ensure that in-flight IPCs from the renderer reach the browser.
(...skipping 15 matching lines...) Expand all
385 content::NotificationService::AllSources()); 406 content::NotificationService::AllSources());
386 chrome::CloseWindow(browser()); 407 chrome::CloseWindow(browser());
387 ClickModalDialogButton(true); 408 ClickModalDialogButton(true);
388 window_observer.Wait(); 409 window_observer.Wait();
389 } 410 }
390 411
391 // Tests double calls to BrowserList::CloseAllBrowsersWithProfile, with a 412 // Tests double calls to BrowserList::CloseAllBrowsersWithProfile, with a
392 // beforeunload handler and clicking Leave in the beforeunload confirm dialog. 413 // beforeunload handler and clicking Leave in the beforeunload confirm dialog.
393 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadOK) { 414 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadOK) {
394 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 415 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
416 // JavaScript onbeforeunload dialogs require a user gesture.
417 for (auto* frame :
418 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) {
419 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16());
420 }
395 421
396 content::WindowedNotificationObserver window_observer( 422 content::WindowedNotificationObserver window_observer(
397 chrome::NOTIFICATION_BROWSER_CLOSED, 423 chrome::NOTIFICATION_BROWSER_CLOSED,
398 content::NotificationService::AllSources()); 424 content::NotificationService::AllSources());
399 UnloadResults unload_results; 425 UnloadResults unload_results;
400 BrowserList::CloseAllBrowsersWithProfile( 426 BrowserList::CloseAllBrowsersWithProfile(
401 browser()->profile(), 427 browser()->profile(),
402 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 428 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
403 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 429 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
404 false); 430 false);
405 BrowserList::CloseAllBrowsersWithProfile( 431 BrowserList::CloseAllBrowsersWithProfile(
406 browser()->profile(), 432 browser()->profile(),
407 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 433 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
408 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 434 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
409 false); 435 false);
410 ClickModalDialogButton(true); 436 ClickModalDialogButton(true);
411 window_observer.Wait(); 437 window_observer.Wait();
412 EXPECT_EQ(1, unload_results.get_successes()); 438 EXPECT_EQ(1, unload_results.get_successes());
413 EXPECT_EQ(0, unload_results.get_aborts()); 439 EXPECT_EQ(0, unload_results.get_aborts());
414 } 440 }
415 441
416 // Tests double calls to BrowserList::CloseAllBrowsersWithProfile, with a 442 // Tests double calls to BrowserList::CloseAllBrowsersWithProfile, with a
417 // beforeunload handler and clicking Stay in the beforeunload confirm dialog. 443 // beforeunload handler and clicking Stay in the beforeunload confirm dialog.
418 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadCancel) { 444 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadCancel) {
419 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 445 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
446 // JavaScript onbeforeunload dialogs require a user gesture.
447 for (auto* frame :
448 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) {
449 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16());
450 }
420 451
421 UnloadResults unload_results; 452 UnloadResults unload_results;
422 BrowserList::CloseAllBrowsersWithProfile( 453 BrowserList::CloseAllBrowsersWithProfile(
423 browser()->profile(), 454 browser()->profile(),
424 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 455 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
425 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 456 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
426 false); 457 false);
427 BrowserList::CloseAllBrowsersWithProfile( 458 BrowserList::CloseAllBrowsersWithProfile(
428 browser()->profile(), 459 browser()->profile(),
429 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 460 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
(...skipping 21 matching lines...) Expand all
451 chrome::CloseWindow(browser()); 482 chrome::CloseWindow(browser());
452 ClickModalDialogButton(true); 483 ClickModalDialogButton(true);
453 window_observer.Wait(); 484 window_observer.Wait();
454 } 485 }
455 486
456 // Tests terminating the browser with a beforeunload handler. 487 // Tests terminating the browser with a beforeunload handler.
457 // Currently only ChromeOS shuts down gracefully. 488 // Currently only ChromeOS shuts down gracefully.
458 #if defined(OS_CHROMEOS) 489 #if defined(OS_CHROMEOS)
459 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserTerminateBeforeUnload) { 490 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserTerminateBeforeUnload) {
460 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 491 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
492 // JavaScript onbeforeunload dialogs require a user gesture.
493 for (auto* frame :
494 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) {
495 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16());
496 }
461 EXPECT_EQ(kill(base::GetCurrentProcessHandle(), SIGTERM), 0); 497 EXPECT_EQ(kill(base::GetCurrentProcessHandle(), SIGTERM), 0);
462 } 498 }
463 #endif 499 #endif
464 500
465 // Tests closing the browser and clicking OK in the beforeunload confirm dialog 501 // Tests closing the browser and clicking OK in the beforeunload confirm dialog
466 // if an inner frame has the focus. 502 // if an inner frame has the focus.
467 // If this flakes, use http://crbug.com/32615 and http://crbug.com/45675 503 // If this flakes, use http://crbug.com/32615 and http://crbug.com/45675
468 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseWithInnerFocusedFrame) { 504 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseWithInnerFocusedFrame) {
469 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, "innerframewithfocus"); 505 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, "innerframewithfocus");
506 // JavaScript onbeforeunload dialogs require a user gesture.
507 for (auto* frame :
508 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) {
509 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16());
510 }
470 511
471 content::WindowedNotificationObserver window_observer( 512 content::WindowedNotificationObserver window_observer(
472 chrome::NOTIFICATION_BROWSER_CLOSED, 513 chrome::NOTIFICATION_BROWSER_CLOSED,
473 content::NotificationService::AllSources()); 514 content::NotificationService::AllSources());
474 chrome::CloseWindow(browser()); 515 chrome::CloseWindow(browser());
475 ClickModalDialogButton(true); 516 ClickModalDialogButton(true);
476 window_observer.Wait(); 517 window_observer.Wait();
477 } 518 }
478 519
479 // Tests closing the browser with a beforeunload handler that takes forever 520 // Tests closing the browser with a beforeunload handler that takes forever
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 629 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
589 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 630 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
590 true); 631 true);
591 window_observer.Wait(); 632 window_observer.Wait();
592 EXPECT_EQ(1, unload_results.get_successes()); 633 EXPECT_EQ(1, unload_results.get_successes());
593 EXPECT_EQ(0, unload_results.get_aborts()); 634 EXPECT_EQ(0, unload_results.get_aborts());
594 } 635 }
595 636
596 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListForceCloseWithBeforeUnload) { 637 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListForceCloseWithBeforeUnload) {
597 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 638 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
639 // JavaScript onbeforeunload dialogs require a user gesture.
640 for (auto* frame :
641 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) {
642 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16());
643 }
598 644
599 content::WindowedNotificationObserver window_observer( 645 content::WindowedNotificationObserver window_observer(
600 chrome::NOTIFICATION_BROWSER_CLOSED, 646 chrome::NOTIFICATION_BROWSER_CLOSED,
601 content::NotificationService::AllSources()); 647 content::NotificationService::AllSources());
602 UnloadResults unload_results; 648 UnloadResults unload_results;
603 BrowserList::CloseAllBrowsersWithProfile( 649 BrowserList::CloseAllBrowsersWithProfile(
604 browser()->profile(), 650 browser()->profile(),
605 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 651 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
606 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 652 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
607 true); 653 true);
608 window_observer.Wait(); 654 window_observer.Wait();
609 EXPECT_EQ(1, unload_results.get_successes()); 655 EXPECT_EQ(1, unload_results.get_successes());
610 EXPECT_EQ(0, unload_results.get_aborts()); 656 EXPECT_EQ(0, unload_results.get_aborts());
611 } 657 }
612 658
613 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListForceCloseAfterNormalClose) { 659 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListForceCloseAfterNormalClose) {
614 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 660 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
661 // JavaScript onbeforeunload dialogs require a user gesture.
662 for (auto* frame :
663 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) {
664 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16());
665 }
615 666
616 content::WindowedNotificationObserver window_observer( 667 content::WindowedNotificationObserver window_observer(
617 chrome::NOTIFICATION_BROWSER_CLOSED, 668 chrome::NOTIFICATION_BROWSER_CLOSED,
618 content::NotificationService::AllSources()); 669 content::NotificationService::AllSources());
619 UnloadResults unload_results; 670 UnloadResults unload_results;
620 BrowserList::CloseAllBrowsersWithProfile( 671 BrowserList::CloseAllBrowsersWithProfile(
621 browser()->profile(), 672 browser()->profile(),
622 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 673 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
623 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 674 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
624 false); 675 false);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 WindowCloseAfterBeforeUnloadCrash 885 WindowCloseAfterBeforeUnloadCrash
835 #endif 886 #endif
836 IN_PROC_BROWSER_TEST_F(FastUnloadTest, 887 IN_PROC_BROWSER_TEST_F(FastUnloadTest,
837 MAYBE_WindowCloseAfterBeforeUnloadCrash) { 888 MAYBE_WindowCloseAfterBeforeUnloadCrash) {
838 // Tests makes no sense in single-process mode since the renderer is hung. 889 // Tests makes no sense in single-process mode since the renderer is hung.
839 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 890 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
840 switches::kSingleProcess)) 891 switches::kSingleProcess))
841 return; 892 return;
842 893
843 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 894 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
895 // JavaScript onbeforeunload dialogs require a user gesture.
896 for (auto* frame :
897 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) {
898 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16());
899 }
844 content::WebContents* beforeunload_contents = 900 content::WebContents* beforeunload_contents =
845 browser()->tab_strip_model()->GetActiveWebContents(); 901 browser()->tab_strip_model()->GetActiveWebContents();
846 902
847 content::WindowedNotificationObserver window_observer( 903 content::WindowedNotificationObserver window_observer(
848 chrome::NOTIFICATION_BROWSER_CLOSED, 904 chrome::NOTIFICATION_BROWSER_CLOSED,
849 content::NotificationService::AllSources()); 905 content::NotificationService::AllSources());
850 chrome::CloseWindow(browser()); 906 chrome::CloseWindow(browser());
851 CrashTab(beforeunload_contents); 907 CrashTab(beforeunload_contents);
852 window_observer.Wait(); 908 window_observer.Wait();
853 } 909 }
(...skipping 12 matching lines...) Expand all
866 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 922 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
867 true); 923 true);
868 window_observer.Wait(); 924 window_observer.Wait();
869 EXPECT_EQ(1, unload_results.get_successes()); 925 EXPECT_EQ(1, unload_results.get_successes());
870 EXPECT_EQ(0, unload_results.get_aborts()); 926 EXPECT_EQ(0, unload_results.get_aborts());
871 } 927 }
872 928
873 IN_PROC_BROWSER_TEST_F(FastUnloadTest, 929 IN_PROC_BROWSER_TEST_F(FastUnloadTest,
874 BrowserListForceCloseWithBeforeUnloadWithFastUnload) { 930 BrowserListForceCloseWithBeforeUnloadWithFastUnload) {
875 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 931 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
932 // JavaScript onbeforeunload dialogs require a user gesture.
933 for (auto* frame :
934 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) {
935 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16());
936 }
876 937
877 content::WindowedNotificationObserver window_observer( 938 content::WindowedNotificationObserver window_observer(
878 chrome::NOTIFICATION_BROWSER_CLOSED, 939 chrome::NOTIFICATION_BROWSER_CLOSED,
879 content::NotificationService::AllSources()); 940 content::NotificationService::AllSources());
880 UnloadResults unload_results; 941 UnloadResults unload_results;
881 BrowserList::CloseAllBrowsersWithProfile( 942 BrowserList::CloseAllBrowsersWithProfile(
882 browser()->profile(), 943 browser()->profile(),
883 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 944 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
884 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 945 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
885 true); 946 true);
886 window_observer.Wait(); 947 window_observer.Wait();
887 EXPECT_EQ(1, unload_results.get_successes()); 948 EXPECT_EQ(1, unload_results.get_successes());
888 EXPECT_EQ(0, unload_results.get_aborts()); 949 EXPECT_EQ(0, unload_results.get_aborts());
889 } 950 }
890 951
891 IN_PROC_BROWSER_TEST_F(FastUnloadTest, 952 IN_PROC_BROWSER_TEST_F(FastUnloadTest,
892 BrowserListForceCloseAfterNormalCloseWithFastUnload) { 953 BrowserListForceCloseAfterNormalCloseWithFastUnload) {
893 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 954 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
955 // JavaScript onbeforeunload dialogs require a user gesture.
956 for (auto* frame :
957 browser()->tab_strip_model()->GetActiveWebContents()->GetAllFrames()) {
958 frame->ExecuteJavaScriptWithUserGestureForTests(base::string16());
959 }
894 960
895 content::WindowedNotificationObserver window_observer( 961 content::WindowedNotificationObserver window_observer(
896 chrome::NOTIFICATION_BROWSER_CLOSED, 962 chrome::NOTIFICATION_BROWSER_CLOSED,
897 content::NotificationService::AllSources()); 963 content::NotificationService::AllSources());
898 UnloadResults unload_results; 964 UnloadResults unload_results;
899 BrowserList::CloseAllBrowsersWithProfile( 965 BrowserList::CloseAllBrowsersWithProfile(
900 browser()->profile(), 966 browser()->profile(),
901 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 967 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
902 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 968 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
903 false); 969 false);
904 BrowserList::CloseAllBrowsersWithProfile( 970 BrowserList::CloseAllBrowsersWithProfile(
905 browser()->profile(), 971 browser()->profile(),
906 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 972 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
907 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 973 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
908 true); 974 true);
909 window_observer.Wait(); 975 window_observer.Wait();
910 EXPECT_EQ(1, unload_results.get_successes()); 976 EXPECT_EQ(1, unload_results.get_successes());
911 EXPECT_EQ(0, unload_results.get_aborts()); 977 EXPECT_EQ(0, unload_results.get_aborts());
912 } 978 }
913 979
914 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs 980 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
915 // and multiple windows. 981 // 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