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/site_instance_impl.h"
11 #include "content/common/dom_storage/dom_storage_types.h"
12 #include "content/common/frame_messages.h"
13 #include "content/common/view_messages.h"
14 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/navigation_controller.h"
16 #include "content/public/browser/storage_partition.h"
17 #include "content/public/common/content_client.h"
18 #include "content/public/common/page_state.h"
19 #include "content/public/common/web_preferences.h"
20 #include "content/test/test_web_contents.h"
21 #include "media/base/video_frame.h"
22 #include "ui/gfx/rect.h"
26 void InitNavigateParams(FrameHostMsg_DidCommitProvisionalLoad_Params
* params
,
29 PageTransition transition
) {
30 params
->page_id
= page_id
;
32 params
->referrer
= Referrer();
33 params
->transition
= transition
;
34 params
->redirects
= std::vector
<GURL
>();
35 params
->should_update_history
= false;
36 params
->searchable_form_url
= GURL();
37 params
->searchable_form_encoding
= std::string();
38 params
->security_info
= std::string();
39 params
->gesture
= NavigationGestureUser
;
40 params
->was_within_same_page
= false;
41 params
->is_post
= false;
42 params
->page_state
= PageState::CreateFromURL(url
);
45 TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost
* rwh
)
46 : rwh_(RenderWidgetHostImpl::From(rwh
)),
48 did_swap_compositor_frame_(false) {
52 TestRenderWidgetHostView::~TestRenderWidgetHostView() {
55 RenderWidgetHost
* TestRenderWidgetHostView::GetRenderWidgetHost() const {
59 gfx::NativeView
TestRenderWidgetHostView::GetNativeView() const {
63 gfx::NativeViewId
TestRenderWidgetHostView::GetNativeViewId() const {
67 gfx::NativeViewAccessible
TestRenderWidgetHostView::GetNativeViewAccessible() {
71 ui::TextInputClient
* TestRenderWidgetHostView::GetTextInputClient() {
72 return &text_input_client_
;
75 bool TestRenderWidgetHostView::HasFocus() const {
79 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
83 void TestRenderWidgetHostView::Show() {
87 void TestRenderWidgetHostView::Hide() {
91 bool TestRenderWidgetHostView::IsShowing() {
95 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status
,
100 void TestRenderWidgetHostView::Destroy() { delete this; }
102 gfx::Rect
TestRenderWidgetHostView::GetViewBounds() const {
106 void TestRenderWidgetHostView::CopyFromCompositingSurface(
107 const gfx::Rect
& src_subrect
,
108 const gfx::Size
& dst_size
,
109 const base::Callback
<void(bool, const SkBitmap
&)>& callback
,
110 const SkColorType color_type
) {
111 callback
.Run(false, SkBitmap());
114 void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
115 const gfx::Rect
& src_subrect
,
116 const scoped_refptr
<media::VideoFrame
>& target
,
117 const base::Callback
<void(bool)>& callback
) {
121 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
125 void TestRenderWidgetHostView::AcceleratedSurfaceInitialized(int host_id
,
129 void TestRenderWidgetHostView::AcceleratedSurfaceBuffersSwapped(
130 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params
& params
,
134 void TestRenderWidgetHostView::AcceleratedSurfacePostSubBuffer(
135 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params
& params
,
139 void TestRenderWidgetHostView::AcceleratedSurfaceSuspend() {
142 bool TestRenderWidgetHostView::HasAcceleratedSurface(
143 const gfx::Size
& desired_size
) {
147 #if defined(OS_MACOSX)
149 void TestRenderWidgetHostView::SetActive(bool active
) {
150 // <viettrungluu@gmail.com>: Do I need to do anything here?
153 bool TestRenderWidgetHostView::SupportsSpeech() const {
157 void TestRenderWidgetHostView::SpeakSelection() {
160 bool TestRenderWidgetHostView::IsSpeaking() const {
164 void TestRenderWidgetHostView::StopSpeaking() {
167 bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
168 const NativeWebKeyboardEvent
& event
) {
174 gfx::Rect
TestRenderWidgetHostView::GetBoundsInRootWindow() {
178 void TestRenderWidgetHostView::OnSwapCompositorFrame(
179 uint32 output_surface_id
,
180 scoped_ptr
<cc::CompositorFrame
> frame
) {
181 did_swap_compositor_frame_
= true;
185 gfx::GLSurfaceHandle
TestRenderWidgetHostView::GetCompositingSurface() {
186 return gfx::GLSurfaceHandle();
189 bool TestRenderWidgetHostView::LockMouse() {
193 void TestRenderWidgetHostView::UnlockMouse() {
197 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
198 gfx::NativeViewAccessible accessible_parent
) {
201 gfx::NativeViewId
TestRenderWidgetHostView::GetParentForWindowlessPlugin()
207 TestRenderViewHost::TestRenderViewHost(
208 SiteInstance
* instance
,
209 RenderViewHostDelegate
* delegate
,
210 RenderWidgetHostDelegate
* widget_delegate
,
212 int main_frame_routing_id
,
214 : RenderViewHostImpl(instance
,
218 main_frame_routing_id
,
221 render_view_created_(false),
222 delete_counter_(NULL
),
223 simulate_fetch_via_proxy_(false),
224 simulate_history_list_was_cleared_(false),
225 contents_mime_type_("text/html"),
226 opener_route_id_(MSG_ROUTING_NONE
),
227 main_render_frame_host_(NULL
) {
228 // TestRenderWidgetHostView installs itself into this->view_ in its
229 // constructor, and deletes itself when TestRenderWidgetHostView::Destroy() is
231 new TestRenderWidgetHostView(this);
234 TestRenderViewHost::~TestRenderViewHost() {
239 bool TestRenderViewHost::CreateRenderView(
240 const base::string16
& frame_name
,
244 bool window_was_created_with_opener
) {
245 DCHECK(!render_view_created_
);
246 render_view_created_
= true;
247 opener_route_id_
= opener_route_id
;
251 bool TestRenderViewHost::IsRenderViewLive() const {
252 return render_view_created_
;
255 bool TestRenderViewHost::IsFullscreen() const {
256 return RenderViewHostImpl::IsFullscreen();
259 void TestRenderViewHost::SendNavigate(int page_id
, const GURL
& url
) {
260 main_render_frame_host_
->SendNavigate(page_id
, url
);
263 void TestRenderViewHost::SendFailedNavigate(int page_id
, const GURL
& url
) {
264 main_render_frame_host_
->SendFailedNavigate(page_id
, url
);
267 void TestRenderViewHost::SendNavigateWithTransition(
270 PageTransition transition
) {
271 main_render_frame_host_
->SendNavigateWithTransition(page_id
, url
, transition
);
274 void TestRenderViewHost::SendNavigateWithOriginalRequestURL(
277 const GURL
& original_request_url
) {
278 main_render_frame_host_
->SendNavigateWithOriginalRequestURL(
279 page_id
, url
, original_request_url
);
282 void TestRenderViewHost::SendNavigateWithFile(
285 const base::FilePath
& file_path
) {
286 main_render_frame_host_
->SendNavigateWithFile(page_id
, url
, file_path
);
289 void TestRenderViewHost::SendNavigateWithParams(
290 FrameHostMsg_DidCommitProvisionalLoad_Params
* params
) {
291 main_render_frame_host_
->SendNavigateWithParams(params
);
294 void TestRenderViewHost::SendNavigateWithTransitionAndResponseCode(
297 PageTransition transition
,
299 main_render_frame_host_
->SendNavigateWithTransitionAndResponseCode(
300 page_id
, url
, transition
, response_code
);
303 void TestRenderViewHost::SendNavigateWithParameters(
306 PageTransition transition
,
307 const GURL
& original_request_url
,
309 const base::FilePath
* file_path_for_history_item
) {
311 main_render_frame_host_
->SendNavigateWithParameters(
312 page_id
, url
, transition
, original_request_url
, response_code
,
313 file_path_for_history_item
, std::vector
<GURL
>());
316 void TestRenderViewHost::SendBeforeUnloadACK(bool proceed
) {
317 // TODO(creis): Move this whole method to TestRenderFrameHost.
318 base::TimeTicks now
= base::TimeTicks::Now();
319 main_render_frame_host_
->OnBeforeUnloadACK(proceed
, now
, now
);
322 void TestRenderViewHost::SetContentsMimeType(const std::string
& mime_type
) {
323 contents_mime_type_
= mime_type
;
324 main_render_frame_host_
->set_contents_mime_type(mime_type
);
327 void TestRenderViewHost::SimulateSwapOutACK() {
331 void TestRenderViewHost::SimulateWasHidden() {
335 void TestRenderViewHost::SimulateWasShown() {
339 void TestRenderViewHost::TestOnStartDragging(
340 const DropData
& drop_data
) {
341 blink::WebDragOperationsMask drag_operation
= blink::WebDragOperationEvery
;
342 DragEventSourceInfo event_info
;
343 OnStartDragging(drop_data
, drag_operation
, SkBitmap(), gfx::Vector2d(),
347 void TestRenderViewHost::TestOnUpdateStateWithFile(
349 const base::FilePath
& file_path
) {
350 OnUpdateState(process_id
,
351 PageState::CreateForTesting(GURL("http://www.google.com"),
357 void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy
) {
358 simulate_fetch_via_proxy_
= proxy
;
361 void TestRenderViewHost::set_simulate_history_list_was_cleared(bool cleared
) {
362 simulate_history_list_was_cleared_
= cleared
;
363 main_render_frame_host_
->set_simulate_history_list_was_cleared(cleared
);
366 RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
367 std::vector
<ui::ScaleFactor
> scale_factors
;
368 scale_factors
.push_back(ui::SCALE_FACTOR_100P
);
369 scoped_set_supported_scale_factors_
.reset(
370 new ui::test::ScopedSetSupportedScaleFactors(scale_factors
));
373 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
376 TestRenderViewHost
* RenderViewHostImplTestHarness::test_rvh() {
377 return static_cast<TestRenderViewHost
*>(rvh());
380 TestRenderViewHost
* RenderViewHostImplTestHarness::pending_test_rvh() {
381 return static_cast<TestRenderViewHost
*>(pending_rvh());
384 TestRenderViewHost
* RenderViewHostImplTestHarness::active_test_rvh() {
385 return static_cast<TestRenderViewHost
*>(active_rvh());
388 TestRenderFrameHost
* RenderViewHostImplTestHarness::main_test_rfh() {
389 return static_cast<TestRenderFrameHost
*>(main_rfh());
392 TestWebContents
* RenderViewHostImplTestHarness::contents() {
393 return static_cast<TestWebContents
*>(web_contents());
396 } // namespace content