Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Side by Side Diff: content/browser/site_per_process_browsertest.cc

Issue 90413002: Ensure that child FrameTreeNodes are deleted after a navigation or crash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/renderer_host/render_view_host_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "content/public/browser/navigation_entry.h" 11 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/browser/notification_observer.h" 12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_service.h" 13 #include "content/public/browser/notification_service.h"
14 #include "content/public/browser/notification_types.h" 14 #include "content/public/browser/notification_types.h"
15 #include "content/public/browser/web_contents_observer.h" 15 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/common/content_switches.h" 16 #include "content/public/common/content_switches.h"
17 #include "content/public/common/url_constants.h"
17 #include "content/public/test/browser_test_utils.h" 18 #include "content/public/test/browser_test_utils.h"
18 #include "content/public/test/test_navigation_observer.h" 19 #include "content/public/test/test_navigation_observer.h"
19 #include "content/public/test/test_utils.h" 20 #include "content/public/test/test_utils.h"
20 #include "content/shell/browser/shell.h" 21 #include "content/shell/browser/shell.h"
21 #include "content/shell/browser/shell_content_browser_client.h" 22 #include "content/shell/browser/shell_content_browser_client.h"
22 #include "content/test/content_browser_test.h" 23 #include "content/test/content_browser_test.h"
23 #include "content/test/content_browser_test_utils.h" 24 #include "content/test/content_browser_test_utils.h"
24 #include "net/base/escape.h" 25 #include "net/base/escape.h"
25 #include "net/dns/mock_host_resolver.h" 26 #include "net/dns/mock_host_resolver.h"
26 27
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 // Navigate to about:blank, which should leave only the root node of the frame 491 // Navigate to about:blank, which should leave only the root node of the frame
491 // tree in the browser process. 492 // tree in the browser process.
492 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); 493 NavigateToURL(shell(), test_server()->GetURL("files/title1.html"));
493 494
494 root = wc->GetFrameTree()->root(); 495 root = wc->GetFrameTree()->root();
495 EXPECT_EQ(0UL, root->child_count()); 496 EXPECT_EQ(0UL, root->child_count());
496 EXPECT_EQ(std::string(), root->frame_name()); 497 EXPECT_EQ(std::string(), root->frame_name());
497 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); 498 EXPECT_EQ(rvh->main_frame_id(), root->frame_id());
498 } 499 }
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
500 // Tests that the |should_replace_current_entry| flag persists correctly across 568 // Tests that the |should_replace_current_entry| flag persists correctly across
501 // request transfers that began with a cross-process navigation. 569 // request transfers that began with a cross-process navigation.
502 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, 570 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
503 ReplaceEntryCrossProcessThenTranfers) { 571 ReplaceEntryCrossProcessThenTranfers) {
504 const NavigationController& controller = 572 const NavigationController& controller =
505 shell()->web_contents()->GetController(); 573 shell()->web_contents()->GetController();
506 host_resolver()->AddRule("*", "127.0.0.1"); 574 host_resolver()->AddRule("*", "127.0.0.1");
507 ASSERT_TRUE(test_server()->Start()); 575 ASSERT_TRUE(test_server()->Start());
508 576
509 // These must all stay in scope with replace_host. 577 // These must all stay in scope with replace_host.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 // There should be two history entries. url2b should have replaced url1. url2b 715 // There should be two history entries. url2b should have replaced url1. url2b
648 // should not have replaced url3b. 716 // should not have replaced url3b.
649 EXPECT_TRUE(controller.GetPendingEntry() == NULL); 717 EXPECT_TRUE(controller.GetPendingEntry() == NULL);
650 EXPECT_EQ(2, controller.GetEntryCount()); 718 EXPECT_EQ(2, controller.GetEntryCount());
651 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 719 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
652 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); 720 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL());
653 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL()); 721 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL());
654 } 722 }
655 723
656 } // namespace content 724 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_view_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698