Chromium Code Reviews| Index: content/browser/devtools/protocol/devtools_protocol_browsertest.cc |
| diff --git a/content/browser/devtools/protocol/devtools_protocol_browsertest.cc b/content/browser/devtools/protocol/devtools_protocol_browsertest.cc |
| index 67af007f80cbe0d8faebb0217eadce59cea62586..5411510c5e0383118f8e70efb48eed4109d7d858 100644 |
| --- a/content/browser/devtools/protocol/devtools_protocol_browsertest.cc |
| +++ b/content/browser/devtools/protocol/devtools_protocol_browsertest.cc |
| @@ -1204,6 +1204,36 @@ class NavigationFinishedObserver : public content::WebContentsObserver { |
| int num_finished_; |
| int num_to_wait_for_; |
| }; |
| + |
| +class LoadFinishedObserver : public content::WebContentsObserver { |
| + public: |
| + explicit LoadFinishedObserver(WebContents* web_contents) |
| + : WebContentsObserver(web_contents), |
| + num_finished_(0), |
| + num_to_wait_for_(0) {} |
| + |
| + ~LoadFinishedObserver() override {} |
| + |
| + void DidStopLoading() override { |
| + num_finished_++; |
| + if (num_finished_ >= num_to_wait_for_ && num_to_wait_for_ != 0) { |
| + base::MessageLoop::current()->QuitNow(); |
| + } |
| + } |
| + |
| + void WaitForLoadsToFinish(int num_to_wait_for) { |
|
nasko
2017/05/24 14:20:03
nit: Arguably, there are no other callers other th
clamy
2017/05/24 18:34:38
Done.
|
| + if (num_finished_ < num_to_wait_for) { |
| + num_to_wait_for_ = num_to_wait_for; |
| + RunMessageLoop(); |
| + } |
| + num_to_wait_for_ = 0; |
| + } |
| + |
| + private: |
| + int num_finished_; |
| + int num_to_wait_for_; |
| +}; |
| + |
| } // namespace |
| IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, PageStopLoading) { |
| @@ -1219,8 +1249,7 @@ IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, PageStopLoading) { |
| params->SetBoolean("enabled", true); |
| SendCommand("Page.setControlNavigations", std::move(params), true); |
| - NavigationFinishedObserver navigation_finished_observer( |
| - shell()->web_contents()); |
| + LoadFinishedObserver load_finished_observer(shell()->web_contents()); |
| // The page will try to navigate twice, however since |
| // Page.setControlNavigations is true, it'll wait for confirmation before |
| @@ -1233,7 +1262,7 @@ IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, PageStopLoading) { |
| SendCommand("Page.stopLoading", nullptr); |
| // Wait for the initial navigation to finish. |
| - navigation_finished_observer.WaitForNavigationsToFinish(1); |
| + load_finished_observer.WaitForLoadsToFinish(1); |
| } |
| IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, ControlNavigationsMainFrame) { |