This source file includes following definitions.
- For
- GetPendingForController
- IsRenderViewHostSwappedOut
- TestOnMessageReceived
- HasTouchEventHandler
- rfh_factory_
- controller
- web_contents
- rvh
- pending_rvh
- active_rvh
- main_rfh
- browser_context
- process
- DeleteContents
- SetContents
- CreateTestWebContents
- NavigateAndCommit
- Reload
- FailedReload
- SetUp
- TearDown
- CreateBrowserContext
- SetRenderProcessHostFactory
#include "content/public/test/test_renderer_host.h"
#include "base/run_loop.h"
#include "content/browser/frame_host/navigation_entry_impl.h"
#include "content/browser/renderer_host/render_view_host_factory.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/browser/site_instance_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.h"
#include "content/test/test_render_frame_host_factory.h"
#include "content/test/test_render_view_host.h"
#include "content/test/test_render_view_host_factory.h"
#include "content/test/test_web_contents.h"
#if defined(OS_WIN)
#include "ui/base/win/scoped_ole_initializer.h"
#endif
#if defined(USE_AURA)
#include "ui/aura/test/aura_test_helper.h"
#include "ui/compositor/test/context_factories_for_test.h"
#endif
namespace content {
RenderViewHostTester* RenderViewHostTester::For(RenderViewHost* host) {
return static_cast<TestRenderViewHost*>(host);
}
RenderViewHost* RenderViewHostTester::GetPendingForController(
NavigationController* controller) {
WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
controller->GetWebContents());
return web_contents->GetRenderManagerForTesting()->pending_render_view_host();
}
bool RenderViewHostTester::IsRenderViewHostSwappedOut(RenderViewHost* rvh) {
return static_cast<RenderViewHostImpl*>(rvh)->rvh_state() ==
RenderViewHostImpl::STATE_SWAPPED_OUT;
}
bool RenderViewHostTester::TestOnMessageReceived(RenderViewHost* rvh,
const IPC::Message& msg) {
return static_cast<RenderViewHostImpl*>(rvh)->OnMessageReceived(msg);
}
bool RenderViewHostTester::HasTouchEventHandler(RenderViewHost* rvh) {
RenderWidgetHostImpl* host_impl = RenderWidgetHostImpl::From(rvh);
return host_impl->has_touch_handler();
}
RenderViewHostTestEnabler::RenderViewHostTestEnabler()
: rph_factory_(new MockRenderProcessHostFactory()),
rvh_factory_(new TestRenderViewHostFactory(rph_factory_.get())),
rfh_factory_(new TestRenderFrameHostFactory()) {}
RenderViewHostTestEnabler::~RenderViewHostTestEnabler() {
}
RenderViewHostTestHarness::RenderViewHostTestHarness()
: thread_bundle_options_(TestBrowserThreadBundle::DEFAULT) {}
RenderViewHostTestHarness::~RenderViewHostTestHarness() {
}
NavigationController& RenderViewHostTestHarness::controller() {
return web_contents()->GetController();
}
WebContents* RenderViewHostTestHarness::web_contents() {
return contents_.get();
}
RenderViewHost* RenderViewHostTestHarness::rvh() {
return web_contents()->GetRenderViewHost();
}
RenderViewHost* RenderViewHostTestHarness::pending_rvh() {
return static_cast<TestWebContents*>(web_contents())->
GetRenderManagerForTesting()->pending_render_view_host();
}
RenderViewHost* RenderViewHostTestHarness::active_rvh() {
return pending_rvh() ? pending_rvh() : rvh();
}
RenderFrameHost* RenderViewHostTestHarness::main_rfh() {
WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
this->web_contents());
return web_contents->GetFrameTree()->GetMainFrame();
}
BrowserContext* RenderViewHostTestHarness::browser_context() {
return browser_context_.get();
}
MockRenderProcessHost* RenderViewHostTestHarness::process() {
return static_cast<MockRenderProcessHost*>(active_rvh()->GetProcess());
}
void RenderViewHostTestHarness::DeleteContents() {
SetContents(NULL);
}
void RenderViewHostTestHarness::SetContents(WebContents* contents) {
contents_.reset(contents);
}
WebContents* RenderViewHostTestHarness::CreateTestWebContents() {
#if defined(OS_WIN)
DCHECK(ole_initializer_ != NULL);
#endif
#if defined(USE_AURA)
DCHECK(aura_test_helper_ != NULL);
#endif
SiteInstance* instance = SiteInstance::Create(browser_context_.get());
return TestWebContents::Create(browser_context_.get(), instance);
}
void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) {
static_cast<TestWebContents*>(web_contents())->NavigateAndCommit(url);
}
void RenderViewHostTestHarness::Reload() {
NavigationEntry* entry = controller().GetLastCommittedEntry();
DCHECK(entry);
controller().Reload(false);
static_cast<TestRenderViewHost*>(
rvh())->SendNavigate(entry->GetPageID(), entry->GetURL());
}
void RenderViewHostTestHarness::FailedReload() {
NavigationEntry* entry = controller().GetLastCommittedEntry();
DCHECK(entry);
controller().Reload(false);
static_cast<TestRenderViewHost*>(
rvh())->SendFailedNavigate(entry->GetPageID(), entry->GetURL());
}
void RenderViewHostTestHarness::SetUp() {
thread_bundle_.reset(new TestBrowserThreadBundle(thread_bundle_options_));
#if defined(OS_WIN)
ole_initializer_.reset(new ui::ScopedOleInitializer());
#endif
#if defined(USE_AURA)
bool enable_pixel_output = false;
ui::InitializeContextFactoryForTests(enable_pixel_output);
aura_test_helper_.reset(
new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
aura_test_helper_->SetUp();
#endif
DCHECK(!browser_context_);
browser_context_.reset(CreateBrowserContext());
SetContents(CreateTestWebContents());
}
void RenderViewHostTestHarness::TearDown() {
SetContents(NULL);
#if defined(USE_AURA)
aura_test_helper_->TearDown();
ui::TerminateContextFactoryForTests();
#endif
base::RunLoop().RunUntilIdle();
#if defined(OS_WIN)
ole_initializer_.reset();
#endif
if (rvh_test_enabler_.rph_factory_)
rvh_test_enabler_.rph_factory_.reset();
BrowserThread::DeleteSoon(content::BrowserThread::UI,
FROM_HERE,
browser_context_.release());
thread_bundle_.reset();
}
BrowserContext* RenderViewHostTestHarness::CreateBrowserContext() {
return new TestBrowserContext();
}
void RenderViewHostTestHarness::SetRenderProcessHostFactory(
RenderProcessHostFactory* factory) {
rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory);
}
}