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 e6e83576d6626b1eab23df2ea201c6032e936fe0..510779494f9d10bcd29e152b1eb3242d3d8f6ef3 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.setControlNavigations", 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()); |
| +} |
|
nasko
2016/07/13 22:37:34
Let's add a test that ensures navigating iframes a
alex clarke (OOO till 29th)
2016/07/14 16:06:04
It turns out this test is actually very awkward to
dgozman
2016/07/14 16:40:32
It's possible to attach to all oopifs separately,
nasko
2016/07/14 16:47:19
Does your CL care about the renderer process at al
alex clarke (OOO till 29th)
2016/07/14 17:26:17
Yes it does :( If IsolateAllSitesForTesting is ena
nasko
2016/07/14 17:55:51
Ok, let's put a TODO to enable OOPIFs later on, on
alex clarke (OOO till 29th)
2016/07/15 13:21:21
I figured out how to get this to work with Isolate
|
| + |
| } // namespace content |