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

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

Issue 692973005: Pass origin information for remote frame creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add EXPECT_TRUE to NavigateToURL in new tests; nits Created 6 years, 1 month 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
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..f4dcbe83100b37988983e6f6dbe15b718fbad1c3 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");
nasko 2014/11/20 17:22:54 Let's use the EmbeddedTestServer in all new tests.
ncarter (slow) 2014/11/20 20:50:45 The three second version: - test_server() becomes
alexmos 2014/11/20 21:09:10 As we discussed in person, I can do that in a sepa
nasko 2014/11/20 21:21:21 Acknowledged.
+ ASSERT_TRUE(test_server()->Start());
+ GURL main_url(test_server()->GetURL("files/frame_tree/top.html"));
+ EXPECT_TRUE(NavigateToURL(shell(), main_url));
+
+ // 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");
+ EXPECT_TRUE(NavigateToURL(shell(), data_url));
nasko 2014/11/20 17:22:54 Why not navigate another iframe on the page instea
alexmos 2014/11/20 21:09:10 Interesting -- doing that made the test crash when
+
+ // 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.
+ EXPECT_TRUE(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");
nasko 2014/11/20 17:22:54 Same as the other tests, let's use EmbeddedTestSer
alexmos 2014/11/20 21:09:10 See above -- will do the whole file in a separate
+ ASSERT_TRUE(test_server()->Start());
+ GURL main_url(test_server()->GetURL("files/site_per_process_main.html"));
+ EXPECT_TRUE(NavigateToURL(shell(), main_url));
+
+ // 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;
nasko 2014/11/20 17:22:54 Ah, you also skip all that boilerplate code and ju
alexmos 2014/11/20 21:09:10 test_server() doesn't support this, right? If so,
nasko 2014/11/20 21:21:21 Yes, the API is on the EmbeddedTestServer. This wa
+ std::string foo_com("foo.com");
+
+ // Load cross-site page into the first frame.
+ 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.
+ EXPECT_EQ(root->current_replication_state().origin.string() + '/',
+ main_url.GetOrigin().spec());
+}
+
} // namespace content
« no previous file with comments | « no previous file | content/browser/frame_host/frame_tree_node.h » ('j') | content/browser/frame_host/navigator_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698