blob: 56be05c6e48cc6df872ff419a00101d68fe438d0 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00005#include "content/browser/renderer_host/test_render_view_host.h"
6
Ben Murdochbb1529c2013-08-08 10:24:53 +01007#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +00008#include "content/browser/dom_storage/session_storage_namespace_impl.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00009#include "content/browser/renderer_host/test_backing_store.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000010#include "content/browser/site_instance_impl.h"
Ben Murdochbb1529c2013-08-08 10:24:53 +010011#include "content/common/dom_storage/dom_storage_types.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000012#include "content/common/view_messages.h"
13#include "content/public/browser/browser_context.h"
14#include "content/public/browser/navigation_controller.h"
15#include "content/public/browser/storage_partition.h"
16#include "content/public/common/content_client.h"
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010017#include "content/public/common/page_state.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000018#include "content/public/common/password_form.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000019#include "content/test/test_web_contents.h"
20#include "media/base/video_frame.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000021#include "ui/gfx/rect.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010022#include "webkit/common/webpreferences.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000023
24namespace content {
25
26namespace {
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +010027
28const int64 kFrameId = 13UL;
29
Torne (Richard Coles)58218062012-11-14 11:43:16 +000030} // namespace
31
32
33void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params,
34 int page_id,
35 const GURL& url,
36 PageTransition transition) {
37 params->page_id = page_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->password_form = PasswordForm();
46 params->security_info = std::string();
47 params->gesture = NavigationGestureUser;
48 params->was_within_same_page = false;
49 params->is_post = false;
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010050 params->page_state = PageState::CreateFromURL(url);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000051}
52
53TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost* rwh)
54 : rwh_(RenderWidgetHostImpl::From(rwh)),
Ben Murdocheb525c52013-07-10 11:40:50 +010055 is_showing_(false),
56 did_swap_compositor_frame_(false) {
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010057 rwh_->SetView(this);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000058}
59
60TestRenderWidgetHostView::~TestRenderWidgetHostView() {
61}
62
63RenderWidgetHost* TestRenderWidgetHostView::GetRenderWidgetHost() const {
64 return NULL;
65}
66
67gfx::NativeView TestRenderWidgetHostView::GetNativeView() const {
68 return NULL;
69}
70
71gfx::NativeViewId TestRenderWidgetHostView::GetNativeViewId() const {
72 return 0;
73}
74
75gfx::NativeViewAccessible TestRenderWidgetHostView::GetNativeViewAccessible() {
76 return NULL;
77}
78
79bool TestRenderWidgetHostView::HasFocus() const {
80 return true;
81}
82
83bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
84 return true;
85}
86
87void TestRenderWidgetHostView::Show() {
88 is_showing_ = true;
89}
90
91void TestRenderWidgetHostView::Hide() {
92 is_showing_ = false;
93}
94
95bool TestRenderWidgetHostView::IsShowing() {
96 return is_showing_;
97}
98
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010099void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status,
100 int error_code) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000101 delete this;
102}
103
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100104void TestRenderWidgetHostView::Destroy() { delete this; }
105
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000106gfx::Rect TestRenderWidgetHostView::GetViewBounds() const {
107 return gfx::Rect();
108}
109
110BackingStore* TestRenderWidgetHostView::AllocBackingStore(
111 const gfx::Size& size) {
112 return new TestBackingStore(rwh_, size);
113}
114
115void TestRenderWidgetHostView::CopyFromCompositingSurface(
116 const gfx::Rect& src_subrect,
117 const gfx::Size& dst_size,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000118 const base::Callback<void(bool, const SkBitmap&)>& callback) {
119 callback.Run(false, SkBitmap());
120}
121
122void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
123 const gfx::Rect& src_subrect,
124 const scoped_refptr<media::VideoFrame>& target,
125 const base::Callback<void(bool)>& callback) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000126 callback.Run(false);
127}
128
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000129bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
130 return false;
131}
132
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000133void TestRenderWidgetHostView::OnAcceleratedCompositingStateChange() {
134}
135
136void TestRenderWidgetHostView::AcceleratedSurfaceBuffersSwapped(
137 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
138 int gpu_host_id) {
139}
140
141void TestRenderWidgetHostView::AcceleratedSurfacePostSubBuffer(
142 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
143 int gpu_host_id) {
144}
145
146void TestRenderWidgetHostView::AcceleratedSurfaceSuspend() {
147}
148
149bool TestRenderWidgetHostView::HasAcceleratedSurface(
150 const gfx::Size& desired_size) {
151 return false;
152}
153
154#if defined(OS_MACOSX)
155
156void TestRenderWidgetHostView::AboutToWaitForBackingStoreMsg() {
157}
158
159void TestRenderWidgetHostView::SetActive(bool active) {
160 // <viettrungluu@gmail.com>: Do I need to do anything here?
161}
162
163bool TestRenderWidgetHostView::SupportsSpeech() const {
164 return false;
165}
166
167void TestRenderWidgetHostView::SpeakSelection() {
168}
169
170bool TestRenderWidgetHostView::IsSpeaking() const {
171 return false;
172}
173
174void TestRenderWidgetHostView::StopSpeaking() {
175}
176
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000177bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
178 const NativeWebKeyboardEvent& event) {
179 return false;
180}
181
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000182#elif defined(OS_WIN) && !defined(USE_AURA)
183void TestRenderWidgetHostView::WillWmDestroy() {
184}
185#endif
186
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000187gfx::Rect TestRenderWidgetHostView::GetBoundsInRootWindow() {
188 return gfx::Rect();
189}
190
191#if defined(TOOLKIT_GTK)
192GdkEventButton* TestRenderWidgetHostView::GetLastMouseDown() {
193 return NULL;
194}
195
196gfx::NativeView TestRenderWidgetHostView::BuildInputMethodsGtkMenu() {
197 return NULL;
198}
199#endif // defined(TOOLKIT_GTK)
200
Ben Murdocheb525c52013-07-10 11:40:50 +0100201void TestRenderWidgetHostView::OnSwapCompositorFrame(
Ben Murdochca12bfa2013-07-23 11:17:05 +0100202 uint32 output_surface_id,
Ben Murdocheb525c52013-07-10 11:40:50 +0100203 scoped_ptr<cc::CompositorFrame> frame) {
204 did_swap_compositor_frame_ = true;
205}
206
207
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000208gfx::GLSurfaceHandle TestRenderWidgetHostView::GetCompositingSurface() {
209 return gfx::GLSurfaceHandle();
210}
211
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000212#if defined(OS_WIN) && !defined(USE_AURA)
213void TestRenderWidgetHostView::SetClickthroughRegion(SkRegion* region) {
214}
215#endif
216
217#if defined(OS_WIN) && defined(USE_AURA)
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100218gfx::NativeViewAccessible
219TestRenderWidgetHostView::AccessibleObjectFromChildId(long child_id) {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000220 NOTIMPLEMENTED();
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100221 return NULL;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000222}
223#endif
224
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000225bool TestRenderWidgetHostView::LockMouse() {
226 return false;
227}
228
229void TestRenderWidgetHostView::UnlockMouse() {
230}
231
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100232#if defined(OS_WIN) && defined(USE_AURA)
233void TestRenderWidgetHostView::SetParentNativeViewAccessible(
234 gfx::NativeViewAccessible accessible_parent) {
235}
236#endif
237
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000238TestRenderViewHost::TestRenderViewHost(
239 SiteInstance* instance,
240 RenderViewHostDelegate* delegate,
241 RenderWidgetHostDelegate* widget_delegate,
242 int routing_id,
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100243 int main_frame_routing_id,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000244 bool swapped_out)
245 : RenderViewHostImpl(instance,
246 delegate,
247 widget_delegate,
248 routing_id,
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100249 main_frame_routing_id,
Ben Murdocha3f7b4e2013-07-24 10:36:34 +0100250 swapped_out),
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000251 render_view_created_(false),
252 delete_counter_(NULL),
253 simulate_fetch_via_proxy_(false),
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100254 simulate_history_list_was_cleared_(false),
Ben Murdochfb250652013-07-31 11:42:55 +0100255 contents_mime_type_("text/html"),
256 opener_route_id_(MSG_ROUTING_NONE) {
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100257 // TestRenderWidgetHostView installs itself into this->view_ in its
258 // constructor, and deletes itself when TestRenderWidgetHostView::Destroy() is
259 // called.
260 new TestRenderWidgetHostView(this);
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100261
262 main_frame_id_ = kFrameId;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000263}
264
265TestRenderViewHost::~TestRenderViewHost() {
266 if (delete_counter_)
267 ++*delete_counter_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000268}
269
270bool TestRenderViewHost::CreateRenderView(
271 const string16& frame_name,
272 int opener_route_id,
273 int32 max_page_id) {
274 DCHECK(!render_view_created_);
275 render_view_created_ = true;
Ben Murdochfb250652013-07-31 11:42:55 +0100276 opener_route_id_ = opener_route_id;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000277 return true;
278}
279
280bool TestRenderViewHost::IsRenderViewLive() const {
281 return render_view_created_;
282}
283
284void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) {
285 SendNavigateWithTransition(page_id, url, PAGE_TRANSITION_LINK);
286}
287
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100288void TestRenderViewHost::SendFailedNavigate(int page_id, const GURL& url) {
289 SendNavigateWithTransitionAndResponseCode(
290 page_id, url, PAGE_TRANSITION_LINK, 500);
291}
292
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000293void TestRenderViewHost::SendNavigateWithTransition(
294 int page_id, const GURL& url, PageTransition transition) {
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100295 SendNavigateWithTransitionAndResponseCode(page_id, url, transition, 200);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000296}
297
298void TestRenderViewHost::SendNavigateWithOriginalRequestURL(
299 int page_id, const GURL& url, const GURL& original_request_url) {
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100300 OnDidStartProvisionalLoadForFrame(kFrameId, -1, true, url);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000301 SendNavigateWithParameters(page_id, url, PAGE_TRANSITION_LINK,
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100302 original_request_url, 200, 0);
303}
304
305void TestRenderViewHost::SendNavigateWithFile(
306 int page_id, const GURL& url, const base::FilePath& file_path) {
307 SendNavigateWithParameters(page_id, url, PAGE_TRANSITION_LINK,
308 url, 200, &file_path);
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100309}
310
311void TestRenderViewHost::SendNavigateWithTransitionAndResponseCode(
312 int page_id, const GURL& url, PageTransition transition,
313 int response_code) {
Ben Murdoch32409262013-08-07 11:04:47 +0100314 OnDidStartProvisionalLoadForFrame(kFrameId, -1, true, url);
315 SendNavigateWithParameters(page_id, url, transition, url, response_code, 0);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000316}
317
318void TestRenderViewHost::SendNavigateWithParameters(
319 int page_id, const GURL& url, PageTransition transition,
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100320 const GURL& original_request_url, int response_code,
321 const base::FilePath* file_path_for_history_item) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000322 ViewHostMsg_FrameNavigate_Params params;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000323 params.page_id = page_id;
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100324 params.frame_id = kFrameId;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000325 params.url = url;
326 params.referrer = Referrer();
327 params.transition = transition;
328 params.redirects = std::vector<GURL>();
329 params.should_update_history = true;
330 params.searchable_form_url = GURL();
331 params.searchable_form_encoding = std::string();
332 params.password_form = PasswordForm();
333 params.security_info = std::string();
334 params.gesture = NavigationGestureUser;
335 params.contents_mime_type = contents_mime_type_;
336 params.is_post = false;
337 params.was_within_same_page = false;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100338 params.http_status_code = response_code;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000339 params.socket_address.set_host("2001:db8::1");
340 params.socket_address.set_port(80);
341 params.was_fetched_via_proxy = simulate_fetch_via_proxy_;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100342 params.history_list_was_cleared = simulate_history_list_was_cleared_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000343 params.original_request_url = original_request_url;
344
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100345 params.page_state = PageState::CreateForTesting(
346 url,
347 false,
348 file_path_for_history_item ? "data" : NULL,
349 file_path_for_history_item);
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100350
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000351 ViewHostMsg_FrameNavigate msg(1, params);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000352 OnNavigate(msg);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000353}
354
355void TestRenderViewHost::SendShouldCloseACK(bool proceed) {
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100356 base::TimeTicks now = base::TimeTicks::Now();
357 OnShouldCloseACK(proceed, now, now);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000358}
359
360void TestRenderViewHost::SetContentsMimeType(const std::string& mime_type) {
361 contents_mime_type_ = mime_type;
362}
363
364void TestRenderViewHost::SimulateSwapOutACK() {
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100365 OnSwappedOut(false);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000366}
367
368void TestRenderViewHost::SimulateWasHidden() {
369 WasHidden();
370}
371
372void TestRenderViewHost::SimulateWasShown() {
373 WasShown();
374}
375
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000376void TestRenderViewHost::TestOnStartDragging(
Ben Murdocheb525c52013-07-10 11:40:50 +0100377 const DropData& drop_data) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000378 WebKit::WebDragOperationsMask drag_operation = WebKit::WebDragOperationEvery;
379 DragEventSourceInfo event_info;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000380 OnStartDragging(drop_data, drag_operation, SkBitmap(), gfx::Vector2d(),
381 event_info);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000382}
383
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100384void TestRenderViewHost::TestOnUpdateStateWithFile(
385 int process_id,
386 const base::FilePath& file_path) {
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100387 OnUpdateState(process_id,
388 PageState::CreateForTesting(GURL("http://www.google.com"),
389 false,
390 "data",
391 &file_path));
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100392}
393
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000394void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy) {
395 simulate_fetch_via_proxy_ = proxy;
396}
397
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100398void TestRenderViewHost::set_simulate_history_list_was_cleared(bool cleared) {
399 simulate_history_list_was_cleared_ = cleared;
400}
401
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000402RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
403}
404
405RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
406}
407
408TestRenderViewHost* RenderViewHostImplTestHarness::test_rvh() {
409 return static_cast<TestRenderViewHost*>(rvh());
410}
411
412TestRenderViewHost* RenderViewHostImplTestHarness::pending_test_rvh() {
413 return static_cast<TestRenderViewHost*>(pending_rvh());
414}
415
416TestRenderViewHost* RenderViewHostImplTestHarness::active_test_rvh() {
417 return static_cast<TestRenderViewHost*>(active_rvh());
418}
419
420TestWebContents* RenderViewHostImplTestHarness::contents() {
421 return static_cast<TestWebContents*>(web_contents());
422}
423
424} // namespace content