Chromium Code Reviews| 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 13825258663da34a2260345b379d40f1a580f3d9..92e244a68649a36b58edb741179815152c08db76 100644 |
| --- a/content/browser/renderer_host/render_process_host_unittest.cc |
| +++ b/content/browser/renderer_host/render_process_host_unittest.cc |
| @@ -11,10 +11,12 @@ |
| #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/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" |
| @@ -478,4 +480,44 @@ 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 = 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 = rph_factory_.GetProcesses()->at(0).get(); |
| + |
| + const GURL kUrl1("http://foo.com"); |
| + SetContents(CreateTestWebContents()); |
| + NavigateAndCommit(kUrl1); |
| + EXPECT_NE(spare_rph, main_test_rfh()->GetProcess()); |
| +} |
| + |
| +// TODO(mattcary): test storage partition shutdown |
|
Benoit L
2017/06/15 22:17:11
Can you also test the case where the process dies?
mattcary
2017/06/16 08:18:56
That seems to be hard to do in the unittests, but
|
| + |
| } // namespace content |