| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 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 "base/run_loop.h" | 5 #include "base/run_loop.h" |
| 6 #include "build/build_config.h" | 6 #include "build/build_config.h" |
| 7 #include "content/browser/frame_host/frame_tree.h" | 7 #include "content/browser/frame_host/frame_tree.h" |
| 8 #include "content/browser/site_per_process_browsertest.h" | 8 #include "content/browser/site_per_process_browsertest.h" |
| 9 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
| 10 #include "content/public/browser/devtools_agent_host.h" | 10 #include "content/public/browser/devtools_agent_host.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 67 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
| 68 NavigateToURL(shell(), main_url); | 68 NavigateToURL(shell(), main_url); |
| 69 | 69 |
| 70 // It is safe to obtain the root frame tree node here, as it doesn't change. | 70 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 71 FrameTreeNode* root = | 71 FrameTreeNode* root = |
| 72 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 72 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 73 GetFrameTree()->root(); | 73 GetFrameTree()->root(); |
| 74 | 74 |
| 75 list = DevToolsAgentHost::GetOrCreateAll(); | 75 list = DevToolsAgentHost::GetOrCreateAll(); |
| 76 EXPECT_EQ(1U, list.size()); | 76 EXPECT_EQ(1U, list.size()); |
| 77 EXPECT_EQ(DevToolsAgentHost::kTypePage, list[0]->GetType()); | 77 EXPECT_EQ(DevToolsAgentHost::TYPE_WEB_CONTENTS, list[0]->GetType()); |
| 78 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); | 78 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); |
| 79 | 79 |
| 80 // Load same-site page into iframe. | 80 // Load same-site page into iframe. |
| 81 FrameTreeNode* child = root->child_at(0); | 81 FrameTreeNode* child = root->child_at(0); |
| 82 GURL http_url(embedded_test_server()->GetURL("/title1.html")); | 82 GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
| 83 NavigateFrameToURL(child, http_url); | 83 NavigateFrameToURL(child, http_url); |
| 84 | 84 |
| 85 list = DevToolsAgentHost::GetOrCreateAll(); | 85 list = DevToolsAgentHost::GetOrCreateAll(); |
| 86 EXPECT_EQ(1U, list.size()); | 86 EXPECT_EQ(1U, list.size()); |
| 87 EXPECT_EQ(DevToolsAgentHost::kTypePage, list[0]->GetType()); | 87 EXPECT_EQ(DevToolsAgentHost::TYPE_WEB_CONTENTS, list[0]->GetType()); |
| 88 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); | 88 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); |
| 89 | 89 |
| 90 // Load cross-site page into iframe. | 90 // Load cross-site page into iframe. |
| 91 GURL::Replacements replace_host; | 91 GURL::Replacements replace_host; |
| 92 GURL cross_site_url(embedded_test_server()->GetURL("/title2.html")); | 92 GURL cross_site_url(embedded_test_server()->GetURL("/title2.html")); |
| 93 replace_host.SetHostStr("foo.com"); | 93 replace_host.SetHostStr("foo.com"); |
| 94 cross_site_url = cross_site_url.ReplaceComponents(replace_host); | 94 cross_site_url = cross_site_url.ReplaceComponents(replace_host); |
| 95 NavigateFrameToURL(root->child_at(0), cross_site_url); | 95 NavigateFrameToURL(root->child_at(0), cross_site_url); |
| 96 | 96 |
| 97 list = DevToolsAgentHost::GetOrCreateAll(); | 97 list = DevToolsAgentHost::GetOrCreateAll(); |
| 98 EXPECT_EQ(2U, list.size()); | 98 EXPECT_EQ(2U, list.size()); |
| 99 EXPECT_EQ(DevToolsAgentHost::kTypePage, list[0]->GetType()); | 99 EXPECT_EQ(DevToolsAgentHost::TYPE_WEB_CONTENTS, list[0]->GetType()); |
| 100 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); | 100 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); |
| 101 EXPECT_EQ(DevToolsAgentHost::kTypePage, list[1]->GetType()); | 101 EXPECT_EQ(DevToolsAgentHost::TYPE_FRAME, list[1]->GetType()); |
| 102 EXPECT_EQ(cross_site_url.spec(), list[1]->GetURL().spec()); | 102 EXPECT_EQ(cross_site_url.spec(), list[1]->GetURL().spec()); |
| 103 | 103 |
| 104 // Attaching to both agent hosts. | 104 // Attaching to both agent hosts. |
| 105 scoped_refptr<DevToolsAgentHost> child_host = list[1]; | 105 scoped_refptr<DevToolsAgentHost> child_host = list[1]; |
| 106 TestClient child_client; | 106 TestClient child_client; |
| 107 child_host->AttachClient(&child_client); | 107 child_host->AttachClient(&child_client); |
| 108 scoped_refptr<DevToolsAgentHost> parent_host = list[0]; | 108 scoped_refptr<DevToolsAgentHost> parent_host = list[0]; |
| 109 TestClient parent_client; | 109 TestClient parent_client; |
| 110 parent_host->AttachClient(&parent_client); | 110 parent_host->AttachClient(&parent_client); |
| 111 | 111 |
| 112 // Send message to parent and child frames and get result back. | 112 // Send message to parent and child frames and get result back. |
| 113 char message[] = "{\"id\": 0, \"method\": \"incorrect.method\"}"; | 113 char message[] = "{\"id\": 0, \"method\": \"incorrect.method\"}"; |
| 114 child_host->DispatchProtocolMessage(&child_client, message); | 114 child_host->DispatchProtocolMessage(&child_client, message); |
| 115 child_client.WaitForReply(); | 115 child_client.WaitForReply(); |
| 116 parent_host->DispatchProtocolMessage(&parent_client, message); | 116 parent_host->DispatchProtocolMessage(&parent_client, message); |
| 117 parent_client.WaitForReply(); | 117 parent_client.WaitForReply(); |
| 118 | 118 |
| 119 // Load back same-site page into iframe. | 119 // Load back same-site page into iframe. |
| 120 NavigateFrameToURL(root->child_at(0), http_url); | 120 NavigateFrameToURL(root->child_at(0), http_url); |
| 121 | 121 |
| 122 list = DevToolsAgentHost::GetOrCreateAll(); | 122 list = DevToolsAgentHost::GetOrCreateAll(); |
| 123 EXPECT_EQ(1U, list.size()); | 123 EXPECT_EQ(1U, list.size()); |
| 124 EXPECT_EQ(DevToolsAgentHost::kTypePage, list[0]->GetType()); | 124 EXPECT_EQ(DevToolsAgentHost::TYPE_WEB_CONTENTS, list[0]->GetType()); |
| 125 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); | 125 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); |
| 126 EXPECT_TRUE(child_client.closed()); | 126 EXPECT_TRUE(child_client.closed()); |
| 127 child_host->DetachClient(&child_client); | 127 child_host->DetachClient(&child_client); |
| 128 child_host = nullptr; | 128 child_host = nullptr; |
| 129 EXPECT_FALSE(parent_client.closed()); | 129 EXPECT_FALSE(parent_client.closed()); |
| 130 parent_host->DetachClient(&parent_client); | 130 parent_host->DetachClient(&parent_client); |
| 131 parent_host = nullptr; | 131 parent_host = nullptr; |
| 132 } | 132 } |
| 133 | 133 |
| 134 IN_PROC_BROWSER_TEST_F(SitePerProcessDevToolsBrowserTest, AgentHostForFrames) { | 134 IN_PROC_BROWSER_TEST_F(SitePerProcessDevToolsBrowserTest, AgentHostForFrames) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 DevToolsAgentHost::GetOrCreateFor(root->current_frame_host()); | 195 DevToolsAgentHost::GetOrCreateFor(root->current_frame_host()); |
| 196 EXPECT_NE(main_frame_agent.get(), child_frame_agent.get()); | 196 EXPECT_NE(main_frame_agent.get(), child_frame_agent.get()); |
| 197 | 197 |
| 198 // Agent for web contents should be the the main frame's one. | 198 // Agent for web contents should be the the main frame's one. |
| 199 scoped_refptr<DevToolsAgentHost> page_agent = | 199 scoped_refptr<DevToolsAgentHost> page_agent = |
| 200 DevToolsAgentHost::GetOrCreateFor(shell()->web_contents()); | 200 DevToolsAgentHost::GetOrCreateFor(shell()->web_contents()); |
| 201 EXPECT_EQ(page_agent.get(), main_frame_agent.get()); | 201 EXPECT_EQ(page_agent.get(), main_frame_agent.get()); |
| 202 } | 202 } |
| 203 | 203 |
| 204 } // namespace content | 204 } // namespace content |
| OLD | NEW |