diff options
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 <script> tags have executed, including jstemplate. - // TODO(joaodasilva): it would be nice to avoid the busy loop, though in - // practice it spins at most once or twice. - std::string ready_state; - do { - scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( - rvh->GetMainFrame(), "document.readyState"); - if (!value.get() || !value->GetAsString(&ready_state)) - return false; - } while (ready_state != "complete"); - return true; + return content::WaitForRenderFrameReady(interstitial->GetMainFrame()); } Visibility GetVisibility(const std::string& node_id) { diff --git a/content/public/test/browser_test_utils.cc b/content/public/test/browser_test_utils.cc index 89dd343..20d6f6c9 100644 --- a/content/public/test/browser_test_utils.cc +++ b/content/public/test/browser_test_utils.cc @@ -723,6 +723,28 @@ void RunTaskAndWaitForInterstitialDetach(content::WebContents* web_contents, loop_runner->Run(); } +bool WaitForRenderFrameReady(RenderFrameHost* rfh) { + if (!rfh) + return false; + std::string result; + EXPECT_TRUE( + content::ExecuteScriptAndExtractString( + rfh, + "(function() {" + " var done = false;" + " function checkState() {" + " if (!done && document.readyState == 'complete') {" + " done = true;" + " window.domAutomationController.send('pageLoadComplete');" + " }" + " }" + " checkState();" + " document.addEventListener('readystatechange', checkState);" + "})();", + &result)); + return result == "pageLoadComplete"; +} + TitleWatcher::TitleWatcher(WebContents* web_contents, const base::string16& expected_title) : WebContentsObserver(web_contents), diff --git a/content/public/test/browser_test_utils.h b/content/public/test/browser_test_utils.h index 303ac74..a55ad06 100644 --- a/content/public/test/browser_test_utils.h +++ b/content/public/test/browser_test_utils.h @@ -243,6 +243,12 @@ void WaitForInterstitialDetach(content::WebContents* web_contents); void RunTaskAndWaitForInterstitialDetach(content::WebContents* web_contents, const base::Closure& task); +// Waits until all resources have loaded in the given RenderFrameHost. +// When the load completes, this function sends a "pageLoadComplete" message +// via domAutomationController. The caller should make sure this extra +// message is handled properly. +bool WaitForRenderFrameReady(RenderFrameHost* rfh) WARN_UNUSED_RESULT; + // Watches title changes on a WebContents, blocking until an expected title is // set. class TitleWatcher : public WebContentsObserver { |