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

Unified Diff: content/browser/devtools/protocol/devtools_protocol_browsertest.cc

Issue 2901833002: Create NavigationHandle after beforeunload with PlzNavigate. (Closed)
Patch Set: Rewrote BeforeUnload test Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
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) {

Powered by Google App Engine
This is Rietveld 408576698