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/loader/resource_dispatcher_host_impl.h"
11 #include "content/browser/site_instance_impl.h"
12 #include "content/common/dom_storage/dom_storage_types.h"
13 #include "content/common/frame_messages.h"
14 #include "content/common/view_messages.h"
15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/storage_partition.h"
19 #include "content/public/common/content_client.h"
20 #include "content/public/common/page_state.h"
21 #include "content/public/common/web_preferences.h"
22 #include "content/test/test_render_frame_host.h"
23 #include "content/test/test_web_contents.h"
24 #include "media/base/video_frame.h"
25 #include "ui/gfx/geometry/rect.h"
29 void InitNavigateParams(FrameHostMsg_DidCommitProvisionalLoad_Params
* params
,
32 bool did_create_new_entry
,
34 ui::PageTransition transition
) {
35 params
->page_id
= page_id
;
36 params
->nav_entry_id
= nav_entry_id
;
38 params
->referrer
= Referrer();
39 params
->transition
= transition
;
40 params
->redirects
= std::vector
<GURL
>();
41 params
->should_update_history
= false;
42 params
->searchable_form_url
= GURL();
43 params
->searchable_form_encoding
= std::string();
44 params
->did_create_new_entry
= did_create_new_entry
;
45 params
->security_info
= std::string();
46 params
->gesture
= NavigationGestureUser
;
47 params
->was_within_same_page
= false;
48 params
->is_post
= false;
49 params
->page_state
= PageState::CreateFromURL(url
);
52 TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost
* rwh
)
53 : rwh_(RenderWidgetHostImpl::From(rwh
)),
56 did_swap_compositor_frame_(false) {
60 TestRenderWidgetHostView::~TestRenderWidgetHostView() {
63 RenderWidgetHost
* TestRenderWidgetHostView::GetRenderWidgetHost() const {
67 gfx::Vector2dF
TestRenderWidgetHostView::GetLastScrollOffset() const {
68 return gfx::Vector2dF();
71 gfx::NativeView
TestRenderWidgetHostView::GetNativeView() const {
75 gfx::NativeViewId
TestRenderWidgetHostView::GetNativeViewId() const {
79 gfx::NativeViewAccessible
TestRenderWidgetHostView::GetNativeViewAccessible() {
83 ui::TextInputClient
* TestRenderWidgetHostView::GetTextInputClient() {
84 return &text_input_client_
;
87 bool TestRenderWidgetHostView::HasFocus() const {
91 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
95 void TestRenderWidgetHostView::Show() {
100 void TestRenderWidgetHostView::Hide() {
104 bool TestRenderWidgetHostView::IsShowing() {
108 void TestRenderWidgetHostView::WasUnOccluded() {
109 is_occluded_
= false;
112 void TestRenderWidgetHostView::WasOccluded() {
116 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status
,
121 void TestRenderWidgetHostView::Destroy() { delete this; }
123 gfx::Rect
TestRenderWidgetHostView::GetViewBounds() const {
127 void TestRenderWidgetHostView::CopyFromCompositingSurface(
128 const gfx::Rect
& src_subrect
,
129 const gfx::Size
& dst_size
,
130 ReadbackRequestCallback
& callback
,
131 const SkColorType preferred_color_type
) {
132 callback
.Run(SkBitmap(), content::READBACK_FAILED
);
135 void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
136 const gfx::Rect
& src_subrect
,
137 const scoped_refptr
<media::VideoFrame
>& target
,
138 const base::Callback
<void(bool)>& callback
) {
142 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
146 bool TestRenderWidgetHostView::HasAcceleratedSurface(
147 const gfx::Size
& desired_size
) {
151 #if defined(OS_MACOSX)
153 void TestRenderWidgetHostView::SetActive(bool active
) {
154 // <viettrungluu@gmail.com>: Do I need to do anything here?
157 bool TestRenderWidgetHostView::SupportsSpeech() const {
161 void TestRenderWidgetHostView::SpeakSelection() {
164 bool TestRenderWidgetHostView::IsSpeaking() const {
168 void TestRenderWidgetHostView::StopSpeaking() {
171 bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
172 const NativeWebKeyboardEvent
& event
) {
178 gfx::Rect
TestRenderWidgetHostView::GetBoundsInRootWindow() {
182 void TestRenderWidgetHostView::OnSwapCompositorFrame(
183 uint32 output_surface_id
,
184 scoped_ptr
<cc::CompositorFrame
> frame
) {
185 did_swap_compositor_frame_
= true;
189 gfx::GLSurfaceHandle
TestRenderWidgetHostView::GetCompositingSurface() {
190 return gfx::GLSurfaceHandle();
193 bool TestRenderWidgetHostView::LockMouse() {
197 void TestRenderWidgetHostView::UnlockMouse() {
201 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
202 gfx::NativeViewAccessible accessible_parent
) {
205 gfx::NativeViewId
TestRenderWidgetHostView::GetParentForWindowlessPlugin()
211 TestRenderViewHost::TestRenderViewHost(
212 SiteInstance
* instance
,
213 RenderViewHostDelegate
* delegate
,
214 RenderWidgetHostDelegate
* widget_delegate
,
216 int main_frame_routing_id
,
218 : RenderViewHostImpl(instance
,
222 main_frame_routing_id
,
225 false /* has_initialized_audio_host */),
226 delete_counter_(NULL
),
227 opener_route_id_(MSG_ROUTING_NONE
) {
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::CreateTestRenderView(
240 const base::string16
& frame_name
,
244 bool window_was_created_with_opener
) {
245 return CreateRenderView(frame_name
, opener_route_id
, proxy_route_id
,
246 max_page_id
, FrameReplicationState(),
247 window_was_created_with_opener
);
250 bool TestRenderViewHost::CreateRenderView(
251 const base::string16
& frame_name
,
255 const FrameReplicationState
& replicated_frame_state
,
256 bool window_was_created_with_opener
) {
257 DCHECK(!IsRenderViewLive());
258 set_renderer_initialized(true);
259 DCHECK(IsRenderViewLive());
260 opener_route_id_
= opener_route_id
;
261 RenderFrameHost
* main_frame
= GetMainFrame();
263 static_cast<RenderFrameHostImpl
*>(main_frame
)->SetRenderFrameCreated(true);
268 bool TestRenderViewHost::IsFullscreenGranted() const {
269 return RenderViewHostImpl::IsFullscreenGranted();
272 MockRenderProcessHost
* TestRenderViewHost::GetProcess() const {
273 return static_cast<MockRenderProcessHost
*>(RenderViewHostImpl::GetProcess());
276 void TestRenderViewHost::SimulateWasHidden() {
280 void TestRenderViewHost::SimulateWasShown() {
281 WasShown(ui::LatencyInfo());
284 WebPreferences
TestRenderViewHost::TestComputeWebkitPrefs() {
285 return ComputeWebkitPrefs();
288 void TestRenderViewHost::TestOnStartDragging(
289 const DropData
& drop_data
) {
290 blink::WebDragOperationsMask drag_operation
= blink::WebDragOperationEvery
;
291 DragEventSourceInfo event_info
;
292 OnStartDragging(drop_data
, drag_operation
, SkBitmap(), gfx::Vector2d(),
296 void TestRenderViewHost::TestOnUpdateStateWithFile(
298 const base::FilePath
& file_path
) {
299 OnUpdateState(page_id
,
300 PageState::CreateForTesting(GURL("http://www.google.com"),
306 RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
307 std::vector
<ui::ScaleFactor
> scale_factors
;
308 scale_factors
.push_back(ui::SCALE_FACTOR_100P
);
309 scoped_set_supported_scale_factors_
.reset(
310 new ui::test::ScopedSetSupportedScaleFactors(scale_factors
));
313 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
316 TestRenderViewHost
* RenderViewHostImplTestHarness::test_rvh() {
317 return contents()->GetRenderViewHost();
320 TestRenderViewHost
* RenderViewHostImplTestHarness::pending_test_rvh() {
321 return contents()->GetPendingMainFrame() ?
322 contents()->GetPendingMainFrame()->GetRenderViewHost() :
326 TestRenderViewHost
* RenderViewHostImplTestHarness::active_test_rvh() {
327 return static_cast<TestRenderViewHost
*>(active_rvh());
330 TestRenderFrameHost
* RenderViewHostImplTestHarness::main_test_rfh() {
331 return contents()->GetMainFrame();
334 TestWebContents
* RenderViewHostImplTestHarness::contents() {
335 return static_cast<TestWebContents
*>(web_contents());
338 } // namespace content