IDB: Make readonly transactions wait for earlier readwrite transactions
[chromium-blink-merge.git] / content / test / test_render_view_host.cc
blob957fae8414caab962749f779a84064186fd75770
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/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 did_swap_compositor_frame_(false) {
52 rwh_->SetView(this);
55 TestRenderWidgetHostView::~TestRenderWidgetHostView() {
58 RenderWidgetHost* TestRenderWidgetHostView::GetRenderWidgetHost() const {
59 return NULL;
62 gfx::Vector2dF TestRenderWidgetHostView::GetLastScrollOffset() const {
63 return gfx::Vector2dF();
66 gfx::NativeView TestRenderWidgetHostView::GetNativeView() const {
67 return NULL;
70 gfx::NativeViewId TestRenderWidgetHostView::GetNativeViewId() const {
71 return 0;
74 gfx::NativeViewAccessible TestRenderWidgetHostView::GetNativeViewAccessible() {
75 return NULL;
78 ui::TextInputClient* TestRenderWidgetHostView::GetTextInputClient() {
79 return &text_input_client_;
82 bool TestRenderWidgetHostView::HasFocus() const {
83 return true;
86 bool TestRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
87 return true;
90 void TestRenderWidgetHostView::Show() {
91 is_showing_ = true;
94 void TestRenderWidgetHostView::Hide() {
95 is_showing_ = false;
98 bool TestRenderWidgetHostView::IsShowing() {
99 return is_showing_;
102 void TestRenderWidgetHostView::RenderProcessGone(base::TerminationStatus status,
103 int error_code) {
104 delete this;
107 void TestRenderWidgetHostView::Destroy() { delete this; }
109 gfx::Rect TestRenderWidgetHostView::GetViewBounds() const {
110 return gfx::Rect();
113 void TestRenderWidgetHostView::CopyFromCompositingSurface(
114 const gfx::Rect& src_subrect,
115 const gfx::Size& dst_size,
116 ReadbackRequestCallback& callback,
117 const SkColorType color_type) {
118 callback.Run(SkBitmap(), content::READBACK_NOT_SUPPORTED);
121 void TestRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
122 const gfx::Rect& src_subrect,
123 const scoped_refptr<media::VideoFrame>& target,
124 const base::Callback<void(bool)>& callback) {
125 callback.Run(false);
128 bool TestRenderWidgetHostView::CanCopyToVideoFrame() const {
129 return false;
132 bool TestRenderWidgetHostView::HasAcceleratedSurface(
133 const gfx::Size& desired_size) {
134 return false;
137 #if defined(OS_MACOSX)
139 void TestRenderWidgetHostView::SetActive(bool active) {
140 // <viettrungluu@gmail.com>: Do I need to do anything here?
143 bool TestRenderWidgetHostView::SupportsSpeech() const {
144 return false;
147 void TestRenderWidgetHostView::SpeakSelection() {
150 bool TestRenderWidgetHostView::IsSpeaking() const {
151 return false;
154 void TestRenderWidgetHostView::StopSpeaking() {
157 bool TestRenderWidgetHostView::PostProcessEventForPluginIme(
158 const NativeWebKeyboardEvent& event) {
159 return false;
162 #endif
164 gfx::Rect TestRenderWidgetHostView::GetBoundsInRootWindow() {
165 return gfx::Rect();
168 void TestRenderWidgetHostView::OnSwapCompositorFrame(
169 uint32 output_surface_id,
170 scoped_ptr<cc::CompositorFrame> frame) {
171 did_swap_compositor_frame_ = true;
175 gfx::GLSurfaceHandle TestRenderWidgetHostView::GetCompositingSurface() {
176 return gfx::GLSurfaceHandle();
179 bool TestRenderWidgetHostView::LockMouse() {
180 return false;
183 void TestRenderWidgetHostView::UnlockMouse() {
186 #if defined(OS_WIN)
187 void TestRenderWidgetHostView::SetParentNativeViewAccessible(
188 gfx::NativeViewAccessible accessible_parent) {
191 gfx::NativeViewId TestRenderWidgetHostView::GetParentForWindowlessPlugin()
192 const {
193 return 0;
195 #endif
197 TestRenderViewHost::TestRenderViewHost(
198 SiteInstance* instance,
199 RenderViewHostDelegate* delegate,
200 RenderWidgetHostDelegate* widget_delegate,
201 int routing_id,
202 int main_frame_routing_id,
203 bool swapped_out)
204 : RenderViewHostImpl(instance,
205 delegate,
206 widget_delegate,
207 routing_id,
208 main_frame_routing_id,
209 swapped_out,
210 false /* hidden */,
211 false /* has_initialized_audio_host */),
212 render_view_created_(false),
213 delete_counter_(NULL),
214 opener_route_id_(MSG_ROUTING_NONE) {
215 // TestRenderWidgetHostView installs itself into this->view_ in its
216 // constructor, and deletes itself when TestRenderWidgetHostView::Destroy() is
217 // called.
218 new TestRenderWidgetHostView(this);
221 TestRenderViewHost::~TestRenderViewHost() {
222 if (delete_counter_)
223 ++*delete_counter_;
226 bool TestRenderViewHost::CreateRenderView(
227 const base::string16& frame_name,
228 int opener_route_id,
229 int proxy_route_id,
230 int32 max_page_id,
231 bool window_was_created_with_opener) {
232 DCHECK(!render_view_created_);
233 render_view_created_ = true;
234 opener_route_id_ = opener_route_id;
235 return true;
238 bool TestRenderViewHost::IsRenderViewLive() const {
239 return render_view_created_;
242 bool TestRenderViewHost::IsFullscreen() const {
243 return RenderViewHostImpl::IsFullscreen();
246 void TestRenderViewHost::SimulateWasHidden() {
247 WasHidden();
250 void TestRenderViewHost::SimulateWasShown() {
251 WasShown(ui::LatencyInfo());
254 void TestRenderViewHost::TestOnStartDragging(
255 const DropData& drop_data) {
256 blink::WebDragOperationsMask drag_operation = blink::WebDragOperationEvery;
257 DragEventSourceInfo event_info;
258 OnStartDragging(drop_data, drag_operation, SkBitmap(), gfx::Vector2d(),
259 event_info);
262 void TestRenderViewHost::TestOnUpdateStateWithFile(
263 int page_id,
264 const base::FilePath& file_path) {
265 OnUpdateState(page_id,
266 PageState::CreateForTesting(GURL("http://www.google.com"),
267 false,
268 "data",
269 &file_path));
272 RenderViewHostImplTestHarness::RenderViewHostImplTestHarness() {
273 std::vector<ui::ScaleFactor> scale_factors;
274 scale_factors.push_back(ui::SCALE_FACTOR_100P);
275 scoped_set_supported_scale_factors_.reset(
276 new ui::test::ScopedSetSupportedScaleFactors(scale_factors));
279 RenderViewHostImplTestHarness::~RenderViewHostImplTestHarness() {
282 TestRenderViewHost* RenderViewHostImplTestHarness::test_rvh() {
283 return contents()->GetRenderViewHost();
286 TestRenderViewHost* RenderViewHostImplTestHarness::pending_test_rvh() {
287 return contents()->GetPendingMainFrame() ?
288 contents()->GetPendingMainFrame()->GetRenderViewHost() :
289 NULL;
292 TestRenderViewHost* RenderViewHostImplTestHarness::active_test_rvh() {
293 return static_cast<TestRenderViewHost*>(active_rvh());
296 TestRenderFrameHost* RenderViewHostImplTestHarness::main_test_rfh() {
297 return contents()->GetMainFrame();
300 TestWebContents* RenderViewHostImplTestHarness::contents() {
301 return static_cast<TestWebContents*>(web_contents());
304 } // namespace content