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_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"
29 const int64 kFrameId = 13UL;
34 void InitNavigateParams(FrameHostMsg_DidCommitProvisionalLoad_Params* params,
37 PageTransition transition) {
38 params->page_id = page_id;
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);
53 TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost* rwh)
54 : rwh_(RenderWidgetHostImpl::From(rwh)),
56 did_swap_compositor_frame_(false) {
60 TestRenderWidgetHostView::~TestRenderWidgetHostView() {
63 RenderWidgetHost* TestRenderWidgetHostView::GetRenderWidgetHost() const {
67 gfx::NativeView TestRenderWidgetHostView::GetNativeView() const {
71 gfx::NativeViewId TestRenderWidgetHostView::GetNativeViewId() const {
75 gfx::NativeViewAccessible TestRenderWidgetHostView::GetNativeViewAccessible() {
79 bool TestRenderWidgetHostView::HasFocus() const {
83 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
87 void TestRenderWidgetHostView::Show() {
91 void TestRenderWidgetHostView::Hide() {
95 bool TestRenderWidgetHostView::IsShowing() {
99 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status,
104 void TestRenderWidgetHostView::Destroy() { delete this; }
106 gfx::Rect TestRenderWidgetHostView::GetViewBounds() const {
110 BackingStore* TestRenderWidgetHostView::AllocBackingStore(
111 const gfx::Size& size) {
112 return new TestBackingStore(rwh_, size);
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());
123 void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
124 const gfx::Rect& src_subrect,
125 const scoped_refptr<media::VideoFrame>& target,
126 const base::Callback<void(bool)>& callback) {
130 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
134 void TestRenderWidgetHostView::OnAcceleratedCompositingStateChange() {
137 void TestRenderWidgetHostView::AcceleratedSurfaceInitialized(int host_id,
141 void TestRenderWidgetHostView::AcceleratedSurfaceBuffersSwapped(
142 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
146 void TestRenderWidgetHostView::AcceleratedSurfacePostSubBuffer(
147 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
151 void TestRenderWidgetHostView::AcceleratedSurfaceSuspend() {
154 bool TestRenderWidgetHostView::HasAcceleratedSurface(
155 const gfx::Size& desired_size) {
159 #if defined(OS_MACOSX)
161 void TestRenderWidgetHostView::SetActive(bool active) {
162 // <viettrungluu@gmail.com>: Do I need to do anything here?
165 bool TestRenderWidgetHostView::SupportsSpeech() const {
169 void TestRenderWidgetHostView::SpeakSelection() {
172 bool TestRenderWidgetHostView::IsSpeaking() const {
176 void TestRenderWidgetHostView::StopSpeaking() {
179 bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
180 const NativeWebKeyboardEvent& event) {
186 gfx::Rect TestRenderWidgetHostView::GetBoundsInRootWindow() {
190 #if defined(TOOLKIT_GTK)
191 GdkEventButton* TestRenderWidgetHostView::GetLastMouseDown() {
195 gfx::NativeView TestRenderWidgetHostView::BuildInputMethodsGtkMenu() {
198 #endif // defined(TOOLKIT_GTK)
200 void TestRenderWidgetHostView::OnSwapCompositorFrame(
201 uint32 output_surface_id,
202 scoped_ptr<cc::CompositorFrame> frame) {
203 did_swap_compositor_frame_ = true;
207 gfx::GLSurfaceHandle TestRenderWidgetHostView::GetCompositingSurface() {
208 return gfx::GLSurfaceHandle();
211 bool TestRenderWidgetHostView::LockMouse() {
215 void TestRenderWidgetHostView::UnlockMouse() {
219 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
220 gfx::NativeViewAccessible accessible_parent) {
223 gfx::NativeViewId TestRenderWidgetHostView::GetParentForWindowlessPlugin()
229 TestRenderViewHost::TestRenderViewHost(
230 SiteInstance* instance,
231 RenderViewHostDelegate* delegate,
232 RenderWidgetHostDelegate* widget_delegate,
234 int main_frame_routing_id,
236 : RenderViewHostImpl(instance,
240 main_frame_routing_id,
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
253 new TestRenderWidgetHostView(this);
255 main_frame_id_ = kFrameId;
258 TestRenderViewHost::~TestRenderViewHost() {
263 bool TestRenderViewHost::CreateRenderView(
264 const base::string16& frame_name,
267 DCHECK(!render_view_created_);
268 render_view_created_ = true;
269 opener_route_id_ = opener_route_id;
273 bool TestRenderViewHost::IsRenderViewLive() const {
274 return render_view_created_;
277 void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) {
278 main_render_frame_host_->SendNavigate(page_id, url);
281 void TestRenderViewHost::SendFailedNavigate(int page_id, const GURL& url) {
282 main_render_frame_host_->SendFailedNavigate(page_id, url);
285 void TestRenderViewHost::SendNavigateWithTransition(
288 PageTransition transition) {
289 main_render_frame_host_->SendNavigateWithTransition(page_id, url, transition);
292 void TestRenderViewHost::SendNavigateWithOriginalRequestURL(
295 const GURL& original_request_url) {
296 main_render_frame_host_->SendNavigateWithOriginalRequestURL(
297 page_id, url, original_request_url);
300 void TestRenderViewHost::SendNavigateWithFile(
303 const base::FilePath& file_path) {
304 main_render_frame_host_->SendNavigateWithFile(page_id, url, file_path);
307 void TestRenderViewHost::SendNavigateWithParams(
308 FrameHostMsg_DidCommitProvisionalLoad_Params* params) {
309 main_render_frame_host_->SendNavigateWithParams(params);
312 void TestRenderViewHost::SendNavigateWithTransitionAndResponseCode(
315 PageTransition transition,
317 main_render_frame_host_->SendNavigateWithTransitionAndResponseCode(
318 page_id, url, transition, response_code);
321 void TestRenderViewHost::SendNavigateWithParameters(
324 PageTransition transition,
325 const GURL& original_request_url,
327 const base::FilePath* file_path_for_history_item) {
329 main_render_frame_host_->SendNavigateWithParameters(
330 page_id, url, transition, original_request_url, response_code,
331 file_path_for_history_item);
334 void TestRenderViewHost::SendShouldCloseACK(bool proceed) {
335 base::TimeTicks now = base::TimeTicks::Now();
336 OnShouldCloseACK(proceed, now, now);
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);
344 void TestRenderViewHost::SimulateSwapOutACK() {
348 void TestRenderViewHost::SimulateWasHidden() {
352 void TestRenderViewHost::SimulateWasShown() {
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(),
364 void TestRenderViewHost::TestOnUpdateStateWithFile(
366 const base::FilePath& file_path) {
367 OnUpdateState(process_id,
368 PageState::CreateForTesting(GURL("http://www.google.com"),
374 void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy) {
375 simulate_fetch_via_proxy_ = proxy;
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);
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));
390 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
393 TestRenderViewHost* RenderViewHostImplTestHarness::test_rvh() {
394 return static_cast<TestRenderViewHost*>(rvh());
397 TestRenderViewHost* RenderViewHostImplTestHarness::pending_test_rvh() {
398 return static_cast<TestRenderViewHost*>(pending_rvh());
401 TestRenderViewHost* RenderViewHostImplTestHarness::active_test_rvh() {
402 return static_cast<TestRenderViewHost*>(active_rvh());
405 TestRenderFrameHost* RenderViewHostImplTestHarness::main_test_rfh() {
406 return static_cast<TestRenderFrameHost*>(main_rfh());
409 TestWebContents* RenderViewHostImplTestHarness::contents() {
410 return static_cast<TestWebContents*>(web_contents());
413 } // namespace content