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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 content::WindowedNotificationObserver load_stop_observer( | 399 content::WindowedNotificationObserver load_stop_observer( |
400 content::NOTIFICATION_LOAD_STOP, | 400 content::NOTIFICATION_LOAD_STOP, |
401 content::NotificationService::AllSources()); | 401 content::NotificationService::AllSources()); |
402 content::SimulateMouseClick( | 402 content::SimulateMouseClick( |
403 browser()->tab_strip_model()->GetActiveWebContents(), 0, | 403 browser()->tab_strip_model()->GetActiveWebContents(), 0, |
404 WebKit::WebMouseEvent::ButtonLeft); | 404 WebKit::WebMouseEvent::ButtonLeft); |
405 observer.Wait(); | 405 observer.Wait(); |
406 load_stop_observer.Wait(); | 406 load_stop_observer.Wait(); |
407 CheckTitle("popup"); | 407 CheckTitle("popup"); |
408 | 408 |
409 content::WindowedNotificationObserver tab_close_observer( | 409 content::WebContentsDestroyedWatcher destroyed_watcher( |
410 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 410 browser()->tab_strip_model()->GetActiveWebContents()); |
411 content::NotificationService::AllSources()); | |
412 chrome::CloseTab(browser()); | 411 chrome::CloseTab(browser()); |
413 tab_close_observer.Wait(); | 412 destroyed_watcher.Wait(); |
414 | 413 |
415 CheckTitle("only_one_unload"); | 414 CheckTitle("only_one_unload"); |
416 } | 415 } |
417 | 416 |
418 class FastUnloadTest : public UnloadTest { | 417 class FastUnloadTest : public UnloadTest { |
419 public: | 418 public: |
420 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 419 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
421 UnloadTest::SetUpCommandLine(command_line); | 420 UnloadTest::SetUpCommandLine(command_line); |
422 command_line->AppendSwitch(switches::kEnableFastUnload); | 421 command_line->AppendSwitch(switches::kEnableFastUnload); |
423 } | 422 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 DISABLED_UnloadHidden | 486 DISABLED_UnloadHidden |
488 #else | 487 #else |
489 #define MAYBE_UnloadHidden \ | 488 #define MAYBE_UnloadHidden \ |
490 UnloadHidden | 489 UnloadHidden |
491 #endif | 490 #endif |
492 IN_PROC_BROWSER_TEST_F(FastUnloadTest, MAYBE_UnloadHidden) { | 491 IN_PROC_BROWSER_TEST_F(FastUnloadTest, MAYBE_UnloadHidden) { |
493 NavigateToPage("no_listeners"); | 492 NavigateToPage("no_listeners"); |
494 NavigateToPageInNewTab("unload_sets_cookie"); | 493 NavigateToPageInNewTab("unload_sets_cookie"); |
495 EXPECT_EQ("", GetCookies("no_listeners")); | 494 EXPECT_EQ("", GetCookies("no_listeners")); |
496 | 495 |
| 496 content::WebContentsDestroyedWatcher destroyed_watcher( |
| 497 browser()->tab_strip_model()->GetActiveWebContents()); |
| 498 |
497 { | 499 { |
498 base::RunLoop run_loop; | 500 base::RunLoop run_loop; |
499 FastTabCloseTabStripModelObserver observer( | 501 FastTabCloseTabStripModelObserver observer( |
500 browser()->tab_strip_model(), &run_loop); | 502 browser()->tab_strip_model(), &run_loop); |
501 chrome::CloseTab(browser()); | 503 chrome::CloseTab(browser()); |
502 run_loop.Run(); | 504 run_loop.Run(); |
503 } | 505 } |
504 | 506 |
505 // Check that the browser only has the original tab. | 507 // Check that the browser only has the original tab. |
506 CheckTitle("no_listeners"); | 508 CheckTitle("no_listeners"); |
507 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 509 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
508 | 510 |
509 // Show that the web contents to go away after the was removed. | 511 // Wait for the actual destruction. |
510 // Without unload-detached, this times-out because it happens earlier. | 512 destroyed_watcher.Wait(); |
511 content::WindowedNotificationObserver contents_destroyed_observer( | |
512 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
513 content::NotificationService::AllSources()); | |
514 contents_destroyed_observer.Wait(); | |
515 | 513 |
516 // Browser still has the same tab. | 514 // Verify that the destruction had the desired effect. |
517 CheckTitle("no_listeners"); | |
518 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
519 EXPECT_EQ("unloaded=ohyeah", GetCookies("no_listeners")); | 515 EXPECT_EQ("unloaded=ohyeah", GetCookies("no_listeners")); |
520 } | 516 } |
521 | 517 |
522 // Test that fast-tab-close does not break a solo tab. | 518 // Test that fast-tab-close does not break a solo tab. |
523 IN_PROC_BROWSER_TEST_F(FastUnloadTest, PRE_ClosingLastTabFinishesUnload) { | 519 IN_PROC_BROWSER_TEST_F(FastUnloadTest, PRE_ClosingLastTabFinishesUnload) { |
524 // The unload handler sleeps before setting the cookie to catch cases when | 520 // The unload handler sleeps before setting the cookie to catch cases when |
525 // unload handlers are not allowed to run to completion. (For example, | 521 // unload handlers are not allowed to run to completion. (For example, |
526 // using the detached handler for the tab and then closing the browser.) | 522 // using the detached handler for the tab and then closing the browser.) |
527 NavigateToPage("unload_sleep_before_cookie"); | 523 NavigateToPage("unload_sleep_before_cookie"); |
528 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 524 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 content::WindowedNotificationObserver window_observer( | 633 content::WindowedNotificationObserver window_observer( |
638 chrome::NOTIFICATION_BROWSER_CLOSED, | 634 chrome::NOTIFICATION_BROWSER_CLOSED, |
639 content::NotificationService::AllSources()); | 635 content::NotificationService::AllSources()); |
640 chrome::CloseWindow(browser()); | 636 chrome::CloseWindow(browser()); |
641 CrashTab(beforeunload_contents); | 637 CrashTab(beforeunload_contents); |
642 window_observer.Wait(); | 638 window_observer.Wait(); |
643 } | 639 } |
644 | 640 |
645 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs | 641 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs |
646 // and multiple windows. | 642 // and multiple windows. |
OLD | NEW |