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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_process_host_unittest.cc
diff --git a/content/browser/renderer_host/render_process_host_unittest.cc b/content/browser/renderer_host/render_process_host_unittest.cc
index 267eb83db4833e8cf2aba9ff405efeee8f06f4b1..4753d921e4171a1260e104eb97d14a7a7c90ff0f 100644
--- a/content/browser/renderer_host/render_process_host_unittest.cc
+++ b/content/browser/renderer_host/render_process_host_unittest.cc
@@ -12,11 +12,13 @@
#include "base/memory/ptr_util.h"
#include "build/build_config.h"
#include "content/common/frame_messages.h"
+#include "content/public/browser/browser_context.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/browser_side_navigation_policy.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/mock_render_process_host.h"
+#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_utils.h"
#include "content/test/test_render_frame_host.h"
#include "content/test/test_render_view_host.h"
@@ -749,4 +751,46 @@ TEST_F(RenderProcessHostUnitTest, ReuseExpectedSiteURLChanges) {
EXPECT_EQ(main_test_rfh()->GetProcess(), site_instance->GetProcess());
}
+class SpareRenderProcessHostUnitTest : public RenderViewHostImplTestHarness {
+ protected:
+ void SetUp() override {
+ SetRenderProcessHostFactory(&rph_factory_);
+ RenderViewHostImplTestHarness::SetUp();
+ SetContents(NULL); // Start with no renderers.
+ while (!rph_factory_.GetProcesses()->empty()) {
+ rph_factory_.Remove(rph_factory_.GetProcesses()->back().get());
+ }
+ }
+
+ MockRenderProcessHostFactory rph_factory_;
+};
+
+TEST_F(SpareRenderProcessHostUnitTest, TestRendererTaken) {
+ RenderProcessHost::WarmupSpareRenderProcessHost(browser_context());
+ ASSERT_EQ(1U, rph_factory_.GetProcesses()->size());
+ RenderProcessHost* spare_rph =
+ RenderProcessHostImpl::GetSpareRenderProcessHostForTesting();
+ EXPECT_EQ(spare_rph, rph_factory_.GetProcesses()->at(0).get());
+
+ const GURL kUrl1("http://foo.com");
+ SetContents(CreateTestWebContents());
+ NavigateAndCommit(kUrl1);
+ EXPECT_EQ(spare_rph, main_test_rfh()->GetProcess());
+ ASSERT_EQ(1U, rph_factory_.GetProcesses()->size());
+}
+
+TEST_F(SpareRenderProcessHostUnitTest, TestRendererNotTaken) {
+ std::unique_ptr<BrowserContext> alternate_context(new TestBrowserContext());
+ RenderProcessHost::WarmupSpareRenderProcessHost(alternate_context.get());
+ ASSERT_EQ(1U, rph_factory_.GetProcesses()->size());
+ RenderProcessHost* spare_rph =
+ RenderProcessHostImpl::GetSpareRenderProcessHostForTesting();
+ EXPECT_EQ(spare_rph, rph_factory_.GetProcesses()->at(0).get());
+
+ const GURL kUrl1("http://foo.com");
+ SetContents(CreateTestWebContents());
+ NavigateAndCommit(kUrl1);
+ EXPECT_NE(spare_rph, main_test_rfh()->GetProcess());
+}
+
} // namespace content
« 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