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/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 Loading... | |
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 blank window, navigating away from it, | |
998 // we create a new SiteInstance. | |
Charlie Reis
2012/08/16 22:28:09
This comment isn't quite right. This should only
nasko
2012/08/16 22:59:23
Done.
| |
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 // Explicit navigation to "about:blank" should use the same SiteInstance and | |
1007 // RenderViewHost. | |
Charlie Reis
2012/08/16 22:28:09
This sort of confuses the issue. By putting any n
nasko
2012/08/16 22:59:23
Done.
| |
1008 NavigateToURL(shell(), GURL(chrome::kAboutBlankURL)); | |
1009 EXPECT_EQ(shell()->web_contents()->GetURL(), GURL(chrome::kAboutBlankURL)); | |
1010 EXPECT_EQ(blank_rvh, shell()->web_contents()->GetRenderViewHost()); | |
1011 EXPECT_EQ(blank_site_instance, shell()->web_contents()->GetRenderViewHost()-> | |
1012 GetSiteInstance()); | |
1013 | |
1014 // Now navigate to the view-source URL and ensure we got different | |
Charlie Reis
2012/08/16 22:28:09
nit: got a
nasko
2012/08/16 22:59:23
Done.
| |
1015 // SiteInstance and RenderViewHost. | |
1016 NavigateToURL(shell(), view_source_url); | |
1017 EXPECT_NE(blank_rvh, shell()->web_contents()->GetRenderViewHost()); | |
1018 EXPECT_NE(blank_site_instance, shell()->web_contents()-> | |
1019 GetRenderViewHost()->GetSiteInstance()); | |
1020 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost()); | |
1021 | |
988 // Load a random page and then navigate to view-source: of it. | 1022 // 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 | 1023 // This used to cause two RVH instances for the same SiteInstance, which |
990 // was a problem. This is no longer the case. | 1024 // was a problem. This is no longer the case. |
991 GURL navigated_url(test_server()->GetURL("files/title2.html")); | |
992 NavigateToURL(shell(), navigated_url); | 1025 NavigateToURL(shell(), navigated_url); |
993 SiteInstance* site_instance1 = shell()->web_contents()-> | 1026 SiteInstance* site_instance1 = shell()->web_contents()-> |
994 GetRenderViewHost()->GetSiteInstance(); | 1027 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()); | 1028 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost()); |
999 | 1029 |
1000 GURL view_source_url(chrome::kViewSourceScheme + std::string(":") + | |
1001 navigated_url.spec()); | |
1002 NavigateToURL(shell(), view_source_url); | 1030 NavigateToURL(shell(), view_source_url); |
1003 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost()); | 1031 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost()); |
1004 SiteInstance* site_instance2 = shell()->web_contents()-> | 1032 SiteInstance* site_instance2 = shell()->web_contents()-> |
1005 GetRenderViewHost()->GetSiteInstance(); | 1033 GetRenderViewHost()->GetSiteInstance(); |
1006 | 1034 |
1007 // Ensure that view-source navigations force a new SiteInstance. | 1035 // Ensure that view-source navigations force a new SiteInstance. |
1008 EXPECT_NE(site_instance1, site_instance2); | 1036 EXPECT_NE(site_instance1, site_instance2); |
1009 | 1037 |
1010 // Now navigate to a different instance so that we swap out again. | 1038 // Now navigate to a different instance so that we swap out again. |
1011 NavigateToURL(shell(), https_server.GetURL("files/title2.html")); | 1039 NavigateToURL(shell(), https_server.GetURL("files/title2.html")); |
1012 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost()); | 1040 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost()); |
1013 | 1041 |
1014 // This used to leak a render view host. | 1042 // This used to leak a render view host. |
1015 shell()->Close(); | 1043 shell()->Close(); |
1016 | 1044 |
1017 RunAllPendingInMessageLoop(); // Needed on ChromeOS. | 1045 RunAllPendingInMessageLoop(); // Needed on ChromeOS. |
1018 | 1046 |
1019 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); | 1047 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); |
1020 } | 1048 } |
1021 | 1049 |
1022 } // namespace content | 1050 } // namespace content |
OLD | NEW |