| 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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 // FrameTreeShape. | 461 // FrameTreeShape. |
| 462 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 462 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 463 FrameTreeShape2) { | 463 FrameTreeShape2) { |
| 464 host_resolver()->AddRule("*", "127.0.0.1"); | 464 host_resolver()->AddRule("*", "127.0.0.1"); |
| 465 ASSERT_TRUE(test_server()->Start()); | 465 ASSERT_TRUE(test_server()->Start()); |
| 466 | 466 |
| 467 NavigateToURL(shell(), | 467 NavigateToURL(shell(), |
| 468 test_server()->GetURL("files/frame_tree/top.html")); | 468 test_server()->GetURL("files/frame_tree/top.html")); |
| 469 | 469 |
| 470 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | 470 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 471 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
| 472 wc->GetRenderViewHost()); | |
| 473 FrameTreeNode* root = wc->GetFrameTree()->root(); | 471 FrameTreeNode* root = wc->GetFrameTree()->root(); |
| 474 | 472 |
| 475 // Check that the root node is properly created with the frame id of the | 473 // Check that the root node is properly created with the frame id of the |
| 476 // initial navigation. | 474 // initial navigation. |
| 477 ASSERT_EQ(3UL, root->child_count()); | 475 ASSERT_EQ(3UL, root->child_count()); |
| 478 EXPECT_EQ(std::string(), root->frame_name()); | 476 EXPECT_EQ(std::string(), root->frame_name()); |
| 479 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | |
| 480 | 477 |
| 481 ASSERT_EQ(2UL, root->child_at(0)->child_count()); | 478 ASSERT_EQ(2UL, root->child_at(0)->child_count()); |
| 482 EXPECT_STREQ("1-1-name", root->child_at(0)->frame_name().c_str()); | 479 EXPECT_STREQ("1-1-name", root->child_at(0)->frame_name().c_str()); |
| 483 | 480 |
| 484 // Verify the deepest node exists and has the right name. | 481 // Verify the deepest node exists and has the right name. |
| 485 ASSERT_EQ(2UL, root->child_at(2)->child_count()); | 482 ASSERT_EQ(2UL, root->child_at(2)->child_count()); |
| 486 EXPECT_EQ(1UL, root->child_at(2)->child_at(1)->child_count()); | 483 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()); | 484 EXPECT_EQ(0UL, root->child_at(2)->child_at(1)->child_at(0)->child_count()); |
| 488 EXPECT_STREQ("3-1-id", | 485 EXPECT_STREQ("3-1-id", |
| 489 root->child_at(2)->child_at(1)->child_at(0)->frame_name().c_str()); | 486 root->child_at(2)->child_at(1)->child_at(0)->frame_name().c_str()); |
| 490 | 487 |
| 491 // Navigate to about:blank, which should leave only the root node of the frame | 488 // Navigate to about:blank, which should leave only the root node of the frame |
| 492 // tree in the browser process. | 489 // tree in the browser process. |
| 493 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); | 490 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); |
| 494 | 491 |
| 495 root = wc->GetFrameTree()->root(); | 492 root = wc->GetFrameTree()->root(); |
| 496 EXPECT_EQ(0UL, root->child_count()); | 493 EXPECT_EQ(0UL, root->child_count()); |
| 497 EXPECT_EQ(std::string(), root->frame_name()); | 494 EXPECT_EQ(std::string(), root->frame_name()); |
| 498 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | |
| 499 } | 495 } |
| 500 | 496 |
| 501 // Test that we can navigate away if the previous renderer doesn't clean up its | 497 // Test that we can navigate away if the previous renderer doesn't clean up its |
| 502 // child frames. | 498 // child frames. |
| 503 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, FrameTreeAfterCrash) { | 499 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, FrameTreeAfterCrash) { |
| 504 ASSERT_TRUE(test_server()->Start()); | 500 ASSERT_TRUE(test_server()->Start()); |
| 505 NavigateToURL(shell(), | 501 NavigateToURL(shell(), |
| 506 test_server()->GetURL("files/frame_tree/top.html")); | 502 test_server()->GetURL("files/frame_tree/top.html")); |
| 507 | 503 |
| 508 // Crash the renderer so that it doesn't send any FrameDetached messages. | 504 // Crash the renderer so that it doesn't send any FrameDetached messages. |
| 509 WindowedNotificationObserver crash_observer( | 505 WindowedNotificationObserver crash_observer( |
| 510 NOTIFICATION_RENDERER_PROCESS_CLOSED, | 506 NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 511 NotificationService::AllSources()); | 507 NotificationService::AllSources()); |
| 512 NavigateToURL(shell(), GURL(kChromeUICrashURL)); | 508 NavigateToURL(shell(), GURL(kChromeUICrashURL)); |
| 513 crash_observer.Wait(); | 509 crash_observer.Wait(); |
| 514 | 510 |
| 515 // The frame tree should be cleared, and the frame ID should be reset. | 511 // The frame tree should be cleared, and the frame ID should be reset. |
| 516 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | 512 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 517 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 513 //RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 518 wc->GetRenderViewHost()); | 514 // wc->GetRenderViewHost()); |
| 519 FrameTreeNode* root = wc->GetFrameTree()->root(); | 515 FrameTreeNode* root = wc->GetFrameTree()->root(); |
| 520 EXPECT_EQ(0UL, root->child_count()); | 516 EXPECT_EQ(0UL, root->child_count()); |
| 521 EXPECT_EQ(FrameTreeNode::kInvalidFrameId, root->frame_id()); | 517 // TODO(creis): We shouldn't be using frame_id here. |
| 522 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | 518 /*EXPECT_EQ(FrameTreeNode::kInvalidFrameId, root->frame_id()); |
| 519 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); */ |
| 523 | 520 |
| 524 // Navigate to a new URL. | 521 // Navigate to a new URL. |
| 525 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); | 522 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); |
| 526 | 523 |
| 527 // The frame ID should now be set. | 524 // The frame ID should now be set. |
| 528 EXPECT_EQ(0UL, root->child_count()); | 525 EXPECT_EQ(0UL, root->child_count()); |
| 529 EXPECT_NE(FrameTreeNode::kInvalidFrameId, root->frame_id()); | 526 // TODO(creis): We shouldn't be using frame_id here. |
| 530 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | 527 /*EXPECT_NE(FrameTreeNode::kInvalidFrameId, root->frame_id()); |
| 528 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); */ |
| 531 } | 529 } |
| 532 | 530 |
| 533 // Test that we can navigate away if the previous renderer doesn't clean up its | 531 // Test that we can navigate away if the previous renderer doesn't clean up its |
| 534 // child frames. | 532 // child frames. |
| 535 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateWithLeftoverFrames) { | 533 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateWithLeftoverFrames) { |
| 536 host_resolver()->AddRule("*", "127.0.0.1"); | 534 host_resolver()->AddRule("*", "127.0.0.1"); |
| 537 ASSERT_TRUE(test_server()->Start()); | 535 ASSERT_TRUE(test_server()->Start()); |
| 538 | 536 |
| 539 GURL base_url = test_server()->GetURL("files/site_isolation/"); | 537 GURL base_url = test_server()->GetURL("files/site_isolation/"); |
| 540 GURL::Replacements replace_host; | 538 GURL::Replacements replace_host; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 555 ASSERT_EQ(3UL, root->child_count()); | 553 ASSERT_EQ(3UL, root->child_count()); |
| 556 | 554 |
| 557 // Navigate to a new URL. We use LoadURL because NavigateToURL will try to | 555 // Navigate to a new URL. We use LoadURL because NavigateToURL will try to |
| 558 // wait for the previous navigation to stop. | 556 // wait for the previous navigation to stop. |
| 559 TestNavigationObserver tab_observer(wc, 1); | 557 TestNavigationObserver tab_observer(wc, 1); |
| 560 shell()->LoadURL(base_url.Resolve("blank.html")); | 558 shell()->LoadURL(base_url.Resolve("blank.html")); |
| 561 tab_observer.Wait(); | 559 tab_observer.Wait(); |
| 562 | 560 |
| 563 // The frame tree should now be cleared, and the frame ID should be valid. | 561 // The frame tree should now be cleared, and the frame ID should be valid. |
| 564 EXPECT_EQ(0UL, root->child_count()); | 562 EXPECT_EQ(0UL, root->child_count()); |
| 565 EXPECT_NE(FrameTreeNode::kInvalidFrameId, root->frame_id()); | 563 // TODO(creis): We shouldn't be using frame_id here. |
| 564 //EXPECT_NE(FrameTreeNode::kInvalidFrameId, root->frame_id()); |
| 566 } | 565 } |
| 567 | 566 |
| 568 // Tests that the |should_replace_current_entry| flag persists correctly across | 567 // Tests that the |should_replace_current_entry| flag persists correctly across |
| 569 // request transfers that began with a cross-process navigation. | 568 // request transfers that began with a cross-process navigation. |
| 570 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 569 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 571 ReplaceEntryCrossProcessThenTranfers) { | 570 ReplaceEntryCrossProcessThenTranfers) { |
| 572 const NavigationController& controller = | 571 const NavigationController& controller = |
| 573 shell()->web_contents()->GetController(); | 572 shell()->web_contents()->GetController(); |
| 574 host_resolver()->AddRule("*", "127.0.0.1"); | 573 host_resolver()->AddRule("*", "127.0.0.1"); |
| 575 ASSERT_TRUE(test_server()->Start()); | 574 ASSERT_TRUE(test_server()->Start()); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 // There should be two history entries. url2b should have replaced url1. url2b | 714 // There should be two history entries. url2b should have replaced url1. url2b |
| 716 // should not have replaced url3b. | 715 // should not have replaced url3b. |
| 717 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 716 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
| 718 EXPECT_EQ(2, controller.GetEntryCount()); | 717 EXPECT_EQ(2, controller.GetEntryCount()); |
| 719 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 718 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
| 720 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); | 719 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); |
| 721 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL()); | 720 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL()); |
| 722 } | 721 } |
| 723 | 722 |
| 724 } // namespace content | 723 } // namespace content |
| OLD | NEW |