From 8543a23f0bc2072149902d80bf36ae143a8dee48 Mon Sep 17 00:00:00 2001 From: meacer Date: Fri, 23 Jan 2015 11:58:45 -0800 Subject: Add WaitForInterstitialReady to browser_test_utils. CaptivePortal and SafeBrowsingBlockingPage tests wait for the interstitial to get ready in different ways. This CL unifies them. BUG=448486 Review URL: https://codereview.chromium.org/829263004 Cr-Commit-Position: refs/heads/master@{#312908} --- .../captive_portal/captive_portal_browsertest.cc | 27 +--------------------- .../safe_browsing/safe_browsing_blocking_page.cc | 7 ++++++ .../safe_browsing_blocking_page_test.cc | 17 ++++---------- content/public/test/browser_test_utils.cc | 22 ++++++++++++++++++ content/public/test/browser_test_utils.h | 6 +++++ 5 files changed, 40 insertions(+), 39 deletions(-) diff --git a/chrome/browser/captive_portal/captive_portal_browsertest.cc b/chrome/browser/captive_portal/captive_portal_browsertest.cc index 1560e3a..7fd8389 100644 --- a/chrome/browser/captive_portal/captive_portal_browsertest.cc +++ b/chrome/browser/captive_portal/captive_portal_browsertest.cc @@ -120,30 +120,6 @@ const char* const kMockHttpsQuickTimeoutUrl = // captive portal. const char* const kInternetConnectedTitle = "Title Of Awesomeness"; -// Wait until all resources have loaded in an interstitial page. -bool WaitForInterstitialReady(content::InterstitialPage* interstitial) { - content::RenderFrameHost* rfh = interstitial->GetMainFrame(); - if (!rfh) - return false; - bool load_complete = false; - EXPECT_TRUE( - content::ExecuteScriptAndExtractBool( - rfh, - "(function() {" - " var done = false;" - " function checkState() {" - " if (!done && document.readyState == 'complete') {" - " done = true;" - " window.domAutomationController.send(true);" - " }" - " }" - " checkState();" - " document.addEventListener('readystatechange', checkState);" - "})();", - &load_complete)); - return load_complete; -} - // A URL request job that hangs until FailJobs() is called. Started jobs // are stored in a static class variable containing a linked list so that // FailJobs() can locate them. @@ -1982,10 +1958,9 @@ IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, tab_strip_model->ActivateTabAt(cert_error_tab_index, false); // Wait for the interstitial to load all the JavaScript code. Otherwise, // trying to click on a button will fail. - EXPECT_TRUE(WaitForInterstitialReady( - broken_tab_contents->GetInterstitialPage())); content::RenderFrameHost* rfh = broken_tab_contents->GetInterstitialPage()->GetMainFrame(); + EXPECT_TRUE(WaitForRenderFrameReady(rfh)); const char kClickConnectButtonJS[] = "document.getElementById('primary-button').click();"; EXPECT_TRUE( diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc index 5b053b1..0515ecd 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc @@ -220,6 +220,13 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { if (command.length() > 1 && command[0] == '"') { command = command.substr(1, command.length() - 2); } + + if (command == "pageLoadComplete") { + // content::WaitForRenderFrameReady sends this message when the page + // load completes. Ignore it. + return; + } + if (command == kDoReportCommand) { SetReportingPreference(true); return; diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc index 9bb0809..bd22f4b 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc @@ -512,20 +512,11 @@ class SafeBrowsingBlockingPageBrowserTest } bool WaitForReady() { - content::RenderViewHost* rvh = GetRenderViewHost(); - if (!rvh) + InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage( + browser()->tab_strip_model()->GetActiveWebContents()); + if (!interstitial) return false; - // Wait until all