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

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

Issue 2929113002: Enable spare RenderProcessHost to be preinitialized. (Closed)
Patch Set: Change creation of storage partition to not break unittests with subtle threading issues Created 3 years, 5 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <limits> 7 #include <limits>
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "content/common/frame_messages.h" 14 #include "content/common/frame_messages.h"
15 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/content_browser_client.h" 16 #include "content/public/browser/content_browser_client.h"
16 #include "content/public/common/browser_side_navigation_policy.h" 17 #include "content/public/common/browser_side_navigation_policy.h"
17 #include "content/public/common/content_constants.h" 18 #include "content/public/common/content_constants.h"
18 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
19 #include "content/public/test/mock_render_process_host.h" 20 #include "content/public/test/mock_render_process_host.h"
21 #include "content/public/test/test_browser_context.h"
20 #include "content/public/test/test_utils.h" 22 #include "content/public/test/test_utils.h"
21 #include "content/test/test_render_frame_host.h" 23 #include "content/test/test_render_frame_host.h"
22 #include "content/test/test_render_view_host.h" 24 #include "content/test/test_render_view_host.h"
23 #include "content/test/test_web_contents.h" 25 #include "content/test/test_web_contents.h"
24 #include "third_party/WebKit/public/web/WebSandboxFlags.h" 26 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
25 27
26 namespace content { 28 namespace content {
27 29
28 class RenderProcessHostUnitTest : public RenderViewHostImplTestHarness {}; 30 class RenderProcessHostUnitTest : public RenderViewHostImplTestHarness {};
29 31
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 // REUSE_PENDING_OR_COMMITTED_SITE policy should now return the process of the 744 // REUSE_PENDING_OR_COMMITTED_SITE policy should now return the process of the
743 // main RFH, as it was registered with the regular site URL when it committed. 745 // main RFH, as it was registered with the regular site URL when it committed.
744 main_test_rfh()->PrepareForCommit(); 746 main_test_rfh()->PrepareForCommit();
745 main_test_rfh()->SendNavigate(0, true, kUrl); 747 main_test_rfh()->SendNavigate(0, true, kUrl);
746 site_instance = SiteInstanceImpl::CreateForURL(browser_context(), kUrl); 748 site_instance = SiteInstanceImpl::CreateForURL(browser_context(), kUrl);
747 site_instance->set_process_reuse_policy( 749 site_instance->set_process_reuse_policy(
748 SiteInstanceImpl::ProcessReusePolicy::REUSE_PENDING_OR_COMMITTED_SITE); 750 SiteInstanceImpl::ProcessReusePolicy::REUSE_PENDING_OR_COMMITTED_SITE);
749 EXPECT_EQ(main_test_rfh()->GetProcess(), site_instance->GetProcess()); 751 EXPECT_EQ(main_test_rfh()->GetProcess(), site_instance->GetProcess());
750 } 752 }
751 753
754 class SpareRenderProcessHostUnitTest : public RenderViewHostImplTestHarness {
755 protected:
756 void SetUp() override {
757 SetRenderProcessHostFactory(&rph_factory_);
758 RenderViewHostImplTestHarness::SetUp();
759 SetContents(NULL); // Start with no renderers.
760 while (!rph_factory_.GetProcesses()->empty()) {
761 rph_factory_.Remove(rph_factory_.GetProcesses()->back().get());
762 }
763 }
764
765 MockRenderProcessHostFactory rph_factory_;
766 };
767
768 TEST_F(SpareRenderProcessHostUnitTest, TestRendererTaken) {
769 RenderProcessHost::WarmupSpareRenderProcessHost(browser_context());
770 ASSERT_EQ(1U, rph_factory_.GetProcesses()->size());
771 RenderProcessHost* spare_rph =
772 RenderProcessHostImpl::GetSpareRenderProcessHostForTesting();
773 EXPECT_EQ(spare_rph, rph_factory_.GetProcesses()->at(0).get());
774
775 const GURL kUrl1("http://foo.com");
776 SetContents(CreateTestWebContents());
777 NavigateAndCommit(kUrl1);
778 EXPECT_EQ(spare_rph, main_test_rfh()->GetProcess());
779 ASSERT_EQ(1U, rph_factory_.GetProcesses()->size());
780 }
781
782 TEST_F(SpareRenderProcessHostUnitTest, TestRendererNotTaken) {
783 std::unique_ptr<BrowserContext> alternate_context(new TestBrowserContext());
784 RenderProcessHost::WarmupSpareRenderProcessHost(alternate_context.get());
785 ASSERT_EQ(1U, rph_factory_.GetProcesses()->size());
786 RenderProcessHost* spare_rph =
787 RenderProcessHostImpl::GetSpareRenderProcessHostForTesting();
788 EXPECT_EQ(spare_rph, rph_factory_.GetProcesses()->at(0).get());
789
790 const GURL kUrl1("http://foo.com");
791 SetContents(CreateTestWebContents());
792 NavigateAndCommit(kUrl1);
793 EXPECT_NE(spare_rph, main_test_rfh()->GetProcess());
794 }
795
752 } // namespace content 796 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.cc ('k') | content/public/browser/render_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698