1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/test/test_render_view_host.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "content/browser/dom_storage/dom_storage_context_wrapper.h"
9 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
10 #include "content/browser/loader/resource_dispatcher_host_impl.h"
11 #include "content/browser/site_instance_impl.h"
12 #include "content/common/dom_storage/dom_storage_types.h"
13 #include "content/common/frame_messages.h"
14 #include "content/common/view_messages.h"
15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/storage_partition.h"
19 #include "content/public/common/content_client.h"
20 #include "content/public/common/page_state.h"
21 #include "content/public/common/web_preferences.h"
22 #include "content/test/test_render_frame_host.h"
23 #include "content/test/test_web_contents.h"
24 #include "media/base/video_frame.h"
25 #include "ui/gfx/rect.h"
29 void InitNavigateParams(FrameHostMsg_DidCommitProvisionalLoad_Params
* params
,
32 ui::PageTransition transition
) {
33 params
->page_id
= page_id
;
35 params
->referrer
= Referrer();
36 params
->transition
= transition
;
37 params
->redirects
= std::vector
<GURL
>();
38 params
->should_update_history
= false;
39 params
->searchable_form_url
= GURL();
40 params
->searchable_form_encoding
= std::string();
41 params
->security_info
= std::string();
42 params
->gesture
= NavigationGestureUser
;
43 params
->was_within_same_page
= false;
44 params
->is_post
= false;
45 params
->page_state
= PageState::CreateFromURL(url
);
48 TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost
* rwh
)
49 : rwh_(RenderWidgetHostImpl::From(rwh
)),
51 did_swap_compositor_frame_(false) {
55 TestRenderWidgetHostView::~TestRenderWidgetHostView() {
58 RenderWidgetHost
* TestRenderWidgetHostView::GetRenderWidgetHost() const {
62 gfx::Vector2dF
TestRenderWidgetHostView::GetLastScrollOffset() const {
63 return gfx::Vector2dF();
66 gfx::NativeView
TestRenderWidgetHostView::GetNativeView() const {
70 gfx::NativeViewId
TestRenderWidgetHostView::GetNativeViewId() const {
74 gfx::NativeViewAccessible
TestRenderWidgetHostView::GetNativeViewAccessible() {
78 ui::TextInputClient
* TestRenderWidgetHostView::GetTextInputClient() {
79 return &text_input_client_
;
82 bool TestRenderWidgetHostView::HasFocus() const {
86 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
90 void TestRenderWidgetHostView::Show() {
94 void TestRenderWidgetHostView::Hide() {
98 bool TestRenderWidgetHostView::IsShowing() {
102 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status
,
107 void TestRenderWidgetHostView::Destroy() { delete this; }
109 gfx::Rect
TestRenderWidgetHostView::GetViewBounds() const {
113 void TestRenderWidgetHostView::CopyFromCompositingSurface(
114 const gfx::Rect
& src_subrect
,
115 const gfx::Size
& dst_size
,
116 ReadbackRequestCallback
& callback
,
117 const SkColorType color_type
) {
118 callback
.Run(SkBitmap(), content::READBACK_NOT_SUPPORTED
);
121 void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
122 const gfx::Rect
& src_subrect
,
123 const scoped_refptr
<media::VideoFrame
>& target
,
124 const base::Callback
<void(bool)>& callback
) {
128 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
132 bool TestRenderWidgetHostView::HasAcceleratedSurface(
133 const gfx::Size
& desired_size
) {
137 #if defined(OS_MACOSX)
139 void TestRenderWidgetHostView::SetActive(bool active
) {
140 // <viettrungluu@gmail.com>: Do I need to do anything here?
143 bool TestRenderWidgetHostView::SupportsSpeech() const {
147 void TestRenderWidgetHostView::SpeakSelection() {
150 bool TestRenderWidgetHostView::IsSpeaking() const {
154 void TestRenderWidgetHostView::StopSpeaking() {
157 bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
158 const NativeWebKeyboardEvent
& event
) {
164 gfx::Rect
TestRenderWidgetHostView::GetBoundsInRootWindow() {
168 void TestRenderWidgetHostView::OnSwapCompositorFrame(
169 uint32 output_surface_id
,
170 scoped_ptr
<cc::CompositorFrame
> frame
) {
171 did_swap_compositor_frame_
= true;
175 gfx::GLSurfaceHandle
TestRenderWidgetHostView::GetCompositingSurface() {
176 return gfx::GLSurfaceHandle();
179 bool TestRenderWidgetHostView::LockMouse() {
183 void TestRenderWidgetHostView::UnlockMouse() {
187 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
188 gfx::NativeViewAccessible accessible_parent
) {
191 gfx::NativeViewId
TestRenderWidgetHostView::GetParentForWindowlessPlugin()
197 TestRenderViewHost::TestRenderViewHost(
198 SiteInstance
* instance
,
199 RenderViewHostDelegate
* delegate
,
200 RenderWidgetHostDelegate
* widget_delegate
,
202 int main_frame_routing_id
,
204 : RenderViewHostImpl(instance
,
208 main_frame_routing_id
,
211 false /* has_initialized_audio_host */),
212 render_view_created_(false),
213 delete_counter_(NULL
),
214 opener_route_id_(MSG_ROUTING_NONE
) {
215 // TestRenderWidgetHostView installs itself into this->view_ in its
216 // constructor, and deletes itself when TestRenderWidgetHostView::Destroy() is
218 new TestRenderWidgetHostView(this);
221 TestRenderViewHost::~TestRenderViewHost() {
226 bool TestRenderViewHost::CreateRenderView(
227 const base::string16
& frame_name
,
231 bool window_was_created_with_opener
) {
232 DCHECK(!render_view_created_
);
233 render_view_created_
= true;
234 opener_route_id_
= opener_route_id
;
238 bool TestRenderViewHost::IsRenderViewLive() const {
239 return render_view_created_
;
242 bool TestRenderViewHost::IsFullscreen() const {
243 return RenderViewHostImpl::IsFullscreen();
246 void TestRenderViewHost::SimulateWasHidden() {
250 void TestRenderViewHost::SimulateWasShown() {
251 WasShown(ui::LatencyInfo());
254 void TestRenderViewHost::TestOnStartDragging(
255 const DropData
& drop_data
) {
256 blink::WebDragOperationsMask drag_operation
= blink::WebDragOperationEvery
;
257 DragEventSourceInfo event_info
;
258 OnStartDragging(drop_data
, drag_operation
, SkBitmap(), gfx::Vector2d(),
262 void TestRenderViewHost::TestOnUpdateStateWithFile(
264 const base::FilePath
& file_path
) {
265 OnUpdateState(page_id
,
266 PageState::CreateForTesting(GURL("http://www.google.com"),
272 RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
273 std::vector
<ui::ScaleFactor
> scale_factors
;
274 scale_factors
.push_back(ui::SCALE_FACTOR_100P
);
275 scoped_set_supported_scale_factors_
.reset(
276 new ui::test::ScopedSetSupportedScaleFactors(scale_factors
));
279 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
282 TestRenderViewHost
* RenderViewHostImplTestHarness::test_rvh() {
283 return contents()->GetRenderViewHost();
286 TestRenderViewHost
* RenderViewHostImplTestHarness::pending_test_rvh() {
287 return contents()->GetPendingMainFrame() ?
288 contents()->GetPendingMainFrame()->GetRenderViewHost() :
292 TestRenderViewHost
* RenderViewHostImplTestHarness::active_test_rvh() {
293 return static_cast<TestRenderViewHost
*>(active_rvh());
296 TestRenderFrameHost
* RenderViewHostImplTestHarness::main_test_rfh() {
297 return contents()->GetMainFrame();
300 TestWebContents
* RenderViewHostImplTestHarness::contents() {
301 return static_cast<TestWebContents
*>(web_contents());
304 } // namespace content