Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/base64.h" | 8 #include "base/base64.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 void WaitForNotification(const std::string& notification) { | 173 void WaitForNotification(const std::string& notification) { |
| 174 waiting_for_notification_ = notification; | 174 waiting_for_notification_ = notification; |
| 175 RunMessageLoop(); | 175 RunMessageLoop(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 std::unique_ptr<base::DictionaryValue> result_; | 178 std::unique_ptr<base::DictionaryValue> result_; |
| 179 scoped_refptr<DevToolsAgentHost> agent_host_; | 179 scoped_refptr<DevToolsAgentHost> agent_host_; |
| 180 int last_sent_id_; | 180 int last_sent_id_; |
| 181 std::vector<int> result_ids_; | 181 std::vector<int> result_ids_; |
| 182 std::vector<std::string> notifications_; | 182 std::vector<std::string> notifications_; |
| 183 std::unique_ptr<base::DictionaryValue> requested_notification_params_; | |
| 183 | 184 |
| 184 private: | 185 private: |
| 185 void DispatchProtocolMessage(DevToolsAgentHost* agent_host, | 186 void DispatchProtocolMessage(DevToolsAgentHost* agent_host, |
| 186 const std::string& message) override { | 187 const std::string& message) override { |
| 187 std::unique_ptr<base::DictionaryValue> root( | 188 std::unique_ptr<base::DictionaryValue> root( |
| 188 static_cast<base::DictionaryValue*>( | 189 static_cast<base::DictionaryValue*>( |
| 189 base::JSONReader::Read(message).release())); | 190 base::JSONReader::Read(message).release())); |
| 190 int id; | 191 int id; |
| 191 if (root->GetInteger("id", &id)) { | 192 if (root->GetInteger("id", &id)) { |
| 192 result_ids_.push_back(id); | 193 result_ids_.push_back(id); |
| 193 base::DictionaryValue* result; | 194 base::DictionaryValue* result; |
| 194 ASSERT_TRUE(root->GetDictionary("result", &result)); | 195 ASSERT_TRUE(root->GetDictionary("result", &result)); |
| 195 result_.reset(result->DeepCopy()); | 196 result_.reset(result->DeepCopy()); |
| 196 in_dispatch_ = false; | 197 in_dispatch_ = false; |
| 197 if (id && id == waiting_for_command_result_id_) { | 198 if (id && id == waiting_for_command_result_id_) { |
| 198 waiting_for_command_result_id_ = 0; | 199 waiting_for_command_result_id_ = 0; |
| 199 base::MessageLoop::current()->QuitNow(); | 200 base::MessageLoop::current()->QuitNow(); |
| 200 } | 201 } |
| 201 } else { | 202 } else { |
| 202 std::string notification; | 203 std::string notification; |
| 203 EXPECT_TRUE(root->GetString("method", ¬ification)); | 204 EXPECT_TRUE(root->GetString("method", ¬ification)); |
| 204 notifications_.push_back(notification); | 205 notifications_.push_back(notification); |
| 205 if (waiting_for_notification_ == notification) { | 206 if (waiting_for_notification_ == notification) { |
| 207 base::DictionaryValue* params; | |
| 208 if (root->GetDictionary("params", ¶ms)) { | |
| 209 requested_notification_params_ = params->CreateDeepCopy(); | |
| 210 } else { | |
| 211 requested_notification_params_.reset(); | |
| 212 } | |
| 206 waiting_for_notification_ = std::string(); | 213 waiting_for_notification_ = std::string(); |
| 207 base::MessageLoop::current()->QuitNow(); | 214 base::MessageLoop::current()->QuitNow(); |
| 208 } | 215 } |
| 209 } | 216 } |
| 210 } | 217 } |
| 211 | 218 |
| 212 void AgentHostClosed(DevToolsAgentHost* agent_host, bool replaced) override { | 219 void AgentHostClosed(DevToolsAgentHost* agent_host, bool replaced) override { |
| 213 EXPECT_TRUE(false); | 220 EXPECT_TRUE(false); |
| 214 } | 221 } |
| 215 | 222 |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, BrowserNewPage) { | 597 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, BrowserNewPage) { |
| 591 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); | 598 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); |
| 592 Attach(); | 599 Attach(); |
| 593 EXPECT_EQ(1u, shell()->windows().size()); | 600 EXPECT_EQ(1u, shell()->windows().size()); |
| 594 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 601 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
| 595 params->SetString("initialUrl", "about:blank"); | 602 params->SetString("initialUrl", "about:blank"); |
| 596 SendCommand("Browser.newPage", std::move(params), true); | 603 SendCommand("Browser.newPage", std::move(params), true); |
| 597 EXPECT_EQ(2u, shell()->windows().size()); | 604 EXPECT_EQ(2u, shell()->windows().size()); |
| 598 } | 605 } |
| 599 | 606 |
| 607 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, NavigationThrottle) { | |
| 608 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); | |
| 609 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 610 Attach(); | |
| 611 SendCommand("Page.enable", nullptr); | |
| 612 | |
| 613 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | |
| 614 params->SetBoolean("enabled", true); | |
| 615 SendCommand("Page.setControlNavigations", std::move(params), true); | |
| 616 | |
| 617 GURL test_url = embedded_test_server()->GetURL("/devtools/meta_tag.html"); | |
| 618 shell()->LoadURL(test_url); | |
| 619 | |
| 620 // Wait for and allow navigation to /devtools/meta_tag.html | |
| 621 WaitForNotification("Page.navigationRequested"); | |
| 622 ASSERT_TRUE(requested_notification_params_.get()); | |
| 623 std::string url; | |
| 624 ASSERT_TRUE(requested_notification_params_->GetString("url", &url)); | |
| 625 EXPECT_TRUE(base::EndsWith(url, "/devtools/meta_tag.html", | |
| 626 base::CompareCase::SENSITIVE)); | |
| 627 int navigation_id; | |
| 628 ASSERT_TRUE(requested_notification_params_->GetInteger("navigationId", | |
| 629 &navigation_id)); | |
| 630 bool renderer_initiated; | |
| 631 ASSERT_TRUE(requested_notification_params_->GetBoolean("rendererInitiated", | |
| 632 &renderer_initiated)); | |
| 633 EXPECT_FALSE(renderer_initiated); | |
| 634 bool is_in_main_frame; | |
| 635 ASSERT_TRUE(requested_notification_params_->GetBoolean("isInMainFrame", | |
| 636 &is_in_main_frame)); | |
| 637 EXPECT_TRUE(is_in_main_frame); | |
| 638 bool is_redirect; | |
| 639 ASSERT_TRUE( | |
| 640 requested_notification_params_->GetBoolean("isRedirect", &is_redirect)); | |
| 641 EXPECT_FALSE(is_redirect); | |
| 642 | |
| 643 params.reset(new base::DictionaryValue()); | |
| 644 params->SetString("response", "Proceed"); | |
| 645 params->SetInteger("navigationId", navigation_id); | |
| 646 SendCommand("Page.processNavigation", std::move(params), true); | |
| 647 | |
| 648 // Wait for and cancel navigation to /devtools/navigation.html | |
| 649 WaitForNotification("Page.navigationRequested"); | |
| 650 | |
| 651 ASSERT_TRUE(requested_notification_params_.get()); | |
| 652 ASSERT_TRUE(requested_notification_params_->GetString("url", &url)); | |
| 653 EXPECT_TRUE(base::EndsWith(url, "/devtools/navigation.html", | |
| 654 base::CompareCase::SENSITIVE)); | |
| 655 ASSERT_TRUE(requested_notification_params_->GetInteger("navigationId", | |
| 656 &navigation_id)); | |
| 657 ASSERT_TRUE(requested_notification_params_->GetBoolean("rendererInitiated", | |
| 658 &renderer_initiated)); | |
| 659 EXPECT_TRUE(renderer_initiated); | |
| 660 ASSERT_TRUE(requested_notification_params_->GetBoolean("isInMainFrame", | |
| 661 &is_in_main_frame)); | |
| 662 EXPECT_TRUE(is_in_main_frame); | |
| 663 ASSERT_TRUE( | |
| 664 requested_notification_params_->GetBoolean("isRedirect", &is_redirect)); | |
| 665 EXPECT_FALSE(is_redirect); | |
| 666 | |
| 667 params.reset(new base::DictionaryValue()); | |
| 668 params->SetString("response", "Cancel"); | |
| 669 params->SetInteger("navigationId", navigation_id); | |
| 670 SendCommand("Page.processNavigation", std::move(params), true); | |
| 671 | |
| 672 // Check the cancellation occurred. | |
| 673 WaitForNotification("Page.frameClearedScheduledNavigation"); | |
| 674 ASSERT_TRUE(requested_notification_params_.get()); | |
| 675 } | |
|
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
| |
| 676 | |
| 600 } // namespace content | 677 } // namespace content |
| OLD | NEW |