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 9f16066cd38752be333d5af39867ef7d4618d346..b4f5594d0e1b80f13f020723a1a0179fefd6aabe 100644 |
| --- a/content/browser/frame_host/frame_tree_browsertest.cc |
| +++ b/content/browser/frame_host/frame_tree_browsertest.cc |
| @@ -199,6 +199,43 @@ IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, IsRenderFrameLive) { |
| EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive()); |
| } |
| +// Ensure that origins are correctly set on navigations. |
| +IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, OriginSetOnNavigation) { |
| + host_resolver()->AddRule("*", "127.0.0.1"); |
| + ASSERT_TRUE(test_server()->Start()); |
| + GURL main_url(test_server()->GetURL("files/frame_tree/top.html")); |
| + NavigateToURL(shell(), main_url); |
|
Charlie Reis
2014/11/19 00:46:18
EXPECT_TRUE? (Here and below.)
alexmos
2014/11/19 02:49:27
Indeed :) I was holding off on rebasing, which I
|
| + |
| + // 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(); |
| + |
| + // 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.string() + '/', |
| + main_url.GetOrigin().spec()); |
| + |
| + GURL frame_url(test_server()->GetURL("files/title1.html")); |
| + NavigateFrameToURL(root->child_at(0), frame_url); |
| + |
| + EXPECT_EQ( |
| + root->child_at(0)->current_replication_state().origin.string() + '/', |
| + frame_url.GetOrigin().spec()); |
| + |
| + GURL data_url("data:text/html,foo"); |
| + 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_replication_state().origin.string(), "null"); |
| + |
| + // Re-navigating to a normal URL should update the origin. |
| + NavigateToURL(shell(), main_url); |
| + EXPECT_EQ(root->current_replication_state().origin.string() + '/', |
| + main_url.GetOrigin().spec()); |
| +} |
| + |
| class CrossProcessFrameTreeBrowserTest : public ContentBrowserTest { |
| public: |
| CrossProcessFrameTreeBrowserTest() {} |
| @@ -277,4 +314,43 @@ IN_PROC_BROWSER_TEST_F(CrossProcessFrameTreeBrowserTest, |
| EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive()); |
| } |
| +IN_PROC_BROWSER_TEST_F(CrossProcessFrameTreeBrowserTest, |
| + OriginSetOnCrossProcessNavigations) { |
| + host_resolver()->AddRule("*", "127.0.0.1"); |
|
Charlie Reis
2014/11/19 00:46:18
nit: 2 space indent
(I think git cl format would p
alexmos
2014/11/19 02:49:27
Done.
|
| + ASSERT_TRUE(test_server()->Start()); |
| + GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
| + NavigateToURL(shell(), main_url); |
|
Charlie Reis
2014/11/19 00:46:18
EXPECT_TRUE?
alexmos
2014/11/19 02:49:27
See above.
|
| + |
| + // 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(); |
| + |
| + EXPECT_EQ(root->current_replication_state().origin.string() + '/', |
| + main_url.GetOrigin().spec()); |
| + |
| + // First frame is an about:blank frame. Check that its origin is correctly |
| + // inherited from the parent. |
| + EXPECT_EQ( |
| + root->child_at(0)->current_replication_state().origin.string() + '/', |
| + main_url.GetOrigin().spec()); |
| + |
| + // These must stay in scope with replace_host. |
| + GURL::Replacements replace_host; |
| + std::string foo_com("foo.com"); |
| + |
| + // Load cross-site page into the first frame |
|
Charlie Reis
2014/11/19 00:46:18
nit: End with period.
alexmos
2014/11/19 02:49:26
Done.
|
| + GURL cross_site_url(test_server()->GetURL("files/title2.html")); |
| + replace_host.SetHostStr(foo_com); |
| + cross_site_url = cross_site_url.ReplaceComponents(replace_host); |
| + NavigateFrameToURL(root->child_at(0), cross_site_url); |
| + |
| + EXPECT_EQ( |
| + root->child_at(0)->current_replication_state().origin.string() + '/', |
| + cross_site_url.GetOrigin().spec()); |
| + |
| + // the root's origin shouldn't have changed |
|
Charlie Reis
2014/11/19 00:46:18
nit: Capitalize, end with period.
alexmos
2014/11/19 02:49:27
Done.
|
| + EXPECT_EQ(root->current_replication_state().origin.string() + '/', |
| + main_url.GetOrigin().spec()); |
| +} |
| + |
| } // namespace content |