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/test/test_web_contents.h"
20 #include "media/base/video_frame.h"
21 #include "ui/gfx/rect.h"
22 #include "webkit/common/webpreferences.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 bool TestRenderWidgetHostView::HasFocus() const {
75 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
79 void TestRenderWidgetHostView::Show() {
83 void TestRenderWidgetHostView::Hide() {
87 bool TestRenderWidgetHostView::IsShowing() {
91 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status
,
96 void TestRenderWidgetHostView::Destroy() { delete this; }
98 gfx::Rect
TestRenderWidgetHostView::GetViewBounds() const {
102 void TestRenderWidgetHostView::CopyFromCompositingSurface(
103 const gfx::Rect
& src_subrect
,
104 const gfx::Size
& dst_size
,
105 const base::Callback
<void(bool, const SkBitmap
&)>& callback
,
106 const SkBitmap::Config config
) {
107 callback
.Run(false, SkBitmap());
110 void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
111 const gfx::Rect
& src_subrect
,
112 const scoped_refptr
<media::VideoFrame
>& target
,
113 const base::Callback
<void(bool)>& callback
) {
117 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
121 void TestRenderWidgetHostView::OnAcceleratedCompositingStateChange() {
124 void TestRenderWidgetHostView::AcceleratedSurfaceInitialized(int host_id
,
128 void TestRenderWidgetHostView::AcceleratedSurfaceBuffersSwapped(
129 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params
& params
,
133 void TestRenderWidgetHostView::AcceleratedSurfacePostSubBuffer(
134 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params
& params
,
138 void TestRenderWidgetHostView::AcceleratedSurfaceSuspend() {
141 bool TestRenderWidgetHostView::HasAcceleratedSurface(
142 const gfx::Size
& desired_size
) {
146 #if defined(OS_MACOSX)
148 void TestRenderWidgetHostView::SetActive(bool active
) {
149 // <viettrungluu@gmail.com>: Do I need to do anything here?
152 bool TestRenderWidgetHostView::SupportsSpeech() const {
156 void TestRenderWidgetHostView::SpeakSelection() {
159 bool TestRenderWidgetHostView::IsSpeaking() const {
163 void TestRenderWidgetHostView::StopSpeaking() {
166 bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
167 const NativeWebKeyboardEvent
& event
) {
173 gfx::Rect
TestRenderWidgetHostView::GetBoundsInRootWindow() {
177 void TestRenderWidgetHostView::OnSwapCompositorFrame(
178 uint32 output_surface_id
,
179 scoped_ptr
<cc::CompositorFrame
> frame
) {
180 did_swap_compositor_frame_
= true;
184 gfx::GLSurfaceHandle
TestRenderWidgetHostView::GetCompositingSurface() {
185 return gfx::GLSurfaceHandle();
188 bool TestRenderWidgetHostView::LockMouse() {
192 void TestRenderWidgetHostView::UnlockMouse() {
196 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
197 gfx::NativeViewAccessible accessible_parent
) {
200 gfx::NativeViewId
TestRenderWidgetHostView::GetParentForWindowlessPlugin()
206 TestRenderViewHost::TestRenderViewHost(
207 SiteInstance
* instance
,
208 RenderViewHostDelegate
* delegate
,
209 RenderWidgetHostDelegate
* widget_delegate
,
211 int main_frame_routing_id
,
213 : RenderViewHostImpl(instance
,
217 main_frame_routing_id
,
220 render_view_created_(false),
221 delete_counter_(NULL
),
222 simulate_fetch_via_proxy_(false),
223 simulate_history_list_was_cleared_(false),
224 contents_mime_type_("text/html"),
225 opener_route_id_(MSG_ROUTING_NONE
),
226 main_render_frame_host_(NULL
) {
227 // TestRenderWidgetHostView installs itself into this->view_ in its
228 // constructor, and deletes itself when TestRenderWidgetHostView::Destroy() is
230 new TestRenderWidgetHostView(this);
233 TestRenderViewHost::~TestRenderViewHost() {
238 bool TestRenderViewHost::CreateRenderView(
239 const base::string16
& frame_name
,
242 bool window_was_created_with_opener
) {
243 DCHECK(!render_view_created_
);
244 render_view_created_
= true;
245 opener_route_id_
= opener_route_id
;
249 bool TestRenderViewHost::IsRenderViewLive() const {
250 return render_view_created_
;
253 bool TestRenderViewHost::IsFullscreen() const {
254 return RenderViewHostImpl::IsFullscreen();
257 void TestRenderViewHost::SendNavigate(int page_id
, const GURL
& url
) {
258 main_render_frame_host_
->SendNavigate(page_id
, url
);
261 void TestRenderViewHost::SendFailedNavigate(int page_id
, const GURL
& url
) {
262 main_render_frame_host_
->SendFailedNavigate(page_id
, url
);
265 void TestRenderViewHost::SendNavigateWithTransition(
268 PageTransition transition
) {
269 main_render_frame_host_
->SendNavigateWithTransition(page_id
, url
, transition
);
272 void TestRenderViewHost::SendNavigateWithOriginalRequestURL(
275 const GURL
& original_request_url
) {
276 main_render_frame_host_
->SendNavigateWithOriginalRequestURL(
277 page_id
, url
, original_request_url
);
280 void TestRenderViewHost::SendNavigateWithFile(
283 const base::FilePath
& file_path
) {
284 main_render_frame_host_
->SendNavigateWithFile(page_id
, url
, file_path
);
287 void TestRenderViewHost::SendNavigateWithParams(
288 FrameHostMsg_DidCommitProvisionalLoad_Params
* params
) {
289 main_render_frame_host_
->SendNavigateWithParams(params
);
292 void TestRenderViewHost::SendNavigateWithTransitionAndResponseCode(
295 PageTransition transition
,
297 main_render_frame_host_
->SendNavigateWithTransitionAndResponseCode(
298 page_id
, url
, transition
, response_code
);
301 void TestRenderViewHost::SendNavigateWithParameters(
304 PageTransition transition
,
305 const GURL
& original_request_url
,
307 const base::FilePath
* file_path_for_history_item
) {
309 main_render_frame_host_
->SendNavigateWithParameters(
310 page_id
, url
, transition
, original_request_url
, response_code
,
311 file_path_for_history_item
, std::vector
<GURL
>());
314 void TestRenderViewHost::SendBeforeUnloadACK(bool proceed
) {
315 // TODO(creis): Move this whole method to TestRenderFrameHost.
316 base::TimeTicks now
= base::TimeTicks::Now();
317 main_render_frame_host_
->OnBeforeUnloadACK(proceed
, now
, now
);
320 void TestRenderViewHost::SetContentsMimeType(const std::string
& mime_type
) {
321 contents_mime_type_
= mime_type
;
322 main_render_frame_host_
->set_contents_mime_type(mime_type
);
325 void TestRenderViewHost::SimulateSwapOutACK() {
329 void TestRenderViewHost::SimulateWasHidden() {
333 void TestRenderViewHost::SimulateWasShown() {
337 void TestRenderViewHost::TestOnStartDragging(
338 const DropData
& drop_data
) {
339 blink::WebDragOperationsMask drag_operation
= blink::WebDragOperationEvery
;
340 DragEventSourceInfo event_info
;
341 OnStartDragging(drop_data
, drag_operation
, SkBitmap(), gfx::Vector2d(),
345 void TestRenderViewHost::TestOnUpdateStateWithFile(
347 const base::FilePath
& file_path
) {
348 OnUpdateState(process_id
,
349 PageState::CreateForTesting(GURL("http://www.google.com"),
355 void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy
) {
356 simulate_fetch_via_proxy_
= proxy
;
359 void TestRenderViewHost::set_simulate_history_list_was_cleared(bool cleared
) {
360 simulate_history_list_was_cleared_
= cleared
;
361 main_render_frame_host_
->set_simulate_history_list_was_cleared(cleared
);
364 RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
365 std::vector
<ui::ScaleFactor
> scale_factors
;
366 scale_factors
.push_back(ui::SCALE_FACTOR_100P
);
367 scoped_set_supported_scale_factors_
.reset(
368 new ui::test::ScopedSetSupportedScaleFactors(scale_factors
));
371 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
374 TestRenderViewHost
* RenderViewHostImplTestHarness::test_rvh() {
375 return static_cast<TestRenderViewHost
*>(rvh());
378 TestRenderViewHost
* RenderViewHostImplTestHarness::pending_test_rvh() {
379 return static_cast<TestRenderViewHost
*>(pending_rvh());
382 TestRenderViewHost
* RenderViewHostImplTestHarness::active_test_rvh() {
383 return static_cast<TestRenderViewHost
*>(active_rvh());
386 TestRenderFrameHost
* RenderViewHostImplTestHarness::main_test_rfh() {
387 return static_cast<TestRenderFrameHost
*>(main_rfh());
390 TestWebContents
* RenderViewHostImplTestHarness::contents() {
391 return static_cast<TestWebContents
*>(web_contents());
394 } // namespace content