Commit ca02dc4c authored by Aaron Colwell's avatar Aaron Colwell Committed by Commit Bot

Remove MockRenderProcessHost::set_is_for_guest_only()

Removing method and updating tests that use it so that the mock behaves
more like the production code.

- Removed setter method.
- Added is_for_guest_only constructor param similar to
  RenderProcessHostImpl.
- Updated MockRenderProcessHostFactory to provide the is_for_guest_only
  parameter based on the SiteInstance::IsGuest() method just like
  RenderProcessHostImpl::CreateRenderProcessHost() does.
- Updated NavigationControllerTest.ReloadWithGuest to actually use a
  guest WebContents so that it doesn't need to change the flag on the
  process to achieve a guest reload.


Bug: 1085275
Change-Id: I23c3db1a810ea6d1f0d7ce9e554585e1caf6b297
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354832
Commit-Queue: Nasko Oskov <nasko@chromium.org>
Auto-Submit: Aaron Colwell <acolwell@chromium.org>
Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797898}
parent 1e50eaad
...@@ -1237,17 +1237,23 @@ TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { ...@@ -1237,17 +1237,23 @@ TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) {
// without ending up in the "we have a wrong process for the URL" branch in // without ending up in the "we have a wrong process for the URL" branch in
// NavigationControllerImpl::ReloadInternal. // NavigationControllerImpl::ReloadInternal.
TEST_F(NavigationControllerTest, ReloadWithGuest) { TEST_F(NavigationControllerTest, ReloadWithGuest) {
NavigationControllerImpl& controller = controller_impl(); const GURL kGuestSiteUrl("my-guest-scheme://someapp/somepath");
scoped_refptr<SiteInstance> guest_instance =
SiteInstance::CreateForGuest(browser_context(), kGuestSiteUrl);
std::unique_ptr<TestWebContents> guest_web_contents(
TestWebContents::Create(browser_context(), guest_instance));
NavigationControllerImpl& controller = guest_web_contents->GetController();
const GURL url1("http://foo1"); const GURL url1("http://foo1");
NavigationSimulator::NavigateAndCommitFromBrowser(contents(), url1); NavigationSimulator::NavigateAndCommitFromBrowser(guest_web_contents.get(),
url1);
ASSERT_TRUE(controller.GetVisibleEntry()); ASSERT_TRUE(controller.GetVisibleEntry());
// Make the entry believe its RenderProcessHost is a guest. // Make the entry believe its RenderProcessHost is a guest.
NavigationEntryImpl* entry1 = controller.GetVisibleEntry(); NavigationEntryImpl* entry1 = controller.GetVisibleEntry();
reinterpret_cast<MockRenderProcessHost*>( ASSERT_EQ(entry1->site_instance(), guest_instance);
entry1->site_instance()->GetProcess()) ASSERT_TRUE(entry1->site_instance()->IsGuest());
->set_is_for_guests_only(true); ASSERT_TRUE(entry1->site_instance()->GetProcess()->IsForGuestsOnly());
// And reload. // And reload.
controller.Reload(ReloadType::NORMAL, true); controller.Reload(ReloadType::NORMAL, true);
......
...@@ -41,8 +41,8 @@ class RenderProcessHostUnitTest : public RenderViewHostImplTestHarness {}; ...@@ -41,8 +41,8 @@ class RenderProcessHostUnitTest : public RenderViewHostImplTestHarness {};
TEST_F(RenderProcessHostUnitTest, GuestsAreNotSuitableHosts) { TEST_F(RenderProcessHostUnitTest, GuestsAreNotSuitableHosts) {
GURL test_url("http://foo.com"); GURL test_url("http://foo.com");
MockRenderProcessHost guest_host(browser_context()); MockRenderProcessHost guest_host(browser_context(),
guest_host.set_is_for_guests_only(true); /*is_for_guest_only=*/true);
scoped_refptr<SiteInstanceImpl> site_instance = scoped_refptr<SiteInstanceImpl> site_instance =
SiteInstanceImpl::CreateForURL(browser_context(), test_url); SiteInstanceImpl::CreateForURL(browser_context(), test_url);
......
...@@ -53,7 +53,8 @@ GetNetworkFactoryCallback() { ...@@ -53,7 +53,8 @@ GetNetworkFactoryCallback() {
} // namespace } // namespace
MockRenderProcessHost::MockRenderProcessHost(BrowserContext* browser_context) MockRenderProcessHost::MockRenderProcessHost(BrowserContext* browser_context,
bool is_for_guests_only)
: bad_msg_count_(0), : bad_msg_count_(0),
factory_(nullptr), factory_(nullptr),
id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()),
...@@ -63,7 +64,7 @@ MockRenderProcessHost::MockRenderProcessHost(BrowserContext* browser_context) ...@@ -63,7 +64,7 @@ MockRenderProcessHost::MockRenderProcessHost(BrowserContext* browser_context)
shutdown_requested_(false), shutdown_requested_(false),
fast_shutdown_started_(false), fast_shutdown_started_(false),
deletion_callback_called_(false), deletion_callback_called_(false),
is_for_guests_only_(false), is_for_guests_only_(is_for_guests_only),
is_process_backgrounded_(false), is_process_backgrounded_(false),
is_unused_(true), is_unused_(true),
keep_alive_ref_count_(0), keep_alive_ref_count_(0),
...@@ -533,8 +534,10 @@ MockRenderProcessHostFactory::~MockRenderProcessHostFactory() { ...@@ -533,8 +534,10 @@ MockRenderProcessHostFactory::~MockRenderProcessHostFactory() {
RenderProcessHost* MockRenderProcessHostFactory::CreateRenderProcessHost( RenderProcessHost* MockRenderProcessHostFactory::CreateRenderProcessHost(
BrowserContext* browser_context, BrowserContext* browser_context,
SiteInstance* site_instance) { SiteInstance* site_instance) {
const bool is_for_guests_only = site_instance && site_instance->IsGuest();
std::unique_ptr<MockRenderProcessHost> host = std::unique_ptr<MockRenderProcessHost> host =
std::make_unique<MockRenderProcessHost>(browser_context); std::make_unique<MockRenderProcessHost>(browser_context,
is_for_guests_only);
processes_.push_back(std::move(host)); processes_.push_back(std::move(host));
processes_.back()->SetFactory(this); processes_.back()->SetFactory(this);
return processes_.back().get(); return processes_.back().get();
......
...@@ -55,7 +55,8 @@ class MockRenderProcessHost : public RenderProcessHost { ...@@ -55,7 +55,8 @@ class MockRenderProcessHost : public RenderProcessHost {
using InterfaceBinder = using InterfaceBinder =
base::RepeatingCallback<void(mojo::ScopedMessagePipeHandle)>; base::RepeatingCallback<void(mojo::ScopedMessagePipeHandle)>;
explicit MockRenderProcessHost(BrowserContext* browser_context); explicit MockRenderProcessHost(BrowserContext* browser_context,
bool is_for_guests_only = false);
~MockRenderProcessHost() override; ~MockRenderProcessHost() override;
// Provides access to all IPC messages that would have been sent to the // Provides access to all IPC messages that would have been sent to the
...@@ -230,10 +231,6 @@ class MockRenderProcessHost : public RenderProcessHost { ...@@ -230,10 +231,6 @@ class MockRenderProcessHost : public RenderProcessHost {
factory_ = factory; factory_ = factory;
} }
void set_is_for_guests_only(bool is_for_guests_only) {
is_for_guests_only_ = is_for_guests_only;
}
void set_is_process_backgrounded(bool is_process_backgrounded) { void set_is_process_backgrounded(bool is_process_backgrounded) {
is_process_backgrounded_ = is_process_backgrounded; is_process_backgrounded_ = is_process_backgrounded;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment