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

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: Alexmos's fixes. 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 GetOriginFromRenderer(FrameTreeNode* node) {
42 std::string origin;
43 EXPECT_TRUE(ExecuteScriptAndExtractString(
44 node->current_frame_host(),
45 "window.domAutomationController.send(document.origin);", &origin));
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 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.
218 GURL main_url(
219 embedded_test_server()->GetURL("a.com", "/frame_tree/top.html"));
209 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 220 EXPECT_TRUE(NavigateToURL(shell(), main_url));
221 WebContents* contents = shell()->web_contents();
210 222
211 // It is safe to obtain the root frame tree node here, as it doesn't change. 223 // 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()) 224 FrameTreeNode* root =
213 ->GetFrameTree()->root(); 225 static_cast<WebContentsImpl*>(contents)->GetFrameTree()->root();
214 226
215 // Extra '/' is added because the replicated origin is serialized in RFC 6454 227 // Extra '/' is added because the replicated origin is serialized in RFC 6454
216 // format, which dictates no trailing '/', whereas GURL::GetOrigin does put a 228 // format, which dictates no trailing '/', whereas GURL::GetOrigin does put a
217 // '/' at the end. 229 // '/' at the end.
218 EXPECT_EQ(root->current_origin().Serialize() + '/', 230 EXPECT_EQ(main_url.GetOrigin().spec(),
219 main_url.GetOrigin().spec()); 231 root->current_origin().Serialize() + '/');
220 232
221 GURL frame_url(embedded_test_server()->GetURL("/title1.html")); 233 // The origin is also exposed via the RenderFrameHost.
234 EXPECT_EQ(
235 main_url.GetOrigin().spec(),
236 root->current_frame_host()->GetLastCommittedOrigin().Serialize() + '/');
237 EXPECT_TRUE(
238 root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith(
239 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.
240 EXPECT_EQ(root->current_origin().Serialize(), GetOriginFromRenderer(root));
241 EXPECT_EQ(root->child_at(0)->current_origin().Serialize(),
242 GetOriginFromRenderer(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);
Charlie Reis 2015/11/24 21:00:42 nit: Swap order (expected, actual).
ncarter (slow) 2015/11/24 22:07:33 Done.
247 EXPECT_EQ(frame_url.GetOrigin().spec(),
248 root->child_at(0)->current_origin().Serialize() + '/');
249 EXPECT_FALSE(
250 root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith(
251 root->child_at(0)->current_frame_host()->GetLastCommittedOrigin()));
252 EXPECT_EQ(root->current_origin().Serialize(), GetOriginFromRenderer(root));
253 EXPECT_EQ(root->child_at(0)->current_origin().Serialize(),
254 GetOriginFromRenderer(root->child_at(0)));
223 255
224 EXPECT_EQ(root->child_at(0)->current_origin().Serialize() + '/', 256 // Parent-initiated about:blank navigation should inherit the parent's a.com
225 frame_url.GetOrigin().spec()); 257 // origin.
258 NavigateIframeToURL(contents, "1-1-id", about_blank);
259 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.
260 EXPECT_EQ(main_url.GetOrigin().spec(),
261 root->child_at(0)->current_origin().Serialize() + '/');
262 EXPECT_EQ(root->current_frame_host()->GetLastCommittedOrigin().Serialize(),
263 root->child_at(0)
264 ->current_frame_host()
265 ->GetLastCommittedOrigin()
266 .Serialize());
267 EXPECT_TRUE(
268 root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith(
269 root->child_at(0)->current_frame_host()->GetLastCommittedOrigin()));
270 EXPECT_EQ(root->current_origin().Serialize(), GetOriginFromRenderer(root));
271 EXPECT_EQ(root->child_at(0)->current_origin().Serialize(),
272 GetOriginFromRenderer(root->child_at(0)));
226 273
227 GURL data_url("data:text/html,foo"); 274 GURL data_url("data:text/html,foo");
228 EXPECT_TRUE(NavigateToURL(shell(), data_url)); 275 EXPECT_TRUE(NavigateToURL(shell(), data_url));
229 276
230 // 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
231 // as "null" per RFC 6454. 278 // as "null" per RFC 6454.
232 EXPECT_EQ(root->current_origin().Serialize(), "null"); 279 EXPECT_EQ("null", root->current_origin().Serialize());
280 EXPECT_TRUE(contents->GetMainFrame()->GetLastCommittedOrigin().unique());
281 EXPECT_EQ("null", GetOriginFromRenderer(root));
233 282
234 // Re-navigating to a normal URL should update the origin. 283 // Re-navigating to a normal URL should update the origin.
235 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 284 EXPECT_TRUE(NavigateToURL(shell(), main_url));
236 EXPECT_EQ(root->current_origin().Serialize() + '/', 285 EXPECT_EQ(main_url.GetOrigin().spec(),
237 main_url.GetOrigin().spec()); 286 root->current_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(root->current_origin().Serialize(), GetOriginFromRenderer(root));
238 } 292 }
239 293
240 // 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.
241 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, SandboxFlagsSetForChildFrames) { 295 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, SandboxFlagsSetForChildFrames) {
242 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html")); 296 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html"));
243 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 297 EXPECT_TRUE(NavigateToURL(shell(), main_url));
244 298
245 // 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.
246 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) 300 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
247 ->GetFrameTree()->root(); 301 ->GetFrameTree()->root();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 470
417 GURL data_url("data:text/html,foo"); 471 GURL data_url("data:text/html,foo");
418 NavigateFrameToURL(root->child_at(1), data_url); 472 NavigateFrameToURL(root->child_at(1), data_url);
419 473
420 // Navigating to a data URL should set a unique origin. This is represented 474 // Navigating to a data URL should set a unique origin. This is represented
421 // as "null" per RFC 6454. 475 // as "null" per RFC 6454.
422 EXPECT_EQ(root->child_at(1)->current_origin().Serialize(), "null"); 476 EXPECT_EQ(root->child_at(1)->current_origin().Serialize(), "null");
423 } 477 }
424 478
425 } // namespace content 479 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698