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 f64e22733db5b3dfe059febad28daa4e5dc797b6..06fef200a671fc7572fa0c891e35657aa8fd6fb8 100644 |
--- a/content/browser/frame_host/frame_tree_browsertest.cc |
+++ b/content/browser/frame_host/frame_tree_browsertest.cc |
@@ -37,6 +37,15 @@ class FrameTreeBrowserTest : public ContentBrowserTest { |
SetupCrossSiteRedirector(embedded_test_server()); |
} |
+ protected: |
+ 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.
|
+ std::string origin; |
+ EXPECT_TRUE(ExecuteScriptAndExtractString( |
+ node->current_frame_host(), |
+ "window.domAutomationController.send(document.origin);", &origin)); |
+ return origin; |
+ } |
+ |
private: |
DISALLOW_COPY_AND_ASSIGN(FrameTreeBrowserTest); |
}; |
@@ -205,36 +214,86 @@ IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, IsRenderFrameLive) { |
// Ensure that origins are correctly set on navigations. |
IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, OriginSetOnNavigation) { |
- GURL main_url(embedded_test_server()->GetURL("/frame_tree/top.html")); |
+ std::string scraped_origin; |
alexmos
2015/11/24 18:23:48
This looks unused.
ncarter (slow)
2015/11/24 19:35:08
Done.
|
+ GURL about_blank("about:blank"); |
+ GURL main_url( |
+ embedded_test_server()->GetURL("a.com", "/frame_tree/top.html")); |
EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
+ WebContents* contents = shell()->web_contents(); |
// It is safe to obtain the root frame tree node here, as it doesn't change. |
- FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
- ->GetFrameTree()->root(); |
+ FrameTreeNode* root = |
+ static_cast<WebContentsImpl*>(contents)->GetFrameTree()->root(); |
// Extra '/' is added because the replicated origin is serialized in RFC 6454 |
// format, which dictates no trailing '/', whereas GURL::GetOrigin does put a |
// '/' at the end. |
- EXPECT_EQ(root->current_origin().Serialize() + '/', |
- main_url.GetOrigin().spec()); |
+ EXPECT_EQ(main_url.GetOrigin().spec(), |
+ root->current_origin().Serialize() + '/'); |
- GURL frame_url(embedded_test_server()->GetURL("/title1.html")); |
+ // The origin is also exposed via the RenderFrameHost. |
+ EXPECT_EQ( |
+ main_url.GetOrigin().spec(), |
+ root->current_frame_host()->GetLastCommittedOrigin().Serialize() + '/'); |
+ EXPECT_TRUE( |
+ root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( |
+ root->child_at(0)->current_frame_host()->GetLastCommittedOrigin())); |
+ EXPECT_EQ(root->current_origin().Serialize(), |
+ GetEffectiveOriginFromRenderer(root)); |
+ EXPECT_EQ(root->child_at(0)->current_origin().Serialize(), |
+ GetEffectiveOriginFromRenderer(root->child_at(0))); |
+ |
+ GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
NavigateFrameToURL(root->child_at(0), frame_url); |
- |
- EXPECT_EQ(root->child_at(0)->current_origin().Serialize() + '/', |
- frame_url.GetOrigin().spec()); |
+ EXPECT_EQ(root->child_at(0)->current_url(), frame_url); |
+ EXPECT_EQ(frame_url.GetOrigin().spec(), |
+ root->child_at(0)->current_origin().Serialize() + '/'); |
+ EXPECT_FALSE( |
+ root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( |
+ root->child_at(0)->current_frame_host()->GetLastCommittedOrigin())); |
+ EXPECT_EQ(root->current_origin().Serialize(), |
+ GetEffectiveOriginFromRenderer(root)); |
+ EXPECT_EQ(root->child_at(0)->current_origin().Serialize(), |
+ GetEffectiveOriginFromRenderer(root->child_at(0))); |
+ |
+ // Parent-initiated about:blank navigation should inherit the parent's a.com |
+ // origin. |
+ NavigateIframeToURL(contents, "1-1-id", about_blank); |
+ EXPECT_EQ(root->child_at(0)->current_url(), about_blank); |
+ EXPECT_EQ(main_url.GetOrigin().spec(), |
+ root->child_at(0)->current_origin().Serialize() + '/'); |
+ EXPECT_EQ(root->current_frame_host()->GetLastCommittedOrigin().Serialize(), |
+ root->child_at(0) |
+ ->current_frame_host() |
+ ->GetLastCommittedOrigin() |
+ .Serialize()); |
+ EXPECT_TRUE( |
+ root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( |
+ root->child_at(0)->current_frame_host()->GetLastCommittedOrigin())); |
+ EXPECT_EQ(root->current_origin().Serialize(), |
+ GetEffectiveOriginFromRenderer(root)); |
+ EXPECT_EQ(root->child_at(0)->current_origin().Serialize(), |
+ GetEffectiveOriginFromRenderer(root->child_at(0))); |
GURL data_url("data:text/html,foo"); |
EXPECT_TRUE(NavigateToURL(shell(), data_url)); |
// Navigating to a data URL should set a unique origin. This is represented |
// as "null" per RFC 6454. |
- EXPECT_EQ(root->current_origin().Serialize(), "null"); |
+ EXPECT_EQ("null", root->current_origin().Serialize()); |
+ EXPECT_TRUE(contents->GetMainFrame()->GetLastCommittedOrigin().unique()); |
+ EXPECT_EQ("null", GetEffectiveOriginFromRenderer(root)); |
// Re-navigating to a normal URL should update the origin. |
EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
- EXPECT_EQ(root->current_origin().Serialize() + '/', |
- main_url.GetOrigin().spec()); |
+ EXPECT_EQ(main_url.GetOrigin().spec(), |
+ root->current_origin().Serialize() + '/'); |
+ EXPECT_EQ( |
+ main_url.GetOrigin().spec(), |
+ contents->GetMainFrame()->GetLastCommittedOrigin().Serialize() + '/'); |
+ EXPECT_FALSE(contents->GetMainFrame()->GetLastCommittedOrigin().unique()); |
+ EXPECT_EQ(root->current_origin().Serialize(), |
+ GetEffectiveOriginFromRenderer(root)); |
} |
// Ensure that sandbox flags are correctly set when child frames are created. |