| 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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 GURL server_redirect_http_url(test_server()->GetURL( | 414 GURL server_redirect_http_url(test_server()->GetURL( |
| 415 "server-redirect?" + client_redirect_http_url.spec())); | 415 "server-redirect?" + client_redirect_http_url.spec())); |
| 416 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); | 416 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); |
| 417 | 417 |
| 418 // DidFailProvisionalLoad when navigating to client_redirect_http_url. | 418 // DidFailProvisionalLoad when navigating to client_redirect_http_url. |
| 419 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); | 419 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
| 420 EXPECT_FALSE(observer.navigation_succeeded()); | 420 EXPECT_FALSE(observer.navigation_succeeded()); |
| 421 } | 421 } |
| 422 } | 422 } |
| 423 | 423 |
| 424 // Ensures FrameTree correctly reflects page structure during navigations. | |
| 425 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
| 426 FrameTreeShape) { | |
| 427 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 428 ASSERT_TRUE(test_server()->Start()); | |
| 429 | |
| 430 GURL base_url = test_server()->GetURL("files/site_isolation/"); | |
| 431 GURL::Replacements replace_host; | |
| 432 std::string host_str("A.com"); // Must stay in scope with replace_host. | |
| 433 replace_host.SetHostStr(host_str); | |
| 434 base_url = base_url.ReplaceComponents(replace_host); | |
| 435 | |
| 436 // Load doc without iframes. Verify FrameTree just has root. | |
| 437 // Frame tree: | |
| 438 // Site-A Root | |
| 439 NavigateToURL(shell(), base_url.Resolve("blank.html")); | |
| 440 FrameTreeNode* root = | |
| 441 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
| 442 GetFrameTree()->root(); | |
| 443 EXPECT_EQ(0U, root->child_count()); | |
| 444 | |
| 445 // Add 2 same-site frames. Verify 3 nodes in tree with proper names. | |
| 446 // Frame tree: | |
| 447 // Site-A Root -- Site-A frame1 | |
| 448 // \-- Site-A frame2 | |
| 449 WindowedNotificationObserver observer1( | |
| 450 content::NOTIFICATION_LOAD_STOP, | |
| 451 content::Source<NavigationController>( | |
| 452 &shell()->web_contents()->GetController())); | |
| 453 NavigateToURL(shell(), base_url.Resolve("frames-X-X.html")); | |
| 454 observer1.Wait(); | |
| 455 ASSERT_EQ(2U, root->child_count()); | |
| 456 EXPECT_EQ(0U, root->child_at(0)->child_count()); | |
| 457 EXPECT_EQ(0U, root->child_at(1)->child_count()); | |
| 458 } | |
| 459 | |
| 460 // TODO(ajwong): Talk with nasko and merge this functionality with | |
| 461 // FrameTreeShape. | |
| 462 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
| 463 FrameTreeShape2) { | |
| 464 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 465 ASSERT_TRUE(test_server()->Start()); | |
| 466 | |
| 467 NavigateToURL(shell(), | |
| 468 test_server()->GetURL("files/frame_tree/top.html")); | |
| 469 | |
| 470 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | |
| 471 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
| 472 wc->GetRenderViewHost()); | |
| 473 FrameTreeNode* root = wc->GetFrameTree()->root(); | |
| 474 | |
| 475 // Check that the root node is properly created with the frame id of the | |
| 476 // initial navigation. | |
| 477 ASSERT_EQ(3UL, root->child_count()); | |
| 478 EXPECT_EQ(std::string(), root->frame_name()); | |
| 479 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | |
| 480 | |
| 481 ASSERT_EQ(2UL, root->child_at(0)->child_count()); | |
| 482 EXPECT_STREQ("1-1-name", root->child_at(0)->frame_name().c_str()); | |
| 483 | |
| 484 // Verify the deepest node exists and has the right name. | |
| 485 ASSERT_EQ(2UL, root->child_at(2)->child_count()); | |
| 486 EXPECT_EQ(1UL, root->child_at(2)->child_at(1)->child_count()); | |
| 487 EXPECT_EQ(0UL, root->child_at(2)->child_at(1)->child_at(0)->child_count()); | |
| 488 EXPECT_STREQ("3-1-id", | |
| 489 root->child_at(2)->child_at(1)->child_at(0)->frame_name().c_str()); | |
| 490 | |
| 491 // Navigate to about:blank, which should leave only the root node of the frame | |
| 492 // tree in the browser process. | |
| 493 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); | |
| 494 | |
| 495 root = wc->GetFrameTree()->root(); | |
| 496 EXPECT_EQ(0UL, root->child_count()); | |
| 497 EXPECT_EQ(std::string(), root->frame_name()); | |
| 498 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | |
| 499 } | |
| 500 | |
| 501 // Test that we can navigate away if the previous renderer doesn't clean up its | |
| 502 // child frames. | |
| 503 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, FrameTreeAfterCrash) { | |
| 504 ASSERT_TRUE(test_server()->Start()); | |
| 505 NavigateToURL(shell(), | |
| 506 test_server()->GetURL("files/frame_tree/top.html")); | |
| 507 | |
| 508 // Crash the renderer so that it doesn't send any FrameDetached messages. | |
| 509 WindowedNotificationObserver crash_observer( | |
| 510 NOTIFICATION_RENDERER_PROCESS_CLOSED, | |
| 511 NotificationService::AllSources()); | |
| 512 NavigateToURL(shell(), GURL(kChromeUICrashURL)); | |
| 513 crash_observer.Wait(); | |
| 514 | |
| 515 // The frame tree should be cleared, and the frame ID should be reset. | |
| 516 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | |
| 517 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
| 518 wc->GetRenderViewHost()); | |
| 519 FrameTreeNode* root = wc->GetFrameTree()->root(); | |
| 520 EXPECT_EQ(0UL, root->child_count()); | |
| 521 EXPECT_EQ(FrameTreeNode::kInvalidFrameId, root->frame_id()); | |
| 522 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | |
| 523 | |
| 524 // Navigate to a new URL. | |
| 525 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); | |
| 526 | |
| 527 // The frame ID should now be set. | |
| 528 EXPECT_EQ(0UL, root->child_count()); | |
| 529 EXPECT_NE(FrameTreeNode::kInvalidFrameId, root->frame_id()); | |
| 530 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | |
| 531 } | |
| 532 | |
| 533 // Test that we can navigate away if the previous renderer doesn't clean up its | |
| 534 // child frames. | |
| 535 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateWithLeftoverFrames) { | |
| 536 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 537 ASSERT_TRUE(test_server()->Start()); | |
| 538 | |
| 539 GURL base_url = test_server()->GetURL("files/site_isolation/"); | |
| 540 GURL::Replacements replace_host; | |
| 541 std::string host_str("A.com"); // Must stay in scope with replace_host. | |
| 542 replace_host.SetHostStr(host_str); | |
| 543 base_url = base_url.ReplaceComponents(replace_host); | |
| 544 | |
| 545 NavigateToURL(shell(), | |
| 546 test_server()->GetURL("files/frame_tree/top.html")); | |
| 547 | |
| 548 // Hang the renderer so that it doesn't send any FrameDetached messages. | |
| 549 // (This navigation will never complete, so don't wait for it.) | |
| 550 shell()->LoadURL(GURL(kChromeUIHangURL)); | |
| 551 | |
| 552 // Check that the frame tree still has children. | |
| 553 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | |
| 554 FrameTreeNode* root = wc->GetFrameTree()->root(); | |
| 555 ASSERT_EQ(3UL, root->child_count()); | |
| 556 | |
| 557 // Navigate to a new URL. We use LoadURL because NavigateToURL will try to | |
| 558 // wait for the previous navigation to stop. | |
| 559 TestNavigationObserver tab_observer(wc, 1); | |
| 560 shell()->LoadURL(base_url.Resolve("blank.html")); | |
| 561 tab_observer.Wait(); | |
| 562 | |
| 563 // The frame tree should now be cleared, and the frame ID should be valid. | |
| 564 EXPECT_EQ(0UL, root->child_count()); | |
| 565 EXPECT_NE(FrameTreeNode::kInvalidFrameId, root->frame_id()); | |
| 566 } | |
| 567 | |
| 568 // Tests that the |should_replace_current_entry| flag persists correctly across | 424 // Tests that the |should_replace_current_entry| flag persists correctly across |
| 569 // request transfers that began with a cross-process navigation. | 425 // request transfers that began with a cross-process navigation. |
| 570 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 426 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 571 ReplaceEntryCrossProcessThenTranfers) { | 427 ReplaceEntryCrossProcessThenTranfers) { |
| 572 const NavigationController& controller = | 428 const NavigationController& controller = |
| 573 shell()->web_contents()->GetController(); | 429 shell()->web_contents()->GetController(); |
| 574 host_resolver()->AddRule("*", "127.0.0.1"); | 430 host_resolver()->AddRule("*", "127.0.0.1"); |
| 575 ASSERT_TRUE(test_server()->Start()); | 431 ASSERT_TRUE(test_server()->Start()); |
| 576 | 432 |
| 577 // These must all stay in scope with replace_host. | 433 // These must all stay in scope with replace_host. |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 // There should be two history entries. url2b should have replaced url1. url2b | 571 // There should be two history entries. url2b should have replaced url1. url2b |
| 716 // should not have replaced url3b. | 572 // should not have replaced url3b. |
| 717 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 573 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
| 718 EXPECT_EQ(2, controller.GetEntryCount()); | 574 EXPECT_EQ(2, controller.GetEntryCount()); |
| 719 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 575 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
| 720 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); | 576 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); |
| 721 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL()); | 577 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL()); |
| 722 } | 578 } |
| 723 | 579 |
| 724 } // namespace content | 580 } // namespace content |
| OLD | NEW |