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 "content/shell/renderer/test_runner/test_runner.h"
9 #include "base/logging.h"
10 #include "content/shell/common/test_runner/test_preferences.h"
11 #include "content/shell/renderer/test_runner/mock_credential_manager_client.h"
12 #include "content/shell/renderer/test_runner/mock_web_speech_recognizer.h"
13 #include "content/shell/renderer/test_runner/test_interfaces.h"
14 #include "content/shell/renderer/test_runner/web_content_settings.h"
15 #include "content/shell/renderer/test_runner/web_test_delegate.h"
16 #include "content/shell/renderer/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/WebLocalCredential.h"
26 #include "third_party/WebKit/public/platform/WebPoint.h"
27 #include "third_party/WebKit/public/platform/WebServiceWorkerRegistration.h"
28 #include "third_party/WebKit/public/platform/WebURLResponse.h"
29 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceMotionData.h"
30 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceOrientationData.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/WebPageOverlay.h"
43 #include "third_party/WebKit/public/web/WebScriptSource.h"
44 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
45 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
46 #include "third_party/WebKit/public/web/WebSettings.h"
47 #include "third_party/WebKit/public/web/WebSurroundingText.h"
48 #include "third_party/WebKit/public/web/WebView.h"
49 #include "third_party/skia/include/core/SkBitmap.h"
50 #include "third_party/skia/include/core/SkCanvas.h"
51 #include "ui/gfx/geometry/rect.h"
52 #include "ui/gfx/geometry/rect_f.h"
53 #include "ui/gfx/geometry/size.h"
54 #include "ui/gfx/skia_util.h"
56 #if defined(__linux__) || defined(ANDROID)
57 #include "third_party/WebKit/public/web/linux/WebFontRendering.h"
60 using namespace blink
;
66 WebString
V8StringToWebString(v8::Local
<v8::String
> v8_str
) {
67 int length
= v8_str
->Utf8Length() + 1;
68 scoped_ptr
<char[]> chars(new char[length
]);
69 v8_str
->WriteUtf8(chars
.get(), length
);
70 return WebString::fromUTF8(chars
.get());
73 class HostMethodTask
: public WebMethodTask
<TestRunner
> {
75 typedef void (TestRunner::*CallbackMethodType
)();
76 HostMethodTask(TestRunner
* object
, CallbackMethodType callback
)
77 : WebMethodTask
<TestRunner
>(object
), callback_(callback
) {}
79 void RunIfValid() override
{ (object_
->*callback_
)(); }
82 CallbackMethodType callback_
;
87 class InvokeCallbackTask
: public WebMethodTask
<TestRunner
> {
89 InvokeCallbackTask(TestRunner
* object
, v8::Local
<v8::Function
> callback
)
90 : WebMethodTask
<TestRunner
>(object
),
91 callback_(blink::mainThreadIsolate(), callback
),
94 void RunIfValid() override
{
95 v8::Isolate
* isolate
= blink::mainThreadIsolate();
96 v8::HandleScope
handle_scope(isolate
);
97 WebFrame
* frame
= object_
->web_view_
->mainFrame();
99 v8::Local
<v8::Context
> context
= frame
->mainWorldScriptContext();
100 if (context
.IsEmpty())
103 v8::Context::Scope
context_scope(context
);
105 scoped_ptr
<v8::Local
<v8::Value
>[]> local_argv
;
107 local_argv
.reset(new v8::Local
<v8::Value
>[argc_
]);
108 for (int i
= 0; i
< argc_
; ++i
)
109 local_argv
[i
] = v8::Local
<v8::Value
>::New(isolate
, argv_
[i
]);
112 frame
->callFunctionEvenIfScriptDisabled(
113 v8::Local
<v8::Function
>::New(isolate
, callback_
),
119 void SetArguments(int argc
, v8::Local
<v8::Value
> argv
[]) {
120 v8::Isolate
* isolate
= blink::mainThreadIsolate();
122 argv_
.reset(new v8::UniquePersistent
<v8::Value
>[argc
]);
123 for (int i
= 0; i
< argc
; ++i
)
124 argv_
[i
] = v8::UniquePersistent
<v8::Value
>(isolate
, argv
[i
]);
128 v8::UniquePersistent
<v8::Function
> callback_
;
130 scoped_ptr
<v8::UniquePersistent
<v8::Value
>[]> argv_
;
133 class TestRunnerBindings
: public gin::Wrappable
<TestRunnerBindings
> {
135 static gin::WrapperInfo kWrapperInfo
;
137 static void Install(base::WeakPtr
<TestRunner
> controller
,
141 explicit TestRunnerBindings(
142 base::WeakPtr
<TestRunner
> controller
);
143 ~TestRunnerBindings() override
;
146 gin::ObjectTemplateBuilder
GetObjectTemplateBuilder(
147 v8::Isolate
* isolate
) override
;
149 void LogToStderr(const std::string
& output
);
151 void WaitUntilDone();
152 void QueueBackNavigation(int how_far_back
);
153 void QueueForwardNavigation(int how_far_forward
);
155 void QueueLoadingScript(const std::string
& script
);
156 void QueueNonLoadingScript(const std::string
& script
);
157 void QueueLoad(gin::Arguments
* args
);
158 void QueueLoadHTMLString(gin::Arguments
* args
);
159 void SetCustomPolicyDelegate(gin::Arguments
* args
);
160 void WaitForPolicyDelegate();
162 void SetCloseRemainingWindowsWhenComplete(gin::Arguments
* args
);
163 void ResetTestHelperControllers();
164 void SetTabKeyCyclesThroughElements(bool tab_key_cycles_through_elements
);
165 void ExecCommand(gin::Arguments
* args
);
166 bool IsCommandEnabled(const std::string
& command
);
167 bool CallShouldCloseOnWebView();
168 void SetDomainRelaxationForbiddenForURLScheme(bool forbidden
,
169 const std::string
& scheme
);
170 v8::Local
<v8::Value
> EvaluateScriptInIsolatedWorldAndReturnValue(
171 int world_id
, const std::string
& script
);
172 void EvaluateScriptInIsolatedWorld(int world_id
, const std::string
& script
);
173 void SetIsolatedWorldSecurityOrigin(int world_id
,
174 v8::Local
<v8::Value
> origin
);
175 void SetIsolatedWorldContentSecurityPolicy(int world_id
,
176 const std::string
& policy
);
177 void AddOriginAccessWhitelistEntry(const std::string
& source_origin
,
178 const std::string
& destination_protocol
,
179 const std::string
& destination_host
,
180 bool allow_destination_subdomains
);
181 void RemoveOriginAccessWhitelistEntry(const std::string
& source_origin
,
182 const std::string
& destination_protocol
,
183 const std::string
& destination_host
,
184 bool allow_destination_subdomains
);
185 bool HasCustomPageSizeStyle(int page_index
);
186 void ForceRedSelectionColors();
187 void InsertStyleSheet(const std::string
& source_code
);
188 bool FindString(const std::string
& search_text
,
189 const std::vector
<std::string
>& options_array
);
190 std::string
SelectionAsMarkup();
191 void SetTextSubpixelPositioning(bool value
);
192 void SetPageVisibility(const std::string
& new_visibility
);
193 void SetTextDirection(const std::string
& direction_name
);
194 void UseUnfortunateSynchronousResizeMode();
195 bool EnableAutoResizeMode(int min_width
,
199 bool DisableAutoResizeMode(int new_width
, int new_height
);
200 void SetMockDeviceLight(double value
);
201 void ResetDeviceLight();
202 void SetMockDeviceMotion(gin::Arguments
* args
);
203 void SetMockDeviceOrientation(gin::Arguments
* args
);
204 void SetMockScreenOrientation(const std::string
& orientation
);
205 void DidChangeBatteryStatus(bool charging
,
207 double dischargingTime
,
209 void ResetBatteryStatus();
210 void DidAcquirePointerLock();
211 void DidNotAcquirePointerLock();
212 void DidLosePointerLock();
213 void SetPointerLockWillFailSynchronously();
214 void SetPointerLockWillRespondAsynchronously();
215 void SetPopupBlockingEnabled(bool block_popups
);
216 void SetJavaScriptCanAccessClipboard(bool can_access
);
217 void SetXSSAuditorEnabled(bool enabled
);
218 void SetAllowUniversalAccessFromFileURLs(bool allow
);
219 void SetAllowFileAccessFromFileURLs(bool allow
);
220 void OverridePreference(const std::string key
, v8::Local
<v8::Value
> value
);
221 void SetAcceptLanguages(const std::string
& accept_languages
);
222 void SetPluginsEnabled(bool enabled
);
223 void DumpEditingCallbacks();
226 void DumpAsTextWithPixelResults();
227 void DumpChildFrameScrollPositions();
228 void DumpChildFramesAsMarkup();
229 void DumpChildFramesAsText();
230 void DumpIconChanges();
231 void SetAudioData(const gin::ArrayBufferView
& view
);
232 void DumpFrameLoadCallbacks();
233 void DumpPingLoaderCallbacks();
234 void DumpUserGestureInFrameLoadCallbacks();
235 void DumpTitleChanges();
236 void DumpCreateView();
237 void SetCanOpenWindows();
238 void DumpResourceLoadCallbacks();
239 void DumpResourceRequestCallbacks();
240 void DumpResourceResponseMIMETypes();
241 void SetImagesAllowed(bool allowed
);
242 void SetMediaAllowed(bool allowed
);
243 void SetScriptsAllowed(bool allowed
);
244 void SetStorageAllowed(bool allowed
);
245 void SetPluginsAllowed(bool allowed
);
246 void SetAllowDisplayOfInsecureContent(bool allowed
);
247 void SetAllowRunningOfInsecureContent(bool allowed
);
248 void DumpPermissionClientCallbacks();
249 void DumpWindowStatusChanges();
250 void DumpProgressFinishedCallback();
251 void DumpSpellCheckCallbacks();
252 void DumpBackForwardList();
253 void DumpSelectionRect();
255 void ClearPrinting();
256 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value
);
257 void SetWillSendRequestClearHeader(const std::string
& header
);
258 void DumpResourceRequestPriorities();
259 void SetUseMockTheme(bool use
);
260 void WaitUntilExternalURLLoad();
261 void DumpDragImage();
262 void DumpNavigationPolicy();
263 void ShowWebInspector(gin::Arguments
* args
);
264 void CloseWebInspector();
265 bool IsChooserShown();
266 void EvaluateInWebInspector(int call_id
, const std::string
& script
);
267 void ClearAllDatabases();
268 void SetDatabaseQuota(int quota
);
269 void SetAlwaysAcceptCookies(bool accept
);
270 void SetWindowIsKey(bool value
);
271 std::string
PathToLocalResource(const std::string
& path
);
272 void SetBackingScaleFactor(double value
, v8::Local
<v8::Function
> callback
);
273 void SetColorProfile(const std::string
& name
,
274 v8::Local
<v8::Function
> callback
);
275 void SetPOSIXLocale(const std::string
& locale
);
276 void SetMIDIAccessorResult(bool result
);
277 void SimulateWebNotificationClick(const std::string
& title
);
278 void AddMockSpeechRecognitionResult(const std::string
& transcript
,
280 void SetMockSpeechRecognitionError(const std::string
& error
,
281 const std::string
& message
);
282 bool WasMockSpeechRecognitionAborted();
283 void AddMockCredentialManagerResponse(const std::string
& id
,
284 const std::string
& name
,
285 const std::string
& avatar
,
286 const std::string
& password
);
287 void AddWebPageOverlay();
288 void RemoveWebPageOverlay();
289 void LayoutAndPaintAsync();
290 void LayoutAndPaintAsyncThen(v8::Local
<v8::Function
> callback
);
291 void GetManifestThen(v8::Local
<v8::Function
> callback
);
292 void CapturePixelsAsyncThen(v8::Local
<v8::Function
> callback
);
293 void CopyImageAtAndCapturePixelsAsyncThen(int x
,
295 v8::Local
<v8::Function
> callback
);
296 void SetCustomTextOutput(std::string output
);
297 void SetViewSourceForFrame(const std::string
& name
, bool enabled
);
298 void SetBluetoothMockDataSet(const std::string
& dataset_name
);
299 void SetGeofencingMockProvider(bool service_available
);
300 void ClearGeofencingMockProvider();
301 void SetGeofencingMockPosition(double latitude
, double longitude
);
302 void SetPermission(const std::string
& name
,
303 const std::string
& value
,
304 const std::string
& origin
,
305 const std::string
& embedding_origin
);
306 void DispatchBeforeInstallPromptEvent(
308 const std::vector
<std::string
>& event_platforms
,
309 v8::Local
<v8::Function
> callback
);
310 void ResolveBeforeInstallPromptPromise(int request_id
,
311 const std::string
& platform
);
313 std::string
PlatformName();
314 std::string
TooltipText();
315 bool DisableNotifyDone();
316 int WebHistoryItemCount();
317 bool InterceptPostMessage();
318 void SetInterceptPostMessage(bool value
);
320 void NotImplemented(const gin::Arguments
& args
);
322 void ForceNextWebGLContextCreationToFail();
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("setGeofencingMockProvider",
574 &TestRunnerBindings::SetGeofencingMockProvider
)
575 .SetMethod("clearGeofencingMockProvider",
576 &TestRunnerBindings::ClearGeofencingMockProvider
)
577 .SetMethod("setGeofencingMockPosition",
578 &TestRunnerBindings::SetGeofencingMockPosition
)
579 .SetMethod("setPermission", &TestRunnerBindings::SetPermission
)
580 .SetMethod("dispatchBeforeInstallPromptEvent",
581 &TestRunnerBindings::DispatchBeforeInstallPromptEvent
)
582 .SetMethod("resolveBeforeInstallPromptPromise",
583 &TestRunnerBindings::ResolveBeforeInstallPromptPromise
)
586 .SetProperty("platformName", &TestRunnerBindings::PlatformName
)
587 .SetProperty("tooltipText", &TestRunnerBindings::TooltipText
)
588 .SetProperty("disableNotifyDone", &TestRunnerBindings::DisableNotifyDone
)
589 // webHistoryItemCount is used by tests in LayoutTests\http\tests\history
590 .SetProperty("webHistoryItemCount",
591 &TestRunnerBindings::WebHistoryItemCount
)
592 .SetProperty("interceptPostMessage",
593 &TestRunnerBindings::InterceptPostMessage
,
594 &TestRunnerBindings::SetInterceptPostMessage
)
596 // The following are stubs.
597 .SetMethod("dumpDatabaseCallbacks", &TestRunnerBindings::NotImplemented
)
598 .SetMethod("setIconDatabaseEnabled", &TestRunnerBindings::NotImplemented
)
599 .SetMethod("setScrollbarPolicy", &TestRunnerBindings::NotImplemented
)
600 .SetMethod("clearAllApplicationCaches",
601 &TestRunnerBindings::NotImplemented
)
602 .SetMethod("clearApplicationCacheForOrigin",
603 &TestRunnerBindings::NotImplemented
)
604 .SetMethod("clearBackForwardList", &TestRunnerBindings::NotImplemented
)
605 .SetMethod("keepWebHistory", &TestRunnerBindings::NotImplemented
)
606 .SetMethod("setApplicationCacheOriginQuota",
607 &TestRunnerBindings::NotImplemented
)
608 .SetMethod("setCallCloseOnWebViews", &TestRunnerBindings::NotImplemented
)
609 .SetMethod("setMainFrameIsFirstResponder",
610 &TestRunnerBindings::NotImplemented
)
611 .SetMethod("setUseDashboardCompatibilityMode",
612 &TestRunnerBindings::NotImplemented
)
613 .SetMethod("deleteAllLocalStorage", &TestRunnerBindings::NotImplemented
)
614 .SetMethod("localStorageDiskUsageForOrigin",
615 &TestRunnerBindings::NotImplemented
)
616 .SetMethod("originsWithLocalStorage", &TestRunnerBindings::NotImplemented
)
617 .SetMethod("deleteLocalStorageForOrigin",
618 &TestRunnerBindings::NotImplemented
)
619 .SetMethod("observeStorageTrackerNotifications",
620 &TestRunnerBindings::NotImplemented
)
621 .SetMethod("syncLocalStorage", &TestRunnerBindings::NotImplemented
)
622 .SetMethod("addDisallowedURL", &TestRunnerBindings::NotImplemented
)
623 .SetMethod("applicationCacheDiskUsageForOrigin",
624 &TestRunnerBindings::NotImplemented
)
625 .SetMethod("abortModal", &TestRunnerBindings::NotImplemented
)
628 // Used at fast/dom/assign-to-window-status.html
629 .SetMethod("dumpStatusCallbacks",
630 &TestRunnerBindings::DumpWindowStatusChanges
);
633 void TestRunnerBindings::LogToStderr(const std::string
& output
) {
634 LOG(ERROR
) << output
;
637 void TestRunnerBindings::NotifyDone() {
639 runner_
->NotifyDone();
642 void TestRunnerBindings::WaitUntilDone() {
644 runner_
->WaitUntilDone();
647 void TestRunnerBindings::QueueBackNavigation(int how_far_back
) {
649 runner_
->QueueBackNavigation(how_far_back
);
652 void TestRunnerBindings::QueueForwardNavigation(int how_far_forward
) {
654 runner_
->QueueForwardNavigation(how_far_forward
);
657 void TestRunnerBindings::QueueReload() {
659 runner_
->QueueReload();
662 void TestRunnerBindings::QueueLoadingScript(const std::string
& script
) {
664 runner_
->QueueLoadingScript(script
);
667 void TestRunnerBindings::QueueNonLoadingScript(const std::string
& script
) {
669 runner_
->QueueNonLoadingScript(script
);
672 void TestRunnerBindings::QueueLoad(gin::Arguments
* args
) {
677 args
->GetNext(&target
);
678 runner_
->QueueLoad(url
, target
);
682 void TestRunnerBindings::QueueLoadHTMLString(gin::Arguments
* args
) {
684 runner_
->QueueLoadHTMLString(args
);
687 void TestRunnerBindings::SetCustomPolicyDelegate(gin::Arguments
* args
) {
689 runner_
->SetCustomPolicyDelegate(args
);
692 void TestRunnerBindings::WaitForPolicyDelegate() {
694 runner_
->WaitForPolicyDelegate();
697 int TestRunnerBindings::WindowCount() {
699 return runner_
->WindowCount();
703 void TestRunnerBindings::SetCloseRemainingWindowsWhenComplete(
704 gin::Arguments
* args
) {
708 // In the original implementation, nothing happens if the argument is
710 bool close_remaining_windows
= false;
711 if (args
->GetNext(&close_remaining_windows
))
712 runner_
->SetCloseRemainingWindowsWhenComplete(close_remaining_windows
);
715 void TestRunnerBindings::ResetTestHelperControllers() {
717 runner_
->ResetTestHelperControllers();
720 void TestRunnerBindings::SetTabKeyCyclesThroughElements(
721 bool tab_key_cycles_through_elements
) {
723 runner_
->SetTabKeyCyclesThroughElements(tab_key_cycles_through_elements
);
726 void TestRunnerBindings::ExecCommand(gin::Arguments
* args
) {
728 runner_
->ExecCommand(args
);
731 bool TestRunnerBindings::IsCommandEnabled(const std::string
& command
) {
733 return runner_
->IsCommandEnabled(command
);
737 bool TestRunnerBindings::CallShouldCloseOnWebView() {
739 return runner_
->CallShouldCloseOnWebView();
743 void TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme(
744 bool forbidden
, const std::string
& scheme
) {
746 runner_
->SetDomainRelaxationForbiddenForURLScheme(forbidden
, scheme
);
750 TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue(
751 int world_id
, const std::string
& script
) {
753 return v8::Local
<v8::Value
>();
754 return runner_
->EvaluateScriptInIsolatedWorldAndReturnValue(world_id
,
758 void TestRunnerBindings::EvaluateScriptInIsolatedWorld(
759 int world_id
, const std::string
& script
) {
761 runner_
->EvaluateScriptInIsolatedWorld(world_id
, script
);
764 void TestRunnerBindings::SetIsolatedWorldSecurityOrigin(
765 int world_id
, v8::Local
<v8::Value
> origin
) {
767 runner_
->SetIsolatedWorldSecurityOrigin(world_id
, origin
);
770 void TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy(
771 int world_id
, const std::string
& policy
) {
773 runner_
->SetIsolatedWorldContentSecurityPolicy(world_id
, policy
);
776 void TestRunnerBindings::AddOriginAccessWhitelistEntry(
777 const std::string
& source_origin
,
778 const std::string
& destination_protocol
,
779 const std::string
& destination_host
,
780 bool allow_destination_subdomains
) {
782 runner_
->AddOriginAccessWhitelistEntry(source_origin
,
783 destination_protocol
,
785 allow_destination_subdomains
);
789 void TestRunnerBindings::RemoveOriginAccessWhitelistEntry(
790 const std::string
& source_origin
,
791 const std::string
& destination_protocol
,
792 const std::string
& destination_host
,
793 bool allow_destination_subdomains
) {
795 runner_
->RemoveOriginAccessWhitelistEntry(source_origin
,
796 destination_protocol
,
798 allow_destination_subdomains
);
802 bool TestRunnerBindings::HasCustomPageSizeStyle(int page_index
) {
804 return runner_
->HasCustomPageSizeStyle(page_index
);
808 void TestRunnerBindings::ForceRedSelectionColors() {
810 runner_
->ForceRedSelectionColors();
813 void TestRunnerBindings::InsertStyleSheet(const std::string
& source_code
) {
815 runner_
->InsertStyleSheet(source_code
);
818 bool TestRunnerBindings::FindString(
819 const std::string
& search_text
,
820 const std::vector
<std::string
>& options_array
) {
822 return runner_
->FindString(search_text
, options_array
);
826 std::string
TestRunnerBindings::SelectionAsMarkup() {
828 return runner_
->SelectionAsMarkup();
829 return std::string();
832 void TestRunnerBindings::SetTextSubpixelPositioning(bool value
) {
834 runner_
->SetTextSubpixelPositioning(value
);
837 void TestRunnerBindings::SetPageVisibility(const std::string
& new_visibility
) {
839 runner_
->SetPageVisibility(new_visibility
);
842 void TestRunnerBindings::SetTextDirection(const std::string
& direction_name
) {
844 runner_
->SetTextDirection(direction_name
);
847 void TestRunnerBindings::UseUnfortunateSynchronousResizeMode() {
849 runner_
->UseUnfortunateSynchronousResizeMode();
852 bool TestRunnerBindings::EnableAutoResizeMode(int min_width
,
857 return runner_
->EnableAutoResizeMode(min_width
, min_height
,
858 max_width
, max_height
);
863 bool TestRunnerBindings::DisableAutoResizeMode(int new_width
, int new_height
) {
865 return runner_
->DisableAutoResizeMode(new_width
, new_height
);
869 void TestRunnerBindings::SetMockDeviceLight(double value
) {
872 runner_
->SetMockDeviceLight(value
);
875 void TestRunnerBindings::ResetDeviceLight() {
877 runner_
->ResetDeviceLight();
880 void TestRunnerBindings::SetMockDeviceMotion(gin::Arguments
* args
) {
884 bool has_acceleration_x
;
885 double acceleration_x
;
886 bool has_acceleration_y
;
887 double acceleration_y
;
888 bool has_acceleration_z
;
889 double acceleration_z
;
890 bool has_acceleration_including_gravity_x
;
891 double acceleration_including_gravity_x
;
892 bool has_acceleration_including_gravity_y
;
893 double acceleration_including_gravity_y
;
894 bool has_acceleration_including_gravity_z
;
895 double acceleration_including_gravity_z
;
896 bool has_rotation_rate_alpha
;
897 double rotation_rate_alpha
;
898 bool has_rotation_rate_beta
;
899 double rotation_rate_beta
;
900 bool has_rotation_rate_gamma
;
901 double rotation_rate_gamma
;
904 args
->GetNext(&has_acceleration_x
);
905 args
->GetNext(& acceleration_x
);
906 args
->GetNext(&has_acceleration_y
);
907 args
->GetNext(& acceleration_y
);
908 args
->GetNext(&has_acceleration_z
);
909 args
->GetNext(& acceleration_z
);
910 args
->GetNext(&has_acceleration_including_gravity_x
);
911 args
->GetNext(& acceleration_including_gravity_x
);
912 args
->GetNext(&has_acceleration_including_gravity_y
);
913 args
->GetNext(& acceleration_including_gravity_y
);
914 args
->GetNext(&has_acceleration_including_gravity_z
);
915 args
->GetNext(& acceleration_including_gravity_z
);
916 args
->GetNext(&has_rotation_rate_alpha
);
917 args
->GetNext(& rotation_rate_alpha
);
918 args
->GetNext(&has_rotation_rate_beta
);
919 args
->GetNext(& rotation_rate_beta
);
920 args
->GetNext(&has_rotation_rate_gamma
);
921 args
->GetNext(& rotation_rate_gamma
);
922 args
->GetNext(& interval
);
924 runner_
->SetMockDeviceMotion(has_acceleration_x
, acceleration_x
,
925 has_acceleration_y
, acceleration_y
,
926 has_acceleration_z
, acceleration_z
,
927 has_acceleration_including_gravity_x
,
928 acceleration_including_gravity_x
,
929 has_acceleration_including_gravity_y
,
930 acceleration_including_gravity_y
,
931 has_acceleration_including_gravity_z
,
932 acceleration_including_gravity_z
,
933 has_rotation_rate_alpha
,
935 has_rotation_rate_beta
,
937 has_rotation_rate_gamma
,
942 void TestRunnerBindings::SetMockDeviceOrientation(gin::Arguments
* args
) {
946 bool has_alpha
= false;
948 bool has_beta
= false;
950 bool has_gamma
= false;
952 bool has_absolute
= false;
953 bool absolute
= false;
955 args
->GetNext(&has_alpha
);
956 args
->GetNext(&alpha
);
957 args
->GetNext(&has_beta
);
958 args
->GetNext(&beta
);
959 args
->GetNext(&has_gamma
);
960 args
->GetNext(&gamma
);
961 args
->GetNext(&has_absolute
);
962 args
->GetNext(&absolute
);
964 runner_
->SetMockDeviceOrientation(has_alpha
, alpha
,
967 has_absolute
, absolute
);
970 void TestRunnerBindings::SetMockScreenOrientation(const std::string
& orientation
) {
974 runner_
->SetMockScreenOrientation(orientation
);
977 void TestRunnerBindings::DidChangeBatteryStatus(bool charging
,
979 double dischargingTime
,
982 runner_
->DidChangeBatteryStatus(charging
, chargingTime
,
983 dischargingTime
, level
);
987 void TestRunnerBindings::ResetBatteryStatus() {
989 runner_
->ResetBatteryStatus();
992 void TestRunnerBindings::DidAcquirePointerLock() {
994 runner_
->DidAcquirePointerLock();
997 void TestRunnerBindings::DidNotAcquirePointerLock() {
999 runner_
->DidNotAcquirePointerLock();
1002 void TestRunnerBindings::DidLosePointerLock() {
1004 runner_
->DidLosePointerLock();
1007 void TestRunnerBindings::SetPointerLockWillFailSynchronously() {
1009 runner_
->SetPointerLockWillFailSynchronously();
1012 void TestRunnerBindings::SetPointerLockWillRespondAsynchronously() {
1014 runner_
->SetPointerLockWillRespondAsynchronously();
1017 void TestRunnerBindings::SetPopupBlockingEnabled(bool block_popups
) {
1019 runner_
->SetPopupBlockingEnabled(block_popups
);
1022 void TestRunnerBindings::SetJavaScriptCanAccessClipboard(bool can_access
) {
1024 runner_
->SetJavaScriptCanAccessClipboard(can_access
);
1027 void TestRunnerBindings::SetXSSAuditorEnabled(bool enabled
) {
1029 runner_
->SetXSSAuditorEnabled(enabled
);
1032 void TestRunnerBindings::SetAllowUniversalAccessFromFileURLs(bool allow
) {
1034 runner_
->SetAllowUniversalAccessFromFileURLs(allow
);
1037 void TestRunnerBindings::SetAllowFileAccessFromFileURLs(bool allow
) {
1039 runner_
->SetAllowFileAccessFromFileURLs(allow
);
1042 void TestRunnerBindings::OverridePreference(const std::string key
,
1043 v8::Local
<v8::Value
> value
) {
1045 runner_
->OverridePreference(key
, value
);
1048 void TestRunnerBindings::SetAcceptLanguages(
1049 const std::string
& accept_languages
) {
1053 runner_
->SetAcceptLanguages(accept_languages
);
1056 void TestRunnerBindings::SetPluginsEnabled(bool enabled
) {
1058 runner_
->SetPluginsEnabled(enabled
);
1061 void TestRunnerBindings::DumpEditingCallbacks() {
1063 runner_
->DumpEditingCallbacks();
1066 void TestRunnerBindings::DumpAsMarkup() {
1068 runner_
->DumpAsMarkup();
1071 void TestRunnerBindings::DumpAsText() {
1073 runner_
->DumpAsText();
1076 void TestRunnerBindings::DumpAsTextWithPixelResults() {
1078 runner_
->DumpAsTextWithPixelResults();
1081 void TestRunnerBindings::DumpChildFrameScrollPositions() {
1083 runner_
->DumpChildFrameScrollPositions();
1086 void TestRunnerBindings::DumpChildFramesAsText() {
1088 runner_
->DumpChildFramesAsText();
1091 void TestRunnerBindings::DumpChildFramesAsMarkup() {
1093 runner_
->DumpChildFramesAsMarkup();
1096 void TestRunnerBindings::DumpIconChanges() {
1098 runner_
->DumpIconChanges();
1101 void TestRunnerBindings::SetAudioData(const gin::ArrayBufferView
& view
) {
1103 runner_
->SetAudioData(view
);
1106 void TestRunnerBindings::DumpFrameLoadCallbacks() {
1108 runner_
->DumpFrameLoadCallbacks();
1111 void TestRunnerBindings::DumpPingLoaderCallbacks() {
1113 runner_
->DumpPingLoaderCallbacks();
1116 void TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks() {
1118 runner_
->DumpUserGestureInFrameLoadCallbacks();
1121 void TestRunnerBindings::DumpTitleChanges() {
1123 runner_
->DumpTitleChanges();
1126 void TestRunnerBindings::DumpCreateView() {
1128 runner_
->DumpCreateView();
1131 void TestRunnerBindings::SetCanOpenWindows() {
1133 runner_
->SetCanOpenWindows();
1136 void TestRunnerBindings::DumpResourceLoadCallbacks() {
1138 runner_
->DumpResourceLoadCallbacks();
1141 void TestRunnerBindings::DumpResourceRequestCallbacks() {
1143 runner_
->DumpResourceRequestCallbacks();
1146 void TestRunnerBindings::DumpResourceResponseMIMETypes() {
1148 runner_
->DumpResourceResponseMIMETypes();
1151 void TestRunnerBindings::SetImagesAllowed(bool allowed
) {
1153 runner_
->SetImagesAllowed(allowed
);
1156 void TestRunnerBindings::SetMediaAllowed(bool allowed
) {
1158 runner_
->SetMediaAllowed(allowed
);
1161 void TestRunnerBindings::SetScriptsAllowed(bool allowed
) {
1163 runner_
->SetScriptsAllowed(allowed
);
1166 void TestRunnerBindings::SetStorageAllowed(bool allowed
) {
1168 runner_
->SetStorageAllowed(allowed
);
1171 void TestRunnerBindings::SetPluginsAllowed(bool allowed
) {
1173 runner_
->SetPluginsAllowed(allowed
);
1176 void TestRunnerBindings::SetAllowDisplayOfInsecureContent(bool allowed
) {
1178 runner_
->SetAllowDisplayOfInsecureContent(allowed
);
1181 void TestRunnerBindings::SetAllowRunningOfInsecureContent(bool allowed
) {
1183 runner_
->SetAllowRunningOfInsecureContent(allowed
);
1186 void TestRunnerBindings::DumpPermissionClientCallbacks() {
1188 runner_
->DumpPermissionClientCallbacks();
1191 void TestRunnerBindings::DumpWindowStatusChanges() {
1193 runner_
->DumpWindowStatusChanges();
1196 void TestRunnerBindings::DumpProgressFinishedCallback() {
1198 runner_
->DumpProgressFinishedCallback();
1201 void TestRunnerBindings::DumpSpellCheckCallbacks() {
1203 runner_
->DumpSpellCheckCallbacks();
1206 void TestRunnerBindings::DumpBackForwardList() {
1208 runner_
->DumpBackForwardList();
1211 void TestRunnerBindings::DumpSelectionRect() {
1213 runner_
->DumpSelectionRect();
1216 void TestRunnerBindings::SetPrinting() {
1218 runner_
->SetPrinting();
1221 void TestRunnerBindings::ClearPrinting() {
1223 runner_
->ClearPrinting();
1226 void TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload(
1229 runner_
->SetShouldStayOnPageAfterHandlingBeforeUnload(value
);
1232 void TestRunnerBindings::SetWillSendRequestClearHeader(
1233 const std::string
& header
) {
1235 runner_
->SetWillSendRequestClearHeader(header
);
1238 void TestRunnerBindings::DumpResourceRequestPriorities() {
1240 runner_
->DumpResourceRequestPriorities();
1243 void TestRunnerBindings::SetUseMockTheme(bool use
) {
1245 runner_
->SetUseMockTheme(use
);
1248 void TestRunnerBindings::WaitUntilExternalURLLoad() {
1250 runner_
->WaitUntilExternalURLLoad();
1253 void TestRunnerBindings::DumpDragImage() {
1255 runner_
->DumpDragImage();
1258 void TestRunnerBindings::DumpNavigationPolicy() {
1260 runner_
->DumpNavigationPolicy();
1263 void TestRunnerBindings::ShowWebInspector(gin::Arguments
* args
) {
1265 std::string settings
;
1266 args
->GetNext(&settings
);
1267 std::string frontend_url
;
1268 args
->GetNext(&frontend_url
);
1269 runner_
->ShowWebInspector(settings
, frontend_url
);
1273 void TestRunnerBindings::CloseWebInspector() {
1275 runner_
->CloseWebInspector();
1278 bool TestRunnerBindings::IsChooserShown() {
1280 return runner_
->IsChooserShown();
1284 void TestRunnerBindings::EvaluateInWebInspector(int call_id
,
1285 const std::string
& script
) {
1287 runner_
->EvaluateInWebInspector(call_id
, script
);
1290 void TestRunnerBindings::ClearAllDatabases() {
1292 runner_
->ClearAllDatabases();
1295 void TestRunnerBindings::SetDatabaseQuota(int quota
) {
1297 runner_
->SetDatabaseQuota(quota
);
1300 void TestRunnerBindings::SetAlwaysAcceptCookies(bool accept
) {
1302 runner_
->SetAlwaysAcceptCookies(accept
);
1305 void TestRunnerBindings::SetWindowIsKey(bool value
) {
1307 runner_
->SetWindowIsKey(value
);
1310 std::string
TestRunnerBindings::PathToLocalResource(const std::string
& path
) {
1312 return runner_
->PathToLocalResource(path
);
1313 return std::string();
1316 void TestRunnerBindings::SetBackingScaleFactor(
1317 double value
, v8::Local
<v8::Function
> callback
) {
1319 runner_
->SetBackingScaleFactor(value
, callback
);
1322 void TestRunnerBindings::SetColorProfile(
1323 const std::string
& name
, v8::Local
<v8::Function
> callback
) {
1325 runner_
->SetColorProfile(name
, callback
);
1328 void TestRunnerBindings::SetBluetoothMockDataSet(const std::string
& name
) {
1330 runner_
->SetBluetoothMockDataSet(name
);
1333 void TestRunnerBindings::SetPOSIXLocale(const std::string
& locale
) {
1335 runner_
->SetPOSIXLocale(locale
);
1338 void TestRunnerBindings::SetMIDIAccessorResult(bool result
) {
1340 runner_
->SetMIDIAccessorResult(result
);
1343 void TestRunnerBindings::SimulateWebNotificationClick(
1344 const std::string
& title
) {
1346 runner_
->SimulateWebNotificationClick(title
);
1349 void TestRunnerBindings::AddMockSpeechRecognitionResult(
1350 const std::string
& transcript
, double confidence
) {
1352 runner_
->AddMockSpeechRecognitionResult(transcript
, confidence
);
1355 void TestRunnerBindings::SetMockSpeechRecognitionError(
1356 const std::string
& error
, const std::string
& message
) {
1358 runner_
->SetMockSpeechRecognitionError(error
, message
);
1361 bool TestRunnerBindings::WasMockSpeechRecognitionAborted() {
1363 return runner_
->WasMockSpeechRecognitionAborted();
1367 void TestRunnerBindings::AddMockCredentialManagerResponse(
1368 const std::string
& id
,
1369 const std::string
& name
,
1370 const std::string
& avatar
,
1371 const std::string
& password
) {
1373 runner_
->AddMockCredentialManagerResponse(id
, name
, avatar
, password
);
1376 void TestRunnerBindings::AddWebPageOverlay() {
1378 runner_
->AddWebPageOverlay();
1381 void TestRunnerBindings::RemoveWebPageOverlay() {
1383 runner_
->RemoveWebPageOverlay();
1386 void TestRunnerBindings::LayoutAndPaintAsync() {
1388 runner_
->LayoutAndPaintAsync();
1391 void TestRunnerBindings::LayoutAndPaintAsyncThen(
1392 v8::Local
<v8::Function
> callback
) {
1394 runner_
->LayoutAndPaintAsyncThen(callback
);
1397 void TestRunnerBindings::GetManifestThen(v8::Local
<v8::Function
> callback
) {
1399 runner_
->GetManifestThen(callback
);
1402 void TestRunnerBindings::CapturePixelsAsyncThen(
1403 v8::Local
<v8::Function
> callback
) {
1405 runner_
->CapturePixelsAsyncThen(callback
);
1408 void TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen(
1409 int x
, int y
, v8::Local
<v8::Function
> callback
) {
1411 runner_
->CopyImageAtAndCapturePixelsAsyncThen(x
, y
, callback
);
1414 void TestRunnerBindings::SetCustomTextOutput(std::string output
) {
1415 runner_
->setCustomTextOutput(output
);
1418 void TestRunnerBindings::SetViewSourceForFrame(const std::string
& name
,
1420 if (runner_
&& runner_
->web_view_
) {
1421 WebFrame
* target_frame
=
1422 runner_
->web_view_
->findFrameByName(WebString::fromUTF8(name
));
1424 target_frame
->enableViewSourceMode(enabled
);
1428 void TestRunnerBindings::SetGeofencingMockProvider(bool service_available
) {
1430 runner_
->SetGeofencingMockProvider(service_available
);
1433 void TestRunnerBindings::ClearGeofencingMockProvider() {
1435 runner_
->ClearGeofencingMockProvider();
1438 void TestRunnerBindings::SetGeofencingMockPosition(double latitude
,
1441 runner_
->SetGeofencingMockPosition(latitude
, longitude
);
1444 void TestRunnerBindings::SetPermission(const std::string
& name
,
1445 const std::string
& value
,
1446 const std::string
& origin
,
1447 const std::string
& embedding_origin
) {
1451 return runner_
->SetPermission(
1452 name
, value
, GURL(origin
), GURL(embedding_origin
));
1455 void TestRunnerBindings::DispatchBeforeInstallPromptEvent(
1457 const std::vector
<std::string
>& event_platforms
,
1458 v8::Local
<v8::Function
> callback
) {
1462 return runner_
->DispatchBeforeInstallPromptEvent(request_id
, event_platforms
,
1466 void TestRunnerBindings::ResolveBeforeInstallPromptPromise(
1468 const std::string
& platform
) {
1472 return runner_
->ResolveBeforeInstallPromptPromise(request_id
, platform
);
1475 std::string
TestRunnerBindings::PlatformName() {
1477 return runner_
->platform_name_
;
1478 return std::string();
1481 std::string
TestRunnerBindings::TooltipText() {
1483 return runner_
->tooltip_text_
;
1484 return std::string();
1487 bool TestRunnerBindings::DisableNotifyDone() {
1489 return runner_
->disable_notify_done_
;
1493 int TestRunnerBindings::WebHistoryItemCount() {
1495 return runner_
->web_history_item_count_
;
1499 bool TestRunnerBindings::InterceptPostMessage() {
1501 return runner_
->intercept_post_message_
;
1505 void TestRunnerBindings::SetInterceptPostMessage(bool value
) {
1507 runner_
->intercept_post_message_
= value
;
1510 void TestRunnerBindings::ForceNextWebGLContextCreationToFail() {
1512 runner_
->ForceNextWebGLContextCreationToFail();
1515 void TestRunnerBindings::NotImplemented(const gin::Arguments
& args
) {
1518 class TestPageOverlay
: public WebPageOverlay
{
1520 TestPageOverlay() {}
1521 virtual ~TestPageOverlay() {}
1523 virtual void paintPageOverlay(WebGraphicsContext
* context
,
1524 const WebSize
& webViewSize
) {
1525 gfx::Rect
rect(webViewSize
);
1526 SkCanvas
* canvas
= context
->beginDrawing(gfx::RectF(rect
));
1528 paint
.setColor(SK_ColorCYAN
);
1529 paint
.setStyle(SkPaint::kFill_Style
);
1530 canvas
->drawRect(gfx::RectToSkRect(rect
), paint
);
1531 context
->endDrawing();
1535 TestRunner::WorkQueue::WorkQueue(TestRunner
* controller
)
1537 , controller_(controller
) {}
1539 TestRunner::WorkQueue::~WorkQueue() {
1543 void TestRunner::WorkQueue::ProcessWorkSoon() {
1544 if (controller_
->topLoadingFrame())
1547 if (!queue_
.empty()) {
1548 // We delay processing queued work to avoid recursion problems.
1549 controller_
->delegate_
->PostTask(new WorkQueueTask(this));
1550 } else if (!controller_
->wait_until_done_
) {
1551 controller_
->delegate_
->TestFinished();
1555 void TestRunner::WorkQueue::Reset() {
1557 while (!queue_
.empty()) {
1558 delete queue_
.front();
1563 void TestRunner::WorkQueue::AddWork(WorkItem
* work
) {
1568 queue_
.push_back(work
);
1571 void TestRunner::WorkQueue::ProcessWork() {
1572 // Quit doing work once a load is in progress.
1573 while (!queue_
.empty()) {
1574 bool startedLoad
= queue_
.front()->Run(controller_
->delegate_
,
1575 controller_
->web_view_
);
1576 delete queue_
.front();
1582 if (!controller_
->wait_until_done_
&& !controller_
->topLoadingFrame())
1583 controller_
->delegate_
->TestFinished();
1586 void TestRunner::WorkQueue::WorkQueueTask::RunIfValid() {
1587 object_
->ProcessWork();
1590 TestRunner::TestRunner(TestInterfaces
* interfaces
)
1591 : test_is_running_(false),
1592 close_remaining_windows_(false),
1594 disable_notify_done_(false),
1595 web_history_item_count_(0),
1596 intercept_post_message_(false),
1597 test_interfaces_(interfaces
),
1600 page_overlay_(nullptr),
1601 web_content_settings_(new WebContentSettings()),
1602 weak_factory_(this) {}
1604 TestRunner::~TestRunner() {}
1606 void TestRunner::Install(WebFrame
* frame
) {
1607 TestRunnerBindings::Install(weak_factory_
.GetWeakPtr(), frame
);
1610 void TestRunner::SetDelegate(WebTestDelegate
* delegate
) {
1611 delegate_
= delegate
;
1612 web_content_settings_
->SetDelegate(delegate
);
1615 void TestRunner::SetWebView(WebView
* webView
, WebTestProxyBase
* proxy
) {
1616 web_view_
= webView
;
1620 void TestRunner::Reset() {
1622 web_view_
->setZoomLevel(0);
1623 web_view_
->setTextZoomFactor(1);
1624 web_view_
->setTabKeyCyclesThroughElements(true);
1625 #if !defined(__APPLE__) && !defined(WIN32) // Actually, TOOLKIT_GTK
1626 // (Constants copied because we can't depend on the header that defined
1627 // them from this file.)
1628 web_view_
->setSelectionColors(
1629 0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232);
1631 web_view_
->setVisibilityState(WebPageVisibilityStateVisible
, true);
1632 web_view_
->mainFrame()->enableViewSourceMode(false);
1634 if (page_overlay_
) {
1635 web_view_
->removePageOverlay(page_overlay_
);
1636 delete page_overlay_
;
1637 page_overlay_
= nullptr;
1641 top_loading_frame_
= nullptr;
1642 wait_until_done_
= false;
1643 wait_until_external_url_load_
= false;
1644 policy_delegate_enabled_
= false;
1645 policy_delegate_is_permissive_
= false;
1646 policy_delegate_should_notify_done_
= false;
1648 WebSecurityPolicy::resetOriginAccessWhitelists();
1649 #if defined(__linux__) || defined(ANDROID)
1650 WebFontRendering::setSubpixelPositioning(false);
1654 // Reset the default quota for each origin to 5MB
1655 delegate_
->SetDatabaseQuota(5 * 1024 * 1024);
1656 delegate_
->SetDeviceColorProfile("reset");
1657 delegate_
->SetDeviceScaleFactor(1);
1658 delegate_
->SetAcceptAllCookies(false);
1659 delegate_
->SetLocale("");
1660 delegate_
->UseUnfortunateSynchronousResizeMode(false);
1661 delegate_
->DisableAutoResizeMode(WebSize());
1662 delegate_
->DeleteAllCookies();
1663 delegate_
->ResetScreenOrientation();
1664 delegate_
->SetBluetoothMockDataSet("");
1665 delegate_
->ClearGeofencingMockProvider();
1666 delegate_
->ResetPermissions();
1667 ResetBatteryStatus();
1671 dump_editting_callbacks_
= false;
1672 dump_as_text_
= false;
1673 dump_as_markup_
= false;
1674 generate_pixel_results_
= true;
1675 dump_child_frame_scroll_positions_
= false;
1676 dump_child_frames_as_markup_
= false;
1677 dump_child_frames_as_text_
= false;
1678 dump_icon_changes_
= false;
1679 dump_as_audio_
= false;
1680 dump_frame_load_callbacks_
= false;
1681 dump_ping_loader_callbacks_
= false;
1682 dump_user_gesture_in_frame_load_callbacks_
= false;
1683 dump_title_changes_
= false;
1684 dump_create_view_
= false;
1685 can_open_windows_
= false;
1686 dump_resource_load_callbacks_
= false;
1687 dump_resource_request_callbacks_
= false;
1688 dump_resource_response_mime_types_
= false;
1689 dump_window_status_changes_
= false;
1690 dump_progress_finished_callback_
= false;
1691 dump_spell_check_callbacks_
= false;
1692 dump_back_forward_list_
= false;
1693 dump_selection_rect_
= false;
1694 dump_drag_image_
= false;
1695 dump_navigation_policy_
= false;
1696 test_repaint_
= false;
1697 sweep_horizontally_
= false;
1698 is_printing_
= false;
1699 midi_accessor_result_
= true;
1700 should_stay_on_page_after_handling_before_unload_
= false;
1701 should_dump_resource_priorities_
= false;
1702 has_custom_text_output_
= false;
1703 custom_text_output_
.clear();
1705 http_headers_to_clear_
.clear();
1707 platform_name_
= "chromium";
1708 tooltip_text_
= std::string();
1709 disable_notify_done_
= false;
1710 web_history_item_count_
= 0;
1711 intercept_post_message_
= false;
1713 web_content_settings_
->Reset();
1715 use_mock_theme_
= true;
1716 pointer_locked_
= false;
1717 pointer_lock_planned_result_
= PointerLockWillSucceed
;
1719 task_list_
.RevokeAll();
1720 work_queue_
.Reset();
1722 if (close_remaining_windows_
&& delegate_
)
1723 delegate_
->CloseRemainingWindows();
1725 close_remaining_windows_
= true;
1728 void TestRunner::SetTestIsRunning(bool running
) {
1729 test_is_running_
= running
;
1732 void TestRunner::InvokeCallback(scoped_ptr
<InvokeCallbackTask
> task
) {
1733 delegate_
->PostTask(task
.release());
1736 bool TestRunner::shouldDumpEditingCallbacks() const {
1737 return dump_editting_callbacks_
;
1740 bool TestRunner::shouldDumpAsText() {
1741 CheckResponseMimeType();
1742 return dump_as_text_
;
1745 void TestRunner::setShouldDumpAsText(bool value
) {
1746 dump_as_text_
= value
;
1749 bool TestRunner::shouldDumpAsMarkup() {
1750 return dump_as_markup_
;
1753 void TestRunner::setShouldDumpAsMarkup(bool value
) {
1754 dump_as_markup_
= value
;
1757 bool TestRunner::shouldDumpAsCustomText() const {
1758 return has_custom_text_output_
;
1761 std::string
TestRunner::customDumpText() const {
1762 return custom_text_output_
;
1765 void TestRunner::setCustomTextOutput(std::string text
) {
1766 custom_text_output_
= text
;
1767 has_custom_text_output_
= true;
1770 bool TestRunner::ShouldGeneratePixelResults() {
1771 CheckResponseMimeType();
1772 return generate_pixel_results_
;
1775 void TestRunner::setShouldGeneratePixelResults(bool value
) {
1776 generate_pixel_results_
= value
;
1779 bool TestRunner::shouldDumpChildFrameScrollPositions() const {
1780 return dump_child_frame_scroll_positions_
;
1783 bool TestRunner::shouldDumpChildFramesAsMarkup() const {
1784 return dump_child_frames_as_markup_
;
1787 bool TestRunner::shouldDumpChildFramesAsText() const {
1788 return dump_child_frames_as_text_
;
1791 bool TestRunner::ShouldDumpAsAudio() const {
1792 return dump_as_audio_
;
1795 void TestRunner::GetAudioData(std::vector
<unsigned char>* buffer_view
) const {
1796 *buffer_view
= audio_data_
;
1799 bool TestRunner::shouldDumpFrameLoadCallbacks() const {
1800 return test_is_running_
&& dump_frame_load_callbacks_
;
1803 void TestRunner::setShouldDumpFrameLoadCallbacks(bool value
) {
1804 dump_frame_load_callbacks_
= value
;
1807 bool TestRunner::shouldDumpPingLoaderCallbacks() const {
1808 return test_is_running_
&& dump_ping_loader_callbacks_
;
1811 void TestRunner::setShouldDumpPingLoaderCallbacks(bool value
) {
1812 dump_ping_loader_callbacks_
= value
;
1815 void TestRunner::setShouldEnableViewSource(bool value
) {
1816 web_view_
->mainFrame()->enableViewSourceMode(value
);
1819 bool TestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const {
1820 return test_is_running_
&& dump_user_gesture_in_frame_load_callbacks_
;
1823 bool TestRunner::shouldDumpTitleChanges() const {
1824 return dump_title_changes_
;
1827 bool TestRunner::shouldDumpIconChanges() const {
1828 return dump_icon_changes_
;
1831 bool TestRunner::shouldDumpCreateView() const {
1832 return dump_create_view_
;
1835 bool TestRunner::canOpenWindows() const {
1836 return can_open_windows_
;
1839 bool TestRunner::shouldDumpResourceLoadCallbacks() const {
1840 return test_is_running_
&& dump_resource_load_callbacks_
;
1843 bool TestRunner::shouldDumpResourceRequestCallbacks() const {
1844 return test_is_running_
&& dump_resource_request_callbacks_
;
1847 bool TestRunner::shouldDumpResourceResponseMIMETypes() const {
1848 return test_is_running_
&& dump_resource_response_mime_types_
;
1851 WebContentSettingsClient
* TestRunner::GetWebContentSettings() const {
1852 return web_content_settings_
.get();
1855 bool TestRunner::shouldDumpStatusCallbacks() const {
1856 return dump_window_status_changes_
;
1859 bool TestRunner::shouldDumpProgressFinishedCallback() const {
1860 return dump_progress_finished_callback_
;
1863 bool TestRunner::shouldDumpSpellCheckCallbacks() const {
1864 return dump_spell_check_callbacks_
;
1867 bool TestRunner::ShouldDumpBackForwardList() const {
1868 return dump_back_forward_list_
;
1871 bool TestRunner::shouldDumpSelectionRect() const {
1872 return dump_selection_rect_
;
1875 bool TestRunner::isPrinting() const {
1876 return is_printing_
;
1879 bool TestRunner::shouldStayOnPageAfterHandlingBeforeUnload() const {
1880 return should_stay_on_page_after_handling_before_unload_
;
1883 bool TestRunner::shouldWaitUntilExternalURLLoad() const {
1884 return wait_until_external_url_load_
;
1887 const std::set
<std::string
>* TestRunner::httpHeadersToClear() const {
1888 return &http_headers_to_clear_
;
1891 void TestRunner::setTopLoadingFrame(WebFrame
* frame
, bool clear
) {
1892 if (frame
->top()->view() != web_view_
)
1894 if (!test_is_running_
)
1897 top_loading_frame_
= nullptr;
1898 LocationChangeDone();
1899 } else if (!top_loading_frame_
) {
1900 top_loading_frame_
= frame
;
1904 WebFrame
* TestRunner::topLoadingFrame() const {
1905 return top_loading_frame_
;
1908 void TestRunner::policyDelegateDone() {
1909 DCHECK(wait_until_done_
);
1910 delegate_
->TestFinished();
1911 wait_until_done_
= false;
1914 bool TestRunner::policyDelegateEnabled() const {
1915 return policy_delegate_enabled_
;
1918 bool TestRunner::policyDelegateIsPermissive() const {
1919 return policy_delegate_is_permissive_
;
1922 bool TestRunner::policyDelegateShouldNotifyDone() const {
1923 return policy_delegate_should_notify_done_
;
1926 bool TestRunner::shouldInterceptPostMessage() const {
1927 return intercept_post_message_
;
1930 bool TestRunner::shouldDumpResourcePriorities() const {
1931 return should_dump_resource_priorities_
;
1934 bool TestRunner::RequestPointerLock() {
1935 switch (pointer_lock_planned_result_
) {
1936 case PointerLockWillSucceed
:
1937 delegate_
->PostDelayedTask(
1938 new HostMethodTask(this, &TestRunner::DidAcquirePointerLockInternal
),
1941 case PointerLockWillRespondAsync
:
1942 DCHECK(!pointer_locked_
);
1944 case PointerLockWillFailSync
:
1945 DCHECK(!pointer_locked_
);
1953 void TestRunner::RequestPointerUnlock() {
1954 delegate_
->PostDelayedTask(
1955 new HostMethodTask(this, &TestRunner::DidLosePointerLockInternal
), 0);
1958 bool TestRunner::isPointerLocked() {
1959 return pointer_locked_
;
1962 void TestRunner::setToolTipText(const WebString
& text
) {
1963 tooltip_text_
= text
.utf8();
1966 bool TestRunner::shouldDumpDragImage() {
1967 return dump_drag_image_
;
1970 bool TestRunner::shouldDumpNavigationPolicy() const {
1971 return dump_navigation_policy_
;
1974 bool TestRunner::midiAccessorResult() {
1975 return midi_accessor_result_
;
1978 void TestRunner::ClearDevToolsLocalStorage() {
1979 delegate_
->ClearDevToolsLocalStorage();
1982 void TestRunner::ShowDevTools(const std::string
& settings
,
1983 const std::string
& frontend_url
) {
1984 delegate_
->ShowDevTools(settings
, frontend_url
);
1987 class WorkItemBackForward
: public TestRunner::WorkItem
{
1989 WorkItemBackForward(int distance
) : distance_(distance
) {}
1991 bool Run(WebTestDelegate
* delegate
, WebView
*) override
{
1992 delegate
->GoToOffset(distance_
);
1993 return true; // FIXME: Did it really start a navigation?
2000 void TestRunner::NotifyDone() {
2001 if (disable_notify_done_
)
2004 // Test didn't timeout. Kill the timeout timer.
2005 task_list_
.RevokeAll();
2007 CompleteNotifyDone();
2010 void TestRunner::WaitUntilDone() {
2011 wait_until_done_
= true;
2014 void TestRunner::QueueBackNavigation(int how_far_back
) {
2015 work_queue_
.AddWork(new WorkItemBackForward(-how_far_back
));
2018 void TestRunner::QueueForwardNavigation(int how_far_forward
) {
2019 work_queue_
.AddWork(new WorkItemBackForward(how_far_forward
));
2022 class WorkItemReload
: public TestRunner::WorkItem
{
2024 bool Run(WebTestDelegate
* delegate
, WebView
*) override
{
2030 void TestRunner::QueueReload() {
2031 work_queue_
.AddWork(new WorkItemReload());
2034 class WorkItemLoadingScript
: public TestRunner::WorkItem
{
2036 WorkItemLoadingScript(const std::string
& script
)
2037 : script_(script
) {}
2039 bool Run(WebTestDelegate
*, WebView
* web_view
) override
{
2040 web_view
->mainFrame()->executeScript(
2041 WebScriptSource(WebString::fromUTF8(script_
)));
2042 return true; // FIXME: Did it really start a navigation?
2046 std::string script_
;
2049 void TestRunner::QueueLoadingScript(const std::string
& script
) {
2050 work_queue_
.AddWork(new WorkItemLoadingScript(script
));
2053 class WorkItemNonLoadingScript
: public TestRunner::WorkItem
{
2055 WorkItemNonLoadingScript(const std::string
& script
)
2056 : script_(script
) {}
2058 bool Run(WebTestDelegate
*, WebView
* web_view
) override
{
2059 web_view
->mainFrame()->executeScript(
2060 WebScriptSource(WebString::fromUTF8(script_
)));
2065 std::string script_
;
2068 void TestRunner::QueueNonLoadingScript(const std::string
& script
) {
2069 work_queue_
.AddWork(new WorkItemNonLoadingScript(script
));
2072 class WorkItemLoad
: public TestRunner::WorkItem
{
2074 WorkItemLoad(const WebURL
& url
, const std::string
& target
)
2075 : url_(url
), target_(target
) {}
2077 bool Run(WebTestDelegate
* delegate
, WebView
*) override
{
2078 delegate
->LoadURLForFrame(url_
, target_
);
2079 return true; // FIXME: Did it really start a navigation?
2084 std::string target_
;
2087 void TestRunner::QueueLoad(const std::string
& url
, const std::string
& target
) {
2088 // FIXME: Implement WebURL::resolve() and avoid GURL.
2089 GURL current_url
= web_view_
->mainFrame()->document().url();
2090 GURL full_url
= current_url
.Resolve(url
);
2091 work_queue_
.AddWork(new WorkItemLoad(full_url
, target
));
2094 class WorkItemLoadHTMLString
: public TestRunner::WorkItem
{
2096 WorkItemLoadHTMLString(const std::string
& html
, const WebURL
& base_url
)
2097 : html_(html
), base_url_(base_url
) {}
2099 WorkItemLoadHTMLString(const std::string
& html
, const WebURL
& base_url
,
2100 const WebURL
& unreachable_url
)
2101 : html_(html
), base_url_(base_url
), unreachable_url_(unreachable_url
) {}
2103 bool Run(WebTestDelegate
*, WebView
* web_view
) override
{
2104 web_view
->mainFrame()->loadHTMLString(
2105 WebData(html_
.data(), html_
.length()),
2106 base_url_
, unreachable_url_
);
2113 WebURL unreachable_url_
;
2116 void TestRunner::QueueLoadHTMLString(gin::Arguments
* args
) {
2118 args
->GetNext(&html
);
2120 std::string base_url_str
;
2121 args
->GetNext(&base_url_str
);
2122 WebURL base_url
= WebURL(GURL(base_url_str
));
2124 if (args
->PeekNext()->IsString()) {
2125 std::string unreachable_url_str
;
2126 args
->GetNext(&unreachable_url_str
);
2127 WebURL unreachable_url
= WebURL(GURL(unreachable_url_str
));
2128 work_queue_
.AddWork(new WorkItemLoadHTMLString(html
, base_url
,
2131 work_queue_
.AddWork(new WorkItemLoadHTMLString(html
, base_url
));
2135 void TestRunner::SetCustomPolicyDelegate(gin::Arguments
* args
) {
2136 args
->GetNext(&policy_delegate_enabled_
);
2137 if (!args
->PeekNext().IsEmpty() && args
->PeekNext()->IsBoolean())
2138 args
->GetNext(&policy_delegate_is_permissive_
);
2141 void TestRunner::WaitForPolicyDelegate() {
2142 policy_delegate_enabled_
= true;
2143 policy_delegate_should_notify_done_
= true;
2144 wait_until_done_
= true;
2147 int TestRunner::WindowCount() {
2148 return test_interfaces_
->GetWindowList().size();
2151 void TestRunner::SetCloseRemainingWindowsWhenComplete(
2152 bool close_remaining_windows
) {
2153 close_remaining_windows_
= close_remaining_windows
;
2156 void TestRunner::ResetTestHelperControllers() {
2157 test_interfaces_
->ResetTestHelperControllers();
2160 void TestRunner::SetTabKeyCyclesThroughElements(
2161 bool tab_key_cycles_through_elements
) {
2162 web_view_
->setTabKeyCyclesThroughElements(tab_key_cycles_through_elements
);
2165 void TestRunner::ExecCommand(gin::Arguments
* args
) {
2166 std::string command
;
2167 args
->GetNext(&command
);
2170 if (args
->Length() >= 3) {
2171 // Ignore the second parameter (which is userInterface)
2172 // since this command emulates a manual action.
2174 args
->GetNext(&value
);
2177 // Note: webkit's version does not return the boolean, so neither do we.
2178 web_view_
->focusedFrame()->executeCommand(WebString::fromUTF8(command
),
2179 WebString::fromUTF8(value
));
2182 bool TestRunner::IsCommandEnabled(const std::string
& command
) {
2183 return web_view_
->focusedFrame()->isCommandEnabled(
2184 WebString::fromUTF8(command
));
2187 bool TestRunner::CallShouldCloseOnWebView() {
2188 return web_view_
->mainFrame()->dispatchBeforeUnloadEvent();
2191 void TestRunner::SetDomainRelaxationForbiddenForURLScheme(
2192 bool forbidden
, const std::string
& scheme
) {
2193 web_view_
->setDomainRelaxationForbidden(forbidden
,
2194 WebString::fromUTF8(scheme
));
2197 v8::Local
<v8::Value
> TestRunner::EvaluateScriptInIsolatedWorldAndReturnValue(
2199 const std::string
& script
) {
2200 WebVector
<v8::Local
<v8::Value
>> values
;
2201 WebScriptSource
source(WebString::fromUTF8(script
));
2202 // This relies on the iframe focusing itself when it loads. This is a bit
2203 // sketchy, but it seems to be what other tests do.
2204 web_view_
->focusedFrame()->executeScriptInIsolatedWorld(
2205 world_id
, &source
, 1, 1, &values
);
2206 // Since only one script was added, only one result is expected
2207 if (values
.size() == 1 && !values
[0].IsEmpty())
2209 return v8::Local
<v8::Value
>();
2212 void TestRunner::EvaluateScriptInIsolatedWorld(int world_id
,
2213 const std::string
& script
) {
2214 WebScriptSource
source(WebString::fromUTF8(script
));
2215 web_view_
->focusedFrame()->executeScriptInIsolatedWorld(
2216 world_id
, &source
, 1, 1);
2219 void TestRunner::SetIsolatedWorldSecurityOrigin(int world_id
,
2220 v8::Local
<v8::Value
> origin
) {
2221 if (!(origin
->IsString() || !origin
->IsNull()))
2224 WebSecurityOrigin web_origin
;
2225 if (origin
->IsString()) {
2226 web_origin
= WebSecurityOrigin::createFromString(
2227 V8StringToWebString(origin
.As
<v8::String
>()));
2229 web_view_
->focusedFrame()->setIsolatedWorldSecurityOrigin(world_id
,
2233 void TestRunner::SetIsolatedWorldContentSecurityPolicy(
2235 const std::string
& policy
) {
2236 web_view_
->focusedFrame()->setIsolatedWorldContentSecurityPolicy(
2237 world_id
, WebString::fromUTF8(policy
));
2240 void TestRunner::AddOriginAccessWhitelistEntry(
2241 const std::string
& source_origin
,
2242 const std::string
& destination_protocol
,
2243 const std::string
& destination_host
,
2244 bool allow_destination_subdomains
) {
2245 WebURL
url((GURL(source_origin
)));
2249 WebSecurityPolicy::addOriginAccessWhitelistEntry(
2251 WebString::fromUTF8(destination_protocol
),
2252 WebString::fromUTF8(destination_host
),
2253 allow_destination_subdomains
);
2256 void TestRunner::RemoveOriginAccessWhitelistEntry(
2257 const std::string
& source_origin
,
2258 const std::string
& destination_protocol
,
2259 const std::string
& destination_host
,
2260 bool allow_destination_subdomains
) {
2261 WebURL
url((GURL(source_origin
)));
2265 WebSecurityPolicy::removeOriginAccessWhitelistEntry(
2267 WebString::fromUTF8(destination_protocol
),
2268 WebString::fromUTF8(destination_host
),
2269 allow_destination_subdomains
);
2272 bool TestRunner::HasCustomPageSizeStyle(int page_index
) {
2273 WebFrame
* frame
= web_view_
->mainFrame();
2276 return frame
->hasCustomPageSizeStyle(page_index
);
2279 void TestRunner::ForceRedSelectionColors() {
2280 web_view_
->setSelectionColors(0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0);
2283 void TestRunner::InsertStyleSheet(const std::string
& source_code
) {
2284 WebLocalFrame::frameForCurrentContext()->document().insertStyleSheet(
2285 WebString::fromUTF8(source_code
));
2288 bool TestRunner::FindString(const std::string
& search_text
,
2289 const std::vector
<std::string
>& options_array
) {
2290 WebFindOptions find_options
;
2291 bool wrap_around
= false;
2292 find_options
.matchCase
= true;
2293 find_options
.findNext
= true;
2295 for (const std::string
& option
: options_array
) {
2296 if (option
== "CaseInsensitive")
2297 find_options
.matchCase
= false;
2298 else if (option
== "Backwards")
2299 find_options
.forward
= false;
2300 else if (option
== "StartInSelection")
2301 find_options
.findNext
= false;
2302 else if (option
== "AtWordStarts")
2303 find_options
.wordStart
= true;
2304 else if (option
== "TreatMedialCapitalAsWordStart")
2305 find_options
.medialCapitalAsWordStart
= true;
2306 else if (option
== "WrapAround")
2310 WebFrame
* frame
= web_view_
->mainFrame();
2311 const bool find_result
= frame
->find(0, WebString::fromUTF8(search_text
),
2312 find_options
, wrap_around
, 0);
2313 frame
->stopFinding(false);
2317 std::string
TestRunner::SelectionAsMarkup() {
2318 return web_view_
->mainFrame()->selectionAsMarkup().utf8();
2321 void TestRunner::SetTextSubpixelPositioning(bool value
) {
2322 #if defined(__linux__) || defined(ANDROID)
2323 // Since FontConfig doesn't provide a variable to control subpixel
2324 // positioning, we'll fall back to setting it globally for all fonts.
2325 WebFontRendering::setSubpixelPositioning(value
);
2329 void TestRunner::SetPageVisibility(const std::string
& new_visibility
) {
2330 if (new_visibility
== "visible")
2331 web_view_
->setVisibilityState(WebPageVisibilityStateVisible
, false);
2332 else if (new_visibility
== "hidden")
2333 web_view_
->setVisibilityState(WebPageVisibilityStateHidden
, false);
2334 else if (new_visibility
== "prerender")
2335 web_view_
->setVisibilityState(WebPageVisibilityStatePrerender
, false);
2338 void TestRunner::SetTextDirection(const std::string
& direction_name
) {
2339 // Map a direction name to a WebTextDirection value.
2340 WebTextDirection direction
;
2341 if (direction_name
== "auto")
2342 direction
= WebTextDirectionDefault
;
2343 else if (direction_name
== "rtl")
2344 direction
= WebTextDirectionRightToLeft
;
2345 else if (direction_name
== "ltr")
2346 direction
= WebTextDirectionLeftToRight
;
2350 web_view_
->setTextDirection(direction
);
2353 void TestRunner::UseUnfortunateSynchronousResizeMode() {
2354 delegate_
->UseUnfortunateSynchronousResizeMode(true);
2357 bool TestRunner::EnableAutoResizeMode(int min_width
,
2361 WebSize
min_size(min_width
, min_height
);
2362 WebSize
max_size(max_width
, max_height
);
2363 delegate_
->EnableAutoResizeMode(min_size
, max_size
);
2367 bool TestRunner::DisableAutoResizeMode(int new_width
, int new_height
) {
2368 WebSize
new_size(new_width
, new_height
);
2369 delegate_
->DisableAutoResizeMode(new_size
);
2373 void TestRunner::SetMockDeviceLight(double value
) {
2374 delegate_
->SetDeviceLightData(value
);
2377 void TestRunner::ResetDeviceLight() {
2378 delegate_
->SetDeviceLightData(-1);
2381 void TestRunner::SetMockDeviceMotion(
2382 bool has_acceleration_x
, double acceleration_x
,
2383 bool has_acceleration_y
, double acceleration_y
,
2384 bool has_acceleration_z
, double acceleration_z
,
2385 bool has_acceleration_including_gravity_x
,
2386 double acceleration_including_gravity_x
,
2387 bool has_acceleration_including_gravity_y
,
2388 double acceleration_including_gravity_y
,
2389 bool has_acceleration_including_gravity_z
,
2390 double acceleration_including_gravity_z
,
2391 bool has_rotation_rate_alpha
, double rotation_rate_alpha
,
2392 bool has_rotation_rate_beta
, double rotation_rate_beta
,
2393 bool has_rotation_rate_gamma
, double rotation_rate_gamma
,
2395 WebDeviceMotionData motion
;
2398 motion
.hasAccelerationX
= has_acceleration_x
;
2399 motion
.accelerationX
= acceleration_x
;
2400 motion
.hasAccelerationY
= has_acceleration_y
;
2401 motion
.accelerationY
= acceleration_y
;
2402 motion
.hasAccelerationZ
= has_acceleration_z
;
2403 motion
.accelerationZ
= acceleration_z
;
2405 // accelerationIncludingGravity
2406 motion
.hasAccelerationIncludingGravityX
=
2407 has_acceleration_including_gravity_x
;
2408 motion
.accelerationIncludingGravityX
= acceleration_including_gravity_x
;
2409 motion
.hasAccelerationIncludingGravityY
=
2410 has_acceleration_including_gravity_y
;
2411 motion
.accelerationIncludingGravityY
= acceleration_including_gravity_y
;
2412 motion
.hasAccelerationIncludingGravityZ
=
2413 has_acceleration_including_gravity_z
;
2414 motion
.accelerationIncludingGravityZ
= acceleration_including_gravity_z
;
2417 motion
.hasRotationRateAlpha
= has_rotation_rate_alpha
;
2418 motion
.rotationRateAlpha
= rotation_rate_alpha
;
2419 motion
.hasRotationRateBeta
= has_rotation_rate_beta
;
2420 motion
.rotationRateBeta
= rotation_rate_beta
;
2421 motion
.hasRotationRateGamma
= has_rotation_rate_gamma
;
2422 motion
.rotationRateGamma
= rotation_rate_gamma
;
2425 motion
.interval
= interval
;
2427 delegate_
->SetDeviceMotionData(motion
);
2430 void TestRunner::SetMockDeviceOrientation(bool has_alpha
, double alpha
,
2431 bool has_beta
, double beta
,
2432 bool has_gamma
, double gamma
,
2433 bool has_absolute
, bool absolute
) {
2434 WebDeviceOrientationData orientation
;
2437 orientation
.hasAlpha
= has_alpha
;
2438 orientation
.alpha
= alpha
;
2441 orientation
.hasBeta
= has_beta
;
2442 orientation
.beta
= beta
;
2445 orientation
.hasGamma
= has_gamma
;
2446 orientation
.gamma
= gamma
;
2449 orientation
.hasAbsolute
= has_absolute
;
2450 orientation
.absolute
= absolute
;
2452 delegate_
->SetDeviceOrientationData(orientation
);
2455 void TestRunner::SetMockScreenOrientation(const std::string
& orientation_str
) {
2456 blink::WebScreenOrientationType orientation
;
2458 if (orientation_str
== "portrait-primary") {
2459 orientation
= WebScreenOrientationPortraitPrimary
;
2460 } else if (orientation_str
== "portrait-secondary") {
2461 orientation
= WebScreenOrientationPortraitSecondary
;
2462 } else if (orientation_str
== "landscape-primary") {
2463 orientation
= WebScreenOrientationLandscapePrimary
;
2464 } else if (orientation_str
== "landscape-secondary") {
2465 orientation
= WebScreenOrientationLandscapeSecondary
;
2468 delegate_
->SetScreenOrientation(orientation
);
2471 void TestRunner::DidChangeBatteryStatus(bool charging
,
2472 double chargingTime
,
2473 double dischargingTime
,
2475 blink::WebBatteryStatus status
;
2476 status
.charging
= charging
;
2477 status
.chargingTime
= chargingTime
;
2478 status
.dischargingTime
= dischargingTime
;
2479 status
.level
= level
;
2480 delegate_
->DidChangeBatteryStatus(status
);
2483 void TestRunner::ResetBatteryStatus() {
2484 blink::WebBatteryStatus status
;
2485 delegate_
->DidChangeBatteryStatus(status
);
2488 void TestRunner::DidAcquirePointerLock() {
2489 DidAcquirePointerLockInternal();
2492 void TestRunner::DidNotAcquirePointerLock() {
2493 DidNotAcquirePointerLockInternal();
2496 void TestRunner::DidLosePointerLock() {
2497 DidLosePointerLockInternal();
2500 void TestRunner::SetPointerLockWillFailSynchronously() {
2501 pointer_lock_planned_result_
= PointerLockWillFailSync
;
2504 void TestRunner::SetPointerLockWillRespondAsynchronously() {
2505 pointer_lock_planned_result_
= PointerLockWillRespondAsync
;
2508 void TestRunner::SetPopupBlockingEnabled(bool block_popups
) {
2509 delegate_
->Preferences()->java_script_can_open_windows_automatically
=
2511 delegate_
->ApplyPreferences();
2514 void TestRunner::SetJavaScriptCanAccessClipboard(bool can_access
) {
2515 delegate_
->Preferences()->java_script_can_access_clipboard
= can_access
;
2516 delegate_
->ApplyPreferences();
2519 void TestRunner::SetXSSAuditorEnabled(bool enabled
) {
2520 delegate_
->Preferences()->xss_auditor_enabled
= enabled
;
2521 delegate_
->ApplyPreferences();
2524 void TestRunner::SetAllowUniversalAccessFromFileURLs(bool allow
) {
2525 delegate_
->Preferences()->allow_universal_access_from_file_urls
= allow
;
2526 delegate_
->ApplyPreferences();
2529 void TestRunner::SetAllowFileAccessFromFileURLs(bool allow
) {
2530 delegate_
->Preferences()->allow_file_access_from_file_urls
= allow
;
2531 delegate_
->ApplyPreferences();
2534 void TestRunner::OverridePreference(const std::string key
,
2535 v8::Local
<v8::Value
> value
) {
2536 TestPreferences
* prefs
= delegate_
->Preferences();
2537 if (key
== "WebKitDefaultFontSize") {
2538 prefs
->default_font_size
= value
->Int32Value();
2539 } else if (key
== "WebKitMinimumFontSize") {
2540 prefs
->minimum_font_size
= value
->Int32Value();
2541 } else if (key
== "WebKitDefaultTextEncodingName") {
2542 v8::Isolate
* isolate
= blink::mainThreadIsolate();
2543 prefs
->default_text_encoding_name
=
2544 V8StringToWebString(value
->ToString(isolate
));
2545 } else if (key
== "WebKitJavaScriptEnabled") {
2546 prefs
->java_script_enabled
= value
->BooleanValue();
2547 } else if (key
== "WebKitSupportsMultipleWindows") {
2548 prefs
->supports_multiple_windows
= value
->BooleanValue();
2549 } else if (key
== "WebKitDisplayImagesKey") {
2550 prefs
->loads_images_automatically
= value
->BooleanValue();
2551 } else if (key
== "WebKitPluginsEnabled") {
2552 prefs
->plugins_enabled
= value
->BooleanValue();
2553 } else if (key
== "WebKitJavaEnabled") {
2554 prefs
->java_enabled
= value
->BooleanValue();
2555 } else if (key
== "WebKitOfflineWebApplicationCacheEnabled") {
2556 prefs
->offline_web_application_cache_enabled
= value
->BooleanValue();
2557 } else if (key
== "WebKitTabToLinksPreferenceKey") {
2558 prefs
->tabs_to_links
= value
->BooleanValue();
2559 } else if (key
== "WebKitWebGLEnabled") {
2560 prefs
->experimental_webgl_enabled
= value
->BooleanValue();
2561 } else if (key
== "WebKitCSSRegionsEnabled") {
2562 prefs
->experimental_css_regions_enabled
= value
->BooleanValue();
2563 } else if (key
== "WebKitCSSGridLayoutEnabled") {
2564 prefs
->experimental_css_grid_layout_enabled
= value
->BooleanValue();
2565 } else if (key
== "WebKitHyperlinkAuditingEnabled") {
2566 prefs
->hyperlink_auditing_enabled
= value
->BooleanValue();
2567 } else if (key
== "WebKitEnableCaretBrowsing") {
2568 prefs
->caret_browsing_enabled
= value
->BooleanValue();
2569 } else if (key
== "WebKitAllowDisplayingInsecureContent") {
2570 prefs
->allow_display_of_insecure_content
= value
->BooleanValue();
2571 } else if (key
== "WebKitAllowRunningInsecureContent") {
2572 prefs
->allow_running_of_insecure_content
= value
->BooleanValue();
2573 } else if (key
== "WebKitDisableReadingFromCanvas") {
2574 prefs
->disable_reading_from_canvas
= value
->BooleanValue();
2575 } else if (key
== "WebKitStrictMixedContentChecking") {
2576 prefs
->strict_mixed_content_checking
= value
->BooleanValue();
2577 } else if (key
== "WebKitStrictPowerfulFeatureRestrictions") {
2578 prefs
->strict_powerful_feature_restrictions
= value
->BooleanValue();
2579 } else if (key
== "WebKitShouldRespectImageOrientation") {
2580 prefs
->should_respect_image_orientation
= value
->BooleanValue();
2581 } else if (key
== "WebKitWebAudioEnabled") {
2582 DCHECK(value
->BooleanValue());
2583 } else if (key
== "WebKitWebSecurityEnabled") {
2584 prefs
->web_security_enabled
= value
->BooleanValue();
2586 std::string
message("Invalid name for preference: ");
2587 message
.append(key
);
2588 delegate_
->PrintMessage(std::string("CONSOLE MESSAGE: ") + message
+ "\n");
2590 delegate_
->ApplyPreferences();
2593 void TestRunner::SetAcceptLanguages(const std::string
& accept_languages
) {
2594 proxy_
->SetAcceptLanguages(accept_languages
);
2597 void TestRunner::SetPluginsEnabled(bool enabled
) {
2598 delegate_
->Preferences()->plugins_enabled
= enabled
;
2599 delegate_
->ApplyPreferences();
2602 void TestRunner::DumpEditingCallbacks() {
2603 dump_editting_callbacks_
= true;
2606 void TestRunner::DumpAsMarkup() {
2607 dump_as_markup_
= true;
2608 generate_pixel_results_
= false;
2611 void TestRunner::DumpAsText() {
2612 dump_as_text_
= true;
2613 generate_pixel_results_
= false;
2616 void TestRunner::DumpAsTextWithPixelResults() {
2617 dump_as_text_
= true;
2618 generate_pixel_results_
= true;
2621 void TestRunner::DumpChildFrameScrollPositions() {
2622 dump_child_frame_scroll_positions_
= true;
2625 void TestRunner::DumpChildFramesAsMarkup() {
2626 dump_child_frames_as_markup_
= true;
2629 void TestRunner::DumpChildFramesAsText() {
2630 dump_child_frames_as_text_
= true;
2633 void TestRunner::DumpIconChanges() {
2634 dump_icon_changes_
= true;
2637 void TestRunner::SetAudioData(const gin::ArrayBufferView
& view
) {
2638 unsigned char* bytes
= static_cast<unsigned char*>(view
.bytes());
2639 audio_data_
.resize(view
.num_bytes());
2640 std::copy(bytes
, bytes
+ view
.num_bytes(), audio_data_
.begin());
2641 dump_as_audio_
= true;
2644 void TestRunner::DumpFrameLoadCallbacks() {
2645 dump_frame_load_callbacks_
= true;
2648 void TestRunner::DumpPingLoaderCallbacks() {
2649 dump_ping_loader_callbacks_
= true;
2652 void TestRunner::DumpUserGestureInFrameLoadCallbacks() {
2653 dump_user_gesture_in_frame_load_callbacks_
= true;
2656 void TestRunner::DumpTitleChanges() {
2657 dump_title_changes_
= true;
2660 void TestRunner::DumpCreateView() {
2661 dump_create_view_
= true;
2664 void TestRunner::SetCanOpenWindows() {
2665 can_open_windows_
= true;
2668 void TestRunner::DumpResourceLoadCallbacks() {
2669 dump_resource_load_callbacks_
= true;
2672 void TestRunner::DumpResourceRequestCallbacks() {
2673 dump_resource_request_callbacks_
= true;
2676 void TestRunner::DumpResourceResponseMIMETypes() {
2677 dump_resource_response_mime_types_
= true;
2680 void TestRunner::SetImagesAllowed(bool allowed
) {
2681 web_content_settings_
->SetImagesAllowed(allowed
);
2684 void TestRunner::SetMediaAllowed(bool allowed
) {
2685 web_content_settings_
->SetMediaAllowed(allowed
);
2688 void TestRunner::SetScriptsAllowed(bool allowed
) {
2689 web_content_settings_
->SetScriptsAllowed(allowed
);
2692 void TestRunner::SetStorageAllowed(bool allowed
) {
2693 web_content_settings_
->SetStorageAllowed(allowed
);
2696 void TestRunner::SetPluginsAllowed(bool allowed
) {
2697 web_content_settings_
->SetPluginsAllowed(allowed
);
2700 void TestRunner::SetAllowDisplayOfInsecureContent(bool allowed
) {
2701 web_content_settings_
->SetDisplayingInsecureContentAllowed(allowed
);
2704 void TestRunner::SetAllowRunningOfInsecureContent(bool allowed
) {
2705 web_content_settings_
->SetRunningInsecureContentAllowed(allowed
);
2708 void TestRunner::DumpPermissionClientCallbacks() {
2709 web_content_settings_
->SetDumpCallbacks(true);
2712 void TestRunner::DumpWindowStatusChanges() {
2713 dump_window_status_changes_
= true;
2716 void TestRunner::DumpProgressFinishedCallback() {
2717 dump_progress_finished_callback_
= true;
2720 void TestRunner::DumpSpellCheckCallbacks() {
2721 dump_spell_check_callbacks_
= true;
2724 void TestRunner::DumpBackForwardList() {
2725 dump_back_forward_list_
= true;
2728 void TestRunner::DumpSelectionRect() {
2729 dump_selection_rect_
= true;
2732 void TestRunner::SetPrinting() {
2733 is_printing_
= true;
2736 void TestRunner::ClearPrinting() {
2737 is_printing_
= false;
2740 void TestRunner::SetShouldStayOnPageAfterHandlingBeforeUnload(bool value
) {
2741 should_stay_on_page_after_handling_before_unload_
= value
;
2744 void TestRunner::SetWillSendRequestClearHeader(const std::string
& header
) {
2745 if (!header
.empty())
2746 http_headers_to_clear_
.insert(header
);
2749 void TestRunner::DumpResourceRequestPriorities() {
2750 should_dump_resource_priorities_
= true;
2753 void TestRunner::SetUseMockTheme(bool use
) {
2754 use_mock_theme_
= use
;
2757 void TestRunner::ShowWebInspector(const std::string
& str
,
2758 const std::string
& frontend_url
) {
2759 ShowDevTools(str
, frontend_url
);
2762 void TestRunner::WaitUntilExternalURLLoad() {
2763 wait_until_external_url_load_
= true;
2766 void TestRunner::DumpDragImage() {
2767 DumpAsTextWithPixelResults();
2768 dump_drag_image_
= true;
2771 void TestRunner::DumpNavigationPolicy() {
2772 dump_navigation_policy_
= true;
2775 void TestRunner::CloseWebInspector() {
2776 delegate_
->CloseDevTools();
2779 bool TestRunner::IsChooserShown() {
2780 return proxy_
->IsChooserShown();
2783 void TestRunner::EvaluateInWebInspector(int call_id
,
2784 const std::string
& script
) {
2785 delegate_
->EvaluateInWebInspector(call_id
, script
);
2788 void TestRunner::ClearAllDatabases() {
2789 delegate_
->ClearAllDatabases();
2792 void TestRunner::SetDatabaseQuota(int quota
) {
2793 delegate_
->SetDatabaseQuota(quota
);
2796 void TestRunner::SetAlwaysAcceptCookies(bool accept
) {
2797 delegate_
->SetAcceptAllCookies(accept
);
2800 void TestRunner::SetWindowIsKey(bool value
) {
2801 delegate_
->SetFocus(proxy_
, value
);
2804 std::string
TestRunner::PathToLocalResource(const std::string
& path
) {
2805 return delegate_
->PathToLocalResource(path
);
2808 void TestRunner::SetBackingScaleFactor(double value
,
2809 v8::Local
<v8::Function
> callback
) {
2810 delegate_
->SetDeviceScaleFactor(value
);
2811 delegate_
->PostTask(new InvokeCallbackTask(this, callback
));
2814 void TestRunner::SetColorProfile(const std::string
& name
,
2815 v8::Local
<v8::Function
> callback
) {
2816 delegate_
->SetDeviceColorProfile(name
);
2817 delegate_
->PostTask(new InvokeCallbackTask(this, callback
));
2820 void TestRunner::SetBluetoothMockDataSet(const std::string
& name
) {
2821 delegate_
->SetBluetoothMockDataSet(name
);
2824 void TestRunner::SetGeofencingMockProvider(bool service_available
) {
2825 delegate_
->SetGeofencingMockProvider(service_available
);
2828 void TestRunner::ClearGeofencingMockProvider() {
2829 delegate_
->ClearGeofencingMockProvider();
2832 void TestRunner::SetGeofencingMockPosition(double latitude
, double longitude
) {
2833 delegate_
->SetGeofencingMockPosition(latitude
, longitude
);
2836 void TestRunner::SetPermission(const std::string
& name
,
2837 const std::string
& value
,
2839 const GURL
& embedding_origin
) {
2840 delegate_
->SetPermission(name
, value
, origin
, embedding_origin
);
2843 void TestRunner::DispatchBeforeInstallPromptEvent(
2845 const std::vector
<std::string
>& event_platforms
,
2846 v8::Local
<v8::Function
> callback
) {
2847 scoped_ptr
<InvokeCallbackTask
> task(
2848 new InvokeCallbackTask(this, callback
));
2850 delegate_
->DispatchBeforeInstallPromptEvent(
2851 request_id
, event_platforms
,
2852 base::Bind(&TestRunner::DispatchBeforeInstallPromptCallback
,
2853 weak_factory_
.GetWeakPtr(), base::Passed(&task
)));
2856 void TestRunner::ResolveBeforeInstallPromptPromise(
2858 const std::string
& platform
) {
2859 delegate_
->ResolveBeforeInstallPromptPromise(request_id
, platform
);
2862 void TestRunner::SetPOSIXLocale(const std::string
& locale
) {
2863 delegate_
->SetLocale(locale
);
2866 void TestRunner::SetMIDIAccessorResult(bool result
) {
2867 midi_accessor_result_
= result
;
2870 void TestRunner::SimulateWebNotificationClick(const std::string
& title
) {
2871 delegate_
->SimulateWebNotificationClick(title
);
2874 void TestRunner::AddMockSpeechRecognitionResult(const std::string
& transcript
,
2875 double confidence
) {
2876 proxy_
->GetSpeechRecognizerMock()->AddMockResult(
2877 WebString::fromUTF8(transcript
), confidence
);
2880 void TestRunner::SetMockSpeechRecognitionError(const std::string
& error
,
2881 const std::string
& message
) {
2882 proxy_
->GetSpeechRecognizerMock()->SetError(WebString::fromUTF8(error
),
2883 WebString::fromUTF8(message
));
2886 bool TestRunner::WasMockSpeechRecognitionAborted() {
2887 return proxy_
->GetSpeechRecognizerMock()->WasAborted();
2890 void TestRunner::AddMockCredentialManagerResponse(const std::string
& id
,
2891 const std::string
& name
,
2892 const std::string
& avatar
,
2893 const std::string
& password
) {
2894 proxy_
->GetCredentialManagerClientMock()->SetResponse(
2895 new WebLocalCredential(WebString::fromUTF8(id
),
2896 WebString::fromUTF8(name
),
2897 WebURL(GURL(avatar
)),
2898 WebString::fromUTF8(password
)));
2901 void TestRunner::AddWebPageOverlay() {
2902 if (web_view_
&& !page_overlay_
) {
2903 page_overlay_
= new TestPageOverlay
;
2904 web_view_
->addPageOverlay(page_overlay_
, 0);
2908 void TestRunner::RemoveWebPageOverlay() {
2909 if (web_view_
&& page_overlay_
) {
2910 web_view_
->removePageOverlay(page_overlay_
);
2911 delete page_overlay_
;
2912 page_overlay_
= nullptr;
2916 void TestRunner::LayoutAndPaintAsync() {
2917 proxy_
->LayoutAndPaintAsyncThen(base::Closure());
2920 void TestRunner::LayoutAndPaintAsyncThen(v8::Local
<v8::Function
> callback
) {
2921 scoped_ptr
<InvokeCallbackTask
> task(
2922 new InvokeCallbackTask(this, callback
));
2923 proxy_
->LayoutAndPaintAsyncThen(base::Bind(&TestRunner::InvokeCallback
,
2924 weak_factory_
.GetWeakPtr(),
2925 base::Passed(&task
)));
2928 void TestRunner::GetManifestThen(v8::Local
<v8::Function
> callback
) {
2929 scoped_ptr
<InvokeCallbackTask
> task(
2930 new InvokeCallbackTask(this, callback
));
2932 delegate_
->FetchManifest(
2933 web_view_
, web_view_
->mainFrame()->document().manifestURL(),
2934 base::Bind(&TestRunner::GetManifestCallback
, weak_factory_
.GetWeakPtr(),
2935 base::Passed(&task
)));
2938 void TestRunner::CapturePixelsAsyncThen(v8::Local
<v8::Function
> callback
) {
2939 scoped_ptr
<InvokeCallbackTask
> task(
2940 new InvokeCallbackTask(this, callback
));
2941 proxy_
->CapturePixelsAsync(base::Bind(&TestRunner::CapturePixelsCallback
,
2942 weak_factory_
.GetWeakPtr(),
2943 base::Passed(&task
)));
2946 void TestRunner::ForceNextWebGLContextCreationToFail() {
2948 web_view_
->forceNextWebGLContextCreationToFail();
2951 void TestRunner::CopyImageAtAndCapturePixelsAsyncThen(
2952 int x
, int y
, v8::Local
<v8::Function
> callback
) {
2953 scoped_ptr
<InvokeCallbackTask
> task(
2954 new InvokeCallbackTask(this, callback
));
2955 proxy_
->CopyImageAtAndCapturePixels(
2956 x
, y
, base::Bind(&TestRunner::CapturePixelsCallback
,
2957 weak_factory_
.GetWeakPtr(),
2958 base::Passed(&task
)));
2961 void TestRunner::GetManifestCallback(scoped_ptr
<InvokeCallbackTask
> task
,
2962 const blink::WebURLResponse
& response
,
2963 const std::string
& data
) {
2964 InvokeCallback(task
.Pass());
2967 void TestRunner::CapturePixelsCallback(scoped_ptr
<InvokeCallbackTask
> task
,
2968 const SkBitmap
& snapshot
) {
2969 v8::Isolate
* isolate
= blink::mainThreadIsolate();
2970 v8::HandleScope
handle_scope(isolate
);
2972 v8::Local
<v8::Context
> context
=
2973 web_view_
->mainFrame()->mainWorldScriptContext();
2974 if (context
.IsEmpty())
2977 v8::Context::Scope
context_scope(context
);
2978 v8::Local
<v8::Value
> argv
[3];
2979 SkAutoLockPixels
snapshot_lock(snapshot
);
2981 // Size can be 0 for cases where copyImageAt was called on position
2982 // that doesn't have an image.
2983 int width
= snapshot
.info().width();
2984 argv
[0] = v8::Number::New(isolate
, width
);
2986 int height
= snapshot
.info().height();
2987 argv
[1] = v8::Number::New(isolate
, height
);
2989 blink::WebArrayBuffer buffer
=
2990 blink::WebArrayBuffer::create(snapshot
.getSize(), 1);
2991 memcpy(buffer
.data(), snapshot
.getPixels(), buffer
.byteLength());
2992 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT
2994 // Skia's internal byte order is BGRA. Must swap the B and R channels in
2995 // order to provide a consistent ordering to the layout tests.
2996 unsigned char* pixels
= static_cast<unsigned char*>(buffer
.data());
2997 unsigned len
= buffer
.byteLength();
2998 for (unsigned i
= 0; i
< len
; i
+= 4) {
2999 std::swap(pixels
[i
], pixels
[i
+ 2]);
3004 argv
[2] = blink::WebArrayBufferConverter::toV8Value(
3005 &buffer
, context
->Global(), isolate
);
3007 task
->SetArguments(3, argv
);
3008 InvokeCallback(task
.Pass());
3011 void TestRunner::DispatchBeforeInstallPromptCallback(
3012 scoped_ptr
<InvokeCallbackTask
> task
,
3014 v8::Isolate
* isolate
= blink::mainThreadIsolate();
3015 v8::HandleScope
handle_scope(isolate
);
3017 v8::Local
<v8::Context
> context
=
3018 web_view_
->mainFrame()->mainWorldScriptContext();
3019 if (context
.IsEmpty())
3022 v8::Context::Scope
context_scope(context
);
3023 v8::Local
<v8::Value
> argv
[1];
3024 argv
[0] = v8::Boolean::New(isolate
, canceled
);
3026 task
->SetArguments(1, argv
);
3027 InvokeCallback(task
.Pass());
3030 void TestRunner::LocationChangeDone() {
3031 web_history_item_count_
= delegate_
->NavigationEntryCount();
3033 // No more new work after the first complete load.
3034 work_queue_
.set_frozen(true);
3036 if (!wait_until_done_
)
3037 work_queue_
.ProcessWorkSoon();
3040 void TestRunner::CheckResponseMimeType() {
3041 // Text output: the test page can request different types of output which we
3043 if (!dump_as_text_
) {
3044 std::string mimeType
=
3045 web_view_
->mainFrame()->dataSource()->response().mimeType().utf8();
3046 if (mimeType
== "text/plain") {
3047 dump_as_text_
= true;
3048 generate_pixel_results_
= false;
3053 void TestRunner::CompleteNotifyDone() {
3054 if (wait_until_done_
&& !topLoadingFrame() && work_queue_
.is_empty())
3055 delegate_
->TestFinished();
3056 wait_until_done_
= false;
3059 void TestRunner::DidAcquirePointerLockInternal() {
3060 pointer_locked_
= true;
3061 web_view_
->didAcquirePointerLock();
3063 // Reset planned result to default.
3064 pointer_lock_planned_result_
= PointerLockWillSucceed
;
3067 void TestRunner::DidNotAcquirePointerLockInternal() {
3068 DCHECK(!pointer_locked_
);
3069 pointer_locked_
= false;
3070 web_view_
->didNotAcquirePointerLock();
3072 // Reset planned result to default.
3073 pointer_lock_planned_result_
= PointerLockWillSucceed
;
3076 void TestRunner::DidLosePointerLockInternal() {
3077 bool was_locked
= pointer_locked_
;
3078 pointer_locked_
= false;
3080 web_view_
->didLosePointerLock();
3083 } // namespace content