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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::kTypePage, 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::kTypePage, 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 EXPECT_EQ(std::string(), list[0]->GetParentId()); |
| 104 EXPECT_EQ(list[0]->GetId(), list[1]->GetParentId()); |
| 105 EXPECT_NE(list[1]->GetId(), list[0]->GetId()); |
103 | 106 |
104 // Attaching to both agent hosts. | 107 // Attaching to both agent hosts. |
105 scoped_refptr<DevToolsAgentHost> child_host = list[1]; | 108 scoped_refptr<DevToolsAgentHost> child_host = list[1]; |
106 TestClient child_client; | 109 TestClient child_client; |
107 child_host->AttachClient(&child_client); | 110 child_host->AttachClient(&child_client); |
108 scoped_refptr<DevToolsAgentHost> parent_host = list[0]; | 111 scoped_refptr<DevToolsAgentHost> parent_host = list[0]; |
109 TestClient parent_client; | 112 TestClient parent_client; |
110 parent_host->AttachClient(&parent_client); | 113 parent_host->AttachClient(&parent_client); |
111 | 114 |
112 // Send message to parent and child frames and get result back. | 115 // Send message to parent and child frames and get result back. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // Load cross-site page into iframe. | 163 // Load cross-site page into iframe. |
161 GURL::Replacements replace_host; | 164 GURL::Replacements replace_host; |
162 GURL cross_site_url(embedded_test_server()->GetURL("/title2.html")); | 165 GURL cross_site_url(embedded_test_server()->GetURL("/title2.html")); |
163 replace_host.SetHostStr("foo.com"); | 166 replace_host.SetHostStr("foo.com"); |
164 cross_site_url = cross_site_url.ReplaceComponents(replace_host); | 167 cross_site_url = cross_site_url.ReplaceComponents(replace_host); |
165 NavigateFrameToURL(root->child_at(0), cross_site_url); | 168 NavigateFrameToURL(root->child_at(0), cross_site_url); |
166 | 169 |
167 child_frame_agent = | 170 child_frame_agent = |
168 DevToolsAgentHost::GetOrCreateFor(child->current_frame_host()); | 171 DevToolsAgentHost::GetOrCreateFor(child->current_frame_host()); |
169 EXPECT_NE(page_agent.get(), child_frame_agent.get()); | 172 EXPECT_NE(page_agent.get(), child_frame_agent.get()); |
| 173 EXPECT_EQ(child_frame_agent->GetParentId(), page_agent->GetId()); |
| 174 EXPECT_NE(child_frame_agent->GetId(), page_agent->GetId()); |
170 } | 175 } |
171 | 176 |
172 IN_PROC_BROWSER_TEST_F(SitePerProcessDevToolsBrowserTest, | 177 IN_PROC_BROWSER_TEST_F(SitePerProcessDevToolsBrowserTest, |
173 AgentHostForPageEqualsOneForMainFrame) { | 178 AgentHostForPageEqualsOneForMainFrame) { |
174 host_resolver()->AddRule("*", "127.0.0.1"); | 179 host_resolver()->AddRule("*", "127.0.0.1"); |
175 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 180 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
176 NavigateToURL(shell(), main_url); | 181 NavigateToURL(shell(), main_url); |
177 | 182 |
178 // It is safe to obtain the root frame tree node here, as it doesn't change. | 183 // It is safe to obtain the root frame tree node here, as it doesn't change. |
179 FrameTreeNode* root = | 184 FrameTreeNode* root = |
180 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 185 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
181 GetFrameTree()->root(); | 186 GetFrameTree()->root(); |
182 FrameTreeNode* child = root->child_at(0); | 187 FrameTreeNode* child = root->child_at(0); |
183 | 188 |
184 // Load cross-site page into iframe. | 189 // Load cross-site page into iframe. |
185 GURL::Replacements replace_host; | 190 GURL::Replacements replace_host; |
186 GURL cross_site_url(embedded_test_server()->GetURL("/title2.html")); | 191 GURL cross_site_url(embedded_test_server()->GetURL("/title2.html")); |
187 replace_host.SetHostStr("foo.com"); | 192 replace_host.SetHostStr("foo.com"); |
188 cross_site_url = cross_site_url.ReplaceComponents(replace_host); | 193 cross_site_url = cross_site_url.ReplaceComponents(replace_host); |
189 NavigateFrameToURL(child, cross_site_url); | 194 NavigateFrameToURL(child, cross_site_url); |
190 | 195 |
191 // First ask for child frame, then for main frame. | 196 // First ask for child frame, then for main frame. |
192 scoped_refptr<DevToolsAgentHost> child_frame_agent = | 197 scoped_refptr<DevToolsAgentHost> child_frame_agent = |
193 DevToolsAgentHost::GetOrCreateFor(child->current_frame_host()); | 198 DevToolsAgentHost::GetOrCreateFor(child->current_frame_host()); |
194 scoped_refptr<DevToolsAgentHost> main_frame_agent = | 199 scoped_refptr<DevToolsAgentHost> main_frame_agent = |
195 DevToolsAgentHost::GetOrCreateFor(root->current_frame_host()); | 200 DevToolsAgentHost::GetOrCreateFor(root->current_frame_host()); |
196 EXPECT_NE(main_frame_agent.get(), child_frame_agent.get()); | 201 EXPECT_NE(main_frame_agent.get(), child_frame_agent.get()); |
| 202 EXPECT_EQ(child_frame_agent->GetParentId(), main_frame_agent->GetId()); |
| 203 EXPECT_NE(child_frame_agent->GetId(), main_frame_agent->GetId()); |
197 | 204 |
198 // Agent for web contents should be the the main frame's one. | 205 // Agent for web contents should be the the main frame's one. |
199 scoped_refptr<DevToolsAgentHost> page_agent = | 206 scoped_refptr<DevToolsAgentHost> page_agent = |
200 DevToolsAgentHost::GetOrCreateFor(shell()->web_contents()); | 207 DevToolsAgentHost::GetOrCreateFor(shell()->web_contents()); |
201 EXPECT_EQ(page_agent.get(), main_frame_agent.get()); | 208 EXPECT_EQ(page_agent.get(), main_frame_agent.get()); |
202 } | 209 } |
203 | 210 |
204 } // namespace content | 211 } // namespace content |
OLD | NEW |