OLD | NEW |
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" |
11 #include "content/public/common/url_constants.h" | 11 #include "content/public/common/url_constants.h" |
12 #include "content/public/test/browser_test_utils.h" | 12 #include "content/public/test/browser_test_utils.h" |
13 #include "content/public/test/content_browser_test.h" | 13 #include "content/public/test/content_browser_test.h" |
14 #include "content/public/test/content_browser_test_utils.h" | 14 #include "content/public/test/content_browser_test_utils.h" |
15 #include "content/public/test/test_navigation_observer.h" | 15 #include "content/public/test/test_navigation_observer.h" |
16 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
17 #include "content/shell/browser/shell.h" | 17 #include "content/shell/browser/shell.h" |
18 #include "content/test/content_browser_test_utils_internal.h" | 18 #include "content/test/content_browser_test_utils_internal.h" |
19 #include "net/dns/mock_host_resolver.h" | 19 #include "net/dns/mock_host_resolver.h" |
20 #include "net/test/embedded_test_server/embedded_test_server.h" | 20 #include "net/test/embedded_test_server/embedded_test_server.h" |
21 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 21 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
| 22 #include "url/url_constants.h" |
22 | 23 |
23 // For fine-grained suppression on flaky tests. | 24 // For fine-grained suppression on flaky tests. |
24 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
25 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
26 #endif | 27 #endif |
27 | 28 |
28 namespace content { | 29 namespace content { |
29 | 30 |
30 class FrameTreeBrowserTest : public ContentBrowserTest { | 31 class FrameTreeBrowserTest : public ContentBrowserTest { |
31 public: | 32 public: |
32 FrameTreeBrowserTest() {} | 33 FrameTreeBrowserTest() {} |
33 | 34 |
34 void SetUpOnMainThread() override { | 35 void SetUpOnMainThread() override { |
35 host_resolver()->AddRule("*", "127.0.0.1"); | 36 host_resolver()->AddRule("*", "127.0.0.1"); |
36 ASSERT_TRUE(embedded_test_server()->Start()); | 37 ASSERT_TRUE(embedded_test_server()->Start()); |
37 SetupCrossSiteRedirector(embedded_test_server()); | 38 SetupCrossSiteRedirector(embedded_test_server()); |
38 } | 39 } |
39 | 40 |
| 41 protected: |
| 42 std::string GetOriginFromRenderer(FrameTreeNode* node) { |
| 43 std::string origin; |
| 44 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 45 node->current_frame_host(), |
| 46 "window.domAutomationController.send(document.origin);", &origin)); |
| 47 return origin; |
| 48 } |
| 49 |
40 private: | 50 private: |
41 DISALLOW_COPY_AND_ASSIGN(FrameTreeBrowserTest); | 51 DISALLOW_COPY_AND_ASSIGN(FrameTreeBrowserTest); |
42 }; | 52 }; |
43 | 53 |
44 // Ensures FrameTree correctly reflects page structure during navigations. | 54 // Ensures FrameTree correctly reflects page structure during navigations. |
45 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, FrameTreeShape) { | 55 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, FrameTreeShape) { |
46 GURL base_url = embedded_test_server()->GetURL("A.com", "/site_isolation/"); | 56 GURL base_url = embedded_test_server()->GetURL("A.com", "/site_isolation/"); |
47 | 57 |
48 // Load doc without iframes. Verify FrameTree just has root. | 58 // Load doc without iframes. Verify FrameTree just has root. |
49 // Frame tree: | 59 // Frame tree: |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 GURL http_url(embedded_test_server()->GetURL("/title1.html")); | 208 GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
199 NavigateFrameToURL(root->child_at(0), http_url); | 209 NavigateFrameToURL(root->child_at(0), http_url); |
200 EXPECT_TRUE( | 210 EXPECT_TRUE( |
201 root->current_frame_host()->render_view_host()->IsRenderViewLive()); | 211 root->current_frame_host()->render_view_host()->IsRenderViewLive()); |
202 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); | 212 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); |
203 EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive()); | 213 EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive()); |
204 } | 214 } |
205 | 215 |
206 // Ensure that origins are correctly set on navigations. | 216 // Ensure that origins are correctly set on navigations. |
207 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, OriginSetOnNavigation) { | 217 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, OriginSetOnNavigation) { |
208 GURL main_url(embedded_test_server()->GetURL("/frame_tree/top.html")); | 218 GURL about_blank(url::kAboutBlankURL); |
| 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_origin().Serialize() + '/', | 231 EXPECT_EQ(main_url.GetOrigin().spec(), |
219 main_url.GetOrigin().spec()); | 232 root->current_origin().Serialize() + '/'); |
| 233 EXPECT_EQ( |
| 234 main_url.GetOrigin().spec(), |
| 235 root->current_frame_host()->GetLastCommittedOrigin().Serialize() + '/'); |
220 | 236 |
221 GURL frame_url(embedded_test_server()->GetURL("/title1.html")); | 237 // The iframe is inititially same-origin. |
| 238 EXPECT_TRUE( |
| 239 root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( |
| 240 root->child_at(0)->current_frame_host()->GetLastCommittedOrigin())); |
| 241 EXPECT_EQ(root->current_origin().Serialize(), GetOriginFromRenderer(root)); |
| 242 EXPECT_EQ(root->child_at(0)->current_origin().Serialize(), |
| 243 GetOriginFromRenderer(root->child_at(0))); |
| 244 |
| 245 // Navigate the iframe cross-origin. |
| 246 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
222 NavigateFrameToURL(root->child_at(0), frame_url); | 247 NavigateFrameToURL(root->child_at(0), frame_url); |
| 248 EXPECT_EQ(frame_url, root->child_at(0)->current_url()); |
| 249 EXPECT_EQ(frame_url.GetOrigin().spec(), |
| 250 root->child_at(0)->current_origin().Serialize() + '/'); |
| 251 EXPECT_FALSE( |
| 252 root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( |
| 253 root->child_at(0)->current_frame_host()->GetLastCommittedOrigin())); |
| 254 EXPECT_EQ(root->current_origin().Serialize(), GetOriginFromRenderer(root)); |
| 255 EXPECT_EQ(root->child_at(0)->current_origin().Serialize(), |
| 256 GetOriginFromRenderer(root->child_at(0))); |
223 | 257 |
224 EXPECT_EQ(root->child_at(0)->current_origin().Serialize() + '/', | 258 // Parent-initiated about:blank navigation should inherit the parent's a.com |
225 frame_url.GetOrigin().spec()); | 259 // origin. |
| 260 NavigateIframeToURL(contents, "1-1-id", about_blank); |
| 261 EXPECT_EQ(about_blank, root->child_at(0)->current_url()); |
| 262 EXPECT_EQ(main_url.GetOrigin().spec(), |
| 263 root->child_at(0)->current_origin().Serialize() + '/'); |
| 264 EXPECT_EQ(root->current_frame_host()->GetLastCommittedOrigin().Serialize(), |
| 265 root->child_at(0) |
| 266 ->current_frame_host() |
| 267 ->GetLastCommittedOrigin() |
| 268 .Serialize()); |
| 269 EXPECT_TRUE( |
| 270 root->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( |
| 271 root->child_at(0)->current_frame_host()->GetLastCommittedOrigin())); |
| 272 EXPECT_EQ(root->current_origin().Serialize(), GetOriginFromRenderer(root)); |
| 273 EXPECT_EQ(root->child_at(0)->current_origin().Serialize(), |
| 274 GetOriginFromRenderer(root->child_at(0))); |
226 | 275 |
227 GURL data_url("data:text/html,foo"); | 276 GURL data_url("data:text/html,foo"); |
228 EXPECT_TRUE(NavigateToURL(shell(), data_url)); | 277 EXPECT_TRUE(NavigateToURL(shell(), data_url)); |
229 | 278 |
230 // Navigating to a data URL should set a unique origin. This is represented | 279 // Navigating to a data URL should set a unique origin. This is represented |
231 // as "null" per RFC 6454. | 280 // as "null" per RFC 6454. |
232 EXPECT_EQ(root->current_origin().Serialize(), "null"); | 281 EXPECT_EQ("null", root->current_origin().Serialize()); |
| 282 EXPECT_TRUE(contents->GetMainFrame()->GetLastCommittedOrigin().unique()); |
| 283 EXPECT_EQ("null", GetOriginFromRenderer(root)); |
233 | 284 |
234 // Re-navigating to a normal URL should update the origin. | 285 // Re-navigating to a normal URL should update the origin. |
235 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 286 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
236 EXPECT_EQ(root->current_origin().Serialize() + '/', | 287 EXPECT_EQ(main_url.GetOrigin().spec(), |
237 main_url.GetOrigin().spec()); | 288 root->current_origin().Serialize() + '/'); |
| 289 EXPECT_EQ( |
| 290 main_url.GetOrigin().spec(), |
| 291 contents->GetMainFrame()->GetLastCommittedOrigin().Serialize() + '/'); |
| 292 EXPECT_FALSE(contents->GetMainFrame()->GetLastCommittedOrigin().unique()); |
| 293 EXPECT_EQ(root->current_origin().Serialize(), GetOriginFromRenderer(root)); |
238 } | 294 } |
239 | 295 |
240 // Ensure that sandbox flags are correctly set when child frames are created. | 296 // Ensure that sandbox flags are correctly set when child frames are created. |
241 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, SandboxFlagsSetForChildFrames) { | 297 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, SandboxFlagsSetForChildFrames) { |
242 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html")); | 298 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html")); |
243 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 299 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
244 | 300 |
245 // It is safe to obtain the root frame tree node here, as it doesn't change. | 301 // 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()) | 302 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
247 ->GetFrameTree()->root(); | 303 ->GetFrameTree()->root(); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 | 472 |
417 GURL data_url("data:text/html,foo"); | 473 GURL data_url("data:text/html,foo"); |
418 NavigateFrameToURL(root->child_at(1), data_url); | 474 NavigateFrameToURL(root->child_at(1), data_url); |
419 | 475 |
420 // Navigating to a data URL should set a unique origin. This is represented | 476 // Navigating to a data URL should set a unique origin. This is represented |
421 // as "null" per RFC 6454. | 477 // as "null" per RFC 6454. |
422 EXPECT_EQ(root->child_at(1)->current_origin().Serialize(), "null"); | 478 EXPECT_EQ(root->child_at(1)->current_origin().Serialize(), "null"); |
423 } | 479 } |
424 | 480 |
425 } // namespace content | 481 } // namespace content |
OLD | NEW |