Update broken references to image assets
[chromium-blink-merge.git] / content / test / test_render_view_host.cc
blob520ac89106ce3bf66a1334c2bb4a711cb8deccdc
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 "base/strings/utf_string_conversions.h"
9 #include "content/browser/dom_storage/dom_storage_context_wrapper.h"
10 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
11 #include "content/browser/loader/resource_dispatcher_host_impl.h"
12 #include "content/browser/site_instance_impl.h"
13 #include "content/common/dom_storage/dom_storage_types.h"
14 #include "content/common/frame_messages.h"
15 #include "content/common/view_messages.h"
16 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/navigation_controller.h"
19 #include "content/public/browser/storage_partition.h"
20 #include "content/public/common/content_client.h"
21 #include "content/public/common/page_state.h"
22 #include "content/public/common/web_preferences.h"
23 #include "content/test/test_render_frame_host.h"
24 #include "content/test/test_web_contents.h"
25 #include "media/base/video_frame.h"
26 #include "ui/gfx/geometry/rect.h"
28 namespace content {
30 void InitNavigateParams(FrameHostMsg_DidCommitProvisionalLoad_Params* params,
31 int page_id,
32 int nav_entry_id,
33 bool did_create_new_entry,
34 const GURL& url,
35 ui::PageTransition transition) {
36 params->page_id = page_id;
37 params->nav_entry_id = nav_entry_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->did_create_new_entry = did_create_new_entry;
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)),
55 is_showing_(false),
56 is_occluded_(false),
57 did_swap_compositor_frame_(false) {
58 rwh_->SetView(this);
61 TestRenderWidgetHostView::~TestRenderWidgetHostView() {
64 RenderWidgetHost* TestRenderWidgetHostView::GetRenderWidgetHost() const {
65 return rwh_;
68 gfx::Vector2dF TestRenderWidgetHostView::GetLastScrollOffset() const {
69 return gfx::Vector2dF();
72 gfx::NativeView TestRenderWidgetHostView::GetNativeView() const {
73 return NULL;
76 gfx::NativeViewId TestRenderWidgetHostView::GetNativeViewId() const {
77 return 0;
80 gfx::NativeViewAccessible TestRenderWidgetHostView::GetNativeViewAccessible() {
81 return NULL;
84 ui::TextInputClient* TestRenderWidgetHostView::GetTextInputClient() {
85 return &text_input_client_;
88 bool TestRenderWidgetHostView::HasFocus() const {
89 return true;
92 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
93 return true;
96 void TestRenderWidgetHostView::Show() {
97 is_showing_ = true;
98 is_occluded_ = false;
101 void TestRenderWidgetHostView::Hide() {
102 is_showing_ = false;
105 bool TestRenderWidgetHostView::IsShowing() {
106 return is_showing_;
109 void TestRenderWidgetHostView::WasUnOccluded() {
110 is_occluded_ = false;
113 void TestRenderWidgetHostView::WasOccluded() {
114 is_occluded_ = true;
117 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status,
118 int error_code) {
119 delete this;
122 void TestRenderWidgetHostView::Destroy() { delete this; }
124 gfx::Rect TestRenderWidgetHostView::GetViewBounds() const {
125 return gfx::Rect();
128 void TestRenderWidgetHostView::CopyFromCompositingSurface(
129 const gfx::Rect& src_subrect,
130 const gfx::Size& dst_size,
131 ReadbackRequestCallback& callback,
132 const SkColorType preferred_color_type) {
133 callback.Run(SkBitmap(), content::READBACK_FAILED);
136 void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
137 const gfx::Rect& src_subrect,
138 const scoped_refptr<media::VideoFrame>& target,
139 const base::Callback<void(bool)>& callback) {
140 callback.Run(false);
143 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
144 return false;
147 bool TestRenderWidgetHostView::HasAcceleratedSurface(
148 const gfx::Size& desired_size) {
149 return false;
152 #if defined(OS_MACOSX)
154 void TestRenderWidgetHostView::SetActive(bool active) {
155 // <viettrungluu@gmail.com>: Do I need to do anything here?
158 bool TestRenderWidgetHostView::SupportsSpeech() const {
159 return false;
162 void TestRenderWidgetHostView::SpeakSelection() {
165 bool TestRenderWidgetHostView::IsSpeaking() const {
166 return false;
169 void TestRenderWidgetHostView::StopSpeaking() {
172 bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
173 const NativeWebKeyboardEvent& event) {
174 return false;
177 #endif
179 gfx::Rect TestRenderWidgetHostView::GetBoundsInRootWindow() {
180 return gfx::Rect();
183 void TestRenderWidgetHostView::OnSwapCompositorFrame(
184 uint32 output_surface_id,
185 scoped_ptr<cc::CompositorFrame> frame) {
186 did_swap_compositor_frame_ = true;
190 gfx::GLSurfaceHandle TestRenderWidgetHostView::GetCompositingSurface() {
191 return gfx::GLSurfaceHandle();
194 bool TestRenderWidgetHostView::LockMouse() {
195 return false;
198 void TestRenderWidgetHostView::UnlockMouse() {
201 #if defined(OS_WIN)
202 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
203 gfx::NativeViewAccessible accessible_parent) {
206 gfx::NativeViewId TestRenderWidgetHostView::GetParentForWindowlessPlugin()
207 const {
208 return 0;
210 #endif
212 TestRenderViewHost::TestRenderViewHost(
213 SiteInstance* instance,
214 RenderViewHostDelegate* delegate,
215 RenderWidgetHostDelegate* widget_delegate,
216 int routing_id,
217 int main_frame_routing_id,
218 bool swapped_out)
219 : RenderViewHostImpl(instance,
220 delegate,
221 widget_delegate,
222 routing_id,
223 main_frame_routing_id,
224 swapped_out,
225 false /* hidden */,
226 false /* has_initialized_audio_host */),
227 delete_counter_(NULL),
228 opener_frame_route_id_(MSG_ROUTING_NONE) {
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::CreateTestRenderView(
241 const base::string16& frame_name,
242 int opener_frame_route_id,
243 int proxy_route_id,
244 int32 max_page_id,
245 bool window_was_created_with_opener) {
246 FrameReplicationState replicated_state;
247 replicated_state.name = base::UTF16ToUTF8(frame_name);
248 return CreateRenderView(opener_frame_route_id, proxy_route_id, max_page_id,
249 replicated_state, window_was_created_with_opener);
252 bool TestRenderViewHost::CreateRenderView(
253 int opener_frame_route_id,
254 int proxy_route_id,
255 int32 max_page_id,
256 const FrameReplicationState& replicated_frame_state,
257 bool window_was_created_with_opener) {
258 DCHECK(!IsRenderViewLive());
259 set_renderer_initialized(true);
260 DCHECK(IsRenderViewLive());
261 opener_frame_route_id_ = opener_frame_route_id;
262 RenderFrameHost* main_frame = GetMainFrame();
263 if (main_frame)
264 static_cast<RenderFrameHostImpl*>(main_frame)->SetRenderFrameCreated(true);
266 return true;
269 bool TestRenderViewHost::IsFullscreenGranted() const {
270 return RenderViewHostImpl::IsFullscreenGranted();
273 MockRenderProcessHost* TestRenderViewHost::GetProcess() const {
274 return static_cast<MockRenderProcessHost*>(RenderViewHostImpl::GetProcess());
277 void TestRenderViewHost::SimulateWasHidden() {
278 WasHidden();
281 void TestRenderViewHost::SimulateWasShown() {
282 WasShown(ui::LatencyInfo());
285 WebPreferences TestRenderViewHost::TestComputeWebkitPrefs() {
286 return ComputeWebkitPrefs();
289 void TestRenderViewHost::TestOnStartDragging(
290 const DropData& drop_data) {
291 blink::WebDragOperationsMask drag_operation = blink::WebDragOperationEvery;
292 DragEventSourceInfo event_info;
293 OnStartDragging(drop_data, drag_operation, SkBitmap(), gfx::Vector2d(),
294 event_info);
297 void TestRenderViewHost::TestOnUpdateStateWithFile(
298 int page_id,
299 const base::FilePath& file_path) {
300 OnUpdateState(page_id,
301 PageState::CreateForTesting(GURL("http://www.google.com"),
302 false,
303 "data",
304 &file_path));
307 RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
308 std::vector<ui::ScaleFactor> scale_factors;
309 scale_factors.push_back(ui::SCALE_FACTOR_100P);
310 scoped_set_supported_scale_factors_.reset(
311 new ui::test::ScopedSetSupportedScaleFactors(scale_factors));
314 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
317 TestRenderViewHost* RenderViewHostImplTestHarness::test_rvh() {
318 return contents()->GetRenderViewHost();
321 TestRenderViewHost* RenderViewHostImplTestHarness::pending_test_rvh() {
322 return contents()->GetPendingMainFrame() ?
323 contents()->GetPendingMainFrame()->GetRenderViewHost() :
324 NULL;
327 TestRenderViewHost* RenderViewHostImplTestHarness::active_test_rvh() {
328 return static_cast<TestRenderViewHost*>(active_rvh());
331 TestRenderFrameHost* RenderViewHostImplTestHarness::main_test_rfh() {
332 return contents()->GetMainFrame();
335 TestWebContents* RenderViewHostImplTestHarness::contents() {
336 return static_cast<TestWebContents*>(web_contents());
339 } // namespace content