38facdbad096320ffa067b8f4b93caa9b7baf2d5
[platform/framework/web/crosswalk.git] / src / content / test / test_render_view_host.cc
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.
4
5 #include "content/test/test_render_view_host.h"
6
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_backing_store.h"
20 #include "content/test/test_web_contents.h"
21 #include "media/base/video_frame.h"
22 #include "ui/gfx/rect.h"
23 #include "webkit/common/webpreferences.h"
24
25 namespace content {
26
27 namespace {
28
29 const int64 kFrameId = 13UL;
30
31 }  // namespace
32
33
34 void InitNavigateParams(FrameHostMsg_DidCommitProvisionalLoad_Params* params,
35                         int page_id,
36                         const GURL& url,
37                         PageTransition transition) {
38   params->page_id = page_id;
39   params->url = url;
40   params->referrer = Referrer();
41   params->transition = transition;
42   params->redirects = std::vector<GURL>();
43   params->should_update_history = false;
44   params->searchable_form_url = GURL();
45   params->searchable_form_encoding = std::string();
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);
51 }
52
53 TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost* rwh)
54     : rwh_(RenderWidgetHostImpl::From(rwh)),
55       is_showing_(false),
56       did_swap_compositor_frame_(false) {
57   rwh_->SetView(this);
58 }
59
60 TestRenderWidgetHostView::~TestRenderWidgetHostView() {
61 }
62
63 RenderWidgetHost* TestRenderWidgetHostView::GetRenderWidgetHost() const {
64   return NULL;
65 }
66
67 gfx::NativeView TestRenderWidgetHostView::GetNativeView() const {
68   return NULL;
69 }
70
71 gfx::NativeViewId TestRenderWidgetHostView::GetNativeViewId() const {
72   return 0;
73 }
74
75 gfx::NativeViewAccessible TestRenderWidgetHostView::GetNativeViewAccessible() {
76   return NULL;
77 }
78
79 bool TestRenderWidgetHostView::HasFocus() const {
80   return true;
81 }
82
83 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
84   return true;
85 }
86
87 void TestRenderWidgetHostView::Show() {
88   is_showing_ = true;
89 }
90
91 void TestRenderWidgetHostView::Hide() {
92   is_showing_ = false;
93 }
94
95 bool TestRenderWidgetHostView::IsShowing() {
96   return is_showing_;
97 }
98
99 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status,
100                                                  int error_code) {
101   delete this;
102 }
103
104 void TestRenderWidgetHostView::Destroy() { delete this; }
105
106 gfx::Rect TestRenderWidgetHostView::GetViewBounds() const {
107   return gfx::Rect();
108 }
109
110 BackingStore* TestRenderWidgetHostView::AllocBackingStore(
111     const gfx::Size& size) {
112   return new TestBackingStore(rwh_, size);
113 }
114
115 void TestRenderWidgetHostView::CopyFromCompositingSurface(
116     const gfx::Rect& src_subrect,
117     const gfx::Size& dst_size,
118     const base::Callback<void(bool, const SkBitmap&)>& callback,
119     const SkBitmap::Config config) {
120   callback.Run(false, SkBitmap());
121 }
122
123 void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
124     const gfx::Rect& src_subrect,
125     const scoped_refptr<media::VideoFrame>& target,
126     const base::Callback<void(bool)>& callback) {
127   callback.Run(false);
128 }
129
130 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
131   return false;
132 }
133
134 void TestRenderWidgetHostView::OnAcceleratedCompositingStateChange() {
135 }
136
137 void TestRenderWidgetHostView::AcceleratedSurfaceInitialized(int host_id,
138                                                              int route_id) {
139 }
140
141 void TestRenderWidgetHostView::AcceleratedSurfaceBuffersSwapped(
142     const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
143     int gpu_host_id) {
144 }
145
146 void TestRenderWidgetHostView::AcceleratedSurfacePostSubBuffer(
147     const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
148     int gpu_host_id) {
149 }
150
151 void TestRenderWidgetHostView::AcceleratedSurfaceSuspend() {
152 }
153
154 bool TestRenderWidgetHostView::HasAcceleratedSurface(
155       const gfx::Size& desired_size) {
156   return false;
157 }
158
159 #if defined(OS_MACOSX)
160
161 void TestRenderWidgetHostView::SetActive(bool active) {
162   // <viettrungluu@gmail.com>: Do I need to do anything here?
163 }
164
165 bool TestRenderWidgetHostView::SupportsSpeech() const {
166   return false;
167 }
168
169 void TestRenderWidgetHostView::SpeakSelection() {
170 }
171
172 bool TestRenderWidgetHostView::IsSpeaking() const {
173   return false;
174 }
175
176 void TestRenderWidgetHostView::StopSpeaking() {
177 }
178
179 bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
180     const NativeWebKeyboardEvent& event) {
181   return false;
182 }
183
184 #endif
185
186 gfx::Rect TestRenderWidgetHostView::GetBoundsInRootWindow() {
187   return gfx::Rect();
188 }
189
190 #if defined(TOOLKIT_GTK)
191 GdkEventButton* TestRenderWidgetHostView::GetLastMouseDown() {
192   return NULL;
193 }
194
195 gfx::NativeView TestRenderWidgetHostView::BuildInputMethodsGtkMenu() {
196   return NULL;
197 }
198 #endif  // defined(TOOLKIT_GTK)
199
200 void TestRenderWidgetHostView::OnSwapCompositorFrame(
201     uint32 output_surface_id,
202     scoped_ptr<cc::CompositorFrame> frame) {
203   did_swap_compositor_frame_ = true;
204 }
205
206
207 gfx::GLSurfaceHandle TestRenderWidgetHostView::GetCompositingSurface() {
208   return gfx::GLSurfaceHandle();
209 }
210
211 bool TestRenderWidgetHostView::LockMouse() {
212   return false;
213 }
214
215 void TestRenderWidgetHostView::UnlockMouse() {
216 }
217
218 #if defined(OS_WIN)
219 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
220     gfx::NativeViewAccessible accessible_parent) {
221 }
222
223 gfx::NativeViewId TestRenderWidgetHostView::GetParentForWindowlessPlugin()
224     const {
225   return 0;
226 }
227 #endif
228
229 TestRenderViewHost::TestRenderViewHost(
230     SiteInstance* instance,
231     RenderViewHostDelegate* delegate,
232     RenderWidgetHostDelegate* widget_delegate,
233     int routing_id,
234     int main_frame_routing_id,
235     bool swapped_out)
236     : RenderViewHostImpl(instance,
237                          delegate,
238                          widget_delegate,
239                          routing_id,
240                          main_frame_routing_id,
241                          swapped_out,
242                          false /* hidden */),
243       render_view_created_(false),
244       delete_counter_(NULL),
245       simulate_fetch_via_proxy_(false),
246       simulate_history_list_was_cleared_(false),
247       contents_mime_type_("text/html"),
248       opener_route_id_(MSG_ROUTING_NONE),
249       main_render_frame_host_(NULL) {
250   // TestRenderWidgetHostView installs itself into this->view_ in its
251   // constructor, and deletes itself when TestRenderWidgetHostView::Destroy() is
252   // called.
253   new TestRenderWidgetHostView(this);
254
255   main_frame_id_ = kFrameId;
256 }
257
258 TestRenderViewHost::~TestRenderViewHost() {
259   if (delete_counter_)
260     ++*delete_counter_;
261 }
262
263 bool TestRenderViewHost::CreateRenderView(
264     const base::string16& frame_name,
265     int opener_route_id,
266     int32 max_page_id) {
267   DCHECK(!render_view_created_);
268   render_view_created_ = true;
269   opener_route_id_ = opener_route_id;
270   return true;
271 }
272
273 bool TestRenderViewHost::IsRenderViewLive() const {
274   return render_view_created_;
275 }
276
277 void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) {
278   main_render_frame_host_->SendNavigate(page_id, url);
279 }
280
281 void TestRenderViewHost::SendFailedNavigate(int page_id, const GURL& url) {
282   main_render_frame_host_->SendFailedNavigate(page_id, url);
283 }
284
285 void TestRenderViewHost::SendNavigateWithTransition(
286     int page_id,
287     const GURL& url,
288     PageTransition transition) {
289   main_render_frame_host_->SendNavigateWithTransition(page_id, url, transition);
290 }
291
292 void TestRenderViewHost::SendNavigateWithOriginalRequestURL(
293     int page_id,
294     const GURL& url,
295     const GURL& original_request_url) {
296   main_render_frame_host_->SendNavigateWithOriginalRequestURL(
297       page_id, url, original_request_url);
298 }
299
300 void TestRenderViewHost::SendNavigateWithFile(
301     int page_id,
302     const GURL& url,
303     const base::FilePath& file_path) {
304   main_render_frame_host_->SendNavigateWithFile(page_id, url, file_path);
305 }
306
307 void TestRenderViewHost::SendNavigateWithParams(
308     FrameHostMsg_DidCommitProvisionalLoad_Params* params) {
309   main_render_frame_host_->SendNavigateWithParams(params);
310 }
311
312 void TestRenderViewHost::SendNavigateWithTransitionAndResponseCode(
313     int page_id,
314     const GURL& url,
315     PageTransition transition,
316     int response_code) {
317   main_render_frame_host_->SendNavigateWithTransitionAndResponseCode(
318       page_id, url, transition, response_code);
319 }
320
321 void TestRenderViewHost::SendNavigateWithParameters(
322     int page_id,
323     const GURL& url,
324     PageTransition transition,
325     const GURL& original_request_url,
326     int response_code,
327     const base::FilePath* file_path_for_history_item) {
328
329   main_render_frame_host_->SendNavigateWithParameters(
330       page_id, url, transition, original_request_url, response_code,
331       file_path_for_history_item);
332 }
333
334 void TestRenderViewHost::SendShouldCloseACK(bool proceed) {
335   base::TimeTicks now = base::TimeTicks::Now();
336   OnShouldCloseACK(proceed, now, now);
337 }
338
339 void TestRenderViewHost::SetContentsMimeType(const std::string& mime_type) {
340   contents_mime_type_ = mime_type;
341   main_render_frame_host_->set_contents_mime_type(mime_type);
342 }
343
344 void TestRenderViewHost::SimulateSwapOutACK() {
345   OnSwappedOut(false);
346 }
347
348 void TestRenderViewHost::SimulateWasHidden() {
349   WasHidden();
350 }
351
352 void TestRenderViewHost::SimulateWasShown() {
353   WasShown();
354 }
355
356 void TestRenderViewHost::TestOnStartDragging(
357     const DropData& drop_data) {
358   blink::WebDragOperationsMask drag_operation = blink::WebDragOperationEvery;
359   DragEventSourceInfo event_info;
360   OnStartDragging(drop_data, drag_operation, SkBitmap(), gfx::Vector2d(),
361                   event_info);
362 }
363
364 void TestRenderViewHost::TestOnUpdateStateWithFile(
365     int process_id,
366     const base::FilePath& file_path) {
367   OnUpdateState(process_id,
368                 PageState::CreateForTesting(GURL("http://www.google.com"),
369                                             false,
370                                             "data",
371                                             &file_path));
372 }
373
374 void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy) {
375   simulate_fetch_via_proxy_ = proxy;
376 }
377
378 void TestRenderViewHost::set_simulate_history_list_was_cleared(bool cleared) {
379   simulate_history_list_was_cleared_ = cleared;
380   main_render_frame_host_->set_simulate_history_list_was_cleared(cleared);
381 }
382
383 RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
384   std::vector<ui::ScaleFactor> scale_factors;
385   scale_factors.push_back(ui::SCALE_FACTOR_100P);
386   scoped_set_supported_scale_factors_.reset(
387       new ui::test::ScopedSetSupportedScaleFactors(scale_factors));
388 }
389
390 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
391 }
392
393 TestRenderViewHost* RenderViewHostImplTestHarness::test_rvh() {
394   return static_cast<TestRenderViewHost*>(rvh());
395 }
396
397 TestRenderViewHost* RenderViewHostImplTestHarness::pending_test_rvh() {
398   return static_cast<TestRenderViewHost*>(pending_rvh());
399 }
400
401 TestRenderViewHost* RenderViewHostImplTestHarness::active_test_rvh() {
402   return static_cast<TestRenderViewHost*>(active_rvh());
403 }
404
405 TestRenderFrameHost* RenderViewHostImplTestHarness::main_test_rfh() {
406   return static_cast<TestRenderFrameHost*>(main_rfh());
407 }
408
409 TestWebContents* RenderViewHostImplTestHarness::contents() {
410   return static_cast<TestWebContents*>(web_contents());
411 }
412
413 }  // namespace content