Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / content / public / test / test_renderer_host.cc
index 80eada2..e96a13c 100644 (file)
@@ -8,12 +8,14 @@
 #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/renderer_host/test_render_view_host.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.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(USE_AURA)
 #include "ui/aura/test/aura_test_helper.h"
+#include "ui/compositor/test/context_factories_for_test.h"
+#include "ui/wm/core/default_activation_client.h"
 #endif
 
 namespace content {
 
+// RenderFrameHostTester ------------------------------------------------------
+
+// static
+RenderFrameHostTester* RenderFrameHostTester::For(RenderFrameHost* host) {
+  return static_cast<TestRenderFrameHost*>(host);
+}
+
 // RenderViewHostTester -------------------------------------------------------
 
 // static
@@ -44,7 +55,8 @@ RenderViewHost* RenderViewHostTester::GetPendingForController(
 
 // static
 bool RenderViewHostTester::IsRenderViewHostSwappedOut(RenderViewHost* rvh) {
-  return static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out();
+  return static_cast<RenderViewHostImpl*>(rvh)->rvh_state() ==
+         RenderViewHostImpl::STATE_SWAPPED_OUT;
 }
 
 // static
@@ -64,8 +76,8 @@ bool RenderViewHostTester::HasTouchEventHandler(RenderViewHost* rvh) {
 
 RenderViewHostTestEnabler::RenderViewHostTestEnabler()
     : rph_factory_(new MockRenderProcessHostFactory()),
-      rvh_factory_(new TestRenderViewHostFactory(rph_factory_.get())) {
-}
+      rvh_factory_(new TestRenderViewHostFactory(rph_factory_.get())),
+      rfh_factory_(new TestRenderFrameHostFactory()) {}
 
 RenderViewHostTestEnabler::~RenderViewHostTestEnabler() {
 }
@@ -88,18 +100,27 @@ WebContents* RenderViewHostTestHarness::web_contents() {
 }
 
 RenderViewHost* RenderViewHostTestHarness::rvh() {
-  return web_contents()->GetRenderViewHost();
+  RenderViewHost* result = web_contents()->GetRenderViewHost();
+  CHECK_EQ(result, web_contents()->GetMainFrame()->GetRenderViewHost());
+  return result;
 }
 
 RenderViewHost* RenderViewHostTestHarness::pending_rvh() {
-  return static_cast<TestWebContents*>(web_contents())->
-      GetRenderManagerForTesting()->pending_render_view_host();
+  return pending_main_rfh() ? pending_main_rfh()->GetRenderViewHost() : NULL;
 }
 
 RenderViewHost* RenderViewHostTestHarness::active_rvh() {
   return pending_rvh() ? pending_rvh() : rvh();
 }
 
+RenderFrameHost* RenderViewHostTestHarness::main_rfh() {
+  return web_contents()->GetMainFrame();
+}
+
+RenderFrameHost* RenderViewHostTestHarness::pending_main_rfh() {
+  return WebContentsTester::For(web_contents())->GetPendingMainFrame();
+}
+
 BrowserContext* RenderViewHostTestHarness::browser_context() {
   return browser_context_.get();
 }
@@ -140,7 +161,8 @@ void RenderViewHostTestHarness::Reload() {
   DCHECK(entry);
   controller().Reload(false);
   static_cast<TestRenderViewHost*>(
-      rvh())->SendNavigate(entry->GetPageID(), entry->GetURL());
+      rvh())->SendNavigateWithTransition(
+          entry->GetPageID(), entry->GetURL(), PAGE_TRANSITION_RELOAD);
 }
 
 void RenderViewHostTestHarness::FailedReload() {
@@ -158,9 +180,15 @@ void RenderViewHostTestHarness::SetUp() {
   ole_initializer_.reset(new ui::ScopedOleInitializer());
 #endif
 #if defined(USE_AURA)
+  // The ContextFactory must exist before any Compositors are created.
+  bool enable_pixel_output = false;
+  ui::ContextFactory* context_factory =
+      ui::InitializeContextFactoryForTests(enable_pixel_output);
+
   aura_test_helper_.reset(
       new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
-  aura_test_helper_->SetUp();
+  aura_test_helper_->SetUp(context_factory);
+  new wm::DefaultActivationClient(aura_test_helper_->root_window());
 #endif
 
   DCHECK(!browser_context_);
@@ -173,6 +201,7 @@ void RenderViewHostTestHarness::TearDown() {
   SetContents(NULL);
 #if defined(USE_AURA)
   aura_test_helper_->TearDown();
+  ui::TerminateContextFactoryForTests();
 #endif
   // Make sure that we flush any messages related to WebContentsImpl destruction
   // before we destroy the browser context.