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 b9e3b43bd796c24b40ff46857c2b4f2dbdd0d546..216926fa6b5060ff7fd27af6159800f41df6ae30 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) { |
+ std::string origin; |
+ EXPECT_TRUE(ExecuteScriptAndExtractString( |
+ node->current_frame_host(), |
+ "window.domAutomationController.send(document.domain);", &origin)); |
alexmos
2015/11/24 00:05:49
Any reason to use this instead of document.origin?
ncarter (slow)
2015/11/24 00:35:33
Good point; I'll switch to document.origin. I orig
|
+ return origin; |
+ } |
+ |
private: |
DISALLOW_COPY_AND_ASSIGN(FrameTreeBrowserTest); |
}; |
@@ -205,25 +214,62 @@ 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; |
+ 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_replication_state().origin.Serialize() + '/', |
- main_url.GetOrigin().spec()); |
+ EXPECT_EQ(main_url.GetOrigin().spec(), |
+ root->current_replication_state().origin.Serialize() + '/'); |
- GURL frame_url(embedded_test_server()->GetURL("/title1.html")); |
- NavigateFrameToURL(root->child_at(0), frame_url); |
+ // The origin is also exposed via the RenderFrameHost. |
+ EXPECT_EQ( |
+ main_url.GetOrigin().spec(), |
+ contents->GetMainFrame()->GetLastCommittedOrigin().Serialize() + '/'); |
+ EXPECT_TRUE( |
+ root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( |
+ root->child_at(0)->current_frame_host()->GetLastCommittedOrigin())); |
+ EXPECT_EQ("a.com", GetEffectiveOriginFromRenderer(root)); |
+ EXPECT_EQ("a.com", 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_url(), frame_url); |
EXPECT_EQ( |
- root->child_at(0)->current_replication_state().origin.Serialize() + '/', |
- frame_url.GetOrigin().spec()); |
+ frame_url.GetOrigin().spec(), |
+ root->child_at(0)->current_replication_state().origin.Serialize() + '/'); |
+ EXPECT_FALSE( |
+ root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( |
+ root->child_at(0)->current_frame_host()->GetLastCommittedOrigin())); |
+ EXPECT_EQ("a.com", GetEffectiveOriginFromRenderer(root)); |
+ EXPECT_EQ("b.com", 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_replication_state().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("a.com", GetEffectiveOriginFromRenderer(root->child_at(0))); |
+ EXPECT_EQ("a.com", GetEffectiveOriginFromRenderer(root)); |
GURL data_url("data:text/html,foo"); |
EXPECT_TRUE(NavigateToURL(shell(), data_url)); |
@@ -231,11 +277,18 @@ IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, OriginSetOnNavigation) { |
// Navigating to a data URL should set a unique origin. This is represented |
// as "null" per RFC 6454. |
EXPECT_EQ(root->current_replication_state().origin.Serialize(), "null"); |
+ EXPECT_TRUE(contents->GetMainFrame()->GetLastCommittedOrigin().unique()); |
+ EXPECT_EQ("", GetEffectiveOriginFromRenderer(root)); |
// Re-navigating to a normal URL should update the origin. |
EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
- EXPECT_EQ(root->current_replication_state().origin.Serialize() + '/', |
- main_url.GetOrigin().spec()); |
+ EXPECT_EQ(main_url.GetOrigin().spec(), |
+ root->current_replication_state().origin.Serialize() + '/'); |
+ EXPECT_EQ( |
+ main_url.GetOrigin().spec(), |
+ contents->GetMainFrame()->GetLastCommittedOrigin().Serialize() + '/'); |
+ EXPECT_FALSE(contents->GetMainFrame()->GetLastCommittedOrigin().unique()); |
+ EXPECT_EQ("a.com", GetEffectiveOriginFromRenderer(root)); |
} |
// Ensure that sandbox flags are correctly set when child frames are created. |