Chromium Code Reviews| 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..37f1b679252e7e62d26a9bdac5f4a22678e097bb 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 GetOriginFromRenderer(FrameTreeNode* node) { |
| + 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,81 @@ 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")); |
| + GURL about_blank("about:blank"); |
|
Charlie Reis
2015/11/24 21:00:42
nit: url::kAboutBlankURL
ncarter (slow)
2015/11/24 22:07:33
Done.
|
| + 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")); |
| - NavigateFrameToURL(root->child_at(0), frame_url); |
| + // 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())); |
|
Charlie Reis
2015/11/24 21:00:42
Can you mention something in the comment above abo
ncarter (slow)
2015/11/24 22:07:33
Done.
|
| + EXPECT_EQ(root->current_origin().Serialize(), GetOriginFromRenderer(root)); |
| + EXPECT_EQ(root->child_at(0)->current_origin().Serialize(), |
| + GetOriginFromRenderer(root->child_at(0))); |
| - EXPECT_EQ(root->child_at(0)->current_origin().Serialize() + '/', |
| - frame_url.GetOrigin().spec()); |
| + 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); |
|
Charlie Reis
2015/11/24 21:00:42
nit: Swap order (expected, actual).
ncarter (slow)
2015/11/24 22:07:33
Done.
|
| + 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(), GetOriginFromRenderer(root)); |
| + EXPECT_EQ(root->child_at(0)->current_origin().Serialize(), |
| + GetOriginFromRenderer(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); |
|
Charlie Reis
2015/11/24 21:00:42
nit: Swap order.
ncarter (slow)
2015/11/24 22:07:33
Done.
|
| + 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(), GetOriginFromRenderer(root)); |
| + EXPECT_EQ(root->child_at(0)->current_origin().Serialize(), |
| + GetOriginFromRenderer(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", GetOriginFromRenderer(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(), GetOriginFromRenderer(root)); |
| } |
| // Ensure that sandbox flags are correctly set when child frames are created. |