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_render_frame_host.h"
21 #include "content/test/test_web_contents.h"
22 #include "media/base/video_frame.h"
23 #include "ui/gfx/rect.h"
27 void InitNavigateParams(FrameHostMsg_DidCommitProvisionalLoad_Params
* params
,
30 PageTransition transition
) {
31 params
->page_id
= page_id
;
33 params
->referrer
= Referrer();
34 params
->transition
= transition
;
35 params
->redirects
= std::vector
<GURL
>();
36 params
->should_update_history
= false;
37 params
->searchable_form_url
= GURL();
38 params
->searchable_form_encoding
= std::string();
39 params
->security_info
= std::string();
40 params
->gesture
= NavigationGestureUser
;
41 params
->was_within_same_page
= false;
42 params
->is_post
= false;
43 params
->page_state
= PageState::CreateFromURL(url
);
46 TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost
* rwh
)
47 : rwh_(RenderWidgetHostImpl::From(rwh
)),
49 did_swap_compositor_frame_(false) {
53 TestRenderWidgetHostView::~TestRenderWidgetHostView() {
56 RenderWidgetHost
* TestRenderWidgetHostView::GetRenderWidgetHost() const {
60 gfx::NativeView
TestRenderWidgetHostView::GetNativeView() const {
64 gfx::NativeViewId
TestRenderWidgetHostView::GetNativeViewId() const {
68 gfx::NativeViewAccessible
TestRenderWidgetHostView::GetNativeViewAccessible() {
72 ui::TextInputClient
* TestRenderWidgetHostView::GetTextInputClient() {
73 return &text_input_client_
;
76 bool TestRenderWidgetHostView::HasFocus() const {
80 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
84 void TestRenderWidgetHostView::Show() {
88 void TestRenderWidgetHostView::Hide() {
92 bool TestRenderWidgetHostView::IsShowing() {
96 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status
,
101 void TestRenderWidgetHostView::Destroy() { delete this; }
103 gfx::Rect
TestRenderWidgetHostView::GetViewBounds() const {
107 void TestRenderWidgetHostView::CopyFromCompositingSurface(
108 const gfx::Rect
& src_subrect
,
109 const gfx::Size
& dst_size
,
110 const base::Callback
<void(bool, const SkBitmap
&)>& callback
,
111 const SkColorType color_type
) {
112 callback
.Run(false, SkBitmap());
115 void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
116 const gfx::Rect
& src_subrect
,
117 const scoped_refptr
<media::VideoFrame
>& target
,
118 const base::Callback
<void(bool)>& callback
) {
122 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
126 void TestRenderWidgetHostView::AcceleratedSurfaceInitialized(int host_id
,
130 void TestRenderWidgetHostView::AcceleratedSurfaceBuffersSwapped(
131 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params
& params
,
135 void TestRenderWidgetHostView::AcceleratedSurfacePostSubBuffer(
136 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params
& params
,
140 void TestRenderWidgetHostView::AcceleratedSurfaceSuspend() {
143 bool TestRenderWidgetHostView::HasAcceleratedSurface(
144 const gfx::Size
& desired_size
) {
148 #if defined(OS_MACOSX)
150 void TestRenderWidgetHostView::SetActive(bool active
) {
151 // <viettrungluu@gmail.com>: Do I need to do anything here?
154 bool TestRenderWidgetHostView::SupportsSpeech() const {
158 void TestRenderWidgetHostView::SpeakSelection() {
161 bool TestRenderWidgetHostView::IsSpeaking() const {
165 void TestRenderWidgetHostView::StopSpeaking() {
168 bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
169 const NativeWebKeyboardEvent
& event
) {
175 gfx::Rect
TestRenderWidgetHostView::GetBoundsInRootWindow() {
179 void TestRenderWidgetHostView::OnSwapCompositorFrame(
180 uint32 output_surface_id
,
181 scoped_ptr
<cc::CompositorFrame
> frame
) {
182 did_swap_compositor_frame_
= true;
186 gfx::GLSurfaceHandle
TestRenderWidgetHostView::GetCompositingSurface() {
187 return gfx::GLSurfaceHandle();
190 bool TestRenderWidgetHostView::LockMouse() {
194 void TestRenderWidgetHostView::UnlockMouse() {
198 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
199 gfx::NativeViewAccessible accessible_parent
) {
202 gfx::NativeViewId
TestRenderWidgetHostView::GetParentForWindowlessPlugin()
208 TestRenderViewHost::TestRenderViewHost(
209 SiteInstance
* instance
,
210 RenderViewHostDelegate
* delegate
,
211 RenderWidgetHostDelegate
* widget_delegate
,
213 int main_frame_routing_id
,
215 : RenderViewHostImpl(instance
,
219 main_frame_routing_id
,
222 render_view_created_(false),
223 delete_counter_(NULL
),
224 simulate_fetch_via_proxy_(false),
225 simulate_history_list_was_cleared_(false),
226 contents_mime_type_("text/html"),
227 opener_route_id_(MSG_ROUTING_NONE
),
228 main_render_frame_host_(NULL
) {
229 // TestRenderWidgetHostView installs itself into this->view_ in its
230 // constructor, and deletes itself when TestRenderWidgetHostView::Destroy() is
232 new TestRenderWidgetHostView(this);
235 TestRenderViewHost::~TestRenderViewHost() {
240 bool TestRenderViewHost::CreateRenderView(
241 const base::string16
& frame_name
,
245 bool window_was_created_with_opener
) {
246 DCHECK(!render_view_created_
);
247 render_view_created_
= true;
248 opener_route_id_
= opener_route_id
;
252 bool TestRenderViewHost::IsRenderViewLive() const {
253 return render_view_created_
;
256 bool TestRenderViewHost::IsFullscreen() const {
257 return RenderViewHostImpl::IsFullscreen();
260 void TestRenderViewHost::SendNavigate(int page_id
, const GURL
& url
) {
261 main_render_frame_host_
->SendNavigate(page_id
, url
);
264 void TestRenderViewHost::SendFailedNavigate(int page_id
, const GURL
& url
) {
265 main_render_frame_host_
->SendFailedNavigate(page_id
, url
);
268 void TestRenderViewHost::SendNavigateWithTransition(
271 PageTransition transition
) {
272 main_render_frame_host_
->SendNavigateWithTransition(page_id
, url
, transition
);
275 void TestRenderViewHost::SendNavigateWithOriginalRequestURL(
278 const GURL
& original_request_url
) {
279 main_render_frame_host_
->SendNavigateWithOriginalRequestURL(
280 page_id
, url
, original_request_url
);
283 void TestRenderViewHost::SendNavigateWithFile(
286 const base::FilePath
& file_path
) {
287 main_render_frame_host_
->SendNavigateWithFile(page_id
, url
, file_path
);
290 void TestRenderViewHost::SendNavigateWithParams(
291 FrameHostMsg_DidCommitProvisionalLoad_Params
* params
) {
292 main_render_frame_host_
->SendNavigateWithParams(params
);
295 void TestRenderViewHost::SendNavigateWithTransitionAndResponseCode(
298 PageTransition transition
,
300 main_render_frame_host_
->SendNavigateWithTransitionAndResponseCode(
301 page_id
, url
, transition
, response_code
);
304 void TestRenderViewHost::SendNavigateWithParameters(
307 PageTransition transition
,
308 const GURL
& original_request_url
,
310 const base::FilePath
* file_path_for_history_item
) {
312 main_render_frame_host_
->SendNavigateWithParameters(
313 page_id
, url
, transition
, original_request_url
, response_code
,
314 file_path_for_history_item
, std::vector
<GURL
>());
317 void TestRenderViewHost::SendBeforeUnloadACK(bool proceed
) {
318 // TODO(creis): Move this whole method to TestRenderFrameHost.
319 base::TimeTicks now
= base::TimeTicks::Now();
320 main_render_frame_host_
->OnBeforeUnloadACK(proceed
, now
, now
);
323 void TestRenderViewHost::SetContentsMimeType(const std::string
& mime_type
) {
324 contents_mime_type_
= mime_type
;
325 main_render_frame_host_
->set_contents_mime_type(mime_type
);
328 void TestRenderViewHost::SimulateSwapOutACK() {
332 void TestRenderViewHost::SimulateWasHidden() {
336 void TestRenderViewHost::SimulateWasShown() {
337 WasShown(ui::LatencyInfo());
340 void TestRenderViewHost::TestOnStartDragging(
341 const DropData
& drop_data
) {
342 blink::WebDragOperationsMask drag_operation
= blink::WebDragOperationEvery
;
343 DragEventSourceInfo event_info
;
344 OnStartDragging(drop_data
, drag_operation
, SkBitmap(), gfx::Vector2d(),
348 void TestRenderViewHost::TestOnUpdateStateWithFile(
350 const base::FilePath
& file_path
) {
351 OnUpdateState(process_id
,
352 PageState::CreateForTesting(GURL("http://www.google.com"),
358 void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy
) {
359 simulate_fetch_via_proxy_
= proxy
;
362 void TestRenderViewHost::set_simulate_history_list_was_cleared(bool cleared
) {
363 simulate_history_list_was_cleared_
= cleared
;
364 main_render_frame_host_
->set_simulate_history_list_was_cleared(cleared
);
367 RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
368 std::vector
<ui::ScaleFactor
> scale_factors
;
369 scale_factors
.push_back(ui::SCALE_FACTOR_100P
);
370 scoped_set_supported_scale_factors_
.reset(
371 new ui::test::ScopedSetSupportedScaleFactors(scale_factors
));
374 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
377 TestRenderViewHost
* RenderViewHostImplTestHarness::test_rvh() {
378 return contents()->GetRenderViewHost();
381 TestRenderViewHost
* RenderViewHostImplTestHarness::pending_test_rvh() {
382 return contents()->GetPendingMainFrame() ?
383 contents()->GetPendingMainFrame()->GetRenderViewHost() :
387 TestRenderViewHost
* RenderViewHostImplTestHarness::active_test_rvh() {
388 return static_cast<TestRenderViewHost
*>(active_rvh());
391 TestRenderFrameHost
* RenderViewHostImplTestHarness::main_test_rfh() {
392 return contents()->GetMainFrame();
395 TestWebContents
* RenderViewHostImplTestHarness::contents() {
396 return static_cast<TestWebContents
*>(web_contents());
399 } // namespace content