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

Side by Side Diff: content/browser/renderer_host/render_view_host_manager_browsertest.cc

Issue 10332146: Merge 136168 - Allow renderers to shut down if they only contain swapped out views. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1132/src/
Patch Set: Created 8 years, 7 months 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_process_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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/test/base/in_process_browser_test.h" 9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/ui_test_utils.h" 10 #include "chrome/test/base/ui_test_utils.h"
11 #include "content/browser/renderer_host/render_view_host_impl.h" 11 #include "content/browser/renderer_host/render_view_host_impl.h"
12 #include "content/browser/site_instance_impl.h" 12 #include "content/browser/site_instance_impl.h"
13 #include "content/browser/web_contents/web_contents_impl.h" 13 #include "content/browser/web_contents/web_contents_impl.h"
14 #include "content/public/browser/navigation_controller.h" 14 #include "content/public/browser/navigation_controller.h"
15 #include "content/public/browser/notification_details.h" 15 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_observer.h" 16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h" 17 #include "content/public/browser/notification_registrar.h"
18 #include "content/public/browser/notification_types.h" 18 #include "content/public/browser/notification_types.h"
19 #include "content/public/browser/render_process_host.h"
19 #include "content/public/browser/render_view_host_observer.h" 20 #include "content/public/browser/render_view_host_observer.h"
20 #include "content/public/common/url_constants.h" 21 #include "content/public/common/url_constants.h"
21 #include "net/base/net_util.h" 22 #include "net/base/net_util.h"
22 #include "net/test/test_server.h" 23 #include "net/test/test_server.h"
23 24
24 using content::RenderViewHost; 25 using content::RenderViewHost;
25 using content::SiteInstance; 26 using content::SiteInstance;
26 27
27 class RenderViewHostManagerTest : public InProcessBrowserTest { 28 class RenderViewHostManagerTest : public InProcessBrowserTest {
28 public: 29 public:
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 // Active tab should not have changed. 511 // Active tab should not have changed.
511 EXPECT_EQ(1, browser()->active_index()); 512 EXPECT_EQ(1, browser()->active_index());
512 513
513 // Should have swapped back into this process. 514 // Should have swapped back into this process.
514 browser()->ActivateTabAt(0, true); 515 browser()->ActivateTabAt(0, true);
515 scoped_refptr<SiteInstance> revisit_site_instance( 516 scoped_refptr<SiteInstance> revisit_site_instance(
516 browser()->GetSelectedWebContents()->GetSiteInstance()); 517 browser()->GetSelectedWebContents()->GetSiteInstance());
517 EXPECT_EQ(orig_site_instance, revisit_site_instance); 518 EXPECT_EQ(orig_site_instance, revisit_site_instance);
518 } 519 }
519 520
521 // Test that opening a new window in the same SiteInstance and then navigating
522 // both windows to a different SiteInstance allows the first process to exit.
523 // See http://crbug.com/126333.
524 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest,
525 ProcessExitWithSwappedOutViews) {
526 // Start two servers with different sites.
527 ASSERT_TRUE(test_server()->Start());
528 net::TestServer https_server(
529 net::TestServer::TYPE_HTTPS,
530 net::TestServer::kLocalhost,
531 FilePath(FILE_PATH_LITERAL("chrome/test/data")));
532 ASSERT_TRUE(https_server.Start());
533
534 // Load a page with links that open in a new window.
535 std::string replacement_path;
536 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
537 "files/click-noreferrer-links.html",
538 https_server.host_port_pair(),
539 &replacement_path));
540 ui_test_utils::NavigateToURL(browser(),
541 test_server()->GetURL(replacement_path));
542
543 // Get the original SiteInstance for later comparison.
544 scoped_refptr<SiteInstance> orig_site_instance(
545 browser()->GetSelectedWebContents()->GetSiteInstance());
546 EXPECT_TRUE(orig_site_instance != NULL);
547
548 // Test clicking a target=foo link.
549 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer((
550 content::Source<content::WebContentsDelegate>(browser())));
551 bool success = false;
552 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
553 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"",
554 L"window.domAutomationController.send(clickSameSiteTargetedLink());",
555 &success));
556 EXPECT_TRUE(success);
557 new_tab_observer.Wait();
558
559 // Opens in new tab.
560 EXPECT_EQ(2, browser()->tab_count());
561 EXPECT_EQ(1, browser()->active_index());
562
563 // Wait for the navigation in the new tab to finish, if it hasn't.
564 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents());
565 EXPECT_EQ("/files/navigate_opener.html",
566 browser()->GetSelectedWebContents()->GetURL().path());
567 EXPECT_EQ(1, browser()->active_index());
568
569 // Should have the same SiteInstance.
570 scoped_refptr<SiteInstance> opened_site_instance(
571 browser()->GetSelectedWebContents()->GetSiteInstance());
572 EXPECT_EQ(orig_site_instance, opened_site_instance);
573
574 // Now navigate the opened tab to a different site.
575 ui_test_utils::NavigateToURL(browser(),
576 https_server.GetURL("files/title1.html"));
577 scoped_refptr<SiteInstance> new_site_instance(
578 browser()->GetSelectedWebContents()->GetSiteInstance());
579 EXPECT_NE(orig_site_instance, new_site_instance);
580
581 // The original process should still be alive, since it is still used in the
582 // first tab.
583 content::RenderProcessHost* orig_process = orig_site_instance->GetProcess();
584 EXPECT_TRUE(orig_process->HasConnection());
585
586 // Navigate the first tab to a different site as well. The original process
587 // should exit, since all of its views are now swapped out.
588 browser()->ActivateTabAt(0, true);
589 ui_test_utils::WindowedNotificationObserver exit_observer(
590 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
591 content::Source<content::RenderProcessHost>(orig_process));
592 ui_test_utils::NavigateToURL(browser(),
593 https_server.GetURL("files/title1.html"));
594 exit_observer.Wait();
595 scoped_refptr<SiteInstance> new_site_instance2(
596 browser()->GetSelectedWebContents()->GetSiteInstance());
597 EXPECT_EQ(new_site_instance, new_site_instance2);
598 }
599
520 // Test for crbug.com/76666. A cross-site navigation that fails with a 204 600 // Test for crbug.com/76666. A cross-site navigation that fails with a 204
521 // error should not make us ignore future renderer-initiated navigations. 601 // error should not make us ignore future renderer-initiated navigations.
522 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ClickLinkAfter204Error) { 602 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ClickLinkAfter204Error) {
523 // Start two servers with different sites. 603 // Start two servers with different sites.
524 ASSERT_TRUE(test_server()->Start()); 604 ASSERT_TRUE(test_server()->Start());
525 net::TestServer https_server( 605 net::TestServer https_server(
526 net::TestServer::TYPE_HTTPS, 606 net::TestServer::TYPE_HTTPS,
527 net::TestServer::kLocalhost, 607 net::TestServer::kLocalhost,
528 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); 608 FilePath(FILE_PATH_LITERAL("chrome/test/data")));
529 ASSERT_TRUE(https_server.Start()); 609 ASSERT_TRUE(https_server.Start());
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 // Now navigate to a different instance so that we swap out again. 869 // Now navigate to a different instance so that we swap out again.
790 ui_test_utils::NavigateToURL(browser(), 870 ui_test_utils::NavigateToURL(browser(),
791 https_server.GetURL("files/title2.html")); 871 https_server.GetURL("files/title2.html"));
792 rvh_observers.AddObserverToRVH(browser()->GetSelectedWebContents()-> 872 rvh_observers.AddObserverToRVH(browser()->GetSelectedWebContents()->
793 GetRenderViewHost()); 873 GetRenderViewHost());
794 874
795 // This used to leak a render view host. 875 // This used to leak a render view host.
796 browser()->CloseTabContents(browser()->GetSelectedWebContents()); 876 browser()->CloseTabContents(browser()->GetSelectedWebContents());
797 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); 877 EXPECT_EQ(0U, rvh_observers.GetNumObservers());
798 } 878 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698