[AndroidWebViewShell] Add MediaStream API layout tests.
[chromium-blink-merge.git] / content / test / test_render_view_host.cc
bloba355a142b353de8b5a2421466b744b4ced1ff555
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"
28 namespace content {
30 void InitNavigateParams(FrameHostMsg_DidCommitProvisionalLoad_Params* params,
31 int page_id,
32 int nav_entry_id,
33 bool did_create_new_entry,
34 const GURL& url,
35 ui::PageTransition transition) {
36 params->page_id = page_id;
37 params->nav_entry_id = nav_entry_id;
38 params->url = url;
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)),
55 is_showing_(false),
56 is_occluded_(false),
57 did_swap_compositor_frame_(false) {
58 rwh_->SetView(this);
61 TestRenderWidgetHostView::~TestRenderWidgetHostView() {
64 RenderWidgetHost* TestRenderWidgetHostView::GetRenderWidgetHost() const {
65 return rwh_;
68 gfx::Vector2dF TestRenderWidgetHostView::GetLastScrollOffset() const {
69 return gfx::Vector2dF();
72 gfx::NativeView TestRenderWidgetHostView::GetNativeView() const {
73 return NULL;
76 gfx::NativeViewId TestRenderWidgetHostView::GetNativeViewId() const {
77 return 0;
80 gfx::NativeViewAccessible TestRenderWidgetHostView::GetNativeViewAccessible() {
81 return NULL;
84 ui::TextInputClient* TestRenderWidgetHostView::GetTextInputClient() {
85 return &text_input_client_;
88 bool TestRenderWidgetHostView::HasFocus() const {
89 return true;
92 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
93 return true;
96 void TestRenderWidgetHostView::Show() {
97 is_showing_ = true;
98 is_occluded_ = false;
101 void TestRenderWidgetHostView::Hide() {
102 is_showing_ = false;
105 bool TestRenderWidgetHostView::IsShowing() {
106 return is_showing_;
109 void TestRenderWidgetHostView::WasUnOccluded() {
110 is_occluded_ = false;
113 void TestRenderWidgetHostView::WasOccluded() {
114 is_occluded_ = true;
117 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status,
118 int error_code) {
119 delete this;
122 void TestRenderWidgetHostView::Destroy() { delete this; }
124 gfx::Rect TestRenderWidgetHostView::GetViewBounds() const {
125 return gfx::Rect();
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) {
140 callback.Run(false);
143 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
144 return false;
147 bool TestRenderWidgetHostView::HasAcceleratedSurface(
148 const gfx::Size& desired_size) {
149 return false;
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 {
159 return false;
162 void TestRenderWidgetHostView::SpeakSelection() {
165 bool TestRenderWidgetHostView::IsSpeaking() const {
166 return false;
169 void TestRenderWidgetHostView::StopSpeaking() {
172 bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
173 const NativeWebKeyboardEvent& event) {
174 return false;
177 #endif
179 bool TestRenderWidgetHostView::GetScreenColorProfile(
180 std::vector<char>* color_profile) {
181 DCHECK(color_profile->empty());
182 return false;
185 gfx::Rect TestRenderWidgetHostView::GetBoundsInRootWindow() {
186 return gfx::Rect();
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() {
201 return false;
204 void TestRenderWidgetHostView::UnlockMouse() {
207 #if defined(OS_WIN)
208 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
209 gfx::NativeViewAccessible accessible_parent) {
212 gfx::NativeViewId TestRenderWidgetHostView::GetParentForWindowlessPlugin()
213 const {
214 return 0;
216 #endif
218 TestRenderViewHost::TestRenderViewHost(
219 SiteInstance* instance,
220 RenderViewHostDelegate* delegate,
221 RenderWidgetHostDelegate* widget_delegate,
222 int32 routing_id,
223 int32 surface_id,
224 int32 main_frame_routing_id,
225 bool swapped_out)
226 : RenderViewHostImpl(instance,
227 delegate,
228 widget_delegate,
229 routing_id,
230 surface_id,
231 main_frame_routing_id,
232 swapped_out,
233 false /* hidden */,
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
239 // called.
240 new TestRenderWidgetHostView(this);
243 TestRenderViewHost::~TestRenderViewHost() {
244 if (delete_counter_)
245 ++*delete_counter_;
248 bool TestRenderViewHost::CreateTestRenderView(
249 const base::string16& frame_name,
250 int opener_frame_route_id,
251 int proxy_route_id,
252 int32 max_page_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,
262 int proxy_route_id,
263 int32 max_page_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();
271 if (main_frame)
272 static_cast<RenderFrameHostImpl*>(main_frame)->SetRenderFrameCreated(true);
274 return 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() {
286 WasHidden();
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(),
302 event_info);
305 void TestRenderViewHost::TestOnUpdateStateWithFile(
306 int page_id,
307 const base::FilePath& file_path) {
308 OnUpdateState(page_id,
309 PageState::CreateForTesting(GURL("http://www.google.com"),
310 false,
311 "data",
312 &file_path));
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() :
332 NULL;
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