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

Side by Side Diff: content/browser/frame_host/frame_tree_browsertest.cc

Issue 1475433002: Expose RenderFrameHost::GetLastCommittedOrigin(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/frame_host/frame_tree.h" 5 #include "content/browser/frame_host/frame_tree.h"
6 #include "content/browser/frame_host/frame_tree_node.h" 6 #include "content/browser/frame_host/frame_tree_node.h"
7 #include "content/browser/renderer_host/render_view_host_impl.h" 7 #include "content/browser/renderer_host/render_view_host_impl.h"
8 #include "content/browser/web_contents/web_contents_impl.h" 8 #include "content/browser/web_contents/web_contents_impl.h"
9 #include "content/public/browser/notification_service.h" 9 #include "content/public/browser/notification_service.h"
10 #include "content/public/browser/notification_types.h" 10 #include "content/public/browser/notification_types.h"
(...skipping 19 matching lines...) Expand all
30 class FrameTreeBrowserTest : public ContentBrowserTest { 30 class FrameTreeBrowserTest : public ContentBrowserTest {
31 public: 31 public:
32 FrameTreeBrowserTest() {} 32 FrameTreeBrowserTest() {}
33 33
34 void SetUpOnMainThread() override { 34 void SetUpOnMainThread() override {
35 host_resolver()->AddRule("*", "127.0.0.1"); 35 host_resolver()->AddRule("*", "127.0.0.1");
36 ASSERT_TRUE(embedded_test_server()->Start()); 36 ASSERT_TRUE(embedded_test_server()->Start());
37 SetupCrossSiteRedirector(embedded_test_server()); 37 SetupCrossSiteRedirector(embedded_test_server());
38 } 38 }
39 39
40 protected:
41 std::string GetEffectiveOriginFromRenderer(FrameTreeNode* node) {
42 std::string origin;
43 EXPECT_TRUE(ExecuteScriptAndExtractString(
44 node->current_frame_host(),
45 "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
46 return origin;
47 }
48
40 private: 49 private:
41 DISALLOW_COPY_AND_ASSIGN(FrameTreeBrowserTest); 50 DISALLOW_COPY_AND_ASSIGN(FrameTreeBrowserTest);
42 }; 51 };
43 52
44 // Ensures FrameTree correctly reflects page structure during navigations. 53 // Ensures FrameTree correctly reflects page structure during navigations.
45 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, FrameTreeShape) { 54 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, FrameTreeShape) {
46 GURL base_url = embedded_test_server()->GetURL("A.com", "/site_isolation/"); 55 GURL base_url = embedded_test_server()->GetURL("A.com", "/site_isolation/");
47 56
48 // Load doc without iframes. Verify FrameTree just has root. 57 // Load doc without iframes. Verify FrameTree just has root.
49 // Frame tree: 58 // Frame tree:
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 GURL http_url(embedded_test_server()->GetURL("/title1.html")); 207 GURL http_url(embedded_test_server()->GetURL("/title1.html"));
199 NavigateFrameToURL(root->child_at(0), http_url); 208 NavigateFrameToURL(root->child_at(0), http_url);
200 EXPECT_TRUE( 209 EXPECT_TRUE(
201 root->current_frame_host()->render_view_host()->IsRenderViewLive()); 210 root->current_frame_host()->render_view_host()->IsRenderViewLive());
202 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); 211 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive());
203 EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive()); 212 EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive());
204 } 213 }
205 214
206 // Ensure that origins are correctly set on navigations. 215 // Ensure that origins are correctly set on navigations.
207 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, OriginSetOnNavigation) { 216 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, OriginSetOnNavigation) {
208 GURL main_url(embedded_test_server()->GetURL("/frame_tree/top.html")); 217 std::string scraped_origin;
218 GURL about_blank("about:blank");
219 GURL main_url(
220 embedded_test_server()->GetURL("a.com", "/frame_tree/top.html"));
209 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 221 EXPECT_TRUE(NavigateToURL(shell(), main_url));
222 WebContents* contents = shell()->web_contents();
210 223
211 // It is safe to obtain the root frame tree node here, as it doesn't change. 224 // It is safe to obtain the root frame tree node here, as it doesn't change.
212 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) 225 FrameTreeNode* root =
213 ->GetFrameTree()->root(); 226 static_cast<WebContentsImpl*>(contents)->GetFrameTree()->root();
214 227
215 // Extra '/' is added because the replicated origin is serialized in RFC 6454 228 // Extra '/' is added because the replicated origin is serialized in RFC 6454
216 // format, which dictates no trailing '/', whereas GURL::GetOrigin does put a 229 // format, which dictates no trailing '/', whereas GURL::GetOrigin does put a
217 // '/' at the end. 230 // '/' at the end.
218 EXPECT_EQ(root->current_replication_state().origin.Serialize() + '/', 231 EXPECT_EQ(main_url.GetOrigin().spec(),
219 main_url.GetOrigin().spec()); 232 root->current_replication_state().origin.Serialize() + '/');
220 233
221 GURL frame_url(embedded_test_server()->GetURL("/title1.html")); 234 // The origin is also exposed via the RenderFrameHost.
235 EXPECT_EQ(
236 main_url.GetOrigin().spec(),
237 contents->GetMainFrame()->GetLastCommittedOrigin().Serialize() + '/');
238 EXPECT_TRUE(
239 root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith(
240 root->child_at(0)->current_frame_host()->GetLastCommittedOrigin()));
241 EXPECT_EQ("a.com", GetEffectiveOriginFromRenderer(root));
242 EXPECT_EQ("a.com", GetEffectiveOriginFromRenderer(root->child_at(0)));
243
244 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html"));
222 NavigateFrameToURL(root->child_at(0), frame_url); 245 NavigateFrameToURL(root->child_at(0), frame_url);
246 EXPECT_EQ(root->child_at(0)->current_url(), frame_url);
247 EXPECT_EQ(
248 frame_url.GetOrigin().spec(),
249 root->child_at(0)->current_replication_state().origin.Serialize() + '/');
250 EXPECT_FALSE(
251 root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith(
252 root->child_at(0)->current_frame_host()->GetLastCommittedOrigin()));
253 EXPECT_EQ("a.com", GetEffectiveOriginFromRenderer(root));
254 EXPECT_EQ("b.com", GetEffectiveOriginFromRenderer(root->child_at(0)));
223 255
256 // Parent-initiated about:blank navigation should inherit the parent's a.com
257 // origin.
258 NavigateIframeToURL(contents, "1-1-id", about_blank);
259 EXPECT_EQ(root->child_at(0)->current_url(), about_blank);
224 EXPECT_EQ( 260 EXPECT_EQ(
225 root->child_at(0)->current_replication_state().origin.Serialize() + '/', 261 main_url.GetOrigin().spec(),
226 frame_url.GetOrigin().spec()); 262 root->child_at(0)->current_replication_state().origin.Serialize() + '/');
263 EXPECT_EQ(root->current_frame_host()->GetLastCommittedOrigin().Serialize(),
264 root->child_at(0)
265 ->current_frame_host()
266 ->GetLastCommittedOrigin()
267 .Serialize());
268 EXPECT_TRUE(
269 root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith(
270 root->child_at(0)->current_frame_host()->GetLastCommittedOrigin()));
271 EXPECT_EQ("a.com", GetEffectiveOriginFromRenderer(root->child_at(0)));
272 EXPECT_EQ("a.com", GetEffectiveOriginFromRenderer(root));
227 273
228 GURL data_url("data:text/html,foo"); 274 GURL data_url("data:text/html,foo");
229 EXPECT_TRUE(NavigateToURL(shell(), data_url)); 275 EXPECT_TRUE(NavigateToURL(shell(), data_url));
230 276
231 // Navigating to a data URL should set a unique origin. This is represented 277 // Navigating to a data URL should set a unique origin. This is represented
232 // as "null" per RFC 6454. 278 // as "null" per RFC 6454.
233 EXPECT_EQ(root->current_replication_state().origin.Serialize(), "null"); 279 EXPECT_EQ(root->current_replication_state().origin.Serialize(), "null");
280 EXPECT_TRUE(contents->GetMainFrame()->GetLastCommittedOrigin().unique());
281 EXPECT_EQ("", GetEffectiveOriginFromRenderer(root));
234 282
235 // Re-navigating to a normal URL should update the origin. 283 // Re-navigating to a normal URL should update the origin.
236 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 284 EXPECT_TRUE(NavigateToURL(shell(), main_url));
237 EXPECT_EQ(root->current_replication_state().origin.Serialize() + '/', 285 EXPECT_EQ(main_url.GetOrigin().spec(),
238 main_url.GetOrigin().spec()); 286 root->current_replication_state().origin.Serialize() + '/');
287 EXPECT_EQ(
288 main_url.GetOrigin().spec(),
289 contents->GetMainFrame()->GetLastCommittedOrigin().Serialize() + '/');
290 EXPECT_FALSE(contents->GetMainFrame()->GetLastCommittedOrigin().unique());
291 EXPECT_EQ("a.com", GetEffectiveOriginFromRenderer(root));
239 } 292 }
240 293
241 // Ensure that sandbox flags are correctly set when child frames are created. 294 // Ensure that sandbox flags are correctly set when child frames are created.
242 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, SandboxFlagsSetForChildFrames) { 295 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, SandboxFlagsSetForChildFrames) {
243 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html")); 296 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html"));
244 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 297 EXPECT_TRUE(NavigateToURL(shell(), main_url));
245 298
246 // It is safe to obtain the root frame tree node here, as it doesn't change. 299 // It is safe to obtain the root frame tree node here, as it doesn't change.
247 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) 300 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
248 ->GetFrameTree()->root(); 301 ->GetFrameTree()->root();
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 GURL data_url("data:text/html,foo"); 477 GURL data_url("data:text/html,foo");
425 NavigateFrameToURL(root->child_at(1), data_url); 478 NavigateFrameToURL(root->child_at(1), data_url);
426 479
427 // Navigating to a data URL should set a unique origin. This is represented 480 // Navigating to a data URL should set a unique origin. This is represented
428 // as "null" per RFC 6454. 481 // as "null" per RFC 6454.
429 EXPECT_EQ(root->child_at(1)->current_replication_state().origin.Serialize(), 482 EXPECT_EQ(root->child_at(1)->current_replication_state().origin.Serialize(),
430 "null"); 483 "null");
431 } 484 }
432 485
433 } // namespace content 486 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698