OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "content/browser/renderer_host/frame_tree.h" | |
8 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
9 #include "content/public/browser/notification_observer.h" | 10 #include "content/public/browser/notification_observer.h" |
10 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
11 #include "content/public/browser/notification_types.h" | 12 #include "content/public/browser/notification_types.h" |
12 #include "content/public/browser/web_contents_observer.h" | 13 #include "content/public/browser/web_contents_observer.h" |
13 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
14 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
15 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
16 #include "content/shell/browser/shell.h" | 17 #include "content/shell/browser/shell.h" |
17 #include "content/test/content_browser_test.h" | 18 #include "content/test/content_browser_test.h" |
18 #include "content/test/content_browser_test_utils.h" | 19 #include "content/test/content_browser_test_utils.h" |
20 #include "net/dns/mock_host_resolver.h" | |
19 | 21 |
20 namespace content { | 22 namespace content { |
21 | 23 |
22 class SitePerProcessWebContentsObserver: public WebContentsObserver { | 24 class SitePerProcessWebContentsObserver: public WebContentsObserver { |
23 public: | 25 public: |
24 explicit SitePerProcessWebContentsObserver(WebContents* web_contents) | 26 explicit SitePerProcessWebContentsObserver(WebContents* web_contents) |
25 : WebContentsObserver(web_contents), | 27 : WebContentsObserver(web_contents), |
26 navigation_succeeded_(true) {} | 28 navigation_succeeded_(true) {} |
27 virtual ~SitePerProcessWebContentsObserver() {} | 29 virtual ~SitePerProcessWebContentsObserver() {} |
28 | 30 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 seen_twice_ = seen_; | 134 seen_twice_ = seen_; |
133 seen_ = true; | 135 seen_ = true; |
134 if (!running_) | 136 if (!running_) |
135 return; | 137 return; |
136 | 138 |
137 message_loop_runner_->Quit(); | 139 message_loop_runner_->Quit(); |
138 running_ = false; | 140 running_ = false; |
139 } | 141 } |
140 | 142 |
141 class SitePerProcessBrowserTest : public ContentBrowserTest { | 143 class SitePerProcessBrowserTest : public ContentBrowserTest { |
142 public: | 144 protected: |
143 SitePerProcessBrowserTest() {} | |
144 | |
145 bool NavigateIframeToURL(Shell* window, | 145 bool NavigateIframeToURL(Shell* window, |
146 const GURL& url, | 146 const GURL& url, |
147 std::string iframe_id) { | 147 std::string iframe_id) { |
148 std::string script = base::StringPrintf( | 148 std::string script = base::StringPrintf( |
149 "var iframes = document.getElementById('%s');iframes.src='%s';", | 149 "var iframes = document.getElementById('%s');iframes.src='%s';", |
150 iframe_id.c_str(), url.spec().c_str()); | 150 iframe_id.c_str(), url.spec().c_str()); |
151 WindowedNotificationObserver load_observer( | 151 WindowedNotificationObserver load_observer( |
152 NOTIFICATION_LOAD_STOP, | 152 NOTIFICATION_LOAD_STOP, |
153 Source<NavigationController>( | 153 Source<NavigationController>( |
154 &shell()->web_contents()->GetController())); | 154 &shell()->web_contents()->GetController())); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 GURL server_redirect_http_url(test_server()->GetURL( | 392 GURL server_redirect_http_url(test_server()->GetURL( |
393 "server-redirect?" + client_redirect_http_url.spec())); | 393 "server-redirect?" + client_redirect_http_url.spec())); |
394 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); | 394 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); |
395 | 395 |
396 // DidFailProvisionalLoad when navigating to client_redirect_http_url. | 396 // DidFailProvisionalLoad when navigating to client_redirect_http_url. |
397 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); | 397 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
398 EXPECT_FALSE(observer.navigation_succeeded()); | 398 EXPECT_FALSE(observer.navigation_succeeded()); |
399 } | 399 } |
400 } | 400 } |
401 | 401 |
402 // Ensures FrameTree correctly reflects page structure during navigations. | |
403 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
404 FrameTreeShape) { | |
405 host_resolver()->AddRule("*", "127.0.0.1"); | |
406 ASSERT_TRUE(test_server()->Start()); | |
407 | |
408 GURL base_url = test_server()->GetURL("files/site_isolation/"); | |
409 GURL::Replacements replace_host; | |
410 std::string host_str("A.com"); // Must stay in scope with replace_host. | |
411 replace_host.SetHostStr(host_str); | |
412 base_url = base_url.ReplaceComponents(replace_host); | |
413 | |
414 // Load doc without iframes. Verify FrameTree just has root. | |
415 // Frame tree: | |
416 // Site-A Root | |
417 NavigateToURL(shell(), base_url.Resolve("blank.html")); | |
418 FrameTreeNode* root = | |
419 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
420 GetFrameTree()->GetRootForTesting(); | |
421 EXPECT_EQ(0U, root->child_count()); | |
422 | |
423 // Add 2 same-site frames. Verify 3 nodes in tree with proper names. | |
424 // Frame tree: | |
425 // Site-A Root -- Site-A frame1 | |
426 // \-- Site-A frame2 | |
427 WindowedNotificationObserver observer1( | |
428 content::NOTIFICATION_LOAD_STOP, | |
429 content::Source<NavigationController>( | |
430 &shell()->web_contents()->GetController())); | |
431 NavigateToURL(shell(), base_url.Resolve("frames-X-X.html")); | |
432 observer1.Wait(); | |
433 ASSERT_EQ(2U, root->child_count()); | |
434 EXPECT_EQ(0U, root->child_at(0)->child_count()); | |
435 EXPECT_EQ(0U, root->child_at(1)->child_count()); | |
436 | |
437 /* | |
438 // nav second frame cross-site document also having 2 frames. Verify 5 nodes | |
Charlie Reis
2013/09/27 19:19:21
If we want to move forward with this CL, let's rem
awong
2013/09/27 20:50:09
Done.
| |
439 // in tree with proper names. | |
440 // Frame tree: | |
441 // Site-A Root -- Site-A frame1 | |
442 // \-- Site-B frame2 -- SiteB frame1 | |
443 // \-- SiteB frame2 | |
444 NavigateToURL(shell(), base_url.Resolve("frames-A-B_0_B-B.html")); | |
445 WindowedNotificationObserver observer2( | |
446 content::NOTIFICATION_LOAD_STOP, | |
447 content::Source<NavigationController>( | |
448 &shell()->web_contents()->GetController())); | |
449 ASSERT_TRUE(ExecuteScriptInFrame(shell()->web_contents(), "/iframe[1]", | |
450 | |
451 "var site_b_base = 'http://B.com:' + document.loca tion.port;" | |
452 " document.getElementById('frame-2').src =" | |
453 " site_b_base + '/files/site_isolation/frames-X-X.html';")); | |
454 observer2.Wait(); | |
455 ASSERT_EQ(2U, root->child_count()); | |
456 EXPECT_EQ(0U, root->child_at(0)->child_count()); | |
457 ASSERT_EQ(2U, root->child_at(1)->child_count()); | |
458 ASSERT_EQ(0U, root->child_at(1)->child_at(0)->child_count()); | |
459 EXPECT_EQ(0U, root->child_at(1)->child_at(1)->child_count()); | |
460 | |
461 // nav second frame in cross-side document having. | |
462 // How to trigger? Maybe just nav it to a page with a same-site frame? | |
463 // Frame tree: | |
464 // Site-A Root -- Site-A frame1 | |
465 // \-- Site-B frame2 -- SiteA frame1 | |
466 // \-- SiteB frame2 | |
467 NavigateToURL(shell(), base_url.Resolve("frames-A-B_0_A-B.html")); | |
468 ASSERT_EQ(2U, root->child_count()); | |
469 EXPECT_EQ(0U, root->child_at(0)->child_count()); | |
470 ASSERT_EQ(2U, root->child_at(1)->child_count()); | |
471 ASSERT_EQ(0U, root->child_at(1)->child_at(0)->child_count()); | |
472 EXPECT_EQ(0U, root->child_at(1)->child_at(1)->child_count()); | |
473 */ | |
402 } | 474 } |
475 | |
476 } // namespace content | |
OLD | NEW |