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 <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/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "content/common/frame_messages.h" | 13 #include "content/common/frame_messages.h" |
14 #include "content/public/browser/browser_context.h" | |
14 #include "content/public/browser/content_browser_client.h" | 15 #include "content/public/browser/content_browser_client.h" |
15 #include "content/public/common/browser_side_navigation_policy.h" | 16 #include "content/public/common/browser_side_navigation_policy.h" |
16 #include "content/public/common/content_constants.h" | 17 #include "content/public/common/content_constants.h" |
17 #include "content/public/test/mock_render_process_host.h" | 18 #include "content/public/test/mock_render_process_host.h" |
19 #include "content/public/test/test_browser_context.h" | |
18 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
19 #include "content/test/test_render_frame_host.h" | 21 #include "content/test/test_render_frame_host.h" |
20 #include "content/test/test_render_view_host.h" | 22 #include "content/test/test_render_view_host.h" |
21 #include "content/test/test_web_contents.h" | 23 #include "content/test/test_web_contents.h" |
22 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 24 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
23 | 25 |
24 namespace content { | 26 namespace content { |
25 | 27 |
26 class RenderProcessHostUnitTest : public RenderViewHostImplTestHarness {}; | 28 class RenderProcessHostUnitTest : public RenderViewHostImplTestHarness {}; |
27 | 29 |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
471 // REUSE_PENDING_OR_COMMITTED_SITE policy should now return the process of the | 473 // REUSE_PENDING_OR_COMMITTED_SITE policy should now return the process of the |
472 // main RFH, as it was registered with the regular site URL when it committed. | 474 // main RFH, as it was registered with the regular site URL when it committed. |
473 main_test_rfh()->PrepareForCommit(); | 475 main_test_rfh()->PrepareForCommit(); |
474 main_test_rfh()->SendNavigate(0, true, kUrl); | 476 main_test_rfh()->SendNavigate(0, true, kUrl); |
475 site_instance = SiteInstanceImpl::CreateForURL(browser_context(), kUrl); | 477 site_instance = SiteInstanceImpl::CreateForURL(browser_context(), kUrl); |
476 site_instance->set_process_reuse_policy( | 478 site_instance->set_process_reuse_policy( |
477 SiteInstanceImpl::ProcessReusePolicy::REUSE_PENDING_OR_COMMITTED_SITE); | 479 SiteInstanceImpl::ProcessReusePolicy::REUSE_PENDING_OR_COMMITTED_SITE); |
478 EXPECT_EQ(main_test_rfh()->GetProcess(), site_instance->GetProcess()); | 480 EXPECT_EQ(main_test_rfh()->GetProcess(), site_instance->GetProcess()); |
479 } | 481 } |
480 | 482 |
483 class SpareRenderProcessHostUnitTest : public RenderViewHostImplTestHarness { | |
484 protected: | |
485 void SetUp() override { | |
486 SetRenderProcessHostFactory(&rph_factory_); | |
487 RenderViewHostImplTestHarness::SetUp(); | |
488 SetContents(NULL); // Start with no renderers. | |
489 while (!rph_factory_.GetProcesses()->empty()) { | |
490 rph_factory_.Remove(rph_factory_.GetProcesses()->back().get()); | |
491 } | |
492 } | |
493 | |
494 MockRenderProcessHostFactory rph_factory_; | |
495 }; | |
496 | |
497 TEST_F(SpareRenderProcessHostUnitTest, TestRendererTaken) { | |
498 RenderProcessHost::WarmupSpareRenderProcessHost(browser_context()); | |
499 ASSERT_EQ(1U, rph_factory_.GetProcesses()->size()); | |
500 RenderProcessHost* spare_rph = rph_factory_.GetProcesses()->at(0).get(); | |
501 | |
502 const GURL kUrl1("http://foo.com"); | |
503 SetContents(CreateTestWebContents()); | |
504 NavigateAndCommit(kUrl1); | |
505 EXPECT_EQ(spare_rph, main_test_rfh()->GetProcess()); | |
506 ASSERT_EQ(1U, rph_factory_.GetProcesses()->size()); | |
507 } | |
508 | |
509 TEST_F(SpareRenderProcessHostUnitTest, TestRendererNotTaken) { | |
510 std::unique_ptr<BrowserContext> alternate_context(new TestBrowserContext()); | |
511 RenderProcessHost::WarmupSpareRenderProcessHost(alternate_context.get()); | |
512 ASSERT_EQ(1U, rph_factory_.GetProcesses()->size()); | |
513 RenderProcessHost* spare_rph = rph_factory_.GetProcesses()->at(0).get(); | |
514 | |
515 const GURL kUrl1("http://foo.com"); | |
516 SetContents(CreateTestWebContents()); | |
517 NavigateAndCommit(kUrl1); | |
518 EXPECT_NE(spare_rph, main_test_rfh()->GetProcess()); | |
519 } | |
520 | |
521 // 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
| |
522 | |
481 } // namespace content | 523 } // namespace content |
OLD | NEW |