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 gfx::Rect
TestRenderWidgetHostView::GetBoundsInRootWindow() {
183 void TestRenderWidgetHostView::OnSwapCompositorFrame(
184 uint32 output_surface_id
,
185 scoped_ptr
<cc::CompositorFrame
> frame
) {
186 did_swap_compositor_frame_
= true;
190 gfx::GLSurfaceHandle
TestRenderWidgetHostView::GetCompositingSurface() {
191 return gfx::GLSurfaceHandle();
194 bool TestRenderWidgetHostView::LockMouse() {
198 void TestRenderWidgetHostView::UnlockMouse() {
202 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
203 gfx::NativeViewAccessible accessible_parent
) {
206 gfx::NativeViewId
TestRenderWidgetHostView::GetParentForWindowlessPlugin()
212 TestRenderViewHost::TestRenderViewHost(
213 SiteInstance
* instance
,
214 RenderViewHostDelegate
* delegate
,
215 RenderWidgetHostDelegate
* widget_delegate
,
217 int main_frame_routing_id
,
219 : RenderViewHostImpl(instance
,
223 main_frame_routing_id
,
226 false /* has_initialized_audio_host */),
227 delete_counter_(NULL
),
228 opener_frame_route_id_(MSG_ROUTING_NONE
) {
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::CreateTestRenderView(
241 const base::string16
& frame_name
,
242 int opener_frame_route_id
,
245 bool window_was_created_with_opener
) {
246 FrameReplicationState replicated_state
;
247 replicated_state
.name
= base::UTF16ToUTF8(frame_name
);
248 return CreateRenderView(opener_frame_route_id
, proxy_route_id
, max_page_id
,
249 replicated_state
, window_was_created_with_opener
);
252 bool TestRenderViewHost::CreateRenderView(
253 int opener_frame_route_id
,
256 const FrameReplicationState
& replicated_frame_state
,
257 bool window_was_created_with_opener
) {
258 DCHECK(!IsRenderViewLive());
259 set_renderer_initialized(true);
260 DCHECK(IsRenderViewLive());
261 opener_frame_route_id_
= opener_frame_route_id
;
262 RenderFrameHost
* main_frame
= GetMainFrame();
264 static_cast<RenderFrameHostImpl
*>(main_frame
)->SetRenderFrameCreated(true);
269 bool TestRenderViewHost::IsFullscreenGranted() const {
270 return RenderViewHostImpl::IsFullscreenGranted();
273 MockRenderProcessHost
* TestRenderViewHost::GetProcess() const {
274 return static_cast<MockRenderProcessHost
*>(RenderViewHostImpl::GetProcess());
277 void TestRenderViewHost::SimulateWasHidden() {
281 void TestRenderViewHost::SimulateWasShown() {
282 WasShown(ui::LatencyInfo());
285 WebPreferences
TestRenderViewHost::TestComputeWebkitPrefs() {
286 return ComputeWebkitPrefs();
289 void TestRenderViewHost::TestOnStartDragging(
290 const DropData
& drop_data
) {
291 blink::WebDragOperationsMask drag_operation
= blink::WebDragOperationEvery
;
292 DragEventSourceInfo event_info
;
293 OnStartDragging(drop_data
, drag_operation
, SkBitmap(), gfx::Vector2d(),
297 void TestRenderViewHost::TestOnUpdateStateWithFile(
299 const base::FilePath
& file_path
) {
300 OnUpdateState(page_id
,
301 PageState::CreateForTesting(GURL("http://www.google.com"),
307 RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
308 std::vector
<ui::ScaleFactor
> scale_factors
;
309 scale_factors
.push_back(ui::SCALE_FACTOR_100P
);
310 scoped_set_supported_scale_factors_
.reset(
311 new ui::test::ScopedSetSupportedScaleFactors(scale_factors
));
314 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
317 TestRenderViewHost
* RenderViewHostImplTestHarness::test_rvh() {
318 return contents()->GetRenderViewHost();
321 TestRenderViewHost
* RenderViewHostImplTestHarness::pending_test_rvh() {
322 return contents()->GetPendingMainFrame() ?
323 contents()->GetPendingMainFrame()->GetRenderViewHost() :
327 TestRenderViewHost
* RenderViewHostImplTestHarness::active_test_rvh() {
328 return static_cast<TestRenderViewHost
*>(active_rvh());
331 TestRenderFrameHost
* RenderViewHostImplTestHarness::main_test_rfh() {
332 return contents()->GetMainFrame();
335 TestWebContents
* RenderViewHostImplTestHarness::contents() {
336 return static_cast<TestWebContents
*>(web_contents());
339 } // namespace content