| 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..26cbd845c2bb4f612d8eb2fad59e4395f33b83fe 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,59 @@ 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.shouldAllowNavigation");
|
| + 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));
|
| +
|
| + params.reset(new base::DictionaryValue());
|
| + params->SetString("response", "Proceed");
|
| + params->SetInteger("navigationId", navigation_id);
|
| + SendCommand("Page.navigationThrottleResponse", std::move(params), true);
|
| +
|
| + // Wait for and cancel navigation to /devtools/navigation.html
|
| + WaitForNotification("Page.shouldAllowNavigation");
|
| +
|
| + 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));
|
| +
|
| + params.reset(new base::DictionaryValue());
|
| + params->SetString("response", "Cancel");
|
| + params->SetInteger("navigationId", navigation_id);
|
| + std::string navigating_frame_id;
|
| + ASSERT_TRUE(requested_notification_params_->GetString("frameId",
|
| + &navigating_frame_id));
|
| + SendCommand("Page.navigationThrottleResponse", std::move(params), true);
|
| +
|
| + // Check the cancellation occurred.
|
| + WaitForNotification("Page.frameClearedScheduledNavigation");
|
| + ASSERT_TRUE(requested_notification_params_.get());
|
| + std::string frame_id;
|
| + ASSERT_TRUE(requested_notification_params_->GetString("frameId", &frame_id));
|
| + EXPECT_EQ(frame_id, navigating_frame_id);
|
| +}
|
| +
|
| } // namespace content
|
|
|