| 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 e6e83576d6626b1eab23df2ea201c6032e936fe0..9116c9c2a2604d242fd96b0befda2f36523a45af 100644
|
| --- a/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
|
| +++ b/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
|
| @@ -180,6 +180,7 @@ class DevToolsProtocolTest : public ContentBrowserTest,
|
| int last_sent_id_;
|
| std::vector<int> result_ids_;
|
| std::vector<std::string> notifications_;
|
| + std::unique_ptr<base::DictionaryValue> requested_notification_params_;
|
|
|
| private:
|
| void DispatchProtocolMessage(DevToolsAgentHost* agent_host,
|
| @@ -203,6 +204,12 @@ class DevToolsProtocolTest : public ContentBrowserTest,
|
| EXPECT_TRUE(root->GetString("method", ¬ification));
|
| notifications_.push_back(notification);
|
| if (waiting_for_notification_ == notification) {
|
| + base::DictionaryValue* params;
|
| + if (root->GetDictionary("params", ¶ms)) {
|
| + requested_notification_params_ = params->CreateDeepCopy();
|
| + } else {
|
| + requested_notification_params_.reset();
|
| + }
|
| waiting_for_notification_ = std::string();
|
| base::MessageLoop::current()->QuitNow();
|
| }
|
| @@ -597,4 +604,74 @@ IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, BrowserNewPage) {
|
| EXPECT_EQ(2u, shell()->windows().size());
|
| }
|
|
|
| +IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, NavigationThrottle) {
|
| + NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
|
| + ASSERT_TRUE(embedded_test_server()->Start());
|
| + Attach();
|
| + SendCommand("Page.enable", nullptr);
|
| +
|
| + std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
|
| + params->SetBoolean("enabled", true);
|
| + SendCommand("Page.setNavigationThrottleEnabled", std::move(params), true);
|
| +
|
| + GURL test_url = embedded_test_server()->GetURL("/devtools/meta_tag.html");
|
| + shell()->LoadURL(test_url);
|
| +
|
| + // Wait for and allow navigation to /devtools/meta_tag.html
|
| + WaitForNotification("Page.navigationRequested");
|
| + ASSERT_TRUE(requested_notification_params_.get());
|
| + std::string url;
|
| + ASSERT_TRUE(requested_notification_params_->GetString("url", &url));
|
| + EXPECT_TRUE(base::EndsWith(url, "/devtools/meta_tag.html",
|
| + base::CompareCase::SENSITIVE));
|
| + int navigation_id;
|
| + ASSERT_TRUE(requested_notification_params_->GetInteger("navigationId",
|
| + &navigation_id));
|
| + bool renderer_initiated;
|
| + ASSERT_TRUE(requested_notification_params_->GetBoolean("rendererInitiated",
|
| + &renderer_initiated));
|
| + EXPECT_FALSE(renderer_initiated);
|
| + bool is_in_main_frame;
|
| + ASSERT_TRUE(requested_notification_params_->GetBoolean("isInMainFrame",
|
| + &is_in_main_frame));
|
| + EXPECT_TRUE(is_in_main_frame);
|
| + bool is_redirect;
|
| + ASSERT_TRUE(
|
| + requested_notification_params_->GetBoolean("isRedirect", &is_redirect));
|
| + EXPECT_FALSE(is_redirect);
|
| +
|
| + params.reset(new base::DictionaryValue());
|
| + params->SetString("response", "Proceed");
|
| + params->SetInteger("navigationId", navigation_id);
|
| + SendCommand("Page.processNavigation", std::move(params), true);
|
| +
|
| + // Wait for and cancel navigation to /devtools/navigation.html
|
| + WaitForNotification("Page.navigationRequested");
|
| +
|
| + ASSERT_TRUE(requested_notification_params_.get());
|
| + ASSERT_TRUE(requested_notification_params_->GetString("url", &url));
|
| + EXPECT_TRUE(base::EndsWith(url, "/devtools/navigation.html",
|
| + base::CompareCase::SENSITIVE));
|
| + ASSERT_TRUE(requested_notification_params_->GetInteger("navigationId",
|
| + &navigation_id));
|
| + ASSERT_TRUE(requested_notification_params_->GetBoolean("rendererInitiated",
|
| + &renderer_initiated));
|
| + EXPECT_TRUE(renderer_initiated);
|
| + ASSERT_TRUE(requested_notification_params_->GetBoolean("isInMainFrame",
|
| + &is_in_main_frame));
|
| + EXPECT_TRUE(is_in_main_frame);
|
| + ASSERT_TRUE(
|
| + requested_notification_params_->GetBoolean("isRedirect", &is_redirect));
|
| + EXPECT_FALSE(is_redirect);
|
| +
|
| + params.reset(new base::DictionaryValue());
|
| + params->SetString("response", "Cancel");
|
| + params->SetInteger("navigationId", navigation_id);
|
| + SendCommand("Page.processNavigation", std::move(params), true);
|
| +
|
| + // Check the cancellation occurred.
|
| + WaitForNotification("Page.frameClearedScheduledNavigation");
|
| + ASSERT_TRUE(requested_notification_params_.get());
|
| +}
|
| +
|
| } // namespace content
|
|
|