Chromium Code Reviews| 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 "base/macros.h" | 5 #include "base/macros.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/frame_host/frame_tree_node.h" | 8 #include "content/browser/frame_host/frame_tree_node.h" |
| 9 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 EXPECT_EQ(target->current_origin().Serialize(), about_blank_origin); | 443 EXPECT_EQ(target->current_origin().Serialize(), about_blank_origin); |
| 444 | 444 |
| 445 std::string document_body; | 445 std::string document_body; |
| 446 EXPECT_TRUE(ExecuteScriptAndExtractString( | 446 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 447 target->current_frame_host(), | 447 target->current_frame_host(), |
| 448 "domAutomationController.send(document.body.innerHTML);", | 448 "domAutomationController.send(document.body.innerHTML);", |
| 449 &document_body)); | 449 &document_body)); |
| 450 EXPECT_EQ("Hi from a.com", document_body); | 450 EXPECT_EQ("Hi from a.com", document_body); |
| 451 } | 451 } |
| 452 | 452 |
| 453 // Ensures that iframe with srcdoc is always put in the same origin as its | |
| 454 // parent frame. | |
| 455 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, ChildFrameWithSrcdoc) { | |
| 456 GURL main_url(embedded_test_server()->GetURL( | |
| 457 "a.com", "/cross_site_iframe_factory.html?a(b)")); | |
| 458 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
| 459 WebContentsImpl* contents = | |
| 460 static_cast<WebContentsImpl*>(shell()->web_contents()); | |
| 461 FrameTreeNode* root = contents->GetFrameTree()->root(); | |
| 462 EXPECT_EQ(1U, root->child_count()); | |
| 463 | |
| 464 FrameTreeNode* child = root->child_at(0); | |
| 465 std::string frame_origin; | |
| 466 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
| 467 child->current_frame_host(), | |
| 468 "domAutomationController.send(document.origin);", &frame_origin)); | |
| 469 EXPECT_TRUE( | |
| 470 child->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( | |
| 471 url::Origin(GURL(frame_origin)))); | |
| 472 EXPECT_FALSE( | |
| 473 root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( | |
| 474 url::Origin(GURL(frame_origin)))); | |
| 475 | |
| 476 // Create a new iframe with srcdoc and add it to the main frame. It should | |
| 477 // be created in the same SiteInstance as the parent. | |
| 478 { | |
| 479 std::string script("var f = document.createElement('iframe');" | |
| 480 "f.srcdoc = 'some content';" | |
| 481 "document.body.appendChild(f)"); | |
| 482 TestNavigationObserver observer(shell()->web_contents()); | |
| 483 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script)); | |
| 484 EXPECT_EQ(2U, root->child_count()); | |
| 485 observer.Wait(); | |
| 486 | |
| 487 EXPECT_EQ(GURL(url::kAboutBlankURL), root->child_at(1)->current_url()); | |
| 488 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
| 489 root->child_at(1)->current_frame_host(), | |
| 490 "domAutomationController.send(document.origin);", &frame_origin)); | |
| 491 EXPECT_EQ(root->current_frame_host()->GetLastCommittedURL().GetOrigin(), | |
| 492 GURL(frame_origin)); | |
| 493 EXPECT_NE(child->current_frame_host()->GetLastCommittedURL().GetOrigin(), | |
| 494 GURL(frame_origin)); | |
| 495 } | |
| 496 | |
| 497 // Set srcdoc on the existing cross-site frame. It should navigate the frame | |
| 498 // back to the origin of the parent. | |
| 499 { | |
| 500 std::string script("var f = document.getElementById('child-0');" | |
| 501 "f.srcdoc = 'some content';"); | |
| 502 TestNavigationObserver observer(shell()->web_contents()); | |
| 503 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script)); | |
| 504 observer.Wait(); | |
| 505 | |
| 506 EXPECT_EQ(GURL(url::kAboutBlankURL), child->current_url()); | |
| 507 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
| 508 child->current_frame_host(), | |
| 509 "domAutomationController.send(document.origin);", &frame_origin)); | |
| 510 EXPECT_EQ(root->current_frame_host()->GetLastCommittedURL().GetOrigin(), | |
| 511 GURL(frame_origin)); | |
| 512 } | |
|
ncarter (slow)
2016/04/29 20:10:30
srcdoc is very entertaining.
I just checked manua
| |
| 513 } | |
| 514 | |
| 453 // Ensure that sandbox flags are correctly set when child frames are created. | 515 // Ensure that sandbox flags are correctly set when child frames are created. |
| 454 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, SandboxFlagsSetForChildFrames) { | 516 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, SandboxFlagsSetForChildFrames) { |
| 455 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html")); | 517 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html")); |
| 456 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 518 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 457 | 519 |
| 458 // It is safe to obtain the root frame tree node here, as it doesn't change. | 520 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 459 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 521 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 460 ->GetFrameTree()->root(); | 522 ->GetFrameTree()->root(); |
| 461 | 523 |
| 462 // Verify that sandbox flags are set properly for all FrameTreeNodes. | 524 // Verify that sandbox flags are set properly for all FrameTreeNodes. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 628 | 690 |
| 629 GURL data_url("data:text/html,foo"); | 691 GURL data_url("data:text/html,foo"); |
| 630 NavigateFrameToURL(root->child_at(1), data_url); | 692 NavigateFrameToURL(root->child_at(1), data_url); |
| 631 | 693 |
| 632 // Navigating to a data URL should set a unique origin. This is represented | 694 // Navigating to a data URL should set a unique origin. This is represented |
| 633 // as "null" per RFC 6454. | 695 // as "null" per RFC 6454. |
| 634 EXPECT_EQ(root->child_at(1)->current_origin().Serialize(), "null"); | 696 EXPECT_EQ(root->child_at(1)->current_origin().Serialize(), "null"); |
| 635 } | 697 } |
| 636 | 698 |
| 637 } // namespace content | 699 } // namespace content |
| OLD | NEW |