Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(799)

Unified Diff: content/browser/frame_host/frame_tree_browsertest.cc

Issue 1922243002: Add a test for iframe srcdoc origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/frame_host/frame_tree_browsertest.cc
diff --git a/content/browser/frame_host/frame_tree_browsertest.cc b/content/browser/frame_host/frame_tree_browsertest.cc
index 782234f5a02c42080fbd25c9578922e428c507eb..396ab05ab2adf590ea9e642fc7bc222d0014be92 100644
--- a/content/browser/frame_host/frame_tree_browsertest.cc
+++ b/content/browser/frame_host/frame_tree_browsertest.cc
@@ -450,6 +450,68 @@ IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest,
EXPECT_EQ("Hi from a.com", document_body);
}
+// Ensures that iframe with srcdoc is always put in the same origin as its
+// parent frame.
+IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, ChildFrameWithSrcdoc) {
+ GURL main_url(embedded_test_server()->GetURL(
+ "a.com", "/cross_site_iframe_factory.html?a(b)"));
+ EXPECT_TRUE(NavigateToURL(shell(), main_url));
+ WebContentsImpl* contents =
+ static_cast<WebContentsImpl*>(shell()->web_contents());
+ FrameTreeNode* root = contents->GetFrameTree()->root();
+ EXPECT_EQ(1U, root->child_count());
+
+ FrameTreeNode* child = root->child_at(0);
+ std::string frame_origin;
+ EXPECT_TRUE(ExecuteScriptAndExtractString(
+ child->current_frame_host(),
+ "domAutomationController.send(document.origin);", &frame_origin));
+ EXPECT_TRUE(
+ child->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith(
+ url::Origin(GURL(frame_origin))));
+ EXPECT_FALSE(
+ root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith(
+ url::Origin(GURL(frame_origin))));
+
+ // Create a new iframe with srcdoc and add it to the main frame. It should
+ // be created in the same SiteInstance as the parent.
+ {
+ std::string script("var f = document.createElement('iframe');"
+ "f.srcdoc = 'some content';"
+ "document.body.appendChild(f)");
+ TestNavigationObserver observer(shell()->web_contents());
+ EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
+ EXPECT_EQ(2U, root->child_count());
+ observer.Wait();
+
+ EXPECT_EQ(GURL(url::kAboutBlankURL), root->child_at(1)->current_url());
+ EXPECT_TRUE(ExecuteScriptAndExtractString(
+ root->child_at(1)->current_frame_host(),
+ "domAutomationController.send(document.origin);", &frame_origin));
+ EXPECT_EQ(root->current_frame_host()->GetLastCommittedURL().GetOrigin(),
+ GURL(frame_origin));
+ EXPECT_NE(child->current_frame_host()->GetLastCommittedURL().GetOrigin(),
+ GURL(frame_origin));
+ }
+
+ // Set srcdoc on the existing cross-site frame. It should navigate the frame
+ // back to the origin of the parent.
+ {
+ std::string script("var f = document.getElementById('child-0');"
+ "f.srcdoc = 'some content';");
+ TestNavigationObserver observer(shell()->web_contents());
+ EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
+ observer.Wait();
+
+ EXPECT_EQ(GURL(url::kAboutBlankURL), child->current_url());
+ EXPECT_TRUE(ExecuteScriptAndExtractString(
+ child->current_frame_host(),
+ "domAutomationController.send(document.origin);", &frame_origin));
+ EXPECT_EQ(root->current_frame_host()->GetLastCommittedURL().GetOrigin(),
+ GURL(frame_origin));
+ }
ncarter (slow) 2016/04/29 20:10:30 srcdoc is very entertaining. I just checked manua
+}
+
// Ensure that sandbox flags are correctly set when child frames are created.
IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, SandboxFlagsSetForChildFrames) {
GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html"));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698