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

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

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

Powered by Google App Engine
This is Rietveld 408576698