1 // Copyright 2015 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 "components/html_viewer/web_test_delegate_impl.h"
9 #include "base/time/time.h"
10 #include "cc/layers/texture_layer.h"
11 #include "components/test_runner/web_task.h"
12 #include "components/test_runner/web_test_interfaces.h"
13 #include "components/test_runner/web_test_proxy.h"
14 #include "third_party/WebKit/public/platform/Platform.h"
15 #include "third_party/WebKit/public/platform/WebString.h"
16 #include "third_party/WebKit/public/platform/WebTaskRunner.h"
17 #include "third_party/WebKit/public/platform/WebThread.h"
18 #include "third_party/WebKit/public/platform/WebTraceLocation.h"
19 #include "third_party/WebKit/public/platform/WebURL.h"
22 namespace html_viewer
{
26 class InvokeTaskHelper
: public blink::WebTaskRunner::Task
{
28 InvokeTaskHelper(scoped_ptr
<test_runner::WebTask
> task
)
29 : task_(task
.Pass()) {}
31 // WebThread::Task implementation:
32 void run() override
{ task_
->run(); }
35 scoped_ptr
<test_runner::WebTask
> task_
;
40 WebTestDelegateImpl::WebTestDelegateImpl()
41 : test_interfaces_(nullptr), proxy_(nullptr) {
44 WebTestDelegateImpl::~WebTestDelegateImpl() {
47 void WebTestDelegateImpl::ClearEditCommand() {
51 void WebTestDelegateImpl::SetEditCommand(const std::string
& name
,
52 const std::string
& value
) {
56 void WebTestDelegateImpl::SetGamepadProvider(
57 test_runner::GamepadController
* controller
) {
61 void WebTestDelegateImpl::SetDeviceLightData(const double data
) {
65 void WebTestDelegateImpl::SetDeviceMotionData(
66 const blink::WebDeviceMotionData
& data
) {
70 void WebTestDelegateImpl::SetDeviceOrientationData(
71 const blink::WebDeviceOrientationData
& data
) {
75 void WebTestDelegateImpl::SetScreenOrientation(
76 const blink::WebScreenOrientationType
& orientation
) {
80 void WebTestDelegateImpl::ResetScreenOrientation() {
84 void WebTestDelegateImpl::DidChangeBatteryStatus(
85 const blink::WebBatteryStatus
& status
) {
89 void WebTestDelegateImpl::PrintMessage(const std::string
& message
) {
93 void WebTestDelegateImpl::PostTask(test_runner::WebTask
* task
) {
94 blink::Platform::current()->currentThread()->taskRunner()->postTask(
95 blink::WebTraceLocation(__FUNCTION__
, __FILE__
),
96 new InvokeTaskHelper(make_scoped_ptr(task
)));
99 void WebTestDelegateImpl::PostDelayedTask(test_runner::WebTask
* task
,
101 blink::Platform::current()->currentThread()->taskRunner()->postDelayedTask(
102 blink::WebTraceLocation(__FUNCTION__
, __FILE__
),
103 new InvokeTaskHelper(make_scoped_ptr(task
)), ms
);
106 blink::WebString
WebTestDelegateImpl::RegisterIsolatedFileSystem(
107 const blink::WebVector
<blink::WebString
>& absolute_filenames
) {
109 return blink::WebString();
112 long long WebTestDelegateImpl::GetCurrentTimeInMillisecond() {
113 return base::TimeDelta(base::Time::Now() - base::Time::UnixEpoch())
115 base::Time::kMicrosecondsPerMillisecond
;
118 blink::WebString
WebTestDelegateImpl::GetAbsoluteWebStringFromUTF8Path(
119 const std::string
& path
) {
121 return blink::WebString::fromUTF8(path
);
124 blink::WebURL
WebTestDelegateImpl::LocalFileToDataURL(
125 const blink::WebURL
& file_url
) {
127 return blink::WebURL();
130 blink::WebURL
WebTestDelegateImpl::RewriteLayoutTestsURL(
131 const std::string
& utf8_url
) {
132 return blink::WebURL(GURL(utf8_url
));
135 test_runner::TestPreferences
* WebTestDelegateImpl::Preferences() {
139 void WebTestDelegateImpl::ApplyPreferences() {
143 void WebTestDelegateImpl::UseUnfortunateSynchronousResizeMode(bool enable
) {
147 void WebTestDelegateImpl::EnableAutoResizeMode(const blink::WebSize
& min_size
,
148 const blink::WebSize
& max_size
) {
152 void WebTestDelegateImpl::DisableAutoResizeMode(
153 const blink::WebSize
& new_size
) {
157 void WebTestDelegateImpl::ClearDevToolsLocalStorage() {
161 void WebTestDelegateImpl::ShowDevTools(const std::string
& settings
,
162 const std::string
& frontend_url
) {
166 void WebTestDelegateImpl::CloseDevTools() {
170 void WebTestDelegateImpl::EvaluateInWebInspector(long call_id
,
171 const std::string
& script
) {
175 void WebTestDelegateImpl::ClearAllDatabases() {
179 void WebTestDelegateImpl::SetDatabaseQuota(int quota
) {
183 void WebTestDelegateImpl::SimulateWebNotificationClick(
184 const std::string
& title
, int action_index
) {
188 void WebTestDelegateImpl::SetDeviceScaleFactor(float factor
) {
192 void WebTestDelegateImpl::SetDeviceColorProfile(const std::string
& name
) {
196 void WebTestDelegateImpl::SetBluetoothMockDataSet(const std::string
& data_set
) {
200 void WebTestDelegateImpl::SetBluetoothManualChooser() {
204 std::vector
<std::string
>
205 WebTestDelegateImpl::GetBluetoothManualChooserEvents() {
207 return std::vector
<std::string
>();
210 void WebTestDelegateImpl::SendBluetoothManualChooserEvent(
211 const std::string
& event
,
212 const std::string
& argument
) {
216 void WebTestDelegateImpl::SetGeofencingMockProvider(bool service_available
) {
220 void WebTestDelegateImpl::ClearGeofencingMockProvider() {
224 void WebTestDelegateImpl::SetGeofencingMockPosition(double latitude
,
229 void WebTestDelegateImpl::SetFocus(test_runner::WebTestProxyBase
* proxy
,
234 void WebTestDelegateImpl::SetAcceptAllCookies(bool accept
) {
238 std::string
WebTestDelegateImpl::PathToLocalResource(
239 const std::string
& resource
) {
241 return std::string();
244 void WebTestDelegateImpl::SetLocale(const std::string
& locale
) {
248 void WebTestDelegateImpl::TestFinished() {
249 std::cout
<< "Content-Type: text/plain\n";
250 std::cout
<< proxy_
->CaptureTree(false, false);
251 std::cout
<< "#EOF\n";
253 test_interfaces_
->SetTestIsRunning(false);
254 if (!completion_callback_
.is_null())
255 completion_callback_
.Run();
258 void WebTestDelegateImpl::CloseRemainingWindows() {
262 void WebTestDelegateImpl::DeleteAllCookies() {
266 int WebTestDelegateImpl::NavigationEntryCount() {
271 void WebTestDelegateImpl::GoToOffset(int offset
) {
275 void WebTestDelegateImpl::Reload() {
279 void WebTestDelegateImpl::LoadURLForFrame(const blink::WebURL
& url
,
280 const std::string
& frame_name
) {
284 bool WebTestDelegateImpl::AllowExternalPages() {
289 std::string
WebTestDelegateImpl::DumpHistoryForWindow(
290 test_runner::WebTestProxyBase
* proxy
) {
292 return std::string();
295 void WebTestDelegateImpl::FetchManifest(
296 blink::WebView
* view
,
298 const base::Callback
<void(const blink::WebURLResponse
& response
,
299 const std::string
& data
)>& callback
) {
303 void WebTestDelegateImpl::SetPermission(const std::string
& permission_name
,
304 const std::string
& permission_value
,
306 const GURL
& embedding_origin
) {
310 void WebTestDelegateImpl::ResetPermissions() {
314 cc::SharedBitmapManager
* WebTestDelegateImpl::GetSharedBitmapManager() {
319 void WebTestDelegateImpl::DispatchBeforeInstallPromptEvent(
321 const std::vector
<std::string
>& event_platforms
,
322 const base::Callback
<void(bool)>& callback
) {
326 void WebTestDelegateImpl::ResolveBeforeInstallPromptPromise(int request_id
,
327 const std::string
& platform
) {
331 blink::WebPlugin
* WebTestDelegateImpl::CreatePluginPlaceholder(
332 blink::WebLocalFrame
* frame
,
333 const blink::WebPluginParams
& params
) {
338 void WebTestDelegateImpl::OnWebTestProxyBaseDestroy(
339 test_runner::WebTestProxyBase
* base
) {
342 } // namespace html_viewer