| 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/frame_host/frame_tree.h" | 8 #include "content/browser/frame_host/frame_tree.h" |
| 9 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 GURL server_redirect_http_url(test_server()->GetURL( | 413 GURL server_redirect_http_url(test_server()->GetURL( |
| 414 "server-redirect?" + client_redirect_http_url.spec())); | 414 "server-redirect?" + client_redirect_http_url.spec())); |
| 415 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); | 415 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); |
| 416 | 416 |
| 417 // DidFailProvisionalLoad when navigating to client_redirect_http_url. | 417 // DidFailProvisionalLoad when navigating to client_redirect_http_url. |
| 418 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); | 418 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
| 419 EXPECT_FALSE(observer.navigation_succeeded()); | 419 EXPECT_FALSE(observer.navigation_succeeded()); |
| 420 } | 420 } |
| 421 } | 421 } |
| 422 | 422 |
| 423 // Ensures FrameTree correctly reflects page structure during navigations. | |
| 424 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
| 425 FrameTreeShape) { | |
| 426 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 427 ASSERT_TRUE(test_server()->Start()); | |
| 428 | |
| 429 GURL base_url = test_server()->GetURL("files/site_isolation/"); | |
| 430 GURL::Replacements replace_host; | |
| 431 std::string host_str("A.com"); // Must stay in scope with replace_host. | |
| 432 replace_host.SetHostStr(host_str); | |
| 433 base_url = base_url.ReplaceComponents(replace_host); | |
| 434 | |
| 435 // Load doc without iframes. Verify FrameTree just has root. | |
| 436 // Frame tree: | |
| 437 // Site-A Root | |
| 438 NavigateToURL(shell(), base_url.Resolve("blank.html")); | |
| 439 FrameTreeNode* root = | |
| 440 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
| 441 GetFrameTree()->root(); | |
| 442 EXPECT_EQ(0U, root->child_count()); | |
| 443 | |
| 444 // Add 2 same-site frames. Verify 3 nodes in tree with proper names. | |
| 445 // Frame tree: | |
| 446 // Site-A Root -- Site-A frame1 | |
| 447 // \-- Site-A frame2 | |
| 448 WindowedNotificationObserver observer1( | |
| 449 content::NOTIFICATION_LOAD_STOP, | |
| 450 content::Source<NavigationController>( | |
| 451 &shell()->web_contents()->GetController())); | |
| 452 NavigateToURL(shell(), base_url.Resolve("frames-X-X.html")); | |
| 453 observer1.Wait(); | |
| 454 ASSERT_EQ(2U, root->child_count()); | |
| 455 EXPECT_EQ(0U, root->child_at(0)->child_count()); | |
| 456 EXPECT_EQ(0U, root->child_at(1)->child_count()); | |
| 457 } | |
| 458 | |
| 459 // TODO(ajwong): Talk with nasko and merge this functionality with | |
| 460 // FrameTreeShape. | |
| 461 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
| 462 FrameTreeShape2) { | |
| 463 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 464 ASSERT_TRUE(test_server()->Start()); | |
| 465 | |
| 466 NavigateToURL(shell(), | |
| 467 test_server()->GetURL("files/frame_tree/top.html")); | |
| 468 | |
| 469 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | |
| 470 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
| 471 wc->GetRenderViewHost()); | |
| 472 FrameTreeNode* root = wc->GetFrameTree()->root(); | |
| 473 | |
| 474 // Check that the root node is properly created with the frame id of the | |
| 475 // initial navigation. | |
| 476 ASSERT_EQ(3UL, root->child_count()); | |
| 477 EXPECT_EQ(std::string(), root->frame_name()); | |
| 478 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | |
| 479 | |
| 480 ASSERT_EQ(2UL, root->child_at(0)->child_count()); | |
| 481 EXPECT_STREQ("1-1-name", root->child_at(0)->frame_name().c_str()); | |
| 482 | |
| 483 // Verify the deepest node exists and has the right name. | |
| 484 ASSERT_EQ(2UL, root->child_at(2)->child_count()); | |
| 485 EXPECT_EQ(1UL, root->child_at(2)->child_at(1)->child_count()); | |
| 486 EXPECT_EQ(0UL, root->child_at(2)->child_at(1)->child_at(0)->child_count()); | |
| 487 EXPECT_STREQ("3-1-id", | |
| 488 root->child_at(2)->child_at(1)->child_at(0)->frame_name().c_str()); | |
| 489 | |
| 490 // Navigate to about:blank, which should leave only the root node of the frame | |
| 491 // tree in the browser process. | |
| 492 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); | |
| 493 | |
| 494 root = wc->GetFrameTree()->root(); | |
| 495 EXPECT_EQ(0UL, root->child_count()); | |
| 496 EXPECT_EQ(std::string(), root->frame_name()); | |
| 497 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | |
| 498 } | |
| 499 | |
| 500 // Tests that the |should_replace_current_entry| flag persists correctly across | 423 // Tests that the |should_replace_current_entry| flag persists correctly across |
| 501 // request transfers that began with a cross-process navigation. | 424 // request transfers that began with a cross-process navigation. |
| 502 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 425 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 503 ReplaceEntryCrossProcessThenTranfers) { | 426 ReplaceEntryCrossProcessThenTranfers) { |
| 504 const NavigationController& controller = | 427 const NavigationController& controller = |
| 505 shell()->web_contents()->GetController(); | 428 shell()->web_contents()->GetController(); |
| 506 host_resolver()->AddRule("*", "127.0.0.1"); | 429 host_resolver()->AddRule("*", "127.0.0.1"); |
| 507 ASSERT_TRUE(test_server()->Start()); | 430 ASSERT_TRUE(test_server()->Start()); |
| 508 | 431 |
| 509 // These must all stay in scope with replace_host. | 432 // These must all stay in scope with replace_host. |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 // There should be two history entries. url2b should have replaced url1. url2b | 570 // There should be two history entries. url2b should have replaced url1. url2b |
| 648 // should not have replaced url3b. | 571 // should not have replaced url3b. |
| 649 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 572 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
| 650 EXPECT_EQ(2, controller.GetEntryCount()); | 573 EXPECT_EQ(2, controller.GetEntryCount()); |
| 651 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 574 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
| 652 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); | 575 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); |
| 653 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL()); | 576 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL()); |
| 654 } | 577 } |
| 655 | 578 |
| 656 } // namespace content | 579 } // namespace content |
| OLD | NEW |