OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "content/browser/frame_host/frame_tree.h" | 5 #include "content/browser/frame_host/frame_tree.h" |
6 #include "content/browser/frame_host/frame_tree_node.h" | 6 #include "content/browser/frame_host/frame_tree_node.h" |
7 #include "content/browser/renderer_host/render_view_host_impl.h" | 7 #include "content/browser/renderer_host/render_view_host_impl.h" |
8 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
9 #include "content/public/browser/notification_service.h" | 9 #include "content/public/browser/notification_service.h" |
10 #include "content/public/browser/notification_types.h" | 10 #include "content/public/browser/notification_types.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 class FrameTreeBrowserTest : public ContentBrowserTest { | 30 class FrameTreeBrowserTest : public ContentBrowserTest { |
31 public: | 31 public: |
32 FrameTreeBrowserTest() {} | 32 FrameTreeBrowserTest() {} |
33 | 33 |
34 void SetUpOnMainThread() override { | 34 void SetUpOnMainThread() override { |
35 host_resolver()->AddRule("*", "127.0.0.1"); | 35 host_resolver()->AddRule("*", "127.0.0.1"); |
36 ASSERT_TRUE(embedded_test_server()->Start()); | 36 ASSERT_TRUE(embedded_test_server()->Start()); |
37 SetupCrossSiteRedirector(embedded_test_server()); | 37 SetupCrossSiteRedirector(embedded_test_server()); |
38 } | 38 } |
39 | 39 |
40 protected: | |
41 std::string GetEffectiveOriginFromRenderer(FrameTreeNode* node) { | |
alexmos
2015/11/24 18:23:48
Nit: can this just be GetOriginFromRenderer? "Eff
ncarter (slow)
2015/11/24 19:35:08
Done.
| |
42 std::string origin; | |
43 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
44 node->current_frame_host(), | |
45 "window.domAutomationController.send(document.origin);", &origin)); | |
46 return origin; | |
47 } | |
48 | |
40 private: | 49 private: |
41 DISALLOW_COPY_AND_ASSIGN(FrameTreeBrowserTest); | 50 DISALLOW_COPY_AND_ASSIGN(FrameTreeBrowserTest); |
42 }; | 51 }; |
43 | 52 |
44 // Ensures FrameTree correctly reflects page structure during navigations. | 53 // Ensures FrameTree correctly reflects page structure during navigations. |
45 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, FrameTreeShape) { | 54 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, FrameTreeShape) { |
46 GURL base_url = embedded_test_server()->GetURL("A.com", "/site_isolation/"); | 55 GURL base_url = embedded_test_server()->GetURL("A.com", "/site_isolation/"); |
47 | 56 |
48 // Load doc without iframes. Verify FrameTree just has root. | 57 // Load doc without iframes. Verify FrameTree just has root. |
49 // Frame tree: | 58 // Frame tree: |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 GURL http_url(embedded_test_server()->GetURL("/title1.html")); | 207 GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
199 NavigateFrameToURL(root->child_at(0), http_url); | 208 NavigateFrameToURL(root->child_at(0), http_url); |
200 EXPECT_TRUE( | 209 EXPECT_TRUE( |
201 root->current_frame_host()->render_view_host()->IsRenderViewLive()); | 210 root->current_frame_host()->render_view_host()->IsRenderViewLive()); |
202 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); | 211 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); |
203 EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive()); | 212 EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive()); |
204 } | 213 } |
205 | 214 |
206 // Ensure that origins are correctly set on navigations. | 215 // Ensure that origins are correctly set on navigations. |
207 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, OriginSetOnNavigation) { | 216 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, OriginSetOnNavigation) { |
208 GURL main_url(embedded_test_server()->GetURL("/frame_tree/top.html")); | 217 std::string scraped_origin; |
alexmos
2015/11/24 18:23:48
This looks unused.
ncarter (slow)
2015/11/24 19:35:08
Done.
| |
218 GURL about_blank("about:blank"); | |
219 GURL main_url( | |
220 embedded_test_server()->GetURL("a.com", "/frame_tree/top.html")); | |
209 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 221 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
222 WebContents* contents = shell()->web_contents(); | |
210 | 223 |
211 // It is safe to obtain the root frame tree node here, as it doesn't change. | 224 // It is safe to obtain the root frame tree node here, as it doesn't change. |
212 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 225 FrameTreeNode* root = |
213 ->GetFrameTree()->root(); | 226 static_cast<WebContentsImpl*>(contents)->GetFrameTree()->root(); |
214 | 227 |
215 // Extra '/' is added because the replicated origin is serialized in RFC 6454 | 228 // Extra '/' is added because the replicated origin is serialized in RFC 6454 |
216 // format, which dictates no trailing '/', whereas GURL::GetOrigin does put a | 229 // format, which dictates no trailing '/', whereas GURL::GetOrigin does put a |
217 // '/' at the end. | 230 // '/' at the end. |
218 EXPECT_EQ(root->current_origin().Serialize() + '/', | 231 EXPECT_EQ(main_url.GetOrigin().spec(), |
219 main_url.GetOrigin().spec()); | 232 root->current_origin().Serialize() + '/'); |
220 | 233 |
221 GURL frame_url(embedded_test_server()->GetURL("/title1.html")); | 234 // The origin is also exposed via the RenderFrameHost. |
235 EXPECT_EQ( | |
236 main_url.GetOrigin().spec(), | |
237 root->current_frame_host()->GetLastCommittedOrigin().Serialize() + '/'); | |
238 EXPECT_TRUE( | |
239 root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( | |
240 root->child_at(0)->current_frame_host()->GetLastCommittedOrigin())); | |
241 EXPECT_EQ(root->current_origin().Serialize(), | |
242 GetEffectiveOriginFromRenderer(root)); | |
243 EXPECT_EQ(root->child_at(0)->current_origin().Serialize(), | |
244 GetEffectiveOriginFromRenderer(root->child_at(0))); | |
245 | |
246 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | |
222 NavigateFrameToURL(root->child_at(0), frame_url); | 247 NavigateFrameToURL(root->child_at(0), frame_url); |
248 EXPECT_EQ(root->child_at(0)->current_url(), frame_url); | |
249 EXPECT_EQ(frame_url.GetOrigin().spec(), | |
250 root->child_at(0)->current_origin().Serialize() + '/'); | |
251 EXPECT_FALSE( | |
252 root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( | |
253 root->child_at(0)->current_frame_host()->GetLastCommittedOrigin())); | |
254 EXPECT_EQ(root->current_origin().Serialize(), | |
255 GetEffectiveOriginFromRenderer(root)); | |
256 EXPECT_EQ(root->child_at(0)->current_origin().Serialize(), | |
257 GetEffectiveOriginFromRenderer(root->child_at(0))); | |
223 | 258 |
224 EXPECT_EQ(root->child_at(0)->current_origin().Serialize() + '/', | 259 // Parent-initiated about:blank navigation should inherit the parent's a.com |
225 frame_url.GetOrigin().spec()); | 260 // origin. |
261 NavigateIframeToURL(contents, "1-1-id", about_blank); | |
262 EXPECT_EQ(root->child_at(0)->current_url(), about_blank); | |
263 EXPECT_EQ(main_url.GetOrigin().spec(), | |
264 root->child_at(0)->current_origin().Serialize() + '/'); | |
265 EXPECT_EQ(root->current_frame_host()->GetLastCommittedOrigin().Serialize(), | |
266 root->child_at(0) | |
267 ->current_frame_host() | |
268 ->GetLastCommittedOrigin() | |
269 .Serialize()); | |
270 EXPECT_TRUE( | |
271 root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( | |
272 root->child_at(0)->current_frame_host()->GetLastCommittedOrigin())); | |
273 EXPECT_EQ(root->current_origin().Serialize(), | |
274 GetEffectiveOriginFromRenderer(root)); | |
275 EXPECT_EQ(root->child_at(0)->current_origin().Serialize(), | |
276 GetEffectiveOriginFromRenderer(root->child_at(0))); | |
226 | 277 |
227 GURL data_url("data:text/html,foo"); | 278 GURL data_url("data:text/html,foo"); |
228 EXPECT_TRUE(NavigateToURL(shell(), data_url)); | 279 EXPECT_TRUE(NavigateToURL(shell(), data_url)); |
229 | 280 |
230 // Navigating to a data URL should set a unique origin. This is represented | 281 // Navigating to a data URL should set a unique origin. This is represented |
231 // as "null" per RFC 6454. | 282 // as "null" per RFC 6454. |
232 EXPECT_EQ(root->current_origin().Serialize(), "null"); | 283 EXPECT_EQ("null", root->current_origin().Serialize()); |
284 EXPECT_TRUE(contents->GetMainFrame()->GetLastCommittedOrigin().unique()); | |
285 EXPECT_EQ("null", GetEffectiveOriginFromRenderer(root)); | |
233 | 286 |
234 // Re-navigating to a normal URL should update the origin. | 287 // Re-navigating to a normal URL should update the origin. |
235 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 288 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
236 EXPECT_EQ(root->current_origin().Serialize() + '/', | 289 EXPECT_EQ(main_url.GetOrigin().spec(), |
237 main_url.GetOrigin().spec()); | 290 root->current_origin().Serialize() + '/'); |
291 EXPECT_EQ( | |
292 main_url.GetOrigin().spec(), | |
293 contents->GetMainFrame()->GetLastCommittedOrigin().Serialize() + '/'); | |
294 EXPECT_FALSE(contents->GetMainFrame()->GetLastCommittedOrigin().unique()); | |
295 EXPECT_EQ(root->current_origin().Serialize(), | |
296 GetEffectiveOriginFromRenderer(root)); | |
238 } | 297 } |
239 | 298 |
240 // Ensure that sandbox flags are correctly set when child frames are created. | 299 // Ensure that sandbox flags are correctly set when child frames are created. |
241 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, SandboxFlagsSetForChildFrames) { | 300 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, SandboxFlagsSetForChildFrames) { |
242 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html")); | 301 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html")); |
243 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 302 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
244 | 303 |
245 // It is safe to obtain the root frame tree node here, as it doesn't change. | 304 // It is safe to obtain the root frame tree node here, as it doesn't change. |
246 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 305 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
247 ->GetFrameTree()->root(); | 306 ->GetFrameTree()->root(); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 | 475 |
417 GURL data_url("data:text/html,foo"); | 476 GURL data_url("data:text/html,foo"); |
418 NavigateFrameToURL(root->child_at(1), data_url); | 477 NavigateFrameToURL(root->child_at(1), data_url); |
419 | 478 |
420 // Navigating to a data URL should set a unique origin. This is represented | 479 // Navigating to a data URL should set a unique origin. This is represented |
421 // as "null" per RFC 6454. | 480 // as "null" per RFC 6454. |
422 EXPECT_EQ(root->child_at(1)->current_origin().Serialize(), "null"); | 481 EXPECT_EQ(root->child_at(1)->current_origin().Serialize(), "null"); |
423 } | 482 } |
424 | 483 |
425 } // namespace content | 484 } // namespace content |
OLD | NEW |