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/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 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 // REUSE_PENDING_OR_COMMITTED_SITE policy should now return the process of the | 658 // REUSE_PENDING_OR_COMMITTED_SITE policy should now return the process of the |
657 // main RFH, as it was registered with the regular site URL when it committed. | 659 // main RFH, as it was registered with the regular site URL when it committed. |
658 main_test_rfh()->PrepareForCommit(); | 660 main_test_rfh()->PrepareForCommit(); |
659 main_test_rfh()->SendNavigate(0, true, kUrl); | 661 main_test_rfh()->SendNavigate(0, true, kUrl); |
660 site_instance = SiteInstanceImpl::CreateForURL(browser_context(), kUrl); | 662 site_instance = SiteInstanceImpl::CreateForURL(browser_context(), kUrl); |
661 site_instance->set_process_reuse_policy( | 663 site_instance->set_process_reuse_policy( |
662 SiteInstanceImpl::ProcessReusePolicy::REUSE_PENDING_OR_COMMITTED_SITE); | 664 SiteInstanceImpl::ProcessReusePolicy::REUSE_PENDING_OR_COMMITTED_SITE); |
663 EXPECT_EQ(main_test_rfh()->GetProcess(), site_instance->GetProcess()); | 665 EXPECT_EQ(main_test_rfh()->GetProcess(), site_instance->GetProcess()); |
664 } | 666 } |
665 | 667 |
| 668 class SpareRenderProcessHostUnitTest : public RenderViewHostImplTestHarness { |
| 669 protected: |
| 670 void SetUp() override { |
| 671 SetRenderProcessHostFactory(&rph_factory_); |
| 672 RenderViewHostImplTestHarness::SetUp(); |
| 673 SetContents(NULL); // Start with no renderers. |
| 674 while (!rph_factory_.GetProcesses()->empty()) { |
| 675 rph_factory_.Remove(rph_factory_.GetProcesses()->back().get()); |
| 676 } |
| 677 } |
| 678 |
| 679 MockRenderProcessHostFactory rph_factory_; |
| 680 }; |
| 681 |
| 682 TEST_F(SpareRenderProcessHostUnitTest, TestRendererTaken) { |
| 683 RenderProcessHost::WarmupSpareRenderProcessHost(browser_context()); |
| 684 ASSERT_EQ(1U, rph_factory_.GetProcesses()->size()); |
| 685 RenderProcessHost* spare_rph = rph_factory_.GetProcesses()->at(0).get(); |
| 686 |
| 687 const GURL kUrl1("http://foo.com"); |
| 688 SetContents(CreateTestWebContents()); |
| 689 NavigateAndCommit(kUrl1); |
| 690 EXPECT_EQ(spare_rph, main_test_rfh()->GetProcess()); |
| 691 ASSERT_EQ(1U, rph_factory_.GetProcesses()->size()); |
| 692 } |
| 693 |
| 694 TEST_F(SpareRenderProcessHostUnitTest, TestRendererNotTaken) { |
| 695 std::unique_ptr<BrowserContext> alternate_context(new TestBrowserContext()); |
| 696 RenderProcessHost::WarmupSpareRenderProcessHost(alternate_context.get()); |
| 697 ASSERT_EQ(1U, rph_factory_.GetProcesses()->size()); |
| 698 RenderProcessHost* spare_rph = rph_factory_.GetProcesses()->at(0).get(); |
| 699 |
| 700 const GURL kUrl1("http://foo.com"); |
| 701 SetContents(CreateTestWebContents()); |
| 702 NavigateAndCommit(kUrl1); |
| 703 EXPECT_NE(spare_rph, main_test_rfh()->GetProcess()); |
| 704 } |
| 705 |
666 } // namespace content | 706 } // namespace content |
OLD | NEW |