Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Unified Diff: content/browser/renderer_host/test_render_view_host.cc

Issue 9645003: Introduce abstractions to allow embedders to test RenderViewHost (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/test_render_view_host.cc
diff --git a/content/browser/renderer_host/test_render_view_host.cc b/content/browser/renderer_host/test_render_view_host.cc
index 0d9649896ba4e59de07211380e2e14d9b074af1c..aaca86e5d6cf6fb4ae740e6f458da930b85f5341 100644
--- a/content/browser/renderer_host/test_render_view_host.cc
+++ b/content/browser/renderer_host/test_render_view_host.cc
@@ -7,30 +7,16 @@
#include "content/browser/renderer_host/test_render_view_host.h"
#include "content/browser/site_instance_impl.h"
#include "content/browser/tab_contents/navigation_controller_impl.h"
-#include "content/browser/tab_contents/navigation_entry_impl.h"
#include "content/browser/tab_contents/test_tab_contents.h"
#include "content/common/dom_storage_common.h"
#include "content/common/view_messages.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/common/content_client.h"
-#include "content/test/test_browser_context.h"
#include "ui/gfx/rect.h"
#include "webkit/forms/password_form.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/glue/webpreferences.h"
-#if defined(USE_AURA)
-#include "ui/aura/root_window.h"
-#include "ui/aura/test/test_stacking_client.h"
-#endif
-
-using content::NavigationController;
-using content::NavigationEntry;
-using content::RenderViewHostDelegate;
-using content::RenderWidgetHost;
-using content::SessionStorageNamespace;
-using content::SiteInstance;
-using content::TestRenderViewHost;
using webkit::forms::PasswordForm;
namespace content {
@@ -55,115 +41,6 @@ void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params,
params->content_state = webkit_glue::CreateHistoryStateForURL(GURL(url));
}
-TestRenderViewHost* TestRenderViewHost::GetPendingForController(
- NavigationController* controller) {
- TabContents* tab_contents = static_cast<TabContents*>(
- controller->GetWebContents());
- return static_cast<TestRenderViewHost*>(
- tab_contents->GetRenderManagerForTesting()->pending_render_view_host());
-}
-
-TestRenderViewHost::TestRenderViewHost(SiteInstance* instance,
- RenderViewHostDelegate* delegate,
- int routing_id)
- : RenderViewHostImpl(instance,
- delegate,
- routing_id,
- kInvalidSessionStorageNamespaceId),
- render_view_created_(false),
- delete_counter_(NULL),
- simulate_fetch_via_proxy_(false),
- contents_mime_type_("text/html") {
- // For normal RenderViewHosts, this is freed when |Shutdown()| is called.
- // For TestRenderViewHost, the view is explicitly deleted in the destructor
- // below, because TestRenderWidgetHostView::Destroy() doesn't |delete this|.
- SetView(new TestRenderWidgetHostView(this));
-}
-
-TestRenderViewHost::~TestRenderViewHost() {
- if (delete_counter_)
- ++*delete_counter_;
-
- // Since this isn't a traditional view, we have to delete it.
- delete GetView();
-}
-
-bool TestRenderViewHost::CreateRenderView(const string16& frame_name,
- int32 max_page_id) {
- DCHECK(!render_view_created_);
- render_view_created_ = true;
- return true;
-}
-
-bool TestRenderViewHost::IsRenderViewLive() const {
- return render_view_created_;
-}
-
-// static
-bool TestRenderViewHost::IsRenderViewHostSwappedOut(RenderViewHost* rwh) {
- return static_cast<RenderViewHostImpl*>(rwh)->is_swapped_out();
-}
-
-// static
-void TestRenderViewHost::EnableAccessibilityUpdatedNotifications(
- RenderViewHost* rvh) {
- static_cast<RenderViewHostImpl*>(
- rvh)->set_send_accessibility_updated_notifications(true);
-}
-
-bool TestRenderViewHost::TestOnMessageReceived(const IPC::Message& msg) {
- return OnMessageReceived(msg);
-}
-
-void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) {
- SendNavigateWithTransition(page_id, url, PAGE_TRANSITION_LINK);
-}
-
-void TestRenderViewHost::SendNavigateWithTransition(
- int page_id, const GURL& url, PageTransition transition) {
- ViewHostMsg_FrameNavigate_Params params;
-
- params.page_id = page_id;
- params.url = url;
- params.referrer = Referrer();
- params.transition = transition;
- params.redirects = std::vector<GURL>();
- params.should_update_history = true;
- params.searchable_form_url = GURL();
- params.searchable_form_encoding = std::string();
- params.password_form = PasswordForm();
- params.security_info = std::string();
- params.gesture = NavigationGestureUser;
- params.contents_mime_type = contents_mime_type_;
- params.is_post = false;
- params.was_within_same_page = false;
- params.http_status_code = 0;
- params.socket_address.set_host("2001:db8::1");
- params.socket_address.set_port(80);
- params.was_fetched_via_proxy = simulate_fetch_via_proxy_;
- params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url));
-
- ViewHostMsg_FrameNavigate msg(1, params);
- OnMsgNavigate(msg);
-}
-
-void TestRenderViewHost::SendShouldCloseACK(bool proceed) {
- OnMsgShouldCloseACK(proceed, base::TimeTicks(), base::TimeTicks());
-}
-
-void TestRenderViewHost::TestOnMsgStartDragging(const WebDropData& drop_data) {
- WebKit::WebDragOperationsMask drag_operation = WebKit::WebDragOperationEvery;
- OnMsgStartDragging(drop_data, drag_operation, SkBitmap(), gfx::Point());
-}
-
-void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy) {
- simulate_fetch_via_proxy_ = proxy;
-}
-
-void TestRenderViewHost::set_contents_mime_type(const std::string& mime_type) {
- contents_mime_type_ = mime_type;
-}
-
TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost* rwh)
: rwh_(RenderWidgetHostImpl::From(rwh)),
is_showing_(false) {
@@ -316,125 +193,125 @@ bool TestRenderWidgetHostView::LockMouse() {
void TestRenderWidgetHostView::UnlockMouse() {
}
-} // namespace content
-
-TestRenderViewHostFactory::TestRenderViewHostFactory(
- content::RenderProcessHostFactory* rph_factory)
- : render_process_host_factory_(rph_factory) {
- RenderViewHostFactory::RegisterFactory(this);
+TestRenderViewHost::TestRenderViewHost(SiteInstance* instance,
+ RenderViewHostDelegate* delegate,
+ int routing_id)
+ : RenderViewHostImpl(instance,
+ delegate,
+ routing_id,
+ kInvalidSessionStorageNamespaceId),
+ render_view_created_(false),
+ delete_counter_(NULL),
+ simulate_fetch_via_proxy_(false),
+ contents_mime_type_("text/html") {
+ // For normal RenderViewHosts, this is freed when |Shutdown()| is
+ // called. For TestRenderViewHost, the view is explicitly
+ // deleted in the destructor below, because
+ // TestRenderWidgetHostView::Destroy() doesn't |delete this|.
+ SetView(new TestRenderWidgetHostView(this));
}
-TestRenderViewHostFactory::~TestRenderViewHostFactory() {
- RenderViewHostFactory::UnregisterFactory();
-}
+TestRenderViewHost::~TestRenderViewHost() {
+ if (delete_counter_)
+ ++*delete_counter_;
-void TestRenderViewHostFactory::set_render_process_host_factory(
- content::RenderProcessHostFactory* rph_factory) {
- render_process_host_factory_ = rph_factory;
+ // Since this isn't a traditional view, we have to delete it.
+ delete GetView();
}
-content::RenderViewHost* TestRenderViewHostFactory::CreateRenderViewHost(
- SiteInstance* instance,
- RenderViewHostDelegate* delegate,
- int routing_id,
- SessionStorageNamespace* session_storage) {
- // See declaration of render_process_host_factory_ below.
- static_cast<SiteInstanceImpl*>(instance)->
- set_render_process_host_factory(render_process_host_factory_);
- return new TestRenderViewHost(instance, delegate, routing_id);
+bool TestRenderViewHost::CreateRenderView(const string16& frame_name,
+ int32 max_page_id) {
+ DCHECK(!render_view_created_);
+ render_view_created_ = true;
+ return true;
}
-RenderViewHostTestHarness::RenderViewHostTestHarness()
- : rph_factory_(),
- rvh_factory_(&rph_factory_),
- contents_(NULL) {
+bool TestRenderViewHost::IsRenderViewLive() const {
+ return render_view_created_;
}
-RenderViewHostTestHarness::~RenderViewHostTestHarness() {
+void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) {
+ SendNavigateWithTransition(page_id, url, PAGE_TRANSITION_LINK);
}
-NavigationController& RenderViewHostTestHarness::controller() {
- return contents()->GetController();
-}
+void TestRenderViewHost::SendNavigateWithTransition(
+ int page_id, const GURL& url, PageTransition transition) {
+ ViewHostMsg_FrameNavigate_Params params;
-TestTabContents* RenderViewHostTestHarness::contents() {
- return contents_.get();
-}
+ params.page_id = page_id;
+ params.url = url;
+ params.referrer = Referrer();
+ params.transition = transition;
+ params.redirects = std::vector<GURL>();
+ params.should_update_history = true;
+ params.searchable_form_url = GURL();
+ params.searchable_form_encoding = std::string();
+ params.password_form = PasswordForm();
+ params.security_info = std::string();
+ params.gesture = NavigationGestureUser;
+ params.contents_mime_type = contents_mime_type_;
+ params.is_post = false;
+ params.was_within_same_page = false;
+ params.http_status_code = 0;
+ params.socket_address.set_host("2001:db8::1");
+ params.socket_address.set_port(80);
+ params.was_fetched_via_proxy = simulate_fetch_via_proxy_;
+ params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url));
-TestRenderViewHost* RenderViewHostTestHarness::rvh() {
- return static_cast<TestRenderViewHost*>(contents()->GetRenderViewHost());
+ ViewHostMsg_FrameNavigate msg(1, params);
+ OnMsgNavigate(msg);
}
-TestRenderViewHost* RenderViewHostTestHarness::pending_rvh() {
- return static_cast<TestRenderViewHost*>(
- contents()->GetRenderManagerForTesting()->pending_render_view_host());
+void TestRenderViewHost::SendShouldCloseACK(bool proceed) {
+ OnMsgShouldCloseACK(proceed, base::TimeTicks(), base::TimeTicks());
}
-TestRenderViewHost* RenderViewHostTestHarness::active_rvh() {
- return pending_rvh() ? pending_rvh() : rvh();
+void TestRenderViewHost::SetContentsMimeType(const std::string& mime_type) {
+ contents_mime_type_ = mime_type;
}
-content::BrowserContext* RenderViewHostTestHarness::browser_context() {
- return browser_context_.get();
+void TestRenderViewHost::SimulateSwapOutACK() {
+ OnSwapOutACK();
}
-MockRenderProcessHost* RenderViewHostTestHarness::process() {
- if (pending_rvh())
- return static_cast<MockRenderProcessHost*>(pending_rvh()->GetProcess());
- return static_cast<MockRenderProcessHost*>(rvh()->GetProcess());
+void TestRenderViewHost::SimulateWasHidden() {
+ WasHidden();
}
-void RenderViewHostTestHarness::DeleteContents() {
- SetContents(NULL);
+void TestRenderViewHost::SimulateWasRestored() {
+ WasRestored();
}
-void RenderViewHostTestHarness::SetContents(TestTabContents* contents) {
- contents_.reset(contents);
+bool TestRenderViewHost::TestOnMessageReceived(const IPC::Message& msg) {
+ return OnMessageReceived(msg);
}
-TestTabContents* RenderViewHostTestHarness::CreateTestTabContents() {
- // See comment above browser_context_ decl for why we check for NULL here.
- if (!browser_context_.get())
- browser_context_.reset(new TestBrowserContext());
-
- // This will be deleted when the TabContents goes away.
- SiteInstance* instance = SiteInstance::Create(browser_context_.get());
-
- return new TestTabContents(browser_context_.get(), instance);
+void TestRenderViewHost::TestOnMsgStartDragging(
+ const WebDropData& drop_data) {
+ WebKit::WebDragOperationsMask drag_operation = WebKit::WebDragOperationEvery;
+ OnMsgStartDragging(drop_data, drag_operation, SkBitmap(), gfx::Point());
}
-void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) {
- contents()->NavigateAndCommit(url);
+void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy) {
+ simulate_fetch_via_proxy_ = proxy;
}
-void RenderViewHostTestHarness::Reload() {
- NavigationEntry* entry = controller().GetLastCommittedEntry();
- DCHECK(entry);
- controller().Reload(false);
- rvh()->SendNavigate(entry->GetPageID(), entry->GetURL());
+RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
}
-void RenderViewHostTestHarness::SetUp() {
-#if defined(USE_AURA)
- root_window_.reset(new aura::RootWindow);
- test_stacking_client_.reset(
- new aura::test::TestStackingClient(root_window_.get()));
-#endif
- SetContents(CreateTestTabContents());
+RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
}
-void RenderViewHostTestHarness::TearDown() {
- SetContents(NULL);
-#if defined(USE_AURA)
- test_stacking_client_.reset();
- root_window_.reset();
-#endif
+TestRenderViewHost* RenderViewHostImplTestHarness::test_rvh() {
+ return static_cast<TestRenderViewHost*>(rvh());
+}
- // Make sure that we flush any messages related to TabContents destruction
- // before we destroy the browser context.
- MessageLoop::current()->RunAllPending();
+TestRenderViewHost* RenderViewHostImplTestHarness::pending_test_rvh() {
+ return static_cast<TestRenderViewHost*>(pending_rvh());
+}
- // Release the browser context on the UI thread.
- message_loop_.DeleteSoon(FROM_HERE, browser_context_.release());
- message_loop_.RunAllPending();
+TestRenderViewHost* RenderViewHostImplTestHarness::active_test_rvh() {
+ return static_cast<TestRenderViewHost*>(active_rvh());
}
+
+} // namespace content
« no previous file with comments | « content/browser/renderer_host/test_render_view_host.h ('k') | content/browser/site_instance_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698