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 "base/strings/utf_string_conversions.h"
9 #include "content/browser/dom_storage/dom_storage_context_wrapper.h"
10 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
11 #include "content/browser/loader/resource_dispatcher_host_impl.h"
12 #include "content/browser/site_instance_impl.h"
13 #include "content/common/dom_storage/dom_storage_types.h"
14 #include "content/common/frame_messages.h"
15 #include "content/common/view_messages.h"
16 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/navigation_controller.h"
19 #include "content/public/browser/storage_partition.h"
20 #include "content/public/common/content_client.h"
21 #include "content/public/common/page_state.h"
22 #include "content/public/common/web_preferences.h"
23 #include "content/test/test_render_frame_host.h"
24 #include "content/test/test_web_contents.h"
25 #include "media/base/video_frame.h"
26 #include "ui/gfx/geometry/rect.h"
30 void InitNavigateParams(FrameHostMsg_DidCommitProvisionalLoad_Params
* params
,
33 bool did_create_new_entry
,
35 ui::PageTransition transition
) {
36 params
->page_id
= page_id
;
37 params
->nav_entry_id
= nav_entry_id
;
39 params
->referrer
= Referrer();
40 params
->transition
= transition
;
41 params
->redirects
= std::vector
<GURL
>();
42 params
->should_update_history
= false;
43 params
->searchable_form_url
= GURL();
44 params
->searchable_form_encoding
= std::string();
45 params
->did_create_new_entry
= did_create_new_entry
;
46 params
->security_info
= std::string();
47 params
->gesture
= NavigationGestureUser
;
48 params
->was_within_same_page
= false;
49 params
->is_post
= false;
50 params
->page_state
= PageState::CreateFromURL(url
);
53 TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost
* rwh
)
54 : rwh_(RenderWidgetHostImpl::From(rwh
)),
57 did_swap_compositor_frame_(false) {
61 TestRenderWidgetHostView::~TestRenderWidgetHostView() {
64 RenderWidgetHost
* TestRenderWidgetHostView::GetRenderWidgetHost() const {
68 gfx::Vector2dF
TestRenderWidgetHostView::GetLastScrollOffset() const {
69 return gfx::Vector2dF();
72 gfx::NativeView
TestRenderWidgetHostView::GetNativeView() const {
76 gfx::NativeViewId
TestRenderWidgetHostView::GetNativeViewId() const {
80 gfx::NativeViewAccessible
TestRenderWidgetHostView::GetNativeViewAccessible() {
84 ui::TextInputClient
* TestRenderWidgetHostView::GetTextInputClient() {
85 return &text_input_client_
;
88 bool TestRenderWidgetHostView::HasFocus() const {
92 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
96 void TestRenderWidgetHostView::Show() {
101 void TestRenderWidgetHostView::Hide() {
105 bool TestRenderWidgetHostView::IsShowing() {
109 void TestRenderWidgetHostView::WasUnOccluded() {
110 is_occluded_
= false;
113 void TestRenderWidgetHostView::WasOccluded() {
117 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status
,
122 void TestRenderWidgetHostView::Destroy() { delete this; }
124 gfx::Rect
TestRenderWidgetHostView::GetViewBounds() const {
128 void TestRenderWidgetHostView::CopyFromCompositingSurface(
129 const gfx::Rect
& src_subrect
,
130 const gfx::Size
& dst_size
,
131 ReadbackRequestCallback
& callback
,
132 const SkColorType preferred_color_type
) {
133 callback
.Run(SkBitmap(), content::READBACK_FAILED
);
136 void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
137 const gfx::Rect
& src_subrect
,
138 const scoped_refptr
<media::VideoFrame
>& target
,
139 const base::Callback
<void(bool)>& callback
) {
143 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
147 bool TestRenderWidgetHostView::HasAcceleratedSurface(
148 const gfx::Size
& desired_size
) {
152 #if defined(OS_MACOSX)
154 void TestRenderWidgetHostView::SetActive(bool active
) {
155 // <viettrungluu@gmail.com>: Do I need to do anything here?
158 bool TestRenderWidgetHostView::SupportsSpeech() const {
162 void TestRenderWidgetHostView::SpeakSelection() {
165 bool TestRenderWidgetHostView::IsSpeaking() const {
169 void TestRenderWidgetHostView::StopSpeaking() {
172 bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
173 const NativeWebKeyboardEvent
& event
) {
179 bool TestRenderWidgetHostView::GetScreenColorProfile(
180 std::vector
<char>* color_profile
) {
181 DCHECK(color_profile
->empty());
185 gfx::Rect
TestRenderWidgetHostView::GetBoundsInRootWindow() {
189 void TestRenderWidgetHostView::OnSwapCompositorFrame(
190 uint32 output_surface_id
,
191 scoped_ptr
<cc::CompositorFrame
> frame
) {
192 did_swap_compositor_frame_
= true;
196 gfx::GLSurfaceHandle
TestRenderWidgetHostView::GetCompositingSurface() {
197 return gfx::GLSurfaceHandle();
200 bool TestRenderWidgetHostView::LockMouse() {
204 void TestRenderWidgetHostView::UnlockMouse() {
208 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
209 gfx::NativeViewAccessible accessible_parent
) {
212 gfx::NativeViewId
TestRenderWidgetHostView::GetParentForWindowlessPlugin()
218 TestRenderViewHost::TestRenderViewHost(
219 SiteInstance
* instance
,
220 RenderViewHostDelegate
* delegate
,
221 RenderWidgetHostDelegate
* widget_delegate
,
224 int32 main_frame_routing_id
,
226 : RenderViewHostImpl(instance
,
231 main_frame_routing_id
,
234 false /* has_initialized_audio_host */),
235 delete_counter_(NULL
),
236 opener_frame_route_id_(MSG_ROUTING_NONE
) {
237 // TestRenderWidgetHostView installs itself into this->view_ in its
238 // constructor, and deletes itself when TestRenderWidgetHostView::Destroy() is
240 new TestRenderWidgetHostView(this);
243 TestRenderViewHost::~TestRenderViewHost() {
248 bool TestRenderViewHost::CreateTestRenderView(
249 const base::string16
& frame_name
,
250 int opener_frame_route_id
,
253 bool window_was_created_with_opener
) {
254 FrameReplicationState replicated_state
;
255 replicated_state
.name
= base::UTF16ToUTF8(frame_name
);
256 return CreateRenderView(opener_frame_route_id
, proxy_route_id
, max_page_id
,
257 replicated_state
, window_was_created_with_opener
);
260 bool TestRenderViewHost::CreateRenderView(
261 int opener_frame_route_id
,
264 const FrameReplicationState
& replicated_frame_state
,
265 bool window_was_created_with_opener
) {
266 DCHECK(!IsRenderViewLive());
267 set_renderer_initialized(true);
268 DCHECK(IsRenderViewLive());
269 opener_frame_route_id_
= opener_frame_route_id
;
270 RenderFrameHost
* main_frame
= GetMainFrame();
272 static_cast<RenderFrameHostImpl
*>(main_frame
)->SetRenderFrameCreated(true);
277 bool TestRenderViewHost::IsFullscreenGranted() const {
278 return RenderViewHostImpl::IsFullscreenGranted();
281 MockRenderProcessHost
* TestRenderViewHost::GetProcess() const {
282 return static_cast<MockRenderProcessHost
*>(RenderViewHostImpl::GetProcess());
285 void TestRenderViewHost::SimulateWasHidden() {
289 void TestRenderViewHost::SimulateWasShown() {
290 WasShown(ui::LatencyInfo());
293 WebPreferences
TestRenderViewHost::TestComputeWebkitPrefs() {
294 return ComputeWebkitPrefs();
297 void TestRenderViewHost::TestOnStartDragging(
298 const DropData
& drop_data
) {
299 blink::WebDragOperationsMask drag_operation
= blink::WebDragOperationEvery
;
300 DragEventSourceInfo event_info
;
301 OnStartDragging(drop_data
, drag_operation
, SkBitmap(), gfx::Vector2d(),
305 void TestRenderViewHost::TestOnUpdateStateWithFile(
307 const base::FilePath
& file_path
) {
308 OnUpdateState(page_id
,
309 PageState::CreateForTesting(GURL("http://www.google.com"),
315 RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
316 std::vector
<ui::ScaleFactor
> scale_factors
;
317 scale_factors
.push_back(ui::SCALE_FACTOR_100P
);
318 scoped_set_supported_scale_factors_
.reset(
319 new ui::test::ScopedSetSupportedScaleFactors(scale_factors
));
322 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
325 TestRenderViewHost
* RenderViewHostImplTestHarness::test_rvh() {
326 return contents()->GetRenderViewHost();
329 TestRenderViewHost
* RenderViewHostImplTestHarness::pending_test_rvh() {
330 return contents()->GetPendingMainFrame() ?
331 contents()->GetPendingMainFrame()->GetRenderViewHost() :
335 TestRenderViewHost
* RenderViewHostImplTestHarness::active_test_rvh() {
336 return static_cast<TestRenderViewHost
*>(active_rvh());
339 TestRenderFrameHost
* RenderViewHostImplTestHarness::main_test_rfh() {
340 return contents()->GetMainFrame();
343 TestWebContents
* RenderViewHostImplTestHarness::contents() {
344 return static_cast<TestWebContents
*>(web_contents());
347 } // namespace content