OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <set> | 5 #include <set> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "content/public/common/page_state.h" | 28 #include "content/public/common/page_state.h" |
29 #include "content/public/common/url_constants.h" | 29 #include "content/public/common/url_constants.h" |
30 #include "content/public/test/browser_test_utils.h" | 30 #include "content/public/test/browser_test_utils.h" |
31 #include "content/public/test/content_browser_test.h" | 31 #include "content/public/test/content_browser_test.h" |
32 #include "content/public/test/content_browser_test_utils.h" | 32 #include "content/public/test/content_browser_test_utils.h" |
33 #include "content/public/test/test_navigation_observer.h" | 33 #include "content/public/test/test_navigation_observer.h" |
34 #include "content/public/test/test_utils.h" | 34 #include "content/public/test/test_utils.h" |
35 #include "content/shell/browser/shell.h" | 35 #include "content/shell/browser/shell.h" |
36 #include "net/base/net_util.h" | 36 #include "net/base/net_util.h" |
37 #include "net/dns/mock_host_resolver.h" | 37 #include "net/dns/mock_host_resolver.h" |
| 38 #include "net/test/embedded_test_server/embedded_test_server.h" |
38 #include "net/test/spawned_test_server/spawned_test_server.h" | 39 #include "net/test/spawned_test_server/spawned_test_server.h" |
39 | 40 |
40 using base::ASCIIToUTF16; | 41 using base::ASCIIToUTF16; |
41 | 42 |
42 namespace content { | 43 namespace content { |
43 | 44 |
44 namespace { | 45 namespace { |
45 | 46 |
46 const char kOpenUrlViaClickTargetFunc[] = | 47 const char kOpenUrlViaClickTargetFunc[] = |
47 "(function(url) {\n" | 48 "(function(url) {\n" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 81 |
81 void StartServer() { | 82 void StartServer() { |
82 // Support multiple sites on the test server. | 83 // Support multiple sites on the test server. |
83 host_resolver()->AddRule("*", "127.0.0.1"); | 84 host_resolver()->AddRule("*", "127.0.0.1"); |
84 ASSERT_TRUE(test_server()->Start()); | 85 ASSERT_TRUE(test_server()->Start()); |
85 | 86 |
86 foo_host_port_ = test_server()->host_port_pair(); | 87 foo_host_port_ = test_server()->host_port_pair(); |
87 foo_host_port_.set_host(foo_com_); | 88 foo_host_port_.set_host(foo_com_); |
88 } | 89 } |
89 | 90 |
| 91 void StartEmbeddedServer() { |
| 92 // Support multiple sites on the embedded test server. |
| 93 host_resolver()->AddRule("*", "127.0.0.1"); |
| 94 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 95 SetupCrossSiteRedirector(embedded_test_server()); |
| 96 } |
| 97 |
90 // Returns a URL on foo.com with the given path. | 98 // Returns a URL on foo.com with the given path. |
91 GURL GetCrossSiteURL(const std::string& path) { | 99 GURL GetCrossSiteURL(const std::string& path) { |
92 GURL cross_site_url(test_server()->GetURL(path)); | 100 GURL cross_site_url(test_server()->GetURL(path)); |
93 return cross_site_url.ReplaceComponents(replace_host_); | 101 return cross_site_url.ReplaceComponents(replace_host_); |
94 } | 102 } |
95 | 103 |
96 protected: | 104 protected: |
97 std::string foo_com_; | 105 std::string foo_com_; |
98 GURL::Replacements replace_host_; | 106 GURL::Replacements replace_host_; |
99 net::HostPortPair foo_host_port_; | 107 net::HostPortPair foo_host_port_; |
(...skipping 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1715 shell()->web_contents()->GetController().GoBack(); | 1723 shell()->web_contents()->GetController().GoBack(); |
1716 back_nav_load_observer.Wait(); | 1724 back_nav_load_observer.Wait(); |
1717 EXPECT_NE(process_id, | 1725 EXPECT_NE(process_id, |
1718 shell()->web_contents()->GetRenderProcessHost()->GetID()); | 1726 shell()->web_contents()->GetRenderProcessHost()->GetID()); |
1719 | 1727 |
1720 // Ensure that the file access still exists in the new process ID. | 1728 // Ensure that the file access still exists in the new process ID. |
1721 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 1729 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
1722 shell()->web_contents()->GetRenderProcessHost()->GetID(), file)); | 1730 shell()->web_contents()->GetRenderProcessHost()->GetID(), file)); |
1723 } | 1731 } |
1724 | 1732 |
| 1733 // Ensures that no RenderFrameHost/RenderViewHost objects are leaked when |
| 1734 // doing a simple cross-process navigation. |
| 1735 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 1736 CleanupOnCrossProcessNavigation) { |
| 1737 StartEmbeddedServer(); |
| 1738 |
| 1739 // Do an initial navigation and capture objects we expect to be cleaned up |
| 1740 // on cross-process navigation. |
| 1741 GURL start_url = embedded_test_server()->GetURL("/title1.html"); |
| 1742 NavigateToURL(shell(), start_url); |
| 1743 |
| 1744 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 1745 ->GetFrameTree() |
| 1746 ->root(); |
| 1747 SiteInstance* orig_site = root->current_frame_host()->GetSiteInstance(); |
| 1748 int initial_process_id = orig_site->GetProcess()->GetID(); |
| 1749 int initial_rfh_id = root->current_frame_host()->GetRoutingID(); |
| 1750 int initial_rvh_id = |
| 1751 root->current_frame_host()->render_view_host()->GetRoutingID(); |
| 1752 |
| 1753 // Navigate cross-process and ensure that cleanup is performed as expected. |
| 1754 GURL cross_site_url = |
| 1755 embedded_test_server()->GetURL("foo.com", "/title2.html"); |
| 1756 NavigateToURL(shell(), cross_site_url); |
| 1757 |
| 1758 EXPECT_NE(orig_site, root->current_frame_host()->GetSiteInstance()); |
| 1759 EXPECT_FALSE(RenderFrameHost::FromID(initial_process_id, initial_rfh_id)); |
| 1760 EXPECT_FALSE(RenderViewHost::FromID(initial_process_id, initial_rvh_id)); |
| 1761 } |
| 1762 |
1725 } // namespace content | 1763 } // namespace content |
OLD | NEW |