Change type of drag-drop window to popup
[chromium-blink-merge.git] / content / test / test_render_view_host.cc
blob06029fc125925d9e9edde2750626d1c71b5cbd42
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/public/common/web_preferences.h"
20 #include "content/test/test_render_frame_host.h"
21 #include "content/test/test_web_contents.h"
22 #include "media/base/video_frame.h"
23 #include "ui/gfx/rect.h"
25 namespace content {
27 void InitNavigateParams(FrameHostMsg_DidCommitProvisionalLoad_Params* params,
28 int page_id,
29 const GURL& url,
30 PageTransition transition) {
31 params->page_id = page_id;
32 params->url = url;
33 params->referrer = Referrer();
34 params->transition = transition;
35 params->redirects = std::vector<GURL>();
36 params->should_update_history = false;
37 params->searchable_form_url = GURL();
38 params->searchable_form_encoding = std::string();
39 params->security_info = std::string();
40 params->gesture = NavigationGestureUser;
41 params->was_within_same_page = false;
42 params->is_post = false;
43 params->page_state = PageState::CreateFromURL(url);
46 TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost* rwh)
47 : rwh_(RenderWidgetHostImpl::From(rwh)),
48 is_showing_(false),
49 did_swap_compositor_frame_(false) {
50 rwh_->SetView(this);
53 TestRenderWidgetHostView::~TestRenderWidgetHostView() {
56 RenderWidgetHost* TestRenderWidgetHostView::GetRenderWidgetHost() const {
57 return NULL;
60 gfx::NativeView TestRenderWidgetHostView::GetNativeView() const {
61 return NULL;
64 gfx::NativeViewId TestRenderWidgetHostView::GetNativeViewId() const {
65 return 0;
68 gfx::NativeViewAccessible TestRenderWidgetHostView::GetNativeViewAccessible() {
69 return NULL;
72 ui::TextInputClient* TestRenderWidgetHostView::GetTextInputClient() {
73 return &text_input_client_;
76 bool TestRenderWidgetHostView::HasFocus() const {
77 return true;
80 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
81 return true;
84 void TestRenderWidgetHostView::Show() {
85 is_showing_ = true;
88 void TestRenderWidgetHostView::Hide() {
89 is_showing_ = false;
92 bool TestRenderWidgetHostView::IsShowing() {
93 return is_showing_;
96 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status,
97 int error_code) {
98 delete this;
101 void TestRenderWidgetHostView::Destroy() { delete this; }
103 gfx::Rect TestRenderWidgetHostView::GetViewBounds() const {
104 return gfx::Rect();
107 void TestRenderWidgetHostView::CopyFromCompositingSurface(
108 const gfx::Rect& src_subrect,
109 const gfx::Size& dst_size,
110 const base::Callback<void(bool, const SkBitmap&)>& callback,
111 const SkColorType color_type) {
112 callback.Run(false, SkBitmap());
115 void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
116 const gfx::Rect& src_subrect,
117 const scoped_refptr<media::VideoFrame>& target,
118 const base::Callback<void(bool)>& callback) {
119 callback.Run(false);
122 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
123 return false;
126 void TestRenderWidgetHostView::AcceleratedSurfaceInitialized(int host_id,
127 int route_id) {
130 void TestRenderWidgetHostView::AcceleratedSurfaceBuffersSwapped(
131 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
132 int gpu_host_id) {
135 void TestRenderWidgetHostView::AcceleratedSurfacePostSubBuffer(
136 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
137 int gpu_host_id) {
140 void TestRenderWidgetHostView::AcceleratedSurfaceSuspend() {
143 bool TestRenderWidgetHostView::HasAcceleratedSurface(
144 const gfx::Size& desired_size) {
145 return false;
148 #if defined(OS_MACOSX)
150 void TestRenderWidgetHostView::SetActive(bool active) {
151 // <viettrungluu@gmail.com>: Do I need to do anything here?
154 bool TestRenderWidgetHostView::SupportsSpeech() const {
155 return false;
158 void TestRenderWidgetHostView::SpeakSelection() {
161 bool TestRenderWidgetHostView::IsSpeaking() const {
162 return false;
165 void TestRenderWidgetHostView::StopSpeaking() {
168 bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
169 const NativeWebKeyboardEvent& event) {
170 return false;
173 #endif
175 gfx::Rect TestRenderWidgetHostView::GetBoundsInRootWindow() {
176 return gfx::Rect();
179 void TestRenderWidgetHostView::OnSwapCompositorFrame(
180 uint32 output_surface_id,
181 scoped_ptr<cc::CompositorFrame> frame) {
182 did_swap_compositor_frame_ = true;
186 gfx::GLSurfaceHandle TestRenderWidgetHostView::GetCompositingSurface() {
187 return gfx::GLSurfaceHandle();
190 bool TestRenderWidgetHostView::LockMouse() {
191 return false;
194 void TestRenderWidgetHostView::UnlockMouse() {
197 #if defined(OS_WIN)
198 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
199 gfx::NativeViewAccessible accessible_parent) {
202 gfx::NativeViewId TestRenderWidgetHostView::GetParentForWindowlessPlugin()
203 const {
204 return 0;
206 #endif
208 TestRenderViewHost::TestRenderViewHost(
209 SiteInstance* instance,
210 RenderViewHostDelegate* delegate,
211 RenderWidgetHostDelegate* widget_delegate,
212 int routing_id,
213 int main_frame_routing_id,
214 bool swapped_out)
215 : RenderViewHostImpl(instance,
216 delegate,
217 widget_delegate,
218 routing_id,
219 main_frame_routing_id,
220 swapped_out,
221 false /* hidden */),
222 render_view_created_(false),
223 delete_counter_(NULL),
224 simulate_fetch_via_proxy_(false),
225 simulate_history_list_was_cleared_(false),
226 contents_mime_type_("text/html"),
227 opener_route_id_(MSG_ROUTING_NONE),
228 main_render_frame_host_(NULL) {
229 // TestRenderWidgetHostView installs itself into this->view_ in its
230 // constructor, and deletes itself when TestRenderWidgetHostView::Destroy() is
231 // called.
232 new TestRenderWidgetHostView(this);
235 TestRenderViewHost::~TestRenderViewHost() {
236 if (delete_counter_)
237 ++*delete_counter_;
240 bool TestRenderViewHost::CreateRenderView(
241 const base::string16& frame_name,
242 int opener_route_id,
243 int proxy_route_id,
244 int32 max_page_id,
245 bool window_was_created_with_opener) {
246 DCHECK(!render_view_created_);
247 render_view_created_ = true;
248 opener_route_id_ = opener_route_id;
249 return true;
252 bool TestRenderViewHost::IsRenderViewLive() const {
253 return render_view_created_;
256 bool TestRenderViewHost::IsFullscreen() const {
257 return RenderViewHostImpl::IsFullscreen();
260 void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) {
261 main_render_frame_host_->SendNavigate(page_id, url);
264 void TestRenderViewHost::SendFailedNavigate(int page_id, const GURL& url) {
265 main_render_frame_host_->SendFailedNavigate(page_id, url);
268 void TestRenderViewHost::SendNavigateWithTransition(
269 int page_id,
270 const GURL& url,
271 PageTransition transition) {
272 main_render_frame_host_->SendNavigateWithTransition(page_id, url, transition);
275 void TestRenderViewHost::SendNavigateWithOriginalRequestURL(
276 int page_id,
277 const GURL& url,
278 const GURL& original_request_url) {
279 main_render_frame_host_->SendNavigateWithOriginalRequestURL(
280 page_id, url, original_request_url);
283 void TestRenderViewHost::SendNavigateWithFile(
284 int page_id,
285 const GURL& url,
286 const base::FilePath& file_path) {
287 main_render_frame_host_->SendNavigateWithFile(page_id, url, file_path);
290 void TestRenderViewHost::SendNavigateWithParams(
291 FrameHostMsg_DidCommitProvisionalLoad_Params* params) {
292 main_render_frame_host_->SendNavigateWithParams(params);
295 void TestRenderViewHost::SendNavigateWithTransitionAndResponseCode(
296 int page_id,
297 const GURL& url,
298 PageTransition transition,
299 int response_code) {
300 main_render_frame_host_->SendNavigateWithTransitionAndResponseCode(
301 page_id, url, transition, response_code);
304 void TestRenderViewHost::SendNavigateWithParameters(
305 int page_id,
306 const GURL& url,
307 PageTransition transition,
308 const GURL& original_request_url,
309 int response_code,
310 const base::FilePath* file_path_for_history_item) {
312 main_render_frame_host_->SendNavigateWithParameters(
313 page_id, url, transition, original_request_url, response_code,
314 file_path_for_history_item, std::vector<GURL>());
317 void TestRenderViewHost::SendBeforeUnloadACK(bool proceed) {
318 // TODO(creis): Move this whole method to TestRenderFrameHost.
319 base::TimeTicks now = base::TimeTicks::Now();
320 main_render_frame_host_->OnBeforeUnloadACK(proceed, now, now);
323 void TestRenderViewHost::SetContentsMimeType(const std::string& mime_type) {
324 contents_mime_type_ = mime_type;
325 main_render_frame_host_->set_contents_mime_type(mime_type);
328 void TestRenderViewHost::SimulateSwapOutACK() {
329 OnSwappedOut(false);
332 void TestRenderViewHost::SimulateWasHidden() {
333 WasHidden();
336 void TestRenderViewHost::SimulateWasShown() {
337 WasShown(ui::LatencyInfo());
340 void TestRenderViewHost::TestOnStartDragging(
341 const DropData& drop_data) {
342 blink::WebDragOperationsMask drag_operation = blink::WebDragOperationEvery;
343 DragEventSourceInfo event_info;
344 OnStartDragging(drop_data, drag_operation, SkBitmap(), gfx::Vector2d(),
345 event_info);
348 void TestRenderViewHost::TestOnUpdateStateWithFile(
349 int process_id,
350 const base::FilePath& file_path) {
351 OnUpdateState(process_id,
352 PageState::CreateForTesting(GURL("http://www.google.com"),
353 false,
354 "data",
355 &file_path));
358 void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy) {
359 simulate_fetch_via_proxy_ = proxy;
362 void TestRenderViewHost::set_simulate_history_list_was_cleared(bool cleared) {
363 simulate_history_list_was_cleared_ = cleared;
364 main_render_frame_host_->set_simulate_history_list_was_cleared(cleared);
367 RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
368 std::vector<ui::ScaleFactor> scale_factors;
369 scale_factors.push_back(ui::SCALE_FACTOR_100P);
370 scoped_set_supported_scale_factors_.reset(
371 new ui::test::ScopedSetSupportedScaleFactors(scale_factors));
374 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
377 TestRenderViewHost* RenderViewHostImplTestHarness::test_rvh() {
378 return contents()->GetRenderViewHost();
381 TestRenderViewHost* RenderViewHostImplTestHarness::pending_test_rvh() {
382 return contents()->GetPendingMainFrame() ?
383 contents()->GetPendingMainFrame()->GetRenderViewHost() :
384 NULL;
387 TestRenderViewHost* RenderViewHostImplTestHarness::active_test_rvh() {
388 return static_cast<TestRenderViewHost*>(active_rvh());
391 TestRenderFrameHost* RenderViewHostImplTestHarness::main_test_rfh() {
392 return contents()->GetMainFrame();
395 TestWebContents* RenderViewHostImplTestHarness::contents() {
396 return static_cast<TestWebContents*>(web_contents());
399 } // namespace content