Call ComputeWebKitPrefs on the correct RVH, and remove dead code.
[chromium-blink-merge.git] / content / test / test_render_view_host.cc
blob5380c93cffdfdb4d7201cdc2772d9532487739e1
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/loader/resource_dispatcher_host_impl.h"
11 #include "content/browser/site_instance_impl.h"
12 #include "content/common/dom_storage/dom_storage_types.h"
13 #include "content/common/frame_messages.h"
14 #include "content/common/view_messages.h"
15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/storage_partition.h"
19 #include "content/public/common/content_client.h"
20 #include "content/public/common/page_state.h"
21 #include "content/public/common/web_preferences.h"
22 #include "content/test/test_render_frame_host.h"
23 #include "content/test/test_web_contents.h"
24 #include "media/base/video_frame.h"
25 #include "ui/gfx/geometry/rect.h"
27 namespace content {
29 void InitNavigateParams(FrameHostMsg_DidCommitProvisionalLoad_Params* params,
30 int page_id,
31 const GURL& url,
32 ui::PageTransition transition) {
33 params->page_id = page_id;
34 params->url = url;
35 params->referrer = Referrer();
36 params->transition = transition;
37 params->redirects = std::vector<GURL>();
38 params->should_update_history = false;
39 params->searchable_form_url = GURL();
40 params->searchable_form_encoding = std::string();
41 params->security_info = std::string();
42 params->gesture = NavigationGestureUser;
43 params->was_within_same_page = false;
44 params->is_post = false;
45 params->page_state = PageState::CreateFromURL(url);
48 TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost* rwh)
49 : rwh_(RenderWidgetHostImpl::From(rwh)),
50 is_showing_(false),
51 is_occluded_(false),
52 did_swap_compositor_frame_(false) {
53 rwh_->SetView(this);
56 TestRenderWidgetHostView::~TestRenderWidgetHostView() {
59 RenderWidgetHost* TestRenderWidgetHostView::GetRenderWidgetHost() const {
60 return NULL;
63 gfx::Vector2dF TestRenderWidgetHostView::GetLastScrollOffset() const {
64 return gfx::Vector2dF();
67 gfx::NativeView TestRenderWidgetHostView::GetNativeView() const {
68 return NULL;
71 gfx::NativeViewId TestRenderWidgetHostView::GetNativeViewId() const {
72 return 0;
75 gfx::NativeViewAccessible TestRenderWidgetHostView::GetNativeViewAccessible() {
76 return NULL;
79 ui::TextInputClient* TestRenderWidgetHostView::GetTextInputClient() {
80 return &text_input_client_;
83 bool TestRenderWidgetHostView::HasFocus() const {
84 return true;
87 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
88 return true;
91 void TestRenderWidgetHostView::Show() {
92 is_showing_ = true;
93 is_occluded_ = false;
96 void TestRenderWidgetHostView::Hide() {
97 is_showing_ = false;
100 bool TestRenderWidgetHostView::IsShowing() {
101 return is_showing_;
104 void TestRenderWidgetHostView::WasUnOccluded() {
105 is_occluded_ = false;
108 void TestRenderWidgetHostView::WasOccluded() {
109 is_occluded_ = true;
112 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status,
113 int error_code) {
114 delete this;
117 void TestRenderWidgetHostView::Destroy() { delete this; }
119 gfx::Rect TestRenderWidgetHostView::GetViewBounds() const {
120 return gfx::Rect();
123 void TestRenderWidgetHostView::CopyFromCompositingSurface(
124 const gfx::Rect& src_subrect,
125 const gfx::Size& dst_size,
126 ReadbackRequestCallback& callback,
127 const SkColorType color_type) {
128 callback.Run(SkBitmap(), content::READBACK_NOT_SUPPORTED);
131 void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
132 const gfx::Rect& src_subrect,
133 const scoped_refptr<media::VideoFrame>& target,
134 const base::Callback<void(bool)>& callback) {
135 callback.Run(false);
138 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
139 return false;
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 false /* has_initialized_audio_host */),
222 render_view_created_(false),
223 delete_counter_(NULL),
224 opener_route_id_(MSG_ROUTING_NONE) {
225 // TestRenderWidgetHostView installs itself into this->view_ in its
226 // constructor, and deletes itself when TestRenderWidgetHostView::Destroy() is
227 // called.
228 new TestRenderWidgetHostView(this);
231 TestRenderViewHost::~TestRenderViewHost() {
232 if (delete_counter_)
233 ++*delete_counter_;
236 bool TestRenderViewHost::CreateRenderView(
237 const base::string16& frame_name,
238 int opener_route_id,
239 int proxy_route_id,
240 int32 max_page_id,
241 bool window_was_created_with_opener) {
242 DCHECK(!render_view_created_);
243 render_view_created_ = true;
244 opener_route_id_ = opener_route_id;
245 return true;
248 bool TestRenderViewHost::IsRenderViewLive() const {
249 return render_view_created_;
252 bool TestRenderViewHost::IsFullscreen() const {
253 return RenderViewHostImpl::IsFullscreen();
256 void TestRenderViewHost::SimulateWasHidden() {
257 WasHidden();
260 void TestRenderViewHost::SimulateWasShown() {
261 WasShown(ui::LatencyInfo());
264 WebPreferences TestRenderViewHost::TestComputeWebkitPrefs() {
265 return ComputeWebkitPrefs();
268 void TestRenderViewHost::TestOnStartDragging(
269 const DropData& drop_data) {
270 blink::WebDragOperationsMask drag_operation = blink::WebDragOperationEvery;
271 DragEventSourceInfo event_info;
272 OnStartDragging(drop_data, drag_operation, SkBitmap(), gfx::Vector2d(),
273 event_info);
276 void TestRenderViewHost::TestOnUpdateStateWithFile(
277 int page_id,
278 const base::FilePath& file_path) {
279 OnUpdateState(page_id,
280 PageState::CreateForTesting(GURL("http://www.google.com"),
281 false,
282 "data",
283 &file_path));
286 RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
287 std::vector<ui::ScaleFactor> scale_factors;
288 scale_factors.push_back(ui::SCALE_FACTOR_100P);
289 scoped_set_supported_scale_factors_.reset(
290 new ui::test::ScopedSetSupportedScaleFactors(scale_factors));
293 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
296 TestRenderViewHost* RenderViewHostImplTestHarness::test_rvh() {
297 return contents()->GetRenderViewHost();
300 TestRenderViewHost* RenderViewHostImplTestHarness::pending_test_rvh() {
301 return contents()->GetPendingMainFrame() ?
302 contents()->GetPendingMainFrame()->GetRenderViewHost() :
303 NULL;
306 TestRenderViewHost* RenderViewHostImplTestHarness::active_test_rvh() {
307 return static_cast<TestRenderViewHost*>(active_rvh());
310 TestRenderFrameHost* RenderViewHostImplTestHarness::main_test_rfh() {
311 return contents()->GetMainFrame();
314 TestWebContents* RenderViewHostImplTestHarness::contents() {
315 return static_cast<TestWebContents*>(web_contents());
318 } // namespace content