diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-05 18:12:48 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-05 18:12:48 +0000 |
commit | 4bfd46161fb19f9fade9e0be75f4fd0f92900edf (patch) | |
tree | a7203ef154c6db1333cf1de002963cb288747667 /content/test | |
parent | 25342bd3361026a14512e5a7ad46877b17f988ef (diff) | |
download | chromium_src-4bfd46161fb19f9fade9e0be75f4fd0f92900edf.zip chromium_src-4bfd46161fb19f9fade9e0be75f4fd0f92900edf.tar.gz chromium_src-4bfd46161fb19f9fade9e0be75f4fd0f92900edf.tar.bz2 |
Move TestRenderFrameHost, TestRenderViewHost and TestBackingStore to content\test as that's where test-only files go.
BUG=304341
Review URL: https://codereview.chromium.org/105143003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238993 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/test')
-rw-r--r-- | content/test/test_backing_store.cc | 38 | ||||
-rw-r--r-- | content/test/test_backing_store.h | 39 | ||||
-rw-r--r-- | content/test/test_render_frame_host.cc | 22 | ||||
-rw-r--r-- | content/test/test_render_frame_host.h | 31 | ||||
-rw-r--r-- | content/test/test_render_frame_host_factory.cc | 2 | ||||
-rw-r--r-- | content/test/test_render_view_host.cc | 434 | ||||
-rw-r--r-- | content/test/test_render_view_host.h | 386 | ||||
-rw-r--r-- | content/test/test_render_view_host_factory.cc | 2 | ||||
-rw-r--r-- | content/test/test_web_contents.cc | 2 |
9 files changed, 953 insertions, 3 deletions
diff --git a/content/test/test_backing_store.cc b/content/test/test_backing_store.cc new file mode 100644 index 0000000..e9415d2 --- /dev/null +++ b/content/test/test_backing_store.cc @@ -0,0 +1,38 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/test/test_backing_store.h" + +namespace content { + +TestBackingStore::TestBackingStore(RenderWidgetHost* widget, + const gfx::Size& size) + : BackingStore(widget, size) { +} + +TestBackingStore::~TestBackingStore() { +} + +void TestBackingStore::PaintToBackingStore( + RenderProcessHost* process, + TransportDIB::Id bitmap, + const gfx::Rect& bitmap_rect, + const std::vector<gfx::Rect>& copy_rects, + float scale_factor, + const base::Closure& completion_callback, + bool* scheduled_completion_callback) { + *scheduled_completion_callback = false; +} + +bool TestBackingStore::CopyFromBackingStore(const gfx::Rect& rect, + skia::PlatformBitmap* output) { + return false; +} + +void TestBackingStore::ScrollBackingStore(const gfx::Vector2d& delta, + const gfx::Rect& clip_rect, + const gfx::Size& view_size) { +} + +} // namespace content diff --git a/content/test/test_backing_store.h b/content/test/test_backing_store.h new file mode 100644 index 0000000..0ee09f5 --- /dev/null +++ b/content/test/test_backing_store.h @@ -0,0 +1,39 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_TEST_TEST_BACKING_STORE_H_ +#define CONTENT_TEST_TEST_BACKING_STORE_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "content/browser/renderer_host/backing_store.h" + +namespace content { + +class TestBackingStore : public BackingStore { + public: + TestBackingStore(RenderWidgetHost* widget, const gfx::Size& size); + virtual ~TestBackingStore(); + + // BackingStore implementation. + virtual void PaintToBackingStore( + RenderProcessHost* process, + TransportDIB::Id bitmap, + const gfx::Rect& bitmap_rect, + const std::vector<gfx::Rect>& copy_rects, + float scale_factor, + const base::Closure& completion_callback, + bool* scheduled_completion_callback) OVERRIDE; + virtual bool CopyFromBackingStore(const gfx::Rect& rect, + skia::PlatformBitmap* output) OVERRIDE; + virtual void ScrollBackingStore(const gfx::Vector2d& delta, + const gfx::Rect& clip_rect, + const gfx::Size& view_size) OVERRIDE; + private: + DISALLOW_COPY_AND_ASSIGN(TestBackingStore); +}; + +} // namespace content + +#endif // CONTENT_TEST_TEST_BACKING_STORE_H_ diff --git a/content/test/test_render_frame_host.cc b/content/test/test_render_frame_host.cc new file mode 100644 index 0000000..263eb45 --- /dev/null +++ b/content/test/test_render_frame_host.cc @@ -0,0 +1,22 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/test/test_render_frame_host.h" + +namespace content { + +TestRenderFrameHost::TestRenderFrameHost(RenderViewHostImpl* render_view_host, + RenderFrameHostDelegate* delegate, + FrameTree* frame_tree, + int routing_id, + bool is_swapped_out) + : RenderFrameHostImpl(render_view_host, + delegate, + frame_tree, + routing_id, + is_swapped_out) {} + +TestRenderFrameHost::~TestRenderFrameHost() {} + +} // namespace content diff --git a/content/test/test_render_frame_host.h b/content/test/test_render_frame_host.h new file mode 100644 index 0000000..9f74e39 --- /dev/null +++ b/content/test/test_render_frame_host.h @@ -0,0 +1,31 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_ +#define CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_ + +#include "base/basictypes.h" +#include "content/browser/frame_host/render_frame_host_impl.h" + +namespace content { + +class TestRenderFrameHost : public RenderFrameHostImpl { + public: + TestRenderFrameHost(RenderViewHostImpl* render_view_host, + RenderFrameHostDelegate* delegate, + FrameTree* frame_tree, + int routing_id, + bool is_swapped_out); + virtual ~TestRenderFrameHost(); + + // TODO(nick): As necessary for testing, override behavior of RenderFrameHost + // here. + + private: + DISALLOW_COPY_AND_ASSIGN(TestRenderFrameHost); +}; + +} // namespace content + +#endif // CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_ diff --git a/content/test/test_render_frame_host_factory.cc b/content/test/test_render_frame_host_factory.cc index 1ec7e8b..8bf5b88 100644 --- a/content/test/test_render_frame_host_factory.cc +++ b/content/test/test_render_frame_host_factory.cc @@ -7,7 +7,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/logging.h" -#include "content/browser/frame_host/test_render_frame_host.h" +#include "content/test/test_render_frame_host.h" namespace content { diff --git a/content/test/test_render_view_host.cc b/content/test/test_render_view_host.cc new file mode 100644 index 0000000..772adda --- /dev/null +++ b/content/test/test_render_view_host.cc @@ -0,0 +1,434 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/test/test_render_view_host.h" + +#include "base/memory/scoped_ptr.h" +#include "content/browser/dom_storage/dom_storage_context_wrapper.h" +#include "content/browser/dom_storage/session_storage_namespace_impl.h" +#include "content/browser/site_instance_impl.h" +#include "content/common/dom_storage/dom_storage_types.h" +#include "content/common/view_messages.h" +#include "content/public/browser/browser_context.h" +#include "content/public/browser/navigation_controller.h" +#include "content/public/browser/storage_partition.h" +#include "content/public/common/content_client.h" +#include "content/public/common/page_state.h" +#include "content/test/test_backing_store.h" +#include "content/test/test_web_contents.h" +#include "media/base/video_frame.h" +#include "ui/gfx/rect.h" +#include "webkit/common/webpreferences.h" + +namespace content { + +namespace { + +const int64 kFrameId = 13UL; + +} // namespace + + +void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params, + int page_id, + const GURL& url, + PageTransition transition) { + params->page_id = page_id; + params->url = url; + params->referrer = Referrer(); + params->transition = transition; + params->redirects = std::vector<GURL>(); + params->should_update_history = false; + params->searchable_form_url = GURL(); + params->searchable_form_encoding = std::string(); + params->security_info = std::string(); + params->gesture = NavigationGestureUser; + params->was_within_same_page = false; + params->is_post = false; + params->page_state = PageState::CreateFromURL(url); +} + +TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost* rwh) + : rwh_(RenderWidgetHostImpl::From(rwh)), + is_showing_(false), + did_swap_compositor_frame_(false) { + rwh_->SetView(this); +} + +TestRenderWidgetHostView::~TestRenderWidgetHostView() { +} + +RenderWidgetHost* TestRenderWidgetHostView::GetRenderWidgetHost() const { + return NULL; +} + +gfx::NativeView TestRenderWidgetHostView::GetNativeView() const { + return NULL; +} + +gfx::NativeViewId TestRenderWidgetHostView::GetNativeViewId() const { + return 0; +} + +gfx::NativeViewAccessible TestRenderWidgetHostView::GetNativeViewAccessible() { + return NULL; +} + +bool TestRenderWidgetHostView::HasFocus() const { + return true; +} + +bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const { + return true; +} + +void TestRenderWidgetHostView::Show() { + is_showing_ = true; +} + +void TestRenderWidgetHostView::Hide() { + is_showing_ = false; +} + +bool TestRenderWidgetHostView::IsShowing() { + return is_showing_; +} + +void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status, + int error_code) { + delete this; +} + +void TestRenderWidgetHostView::Destroy() { delete this; } + +gfx::Rect TestRenderWidgetHostView::GetViewBounds() const { + return gfx::Rect(); +} + +BackingStore* TestRenderWidgetHostView::AllocBackingStore( + const gfx::Size& size) { + return new TestBackingStore(rwh_, size); +} + +void TestRenderWidgetHostView::CopyFromCompositingSurface( + const gfx::Rect& src_subrect, + const gfx::Size& dst_size, + const base::Callback<void(bool, const SkBitmap&)>& callback) { + callback.Run(false, SkBitmap()); +} + +void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame( + const gfx::Rect& src_subrect, + const scoped_refptr<media::VideoFrame>& target, + const base::Callback<void(bool)>& callback) { + callback.Run(false); +} + +bool TestRenderWidgetHostView::CanCopyToVideoFrame() const { + return false; +} + +void TestRenderWidgetHostView::OnAcceleratedCompositingStateChange() { +} + +void TestRenderWidgetHostView::AcceleratedSurfaceInitialized(int host_id, + int route_id) { +} + +void TestRenderWidgetHostView::AcceleratedSurfaceBuffersSwapped( + const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, + int gpu_host_id) { +} + +void TestRenderWidgetHostView::AcceleratedSurfacePostSubBuffer( + const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, + int gpu_host_id) { +} + +void TestRenderWidgetHostView::AcceleratedSurfaceSuspend() { +} + +bool TestRenderWidgetHostView::HasAcceleratedSurface( + const gfx::Size& desired_size) { + return false; +} + +#if defined(OS_MACOSX) + +void TestRenderWidgetHostView::AboutToWaitForBackingStoreMsg() { +} + +void TestRenderWidgetHostView::SetActive(bool active) { + // <viettrungluu@gmail.com>: Do I need to do anything here? +} + +bool TestRenderWidgetHostView::SupportsSpeech() const { + return false; +} + +void TestRenderWidgetHostView::SpeakSelection() { +} + +bool TestRenderWidgetHostView::IsSpeaking() const { + return false; +} + +void TestRenderWidgetHostView::StopSpeaking() { +} + +bool TestRenderWidgetHostView::PostProcessEventForPluginIme( + const NativeWebKeyboardEvent& event) { + return false; +} + +#elif defined(OS_WIN) && !defined(USE_AURA) +void TestRenderWidgetHostView::WillWmDestroy() { +} +#endif + +gfx::Rect TestRenderWidgetHostView::GetBoundsInRootWindow() { + return gfx::Rect(); +} + +#if defined(TOOLKIT_GTK) +GdkEventButton* TestRenderWidgetHostView::GetLastMouseDown() { + return NULL; +} + +gfx::NativeView TestRenderWidgetHostView::BuildInputMethodsGtkMenu() { + return NULL; +} +#endif // defined(TOOLKIT_GTK) + +void TestRenderWidgetHostView::OnSwapCompositorFrame( + uint32 output_surface_id, + scoped_ptr<cc::CompositorFrame> frame) { + did_swap_compositor_frame_ = true; +} + + +gfx::GLSurfaceHandle TestRenderWidgetHostView::GetCompositingSurface() { + return gfx::GLSurfaceHandle(); +} + +#if defined(OS_WIN) && !defined(USE_AURA) +void TestRenderWidgetHostView::SetClickthroughRegion(SkRegion* region) { +} +#endif + +bool TestRenderWidgetHostView::LockMouse() { + return false; +} + +void TestRenderWidgetHostView::UnlockMouse() { +} + +#if defined(OS_WIN) && defined(USE_AURA) +void TestRenderWidgetHostView::SetParentNativeViewAccessible( + gfx::NativeViewAccessible accessible_parent) { +} + +gfx::NativeViewId TestRenderWidgetHostView::GetParentForWindowlessPlugin() + const { + return 0; +} +#endif + +TestRenderViewHost::TestRenderViewHost( + SiteInstance* instance, + RenderViewHostDelegate* delegate, + RenderFrameHostDelegate* frame_delegate, + RenderWidgetHostDelegate* widget_delegate, + int routing_id, + int main_frame_routing_id, + bool swapped_out) + : RenderViewHostImpl(instance, + delegate, + frame_delegate, + widget_delegate, + routing_id, + main_frame_routing_id, + swapped_out, + false /* hidden */), + render_view_created_(false), + delete_counter_(NULL), + simulate_fetch_via_proxy_(false), + simulate_history_list_was_cleared_(false), + contents_mime_type_("text/html"), + opener_route_id_(MSG_ROUTING_NONE) { + // TestRenderWidgetHostView installs itself into this->view_ in its + // constructor, and deletes itself when TestRenderWidgetHostView::Destroy() is + // called. + new TestRenderWidgetHostView(this); + + main_frame_id_ = kFrameId; +} + +TestRenderViewHost::~TestRenderViewHost() { + if (delete_counter_) + ++*delete_counter_; +} + +bool TestRenderViewHost::CreateRenderView( + const base::string16& frame_name, + int opener_route_id, + int32 max_page_id) { + DCHECK(!render_view_created_); + render_view_created_ = true; + opener_route_id_ = opener_route_id; + return true; +} + +bool TestRenderViewHost::IsRenderViewLive() const { + return render_view_created_; +} + +void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) { + SendNavigateWithTransition(page_id, url, PAGE_TRANSITION_LINK); +} + +void TestRenderViewHost::SendFailedNavigate(int page_id, const GURL& url) { + SendNavigateWithTransitionAndResponseCode( + page_id, url, PAGE_TRANSITION_LINK, 500); +} + +void TestRenderViewHost::SendNavigateWithTransition( + int page_id, const GURL& url, PageTransition transition) { + SendNavigateWithTransitionAndResponseCode(page_id, url, transition, 200); +} + +void TestRenderViewHost::SendNavigateWithOriginalRequestURL( + int page_id, const GURL& url, const GURL& original_request_url) { + OnDidStartProvisionalLoadForFrame(kFrameId, -1, true, url); + SendNavigateWithParameters(page_id, url, PAGE_TRANSITION_LINK, + original_request_url, 200, 0); +} + +void TestRenderViewHost::SendNavigateWithFile( + int page_id, const GURL& url, const base::FilePath& file_path) { + SendNavigateWithParameters(page_id, url, PAGE_TRANSITION_LINK, + url, 200, &file_path); +} + +void TestRenderViewHost::SendNavigateWithTransitionAndResponseCode( + int page_id, const GURL& url, PageTransition transition, + int response_code) { + // DidStartProvisionalLoad may delete the pending entry that holds |url|, + // so we keep a copy of it to use in SendNavigateWithParameters. + GURL url_copy(url); + OnDidStartProvisionalLoadForFrame(kFrameId, -1, true, url_copy); + SendNavigateWithParameters(page_id, url_copy, transition, url_copy, + response_code, 0); +} + +void TestRenderViewHost::SendNavigateWithParameters( + int page_id, const GURL& url, PageTransition transition, + const GURL& original_request_url, int response_code, + const base::FilePath* file_path_for_history_item) { + ViewHostMsg_FrameNavigate_Params params; + params.page_id = page_id; + params.frame_id = kFrameId; + 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.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 = response_code; + params.socket_address.set_host("2001:db8::1"); + params.socket_address.set_port(80); + params.was_fetched_via_proxy = simulate_fetch_via_proxy_; + params.history_list_was_cleared = simulate_history_list_was_cleared_; + params.original_request_url = original_request_url; + + params.page_state = PageState::CreateForTesting( + url, + false, + file_path_for_history_item ? "data" : NULL, + file_path_for_history_item); + + ViewHostMsg_FrameNavigate msg(1, params); + OnNavigate(msg); +} + +void TestRenderViewHost::SendShouldCloseACK(bool proceed) { + base::TimeTicks now = base::TimeTicks::Now(); + OnShouldCloseACK(proceed, now, now); +} + +void TestRenderViewHost::SetContentsMimeType(const std::string& mime_type) { + contents_mime_type_ = mime_type; +} + +void TestRenderViewHost::SimulateSwapOutACK() { + OnSwappedOut(false); +} + +void TestRenderViewHost::SimulateWasHidden() { + WasHidden(); +} + +void TestRenderViewHost::SimulateWasShown() { + WasShown(); +} + +void TestRenderViewHost::TestOnStartDragging( + const DropData& drop_data) { + blink::WebDragOperationsMask drag_operation = blink::WebDragOperationEvery; + DragEventSourceInfo event_info; + OnStartDragging(drop_data, drag_operation, SkBitmap(), gfx::Vector2d(), + event_info); +} + +void TestRenderViewHost::TestOnUpdateStateWithFile( + int process_id, + const base::FilePath& file_path) { + OnUpdateState(process_id, + PageState::CreateForTesting(GURL("http://www.google.com"), + false, + "data", + &file_path)); +} + +void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy) { + simulate_fetch_via_proxy_ = proxy; +} + +void TestRenderViewHost::set_simulate_history_list_was_cleared(bool cleared) { + simulate_history_list_was_cleared_ = cleared; +} + +RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() { + std::vector<ui::ScaleFactor> scale_factors; + scale_factors.push_back(ui::SCALE_FACTOR_100P); + scoped_set_supported_scale_factors_.reset( + new ui::test::ScopedSetSupportedScaleFactors(scale_factors)); +} + +RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() { +} + +TestRenderViewHost* RenderViewHostImplTestHarness::test_rvh() { + return static_cast<TestRenderViewHost*>(rvh()); +} + +TestRenderViewHost* RenderViewHostImplTestHarness::pending_test_rvh() { + return static_cast<TestRenderViewHost*>(pending_rvh()); +} + +TestRenderViewHost* RenderViewHostImplTestHarness::active_test_rvh() { + return static_cast<TestRenderViewHost*>(active_rvh()); +} + +TestWebContents* RenderViewHostImplTestHarness::contents() { + return static_cast<TestWebContents*>(web_contents()); +} + +} // namespace content diff --git a/content/test/test_render_view_host.h b/content/test/test_render_view_host.h new file mode 100644 index 0000000..fd44b5c --- /dev/null +++ b/content/test/test_render_view_host.h @@ -0,0 +1,386 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_TEST_TEST_RENDER_VIEW_HOST_H_ +#define CONTENT_TEST_TEST_RENDER_VIEW_HOST_H_ + +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "base/gtest_prod_util.h" +#include "build/build_config.h" +#include "content/browser/renderer_host/render_view_host_impl.h" +#include "content/browser/renderer_host/render_widget_host_view_base.h" +#include "content/public/common/page_transition_types.h" +#include "content/public/test/test_renderer_host.h" +#include "ui/base/layout.h" +#include "ui/gfx/vector2d_f.h" + +// This file provides a testing framework for mocking out the RenderProcessHost +// layer. It allows you to test RenderViewHost, WebContentsImpl, +// NavigationController, and other layers above that without running an actual +// renderer process. +// +// To use, derive your test base class from RenderViewHostImplTestHarness. + +struct ViewHostMsg_FrameNavigate_Params; + +namespace gfx { +class Rect; +} + +namespace content { + +class SiteInstance; +class TestWebContents; + +// Utility function to initialize ViewHostMsg_NavigateParams_Params +// with given |page_id|, |url| and |transition_type|. +void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params, + int page_id, + const GURL& url, + PageTransition transition_type); + +// TestRenderViewHostView ------------------------------------------------------ + +// Subclass the RenderViewHost's view so that we can call Show(), etc., +// without having side-effects. +class TestRenderWidgetHostView : public RenderWidgetHostViewBase { + public: + explicit TestRenderWidgetHostView(RenderWidgetHost* rwh); + virtual ~TestRenderWidgetHostView(); + + // RenderWidgetHostView implementation. + virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE {} + virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE; + virtual void SetSize(const gfx::Size& size) OVERRIDE {} + virtual void SetBounds(const gfx::Rect& rect) OVERRIDE {} + virtual gfx::NativeView GetNativeView() const OVERRIDE; + virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE; + virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE; + virtual bool HasFocus() const OVERRIDE; + virtual bool IsSurfaceAvailableForCopy() const OVERRIDE; + virtual void Show() OVERRIDE; + virtual void Hide() OVERRIDE; + virtual bool IsShowing() OVERRIDE; + virtual gfx::Rect GetViewBounds() const OVERRIDE; +#if defined(OS_MACOSX) + virtual void SetActive(bool active) OVERRIDE; + virtual void SetTakesFocusOnlyOnMouseDown(bool flag) OVERRIDE {} + virtual void SetWindowVisibility(bool visible) OVERRIDE {} + virtual void WindowFrameChanged() OVERRIDE {} + virtual void ShowDefinitionForSelection() OVERRIDE {} + virtual bool SupportsSpeech() const OVERRIDE; + virtual void SpeakSelection() OVERRIDE; + virtual bool IsSpeaking() const OVERRIDE; + virtual void StopSpeaking() OVERRIDE; +#endif // defined(OS_MACOSX) +#if defined(TOOLKIT_GTK) + virtual GdkEventButton* GetLastMouseDown() OVERRIDE; + virtual gfx::NativeView BuildInputMethodsGtkMenu() OVERRIDE; +#endif // defined(TOOLKIT_GTK) + virtual void OnSwapCompositorFrame( + uint32 output_surface_id, + scoped_ptr<cc::CompositorFrame> frame) OVERRIDE; + + // RenderWidgetHostViewPort implementation. + virtual void InitAsPopup(RenderWidgetHostView* parent_host_view, + const gfx::Rect& pos) OVERRIDE {} + virtual void InitAsFullscreen( + RenderWidgetHostView* reference_host_view) OVERRIDE {} + virtual void WasShown() OVERRIDE {} + virtual void WasHidden() OVERRIDE {} + virtual void MovePluginWindows( + const gfx::Vector2d& scroll_offset, + const std::vector<WebPluginGeometry>& moves) OVERRIDE {} + virtual void Focus() OVERRIDE {} + virtual void Blur() OVERRIDE {} + virtual void SetIsLoading(bool is_loading) OVERRIDE {} + virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE {} + virtual void TextInputTypeChanged(ui::TextInputType type, + ui::TextInputMode input_mode, + bool can_compose_inline) OVERRIDE {} + virtual void ImeCancelComposition() OVERRIDE {} +#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA) + virtual void ImeCompositionRangeChanged( + const gfx::Range& range, + const std::vector<gfx::Rect>& character_bounds) OVERRIDE {} +#endif + virtual void DidUpdateBackingStore( + const gfx::Rect& scroll_rect, + const gfx::Vector2d& scroll_delta, + const std::vector<gfx::Rect>& rects, + const ui::LatencyInfo& latency_info) OVERRIDE {} + virtual void RenderProcessGone(base::TerminationStatus status, + int error_code) OVERRIDE; + virtual void WillDestroyRenderWidget(RenderWidgetHost* rwh) { } + virtual void Destroy() OVERRIDE; + virtual void SetTooltipText(const base::string16& tooltip_text) OVERRIDE {} + virtual void SelectionBoundsChanged( + const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE {} + virtual void ScrollOffsetChanged() OVERRIDE {} + virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE; + virtual void CopyFromCompositingSurface( + const gfx::Rect& src_subrect, + const gfx::Size& dst_size, + const base::Callback<void(bool, const SkBitmap&)>& callback) OVERRIDE; + virtual void CopyFromCompositingSurfaceToVideoFrame( + const gfx::Rect& src_subrect, + const scoped_refptr<media::VideoFrame>& target, + const base::Callback<void(bool)>& callback) OVERRIDE; + virtual bool CanCopyToVideoFrame() const OVERRIDE; + virtual void OnAcceleratedCompositingStateChange() OVERRIDE; + virtual void AcceleratedSurfaceInitialized(int host_id, + int route_id) OVERRIDE; + virtual void AcceleratedSurfaceBuffersSwapped( + const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, + int gpu_host_id) OVERRIDE; + virtual void AcceleratedSurfacePostSubBuffer( + const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, + int gpu_host_id) OVERRIDE; + virtual void AcceleratedSurfaceSuspend() OVERRIDE; + virtual void AcceleratedSurfaceRelease() OVERRIDE {} + virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE; +#if defined(OS_MACOSX) + virtual void AboutToWaitForBackingStoreMsg() OVERRIDE; + virtual bool PostProcessEventForPluginIme( + const NativeWebKeyboardEvent& event) OVERRIDE; +#elif defined(OS_ANDROID) + virtual void ShowDisambiguationPopup( + const gfx::Rect& target_rect, + const SkBitmap& zoomed_bitmap) OVERRIDE {} + virtual void HasTouchEventHandlers(bool need_touch_events) OVERRIDE {} +#elif defined(OS_WIN) && !defined(USE_AURA) + virtual void WillWmDestroy() OVERRIDE; +#endif + virtual void GetScreenInfo(blink::WebScreenInfo* results) OVERRIDE {} + virtual gfx::Rect GetBoundsInRootWindow() OVERRIDE; + virtual void SetHasHorizontalScrollbar( + bool has_horizontal_scrollbar) OVERRIDE { } + virtual void SetScrollOffsetPinning( + bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE { } + virtual void OnAccessibilityEvents( + const std::vector<AccessibilityHostMsg_EventParams>& params) OVERRIDE {} + virtual gfx::GLSurfaceHandle GetCompositingSurface() OVERRIDE; +#if defined(OS_WIN) && !defined(USE_AURA) + virtual void SetClickthroughRegion(SkRegion* region) OVERRIDE; +#endif + virtual bool LockMouse() OVERRIDE; + virtual void UnlockMouse() OVERRIDE; +#if defined(OS_WIN) && defined(USE_AURA) + virtual void SetParentNativeViewAccessible( + gfx::NativeViewAccessible accessible_parent) OVERRIDE; + virtual gfx::NativeViewId GetParentForWindowlessPlugin() const OVERRIDE; +#endif + + bool is_showing() const { return is_showing_; } + bool did_swap_compositor_frame() const { return did_swap_compositor_frame_; } + + protected: + RenderWidgetHostImpl* rwh_; + + private: + bool is_showing_; + bool did_swap_compositor_frame_; +}; + +#if defined(COMPILER_MSVC) +// See comment for same warning on RenderViewHostImpl. +#pragma warning(push) +#pragma warning(disable: 4250) +#endif + +// TestRenderViewHost ---------------------------------------------------------- + +// TODO(brettw) this should use a TestWebContents which should be generalized +// from the WebContentsImpl test. We will probably also need that class' version +// of CreateRenderViewForRenderManager when more complicated tests start using +// this. +// +// Note that users outside of content must use this class by getting +// the separate RenderViewHostTester interface via +// RenderViewHostTester::For(rvh) on the RenderViewHost they want to +// drive tests on. +// +// Users within content may directly static_cast from a +// RenderViewHost* to a TestRenderViewHost*. +// +// The reasons we do it this way rather than extending the parallel +// inheritance hierarchy we have for RenderWidgetHost/RenderViewHost +// vs. RenderWidgetHostImpl/RenderViewHostImpl are: +// +// a) Extending the parallel class hierarchy further would require +// more classes to use virtual inheritance. This is a complexity that +// is better to avoid, especially when it would be introduced in the +// production code solely to facilitate testing code. +// +// b) While users outside of content only need to drive tests on a +// RenderViewHost, content needs a test version of the full +// RenderViewHostImpl so that it can test all methods on that concrete +// class (e.g. overriding a method such as +// RenderViewHostImpl::CreateRenderView). This would have complicated +// the dual class hierarchy even further. +// +// The reason we do it this way instead of using composition is +// similar to (b) above, essentially it gets very tricky. By using +// the split interface we avoid complexity within content and maintain +// reasonable utility for embedders. +class TestRenderViewHost + : public RenderViewHostImpl, + public RenderViewHostTester { + public: + TestRenderViewHost(SiteInstance* instance, + RenderViewHostDelegate* delegate, + RenderFrameHostDelegate* frame_delegate, + RenderWidgetHostDelegate* widget_delegate, + int routing_id, + int main_frame_routing_id, + bool swapped_out); + virtual ~TestRenderViewHost(); + + // RenderViewHostTester implementation. Note that CreateRenderView + // is not specified since it is synonymous with the one from + // RenderViewHostImpl, see below. + virtual void SendNavigate(int page_id, const GURL& url) OVERRIDE; + virtual void SendFailedNavigate(int page_id, const GURL& url) OVERRIDE; + virtual void SendNavigateWithTransition(int page_id, const GURL& url, + PageTransition transition) OVERRIDE; + virtual void SendShouldCloseACK(bool proceed) OVERRIDE; + virtual void SetContentsMimeType(const std::string& mime_type) OVERRIDE; + virtual void SimulateSwapOutACK() OVERRIDE; + virtual void SimulateWasHidden() OVERRIDE; + virtual void SimulateWasShown() OVERRIDE; + + // Calls OnNavigate on the RenderViewHost with the given information, + // including a custom original request URL. Sets the rest of the + // parameters in the message to the "typical" values. This is a helper + // function for simulating the most common types of loads. + void SendNavigateWithOriginalRequestURL( + int page_id, const GURL& url, const GURL& original_request_url); + + void SendNavigateWithFile( + int page_id, const GURL& url, const base::FilePath& file_path); + + void TestOnUpdateStateWithFile( + int process_id, const base::FilePath& file_path); + + void TestOnStartDragging(const DropData& drop_data); + + // If set, *delete_counter is incremented when this object destructs. + void set_delete_counter(int* delete_counter) { + delete_counter_ = delete_counter; + } + + // Sets whether the RenderView currently exists or not. This controls the + // return value from IsRenderViewLive, which the rest of the system uses to + // check whether the RenderView has crashed or not. + void set_render_view_created(bool created) { + render_view_created_ = created; + } + + // Returns whether the RenderViewHost is currently waiting to hear the result + // of a before unload handler from the renderer. + bool is_waiting_for_beforeunload_ack() const { + return is_waiting_for_beforeunload_ack_; + } + + // Returns whether the RenderViewHost is currently waiting to hear the result + // of an unload handler from the renderer. + bool is_waiting_for_unload_ack() const { + return is_waiting_for_unload_ack_; + } + + // Sets whether the RenderViewHost is currently swapped out, and thus + // filtering messages from the renderer. + void set_is_swapped_out(bool is_swapped_out) { + is_swapped_out_ = is_swapped_out; + } + + // If set, navigations will appear to have loaded through a proxy + // (ViewHostMsg_FrameNavigte_Params::was_fetched_via_proxy). + // False by default. + void set_simulate_fetch_via_proxy(bool proxy); + + // If set, navigations will appear to have cleared the history list in the + // RenderView (ViewHostMsg_FrameNavigate_Params::history_list_was_cleared). + // False by default. + void set_simulate_history_list_was_cleared(bool cleared); + + // The opener route id passed to CreateRenderView(). + int opener_route_id() const { return opener_route_id_; } + + // RenderViewHost overrides -------------------------------------------------- + + virtual bool CreateRenderView(const base::string16& frame_name, + int opener_route_id, + int32 max_page_id) OVERRIDE; + virtual bool IsRenderViewLive() const OVERRIDE; + + private: + FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, FilterNavigate); + + void SendNavigateWithTransitionAndResponseCode(int page_id, + const GURL& url, + PageTransition transition, + int response_code); + + // Calls OnNavigate on the RenderViewHost with the given information. + // Sets the rest of the parameters in the message to the "typical" values. + // This is a helper function for simulating the most common types of loads. + void SendNavigateWithParameters( + int page_id, + const GURL& url, + PageTransition transition, + const GURL& original_request_url, + int response_code, + const base::FilePath* file_path_for_history_item); + + // Tracks if the caller thinks if it created the RenderView. This is so we can + // respond to IsRenderViewLive appropriately. + bool render_view_created_; + + // See set_delete_counter() above. May be NULL. + int* delete_counter_; + + // See set_simulate_fetch_via_proxy() above. + bool simulate_fetch_via_proxy_; + + // See set_simulate_history_list_was_cleared() above. + bool simulate_history_list_was_cleared_; + + // See SetContentsMimeType() above. + std::string contents_mime_type_; + + // See opener_route_id() above. + int opener_route_id_; + + DISALLOW_COPY_AND_ASSIGN(TestRenderViewHost); +}; + +#if defined(COMPILER_MSVC) +#pragma warning(pop) +#endif + +// Adds methods to get straight at the impl classes. +class RenderViewHostImplTestHarness : public RenderViewHostTestHarness { + public: + RenderViewHostImplTestHarness(); + virtual ~RenderViewHostImplTestHarness(); + + TestRenderViewHost* test_rvh(); + TestRenderViewHost* pending_test_rvh(); + TestRenderViewHost* active_test_rvh(); + TestWebContents* contents(); + + private: + typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> + ScopedSetSupportedScaleFactors; + ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; + DISALLOW_COPY_AND_ASSIGN(RenderViewHostImplTestHarness); +}; + +} // namespace content + +#endif // CONTENT_TEST_TEST_RENDER_VIEW_HOST_H_ diff --git a/content/test/test_render_view_host_factory.cc b/content/test/test_render_view_host_factory.cc index ebba612..6cd4e8a 100644 --- a/content/test/test_render_view_host_factory.cc +++ b/content/test/test_render_view_host_factory.cc @@ -4,9 +4,9 @@ #include "content/test/test_render_view_host_factory.h" -#include "content/browser/renderer_host/test_render_view_host.h" #include "content/browser/site_instance_impl.h" #include "content/public/browser/render_process_host_factory.h" +#include "content/test/test_render_view_host.h" namespace content { diff --git a/content/test/test_web_contents.cc b/content/test/test_web_contents.cc index d36a9d8..a2a42e6 100644 --- a/content/test/test_web_contents.cc +++ b/content/test/test_web_contents.cc @@ -9,7 +9,6 @@ #include "content/browser/browser_url_handler_impl.h" #include "content/browser/frame_host/navigation_entry_impl.h" #include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/browser/renderer_host/test_render_view_host.h" #include "content/browser/site_instance_impl.h" #include "content/common/view_messages.h" #include "content/public/browser/notification_registrar.h" @@ -18,6 +17,7 @@ #include "content/public/common/page_state.h" #include "content/public/common/page_transition_types.h" #include "content/public/test/mock_render_process_host.h" +#include "content/test/test_render_view_host.h" namespace content { |