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

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

Issue 10825402: View-source URLs should use a separate SiteInstance in all cases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes based on Charlie's comments. Created 8 years, 4 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 | « no previous file | content/browser/web_contents/render_view_host_manager.cc » ('j') | 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 "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.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/site_instance_impl.h" 10 #include "content/browser/site_instance_impl.h"
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 968
969 void RemoveObserver(RVHObserver* observer) { 969 void RemoveObserver(RVHObserver* observer) {
970 observers_.remove(observer); 970 observers_.remove(observer);
971 } 971 }
972 972
973 std::list<RVHObserver*> observers_; 973 std::list<RVHObserver*> observers_;
974 }; 974 };
975 975
976 // Test for crbug.com/90867. Make sure we don't leak render view hosts since 976 // Test for crbug.com/90867. Make sure we don't leak render view hosts since
977 // they may cause crashes or memory corruptions when trying to call dead 977 // they may cause crashes or memory corruptions when trying to call dead
978 // delegate_. 978 // delegate_. This test also verifies crbug.com/117420 and crbug.com/143255 to
979 // ensure that a separate SiteInstance is created when navigating to view-source
980 // URLs, regardless of current URL.
979 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, LeakingRenderViewHosts) { 981 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, LeakingRenderViewHosts) {
980 // Start two servers with different sites. 982 // Start two servers with different sites.
981 ASSERT_TRUE(test_server()->Start()); 983 ASSERT_TRUE(test_server()->Start());
982 net::TestServer https_server( 984 net::TestServer https_server(
983 net::TestServer::TYPE_HTTPS, 985 net::TestServer::TYPE_HTTPS,
984 net::TestServer::kLocalhost, 986 net::TestServer::kLocalhost,
985 FilePath(FILE_PATH_LITERAL("content/test/data"))); 987 FilePath(FILE_PATH_LITERAL("content/test/data")));
986 ASSERT_TRUE(https_server.Start()); 988 ASSERT_TRUE(https_server.Start());
987 989
990 // Observe the created render_view_host's to make sure they will not leak.
991 RenderViewHostObserverArray rvh_observers;
992
993 GURL navigated_url(test_server()->GetURL("files/title2.html"));
994 GURL view_source_url(chrome::kViewSourceScheme + std::string(":") +
995 navigated_url.spec());
996
997 // Let's ensure that when we start with a blank window, navigating away to a
998 // view-source URL, we create a new SiteInstance.
999 content::RenderViewHost* blank_rvh = shell()->web_contents()->
1000 GetRenderViewHost();
1001 SiteInstance* blank_site_instance = blank_rvh->GetSiteInstance();
1002 EXPECT_EQ(shell()->web_contents()->GetURL(), GURL::EmptyGURL());
1003 EXPECT_EQ(blank_site_instance->GetSite(), GURL::EmptyGURL());
1004 rvh_observers.AddObserverToRVH(blank_rvh);
1005
1006 // Now navigate to the view-source URL and ensure we got a different
1007 // SiteInstance and RenderViewHost.
1008 NavigateToURL(shell(), view_source_url);
1009 EXPECT_NE(blank_rvh, shell()->web_contents()->GetRenderViewHost());
1010 EXPECT_NE(blank_site_instance, shell()->web_contents()->
1011 GetRenderViewHost()->GetSiteInstance());
1012 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost());
1013
988 // Load a random page and then navigate to view-source: of it. 1014 // Load a random page and then navigate to view-source: of it.
989 // This used to cause two RVH instances for the same SiteInstance, which 1015 // This used to cause two RVH instances for the same SiteInstance, which
990 // was a problem. This is no longer the case. 1016 // was a problem. This is no longer the case.
991 GURL navigated_url(test_server()->GetURL("files/title2.html"));
992 NavigateToURL(shell(), navigated_url); 1017 NavigateToURL(shell(), navigated_url);
993 SiteInstance* site_instance1 = shell()->web_contents()-> 1018 SiteInstance* site_instance1 = shell()->web_contents()->
994 GetRenderViewHost()->GetSiteInstance(); 1019 GetRenderViewHost()->GetSiteInstance();
995
996 // Observe the newly created render_view_host to make sure it will not leak.
997 RenderViewHostObserverArray rvh_observers;
998 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost()); 1020 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost());
999 1021
1000 GURL view_source_url(chrome::kViewSourceScheme + std::string(":") +
1001 navigated_url.spec());
1002 NavigateToURL(shell(), view_source_url); 1022 NavigateToURL(shell(), view_source_url);
1003 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost()); 1023 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost());
1004 SiteInstance* site_instance2 = shell()->web_contents()-> 1024 SiteInstance* site_instance2 = shell()->web_contents()->
1005 GetRenderViewHost()->GetSiteInstance(); 1025 GetRenderViewHost()->GetSiteInstance();
1006 1026
1007 // Ensure that view-source navigations force a new SiteInstance. 1027 // Ensure that view-source navigations force a new SiteInstance.
1008 EXPECT_NE(site_instance1, site_instance2); 1028 EXPECT_NE(site_instance1, site_instance2);
1009 1029
1010 // Now navigate to a different instance so that we swap out again. 1030 // Now navigate to a different instance so that we swap out again.
1011 NavigateToURL(shell(), https_server.GetURL("files/title2.html")); 1031 NavigateToURL(shell(), https_server.GetURL("files/title2.html"));
1012 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost()); 1032 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost());
1013 1033
1014 // This used to leak a render view host. 1034 // This used to leak a render view host.
1015 shell()->Close(); 1035 shell()->Close();
1016 1036
1017 RunAllPendingInMessageLoop(); // Needed on ChromeOS. 1037 RunAllPendingInMessageLoop(); // Needed on ChromeOS.
1018 1038
1019 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); 1039 EXPECT_EQ(0U, rvh_observers.GetNumObservers());
1020 } 1040 }
1021 1041
1022 } // namespace content 1042 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/web_contents/render_view_host_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698