1 // Copyright 2014 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/test_runner/test_runner.h"
9 #include "base/logging.h"
10 #include "components/test_runner/mock_credential_manager_client.h"
11 #include "components/test_runner/mock_web_speech_recognizer.h"
12 #include "components/test_runner/test_interfaces.h"
13 #include "components/test_runner/test_preferences.h"
14 #include "components/test_runner/web_content_settings.h"
15 #include "components/test_runner/web_test_delegate.h"
16 #include "components/test_runner/web_test_proxy.h"
17 #include "gin/arguments.h"
18 #include "gin/array_buffer.h"
19 #include "gin/handle.h"
20 #include "gin/object_template_builder.h"
21 #include "gin/wrappable.h"
22 #include "third_party/WebKit/public/platform/WebBatteryStatus.h"
23 #include "third_party/WebKit/public/platform/WebCanvas.h"
24 #include "third_party/WebKit/public/platform/WebData.h"
25 #include "third_party/WebKit/public/platform/WebPasswordCredential.h"
26 #include "third_party/WebKit/public/platform/WebPoint.h"
27 #include "third_party/WebKit/public/platform/WebURLResponse.h"
28 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceMotionData.h"
29 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceOrientationData.h"
30 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWorkerRegistration.h"
31 #include "third_party/WebKit/public/web/WebArrayBuffer.h"
32 #include "third_party/WebKit/public/web/WebArrayBufferConverter.h"
33 #include "third_party/WebKit/public/web/WebBindings.h"
34 #include "third_party/WebKit/public/web/WebDataSource.h"
35 #include "third_party/WebKit/public/web/WebDocument.h"
36 #include "third_party/WebKit/public/web/WebFindOptions.h"
37 #include "third_party/WebKit/public/web/WebFrame.h"
38 #include "third_party/WebKit/public/web/WebGraphicsContext.h"
39 #include "third_party/WebKit/public/web/WebInputElement.h"
40 #include "third_party/WebKit/public/web/WebKit.h"
41 #include "third_party/WebKit/public/web/WebLocalFrame.h"
42 #include "third_party/WebKit/public/web/WebScriptSource.h"
43 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
44 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
45 #include "third_party/WebKit/public/web/WebSettings.h"
46 #include "third_party/WebKit/public/web/WebSurroundingText.h"
47 #include "third_party/WebKit/public/web/WebView.h"
48 #include "third_party/skia/include/core/SkBitmap.h"
49 #include "third_party/skia/include/core/SkCanvas.h"
50 #include "ui/gfx/geometry/rect.h"
51 #include "ui/gfx/geometry/rect_f.h"
52 #include "ui/gfx/geometry/size.h"
53 #include "ui/gfx/skia_util.h"
55 #if defined(__linux__) || defined(ANDROID)
56 #include "third_party/WebKit/public/web/linux/WebFontRendering.h"
59 using namespace blink
;
61 namespace test_runner
{
65 WebString
V8StringToWebString(v8::Local
<v8::String
> v8_str
) {
66 int length
= v8_str
->Utf8Length() + 1;
67 scoped_ptr
<char[]> chars(new char[length
]);
68 v8_str
->WriteUtf8(chars
.get(), length
);
69 return WebString::fromUTF8(chars
.get());
72 class HostMethodTask
: public WebMethodTask
<TestRunner
> {
74 typedef void (TestRunner::*CallbackMethodType
)();
75 HostMethodTask(TestRunner
* object
, CallbackMethodType callback
)
76 : WebMethodTask
<TestRunner
>(object
), callback_(callback
) {}
78 void RunIfValid() override
{ (object_
->*callback_
)(); }
81 CallbackMethodType callback_
;
86 class InvokeCallbackTask
: public WebMethodTask
<TestRunner
> {
88 InvokeCallbackTask(TestRunner
* object
, v8::Local
<v8::Function
> callback
)
89 : WebMethodTask
<TestRunner
>(object
),
90 callback_(blink::mainThreadIsolate(), callback
),
93 void RunIfValid() override
{
94 v8::Isolate
* isolate
= blink::mainThreadIsolate();
95 v8::HandleScope
handle_scope(isolate
);
96 WebFrame
* frame
= object_
->web_view_
->mainFrame();
98 v8::Local
<v8::Context
> context
= frame
->mainWorldScriptContext();
99 if (context
.IsEmpty())
102 v8::Context::Scope
context_scope(context
);
104 scoped_ptr
<v8::Local
<v8::Value
>[]> local_argv
;
106 local_argv
.reset(new v8::Local
<v8::Value
>[argc_
]);
107 for (int i
= 0; i
< argc_
; ++i
)
108 local_argv
[i
] = v8::Local
<v8::Value
>::New(isolate
, argv_
[i
]);
111 frame
->callFunctionEvenIfScriptDisabled(
112 v8::Local
<v8::Function
>::New(isolate
, callback_
),
118 void SetArguments(int argc
, v8::Local
<v8::Value
> argv
[]) {
119 v8::Isolate
* isolate
= blink::mainThreadIsolate();
121 argv_
.reset(new v8::UniquePersistent
<v8::Value
>[argc
]);
122 for (int i
= 0; i
< argc
; ++i
)
123 argv_
[i
] = v8::UniquePersistent
<v8::Value
>(isolate
, argv
[i
]);
127 v8::UniquePersistent
<v8::Function
> callback_
;
129 scoped_ptr
<v8::UniquePersistent
<v8::Value
>[]> argv_
;
132 class TestRunnerBindings
: public gin::Wrappable
<TestRunnerBindings
> {
134 static gin::WrapperInfo kWrapperInfo
;
136 static void Install(base::WeakPtr
<TestRunner
> controller
,
140 explicit TestRunnerBindings(
141 base::WeakPtr
<TestRunner
> controller
);
142 ~TestRunnerBindings() override
;
145 gin::ObjectTemplateBuilder
GetObjectTemplateBuilder(
146 v8::Isolate
* isolate
) override
;
148 void LogToStderr(const std::string
& output
);
150 void WaitUntilDone();
151 void QueueBackNavigation(int how_far_back
);
152 void QueueForwardNavigation(int how_far_forward
);
154 void QueueLoadingScript(const std::string
& script
);
155 void QueueNonLoadingScript(const std::string
& script
);
156 void QueueLoad(gin::Arguments
* args
);
157 void QueueLoadHTMLString(gin::Arguments
* args
);
158 void SetCustomPolicyDelegate(gin::Arguments
* args
);
159 void WaitForPolicyDelegate();
161 void SetCloseRemainingWindowsWhenComplete(gin::Arguments
* args
);
162 void ResetTestHelperControllers();
163 void SetTabKeyCyclesThroughElements(bool tab_key_cycles_through_elements
);
164 void ExecCommand(gin::Arguments
* args
);
165 bool IsCommandEnabled(const std::string
& command
);
166 bool CallShouldCloseOnWebView();
167 void SetDomainRelaxationForbiddenForURLScheme(bool forbidden
,
168 const std::string
& scheme
);
169 v8::Local
<v8::Value
> EvaluateScriptInIsolatedWorldAndReturnValue(
170 int world_id
, const std::string
& script
);
171 void EvaluateScriptInIsolatedWorld(int world_id
, const std::string
& script
);
172 void SetIsolatedWorldSecurityOrigin(int world_id
,
173 v8::Local
<v8::Value
> origin
);
174 void SetIsolatedWorldContentSecurityPolicy(int world_id
,
175 const std::string
& policy
);
176 void AddOriginAccessWhitelistEntry(const std::string
& source_origin
,
177 const std::string
& destination_protocol
,
178 const std::string
& destination_host
,
179 bool allow_destination_subdomains
);
180 void RemoveOriginAccessWhitelistEntry(const std::string
& source_origin
,
181 const std::string
& destination_protocol
,
182 const std::string
& destination_host
,
183 bool allow_destination_subdomains
);
184 bool HasCustomPageSizeStyle(int page_index
);
185 void ForceRedSelectionColors();
186 void InsertStyleSheet(const std::string
& source_code
);
187 bool FindString(const std::string
& search_text
,
188 const std::vector
<std::string
>& options_array
);
189 std::string
SelectionAsMarkup();
190 void SetTextSubpixelPositioning(bool value
);
191 void SetPageVisibility(const std::string
& new_visibility
);
192 void SetTextDirection(const std::string
& direction_name
);
193 void UseUnfortunateSynchronousResizeMode();
194 bool EnableAutoResizeMode(int min_width
,
198 bool DisableAutoResizeMode(int new_width
, int new_height
);
199 void SetMockDeviceLight(double value
);
200 void ResetDeviceLight();
201 void SetMockDeviceMotion(gin::Arguments
* args
);
202 void SetMockDeviceOrientation(gin::Arguments
* args
);
203 void SetMockScreenOrientation(const std::string
& orientation
);
204 void DidChangeBatteryStatus(bool charging
,
206 double dischargingTime
,
208 void ResetBatteryStatus();
209 void DidAcquirePointerLock();
210 void DidNotAcquirePointerLock();
211 void DidLosePointerLock();
212 void SetPointerLockWillFailSynchronously();
213 void SetPointerLockWillRespondAsynchronously();
214 void SetPopupBlockingEnabled(bool block_popups
);
215 void SetJavaScriptCanAccessClipboard(bool can_access
);
216 void SetXSSAuditorEnabled(bool enabled
);
217 void SetAllowUniversalAccessFromFileURLs(bool allow
);
218 void SetAllowFileAccessFromFileURLs(bool allow
);
219 void OverridePreference(const std::string key
, v8::Local
<v8::Value
> value
);
220 void SetAcceptLanguages(const std::string
& accept_languages
);
221 void SetPluginsEnabled(bool enabled
);
222 void DumpEditingCallbacks();
225 void DumpAsTextWithPixelResults();
226 void DumpChildFrameScrollPositions();
227 void DumpChildFramesAsMarkup();
228 void DumpChildFramesAsText();
229 void DumpIconChanges();
230 void SetAudioData(const gin::ArrayBufferView
& view
);
231 void DumpFrameLoadCallbacks();
232 void DumpPingLoaderCallbacks();
233 void DumpUserGestureInFrameLoadCallbacks();
234 void DumpTitleChanges();
235 void DumpCreateView();
236 void SetCanOpenWindows();
237 void DumpResourceLoadCallbacks();
238 void DumpResourceRequestCallbacks();
239 void DumpResourceResponseMIMETypes();
240 void SetImagesAllowed(bool allowed
);
241 void SetMediaAllowed(bool allowed
);
242 void SetScriptsAllowed(bool allowed
);
243 void SetStorageAllowed(bool allowed
);
244 void SetPluginsAllowed(bool allowed
);
245 void SetAllowDisplayOfInsecureContent(bool allowed
);
246 void SetAllowRunningOfInsecureContent(bool allowed
);
247 void DumpPermissionClientCallbacks();
248 void DumpWindowStatusChanges();
249 void DumpProgressFinishedCallback();
250 void DumpSpellCheckCallbacks();
251 void DumpBackForwardList();
252 void DumpSelectionRect();
254 void ClearPrinting();
255 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value
);
256 void SetWillSendRequestClearHeader(const std::string
& header
);
257 void DumpResourceRequestPriorities();
258 void SetUseMockTheme(bool use
);
259 void WaitUntilExternalURLLoad();
260 void DumpDragImage();
261 void DumpNavigationPolicy();
262 void ShowWebInspector(gin::Arguments
* args
);
263 void CloseWebInspector();
264 bool IsChooserShown();
265 void EvaluateInWebInspector(int call_id
, const std::string
& script
);
266 void ClearAllDatabases();
267 void SetDatabaseQuota(int quota
);
268 void SetAlwaysAcceptCookies(bool accept
);
269 void SetWindowIsKey(bool value
);
270 std::string
PathToLocalResource(const std::string
& path
);
271 void SetBackingScaleFactor(double value
, v8::Local
<v8::Function
> callback
);
272 void SetColorProfile(const std::string
& name
,
273 v8::Local
<v8::Function
> callback
);
274 void SetPOSIXLocale(const std::string
& locale
);
275 void SetMIDIAccessorResult(bool result
);
276 void SimulateWebNotificationClick(gin::Arguments
* args
);
277 void AddMockSpeechRecognitionResult(const std::string
& transcript
,
279 void SetMockSpeechRecognitionError(const std::string
& error
,
280 const std::string
& message
);
281 bool WasMockSpeechRecognitionAborted();
282 void AddMockCredentialManagerResponse(const std::string
& id
,
283 const std::string
& name
,
284 const std::string
& avatar
,
285 const std::string
& password
);
286 void AddWebPageOverlay();
287 void RemoveWebPageOverlay();
288 void LayoutAndPaintAsync();
289 void LayoutAndPaintAsyncThen(v8::Local
<v8::Function
> callback
);
290 void GetManifestThen(v8::Local
<v8::Function
> callback
);
291 void CapturePixelsAsyncThen(v8::Local
<v8::Function
> callback
);
292 void CopyImageAtAndCapturePixelsAsyncThen(int x
,
294 v8::Local
<v8::Function
> callback
);
295 void SetCustomTextOutput(std::string output
);
296 void SetViewSourceForFrame(const std::string
& name
, bool enabled
);
297 void SetBluetoothMockDataSet(const std::string
& dataset_name
);
298 void SetGeofencingMockProvider(bool service_available
);
299 void ClearGeofencingMockProvider();
300 void SetGeofencingMockPosition(double latitude
, double longitude
);
301 void SetPermission(const std::string
& name
,
302 const std::string
& value
,
303 const std::string
& origin
,
304 const std::string
& embedding_origin
);
305 void DispatchBeforeInstallPromptEvent(
307 const std::vector
<std::string
>& event_platforms
,
308 v8::Local
<v8::Function
> callback
);
309 void ResolveBeforeInstallPromptPromise(int request_id
,
310 const std::string
& platform
);
312 std::string
PlatformName();
313 std::string
TooltipText();
314 bool DisableNotifyDone();
315 int WebHistoryItemCount();
316 bool InterceptPostMessage();
317 void SetInterceptPostMessage(bool value
);
319 void NotImplemented(const gin::Arguments
& args
);
321 void ForceNextWebGLContextCreationToFail();
322 void ForceNextDrawingBufferCreationToFail();
324 base::WeakPtr
<TestRunner
> runner_
;
326 DISALLOW_COPY_AND_ASSIGN(TestRunnerBindings
);
329 gin::WrapperInfo
TestRunnerBindings::kWrapperInfo
= {
330 gin::kEmbedderNativeGin
};
333 void TestRunnerBindings::Install(base::WeakPtr
<TestRunner
> runner
,
335 v8::Isolate
* isolate
= blink::mainThreadIsolate();
336 v8::HandleScope
handle_scope(isolate
);
337 v8::Local
<v8::Context
> context
= frame
->mainWorldScriptContext();
338 if (context
.IsEmpty())
341 v8::Context::Scope
context_scope(context
);
343 TestRunnerBindings
* wrapped
= new TestRunnerBindings(runner
);
344 gin::Handle
<TestRunnerBindings
> bindings
=
345 gin::CreateHandle(isolate
, wrapped
);
346 if (bindings
.IsEmpty())
348 v8::Local
<v8::Object
> global
= context
->Global();
349 v8::Local
<v8::Value
> v8_bindings
= bindings
.ToV8();
351 std::vector
<std::string
> names
;
352 names
.push_back("testRunner");
353 names
.push_back("layoutTestController");
354 for (size_t i
= 0; i
< names
.size(); ++i
)
355 global
->Set(gin::StringToV8(isolate
, names
[i
].c_str()), v8_bindings
);
358 TestRunnerBindings::TestRunnerBindings(base::WeakPtr
<TestRunner
> runner
)
361 TestRunnerBindings::~TestRunnerBindings() {}
363 gin::ObjectTemplateBuilder
TestRunnerBindings::GetObjectTemplateBuilder(
364 v8::Isolate
* isolate
) {
365 return gin::Wrappable
<TestRunnerBindings
>::GetObjectTemplateBuilder(isolate
)
366 // Methods controlling test execution.
367 .SetMethod("logToStderr", &TestRunnerBindings::LogToStderr
)
368 .SetMethod("notifyDone", &TestRunnerBindings::NotifyDone
)
369 .SetMethod("waitUntilDone", &TestRunnerBindings::WaitUntilDone
)
370 .SetMethod("queueBackNavigation",
371 &TestRunnerBindings::QueueBackNavigation
)
372 .SetMethod("queueForwardNavigation",
373 &TestRunnerBindings::QueueForwardNavigation
)
374 .SetMethod("queueReload", &TestRunnerBindings::QueueReload
)
375 .SetMethod("queueLoadingScript", &TestRunnerBindings::QueueLoadingScript
)
376 .SetMethod("queueNonLoadingScript",
377 &TestRunnerBindings::QueueNonLoadingScript
)
378 .SetMethod("queueLoad", &TestRunnerBindings::QueueLoad
)
379 .SetMethod("queueLoadHTMLString",
380 &TestRunnerBindings::QueueLoadHTMLString
)
381 .SetMethod("setCustomPolicyDelegate",
382 &TestRunnerBindings::SetCustomPolicyDelegate
)
383 .SetMethod("waitForPolicyDelegate",
384 &TestRunnerBindings::WaitForPolicyDelegate
)
385 .SetMethod("windowCount", &TestRunnerBindings::WindowCount
)
386 .SetMethod("setCloseRemainingWindowsWhenComplete",
387 &TestRunnerBindings::SetCloseRemainingWindowsWhenComplete
)
388 .SetMethod("resetTestHelperControllers",
389 &TestRunnerBindings::ResetTestHelperControllers
)
390 .SetMethod("setTabKeyCyclesThroughElements",
391 &TestRunnerBindings::SetTabKeyCyclesThroughElements
)
392 .SetMethod("execCommand", &TestRunnerBindings::ExecCommand
)
393 .SetMethod("isCommandEnabled", &TestRunnerBindings::IsCommandEnabled
)
394 .SetMethod("callShouldCloseOnWebView",
395 &TestRunnerBindings::CallShouldCloseOnWebView
)
396 .SetMethod("setDomainRelaxationForbiddenForURLScheme",
397 &TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme
)
399 "evaluateScriptInIsolatedWorldAndReturnValue",
400 &TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue
)
401 .SetMethod("evaluateScriptInIsolatedWorld",
402 &TestRunnerBindings::EvaluateScriptInIsolatedWorld
)
403 .SetMethod("setIsolatedWorldSecurityOrigin",
404 &TestRunnerBindings::SetIsolatedWorldSecurityOrigin
)
405 .SetMethod("setIsolatedWorldContentSecurityPolicy",
406 &TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy
)
407 .SetMethod("addOriginAccessWhitelistEntry",
408 &TestRunnerBindings::AddOriginAccessWhitelistEntry
)
409 .SetMethod("removeOriginAccessWhitelistEntry",
410 &TestRunnerBindings::RemoveOriginAccessWhitelistEntry
)
411 .SetMethod("hasCustomPageSizeStyle",
412 &TestRunnerBindings::HasCustomPageSizeStyle
)
413 .SetMethod("forceRedSelectionColors",
414 &TestRunnerBindings::ForceRedSelectionColors
)
415 .SetMethod("insertStyleSheet", &TestRunnerBindings::InsertStyleSheet
)
416 .SetMethod("findString", &TestRunnerBindings::FindString
)
417 .SetMethod("selectionAsMarkup", &TestRunnerBindings::SelectionAsMarkup
)
418 .SetMethod("setTextSubpixelPositioning",
419 &TestRunnerBindings::SetTextSubpixelPositioning
)
420 .SetMethod("setPageVisibility", &TestRunnerBindings::SetPageVisibility
)
421 .SetMethod("setTextDirection", &TestRunnerBindings::SetTextDirection
)
422 .SetMethod("useUnfortunateSynchronousResizeMode",
423 &TestRunnerBindings::UseUnfortunateSynchronousResizeMode
)
424 .SetMethod("enableAutoResizeMode",
425 &TestRunnerBindings::EnableAutoResizeMode
)
426 .SetMethod("disableAutoResizeMode",
427 &TestRunnerBindings::DisableAutoResizeMode
)
428 .SetMethod("setMockDeviceLight", &TestRunnerBindings::SetMockDeviceLight
)
429 .SetMethod("resetDeviceLight", &TestRunnerBindings::ResetDeviceLight
)
430 .SetMethod("setMockDeviceMotion",
431 &TestRunnerBindings::SetMockDeviceMotion
)
432 .SetMethod("setMockDeviceOrientation",
433 &TestRunnerBindings::SetMockDeviceOrientation
)
434 .SetMethod("setMockScreenOrientation",
435 &TestRunnerBindings::SetMockScreenOrientation
)
436 .SetMethod("didChangeBatteryStatus",
437 &TestRunnerBindings::DidChangeBatteryStatus
)
438 .SetMethod("resetBatteryStatus", &TestRunnerBindings::ResetBatteryStatus
)
439 .SetMethod("didAcquirePointerLock",
440 &TestRunnerBindings::DidAcquirePointerLock
)
441 .SetMethod("didNotAcquirePointerLock",
442 &TestRunnerBindings::DidNotAcquirePointerLock
)
443 .SetMethod("didLosePointerLock", &TestRunnerBindings::DidLosePointerLock
)
444 .SetMethod("setPointerLockWillFailSynchronously",
445 &TestRunnerBindings::SetPointerLockWillFailSynchronously
)
446 .SetMethod("setPointerLockWillRespondAsynchronously",
447 &TestRunnerBindings::SetPointerLockWillRespondAsynchronously
)
448 .SetMethod("setPopupBlockingEnabled",
449 &TestRunnerBindings::SetPopupBlockingEnabled
)
450 .SetMethod("setJavaScriptCanAccessClipboard",
451 &TestRunnerBindings::SetJavaScriptCanAccessClipboard
)
452 .SetMethod("setXSSAuditorEnabled",
453 &TestRunnerBindings::SetXSSAuditorEnabled
)
454 .SetMethod("setAllowUniversalAccessFromFileURLs",
455 &TestRunnerBindings::SetAllowUniversalAccessFromFileURLs
)
456 .SetMethod("setAllowFileAccessFromFileURLs",
457 &TestRunnerBindings::SetAllowFileAccessFromFileURLs
)
458 .SetMethod("overridePreference", &TestRunnerBindings::OverridePreference
)
459 .SetMethod("setAcceptLanguages", &TestRunnerBindings::SetAcceptLanguages
)
460 .SetMethod("setPluginsEnabled", &TestRunnerBindings::SetPluginsEnabled
)
461 .SetMethod("dumpEditingCallbacks",
462 &TestRunnerBindings::DumpEditingCallbacks
)
463 .SetMethod("dumpAsMarkup", &TestRunnerBindings::DumpAsMarkup
)
464 .SetMethod("dumpAsText", &TestRunnerBindings::DumpAsText
)
465 .SetMethod("dumpAsTextWithPixelResults",
466 &TestRunnerBindings::DumpAsTextWithPixelResults
)
467 .SetMethod("dumpChildFrameScrollPositions",
468 &TestRunnerBindings::DumpChildFrameScrollPositions
)
469 .SetMethod("dumpChildFramesAsText",
470 &TestRunnerBindings::DumpChildFramesAsText
)
471 .SetMethod("dumpChildFramesAsMarkup",
472 &TestRunnerBindings::DumpChildFramesAsMarkup
)
473 .SetMethod("dumpIconChanges", &TestRunnerBindings::DumpIconChanges
)
474 .SetMethod("setAudioData", &TestRunnerBindings::SetAudioData
)
475 .SetMethod("dumpFrameLoadCallbacks",
476 &TestRunnerBindings::DumpFrameLoadCallbacks
)
477 .SetMethod("dumpPingLoaderCallbacks",
478 &TestRunnerBindings::DumpPingLoaderCallbacks
)
479 .SetMethod("dumpUserGestureInFrameLoadCallbacks",
480 &TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks
)
481 .SetMethod("dumpTitleChanges", &TestRunnerBindings::DumpTitleChanges
)
482 .SetMethod("dumpCreateView", &TestRunnerBindings::DumpCreateView
)
483 .SetMethod("setCanOpenWindows", &TestRunnerBindings::SetCanOpenWindows
)
484 .SetMethod("dumpResourceLoadCallbacks",
485 &TestRunnerBindings::DumpResourceLoadCallbacks
)
486 .SetMethod("dumpResourceRequestCallbacks",
487 &TestRunnerBindings::DumpResourceRequestCallbacks
)
488 .SetMethod("dumpResourceResponseMIMETypes",
489 &TestRunnerBindings::DumpResourceResponseMIMETypes
)
490 .SetMethod("setImagesAllowed", &TestRunnerBindings::SetImagesAllowed
)
491 .SetMethod("setMediaAllowed", &TestRunnerBindings::SetMediaAllowed
)
492 .SetMethod("setScriptsAllowed", &TestRunnerBindings::SetScriptsAllowed
)
493 .SetMethod("setStorageAllowed", &TestRunnerBindings::SetStorageAllowed
)
494 .SetMethod("setPluginsAllowed", &TestRunnerBindings::SetPluginsAllowed
)
495 .SetMethod("setAllowDisplayOfInsecureContent",
496 &TestRunnerBindings::SetAllowDisplayOfInsecureContent
)
497 .SetMethod("setAllowRunningOfInsecureContent",
498 &TestRunnerBindings::SetAllowRunningOfInsecureContent
)
499 .SetMethod("dumpPermissionClientCallbacks",
500 &TestRunnerBindings::DumpPermissionClientCallbacks
)
501 .SetMethod("dumpWindowStatusChanges",
502 &TestRunnerBindings::DumpWindowStatusChanges
)
503 .SetMethod("dumpProgressFinishedCallback",
504 &TestRunnerBindings::DumpProgressFinishedCallback
)
505 .SetMethod("dumpSpellCheckCallbacks",
506 &TestRunnerBindings::DumpSpellCheckCallbacks
)
507 .SetMethod("dumpBackForwardList",
508 &TestRunnerBindings::DumpBackForwardList
)
509 .SetMethod("dumpSelectionRect", &TestRunnerBindings::DumpSelectionRect
)
510 .SetMethod("setPrinting", &TestRunnerBindings::SetPrinting
)
511 .SetMethod("clearPrinting", &TestRunnerBindings::ClearPrinting
)
513 "setShouldStayOnPageAfterHandlingBeforeUnload",
514 &TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload
)
515 .SetMethod("setWillSendRequestClearHeader",
516 &TestRunnerBindings::SetWillSendRequestClearHeader
)
517 .SetMethod("dumpResourceRequestPriorities",
518 &TestRunnerBindings::DumpResourceRequestPriorities
)
519 .SetMethod("setUseMockTheme", &TestRunnerBindings::SetUseMockTheme
)
520 .SetMethod("waitUntilExternalURLLoad",
521 &TestRunnerBindings::WaitUntilExternalURLLoad
)
522 .SetMethod("dumpDragImage", &TestRunnerBindings::DumpDragImage
)
523 .SetMethod("dumpNavigationPolicy",
524 &TestRunnerBindings::DumpNavigationPolicy
)
525 .SetMethod("showWebInspector", &TestRunnerBindings::ShowWebInspector
)
526 .SetMethod("closeWebInspector", &TestRunnerBindings::CloseWebInspector
)
527 .SetMethod("isChooserShown", &TestRunnerBindings::IsChooserShown
)
528 .SetMethod("evaluateInWebInspector",
529 &TestRunnerBindings::EvaluateInWebInspector
)
530 .SetMethod("clearAllDatabases", &TestRunnerBindings::ClearAllDatabases
)
531 .SetMethod("setDatabaseQuota", &TestRunnerBindings::SetDatabaseQuota
)
532 .SetMethod("setAlwaysAcceptCookies",
533 &TestRunnerBindings::SetAlwaysAcceptCookies
)
534 .SetMethod("setWindowIsKey", &TestRunnerBindings::SetWindowIsKey
)
535 .SetMethod("pathToLocalResource",
536 &TestRunnerBindings::PathToLocalResource
)
537 .SetMethod("setBackingScaleFactor",
538 &TestRunnerBindings::SetBackingScaleFactor
)
539 .SetMethod("setColorProfile", &TestRunnerBindings::SetColorProfile
)
540 .SetMethod("setPOSIXLocale", &TestRunnerBindings::SetPOSIXLocale
)
541 .SetMethod("setMIDIAccessorResult",
542 &TestRunnerBindings::SetMIDIAccessorResult
)
543 .SetMethod("simulateWebNotificationClick",
544 &TestRunnerBindings::SimulateWebNotificationClick
)
545 .SetMethod("addMockSpeechRecognitionResult",
546 &TestRunnerBindings::AddMockSpeechRecognitionResult
)
547 .SetMethod("setMockSpeechRecognitionError",
548 &TestRunnerBindings::SetMockSpeechRecognitionError
)
549 .SetMethod("wasMockSpeechRecognitionAborted",
550 &TestRunnerBindings::WasMockSpeechRecognitionAborted
)
551 .SetMethod("addMockCredentialManagerResponse",
552 &TestRunnerBindings::AddMockCredentialManagerResponse
)
553 .SetMethod("addWebPageOverlay", &TestRunnerBindings::AddWebPageOverlay
)
554 .SetMethod("removeWebPageOverlay",
555 &TestRunnerBindings::RemoveWebPageOverlay
)
556 .SetMethod("layoutAndPaintAsync",
557 &TestRunnerBindings::LayoutAndPaintAsync
)
558 .SetMethod("layoutAndPaintAsyncThen",
559 &TestRunnerBindings::LayoutAndPaintAsyncThen
)
560 .SetMethod("getManifestThen", &TestRunnerBindings::GetManifestThen
)
561 .SetMethod("capturePixelsAsyncThen",
562 &TestRunnerBindings::CapturePixelsAsyncThen
)
563 .SetMethod("copyImageAtAndCapturePixelsAsyncThen",
564 &TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen
)
565 .SetMethod("setCustomTextOutput",
566 &TestRunnerBindings::SetCustomTextOutput
)
567 .SetMethod("setViewSourceForFrame",
568 &TestRunnerBindings::SetViewSourceForFrame
)
569 .SetMethod("setBluetoothMockDataSet",
570 &TestRunnerBindings::SetBluetoothMockDataSet
)
571 .SetMethod("forceNextWebGLContextCreationToFail",
572 &TestRunnerBindings::ForceNextWebGLContextCreationToFail
)
573 .SetMethod("forceNextDrawingBufferCreationToFail",
574 &TestRunnerBindings::ForceNextDrawingBufferCreationToFail
)
575 .SetMethod("setGeofencingMockProvider",
576 &TestRunnerBindings::SetGeofencingMockProvider
)
577 .SetMethod("clearGeofencingMockProvider",
578 &TestRunnerBindings::ClearGeofencingMockProvider
)
579 .SetMethod("setGeofencingMockPosition",
580 &TestRunnerBindings::SetGeofencingMockPosition
)
581 .SetMethod("setPermission", &TestRunnerBindings::SetPermission
)
582 .SetMethod("dispatchBeforeInstallPromptEvent",
583 &TestRunnerBindings::DispatchBeforeInstallPromptEvent
)
584 .SetMethod("resolveBeforeInstallPromptPromise",
585 &TestRunnerBindings::ResolveBeforeInstallPromptPromise
)
588 .SetProperty("platformName", &TestRunnerBindings::PlatformName
)
589 .SetProperty("tooltipText", &TestRunnerBindings::TooltipText
)
590 .SetProperty("disableNotifyDone", &TestRunnerBindings::DisableNotifyDone
)
591 // webHistoryItemCount is used by tests in LayoutTests\http\tests\history
592 .SetProperty("webHistoryItemCount",
593 &TestRunnerBindings::WebHistoryItemCount
)
594 .SetProperty("interceptPostMessage",
595 &TestRunnerBindings::InterceptPostMessage
,
596 &TestRunnerBindings::SetInterceptPostMessage
)
598 // The following are stubs.
599 .SetMethod("dumpDatabaseCallbacks", &TestRunnerBindings::NotImplemented
)
600 .SetMethod("setIconDatabaseEnabled", &TestRunnerBindings::NotImplemented
)
601 .SetMethod("setScrollbarPolicy", &TestRunnerBindings::NotImplemented
)
602 .SetMethod("clearAllApplicationCaches",
603 &TestRunnerBindings::NotImplemented
)
604 .SetMethod("clearApplicationCacheForOrigin",
605 &TestRunnerBindings::NotImplemented
)
606 .SetMethod("clearBackForwardList", &TestRunnerBindings::NotImplemented
)
607 .SetMethod("keepWebHistory", &TestRunnerBindings::NotImplemented
)
608 .SetMethod("setApplicationCacheOriginQuota",
609 &TestRunnerBindings::NotImplemented
)
610 .SetMethod("setCallCloseOnWebViews", &TestRunnerBindings::NotImplemented
)
611 .SetMethod("setMainFrameIsFirstResponder",
612 &TestRunnerBindings::NotImplemented
)
613 .SetMethod("setUseDashboardCompatibilityMode",
614 &TestRunnerBindings::NotImplemented
)
615 .SetMethod("deleteAllLocalStorage", &TestRunnerBindings::NotImplemented
)
616 .SetMethod("localStorageDiskUsageForOrigin",
617 &TestRunnerBindings::NotImplemented
)
618 .SetMethod("originsWithLocalStorage", &TestRunnerBindings::NotImplemented
)
619 .SetMethod("deleteLocalStorageForOrigin",
620 &TestRunnerBindings::NotImplemented
)
621 .SetMethod("observeStorageTrackerNotifications",
622 &TestRunnerBindings::NotImplemented
)
623 .SetMethod("syncLocalStorage", &TestRunnerBindings::NotImplemented
)
624 .SetMethod("addDisallowedURL", &TestRunnerBindings::NotImplemented
)
625 .SetMethod("applicationCacheDiskUsageForOrigin",
626 &TestRunnerBindings::NotImplemented
)
627 .SetMethod("abortModal", &TestRunnerBindings::NotImplemented
)
630 // Used at fast/dom/assign-to-window-status.html
631 .SetMethod("dumpStatusCallbacks",
632 &TestRunnerBindings::DumpWindowStatusChanges
);
635 void TestRunnerBindings::LogToStderr(const std::string
& output
) {
636 LOG(ERROR
) << output
;
639 void TestRunnerBindings::NotifyDone() {
641 runner_
->NotifyDone();
644 void TestRunnerBindings::WaitUntilDone() {
646 runner_
->WaitUntilDone();
649 void TestRunnerBindings::QueueBackNavigation(int how_far_back
) {
651 runner_
->QueueBackNavigation(how_far_back
);
654 void TestRunnerBindings::QueueForwardNavigation(int how_far_forward
) {
656 runner_
->QueueForwardNavigation(how_far_forward
);
659 void TestRunnerBindings::QueueReload() {
661 runner_
->QueueReload();
664 void TestRunnerBindings::QueueLoadingScript(const std::string
& script
) {
666 runner_
->QueueLoadingScript(script
);
669 void TestRunnerBindings::QueueNonLoadingScript(const std::string
& script
) {
671 runner_
->QueueNonLoadingScript(script
);
674 void TestRunnerBindings::QueueLoad(gin::Arguments
* args
) {
679 args
->GetNext(&target
);
680 runner_
->QueueLoad(url
, target
);
684 void TestRunnerBindings::QueueLoadHTMLString(gin::Arguments
* args
) {
686 runner_
->QueueLoadHTMLString(args
);
689 void TestRunnerBindings::SetCustomPolicyDelegate(gin::Arguments
* args
) {
691 runner_
->SetCustomPolicyDelegate(args
);
694 void TestRunnerBindings::WaitForPolicyDelegate() {
696 runner_
->WaitForPolicyDelegate();
699 int TestRunnerBindings::WindowCount() {
701 return runner_
->WindowCount();
705 void TestRunnerBindings::SetCloseRemainingWindowsWhenComplete(
706 gin::Arguments
* args
) {
710 // In the original implementation, nothing happens if the argument is
712 bool close_remaining_windows
= false;
713 if (args
->GetNext(&close_remaining_windows
))
714 runner_
->SetCloseRemainingWindowsWhenComplete(close_remaining_windows
);
717 void TestRunnerBindings::ResetTestHelperControllers() {
719 runner_
->ResetTestHelperControllers();
722 void TestRunnerBindings::SetTabKeyCyclesThroughElements(
723 bool tab_key_cycles_through_elements
) {
725 runner_
->SetTabKeyCyclesThroughElements(tab_key_cycles_through_elements
);
728 void TestRunnerBindings::ExecCommand(gin::Arguments
* args
) {
730 runner_
->ExecCommand(args
);
733 bool TestRunnerBindings::IsCommandEnabled(const std::string
& command
) {
735 return runner_
->IsCommandEnabled(command
);
739 bool TestRunnerBindings::CallShouldCloseOnWebView() {
741 return runner_
->CallShouldCloseOnWebView();
745 void TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme(
746 bool forbidden
, const std::string
& scheme
) {
748 runner_
->SetDomainRelaxationForbiddenForURLScheme(forbidden
, scheme
);
752 TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue(
753 int world_id
, const std::string
& script
) {
754 if (!runner_
|| world_id
<= 0 || world_id
>= (1 << 29))
755 return v8::Local
<v8::Value
>();
756 return runner_
->EvaluateScriptInIsolatedWorldAndReturnValue(world_id
,
760 void TestRunnerBindings::EvaluateScriptInIsolatedWorld(
761 int world_id
, const std::string
& script
) {
762 if (runner_
&& world_id
> 0 && world_id
< (1 << 29))
763 runner_
->EvaluateScriptInIsolatedWorld(world_id
, script
);
766 void TestRunnerBindings::SetIsolatedWorldSecurityOrigin(
767 int world_id
, v8::Local
<v8::Value
> origin
) {
769 runner_
->SetIsolatedWorldSecurityOrigin(world_id
, origin
);
772 void TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy(
773 int world_id
, const std::string
& policy
) {
775 runner_
->SetIsolatedWorldContentSecurityPolicy(world_id
, policy
);
778 void TestRunnerBindings::AddOriginAccessWhitelistEntry(
779 const std::string
& source_origin
,
780 const std::string
& destination_protocol
,
781 const std::string
& destination_host
,
782 bool allow_destination_subdomains
) {
784 runner_
->AddOriginAccessWhitelistEntry(source_origin
,
785 destination_protocol
,
787 allow_destination_subdomains
);
791 void TestRunnerBindings::RemoveOriginAccessWhitelistEntry(
792 const std::string
& source_origin
,
793 const std::string
& destination_protocol
,
794 const std::string
& destination_host
,
795 bool allow_destination_subdomains
) {
797 runner_
->RemoveOriginAccessWhitelistEntry(source_origin
,
798 destination_protocol
,
800 allow_destination_subdomains
);
804 bool TestRunnerBindings::HasCustomPageSizeStyle(int page_index
) {
806 return runner_
->HasCustomPageSizeStyle(page_index
);
810 void TestRunnerBindings::ForceRedSelectionColors() {
812 runner_
->ForceRedSelectionColors();
815 void TestRunnerBindings::InsertStyleSheet(const std::string
& source_code
) {
817 runner_
->InsertStyleSheet(source_code
);
820 bool TestRunnerBindings::FindString(
821 const std::string
& search_text
,
822 const std::vector
<std::string
>& options_array
) {
824 return runner_
->FindString(search_text
, options_array
);
828 std::string
TestRunnerBindings::SelectionAsMarkup() {
830 return runner_
->SelectionAsMarkup();
831 return std::string();
834 void TestRunnerBindings::SetTextSubpixelPositioning(bool value
) {
836 runner_
->SetTextSubpixelPositioning(value
);
839 void TestRunnerBindings::SetPageVisibility(const std::string
& new_visibility
) {
841 runner_
->SetPageVisibility(new_visibility
);
844 void TestRunnerBindings::SetTextDirection(const std::string
& direction_name
) {
846 runner_
->SetTextDirection(direction_name
);
849 void TestRunnerBindings::UseUnfortunateSynchronousResizeMode() {
851 runner_
->UseUnfortunateSynchronousResizeMode();
854 bool TestRunnerBindings::EnableAutoResizeMode(int min_width
,
859 return runner_
->EnableAutoResizeMode(min_width
, min_height
,
860 max_width
, max_height
);
865 bool TestRunnerBindings::DisableAutoResizeMode(int new_width
, int new_height
) {
867 return runner_
->DisableAutoResizeMode(new_width
, new_height
);
871 void TestRunnerBindings::SetMockDeviceLight(double value
) {
874 runner_
->SetMockDeviceLight(value
);
877 void TestRunnerBindings::ResetDeviceLight() {
879 runner_
->ResetDeviceLight();
882 void TestRunnerBindings::SetMockDeviceMotion(gin::Arguments
* args
) {
886 bool has_acceleration_x
;
887 double acceleration_x
;
888 bool has_acceleration_y
;
889 double acceleration_y
;
890 bool has_acceleration_z
;
891 double acceleration_z
;
892 bool has_acceleration_including_gravity_x
;
893 double acceleration_including_gravity_x
;
894 bool has_acceleration_including_gravity_y
;
895 double acceleration_including_gravity_y
;
896 bool has_acceleration_including_gravity_z
;
897 double acceleration_including_gravity_z
;
898 bool has_rotation_rate_alpha
;
899 double rotation_rate_alpha
;
900 bool has_rotation_rate_beta
;
901 double rotation_rate_beta
;
902 bool has_rotation_rate_gamma
;
903 double rotation_rate_gamma
;
906 args
->GetNext(&has_acceleration_x
);
907 args
->GetNext(& acceleration_x
);
908 args
->GetNext(&has_acceleration_y
);
909 args
->GetNext(& acceleration_y
);
910 args
->GetNext(&has_acceleration_z
);
911 args
->GetNext(& acceleration_z
);
912 args
->GetNext(&has_acceleration_including_gravity_x
);
913 args
->GetNext(& acceleration_including_gravity_x
);
914 args
->GetNext(&has_acceleration_including_gravity_y
);
915 args
->GetNext(& acceleration_including_gravity_y
);
916 args
->GetNext(&has_acceleration_including_gravity_z
);
917 args
->GetNext(& acceleration_including_gravity_z
);
918 args
->GetNext(&has_rotation_rate_alpha
);
919 args
->GetNext(& rotation_rate_alpha
);
920 args
->GetNext(&has_rotation_rate_beta
);
921 args
->GetNext(& rotation_rate_beta
);
922 args
->GetNext(&has_rotation_rate_gamma
);
923 args
->GetNext(& rotation_rate_gamma
);
924 args
->GetNext(& interval
);
926 runner_
->SetMockDeviceMotion(has_acceleration_x
, acceleration_x
,
927 has_acceleration_y
, acceleration_y
,
928 has_acceleration_z
, acceleration_z
,
929 has_acceleration_including_gravity_x
,
930 acceleration_including_gravity_x
,
931 has_acceleration_including_gravity_y
,
932 acceleration_including_gravity_y
,
933 has_acceleration_including_gravity_z
,
934 acceleration_including_gravity_z
,
935 has_rotation_rate_alpha
,
937 has_rotation_rate_beta
,
939 has_rotation_rate_gamma
,
944 void TestRunnerBindings::SetMockDeviceOrientation(gin::Arguments
* args
) {
948 bool has_alpha
= false;
950 bool has_beta
= false;
952 bool has_gamma
= false;
954 bool has_absolute
= false;
955 bool absolute
= false;
957 args
->GetNext(&has_alpha
);
958 args
->GetNext(&alpha
);
959 args
->GetNext(&has_beta
);
960 args
->GetNext(&beta
);
961 args
->GetNext(&has_gamma
);
962 args
->GetNext(&gamma
);
963 args
->GetNext(&has_absolute
);
964 args
->GetNext(&absolute
);
966 runner_
->SetMockDeviceOrientation(has_alpha
, alpha
,
969 has_absolute
, absolute
);
972 void TestRunnerBindings::SetMockScreenOrientation(
973 const std::string
& orientation
) {
977 runner_
->SetMockScreenOrientation(orientation
);
980 void TestRunnerBindings::DidChangeBatteryStatus(bool charging
,
982 double dischargingTime
,
985 runner_
->DidChangeBatteryStatus(charging
, chargingTime
,
986 dischargingTime
, level
);
990 void TestRunnerBindings::ResetBatteryStatus() {
992 runner_
->ResetBatteryStatus();
995 void TestRunnerBindings::DidAcquirePointerLock() {
997 runner_
->DidAcquirePointerLock();
1000 void TestRunnerBindings::DidNotAcquirePointerLock() {
1002 runner_
->DidNotAcquirePointerLock();
1005 void TestRunnerBindings::DidLosePointerLock() {
1007 runner_
->DidLosePointerLock();
1010 void TestRunnerBindings::SetPointerLockWillFailSynchronously() {
1012 runner_
->SetPointerLockWillFailSynchronously();
1015 void TestRunnerBindings::SetPointerLockWillRespondAsynchronously() {
1017 runner_
->SetPointerLockWillRespondAsynchronously();
1020 void TestRunnerBindings::SetPopupBlockingEnabled(bool block_popups
) {
1022 runner_
->SetPopupBlockingEnabled(block_popups
);
1025 void TestRunnerBindings::SetJavaScriptCanAccessClipboard(bool can_access
) {
1027 runner_
->SetJavaScriptCanAccessClipboard(can_access
);
1030 void TestRunnerBindings::SetXSSAuditorEnabled(bool enabled
) {
1032 runner_
->SetXSSAuditorEnabled(enabled
);
1035 void TestRunnerBindings::SetAllowUniversalAccessFromFileURLs(bool allow
) {
1037 runner_
->SetAllowUniversalAccessFromFileURLs(allow
);
1040 void TestRunnerBindings::SetAllowFileAccessFromFileURLs(bool allow
) {
1042 runner_
->SetAllowFileAccessFromFileURLs(allow
);
1045 void TestRunnerBindings::OverridePreference(const std::string key
,
1046 v8::Local
<v8::Value
> value
) {
1048 runner_
->OverridePreference(key
, value
);
1051 void TestRunnerBindings::SetAcceptLanguages(
1052 const std::string
& accept_languages
) {
1056 runner_
->SetAcceptLanguages(accept_languages
);
1059 void TestRunnerBindings::SetPluginsEnabled(bool enabled
) {
1061 runner_
->SetPluginsEnabled(enabled
);
1064 void TestRunnerBindings::DumpEditingCallbacks() {
1066 runner_
->DumpEditingCallbacks();
1069 void TestRunnerBindings::DumpAsMarkup() {
1071 runner_
->DumpAsMarkup();
1074 void TestRunnerBindings::DumpAsText() {
1076 runner_
->DumpAsText();
1079 void TestRunnerBindings::DumpAsTextWithPixelResults() {
1081 runner_
->DumpAsTextWithPixelResults();
1084 void TestRunnerBindings::DumpChildFrameScrollPositions() {
1086 runner_
->DumpChildFrameScrollPositions();
1089 void TestRunnerBindings::DumpChildFramesAsText() {
1091 runner_
->DumpChildFramesAsText();
1094 void TestRunnerBindings::DumpChildFramesAsMarkup() {
1096 runner_
->DumpChildFramesAsMarkup();
1099 void TestRunnerBindings::DumpIconChanges() {
1101 runner_
->DumpIconChanges();
1104 void TestRunnerBindings::SetAudioData(const gin::ArrayBufferView
& view
) {
1106 runner_
->SetAudioData(view
);
1109 void TestRunnerBindings::DumpFrameLoadCallbacks() {
1111 runner_
->DumpFrameLoadCallbacks();
1114 void TestRunnerBindings::DumpPingLoaderCallbacks() {
1116 runner_
->DumpPingLoaderCallbacks();
1119 void TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks() {
1121 runner_
->DumpUserGestureInFrameLoadCallbacks();
1124 void TestRunnerBindings::DumpTitleChanges() {
1126 runner_
->DumpTitleChanges();
1129 void TestRunnerBindings::DumpCreateView() {
1131 runner_
->DumpCreateView();
1134 void TestRunnerBindings::SetCanOpenWindows() {
1136 runner_
->SetCanOpenWindows();
1139 void TestRunnerBindings::DumpResourceLoadCallbacks() {
1141 runner_
->DumpResourceLoadCallbacks();
1144 void TestRunnerBindings::DumpResourceRequestCallbacks() {
1146 runner_
->DumpResourceRequestCallbacks();
1149 void TestRunnerBindings::DumpResourceResponseMIMETypes() {
1151 runner_
->DumpResourceResponseMIMETypes();
1154 void TestRunnerBindings::SetImagesAllowed(bool allowed
) {
1156 runner_
->SetImagesAllowed(allowed
);
1159 void TestRunnerBindings::SetMediaAllowed(bool allowed
) {
1161 runner_
->SetMediaAllowed(allowed
);
1164 void TestRunnerBindings::SetScriptsAllowed(bool allowed
) {
1166 runner_
->SetScriptsAllowed(allowed
);
1169 void TestRunnerBindings::SetStorageAllowed(bool allowed
) {
1171 runner_
->SetStorageAllowed(allowed
);
1174 void TestRunnerBindings::SetPluginsAllowed(bool allowed
) {
1176 runner_
->SetPluginsAllowed(allowed
);
1179 void TestRunnerBindings::SetAllowDisplayOfInsecureContent(bool allowed
) {
1181 runner_
->SetAllowDisplayOfInsecureContent(allowed
);
1184 void TestRunnerBindings::SetAllowRunningOfInsecureContent(bool allowed
) {
1186 runner_
->SetAllowRunningOfInsecureContent(allowed
);
1189 void TestRunnerBindings::DumpPermissionClientCallbacks() {
1191 runner_
->DumpPermissionClientCallbacks();
1194 void TestRunnerBindings::DumpWindowStatusChanges() {
1196 runner_
->DumpWindowStatusChanges();
1199 void TestRunnerBindings::DumpProgressFinishedCallback() {
1201 runner_
->DumpProgressFinishedCallback();
1204 void TestRunnerBindings::DumpSpellCheckCallbacks() {
1206 runner_
->DumpSpellCheckCallbacks();
1209 void TestRunnerBindings::DumpBackForwardList() {
1211 runner_
->DumpBackForwardList();
1214 void TestRunnerBindings::DumpSelectionRect() {
1216 runner_
->DumpSelectionRect();
1219 void TestRunnerBindings::SetPrinting() {
1221 runner_
->SetPrinting();
1224 void TestRunnerBindings::ClearPrinting() {
1226 runner_
->ClearPrinting();
1229 void TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload(
1232 runner_
->SetShouldStayOnPageAfterHandlingBeforeUnload(value
);
1235 void TestRunnerBindings::SetWillSendRequestClearHeader(
1236 const std::string
& header
) {
1238 runner_
->SetWillSendRequestClearHeader(header
);
1241 void TestRunnerBindings::DumpResourceRequestPriorities() {
1243 runner_
->DumpResourceRequestPriorities();
1246 void TestRunnerBindings::SetUseMockTheme(bool use
) {
1248 runner_
->SetUseMockTheme(use
);
1251 void TestRunnerBindings::WaitUntilExternalURLLoad() {
1253 runner_
->WaitUntilExternalURLLoad();
1256 void TestRunnerBindings::DumpDragImage() {
1258 runner_
->DumpDragImage();
1261 void TestRunnerBindings::DumpNavigationPolicy() {
1263 runner_
->DumpNavigationPolicy();
1266 void TestRunnerBindings::ShowWebInspector(gin::Arguments
* args
) {
1268 std::string settings
;
1269 args
->GetNext(&settings
);
1270 std::string frontend_url
;
1271 args
->GetNext(&frontend_url
);
1272 runner_
->ShowWebInspector(settings
, frontend_url
);
1276 void TestRunnerBindings::CloseWebInspector() {
1278 runner_
->CloseWebInspector();
1281 bool TestRunnerBindings::IsChooserShown() {
1283 return runner_
->IsChooserShown();
1287 void TestRunnerBindings::EvaluateInWebInspector(int call_id
,
1288 const std::string
& script
) {
1290 runner_
->EvaluateInWebInspector(call_id
, script
);
1293 void TestRunnerBindings::ClearAllDatabases() {
1295 runner_
->ClearAllDatabases();
1298 void TestRunnerBindings::SetDatabaseQuota(int quota
) {
1300 runner_
->SetDatabaseQuota(quota
);
1303 void TestRunnerBindings::SetAlwaysAcceptCookies(bool accept
) {
1305 runner_
->SetAlwaysAcceptCookies(accept
);
1308 void TestRunnerBindings::SetWindowIsKey(bool value
) {
1310 runner_
->SetWindowIsKey(value
);
1313 std::string
TestRunnerBindings::PathToLocalResource(const std::string
& path
) {
1315 return runner_
->PathToLocalResource(path
);
1316 return std::string();
1319 void TestRunnerBindings::SetBackingScaleFactor(
1320 double value
, v8::Local
<v8::Function
> callback
) {
1322 runner_
->SetBackingScaleFactor(value
, callback
);
1325 void TestRunnerBindings::SetColorProfile(
1326 const std::string
& name
, v8::Local
<v8::Function
> callback
) {
1328 runner_
->SetColorProfile(name
, callback
);
1331 void TestRunnerBindings::SetBluetoothMockDataSet(const std::string
& name
) {
1333 runner_
->SetBluetoothMockDataSet(name
);
1336 void TestRunnerBindings::SetPOSIXLocale(const std::string
& locale
) {
1338 runner_
->SetPOSIXLocale(locale
);
1341 void TestRunnerBindings::SetMIDIAccessorResult(bool result
) {
1343 runner_
->SetMIDIAccessorResult(result
);
1346 void TestRunnerBindings::SimulateWebNotificationClick(gin::Arguments
* args
) {
1350 int action_index
= -1;
1351 if (args
->GetNext(&title
) &&
1352 (args
->PeekNext().IsEmpty() || args
->GetNext(&action_index
)))
1353 runner_
->SimulateWebNotificationClick(title
, action_index
);
1358 void TestRunnerBindings::AddMockSpeechRecognitionResult(
1359 const std::string
& transcript
, double confidence
) {
1361 runner_
->AddMockSpeechRecognitionResult(transcript
, confidence
);
1364 void TestRunnerBindings::SetMockSpeechRecognitionError(
1365 const std::string
& error
, const std::string
& message
) {
1367 runner_
->SetMockSpeechRecognitionError(error
, message
);
1370 bool TestRunnerBindings::WasMockSpeechRecognitionAborted() {
1372 return runner_
->WasMockSpeechRecognitionAborted();
1376 void TestRunnerBindings::AddMockCredentialManagerResponse(
1377 const std::string
& id
,
1378 const std::string
& name
,
1379 const std::string
& avatar
,
1380 const std::string
& password
) {
1382 runner_
->AddMockCredentialManagerResponse(id
, name
, avatar
, password
);
1385 void TestRunnerBindings::AddWebPageOverlay() {
1387 runner_
->AddWebPageOverlay();
1390 void TestRunnerBindings::RemoveWebPageOverlay() {
1392 runner_
->RemoveWebPageOverlay();
1395 void TestRunnerBindings::LayoutAndPaintAsync() {
1397 runner_
->LayoutAndPaintAsync();
1400 void TestRunnerBindings::LayoutAndPaintAsyncThen(
1401 v8::Local
<v8::Function
> callback
) {
1403 runner_
->LayoutAndPaintAsyncThen(callback
);
1406 void TestRunnerBindings::GetManifestThen(v8::Local
<v8::Function
> callback
) {
1408 runner_
->GetManifestThen(callback
);
1411 void TestRunnerBindings::CapturePixelsAsyncThen(
1412 v8::Local
<v8::Function
> callback
) {
1414 runner_
->CapturePixelsAsyncThen(callback
);
1417 void TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen(
1418 int x
, int y
, v8::Local
<v8::Function
> callback
) {
1420 runner_
->CopyImageAtAndCapturePixelsAsyncThen(x
, y
, callback
);
1423 void TestRunnerBindings::SetCustomTextOutput(std::string output
) {
1424 runner_
->setCustomTextOutput(output
);
1427 void TestRunnerBindings::SetViewSourceForFrame(const std::string
& name
,
1429 if (runner_
&& runner_
->web_view_
) {
1430 WebFrame
* target_frame
=
1431 runner_
->web_view_
->findFrameByName(WebString::fromUTF8(name
));
1433 target_frame
->enableViewSourceMode(enabled
);
1437 void TestRunnerBindings::SetGeofencingMockProvider(bool service_available
) {
1439 runner_
->SetGeofencingMockProvider(service_available
);
1442 void TestRunnerBindings::ClearGeofencingMockProvider() {
1444 runner_
->ClearGeofencingMockProvider();
1447 void TestRunnerBindings::SetGeofencingMockPosition(double latitude
,
1450 runner_
->SetGeofencingMockPosition(latitude
, longitude
);
1453 void TestRunnerBindings::SetPermission(const std::string
& name
,
1454 const std::string
& value
,
1455 const std::string
& origin
,
1456 const std::string
& embedding_origin
) {
1460 return runner_
->SetPermission(
1461 name
, value
, GURL(origin
), GURL(embedding_origin
));
1464 void TestRunnerBindings::DispatchBeforeInstallPromptEvent(
1466 const std::vector
<std::string
>& event_platforms
,
1467 v8::Local
<v8::Function
> callback
) {
1471 return runner_
->DispatchBeforeInstallPromptEvent(request_id
, event_platforms
,
1475 void TestRunnerBindings::ResolveBeforeInstallPromptPromise(
1477 const std::string
& platform
) {
1481 return runner_
->ResolveBeforeInstallPromptPromise(request_id
, platform
);
1484 std::string
TestRunnerBindings::PlatformName() {
1486 return runner_
->platform_name_
;
1487 return std::string();
1490 std::string
TestRunnerBindings::TooltipText() {
1492 return runner_
->tooltip_text_
;
1493 return std::string();
1496 bool TestRunnerBindings::DisableNotifyDone() {
1498 return runner_
->disable_notify_done_
;
1502 int TestRunnerBindings::WebHistoryItemCount() {
1504 return runner_
->web_history_item_count_
;
1508 bool TestRunnerBindings::InterceptPostMessage() {
1510 return runner_
->intercept_post_message_
;
1514 void TestRunnerBindings::SetInterceptPostMessage(bool value
) {
1516 runner_
->intercept_post_message_
= value
;
1519 void TestRunnerBindings::ForceNextWebGLContextCreationToFail() {
1521 runner_
->ForceNextWebGLContextCreationToFail();
1524 void TestRunnerBindings::ForceNextDrawingBufferCreationToFail() {
1526 runner_
->ForceNextDrawingBufferCreationToFail();
1529 void TestRunnerBindings::NotImplemented(const gin::Arguments
& args
) {
1532 TestRunner::WorkQueue::WorkQueue(TestRunner
* controller
)
1534 , controller_(controller
) {}
1536 TestRunner::WorkQueue::~WorkQueue() {
1540 void TestRunner::WorkQueue::ProcessWorkSoon() {
1541 if (controller_
->topLoadingFrame())
1544 if (!queue_
.empty()) {
1545 // We delay processing queued work to avoid recursion problems.
1546 controller_
->delegate_
->PostTask(new WorkQueueTask(this));
1547 } else if (!controller_
->wait_until_done_
) {
1548 controller_
->delegate_
->TestFinished();
1552 void TestRunner::WorkQueue::Reset() {
1554 while (!queue_
.empty()) {
1555 delete queue_
.front();
1560 void TestRunner::WorkQueue::AddWork(WorkItem
* work
) {
1565 queue_
.push_back(work
);
1568 void TestRunner::WorkQueue::ProcessWork() {
1569 // Quit doing work once a load is in progress.
1570 while (!queue_
.empty()) {
1571 bool startedLoad
= queue_
.front()->Run(controller_
->delegate_
,
1572 controller_
->web_view_
);
1573 delete queue_
.front();
1579 if (!controller_
->wait_until_done_
&& !controller_
->topLoadingFrame())
1580 controller_
->delegate_
->TestFinished();
1583 void TestRunner::WorkQueue::WorkQueueTask::RunIfValid() {
1584 object_
->ProcessWork();
1587 TestRunner::TestRunner(TestInterfaces
* interfaces
)
1588 : test_is_running_(false),
1589 close_remaining_windows_(false),
1591 disable_notify_done_(false),
1592 web_history_item_count_(0),
1593 intercept_post_message_(false),
1594 test_interfaces_(interfaces
),
1597 web_content_settings_(new WebContentSettings()),
1598 weak_factory_(this) {}
1600 TestRunner::~TestRunner() {}
1602 void TestRunner::Install(WebFrame
* frame
) {
1603 TestRunnerBindings::Install(weak_factory_
.GetWeakPtr(), frame
);
1606 void TestRunner::SetDelegate(WebTestDelegate
* delegate
) {
1607 delegate_
= delegate
;
1608 web_content_settings_
->SetDelegate(delegate
);
1611 void TestRunner::SetWebView(WebView
* webView
, WebTestProxyBase
* proxy
) {
1612 web_view_
= webView
;
1616 void TestRunner::Reset() {
1618 web_view_
->setZoomLevel(0);
1619 web_view_
->setTextZoomFactor(1);
1620 web_view_
->setTabKeyCyclesThroughElements(true);
1621 #if !defined(__APPLE__) && !defined(WIN32) // Actually, TOOLKIT_GTK
1622 // (Constants copied because we can't depend on the header that defined
1623 // them from this file.)
1624 web_view_
->setSelectionColors(
1625 0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232);
1627 web_view_
->setVisibilityState(WebPageVisibilityStateVisible
, true);
1628 web_view_
->mainFrame()->enableViewSourceMode(false);
1630 web_view_
->setPageOverlayColor(SK_ColorTRANSPARENT
);
1633 top_loading_frame_
= nullptr;
1634 wait_until_done_
= false;
1635 wait_until_external_url_load_
= false;
1636 policy_delegate_enabled_
= false;
1637 policy_delegate_is_permissive_
= false;
1638 policy_delegate_should_notify_done_
= false;
1640 WebSecurityPolicy::resetOriginAccessWhitelists();
1641 #if defined(__linux__) || defined(ANDROID)
1642 WebFontRendering::setSubpixelPositioning(false);
1646 // Reset the default quota for each origin to 5MB
1647 delegate_
->SetDatabaseQuota(5 * 1024 * 1024);
1648 delegate_
->SetDeviceColorProfile("reset");
1649 delegate_
->SetDeviceScaleFactor(1);
1650 delegate_
->SetAcceptAllCookies(false);
1651 delegate_
->SetLocale("");
1652 delegate_
->UseUnfortunateSynchronousResizeMode(false);
1653 delegate_
->DisableAutoResizeMode(WebSize());
1654 delegate_
->DeleteAllCookies();
1655 delegate_
->ResetScreenOrientation();
1656 delegate_
->SetBluetoothMockDataSet("");
1657 delegate_
->ClearGeofencingMockProvider();
1658 delegate_
->ResetPermissions();
1659 ResetBatteryStatus();
1663 dump_editting_callbacks_
= false;
1664 dump_as_text_
= false;
1665 dump_as_markup_
= false;
1666 generate_pixel_results_
= true;
1667 dump_child_frame_scroll_positions_
= false;
1668 dump_child_frames_as_markup_
= false;
1669 dump_child_frames_as_text_
= false;
1670 dump_icon_changes_
= false;
1671 dump_as_audio_
= false;
1672 dump_frame_load_callbacks_
= false;
1673 dump_ping_loader_callbacks_
= false;
1674 dump_user_gesture_in_frame_load_callbacks_
= false;
1675 dump_title_changes_
= false;
1676 dump_create_view_
= false;
1677 can_open_windows_
= false;
1678 dump_resource_load_callbacks_
= false;
1679 dump_resource_request_callbacks_
= false;
1680 dump_resource_response_mime_types_
= false;
1681 dump_window_status_changes_
= false;
1682 dump_progress_finished_callback_
= false;
1683 dump_spell_check_callbacks_
= false;
1684 dump_back_forward_list_
= false;
1685 dump_selection_rect_
= false;
1686 dump_drag_image_
= false;
1687 dump_navigation_policy_
= false;
1688 test_repaint_
= false;
1689 sweep_horizontally_
= false;
1690 is_printing_
= false;
1691 midi_accessor_result_
= true;
1692 should_stay_on_page_after_handling_before_unload_
= false;
1693 should_dump_resource_priorities_
= false;
1694 has_custom_text_output_
= false;
1695 custom_text_output_
.clear();
1697 http_headers_to_clear_
.clear();
1699 platform_name_
= "chromium";
1700 tooltip_text_
= std::string();
1701 disable_notify_done_
= false;
1702 web_history_item_count_
= 0;
1703 intercept_post_message_
= false;
1705 web_content_settings_
->Reset();
1707 use_mock_theme_
= true;
1708 pointer_locked_
= false;
1709 pointer_lock_planned_result_
= PointerLockWillSucceed
;
1711 task_list_
.RevokeAll();
1712 work_queue_
.Reset();
1714 if (close_remaining_windows_
&& delegate_
)
1715 delegate_
->CloseRemainingWindows();
1717 close_remaining_windows_
= true;
1720 void TestRunner::SetTestIsRunning(bool running
) {
1721 test_is_running_
= running
;
1724 void TestRunner::InvokeCallback(scoped_ptr
<InvokeCallbackTask
> task
) {
1725 delegate_
->PostTask(task
.release());
1728 bool TestRunner::shouldDumpEditingCallbacks() const {
1729 return dump_editting_callbacks_
;
1732 bool TestRunner::shouldDumpAsText() {
1733 CheckResponseMimeType();
1734 return dump_as_text_
;
1737 void TestRunner::setShouldDumpAsText(bool value
) {
1738 dump_as_text_
= value
;
1741 bool TestRunner::shouldDumpAsMarkup() {
1742 return dump_as_markup_
;
1745 void TestRunner::setShouldDumpAsMarkup(bool value
) {
1746 dump_as_markup_
= value
;
1749 bool TestRunner::shouldDumpAsCustomText() const {
1750 return has_custom_text_output_
;
1753 std::string
TestRunner::customDumpText() const {
1754 return custom_text_output_
;
1757 void TestRunner::setCustomTextOutput(std::string text
) {
1758 custom_text_output_
= text
;
1759 has_custom_text_output_
= true;
1762 bool TestRunner::ShouldGeneratePixelResults() {
1763 CheckResponseMimeType();
1764 return generate_pixel_results_
;
1767 bool TestRunner::ShouldStayOnPageAfterHandlingBeforeUnload() const {
1768 return should_stay_on_page_after_handling_before_unload_
;
1772 void TestRunner::setShouldGeneratePixelResults(bool value
) {
1773 generate_pixel_results_
= value
;
1776 bool TestRunner::shouldDumpChildFrameScrollPositions() const {
1777 return dump_child_frame_scroll_positions_
;
1780 bool TestRunner::shouldDumpChildFramesAsMarkup() const {
1781 return dump_child_frames_as_markup_
;
1784 bool TestRunner::shouldDumpChildFramesAsText() const {
1785 return dump_child_frames_as_text_
;
1788 bool TestRunner::ShouldDumpAsAudio() const {
1789 return dump_as_audio_
;
1792 void TestRunner::GetAudioData(std::vector
<unsigned char>* buffer_view
) const {
1793 *buffer_view
= audio_data_
;
1796 bool TestRunner::shouldDumpFrameLoadCallbacks() const {
1797 return test_is_running_
&& dump_frame_load_callbacks_
;
1800 void TestRunner::setShouldDumpFrameLoadCallbacks(bool value
) {
1801 dump_frame_load_callbacks_
= value
;
1804 bool TestRunner::shouldDumpPingLoaderCallbacks() const {
1805 return test_is_running_
&& dump_ping_loader_callbacks_
;
1808 void TestRunner::setShouldDumpPingLoaderCallbacks(bool value
) {
1809 dump_ping_loader_callbacks_
= value
;
1812 void TestRunner::setShouldEnableViewSource(bool value
) {
1813 web_view_
->mainFrame()->enableViewSourceMode(value
);
1816 bool TestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const {
1817 return test_is_running_
&& dump_user_gesture_in_frame_load_callbacks_
;
1820 bool TestRunner::shouldDumpTitleChanges() const {
1821 return dump_title_changes_
;
1824 bool TestRunner::shouldDumpIconChanges() const {
1825 return dump_icon_changes_
;
1828 bool TestRunner::shouldDumpCreateView() const {
1829 return dump_create_view_
;
1832 bool TestRunner::canOpenWindows() const {
1833 return can_open_windows_
;
1836 bool TestRunner::shouldDumpResourceLoadCallbacks() const {
1837 return test_is_running_
&& dump_resource_load_callbacks_
;
1840 bool TestRunner::shouldDumpResourceRequestCallbacks() const {
1841 return test_is_running_
&& dump_resource_request_callbacks_
;
1844 bool TestRunner::shouldDumpResourceResponseMIMETypes() const {
1845 return test_is_running_
&& dump_resource_response_mime_types_
;
1848 WebContentSettingsClient
* TestRunner::GetWebContentSettings() const {
1849 return web_content_settings_
.get();
1852 bool TestRunner::shouldDumpStatusCallbacks() const {
1853 return dump_window_status_changes_
;
1856 bool TestRunner::shouldDumpProgressFinishedCallback() const {
1857 return dump_progress_finished_callback_
;
1860 bool TestRunner::shouldDumpSpellCheckCallbacks() const {
1861 return dump_spell_check_callbacks_
;
1864 bool TestRunner::ShouldDumpBackForwardList() const {
1865 return dump_back_forward_list_
;
1868 bool TestRunner::shouldDumpSelectionRect() const {
1869 return dump_selection_rect_
;
1872 bool TestRunner::isPrinting() const {
1873 return is_printing_
;
1876 bool TestRunner::shouldWaitUntilExternalURLLoad() const {
1877 return wait_until_external_url_load_
;
1880 const std::set
<std::string
>* TestRunner::httpHeadersToClear() const {
1881 return &http_headers_to_clear_
;
1884 void TestRunner::setTopLoadingFrame(WebFrame
* frame
, bool clear
) {
1885 if (frame
->top()->view() != web_view_
)
1887 if (!test_is_running_
)
1890 top_loading_frame_
= nullptr;
1891 LocationChangeDone();
1892 } else if (!top_loading_frame_
) {
1893 top_loading_frame_
= frame
;
1897 WebFrame
* TestRunner::topLoadingFrame() const {
1898 return top_loading_frame_
;
1901 void TestRunner::policyDelegateDone() {
1902 DCHECK(wait_until_done_
);
1903 delegate_
->TestFinished();
1904 wait_until_done_
= false;
1907 bool TestRunner::policyDelegateEnabled() const {
1908 return policy_delegate_enabled_
;
1911 bool TestRunner::policyDelegateIsPermissive() const {
1912 return policy_delegate_is_permissive_
;
1915 bool TestRunner::policyDelegateShouldNotifyDone() const {
1916 return policy_delegate_should_notify_done_
;
1919 bool TestRunner::shouldInterceptPostMessage() const {
1920 return intercept_post_message_
;
1923 bool TestRunner::shouldDumpResourcePriorities() const {
1924 return should_dump_resource_priorities_
;
1927 bool TestRunner::RequestPointerLock() {
1928 switch (pointer_lock_planned_result_
) {
1929 case PointerLockWillSucceed
:
1930 delegate_
->PostDelayedTask(
1931 new HostMethodTask(this, &TestRunner::DidAcquirePointerLockInternal
),
1934 case PointerLockWillRespondAsync
:
1935 DCHECK(!pointer_locked_
);
1937 case PointerLockWillFailSync
:
1938 DCHECK(!pointer_locked_
);
1946 void TestRunner::RequestPointerUnlock() {
1947 delegate_
->PostDelayedTask(
1948 new HostMethodTask(this, &TestRunner::DidLosePointerLockInternal
), 0);
1951 bool TestRunner::isPointerLocked() {
1952 return pointer_locked_
;
1955 void TestRunner::setToolTipText(const WebString
& text
) {
1956 tooltip_text_
= text
.utf8();
1959 bool TestRunner::shouldDumpDragImage() {
1960 return dump_drag_image_
;
1963 bool TestRunner::shouldDumpNavigationPolicy() const {
1964 return dump_navigation_policy_
;
1967 bool TestRunner::midiAccessorResult() {
1968 return midi_accessor_result_
;
1971 void TestRunner::ClearDevToolsLocalStorage() {
1972 delegate_
->ClearDevToolsLocalStorage();
1975 void TestRunner::ShowDevTools(const std::string
& settings
,
1976 const std::string
& frontend_url
) {
1977 delegate_
->ShowDevTools(settings
, frontend_url
);
1980 class WorkItemBackForward
: public TestRunner::WorkItem
{
1982 WorkItemBackForward(int distance
) : distance_(distance
) {}
1984 bool Run(WebTestDelegate
* delegate
, WebView
*) override
{
1985 delegate
->GoToOffset(distance_
);
1986 return true; // FIXME: Did it really start a navigation?
1993 void TestRunner::NotifyDone() {
1994 if (disable_notify_done_
)
1997 // Test didn't timeout. Kill the timeout timer.
1998 task_list_
.RevokeAll();
2000 CompleteNotifyDone();
2003 void TestRunner::WaitUntilDone() {
2004 wait_until_done_
= true;
2007 void TestRunner::QueueBackNavigation(int how_far_back
) {
2008 work_queue_
.AddWork(new WorkItemBackForward(-how_far_back
));
2011 void TestRunner::QueueForwardNavigation(int how_far_forward
) {
2012 work_queue_
.AddWork(new WorkItemBackForward(how_far_forward
));
2015 class WorkItemReload
: public TestRunner::WorkItem
{
2017 bool Run(WebTestDelegate
* delegate
, WebView
*) override
{
2023 void TestRunner::QueueReload() {
2024 work_queue_
.AddWork(new WorkItemReload());
2027 class WorkItemLoadingScript
: public TestRunner::WorkItem
{
2029 WorkItemLoadingScript(const std::string
& script
)
2030 : script_(script
) {}
2032 bool Run(WebTestDelegate
*, WebView
* web_view
) override
{
2033 web_view
->mainFrame()->executeScript(
2034 WebScriptSource(WebString::fromUTF8(script_
)));
2035 return true; // FIXME: Did it really start a navigation?
2039 std::string script_
;
2042 void TestRunner::QueueLoadingScript(const std::string
& script
) {
2043 work_queue_
.AddWork(new WorkItemLoadingScript(script
));
2046 class WorkItemNonLoadingScript
: public TestRunner::WorkItem
{
2048 WorkItemNonLoadingScript(const std::string
& script
)
2049 : script_(script
) {}
2051 bool Run(WebTestDelegate
*, WebView
* web_view
) override
{
2052 web_view
->mainFrame()->executeScript(
2053 WebScriptSource(WebString::fromUTF8(script_
)));
2058 std::string script_
;
2061 void TestRunner::QueueNonLoadingScript(const std::string
& script
) {
2062 work_queue_
.AddWork(new WorkItemNonLoadingScript(script
));
2065 class WorkItemLoad
: public TestRunner::WorkItem
{
2067 WorkItemLoad(const WebURL
& url
, const std::string
& target
)
2068 : url_(url
), target_(target
) {}
2070 bool Run(WebTestDelegate
* delegate
, WebView
*) override
{
2071 delegate
->LoadURLForFrame(url_
, target_
);
2072 return true; // FIXME: Did it really start a navigation?
2077 std::string target_
;
2080 void TestRunner::QueueLoad(const std::string
& url
, const std::string
& target
) {
2081 // FIXME: Implement WebURL::resolve() and avoid GURL.
2082 GURL current_url
= web_view_
->mainFrame()->document().url();
2083 GURL full_url
= current_url
.Resolve(url
);
2084 work_queue_
.AddWork(new WorkItemLoad(full_url
, target
));
2087 class WorkItemLoadHTMLString
: public TestRunner::WorkItem
{
2089 WorkItemLoadHTMLString(const std::string
& html
, const WebURL
& base_url
)
2090 : html_(html
), base_url_(base_url
) {}
2092 WorkItemLoadHTMLString(const std::string
& html
, const WebURL
& base_url
,
2093 const WebURL
& unreachable_url
)
2094 : html_(html
), base_url_(base_url
), unreachable_url_(unreachable_url
) {}
2096 bool Run(WebTestDelegate
*, WebView
* web_view
) override
{
2097 web_view
->mainFrame()->loadHTMLString(
2098 WebData(html_
.data(), html_
.length()),
2099 base_url_
, unreachable_url_
);
2106 WebURL unreachable_url_
;
2109 void TestRunner::QueueLoadHTMLString(gin::Arguments
* args
) {
2111 args
->GetNext(&html
);
2113 std::string base_url_str
;
2114 args
->GetNext(&base_url_str
);
2115 WebURL base_url
= WebURL(GURL(base_url_str
));
2117 if (!args
->PeekNext().IsEmpty() && args
->PeekNext()->IsString()) {
2118 std::string unreachable_url_str
;
2119 args
->GetNext(&unreachable_url_str
);
2120 WebURL unreachable_url
= WebURL(GURL(unreachable_url_str
));
2121 work_queue_
.AddWork(new WorkItemLoadHTMLString(html
, base_url
,
2124 work_queue_
.AddWork(new WorkItemLoadHTMLString(html
, base_url
));
2128 void TestRunner::SetCustomPolicyDelegate(gin::Arguments
* args
) {
2129 args
->GetNext(&policy_delegate_enabled_
);
2130 if (!args
->PeekNext().IsEmpty() && args
->PeekNext()->IsBoolean())
2131 args
->GetNext(&policy_delegate_is_permissive_
);
2134 void TestRunner::WaitForPolicyDelegate() {
2135 policy_delegate_enabled_
= true;
2136 policy_delegate_should_notify_done_
= true;
2137 wait_until_done_
= true;
2140 int TestRunner::WindowCount() {
2141 return test_interfaces_
->GetWindowList().size();
2144 void TestRunner::SetCloseRemainingWindowsWhenComplete(
2145 bool close_remaining_windows
) {
2146 close_remaining_windows_
= close_remaining_windows
;
2149 void TestRunner::ResetTestHelperControllers() {
2150 test_interfaces_
->ResetTestHelperControllers();
2153 void TestRunner::SetTabKeyCyclesThroughElements(
2154 bool tab_key_cycles_through_elements
) {
2155 web_view_
->setTabKeyCyclesThroughElements(tab_key_cycles_through_elements
);
2158 void TestRunner::ExecCommand(gin::Arguments
* args
) {
2159 std::string command
;
2160 args
->GetNext(&command
);
2163 if (args
->Length() >= 3) {
2164 // Ignore the second parameter (which is userInterface)
2165 // since this command emulates a manual action.
2167 args
->GetNext(&value
);
2170 // Note: webkit's version does not return the boolean, so neither do we.
2171 web_view_
->focusedFrame()->executeCommand(WebString::fromUTF8(command
),
2172 WebString::fromUTF8(value
));
2175 bool TestRunner::IsCommandEnabled(const std::string
& command
) {
2176 return web_view_
->focusedFrame()->isCommandEnabled(
2177 WebString::fromUTF8(command
));
2180 bool TestRunner::CallShouldCloseOnWebView() {
2181 return web_view_
->mainFrame()->dispatchBeforeUnloadEvent();
2184 void TestRunner::SetDomainRelaxationForbiddenForURLScheme(
2185 bool forbidden
, const std::string
& scheme
) {
2186 web_view_
->setDomainRelaxationForbidden(forbidden
,
2187 WebString::fromUTF8(scheme
));
2190 v8::Local
<v8::Value
> TestRunner::EvaluateScriptInIsolatedWorldAndReturnValue(
2192 const std::string
& script
) {
2193 WebVector
<v8::Local
<v8::Value
>> values
;
2194 WebScriptSource
source(WebString::fromUTF8(script
));
2195 // This relies on the iframe focusing itself when it loads. This is a bit
2196 // sketchy, but it seems to be what other tests do.
2197 web_view_
->focusedFrame()->executeScriptInIsolatedWorld(
2198 world_id
, &source
, 1, 1, &values
);
2199 // Since only one script was added, only one result is expected
2200 if (values
.size() == 1 && !values
[0].IsEmpty())
2202 return v8::Local
<v8::Value
>();
2205 void TestRunner::EvaluateScriptInIsolatedWorld(int world_id
,
2206 const std::string
& script
) {
2207 WebScriptSource
source(WebString::fromUTF8(script
));
2208 web_view_
->focusedFrame()->executeScriptInIsolatedWorld(
2209 world_id
, &source
, 1, 1);
2212 void TestRunner::SetIsolatedWorldSecurityOrigin(int world_id
,
2213 v8::Local
<v8::Value
> origin
) {
2214 if (!(origin
->IsString() || !origin
->IsNull()))
2217 WebSecurityOrigin web_origin
;
2218 if (origin
->IsString()) {
2219 web_origin
= WebSecurityOrigin::createFromString(
2220 V8StringToWebString(origin
.As
<v8::String
>()));
2222 web_view_
->focusedFrame()->setIsolatedWorldSecurityOrigin(world_id
,
2226 void TestRunner::SetIsolatedWorldContentSecurityPolicy(
2228 const std::string
& policy
) {
2229 web_view_
->focusedFrame()->setIsolatedWorldContentSecurityPolicy(
2230 world_id
, WebString::fromUTF8(policy
));
2233 void TestRunner::AddOriginAccessWhitelistEntry(
2234 const std::string
& source_origin
,
2235 const std::string
& destination_protocol
,
2236 const std::string
& destination_host
,
2237 bool allow_destination_subdomains
) {
2238 WebURL
url((GURL(source_origin
)));
2242 WebSecurityPolicy::addOriginAccessWhitelistEntry(
2244 WebString::fromUTF8(destination_protocol
),
2245 WebString::fromUTF8(destination_host
),
2246 allow_destination_subdomains
);
2249 void TestRunner::RemoveOriginAccessWhitelistEntry(
2250 const std::string
& source_origin
,
2251 const std::string
& destination_protocol
,
2252 const std::string
& destination_host
,
2253 bool allow_destination_subdomains
) {
2254 WebURL
url((GURL(source_origin
)));
2258 WebSecurityPolicy::removeOriginAccessWhitelistEntry(
2260 WebString::fromUTF8(destination_protocol
),
2261 WebString::fromUTF8(destination_host
),
2262 allow_destination_subdomains
);
2265 bool TestRunner::HasCustomPageSizeStyle(int page_index
) {
2266 WebFrame
* frame
= web_view_
->mainFrame();
2269 return frame
->hasCustomPageSizeStyle(page_index
);
2272 void TestRunner::ForceRedSelectionColors() {
2273 web_view_
->setSelectionColors(0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0);
2276 void TestRunner::InsertStyleSheet(const std::string
& source_code
) {
2277 WebLocalFrame::frameForCurrentContext()->document().insertStyleSheet(
2278 WebString::fromUTF8(source_code
));
2281 bool TestRunner::FindString(const std::string
& search_text
,
2282 const std::vector
<std::string
>& options_array
) {
2283 WebFindOptions find_options
;
2284 bool wrap_around
= false;
2285 find_options
.matchCase
= true;
2286 find_options
.findNext
= true;
2288 for (const std::string
& option
: options_array
) {
2289 if (option
== "CaseInsensitive")
2290 find_options
.matchCase
= false;
2291 else if (option
== "Backwards")
2292 find_options
.forward
= false;
2293 else if (option
== "StartInSelection")
2294 find_options
.findNext
= false;
2295 else if (option
== "AtWordStarts")
2296 find_options
.wordStart
= true;
2297 else if (option
== "TreatMedialCapitalAsWordStart")
2298 find_options
.medialCapitalAsWordStart
= true;
2299 else if (option
== "WrapAround")
2303 WebFrame
* frame
= web_view_
->mainFrame();
2304 const bool find_result
= frame
->find(0, WebString::fromUTF8(search_text
),
2305 find_options
, wrap_around
, 0);
2306 frame
->stopFinding(false);
2310 std::string
TestRunner::SelectionAsMarkup() {
2311 return web_view_
->mainFrame()->selectionAsMarkup().utf8();
2314 void TestRunner::SetTextSubpixelPositioning(bool value
) {
2315 #if defined(__linux__) || defined(ANDROID)
2316 // Since FontConfig doesn't provide a variable to control subpixel
2317 // positioning, we'll fall back to setting it globally for all fonts.
2318 WebFontRendering::setSubpixelPositioning(value
);
2322 void TestRunner::SetPageVisibility(const std::string
& new_visibility
) {
2323 if (new_visibility
== "visible")
2324 web_view_
->setVisibilityState(WebPageVisibilityStateVisible
, false);
2325 else if (new_visibility
== "hidden")
2326 web_view_
->setVisibilityState(WebPageVisibilityStateHidden
, false);
2327 else if (new_visibility
== "prerender")
2328 web_view_
->setVisibilityState(WebPageVisibilityStatePrerender
, false);
2331 void TestRunner::SetTextDirection(const std::string
& direction_name
) {
2332 // Map a direction name to a WebTextDirection value.
2333 WebTextDirection direction
;
2334 if (direction_name
== "auto")
2335 direction
= WebTextDirectionDefault
;
2336 else if (direction_name
== "rtl")
2337 direction
= WebTextDirectionRightToLeft
;
2338 else if (direction_name
== "ltr")
2339 direction
= WebTextDirectionLeftToRight
;
2343 web_view_
->setTextDirection(direction
);
2346 void TestRunner::UseUnfortunateSynchronousResizeMode() {
2347 delegate_
->UseUnfortunateSynchronousResizeMode(true);
2350 bool TestRunner::EnableAutoResizeMode(int min_width
,
2354 WebSize
min_size(min_width
, min_height
);
2355 WebSize
max_size(max_width
, max_height
);
2356 delegate_
->EnableAutoResizeMode(min_size
, max_size
);
2360 bool TestRunner::DisableAutoResizeMode(int new_width
, int new_height
) {
2361 WebSize
new_size(new_width
, new_height
);
2362 delegate_
->DisableAutoResizeMode(new_size
);
2366 void TestRunner::SetMockDeviceLight(double value
) {
2367 delegate_
->SetDeviceLightData(value
);
2370 void TestRunner::ResetDeviceLight() {
2371 delegate_
->SetDeviceLightData(-1);
2374 void TestRunner::SetMockDeviceMotion(
2375 bool has_acceleration_x
, double acceleration_x
,
2376 bool has_acceleration_y
, double acceleration_y
,
2377 bool has_acceleration_z
, double acceleration_z
,
2378 bool has_acceleration_including_gravity_x
,
2379 double acceleration_including_gravity_x
,
2380 bool has_acceleration_including_gravity_y
,
2381 double acceleration_including_gravity_y
,
2382 bool has_acceleration_including_gravity_z
,
2383 double acceleration_including_gravity_z
,
2384 bool has_rotation_rate_alpha
, double rotation_rate_alpha
,
2385 bool has_rotation_rate_beta
, double rotation_rate_beta
,
2386 bool has_rotation_rate_gamma
, double rotation_rate_gamma
,
2388 WebDeviceMotionData motion
;
2391 motion
.hasAccelerationX
= has_acceleration_x
;
2392 motion
.accelerationX
= acceleration_x
;
2393 motion
.hasAccelerationY
= has_acceleration_y
;
2394 motion
.accelerationY
= acceleration_y
;
2395 motion
.hasAccelerationZ
= has_acceleration_z
;
2396 motion
.accelerationZ
= acceleration_z
;
2398 // accelerationIncludingGravity
2399 motion
.hasAccelerationIncludingGravityX
=
2400 has_acceleration_including_gravity_x
;
2401 motion
.accelerationIncludingGravityX
= acceleration_including_gravity_x
;
2402 motion
.hasAccelerationIncludingGravityY
=
2403 has_acceleration_including_gravity_y
;
2404 motion
.accelerationIncludingGravityY
= acceleration_including_gravity_y
;
2405 motion
.hasAccelerationIncludingGravityZ
=
2406 has_acceleration_including_gravity_z
;
2407 motion
.accelerationIncludingGravityZ
= acceleration_including_gravity_z
;
2410 motion
.hasRotationRateAlpha
= has_rotation_rate_alpha
;
2411 motion
.rotationRateAlpha
= rotation_rate_alpha
;
2412 motion
.hasRotationRateBeta
= has_rotation_rate_beta
;
2413 motion
.rotationRateBeta
= rotation_rate_beta
;
2414 motion
.hasRotationRateGamma
= has_rotation_rate_gamma
;
2415 motion
.rotationRateGamma
= rotation_rate_gamma
;
2418 motion
.interval
= interval
;
2420 delegate_
->SetDeviceMotionData(motion
);
2423 void TestRunner::SetMockDeviceOrientation(bool has_alpha
, double alpha
,
2424 bool has_beta
, double beta
,
2425 bool has_gamma
, double gamma
,
2426 bool has_absolute
, bool absolute
) {
2427 WebDeviceOrientationData orientation
;
2430 orientation
.hasAlpha
= has_alpha
;
2431 orientation
.alpha
= alpha
;
2434 orientation
.hasBeta
= has_beta
;
2435 orientation
.beta
= beta
;
2438 orientation
.hasGamma
= has_gamma
;
2439 orientation
.gamma
= gamma
;
2442 orientation
.hasAbsolute
= has_absolute
;
2443 orientation
.absolute
= absolute
;
2445 delegate_
->SetDeviceOrientationData(orientation
);
2448 void TestRunner::SetMockScreenOrientation(const std::string
& orientation_str
) {
2449 blink::WebScreenOrientationType orientation
;
2451 if (orientation_str
== "portrait-primary") {
2452 orientation
= WebScreenOrientationPortraitPrimary
;
2453 } else if (orientation_str
== "portrait-secondary") {
2454 orientation
= WebScreenOrientationPortraitSecondary
;
2455 } else if (orientation_str
== "landscape-primary") {
2456 orientation
= WebScreenOrientationLandscapePrimary
;
2457 } else if (orientation_str
== "landscape-secondary") {
2458 orientation
= WebScreenOrientationLandscapeSecondary
;
2461 delegate_
->SetScreenOrientation(orientation
);
2464 void TestRunner::DidChangeBatteryStatus(bool charging
,
2465 double chargingTime
,
2466 double dischargingTime
,
2468 blink::WebBatteryStatus status
;
2469 status
.charging
= charging
;
2470 status
.chargingTime
= chargingTime
;
2471 status
.dischargingTime
= dischargingTime
;
2472 status
.level
= level
;
2473 delegate_
->DidChangeBatteryStatus(status
);
2476 void TestRunner::ResetBatteryStatus() {
2477 blink::WebBatteryStatus status
;
2478 delegate_
->DidChangeBatteryStatus(status
);
2481 void TestRunner::DidAcquirePointerLock() {
2482 DidAcquirePointerLockInternal();
2485 void TestRunner::DidNotAcquirePointerLock() {
2486 DidNotAcquirePointerLockInternal();
2489 void TestRunner::DidLosePointerLock() {
2490 DidLosePointerLockInternal();
2493 void TestRunner::SetPointerLockWillFailSynchronously() {
2494 pointer_lock_planned_result_
= PointerLockWillFailSync
;
2497 void TestRunner::SetPointerLockWillRespondAsynchronously() {
2498 pointer_lock_planned_result_
= PointerLockWillRespondAsync
;
2501 void TestRunner::SetPopupBlockingEnabled(bool block_popups
) {
2502 delegate_
->Preferences()->java_script_can_open_windows_automatically
=
2504 delegate_
->ApplyPreferences();
2507 void TestRunner::SetJavaScriptCanAccessClipboard(bool can_access
) {
2508 delegate_
->Preferences()->java_script_can_access_clipboard
= can_access
;
2509 delegate_
->ApplyPreferences();
2512 void TestRunner::SetXSSAuditorEnabled(bool enabled
) {
2513 delegate_
->Preferences()->xss_auditor_enabled
= enabled
;
2514 delegate_
->ApplyPreferences();
2517 void TestRunner::SetAllowUniversalAccessFromFileURLs(bool allow
) {
2518 delegate_
->Preferences()->allow_universal_access_from_file_urls
= allow
;
2519 delegate_
->ApplyPreferences();
2522 void TestRunner::SetAllowFileAccessFromFileURLs(bool allow
) {
2523 delegate_
->Preferences()->allow_file_access_from_file_urls
= allow
;
2524 delegate_
->ApplyPreferences();
2527 void TestRunner::OverridePreference(const std::string key
,
2528 v8::Local
<v8::Value
> value
) {
2529 TestPreferences
* prefs
= delegate_
->Preferences();
2530 if (key
== "WebKitDefaultFontSize") {
2531 prefs
->default_font_size
= value
->Int32Value();
2532 } else if (key
== "WebKitMinimumFontSize") {
2533 prefs
->minimum_font_size
= value
->Int32Value();
2534 } else if (key
== "WebKitDefaultTextEncodingName") {
2535 v8::Isolate
* isolate
= blink::mainThreadIsolate();
2536 prefs
->default_text_encoding_name
=
2537 V8StringToWebString(value
->ToString(isolate
));
2538 } else if (key
== "WebKitJavaScriptEnabled") {
2539 prefs
->java_script_enabled
= value
->BooleanValue();
2540 } else if (key
== "WebKitSupportsMultipleWindows") {
2541 prefs
->supports_multiple_windows
= value
->BooleanValue();
2542 } else if (key
== "WebKitDisplayImagesKey") {
2543 prefs
->loads_images_automatically
= value
->BooleanValue();
2544 } else if (key
== "WebKitPluginsEnabled") {
2545 prefs
->plugins_enabled
= value
->BooleanValue();
2546 } else if (key
== "WebKitOfflineWebApplicationCacheEnabled") {
2547 prefs
->offline_web_application_cache_enabled
= value
->BooleanValue();
2548 } else if (key
== "WebKitTabToLinksPreferenceKey") {
2549 prefs
->tabs_to_links
= value
->BooleanValue();
2550 } else if (key
== "WebKitWebGLEnabled") {
2551 prefs
->experimental_webgl_enabled
= value
->BooleanValue();
2552 } else if (key
== "WebKitCSSRegionsEnabled") {
2553 prefs
->experimental_css_regions_enabled
= value
->BooleanValue();
2554 } else if (key
== "WebKitCSSGridLayoutEnabled") {
2555 prefs
->experimental_css_grid_layout_enabled
= value
->BooleanValue();
2556 } else if (key
== "WebKitHyperlinkAuditingEnabled") {
2557 prefs
->hyperlink_auditing_enabled
= value
->BooleanValue();
2558 } else if (key
== "WebKitEnableCaretBrowsing") {
2559 prefs
->caret_browsing_enabled
= value
->BooleanValue();
2560 } else if (key
== "WebKitAllowDisplayingInsecureContent") {
2561 prefs
->allow_display_of_insecure_content
= value
->BooleanValue();
2562 } else if (key
== "WebKitAllowRunningInsecureContent") {
2563 prefs
->allow_running_of_insecure_content
= value
->BooleanValue();
2564 } else if (key
== "WebKitDisableReadingFromCanvas") {
2565 prefs
->disable_reading_from_canvas
= value
->BooleanValue();
2566 } else if (key
== "WebKitStrictMixedContentChecking") {
2567 prefs
->strict_mixed_content_checking
= value
->BooleanValue();
2568 } else if (key
== "WebKitStrictPowerfulFeatureRestrictions") {
2569 prefs
->strict_powerful_feature_restrictions
= value
->BooleanValue();
2570 } else if (key
== "WebKitShouldRespectImageOrientation") {
2571 prefs
->should_respect_image_orientation
= value
->BooleanValue();
2572 } else if (key
== "WebKitWebAudioEnabled") {
2573 DCHECK(value
->BooleanValue());
2574 } else if (key
== "WebKitWebSecurityEnabled") {
2575 prefs
->web_security_enabled
= value
->BooleanValue();
2577 std::string
message("Invalid name for preference: ");
2578 message
.append(key
);
2579 delegate_
->PrintMessage(std::string("CONSOLE MESSAGE: ") + message
+ "\n");
2581 delegate_
->ApplyPreferences();
2584 void TestRunner::SetAcceptLanguages(const std::string
& accept_languages
) {
2585 proxy_
->SetAcceptLanguages(accept_languages
);
2588 void TestRunner::SetPluginsEnabled(bool enabled
) {
2589 delegate_
->Preferences()->plugins_enabled
= enabled
;
2590 delegate_
->ApplyPreferences();
2593 void TestRunner::DumpEditingCallbacks() {
2594 dump_editting_callbacks_
= true;
2597 void TestRunner::DumpAsMarkup() {
2598 dump_as_markup_
= true;
2599 generate_pixel_results_
= false;
2602 void TestRunner::DumpAsText() {
2603 dump_as_text_
= true;
2604 generate_pixel_results_
= false;
2607 void TestRunner::DumpAsTextWithPixelResults() {
2608 dump_as_text_
= true;
2609 generate_pixel_results_
= true;
2612 void TestRunner::DumpChildFrameScrollPositions() {
2613 dump_child_frame_scroll_positions_
= true;
2616 void TestRunner::DumpChildFramesAsMarkup() {
2617 dump_child_frames_as_markup_
= true;
2620 void TestRunner::DumpChildFramesAsText() {
2621 dump_child_frames_as_text_
= true;
2624 void TestRunner::DumpIconChanges() {
2625 dump_icon_changes_
= true;
2628 void TestRunner::SetAudioData(const gin::ArrayBufferView
& view
) {
2629 unsigned char* bytes
= static_cast<unsigned char*>(view
.bytes());
2630 audio_data_
.resize(view
.num_bytes());
2631 std::copy(bytes
, bytes
+ view
.num_bytes(), audio_data_
.begin());
2632 dump_as_audio_
= true;
2635 void TestRunner::DumpFrameLoadCallbacks() {
2636 dump_frame_load_callbacks_
= true;
2639 void TestRunner::DumpPingLoaderCallbacks() {
2640 dump_ping_loader_callbacks_
= true;
2643 void TestRunner::DumpUserGestureInFrameLoadCallbacks() {
2644 dump_user_gesture_in_frame_load_callbacks_
= true;
2647 void TestRunner::DumpTitleChanges() {
2648 dump_title_changes_
= true;
2651 void TestRunner::DumpCreateView() {
2652 dump_create_view_
= true;
2655 void TestRunner::SetCanOpenWindows() {
2656 can_open_windows_
= true;
2659 void TestRunner::DumpResourceLoadCallbacks() {
2660 dump_resource_load_callbacks_
= true;
2663 void TestRunner::DumpResourceRequestCallbacks() {
2664 dump_resource_request_callbacks_
= true;
2667 void TestRunner::DumpResourceResponseMIMETypes() {
2668 dump_resource_response_mime_types_
= true;
2671 void TestRunner::SetImagesAllowed(bool allowed
) {
2672 web_content_settings_
->SetImagesAllowed(allowed
);
2675 void TestRunner::SetMediaAllowed(bool allowed
) {
2676 web_content_settings_
->SetMediaAllowed(allowed
);
2679 void TestRunner::SetScriptsAllowed(bool allowed
) {
2680 web_content_settings_
->SetScriptsAllowed(allowed
);
2683 void TestRunner::SetStorageAllowed(bool allowed
) {
2684 web_content_settings_
->SetStorageAllowed(allowed
);
2687 void TestRunner::SetPluginsAllowed(bool allowed
) {
2688 web_content_settings_
->SetPluginsAllowed(allowed
);
2691 void TestRunner::SetAllowDisplayOfInsecureContent(bool allowed
) {
2692 web_content_settings_
->SetDisplayingInsecureContentAllowed(allowed
);
2695 void TestRunner::SetAllowRunningOfInsecureContent(bool allowed
) {
2696 web_content_settings_
->SetRunningInsecureContentAllowed(allowed
);
2699 void TestRunner::DumpPermissionClientCallbacks() {
2700 web_content_settings_
->SetDumpCallbacks(true);
2703 void TestRunner::DumpWindowStatusChanges() {
2704 dump_window_status_changes_
= true;
2707 void TestRunner::DumpProgressFinishedCallback() {
2708 dump_progress_finished_callback_
= true;
2711 void TestRunner::DumpSpellCheckCallbacks() {
2712 dump_spell_check_callbacks_
= true;
2715 void TestRunner::DumpBackForwardList() {
2716 dump_back_forward_list_
= true;
2719 void TestRunner::DumpSelectionRect() {
2720 dump_selection_rect_
= true;
2723 void TestRunner::SetPrinting() {
2724 is_printing_
= true;
2727 void TestRunner::ClearPrinting() {
2728 is_printing_
= false;
2731 void TestRunner::SetShouldStayOnPageAfterHandlingBeforeUnload(bool value
) {
2732 should_stay_on_page_after_handling_before_unload_
= value
;
2735 void TestRunner::SetWillSendRequestClearHeader(const std::string
& header
) {
2736 if (!header
.empty())
2737 http_headers_to_clear_
.insert(header
);
2740 void TestRunner::DumpResourceRequestPriorities() {
2741 should_dump_resource_priorities_
= true;
2744 void TestRunner::SetUseMockTheme(bool use
) {
2745 use_mock_theme_
= use
;
2748 void TestRunner::ShowWebInspector(const std::string
& str
,
2749 const std::string
& frontend_url
) {
2750 ShowDevTools(str
, frontend_url
);
2753 void TestRunner::WaitUntilExternalURLLoad() {
2754 wait_until_external_url_load_
= true;
2757 void TestRunner::DumpDragImage() {
2758 DumpAsTextWithPixelResults();
2759 dump_drag_image_
= true;
2762 void TestRunner::DumpNavigationPolicy() {
2763 dump_navigation_policy_
= true;
2766 void TestRunner::CloseWebInspector() {
2767 delegate_
->CloseDevTools();
2770 bool TestRunner::IsChooserShown() {
2771 return proxy_
->IsChooserShown();
2774 void TestRunner::EvaluateInWebInspector(int call_id
,
2775 const std::string
& script
) {
2776 delegate_
->EvaluateInWebInspector(call_id
, script
);
2779 void TestRunner::ClearAllDatabases() {
2780 delegate_
->ClearAllDatabases();
2783 void TestRunner::SetDatabaseQuota(int quota
) {
2784 delegate_
->SetDatabaseQuota(quota
);
2787 void TestRunner::SetAlwaysAcceptCookies(bool accept
) {
2788 delegate_
->SetAcceptAllCookies(accept
);
2791 void TestRunner::SetWindowIsKey(bool value
) {
2792 delegate_
->SetFocus(proxy_
, value
);
2795 std::string
TestRunner::PathToLocalResource(const std::string
& path
) {
2796 return delegate_
->PathToLocalResource(path
);
2799 void TestRunner::SetBackingScaleFactor(double value
,
2800 v8::Local
<v8::Function
> callback
) {
2801 delegate_
->SetDeviceScaleFactor(value
);
2802 delegate_
->PostTask(new InvokeCallbackTask(this, callback
));
2805 void TestRunner::SetColorProfile(const std::string
& name
,
2806 v8::Local
<v8::Function
> callback
) {
2807 delegate_
->SetDeviceColorProfile(name
);
2808 delegate_
->PostTask(new InvokeCallbackTask(this, callback
));
2811 void TestRunner::SetBluetoothMockDataSet(const std::string
& name
) {
2812 delegate_
->SetBluetoothMockDataSet(name
);
2815 void TestRunner::SetGeofencingMockProvider(bool service_available
) {
2816 delegate_
->SetGeofencingMockProvider(service_available
);
2819 void TestRunner::ClearGeofencingMockProvider() {
2820 delegate_
->ClearGeofencingMockProvider();
2823 void TestRunner::SetGeofencingMockPosition(double latitude
, double longitude
) {
2824 delegate_
->SetGeofencingMockPosition(latitude
, longitude
);
2827 void TestRunner::SetPermission(const std::string
& name
,
2828 const std::string
& value
,
2830 const GURL
& embedding_origin
) {
2831 delegate_
->SetPermission(name
, value
, origin
, embedding_origin
);
2834 void TestRunner::DispatchBeforeInstallPromptEvent(
2836 const std::vector
<std::string
>& event_platforms
,
2837 v8::Local
<v8::Function
> callback
) {
2838 scoped_ptr
<InvokeCallbackTask
> task(
2839 new InvokeCallbackTask(this, callback
));
2841 delegate_
->DispatchBeforeInstallPromptEvent(
2842 request_id
, event_platforms
,
2843 base::Bind(&TestRunner::DispatchBeforeInstallPromptCallback
,
2844 weak_factory_
.GetWeakPtr(), base::Passed(&task
)));
2847 void TestRunner::ResolveBeforeInstallPromptPromise(
2849 const std::string
& platform
) {
2850 delegate_
->ResolveBeforeInstallPromptPromise(request_id
, platform
);
2853 void TestRunner::SetPOSIXLocale(const std::string
& locale
) {
2854 delegate_
->SetLocale(locale
);
2857 void TestRunner::SetMIDIAccessorResult(bool result
) {
2858 midi_accessor_result_
= result
;
2861 void TestRunner::SimulateWebNotificationClick(const std::string
& title
,
2863 delegate_
->SimulateWebNotificationClick(title
, action_index
);
2866 void TestRunner::AddMockSpeechRecognitionResult(const std::string
& transcript
,
2867 double confidence
) {
2868 proxy_
->GetSpeechRecognizerMock()->AddMockResult(
2869 WebString::fromUTF8(transcript
), confidence
);
2872 void TestRunner::SetMockSpeechRecognitionError(const std::string
& error
,
2873 const std::string
& message
) {
2874 proxy_
->GetSpeechRecognizerMock()->SetError(WebString::fromUTF8(error
),
2875 WebString::fromUTF8(message
));
2878 bool TestRunner::WasMockSpeechRecognitionAborted() {
2879 return proxy_
->GetSpeechRecognizerMock()->WasAborted();
2882 void TestRunner::AddMockCredentialManagerResponse(const std::string
& id
,
2883 const std::string
& name
,
2884 const std::string
& avatar
,
2885 const std::string
& password
) {
2886 proxy_
->GetCredentialManagerClientMock()->SetResponse(
2887 new WebPasswordCredential(WebString::fromUTF8(id
),
2888 WebString::fromUTF8(password
),
2889 WebString::fromUTF8(name
),
2890 WebURL(GURL(avatar
))));
2893 void TestRunner::AddWebPageOverlay() {
2895 web_view_
->setPageOverlayColor(SK_ColorCYAN
);
2898 void TestRunner::RemoveWebPageOverlay() {
2900 web_view_
->setPageOverlayColor(SK_ColorTRANSPARENT
);
2903 void TestRunner::LayoutAndPaintAsync() {
2904 proxy_
->LayoutAndPaintAsyncThen(base::Closure());
2907 void TestRunner::LayoutAndPaintAsyncThen(v8::Local
<v8::Function
> callback
) {
2908 scoped_ptr
<InvokeCallbackTask
> task(
2909 new InvokeCallbackTask(this, callback
));
2910 proxy_
->LayoutAndPaintAsyncThen(base::Bind(&TestRunner::InvokeCallback
,
2911 weak_factory_
.GetWeakPtr(),
2912 base::Passed(&task
)));
2915 void TestRunner::GetManifestThen(v8::Local
<v8::Function
> callback
) {
2916 scoped_ptr
<InvokeCallbackTask
> task(
2917 new InvokeCallbackTask(this, callback
));
2919 delegate_
->FetchManifest(
2920 web_view_
, web_view_
->mainFrame()->document().manifestURL(),
2921 base::Bind(&TestRunner::GetManifestCallback
, weak_factory_
.GetWeakPtr(),
2922 base::Passed(&task
)));
2925 void TestRunner::CapturePixelsAsyncThen(v8::Local
<v8::Function
> callback
) {
2926 scoped_ptr
<InvokeCallbackTask
> task(
2927 new InvokeCallbackTask(this, callback
));
2928 proxy_
->CapturePixelsAsync(base::Bind(&TestRunner::CapturePixelsCallback
,
2929 weak_factory_
.GetWeakPtr(),
2930 base::Passed(&task
)));
2933 void TestRunner::ForceNextWebGLContextCreationToFail() {
2935 web_view_
->forceNextWebGLContextCreationToFail();
2938 void TestRunner::ForceNextDrawingBufferCreationToFail() {
2940 web_view_
->forceNextDrawingBufferCreationToFail();
2943 void TestRunner::CopyImageAtAndCapturePixelsAsyncThen(
2944 int x
, int y
, v8::Local
<v8::Function
> callback
) {
2945 scoped_ptr
<InvokeCallbackTask
> task(
2946 new InvokeCallbackTask(this, callback
));
2947 proxy_
->CopyImageAtAndCapturePixels(
2948 x
, y
, base::Bind(&TestRunner::CapturePixelsCallback
,
2949 weak_factory_
.GetWeakPtr(),
2950 base::Passed(&task
)));
2953 void TestRunner::GetManifestCallback(scoped_ptr
<InvokeCallbackTask
> task
,
2954 const blink::WebURLResponse
& response
,
2955 const std::string
& data
) {
2956 InvokeCallback(task
.Pass());
2959 void TestRunner::CapturePixelsCallback(scoped_ptr
<InvokeCallbackTask
> task
,
2960 const SkBitmap
& snapshot
) {
2961 v8::Isolate
* isolate
= blink::mainThreadIsolate();
2962 v8::HandleScope
handle_scope(isolate
);
2964 v8::Local
<v8::Context
> context
=
2965 web_view_
->mainFrame()->mainWorldScriptContext();
2966 if (context
.IsEmpty())
2969 v8::Context::Scope
context_scope(context
);
2970 v8::Local
<v8::Value
> argv
[3];
2971 SkAutoLockPixels
snapshot_lock(snapshot
);
2973 // Size can be 0 for cases where copyImageAt was called on position
2974 // that doesn't have an image.
2975 int width
= snapshot
.info().width();
2976 argv
[0] = v8::Number::New(isolate
, width
);
2978 int height
= snapshot
.info().height();
2979 argv
[1] = v8::Number::New(isolate
, height
);
2981 blink::WebArrayBuffer buffer
=
2982 blink::WebArrayBuffer::create(snapshot
.getSize(), 1);
2983 memcpy(buffer
.data(), snapshot
.getPixels(), buffer
.byteLength());
2984 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT
2986 // Skia's internal byte order is BGRA. Must swap the B and R channels in
2987 // order to provide a consistent ordering to the layout tests.
2988 unsigned char* pixels
= static_cast<unsigned char*>(buffer
.data());
2989 unsigned len
= buffer
.byteLength();
2990 for (unsigned i
= 0; i
< len
; i
+= 4) {
2991 std::swap(pixels
[i
], pixels
[i
+ 2]);
2996 argv
[2] = blink::WebArrayBufferConverter::toV8Value(
2997 &buffer
, context
->Global(), isolate
);
2999 task
->SetArguments(3, argv
);
3000 InvokeCallback(task
.Pass());
3003 void TestRunner::DispatchBeforeInstallPromptCallback(
3004 scoped_ptr
<InvokeCallbackTask
> task
,
3006 v8::Isolate
* isolate
= blink::mainThreadIsolate();
3007 v8::HandleScope
handle_scope(isolate
);
3009 v8::Local
<v8::Context
> context
=
3010 web_view_
->mainFrame()->mainWorldScriptContext();
3011 if (context
.IsEmpty())
3014 v8::Context::Scope
context_scope(context
);
3015 v8::Local
<v8::Value
> argv
[1];
3016 argv
[0] = v8::Boolean::New(isolate
, canceled
);
3018 task
->SetArguments(1, argv
);
3019 InvokeCallback(task
.Pass());
3022 void TestRunner::LocationChangeDone() {
3023 web_history_item_count_
= delegate_
->NavigationEntryCount();
3025 // No more new work after the first complete load.
3026 work_queue_
.set_frozen(true);
3028 if (!wait_until_done_
)
3029 work_queue_
.ProcessWorkSoon();
3032 void TestRunner::CheckResponseMimeType() {
3033 // Text output: the test page can request different types of output which we
3035 if (!dump_as_text_
) {
3036 std::string mimeType
=
3037 web_view_
->mainFrame()->dataSource()->response().mimeType().utf8();
3038 if (mimeType
== "text/plain") {
3039 dump_as_text_
= true;
3040 generate_pixel_results_
= false;
3045 void TestRunner::CompleteNotifyDone() {
3046 if (wait_until_done_
&& !topLoadingFrame() && work_queue_
.is_empty())
3047 delegate_
->TestFinished();
3048 wait_until_done_
= false;
3051 void TestRunner::DidAcquirePointerLockInternal() {
3052 pointer_locked_
= true;
3053 web_view_
->didAcquirePointerLock();
3055 // Reset planned result to default.
3056 pointer_lock_planned_result_
= PointerLockWillSucceed
;
3059 void TestRunner::DidNotAcquirePointerLockInternal() {
3060 DCHECK(!pointer_locked_
);
3061 pointer_locked_
= false;
3062 web_view_
->didNotAcquirePointerLock();
3064 // Reset planned result to default.
3065 pointer_lock_planned_result_
= PointerLockWillSucceed
;
3068 void TestRunner::DidLosePointerLockInternal() {
3069 bool was_locked
= pointer_locked_
;
3070 pointer_locked_
= false;
3072 web_view_
->didLosePointerLock();
3075 } // namespace test_runner