| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 #endif | 144 #endif |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 | 147 |
| 148 void SetUpOnMainThread() override { | 148 void SetUpOnMainThread() override { |
| 149 BrowserThread::PostTask( | 149 BrowserThread::PostTask( |
| 150 BrowserThread::IO, FROM_HERE, | 150 BrowserThread::IO, FROM_HERE, |
| 151 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 151 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void CheckTitle(const char* expected_title) { | 154 void CheckTitle(const char* expected_title, bool wait = false) { |
| 155 auto* web_contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 155 base::string16 expected = base::ASCIIToUTF16(expected_title); | 156 base::string16 expected = base::ASCIIToUTF16(expected_title); |
| 156 EXPECT_EQ(expected, | 157 base::string16 actual; |
| 157 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); | 158 if (wait) |
| 159 actual = content::TitleWatcher(web_contents, expected).WaitAndGetTitle(); |
| 160 else |
| 161 actual = web_contents->GetTitle(); |
| 162 EXPECT_EQ(expected, actual); |
| 158 } | 163 } |
| 159 | 164 |
| 160 void NavigateToDataURL(const char* html_content, const char* expected_title) { | 165 void NavigateToDataURL(const char* html_content, const char* expected_title) { |
| 161 ui_test_utils::NavigateToURL( | 166 ui_test_utils::NavigateToURL( |
| 162 browser(), GURL(std::string("data:text/html,") + html_content)); | 167 browser(), GURL(std::string("data:text/html,") + html_content)); |
| 163 CheckTitle(expected_title); | 168 CheckTitle(expected_title); |
| 164 } | 169 } |
| 165 | 170 |
| 166 void NavigateToNolistenersFileTwice() { | 171 void NavigateToNolistenersFileTwice() { |
| 167 GURL url(net::URLRequestMockHTTPJob::GetMockUrl("title2.html")); | 172 GURL url(net::URLRequestMockHTTPJob::GetMockUrl("title2.html")); |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 // http://crbug.com/86769. | 610 // http://crbug.com/86769. |
| 606 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseTabWhenOtherTabHasListener) { | 611 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseTabWhenOtherTabHasListener) { |
| 607 NavigateToDataURL(CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER, "only_one_unload"); | 612 NavigateToDataURL(CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER, "only_one_unload"); |
| 608 | 613 |
| 609 // Simulate a click to force user_gesture to true; if we don't, the resulting | 614 // Simulate a click to force user_gesture to true; if we don't, the resulting |
| 610 // popup will be constrained, which isn't what we want to test. | 615 // popup will be constrained, which isn't what we want to test. |
| 611 | 616 |
| 612 content::WindowedNotificationObserver observer( | 617 content::WindowedNotificationObserver observer( |
| 613 chrome::NOTIFICATION_TAB_ADDED, | 618 chrome::NOTIFICATION_TAB_ADDED, |
| 614 content::NotificationService::AllSources()); | 619 content::NotificationService::AllSources()); |
| 615 content::WindowedNotificationObserver load_stop_observer( | |
| 616 content::NOTIFICATION_LOAD_STOP, | |
| 617 content::NotificationService::AllSources()); | |
| 618 content::SimulateMouseClick( | 620 content::SimulateMouseClick( |
| 619 browser()->tab_strip_model()->GetActiveWebContents(), 0, | 621 browser()->tab_strip_model()->GetActiveWebContents(), 0, |
| 620 blink::WebMouseEvent::Button::kLeft); | 622 blink::WebMouseEvent::Button::kLeft); |
| 621 observer.Wait(); | 623 observer.Wait(); |
| 622 load_stop_observer.Wait(); | 624 // Need to wait for the title, because the initial page (about:blank) can stop |
| 623 CheckTitle("popup"); | 625 // loading before the click handler calls document.write. |
| 626 CheckTitle("popup", true); |
| 624 | 627 |
| 625 content::WebContentsDestroyedWatcher destroyed_watcher( | 628 content::WebContentsDestroyedWatcher destroyed_watcher( |
| 626 browser()->tab_strip_model()->GetActiveWebContents()); | 629 browser()->tab_strip_model()->GetActiveWebContents()); |
| 627 chrome::CloseTab(browser()); | 630 chrome::CloseTab(browser()); |
| 628 destroyed_watcher.Wait(); | 631 destroyed_watcher.Wait(); |
| 629 | 632 |
| 630 CheckTitle("only_one_unload"); | 633 CheckTitle("only_one_unload"); |
| 631 } | 634 } |
| 632 | 635 |
| 633 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListForceCloseNoUnloadListeners) { | 636 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListForceCloseNoUnloadListeners) { |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), | 963 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), |
| 961 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), | 964 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), |
| 962 true); | 965 true); |
| 963 window_observer.Wait(); | 966 window_observer.Wait(); |
| 964 EXPECT_EQ(1, unload_results.get_successes()); | 967 EXPECT_EQ(1, unload_results.get_successes()); |
| 965 EXPECT_EQ(0, unload_results.get_aborts()); | 968 EXPECT_EQ(0, unload_results.get_aborts()); |
| 966 } | 969 } |
| 967 | 970 |
| 968 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs | 971 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs |
| 969 // and multiple windows. | 972 // and multiple windows. |
| OLD | NEW |