[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / content / test / test_render_view_host.cc
blob6a1177d939d579ade07b4bb01a8107390e598d17
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_web_contents.h"
21 #include "media/base/video_frame.h"
22 #include "ui/gfx/rect.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 ui::TextInputClient* TestRenderWidgetHostView::GetTextInputClient() {
72 return &text_input_client_;
75 bool TestRenderWidgetHostView::HasFocus() const {
76 return true;
79 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
80 return true;
83 void TestRenderWidgetHostView::Show() {
84 is_showing_ = true;
87 void TestRenderWidgetHostView::Hide() {
88 is_showing_ = false;
91 bool TestRenderWidgetHostView::IsShowing() {
92 return is_showing_;
95 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status,
96 int error_code) {
97 delete this;
100 void TestRenderWidgetHostView::Destroy() { delete this; }
102 gfx::Rect TestRenderWidgetHostView::GetViewBounds() const {
103 return gfx::Rect();
106 void TestRenderWidgetHostView::CopyFromCompositingSurface(
107 const gfx::Rect& src_subrect,
108 const gfx::Size& dst_size,
109 const base::Callback<void(bool, const SkBitmap&)>& callback,
110 const SkColorType color_type) {
111 callback.Run(false, SkBitmap());
114 void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
115 const gfx::Rect& src_subrect,
116 const scoped_refptr<media::VideoFrame>& target,
117 const base::Callback<void(bool)>& callback) {
118 callback.Run(false);
121 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
122 return false;
125 void TestRenderWidgetHostView::AcceleratedSurfaceInitialized(int host_id,
126 int route_id) {
129 void TestRenderWidgetHostView::AcceleratedSurfaceBuffersSwapped(
130 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
131 int gpu_host_id) {
134 void TestRenderWidgetHostView::AcceleratedSurfacePostSubBuffer(
135 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
136 int gpu_host_id) {
139 void TestRenderWidgetHostView::AcceleratedSurfaceSuspend() {
142 bool TestRenderWidgetHostView::HasAcceleratedSurface(
143 const gfx::Size& desired_size) {
144 return false;
147 #if defined(OS_MACOSX)
149 void TestRenderWidgetHostView::SetActive(bool active) {
150 // <viettrungluu@gmail.com>: Do I need to do anything here?
153 bool TestRenderWidgetHostView::SupportsSpeech() const {
154 return false;
157 void TestRenderWidgetHostView::SpeakSelection() {
160 bool TestRenderWidgetHostView::IsSpeaking() const {
161 return false;
164 void TestRenderWidgetHostView::StopSpeaking() {
167 bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
168 const NativeWebKeyboardEvent& event) {
169 return false;
172 #endif
174 gfx::Rect TestRenderWidgetHostView::GetBoundsInRootWindow() {
175 return gfx::Rect();
178 void TestRenderWidgetHostView::OnSwapCompositorFrame(
179 uint32 output_surface_id,
180 scoped_ptr<cc::CompositorFrame> frame) {
181 did_swap_compositor_frame_ = true;
185 gfx::GLSurfaceHandle TestRenderWidgetHostView::GetCompositingSurface() {
186 return gfx::GLSurfaceHandle();
189 bool TestRenderWidgetHostView::LockMouse() {
190 return false;
193 void TestRenderWidgetHostView::UnlockMouse() {
196 #if defined(OS_WIN)
197 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
198 gfx::NativeViewAccessible accessible_parent) {
201 gfx::NativeViewId TestRenderWidgetHostView::GetParentForWindowlessPlugin()
202 const {
203 return 0;
205 #endif
207 TestRenderViewHost::TestRenderViewHost(
208 SiteInstance* instance,
209 RenderViewHostDelegate* delegate,
210 RenderWidgetHostDelegate* widget_delegate,
211 int routing_id,
212 int main_frame_routing_id,
213 bool swapped_out)
214 : RenderViewHostImpl(instance,
215 delegate,
216 widget_delegate,
217 routing_id,
218 main_frame_routing_id,
219 swapped_out,
220 false /* hidden */),
221 render_view_created_(false),
222 delete_counter_(NULL),
223 simulate_fetch_via_proxy_(false),
224 simulate_history_list_was_cleared_(false),
225 contents_mime_type_("text/html"),
226 opener_route_id_(MSG_ROUTING_NONE),
227 main_render_frame_host_(NULL) {
228 // TestRenderWidgetHostView installs itself into this->view_ in its
229 // constructor, and deletes itself when TestRenderWidgetHostView::Destroy() is
230 // called.
231 new TestRenderWidgetHostView(this);
234 TestRenderViewHost::~TestRenderViewHost() {
235 if (delete_counter_)
236 ++*delete_counter_;
239 bool TestRenderViewHost::CreateRenderView(
240 const base::string16& frame_name,
241 int opener_route_id,
242 int proxy_route_id,
243 int32 max_page_id,
244 bool window_was_created_with_opener) {
245 DCHECK(!render_view_created_);
246 render_view_created_ = true;
247 opener_route_id_ = opener_route_id;
248 return true;
251 bool TestRenderViewHost::IsRenderViewLive() const {
252 return render_view_created_;
255 bool TestRenderViewHost::IsFullscreen() const {
256 return RenderViewHostImpl::IsFullscreen();
259 void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) {
260 main_render_frame_host_->SendNavigate(page_id, url);
263 void TestRenderViewHost::SendFailedNavigate(int page_id, const GURL& url) {
264 main_render_frame_host_->SendFailedNavigate(page_id, url);
267 void TestRenderViewHost::SendNavigateWithTransition(
268 int page_id,
269 const GURL& url,
270 PageTransition transition) {
271 main_render_frame_host_->SendNavigateWithTransition(page_id, url, transition);
274 void TestRenderViewHost::SendNavigateWithOriginalRequestURL(
275 int page_id,
276 const GURL& url,
277 const GURL& original_request_url) {
278 main_render_frame_host_->SendNavigateWithOriginalRequestURL(
279 page_id, url, original_request_url);
282 void TestRenderViewHost::SendNavigateWithFile(
283 int page_id,
284 const GURL& url,
285 const base::FilePath& file_path) {
286 main_render_frame_host_->SendNavigateWithFile(page_id, url, file_path);
289 void TestRenderViewHost::SendNavigateWithParams(
290 FrameHostMsg_DidCommitProvisionalLoad_Params* params) {
291 main_render_frame_host_->SendNavigateWithParams(params);
294 void TestRenderViewHost::SendNavigateWithTransitionAndResponseCode(
295 int page_id,
296 const GURL& url,
297 PageTransition transition,
298 int response_code) {
299 main_render_frame_host_->SendNavigateWithTransitionAndResponseCode(
300 page_id, url, transition, response_code);
303 void TestRenderViewHost::SendNavigateWithParameters(
304 int page_id,
305 const GURL& url,
306 PageTransition transition,
307 const GURL& original_request_url,
308 int response_code,
309 const base::FilePath* file_path_for_history_item) {
311 main_render_frame_host_->SendNavigateWithParameters(
312 page_id, url, transition, original_request_url, response_code,
313 file_path_for_history_item, std::vector<GURL>());
316 void TestRenderViewHost::SendBeforeUnloadACK(bool proceed) {
317 // TODO(creis): Move this whole method to TestRenderFrameHost.
318 base::TimeTicks now = base::TimeTicks::Now();
319 main_render_frame_host_->OnBeforeUnloadACK(proceed, now, now);
322 void TestRenderViewHost::SetContentsMimeType(const std::string& mime_type) {
323 contents_mime_type_ = mime_type;
324 main_render_frame_host_->set_contents_mime_type(mime_type);
327 void TestRenderViewHost::SimulateSwapOutACK() {
328 OnSwappedOut(false);
331 void TestRenderViewHost::SimulateWasHidden() {
332 WasHidden();
335 void TestRenderViewHost::SimulateWasShown() {
336 WasShown();
339 void TestRenderViewHost::TestOnStartDragging(
340 const DropData& drop_data) {
341 blink::WebDragOperationsMask drag_operation = blink::WebDragOperationEvery;
342 DragEventSourceInfo event_info;
343 OnStartDragging(drop_data, drag_operation, SkBitmap(), gfx::Vector2d(),
344 event_info);
347 void TestRenderViewHost::TestOnUpdateStateWithFile(
348 int process_id,
349 const base::FilePath& file_path) {
350 OnUpdateState(process_id,
351 PageState::CreateForTesting(GURL("http://www.google.com"),
352 false,
353 "data",
354 &file_path));
357 void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy) {
358 simulate_fetch_via_proxy_ = proxy;
361 void TestRenderViewHost::set_simulate_history_list_was_cleared(bool cleared) {
362 simulate_history_list_was_cleared_ = cleared;
363 main_render_frame_host_->set_simulate_history_list_was_cleared(cleared);
366 RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
367 std::vector<ui::ScaleFactor> scale_factors;
368 scale_factors.push_back(ui::SCALE_FACTOR_100P);
369 scoped_set_supported_scale_factors_.reset(
370 new ui::test::ScopedSetSupportedScaleFactors(scale_factors));
373 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
376 TestRenderViewHost* RenderViewHostImplTestHarness::test_rvh() {
377 return static_cast<TestRenderViewHost*>(rvh());
380 TestRenderViewHost* RenderViewHostImplTestHarness::pending_test_rvh() {
381 return static_cast<TestRenderViewHost*>(pending_rvh());
384 TestRenderViewHost* RenderViewHostImplTestHarness::active_test_rvh() {
385 return static_cast<TestRenderViewHost*>(active_rvh());
388 TestRenderFrameHost* RenderViewHostImplTestHarness::main_test_rfh() {
389 return static_cast<TestRenderFrameHost*>(main_rfh());
392 TestWebContents* RenderViewHostImplTestHarness::contents() {
393 return static_cast<TestWebContents*>(web_contents());
396 } // namespace content