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 ui::PageTransition transition
) {
33 params
->page_id
= page_id
;
35 params
->referrer
= Referrer();
36 params
->transition
= transition
;
37 params
->redirects
= std::vector
<GURL
>();
38 params
->should_update_history
= false;
39 params
->searchable_form_url
= GURL();
40 params
->searchable_form_encoding
= std::string();
41 params
->security_info
= std::string();
42 params
->gesture
= NavigationGestureUser
;
43 params
->was_within_same_page
= false;
44 params
->is_post
= false;
45 params
->page_state
= PageState::CreateFromURL(url
);
48 TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost
* rwh
)
49 : rwh_(RenderWidgetHostImpl::From(rwh
)),
52 did_swap_compositor_frame_(false) {
56 TestRenderWidgetHostView::~TestRenderWidgetHostView() {
59 RenderWidgetHost
* TestRenderWidgetHostView::GetRenderWidgetHost() const {
63 gfx::Vector2dF
TestRenderWidgetHostView::GetLastScrollOffset() const {
64 return gfx::Vector2dF();
67 gfx::NativeView
TestRenderWidgetHostView::GetNativeView() const {
71 gfx::NativeViewId
TestRenderWidgetHostView::GetNativeViewId() const {
75 gfx::NativeViewAccessible
TestRenderWidgetHostView::GetNativeViewAccessible() {
79 ui::TextInputClient
* TestRenderWidgetHostView::GetTextInputClient() {
80 return &text_input_client_
;
83 bool TestRenderWidgetHostView::HasFocus() const {
87 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
91 void TestRenderWidgetHostView::Show() {
96 void TestRenderWidgetHostView::Hide() {
100 bool TestRenderWidgetHostView::IsShowing() {
104 void TestRenderWidgetHostView::WasUnOccluded() {
105 is_occluded_
= false;
108 void TestRenderWidgetHostView::WasOccluded() {
112 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status
,
117 void TestRenderWidgetHostView::Destroy() { delete this; }
119 gfx::Rect
TestRenderWidgetHostView::GetViewBounds() const {
123 void TestRenderWidgetHostView::CopyFromCompositingSurface(
124 const gfx::Rect
& src_subrect
,
125 const gfx::Size
& dst_size
,
126 ReadbackRequestCallback
& callback
,
127 const SkColorType color_type
) {
128 callback
.Run(SkBitmap(), content::READBACK_NOT_SUPPORTED
);
131 void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
132 const gfx::Rect
& src_subrect
,
133 const scoped_refptr
<media::VideoFrame
>& target
,
134 const base::Callback
<void(bool)>& callback
) {
138 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
142 bool TestRenderWidgetHostView::HasAcceleratedSurface(
143 const gfx::Size
& desired_size
) {
147 #if defined(OS_MACOSX)
149 void TestRenderWidgetHostView::SetActive(bool active
) {
150 // <viettrungluu@gmail.com>: Do I need to do anything here?
153 bool TestRenderWidgetHostView::SupportsSpeech() const {
157 void TestRenderWidgetHostView::SpeakSelection() {
160 bool TestRenderWidgetHostView::IsSpeaking() const {
164 void TestRenderWidgetHostView::StopSpeaking() {
167 bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
168 const NativeWebKeyboardEvent
& event
) {
174 gfx::Rect
TestRenderWidgetHostView::GetBoundsInRootWindow() {
178 void TestRenderWidgetHostView::OnSwapCompositorFrame(
179 uint32 output_surface_id
,
180 scoped_ptr
<cc::CompositorFrame
> frame
) {
181 did_swap_compositor_frame_
= true;
185 gfx::GLSurfaceHandle
TestRenderWidgetHostView::GetCompositingSurface() {
186 return gfx::GLSurfaceHandle();
189 bool TestRenderWidgetHostView::LockMouse() {
193 void TestRenderWidgetHostView::UnlockMouse() {
197 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
198 gfx::NativeViewAccessible accessible_parent
) {
201 gfx::NativeViewId
TestRenderWidgetHostView::GetParentForWindowlessPlugin()
207 TestRenderViewHost::TestRenderViewHost(
208 SiteInstance
* instance
,
209 RenderViewHostDelegate
* delegate
,
210 RenderWidgetHostDelegate
* widget_delegate
,
212 int main_frame_routing_id
,
214 : RenderViewHostImpl(instance
,
218 main_frame_routing_id
,
221 false /* has_initialized_audio_host */),
222 render_view_created_(false),
223 delete_counter_(NULL
),
224 opener_route_id_(MSG_ROUTING_NONE
) {
225 // TestRenderWidgetHostView installs itself into this->view_ in its
226 // constructor, and deletes itself when TestRenderWidgetHostView::Destroy() is
228 new TestRenderWidgetHostView(this);
231 TestRenderViewHost::~TestRenderViewHost() {
236 bool TestRenderViewHost::CreateRenderView(
237 const base::string16
& frame_name
,
241 bool window_was_created_with_opener
) {
242 DCHECK(!render_view_created_
);
243 render_view_created_
= true;
244 opener_route_id_
= opener_route_id
;
248 bool TestRenderViewHost::IsRenderViewLive() const {
249 return render_view_created_
;
252 bool TestRenderViewHost::IsFullscreen() const {
253 return RenderViewHostImpl::IsFullscreen();
256 void TestRenderViewHost::SimulateWasHidden() {
260 void TestRenderViewHost::SimulateWasShown() {
261 WasShown(ui::LatencyInfo());
264 WebPreferences
TestRenderViewHost::TestComputeWebkitPrefs() {
265 return ComputeWebkitPrefs();
268 void TestRenderViewHost::TestOnStartDragging(
269 const DropData
& drop_data
) {
270 blink::WebDragOperationsMask drag_operation
= blink::WebDragOperationEvery
;
271 DragEventSourceInfo event_info
;
272 OnStartDragging(drop_data
, drag_operation
, SkBitmap(), gfx::Vector2d(),
276 void TestRenderViewHost::TestOnUpdateStateWithFile(
278 const base::FilePath
& file_path
) {
279 OnUpdateState(page_id
,
280 PageState::CreateForTesting(GURL("http://www.google.com"),
286 RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
287 std::vector
<ui::ScaleFactor
> scale_factors
;
288 scale_factors
.push_back(ui::SCALE_FACTOR_100P
);
289 scoped_set_supported_scale_factors_
.reset(
290 new ui::test::ScopedSetSupportedScaleFactors(scale_factors
));
293 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
296 TestRenderViewHost
* RenderViewHostImplTestHarness::test_rvh() {
297 return contents()->GetRenderViewHost();
300 TestRenderViewHost
* RenderViewHostImplTestHarness::pending_test_rvh() {
301 return contents()->GetPendingMainFrame() ?
302 contents()->GetPendingMainFrame()->GetRenderViewHost() :
306 TestRenderViewHost
* RenderViewHostImplTestHarness::active_test_rvh() {
307 return static_cast<TestRenderViewHost
*>(active_rvh());
310 TestRenderFrameHost
* RenderViewHostImplTestHarness::main_test_rfh() {
311 return contents()->GetMainFrame();
314 TestWebContents
* RenderViewHostImplTestHarness::contents() {
315 return static_cast<TestWebContents
*>(web_contents());
318 } // namespace content