Cast: Skip receiver log messages with time delta that can't be encoded.
[chromium-blink-merge.git] / content / test / layouttest_support.cc
blob9f175e0a7aaef8ab0aa13d9b0d47c468c1b1f968
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/public/test/layouttest_support.h"
7 #include "base/callback.h"
8 #include "base/lazy_instance.h"
9 #include "content/browser/renderer_host/render_widget_host_impl.h"
10 #include "content/common/gpu/image_transport_surface.h"
11 #include "content/renderer/render_thread_impl.h"
12 #include "content/renderer/render_view_impl.h"
13 #include "content/renderer/renderer_webkitplatformsupport_impl.h"
14 #include "content/shell/renderer/test_runner/WebFrameTestProxy.h"
15 #include "content/shell/renderer/test_runner/WebTestProxy.h"
16 #include "content/test/test_media_stream_client.h"
17 #include "third_party/WebKit/public/platform/WebDeviceMotionData.h"
18 #include "third_party/WebKit/public/platform/WebDeviceOrientationData.h"
19 #include "third_party/WebKit/public/platform/WebGamepads.h"
21 #if defined(OS_MACOSX)
22 #include "content/browser/renderer_host/popup_menu_helper_mac.h"
23 #endif
25 using blink::WebDeviceMotionData;
26 using blink::WebDeviceOrientationData;
27 using blink::WebGamepads;
28 using blink::WebRect;
29 using blink::WebSize;
30 using WebTestRunner::WebFrameTestProxy;
31 using WebTestRunner::WebTestProxy;
32 using WebTestRunner::WebTestProxyBase;
34 namespace content {
36 namespace {
38 base::LazyInstance<base::Callback<void(RenderView*, WebTestProxyBase*)> >::Leaky
39 g_callback = LAZY_INSTANCE_INITIALIZER;
41 RenderViewImpl* CreateWebTestProxy(RenderViewImplParams* params) {
42 typedef WebTestProxy<RenderViewImpl, RenderViewImplParams*> ProxyType;
43 ProxyType* render_view_proxy = new ProxyType(
44 reinterpret_cast<RenderViewImplParams*>(params));
45 if (g_callback == 0)
46 return render_view_proxy;
47 g_callback.Get().Run(
48 static_cast<RenderView*>(render_view_proxy), render_view_proxy);
49 return render_view_proxy;
52 WebTestProxyBase* GetWebTestProxyBase(RenderViewImpl* render_view) {
53 typedef WebTestProxy<RenderViewImpl, RenderViewImplParams*> ViewProxy;
55 ViewProxy* render_view_proxy = static_cast<ViewProxy*>(render_view);
56 return static_cast<WebTestProxyBase*>(render_view_proxy);
59 RenderFrameImpl* CreateWebFrameTestProxy(
60 RenderViewImpl* render_view,
61 int32 routing_id) {
62 typedef WebFrameTestProxy<RenderFrameImpl, RenderViewImpl*, int32> FrameProxy;
64 FrameProxy* render_frame_proxy = new FrameProxy(render_view, routing_id);
65 render_frame_proxy->setBaseProxy(GetWebTestProxyBase(render_view));
66 render_frame_proxy->setVersion(3);
68 return render_frame_proxy;
71 } // namespace
74 void EnableWebTestProxyCreation(
75 const base::Callback<void(RenderView*, WebTestProxyBase*)>& callback) {
76 g_callback.Get() = callback;
77 RenderViewImpl::InstallCreateHook(CreateWebTestProxy);
78 RenderFrameImpl::InstallCreateHook(CreateWebFrameTestProxy);
81 void SetMockGamepads(const WebGamepads& pads) {
82 RendererWebKitPlatformSupportImpl::SetMockGamepadsForTesting(pads);
85 void SetMockDeviceMotionData(const WebDeviceMotionData& data) {
86 RendererWebKitPlatformSupportImpl::SetMockDeviceMotionDataForTesting(data);
89 void SetMockDeviceOrientationData(const WebDeviceOrientationData& data) {
90 RendererWebKitPlatformSupportImpl::
91 SetMockDeviceOrientationDataForTesting(data);
94 void EnableRendererLayoutTestMode() {
95 RenderThreadImpl::current()->set_layout_test_mode(true);
98 void EnableBrowserLayoutTestMode() {
99 #if defined(OS_MACOSX)
100 ImageTransportSurface::SetAllowOSMesaForTesting(true);
101 PopupMenuHelper::DontShowPopupMenuForTesting();
102 #endif
103 RenderWidgetHostImpl::DisableResizeAckCheckForTesting();
106 int GetLocalSessionHistoryLength(RenderView* render_view) {
107 return static_cast<RenderViewImpl*>(render_view)->
108 GetLocalSessionHistoryLengthForTesting();
111 void SyncNavigationState(RenderView* render_view) {
112 static_cast<RenderViewImpl*>(render_view)->SyncNavigationState();
115 void SetFocusAndActivate(RenderView* render_view, bool enable) {
116 static_cast<RenderViewImpl*>(render_view)->
117 SetFocusAndActivateForTesting(enable);
120 void ForceResizeRenderView(RenderView* render_view,
121 const WebSize& new_size) {
122 RenderViewImpl* render_view_impl = static_cast<RenderViewImpl*>(render_view);
123 render_view_impl->ForceResizeForTesting(new_size);
124 GetWebTestProxyBase(render_view_impl)->didForceResize();
127 void SetDeviceScaleFactor(RenderView* render_view, float factor) {
128 static_cast<RenderViewImpl*>(render_view)->
129 SetDeviceScaleFactorForTesting(factor);
132 void UseSynchronousResizeMode(RenderView* render_view, bool enable) {
133 static_cast<RenderViewImpl*>(render_view)->
134 UseSynchronousResizeModeForTesting(enable);
137 void EnableAutoResizeMode(RenderView* render_view,
138 const WebSize& min_size,
139 const WebSize& max_size) {
140 static_cast<RenderViewImpl*>(render_view)->
141 EnableAutoResizeForTesting(min_size, max_size);
144 void DisableAutoResizeMode(RenderView* render_view, const WebSize& new_size) {
145 static_cast<RenderViewImpl*>(render_view)->
146 DisableAutoResizeForTesting(new_size);
149 void UseMockMediaStreams(RenderView* render_view) {
150 RenderViewImpl* render_view_impl = static_cast<RenderViewImpl*>(render_view);
151 render_view_impl->SetMediaStreamClientForTesting(
152 new TestMediaStreamClient(render_view_impl));
155 } // namespace content