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" |
| 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
8 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
9 #include "content/public/browser/notification_observer.h" | 11 #include "content/public/browser/notification_observer.h" |
10 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
11 #include "content/public/browser/notification_types.h" | 13 #include "content/public/browser/notification_types.h" |
12 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
13 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
14 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
15 #include "content/public/test/test_utils.h" | 17 #include "content/public/test/test_utils.h" |
16 #include "content/shell/browser/shell.h" | 18 #include "content/shell/browser/shell.h" |
17 #include "content/test/content_browser_test.h" | 19 #include "content/test/content_browser_test.h" |
18 #include "content/test/content_browser_test_utils.h" | 20 #include "content/test/content_browser_test_utils.h" |
| 21 #include "net/dns/mock_host_resolver.h" |
19 | 22 |
20 namespace content { | 23 namespace content { |
21 | 24 |
22 class SitePerProcessWebContentsObserver: public WebContentsObserver { | 25 class SitePerProcessWebContentsObserver: public WebContentsObserver { |
23 public: | 26 public: |
24 explicit SitePerProcessWebContentsObserver(WebContents* web_contents) | 27 explicit SitePerProcessWebContentsObserver(WebContents* web_contents) |
25 : WebContentsObserver(web_contents), | 28 : WebContentsObserver(web_contents), |
26 navigation_succeeded_(true) {} | 29 navigation_succeeded_(true) {} |
27 virtual ~SitePerProcessWebContentsObserver() {} | 30 virtual ~SitePerProcessWebContentsObserver() {} |
28 | 31 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 seen_twice_ = seen_; | 135 seen_twice_ = seen_; |
133 seen_ = true; | 136 seen_ = true; |
134 if (!running_) | 137 if (!running_) |
135 return; | 138 return; |
136 | 139 |
137 message_loop_runner_->Quit(); | 140 message_loop_runner_->Quit(); |
138 running_ = false; | 141 running_ = false; |
139 } | 142 } |
140 | 143 |
141 class SitePerProcessBrowserTest : public ContentBrowserTest { | 144 class SitePerProcessBrowserTest : public ContentBrowserTest { |
142 public: | 145 protected: |
143 SitePerProcessBrowserTest() {} | |
144 | |
145 bool NavigateIframeToURL(Shell* window, | 146 bool NavigateIframeToURL(Shell* window, |
146 const GURL& url, | 147 const GURL& url, |
147 std::string iframe_id) { | 148 std::string iframe_id) { |
148 std::string script = base::StringPrintf( | 149 std::string script = base::StringPrintf( |
149 "var iframes = document.getElementById('%s');iframes.src='%s';", | 150 "var iframes = document.getElementById('%s');iframes.src='%s';", |
150 iframe_id.c_str(), url.spec().c_str()); | 151 iframe_id.c_str(), url.spec().c_str()); |
151 WindowedNotificationObserver load_observer( | 152 WindowedNotificationObserver load_observer( |
152 NOTIFICATION_LOAD_STOP, | 153 NOTIFICATION_LOAD_STOP, |
153 Source<NavigationController>( | 154 Source<NavigationController>( |
154 &shell()->web_contents()->GetController())); | 155 &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( | 393 GURL server_redirect_http_url(test_server()->GetURL( |
393 "server-redirect?" + client_redirect_http_url.spec())); | 394 "server-redirect?" + client_redirect_http_url.spec())); |
394 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); | 395 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); |
395 | 396 |
396 // DidFailProvisionalLoad when navigating to client_redirect_http_url. | 397 // DidFailProvisionalLoad when navigating to client_redirect_http_url. |
397 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); | 398 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
398 EXPECT_FALSE(observer.navigation_succeeded()); | 399 EXPECT_FALSE(observer.navigation_succeeded()); |
399 } | 400 } |
400 } | 401 } |
401 | 402 |
| 403 // Ensures FrameTree correctly reflects page structure during navigations. |
| 404 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 405 FrameTreeShape) { |
| 406 host_resolver()->AddRule("*", "127.0.0.1"); |
| 407 ASSERT_TRUE(test_server()->Start()); |
| 408 |
| 409 GURL base_url = test_server()->GetURL("files/site_isolation/"); |
| 410 GURL::Replacements replace_host; |
| 411 std::string host_str("A.com"); // Must stay in scope with replace_host. |
| 412 replace_host.SetHostStr(host_str); |
| 413 base_url = base_url.ReplaceComponents(replace_host); |
| 414 |
| 415 // Load doc without iframes. Verify FrameTree just has root. |
| 416 // Frame tree: |
| 417 // Site-A Root |
| 418 NavigateToURL(shell(), base_url.Resolve("blank.html")); |
| 419 FrameTreeNode* root = |
| 420 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 421 GetFrameTree()->GetRootForTesting(); |
| 422 EXPECT_EQ(0U, root->child_count()); |
| 423 |
| 424 // Add 2 same-site frames. Verify 3 nodes in tree with proper names. |
| 425 // Frame tree: |
| 426 // Site-A Root -- Site-A frame1 |
| 427 // \-- Site-A frame2 |
| 428 WindowedNotificationObserver observer1( |
| 429 content::NOTIFICATION_LOAD_STOP, |
| 430 content::Source<NavigationController>( |
| 431 &shell()->web_contents()->GetController())); |
| 432 NavigateToURL(shell(), base_url.Resolve("frames-X-X.html")); |
| 433 observer1.Wait(); |
| 434 ASSERT_EQ(2U, root->child_count()); |
| 435 EXPECT_EQ(0U, root->child_at(0)->child_count()); |
| 436 EXPECT_EQ(0U, root->child_at(1)->child_count()); |
402 } | 437 } |
| 438 |
| 439 // TODO(ajwong): Talk with nasko and merge this functionality with |
| 440 // FrameTreeShape. |
| 441 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 442 FrameTreeShape2) { |
| 443 host_resolver()->AddRule("*", "127.0.0.1"); |
| 444 ASSERT_TRUE(test_server()->Start()); |
| 445 |
| 446 NavigateToURL(shell(), |
| 447 test_server()->GetURL("files/frame_tree/top.html")); |
| 448 |
| 449 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 450 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 451 wc->GetRenderViewHost()); |
| 452 FrameTreeNode* root = wc->GetFrameTree()->GetRootForTesting(); |
| 453 |
| 454 // Check that the root node is properly created with the frame id of the |
| 455 // initial navigation. |
| 456 ASSERT_EQ(3UL, root->child_count()); |
| 457 EXPECT_EQ(std::string(), root->frame_name()); |
| 458 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); |
| 459 |
| 460 ASSERT_EQ(2UL, root->child_at(0)->child_count()); |
| 461 EXPECT_STREQ("1-1-name", root->child_at(0)->frame_name().c_str()); |
| 462 |
| 463 // Verify the deepest node exists and has the right name. |
| 464 ASSERT_EQ(2UL, root->child_at(2)->child_count()); |
| 465 EXPECT_EQ(1UL, root->child_at(2)->child_at(1)->child_count()); |
| 466 EXPECT_EQ(0UL, root->child_at(2)->child_at(1)->child_at(0)->child_count()); |
| 467 EXPECT_STREQ("3-1-id", |
| 468 root->child_at(2)->child_at(1)->child_at(0)->frame_name().c_str()); |
| 469 |
| 470 // Navigate to about:blank, which should leave only the root node of the frame |
| 471 // tree in the browser process. |
| 472 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); |
| 473 |
| 474 root = wc->GetFrameTree()->GetRootForTesting(); |
| 475 EXPECT_EQ(0UL, root->child_count()); |
| 476 EXPECT_EQ(std::string(), root->frame_name()); |
| 477 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); |
| 478 } |
| 479 |
| 480 } // namespace content |
OLD | NEW |