| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 |
| 6 #include "content/browser/frame_host/frame_tree.h" |
| 7 #include "content/browser/site_per_process_browsertest.h" |
| 8 #include "content/browser/web_contents/web_contents_impl.h" |
| 9 #include "content/public/browser/devtools_agent_host.h" |
| 10 #include "content/public/test/content_browser_test_utils.h" |
| 11 #include "content/public/test/test_utils.h" |
| 12 #include "content/shell/browser/shell.h" |
| 13 #include "content/test/content_browser_test_utils_internal.h" |
| 14 #include "net/dns/mock_host_resolver.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 class SitePerProcessDevToolsBrowserTest |
| 19 : public SitePerProcessBrowserTest { |
| 20 public: |
| 21 SitePerProcessDevToolsBrowserTest() {} |
| 22 }; |
| 23 |
| 24 class TestClient: public DevToolsAgentHostClient { |
| 25 public: |
| 26 TestClient() : closed_(false) {} |
| 27 ~TestClient() override {} |
| 28 |
| 29 bool closed() { return closed_; } |
| 30 |
| 31 void DispatchProtocolMessage( |
| 32 DevToolsAgentHost* agent_host, |
| 33 const std::string& message) override { |
| 34 } |
| 35 |
| 36 void AgentHostClosed( |
| 37 DevToolsAgentHost* agent_host, |
| 38 bool replaced_with_another_client) override { |
| 39 closed_ = true; |
| 40 } |
| 41 |
| 42 private: |
| 43 bool closed_; |
| 44 }; |
| 45 |
| 46 IN_PROC_BROWSER_TEST_F(SitePerProcessDevToolsBrowserTest, |
| 47 CrossSiteIframeAgentHost) { |
| 48 DevToolsAgentHost::List list; |
| 49 host_resolver()->AddRule("*", "127.0.0.1"); |
| 50 ASSERT_TRUE(test_server()->Start()); |
| 51 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
| 52 NavigateToURL(shell(), main_url); |
| 53 |
| 54 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 55 FrameTreeNode* root = |
| 56 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 57 GetFrameTree()->root(); |
| 58 |
| 59 list = DevToolsAgentHost::GetOrCreateAll(); |
| 60 EXPECT_EQ(1U, list.size()); |
| 61 EXPECT_EQ(DevToolsAgentHost::TYPE_WEB_CONTENTS, list[0]->GetType()); |
| 62 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); |
| 63 |
| 64 // Load same-site page into iframe. |
| 65 FrameTreeNode* child = root->child_at(0); |
| 66 GURL http_url(test_server()->GetURL("files/title1.html")); |
| 67 NavigateFrameToURL(child, http_url); |
| 68 |
| 69 list = DevToolsAgentHost::GetOrCreateAll(); |
| 70 EXPECT_EQ(1U, list.size()); |
| 71 EXPECT_EQ(DevToolsAgentHost::TYPE_WEB_CONTENTS, list[0]->GetType()); |
| 72 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); |
| 73 |
| 74 // Load cross-site page into iframe. |
| 75 GURL::Replacements replace_host; |
| 76 GURL cross_site_url(test_server()->GetURL("files/title2.html")); |
| 77 replace_host.SetHostStr("foo.com"); |
| 78 cross_site_url = cross_site_url.ReplaceComponents(replace_host); |
| 79 NavigateFrameToURL(root->child_at(0), cross_site_url); |
| 80 |
| 81 list = DevToolsAgentHost::GetOrCreateAll(); |
| 82 EXPECT_EQ(2U, list.size()); |
| 83 EXPECT_EQ(DevToolsAgentHost::TYPE_WEB_CONTENTS, list[0]->GetType()); |
| 84 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); |
| 85 EXPECT_EQ(DevToolsAgentHost::TYPE_FRAME, list[1]->GetType()); |
| 86 EXPECT_EQ(cross_site_url.spec(), list[1]->GetURL().spec()); |
| 87 |
| 88 // Attaching to child frame. |
| 89 scoped_refptr<DevToolsAgentHost> child_host = list[1]; |
| 90 TestClient client; |
| 91 child_host->AttachClient(&client); |
| 92 |
| 93 // Load back same-site page into iframe. |
| 94 NavigateFrameToURL(root->child_at(0), http_url); |
| 95 |
| 96 list = DevToolsAgentHost::GetOrCreateAll(); |
| 97 EXPECT_EQ(1U, list.size()); |
| 98 EXPECT_EQ(DevToolsAgentHost::TYPE_WEB_CONTENTS, list[0]->GetType()); |
| 99 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); |
| 100 // TODO(dgozman): we should get closed notification here. |
| 101 // See http://crbug.com/464993. |
| 102 EXPECT_FALSE(client.closed()); |
| 103 child_host->DetachClient(); |
| 104 child_host = nullptr; |
| 105 } |
| 106 |
| 107 } // namespace content |
| OLD | NEW |