Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / content / test / test_render_view_host.cc
blob2c8fad9bf2b4776a29cdb39d3ca6e7689937f595
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/site_instance_impl.h"
11 #include "content/common/dom_storage/dom_storage_types.h"
12 #include "content/common/frame_messages.h"
13 #include "content/common/view_messages.h"
14 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/navigation_controller.h"
16 #include "content/public/browser/storage_partition.h"
17 #include "content/public/common/content_client.h"
18 #include "content/public/common/page_state.h"
19 #include "content/test/test_web_contents.h"
20 #include "media/base/video_frame.h"
21 #include "ui/gfx/rect.h"
22 #include "webkit/common/webpreferences.h"
24 namespace content {
26 void InitNavigateParams(FrameHostMsg_DidCommitProvisionalLoad_Params* params,
27 int page_id,
28 const GURL& url,
29 PageTransition transition) {
30 params->page_id = page_id;
31 params->url = url;
32 params->referrer = Referrer();
33 params->transition = transition;
34 params->redirects = std::vector<GURL>();
35 params->should_update_history = false;
36 params->searchable_form_url = GURL();
37 params->searchable_form_encoding = std::string();
38 params->security_info = std::string();
39 params->gesture = NavigationGestureUser;
40 params->was_within_same_page = false;
41 params->is_post = false;
42 params->page_state = PageState::CreateFromURL(url);
45 TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost* rwh)
46 : rwh_(RenderWidgetHostImpl::From(rwh)),
47 is_showing_(false),
48 did_swap_compositor_frame_(false) {
49 rwh_->SetView(this);
52 TestRenderWidgetHostView::~TestRenderWidgetHostView() {
55 RenderWidgetHost* TestRenderWidgetHostView::GetRenderWidgetHost() const {
56 return NULL;
59 gfx::NativeView TestRenderWidgetHostView::GetNativeView() const {
60 return NULL;
63 gfx::NativeViewId TestRenderWidgetHostView::GetNativeViewId() const {
64 return 0;
67 gfx::NativeViewAccessible TestRenderWidgetHostView::GetNativeViewAccessible() {
68 return NULL;
71 bool TestRenderWidgetHostView::HasFocus() const {
72 return true;
75 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
76 return true;
79 void TestRenderWidgetHostView::Show() {
80 is_showing_ = true;
83 void TestRenderWidgetHostView::Hide() {
84 is_showing_ = false;
87 bool TestRenderWidgetHostView::IsShowing() {
88 return is_showing_;
91 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status,
92 int error_code) {
93 delete this;
96 void TestRenderWidgetHostView::Destroy() { delete this; }
98 gfx::Rect TestRenderWidgetHostView::GetViewBounds() const {
99 return gfx::Rect();
102 void TestRenderWidgetHostView::CopyFromCompositingSurface(
103 const gfx::Rect& src_subrect,
104 const gfx::Size& dst_size,
105 const base::Callback<void(bool, const SkBitmap&)>& callback,
106 const SkBitmap::Config config) {
107 callback.Run(false, SkBitmap());
110 void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
111 const gfx::Rect& src_subrect,
112 const scoped_refptr<media::VideoFrame>& target,
113 const base::Callback<void(bool)>& callback) {
114 callback.Run(false);
117 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
118 return false;
121 void TestRenderWidgetHostView::OnAcceleratedCompositingStateChange() {
124 void TestRenderWidgetHostView::AcceleratedSurfaceInitialized(int host_id,
125 int route_id) {
128 void TestRenderWidgetHostView::AcceleratedSurfaceBuffersSwapped(
129 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
130 int gpu_host_id) {
133 void TestRenderWidgetHostView::AcceleratedSurfacePostSubBuffer(
134 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
135 int gpu_host_id) {
138 void TestRenderWidgetHostView::AcceleratedSurfaceSuspend() {
141 bool TestRenderWidgetHostView::HasAcceleratedSurface(
142 const gfx::Size& desired_size) {
143 return false;
146 #if defined(OS_MACOSX)
148 void TestRenderWidgetHostView::SetActive(bool active) {
149 // <viettrungluu@gmail.com>: Do I need to do anything here?
152 bool TestRenderWidgetHostView::SupportsSpeech() const {
153 return false;
156 void TestRenderWidgetHostView::SpeakSelection() {
159 bool TestRenderWidgetHostView::IsSpeaking() const {
160 return false;
163 void TestRenderWidgetHostView::StopSpeaking() {
166 bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
167 const NativeWebKeyboardEvent& event) {
168 return false;
171 #endif
173 gfx::Rect TestRenderWidgetHostView::GetBoundsInRootWindow() {
174 return gfx::Rect();
177 void TestRenderWidgetHostView::OnSwapCompositorFrame(
178 uint32 output_surface_id,
179 scoped_ptr<cc::CompositorFrame> frame) {
180 did_swap_compositor_frame_ = true;
184 gfx::GLSurfaceHandle TestRenderWidgetHostView::GetCompositingSurface() {
185 return gfx::GLSurfaceHandle();
188 bool TestRenderWidgetHostView::LockMouse() {
189 return false;
192 void TestRenderWidgetHostView::UnlockMouse() {
195 #if defined(OS_WIN)
196 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
197 gfx::NativeViewAccessible accessible_parent) {
200 gfx::NativeViewId TestRenderWidgetHostView::GetParentForWindowlessPlugin()
201 const {
202 return 0;
204 #endif
206 TestRenderViewHost::TestRenderViewHost(
207 SiteInstance* instance,
208 RenderViewHostDelegate* delegate,
209 RenderWidgetHostDelegate* widget_delegate,
210 int routing_id,
211 int main_frame_routing_id,
212 bool swapped_out)
213 : RenderViewHostImpl(instance,
214 delegate,
215 widget_delegate,
216 routing_id,
217 main_frame_routing_id,
218 swapped_out,
219 false /* hidden */),
220 render_view_created_(false),
221 delete_counter_(NULL),
222 simulate_fetch_via_proxy_(false),
223 simulate_history_list_was_cleared_(false),
224 contents_mime_type_("text/html"),
225 opener_route_id_(MSG_ROUTING_NONE),
226 main_render_frame_host_(NULL) {
227 // TestRenderWidgetHostView installs itself into this->view_ in its
228 // constructor, and deletes itself when TestRenderWidgetHostView::Destroy() is
229 // called.
230 new TestRenderWidgetHostView(this);
233 TestRenderViewHost::~TestRenderViewHost() {
234 if (delete_counter_)
235 ++*delete_counter_;
238 bool TestRenderViewHost::CreateRenderView(
239 const base::string16& frame_name,
240 int opener_route_id,
241 int32 max_page_id,
242 bool window_was_created_with_opener) {
243 DCHECK(!render_view_created_);
244 render_view_created_ = true;
245 opener_route_id_ = opener_route_id;
246 return true;
249 bool TestRenderViewHost::IsRenderViewLive() const {
250 return render_view_created_;
253 bool TestRenderViewHost::IsFullscreen() const {
254 return RenderViewHostImpl::IsFullscreen();
257 void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) {
258 main_render_frame_host_->SendNavigate(page_id, url);
261 void TestRenderViewHost::SendFailedNavigate(int page_id, const GURL& url) {
262 main_render_frame_host_->SendFailedNavigate(page_id, url);
265 void TestRenderViewHost::SendNavigateWithTransition(
266 int page_id,
267 const GURL& url,
268 PageTransition transition) {
269 main_render_frame_host_->SendNavigateWithTransition(page_id, url, transition);
272 void TestRenderViewHost::SendNavigateWithOriginalRequestURL(
273 int page_id,
274 const GURL& url,
275 const GURL& original_request_url) {
276 main_render_frame_host_->SendNavigateWithOriginalRequestURL(
277 page_id, url, original_request_url);
280 void TestRenderViewHost::SendNavigateWithFile(
281 int page_id,
282 const GURL& url,
283 const base::FilePath& file_path) {
284 main_render_frame_host_->SendNavigateWithFile(page_id, url, file_path);
287 void TestRenderViewHost::SendNavigateWithParams(
288 FrameHostMsg_DidCommitProvisionalLoad_Params* params) {
289 main_render_frame_host_->SendNavigateWithParams(params);
292 void TestRenderViewHost::SendNavigateWithTransitionAndResponseCode(
293 int page_id,
294 const GURL& url,
295 PageTransition transition,
296 int response_code) {
297 main_render_frame_host_->SendNavigateWithTransitionAndResponseCode(
298 page_id, url, transition, response_code);
301 void TestRenderViewHost::SendNavigateWithParameters(
302 int page_id,
303 const GURL& url,
304 PageTransition transition,
305 const GURL& original_request_url,
306 int response_code,
307 const base::FilePath* file_path_for_history_item) {
309 main_render_frame_host_->SendNavigateWithParameters(
310 page_id, url, transition, original_request_url, response_code,
311 file_path_for_history_item, std::vector<GURL>());
314 void TestRenderViewHost::SendBeforeUnloadACK(bool proceed) {
315 // TODO(creis): Move this whole method to TestRenderFrameHost.
316 base::TimeTicks now = base::TimeTicks::Now();
317 main_render_frame_host_->OnBeforeUnloadACK(proceed, now, now);
320 void TestRenderViewHost::SetContentsMimeType(const std::string& mime_type) {
321 contents_mime_type_ = mime_type;
322 main_render_frame_host_->set_contents_mime_type(mime_type);
325 void TestRenderViewHost::SimulateSwapOutACK() {
326 OnSwappedOut(false);
329 void TestRenderViewHost::SimulateWasHidden() {
330 WasHidden();
333 void TestRenderViewHost::SimulateWasShown() {
334 WasShown();
337 void TestRenderViewHost::TestOnStartDragging(
338 const DropData& drop_data) {
339 blink::WebDragOperationsMask drag_operation = blink::WebDragOperationEvery;
340 DragEventSourceInfo event_info;
341 OnStartDragging(drop_data, drag_operation, SkBitmap(), gfx::Vector2d(),
342 event_info);
345 void TestRenderViewHost::TestOnUpdateStateWithFile(
346 int process_id,
347 const base::FilePath& file_path) {
348 OnUpdateState(process_id,
349 PageState::CreateForTesting(GURL("http://www.google.com"),
350 false,
351 "data",
352 &file_path));
355 void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy) {
356 simulate_fetch_via_proxy_ = proxy;
359 void TestRenderViewHost::set_simulate_history_list_was_cleared(bool cleared) {
360 simulate_history_list_was_cleared_ = cleared;
361 main_render_frame_host_->set_simulate_history_list_was_cleared(cleared);
364 RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
365 std::vector<ui::ScaleFactor> scale_factors;
366 scale_factors.push_back(ui::SCALE_FACTOR_100P);
367 scoped_set_supported_scale_factors_.reset(
368 new ui::test::ScopedSetSupportedScaleFactors(scale_factors));
371 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
374 TestRenderViewHost* RenderViewHostImplTestHarness::test_rvh() {
375 return static_cast<TestRenderViewHost*>(rvh());
378 TestRenderViewHost* RenderViewHostImplTestHarness::pending_test_rvh() {
379 return static_cast<TestRenderViewHost*>(pending_rvh());
382 TestRenderViewHost* RenderViewHostImplTestHarness::active_test_rvh() {
383 return static_cast<TestRenderViewHost*>(active_rvh());
386 TestRenderFrameHost* RenderViewHostImplTestHarness::main_test_rfh() {
387 return static_cast<TestRenderFrameHost*>(main_rfh());
390 TestWebContents* RenderViewHostImplTestHarness::contents() {
391 return static_cast<TestWebContents*>(web_contents());
394 } // namespace content