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

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_browsertest.cc

Issue 1151393003: Add ref-count on RenderViewHost for each new RenderFrameProxyHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix up formatting. Created 5 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
OLDNEW
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
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
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
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 // This class implements waiting for RenderFrameHost destruction. It relies on
1734 // the fact that RenderFrameDeleted event is fired when RenderFrameHost is
1735 // destroyed.
1736 // Note: RenderFrameDeleted is also fired when the process associated with the
1737 // RenderFrameHost crashes, so this cannot be used in cases where process dying
1738 // is expected.
ncarter (slow) 2015/05/22 23:03:14 If you wanted to make it robust against this, you
ncarter (slow) 2015/05/22 23:04:29 [but I'm okay with just leaving the "Note:" too]
1739 class RenderFrameHostDestructionObserver : public WebContentsObserver {
ncarter (slow) 2015/05/22 23:03:14 This is pretty similar to https://code.google.com/
nasko 2015/05/22 23:46:49 Might be a good idea. I'd leave that for another C
ncarter (slow) 2015/05/23 00:33:36 Acknowledged.
1740 public:
1741 explicit RenderFrameHostDestructionObserver(WebContents* web_contents)
1742 : WebContentsObserver(web_contents),
1743 message_loop_runner_(new MessageLoopRunner),
1744 started_watching(false) {}
1745 ~RenderFrameHostDestructionObserver() override {}
1746
1747 void Observe(RenderFrameHost* rfh) {
ncarter (slow) 2015/05/22 23:03:14 This shadows WebContentsObserver::Observe, which i
nasko 2015/05/22 23:46:50 Done.
1748 started_watching = true;
1749 watched_render_frame_hosts_.insert(rfh);
1750 }
1751
1752 void Wait() {
1753 if (!started_watching)
1754 return;
1755 message_loop_runner_->Run();
1756 }
1757
1758 private:
1759 // WebContentsObserver implementation:
1760 void RenderFrameDeleted(RenderFrameHost* rfh) override {
ncarter (slow) 2015/05/22 23:03:14 This should be public.
nasko 2015/05/22 23:46:49 Why should it? I've changed it, but curious about
ncarter (slow) 2015/05/23 00:33:36 1. When you have something that's private in a der
nasko 2015/05/23 02:23:08 Acknowledged.
1761 watched_render_frame_hosts_.erase(rfh);
1762 if (!started_watching)
1763 return;
1764 if (watched_render_frame_hosts_.size() == 0) {
1765 base::MessageLoop::current()->PostTask(
1766 FROM_HERE, message_loop_runner_->QuitClosure());
1767 }
1768 }
1769
1770 scoped_refptr<MessageLoopRunner> message_loop_runner_;
1771 bool started_watching;
1772 std::set<RenderFrameHost*> watched_render_frame_hosts_;
1773 };
1774
1775 // Ensures that no RenderFrameHost/RenderViewHost objects are leaked when
1776 // doing a simple cross-process navigation.
1777 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
1778 CleanupOnCrossProcessNavigation) {
1779 StartEmbeddedServer();
1780
1781 // Do an initial navigation and capture objects we expect to be cleaned up
1782 // on cross-process navigation.
1783 GURL start_url = embedded_test_server()->GetURL("/title1.html");
1784 NavigateToURL(shell(), start_url);
1785
1786 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
1787 ->GetFrameTree()
1788 ->root();
1789 int32 orig_site_instance_id =
1790 root->current_frame_host()->GetSiteInstance()->GetId();
1791 int initial_process_id =
1792 root->current_frame_host()->GetSiteInstance()->GetProcess()->GetID();
1793 int initial_rfh_id = root->current_frame_host()->GetRoutingID();
1794 int initial_rvh_id =
1795 root->current_frame_host()->render_view_host()->GetRoutingID();
1796
1797 // Navigate cross-process and ensure that cleanup is performed as expected.
1798 GURL cross_site_url =
1799 embedded_test_server()->GetURL("foo.com", "/title2.html");
1800 RenderFrameHostDestructionObserver rfh_observer(shell()->web_contents());
1801 rfh_observer.Observe(root->current_frame_host());
1802 NavigateToURL(shell(), cross_site_url);
1803 rfh_observer.Wait();
1804
1805 EXPECT_NE(orig_site_instance_id,
1806 root->current_frame_host()->GetSiteInstance()->GetId());
1807 EXPECT_FALSE(RenderFrameHost::FromID(initial_process_id, initial_rfh_id));
1808 EXPECT_FALSE(RenderViewHost::FromID(initial_process_id, initial_rvh_id));
1809 }
1810
1725 } // namespace content 1811 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698