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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 const std::string CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER = | 107 const std::string CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER = |
108 "<html><head><title>only_one_unload</title></head>" | 108 "<html><head><title>only_one_unload</title></head>" |
109 "<body onclick=\"window.open('data:text/html," | 109 "<body onclick=\"window.open('data:text/html," |
110 "<html><head><title>popup</title></head></body>')\" " | 110 "<html><head><title>popup</title></head></body>')\" " |
111 "onbeforeunload='return;'>" | 111 "onbeforeunload='return;'>" |
112 "</body></html>"; | 112 "</body></html>"; |
113 | 113 |
114 class UnloadTest : public InProcessBrowserTest { | 114 class UnloadTest : public InProcessBrowserTest { |
115 public: | 115 public: |
116 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 116 virtual void SetUpCommandLine(CommandLine* command_line) override { |
117 const testing::TestInfo* const test_info = | 117 const testing::TestInfo* const test_info = |
118 testing::UnitTest::GetInstance()->current_test_info(); | 118 testing::UnitTest::GetInstance()->current_test_info(); |
119 if (strcmp(test_info->name(), | 119 if (strcmp(test_info->name(), |
120 "BrowserCloseTabWhenOtherTabHasListener") == 0) { | 120 "BrowserCloseTabWhenOtherTabHasListener") == 0) { |
121 command_line->AppendSwitch(switches::kDisablePopupBlocking); | 121 command_line->AppendSwitch(switches::kDisablePopupBlocking); |
122 } else if (strcmp(test_info->name(), "BrowserTerminateBeforeUnload") == 0) { | 122 } else if (strcmp(test_info->name(), "BrowserTerminateBeforeUnload") == 0) { |
123 #if defined(OS_POSIX) | 123 #if defined(OS_POSIX) |
124 DisableSIGTERMHandling(); | 124 DisableSIGTERMHandling(); |
125 #endif | 125 #endif |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 virtual void SetUpOnMainThread() OVERRIDE { | 129 virtual void SetUpOnMainThread() override { |
130 BrowserThread::PostTask( | 130 BrowserThread::PostTask( |
131 BrowserThread::IO, FROM_HERE, | 131 BrowserThread::IO, FROM_HERE, |
132 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 132 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
133 } | 133 } |
134 | 134 |
135 void CheckTitle(const char* expected_title) { | 135 void CheckTitle(const char* expected_title) { |
136 base::string16 expected = base::ASCIIToUTF16(expected_title); | 136 base::string16 expected = base::ASCIIToUTF16(expected_title); |
137 EXPECT_EQ(expected, | 137 EXPECT_EQ(expected, |
138 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); | 138 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
139 } | 139 } |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 content::WebContentsDestroyedWatcher destroyed_watcher( | 409 content::WebContentsDestroyedWatcher destroyed_watcher( |
410 browser()->tab_strip_model()->GetActiveWebContents()); | 410 browser()->tab_strip_model()->GetActiveWebContents()); |
411 chrome::CloseTab(browser()); | 411 chrome::CloseTab(browser()); |
412 destroyed_watcher.Wait(); | 412 destroyed_watcher.Wait(); |
413 | 413 |
414 CheckTitle("only_one_unload"); | 414 CheckTitle("only_one_unload"); |
415 } | 415 } |
416 | 416 |
417 class FastUnloadTest : public UnloadTest { | 417 class FastUnloadTest : public UnloadTest { |
418 public: | 418 public: |
419 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 419 virtual void SetUpCommandLine(CommandLine* command_line) override { |
420 UnloadTest::SetUpCommandLine(command_line); | 420 UnloadTest::SetUpCommandLine(command_line); |
421 command_line->AppendSwitch(switches::kEnableFastUnload); | 421 command_line->AppendSwitch(switches::kEnableFastUnload); |
422 } | 422 } |
423 | 423 |
424 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 424 virtual void SetUpInProcessBrowserTestFixture() override { |
425 ASSERT_TRUE(test_server()->Start()); | 425 ASSERT_TRUE(test_server()->Start()); |
426 } | 426 } |
427 | 427 |
428 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { | 428 virtual void TearDownInProcessBrowserTestFixture() override { |
429 test_server()->Stop(); | 429 test_server()->Stop(); |
430 } | 430 } |
431 | 431 |
432 GURL GetUrl(const std::string& name) { | 432 GURL GetUrl(const std::string& name) { |
433 return GURL(test_server()->GetURL( | 433 return GURL(test_server()->GetURL( |
434 "files/fast_tab_close/" + name + ".html")); | 434 "files/fast_tab_close/" + name + ".html")); |
435 } | 435 } |
436 | 436 |
437 void NavigateToPage(const char* name) { | 437 void NavigateToPage(const char* name) { |
438 ui_test_utils::NavigateToURL(browser(), GetUrl(name)); | 438 ui_test_utils::NavigateToURL(browser(), GetUrl(name)); |
(...skipping 22 matching lines...) Expand all Loading... |
461 run_loop_(run_loop) { | 461 run_loop_(run_loop) { |
462 model_->AddObserver(this); | 462 model_->AddObserver(this); |
463 } | 463 } |
464 | 464 |
465 virtual ~FastTabCloseTabStripModelObserver() { | 465 virtual ~FastTabCloseTabStripModelObserver() { |
466 model_->RemoveObserver(this); | 466 model_->RemoveObserver(this); |
467 } | 467 } |
468 | 468 |
469 // TabStripModelObserver: | 469 // TabStripModelObserver: |
470 virtual void TabDetachedAt(content::WebContents* contents, | 470 virtual void TabDetachedAt(content::WebContents* contents, |
471 int index) OVERRIDE { | 471 int index) override { |
472 run_loop_->Quit(); | 472 run_loop_->Quit(); |
473 } | 473 } |
474 | 474 |
475 private: | 475 private: |
476 TabStripModel* const model_; | 476 TabStripModel* const model_; |
477 base::RunLoop* const run_loop_; | 477 base::RunLoop* const run_loop_; |
478 }; | 478 }; |
479 | 479 |
480 | 480 |
481 // Test that fast-tab-close works when closing a tab with an unload handler | 481 // Test that fast-tab-close works when closing a tab with an unload handler |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 content::WindowedNotificationObserver window_observer( | 633 content::WindowedNotificationObserver window_observer( |
634 chrome::NOTIFICATION_BROWSER_CLOSED, | 634 chrome::NOTIFICATION_BROWSER_CLOSED, |
635 content::NotificationService::AllSources()); | 635 content::NotificationService::AllSources()); |
636 chrome::CloseWindow(browser()); | 636 chrome::CloseWindow(browser()); |
637 CrashTab(beforeunload_contents); | 637 CrashTab(beforeunload_contents); |
638 window_observer.Wait(); | 638 window_observer.Wait(); |
639 } | 639 } |
640 | 640 |
641 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs | 641 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs |
642 // and multiple windows. | 642 // and multiple windows. |
OLD | NEW |