Index: chrome/browser/unload_browsertest.cc |
diff --git a/chrome/browser/unload_browsertest.cc b/chrome/browser/unload_browsertest.cc |
index ae66d8c3002daa0b7a8d0c0df32da291f1b1a834..9948a187481ff6ec308bd7f3c5808665780ba31a 100644 |
--- a/chrome/browser/unload_browsertest.cc |
+++ b/chrome/browser/unload_browsertest.cc |
@@ -151,10 +151,15 @@ class UnloadTest : public InProcessBrowserTest { |
base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
} |
- void CheckTitle(const char* expected_title) { |
+ void CheckTitle(const char* expected_title, bool wait = false) { |
+ auto* web_contents = browser()->tab_strip_model()->GetActiveWebContents(); |
base::string16 expected = base::ASCIIToUTF16(expected_title); |
- EXPECT_EQ(expected, |
- browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
+ base::string16 actual; |
+ if (wait) |
+ actual = content::TitleWatcher(web_contents, expected).WaitAndGetTitle(); |
+ else |
+ actual = web_contents->GetTitle(); |
+ EXPECT_EQ(expected, actual); |
} |
void NavigateToDataURL(const char* html_content, const char* expected_title) { |
@@ -612,15 +617,13 @@ IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseTabWhenOtherTabHasListener) { |
content::WindowedNotificationObserver observer( |
chrome::NOTIFICATION_TAB_ADDED, |
content::NotificationService::AllSources()); |
- content::WindowedNotificationObserver load_stop_observer( |
- content::NOTIFICATION_LOAD_STOP, |
- content::NotificationService::AllSources()); |
content::SimulateMouseClick( |
browser()->tab_strip_model()->GetActiveWebContents(), 0, |
blink::WebMouseEvent::Button::kLeft); |
observer.Wait(); |
- load_stop_observer.Wait(); |
- CheckTitle("popup"); |
+ // Need to wait for the title, because the initial page (about:blank) can stop |
+ // loading before the click handler calls document.write. |
+ CheckTitle("popup", true); |
content::WebContentsDestroyedWatcher destroyed_watcher( |
browser()->tab_strip_model()->GetActiveWebContents()); |