1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/test_runner/test_runner.h"
9 #include "base/logging.h"
10 #include "components/test_runner/mock_credential_manager_client.h"
11 #include "components/test_runner/mock_web_speech_recognizer.h"
12 #include "components/test_runner/test_interfaces.h"
13 #include "components/test_runner/test_preferences.h"
14 #include "components/test_runner/web_content_settings.h"
15 #include "components/test_runner/web_test_delegate.h"
16 #include "components/test_runner/web_test_proxy.h"
17 #include "gin/arguments.h"
18 #include "gin/array_buffer.h"
19 #include "gin/handle.h"
20 #include "gin/object_template_builder.h"
21 #include "gin/wrappable.h"
22 #include "third_party/WebKit/public/platform/WebBatteryStatus.h"
23 #include "third_party/WebKit/public/platform/WebCanvas.h"
24 #include "third_party/WebKit/public/platform/WebData.h"
25 #include "third_party/WebKit/public/platform/WebPasswordCredential.h"
26 #include "third_party/WebKit/public/platform/WebPoint.h"
27 #include "third_party/WebKit/public/platform/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
;
62 namespace test_runner
{
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();
323 void ForceNextDrawingBufferCreationToFail();
325 base::WeakPtr
<TestRunner
> runner_
;
327 DISALLOW_COPY_AND_ASSIGN(TestRunnerBindings
);
330 gin::WrapperInfo
TestRunnerBindings::kWrapperInfo
= {
331 gin::kEmbedderNativeGin
};
334 void TestRunnerBindings::Install(base::WeakPtr
<TestRunner
> runner
,
336 v8::Isolate
* isolate
= blink::mainThreadIsolate();
337 v8::HandleScope
handle_scope(isolate
);
338 v8::Local
<v8::Context
> context
= frame
->mainWorldScriptContext();
339 if (context
.IsEmpty())
342 v8::Context::Scope
context_scope(context
);
344 TestRunnerBindings
* wrapped
= new TestRunnerBindings(runner
);
345 gin::Handle
<TestRunnerBindings
> bindings
=
346 gin::CreateHandle(isolate
, wrapped
);
347 if (bindings
.IsEmpty())
349 v8::Local
<v8::Object
> global
= context
->Global();
350 v8::Local
<v8::Value
> v8_bindings
= bindings
.ToV8();
352 std::vector
<std::string
> names
;
353 names
.push_back("testRunner");
354 names
.push_back("layoutTestController");
355 for (size_t i
= 0; i
< names
.size(); ++i
)
356 global
->Set(gin::StringToV8(isolate
, names
[i
].c_str()), v8_bindings
);
359 TestRunnerBindings::TestRunnerBindings(base::WeakPtr
<TestRunner
> runner
)
362 TestRunnerBindings::~TestRunnerBindings() {}
364 gin::ObjectTemplateBuilder
TestRunnerBindings::GetObjectTemplateBuilder(
365 v8::Isolate
* isolate
) {
366 return gin::Wrappable
<TestRunnerBindings
>::GetObjectTemplateBuilder(isolate
)
367 // Methods controlling test execution.
368 .SetMethod("logToStderr", &TestRunnerBindings::LogToStderr
)
369 .SetMethod("notifyDone", &TestRunnerBindings::NotifyDone
)
370 .SetMethod("waitUntilDone", &TestRunnerBindings::WaitUntilDone
)
371 .SetMethod("queueBackNavigation",
372 &TestRunnerBindings::QueueBackNavigation
)
373 .SetMethod("queueForwardNavigation",
374 &TestRunnerBindings::QueueForwardNavigation
)
375 .SetMethod("queueReload", &TestRunnerBindings::QueueReload
)
376 .SetMethod("queueLoadingScript", &TestRunnerBindings::QueueLoadingScript
)
377 .SetMethod("queueNonLoadingScript",
378 &TestRunnerBindings::QueueNonLoadingScript
)
379 .SetMethod("queueLoad", &TestRunnerBindings::QueueLoad
)
380 .SetMethod("queueLoadHTMLString",
381 &TestRunnerBindings::QueueLoadHTMLString
)
382 .SetMethod("setCustomPolicyDelegate",
383 &TestRunnerBindings::SetCustomPolicyDelegate
)
384 .SetMethod("waitForPolicyDelegate",
385 &TestRunnerBindings::WaitForPolicyDelegate
)
386 .SetMethod("windowCount", &TestRunnerBindings::WindowCount
)
387 .SetMethod("setCloseRemainingWindowsWhenComplete",
388 &TestRunnerBindings::SetCloseRemainingWindowsWhenComplete
)
389 .SetMethod("resetTestHelperControllers",
390 &TestRunnerBindings::ResetTestHelperControllers
)
391 .SetMethod("setTabKeyCyclesThroughElements",
392 &TestRunnerBindings::SetTabKeyCyclesThroughElements
)
393 .SetMethod("execCommand", &TestRunnerBindings::ExecCommand
)
394 .SetMethod("isCommandEnabled", &TestRunnerBindings::IsCommandEnabled
)
395 .SetMethod("callShouldCloseOnWebView",
396 &TestRunnerBindings::CallShouldCloseOnWebView
)
397 .SetMethod("setDomainRelaxationForbiddenForURLScheme",
398 &TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme
)
400 "evaluateScriptInIsolatedWorldAndReturnValue",
401 &TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue
)
402 .SetMethod("evaluateScriptInIsolatedWorld",
403 &TestRunnerBindings::EvaluateScriptInIsolatedWorld
)
404 .SetMethod("setIsolatedWorldSecurityOrigin",
405 &TestRunnerBindings::SetIsolatedWorldSecurityOrigin
)
406 .SetMethod("setIsolatedWorldContentSecurityPolicy",
407 &TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy
)
408 .SetMethod("addOriginAccessWhitelistEntry",
409 &TestRunnerBindings::AddOriginAccessWhitelistEntry
)
410 .SetMethod("removeOriginAccessWhitelistEntry",
411 &TestRunnerBindings::RemoveOriginAccessWhitelistEntry
)
412 .SetMethod("hasCustomPageSizeStyle",
413 &TestRunnerBindings::HasCustomPageSizeStyle
)
414 .SetMethod("forceRedSelectionColors",
415 &TestRunnerBindings::ForceRedSelectionColors
)
416 .SetMethod("insertStyleSheet", &TestRunnerBindings::InsertStyleSheet
)
417 .SetMethod("findString", &TestRunnerBindings::FindString
)
418 .SetMethod("selectionAsMarkup", &TestRunnerBindings::SelectionAsMarkup
)
419 .SetMethod("setTextSubpixelPositioning",
420 &TestRunnerBindings::SetTextSubpixelPositioning
)
421 .SetMethod("setPageVisibility", &TestRunnerBindings::SetPageVisibility
)
422 .SetMethod("setTextDirection", &TestRunnerBindings::SetTextDirection
)
423 .SetMethod("useUnfortunateSynchronousResizeMode",
424 &TestRunnerBindings::UseUnfortunateSynchronousResizeMode
)
425 .SetMethod("enableAutoResizeMode",
426 &TestRunnerBindings::EnableAutoResizeMode
)
427 .SetMethod("disableAutoResizeMode",
428 &TestRunnerBindings::DisableAutoResizeMode
)
429 .SetMethod("setMockDeviceLight", &TestRunnerBindings::SetMockDeviceLight
)
430 .SetMethod("resetDeviceLight", &TestRunnerBindings::ResetDeviceLight
)
431 .SetMethod("setMockDeviceMotion",
432 &TestRunnerBindings::SetMockDeviceMotion
)
433 .SetMethod("setMockDeviceOrientation",
434 &TestRunnerBindings::SetMockDeviceOrientation
)
435 .SetMethod("setMockScreenOrientation",
436 &TestRunnerBindings::SetMockScreenOrientation
)
437 .SetMethod("didChangeBatteryStatus",
438 &TestRunnerBindings::DidChangeBatteryStatus
)
439 .SetMethod("resetBatteryStatus", &TestRunnerBindings::ResetBatteryStatus
)
440 .SetMethod("didAcquirePointerLock",
441 &TestRunnerBindings::DidAcquirePointerLock
)
442 .SetMethod("didNotAcquirePointerLock",
443 &TestRunnerBindings::DidNotAcquirePointerLock
)
444 .SetMethod("didLosePointerLock", &TestRunnerBindings::DidLosePointerLock
)
445 .SetMethod("setPointerLockWillFailSynchronously",
446 &TestRunnerBindings::SetPointerLockWillFailSynchronously
)
447 .SetMethod("setPointerLockWillRespondAsynchronously",
448 &TestRunnerBindings::SetPointerLockWillRespondAsynchronously
)
449 .SetMethod("setPopupBlockingEnabled",
450 &TestRunnerBindings::SetPopupBlockingEnabled
)
451 .SetMethod("setJavaScriptCanAccessClipboard",
452 &TestRunnerBindings::SetJavaScriptCanAccessClipboard
)
453 .SetMethod("setXSSAuditorEnabled",
454 &TestRunnerBindings::SetXSSAuditorEnabled
)
455 .SetMethod("setAllowUniversalAccessFromFileURLs",
456 &TestRunnerBindings::SetAllowUniversalAccessFromFileURLs
)
457 .SetMethod("setAllowFileAccessFromFileURLs",
458 &TestRunnerBindings::SetAllowFileAccessFromFileURLs
)
459 .SetMethod("overridePreference", &TestRunnerBindings::OverridePreference
)
460 .SetMethod("setAcceptLanguages", &TestRunnerBindings::SetAcceptLanguages
)
461 .SetMethod("setPluginsEnabled", &TestRunnerBindings::SetPluginsEnabled
)
462 .SetMethod("dumpEditingCallbacks",
463 &TestRunnerBindings::DumpEditingCallbacks
)
464 .SetMethod("dumpAsMarkup", &TestRunnerBindings::DumpAsMarkup
)
465 .SetMethod("dumpAsText", &TestRunnerBindings::DumpAsText
)
466 .SetMethod("dumpAsTextWithPixelResults",
467 &TestRunnerBindings::DumpAsTextWithPixelResults
)
468 .SetMethod("dumpChildFrameScrollPositions",
469 &TestRunnerBindings::DumpChildFrameScrollPositions
)
470 .SetMethod("dumpChildFramesAsText",
471 &TestRunnerBindings::DumpChildFramesAsText
)
472 .SetMethod("dumpChildFramesAsMarkup",
473 &TestRunnerBindings::DumpChildFramesAsMarkup
)
474 .SetMethod("dumpIconChanges", &TestRunnerBindings::DumpIconChanges
)
475 .SetMethod("setAudioData", &TestRunnerBindings::SetAudioData
)
476 .SetMethod("dumpFrameLoadCallbacks",
477 &TestRunnerBindings::DumpFrameLoadCallbacks
)
478 .SetMethod("dumpPingLoaderCallbacks",
479 &TestRunnerBindings::DumpPingLoaderCallbacks
)
480 .SetMethod("dumpUserGestureInFrameLoadCallbacks",
481 &TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks
)
482 .SetMethod("dumpTitleChanges", &TestRunnerBindings::DumpTitleChanges
)
483 .SetMethod("dumpCreateView", &TestRunnerBindings::DumpCreateView
)
484 .SetMethod("setCanOpenWindows", &TestRunnerBindings::SetCanOpenWindows
)
485 .SetMethod("dumpResourceLoadCallbacks",
486 &TestRunnerBindings::DumpResourceLoadCallbacks
)
487 .SetMethod("dumpResourceRequestCallbacks",
488 &TestRunnerBindings::DumpResourceRequestCallbacks
)
489 .SetMethod("dumpResourceResponseMIMETypes",
490 &TestRunnerBindings::DumpResourceResponseMIMETypes
)
491 .SetMethod("setImagesAllowed", &TestRunnerBindings::SetImagesAllowed
)
492 .SetMethod("setMediaAllowed", &TestRunnerBindings::SetMediaAllowed
)
493 .SetMethod("setScriptsAllowed", &TestRunnerBindings::SetScriptsAllowed
)
494 .SetMethod("setStorageAllowed", &TestRunnerBindings::SetStorageAllowed
)
495 .SetMethod("setPluginsAllowed", &TestRunnerBindings::SetPluginsAllowed
)
496 .SetMethod("setAllowDisplayOfInsecureContent",
497 &TestRunnerBindings::SetAllowDisplayOfInsecureContent
)
498 .SetMethod("setAllowRunningOfInsecureContent",
499 &TestRunnerBindings::SetAllowRunningOfInsecureContent
)
500 .SetMethod("dumpPermissionClientCallbacks",
501 &TestRunnerBindings::DumpPermissionClientCallbacks
)
502 .SetMethod("dumpWindowStatusChanges",
503 &TestRunnerBindings::DumpWindowStatusChanges
)
504 .SetMethod("dumpProgressFinishedCallback",
505 &TestRunnerBindings::DumpProgressFinishedCallback
)
506 .SetMethod("dumpSpellCheckCallbacks",
507 &TestRunnerBindings::DumpSpellCheckCallbacks
)
508 .SetMethod("dumpBackForwardList",
509 &TestRunnerBindings::DumpBackForwardList
)
510 .SetMethod("dumpSelectionRect", &TestRunnerBindings::DumpSelectionRect
)
511 .SetMethod("setPrinting", &TestRunnerBindings::SetPrinting
)
512 .SetMethod("clearPrinting", &TestRunnerBindings::ClearPrinting
)
514 "setShouldStayOnPageAfterHandlingBeforeUnload",
515 &TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload
)
516 .SetMethod("setWillSendRequestClearHeader",
517 &TestRunnerBindings::SetWillSendRequestClearHeader
)
518 .SetMethod("dumpResourceRequestPriorities",
519 &TestRunnerBindings::DumpResourceRequestPriorities
)
520 .SetMethod("setUseMockTheme", &TestRunnerBindings::SetUseMockTheme
)
521 .SetMethod("waitUntilExternalURLLoad",
522 &TestRunnerBindings::WaitUntilExternalURLLoad
)
523 .SetMethod("dumpDragImage", &TestRunnerBindings::DumpDragImage
)
524 .SetMethod("dumpNavigationPolicy",
525 &TestRunnerBindings::DumpNavigationPolicy
)
526 .SetMethod("showWebInspector", &TestRunnerBindings::ShowWebInspector
)
527 .SetMethod("closeWebInspector", &TestRunnerBindings::CloseWebInspector
)
528 .SetMethod("isChooserShown", &TestRunnerBindings::IsChooserShown
)
529 .SetMethod("evaluateInWebInspector",
530 &TestRunnerBindings::EvaluateInWebInspector
)
531 .SetMethod("clearAllDatabases", &TestRunnerBindings::ClearAllDatabases
)
532 .SetMethod("setDatabaseQuota", &TestRunnerBindings::SetDatabaseQuota
)
533 .SetMethod("setAlwaysAcceptCookies",
534 &TestRunnerBindings::SetAlwaysAcceptCookies
)
535 .SetMethod("setWindowIsKey", &TestRunnerBindings::SetWindowIsKey
)
536 .SetMethod("pathToLocalResource",
537 &TestRunnerBindings::PathToLocalResource
)
538 .SetMethod("setBackingScaleFactor",
539 &TestRunnerBindings::SetBackingScaleFactor
)
540 .SetMethod("setColorProfile", &TestRunnerBindings::SetColorProfile
)
541 .SetMethod("setPOSIXLocale", &TestRunnerBindings::SetPOSIXLocale
)
542 .SetMethod("setMIDIAccessorResult",
543 &TestRunnerBindings::SetMIDIAccessorResult
)
544 .SetMethod("simulateWebNotificationClick",
545 &TestRunnerBindings::SimulateWebNotificationClick
)
546 .SetMethod("addMockSpeechRecognitionResult",
547 &TestRunnerBindings::AddMockSpeechRecognitionResult
)
548 .SetMethod("setMockSpeechRecognitionError",
549 &TestRunnerBindings::SetMockSpeechRecognitionError
)
550 .SetMethod("wasMockSpeechRecognitionAborted",
551 &TestRunnerBindings::WasMockSpeechRecognitionAborted
)
552 .SetMethod("addMockCredentialManagerResponse",
553 &TestRunnerBindings::AddMockCredentialManagerResponse
)
554 .SetMethod("addWebPageOverlay", &TestRunnerBindings::AddWebPageOverlay
)
555 .SetMethod("removeWebPageOverlay",
556 &TestRunnerBindings::RemoveWebPageOverlay
)
557 .SetMethod("layoutAndPaintAsync",
558 &TestRunnerBindings::LayoutAndPaintAsync
)
559 .SetMethod("layoutAndPaintAsyncThen",
560 &TestRunnerBindings::LayoutAndPaintAsyncThen
)
561 .SetMethod("getManifestThen", &TestRunnerBindings::GetManifestThen
)
562 .SetMethod("capturePixelsAsyncThen",
563 &TestRunnerBindings::CapturePixelsAsyncThen
)
564 .SetMethod("copyImageAtAndCapturePixelsAsyncThen",
565 &TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen
)
566 .SetMethod("setCustomTextOutput",
567 &TestRunnerBindings::SetCustomTextOutput
)
568 .SetMethod("setViewSourceForFrame",
569 &TestRunnerBindings::SetViewSourceForFrame
)
570 .SetMethod("setBluetoothMockDataSet",
571 &TestRunnerBindings::SetBluetoothMockDataSet
)
572 .SetMethod("forceNextWebGLContextCreationToFail",
573 &TestRunnerBindings::ForceNextWebGLContextCreationToFail
)
574 .SetMethod("forceNextDrawingBufferCreationToFail",
575 &TestRunnerBindings::ForceNextDrawingBufferCreationToFail
)
576 .SetMethod("setGeofencingMockProvider",
577 &TestRunnerBindings::SetGeofencingMockProvider
)
578 .SetMethod("clearGeofencingMockProvider",
579 &TestRunnerBindings::ClearGeofencingMockProvider
)
580 .SetMethod("setGeofencingMockPosition",
581 &TestRunnerBindings::SetGeofencingMockPosition
)
582 .SetMethod("setPermission", &TestRunnerBindings::SetPermission
)
583 .SetMethod("dispatchBeforeInstallPromptEvent",
584 &TestRunnerBindings::DispatchBeforeInstallPromptEvent
)
585 .SetMethod("resolveBeforeInstallPromptPromise",
586 &TestRunnerBindings::ResolveBeforeInstallPromptPromise
)
589 .SetProperty("platformName", &TestRunnerBindings::PlatformName
)
590 .SetProperty("tooltipText", &TestRunnerBindings::TooltipText
)
591 .SetProperty("disableNotifyDone", &TestRunnerBindings::DisableNotifyDone
)
592 // webHistoryItemCount is used by tests in LayoutTests\http\tests\history
593 .SetProperty("webHistoryItemCount",
594 &TestRunnerBindings::WebHistoryItemCount
)
595 .SetProperty("interceptPostMessage",
596 &TestRunnerBindings::InterceptPostMessage
,
597 &TestRunnerBindings::SetInterceptPostMessage
)
599 // The following are stubs.
600 .SetMethod("dumpDatabaseCallbacks", &TestRunnerBindings::NotImplemented
)
601 .SetMethod("setIconDatabaseEnabled", &TestRunnerBindings::NotImplemented
)
602 .SetMethod("setScrollbarPolicy", &TestRunnerBindings::NotImplemented
)
603 .SetMethod("clearAllApplicationCaches",
604 &TestRunnerBindings::NotImplemented
)
605 .SetMethod("clearApplicationCacheForOrigin",
606 &TestRunnerBindings::NotImplemented
)
607 .SetMethod("clearBackForwardList", &TestRunnerBindings::NotImplemented
)
608 .SetMethod("keepWebHistory", &TestRunnerBindings::NotImplemented
)
609 .SetMethod("setApplicationCacheOriginQuota",
610 &TestRunnerBindings::NotImplemented
)
611 .SetMethod("setCallCloseOnWebViews", &TestRunnerBindings::NotImplemented
)
612 .SetMethod("setMainFrameIsFirstResponder",
613 &TestRunnerBindings::NotImplemented
)
614 .SetMethod("setUseDashboardCompatibilityMode",
615 &TestRunnerBindings::NotImplemented
)
616 .SetMethod("deleteAllLocalStorage", &TestRunnerBindings::NotImplemented
)
617 .SetMethod("localStorageDiskUsageForOrigin",
618 &TestRunnerBindings::NotImplemented
)
619 .SetMethod("originsWithLocalStorage", &TestRunnerBindings::NotImplemented
)
620 .SetMethod("deleteLocalStorageForOrigin",
621 &TestRunnerBindings::NotImplemented
)
622 .SetMethod("observeStorageTrackerNotifications",
623 &TestRunnerBindings::NotImplemented
)
624 .SetMethod("syncLocalStorage", &TestRunnerBindings::NotImplemented
)
625 .SetMethod("addDisallowedURL", &TestRunnerBindings::NotImplemented
)
626 .SetMethod("applicationCacheDiskUsageForOrigin",
627 &TestRunnerBindings::NotImplemented
)
628 .SetMethod("abortModal", &TestRunnerBindings::NotImplemented
)
631 // Used at fast/dom/assign-to-window-status.html
632 .SetMethod("dumpStatusCallbacks",
633 &TestRunnerBindings::DumpWindowStatusChanges
);
636 void TestRunnerBindings::LogToStderr(const std::string
& output
) {
637 LOG(ERROR
) << output
;
640 void TestRunnerBindings::NotifyDone() {
642 runner_
->NotifyDone();
645 void TestRunnerBindings::WaitUntilDone() {
647 runner_
->WaitUntilDone();
650 void TestRunnerBindings::QueueBackNavigation(int how_far_back
) {
652 runner_
->QueueBackNavigation(how_far_back
);
655 void TestRunnerBindings::QueueForwardNavigation(int how_far_forward
) {
657 runner_
->QueueForwardNavigation(how_far_forward
);
660 void TestRunnerBindings::QueueReload() {
662 runner_
->QueueReload();
665 void TestRunnerBindings::QueueLoadingScript(const std::string
& script
) {
667 runner_
->QueueLoadingScript(script
);
670 void TestRunnerBindings::QueueNonLoadingScript(const std::string
& script
) {
672 runner_
->QueueNonLoadingScript(script
);
675 void TestRunnerBindings::QueueLoad(gin::Arguments
* args
) {
680 args
->GetNext(&target
);
681 runner_
->QueueLoad(url
, target
);
685 void TestRunnerBindings::QueueLoadHTMLString(gin::Arguments
* args
) {
687 runner_
->QueueLoadHTMLString(args
);
690 void TestRunnerBindings::SetCustomPolicyDelegate(gin::Arguments
* args
) {
692 runner_
->SetCustomPolicyDelegate(args
);
695 void TestRunnerBindings::WaitForPolicyDelegate() {
697 runner_
->WaitForPolicyDelegate();
700 int TestRunnerBindings::WindowCount() {
702 return runner_
->WindowCount();
706 void TestRunnerBindings::SetCloseRemainingWindowsWhenComplete(
707 gin::Arguments
* args
) {
711 // In the original implementation, nothing happens if the argument is
713 bool close_remaining_windows
= false;
714 if (args
->GetNext(&close_remaining_windows
))
715 runner_
->SetCloseRemainingWindowsWhenComplete(close_remaining_windows
);
718 void TestRunnerBindings::ResetTestHelperControllers() {
720 runner_
->ResetTestHelperControllers();
723 void TestRunnerBindings::SetTabKeyCyclesThroughElements(
724 bool tab_key_cycles_through_elements
) {
726 runner_
->SetTabKeyCyclesThroughElements(tab_key_cycles_through_elements
);
729 void TestRunnerBindings::ExecCommand(gin::Arguments
* args
) {
731 runner_
->ExecCommand(args
);
734 bool TestRunnerBindings::IsCommandEnabled(const std::string
& command
) {
736 return runner_
->IsCommandEnabled(command
);
740 bool TestRunnerBindings::CallShouldCloseOnWebView() {
742 return runner_
->CallShouldCloseOnWebView();
746 void TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme(
747 bool forbidden
, const std::string
& scheme
) {
749 runner_
->SetDomainRelaxationForbiddenForURLScheme(forbidden
, scheme
);
753 TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue(
754 int world_id
, const std::string
& script
) {
756 return v8::Local
<v8::Value
>();
757 return runner_
->EvaluateScriptInIsolatedWorldAndReturnValue(world_id
,
761 void TestRunnerBindings::EvaluateScriptInIsolatedWorld(
762 int world_id
, const std::string
& script
) {
764 runner_
->EvaluateScriptInIsolatedWorld(world_id
, script
);
767 void TestRunnerBindings::SetIsolatedWorldSecurityOrigin(
768 int world_id
, v8::Local
<v8::Value
> origin
) {
770 runner_
->SetIsolatedWorldSecurityOrigin(world_id
, origin
);
773 void TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy(
774 int world_id
, const std::string
& policy
) {
776 runner_
->SetIsolatedWorldContentSecurityPolicy(world_id
, policy
);
779 void TestRunnerBindings::AddOriginAccessWhitelistEntry(
780 const std::string
& source_origin
,
781 const std::string
& destination_protocol
,
782 const std::string
& destination_host
,
783 bool allow_destination_subdomains
) {
785 runner_
->AddOriginAccessWhitelistEntry(source_origin
,
786 destination_protocol
,
788 allow_destination_subdomains
);
792 void TestRunnerBindings::RemoveOriginAccessWhitelistEntry(
793 const std::string
& source_origin
,
794 const std::string
& destination_protocol
,
795 const std::string
& destination_host
,
796 bool allow_destination_subdomains
) {
798 runner_
->RemoveOriginAccessWhitelistEntry(source_origin
,
799 destination_protocol
,
801 allow_destination_subdomains
);
805 bool TestRunnerBindings::HasCustomPageSizeStyle(int page_index
) {
807 return runner_
->HasCustomPageSizeStyle(page_index
);
811 void TestRunnerBindings::ForceRedSelectionColors() {
813 runner_
->ForceRedSelectionColors();
816 void TestRunnerBindings::InsertStyleSheet(const std::string
& source_code
) {
818 runner_
->InsertStyleSheet(source_code
);
821 bool TestRunnerBindings::FindString(
822 const std::string
& search_text
,
823 const std::vector
<std::string
>& options_array
) {
825 return runner_
->FindString(search_text
, options_array
);
829 std::string
TestRunnerBindings::SelectionAsMarkup() {
831 return runner_
->SelectionAsMarkup();
832 return std::string();
835 void TestRunnerBindings::SetTextSubpixelPositioning(bool value
) {
837 runner_
->SetTextSubpixelPositioning(value
);
840 void TestRunnerBindings::SetPageVisibility(const std::string
& new_visibility
) {
842 runner_
->SetPageVisibility(new_visibility
);
845 void TestRunnerBindings::SetTextDirection(const std::string
& direction_name
) {
847 runner_
->SetTextDirection(direction_name
);
850 void TestRunnerBindings::UseUnfortunateSynchronousResizeMode() {
852 runner_
->UseUnfortunateSynchronousResizeMode();
855 bool TestRunnerBindings::EnableAutoResizeMode(int min_width
,
860 return runner_
->EnableAutoResizeMode(min_width
, min_height
,
861 max_width
, max_height
);
866 bool TestRunnerBindings::DisableAutoResizeMode(int new_width
, int new_height
) {
868 return runner_
->DisableAutoResizeMode(new_width
, new_height
);
872 void TestRunnerBindings::SetMockDeviceLight(double value
) {
875 runner_
->SetMockDeviceLight(value
);
878 void TestRunnerBindings::ResetDeviceLight() {
880 runner_
->ResetDeviceLight();
883 void TestRunnerBindings::SetMockDeviceMotion(gin::Arguments
* args
) {
887 bool has_acceleration_x
;
888 double acceleration_x
;
889 bool has_acceleration_y
;
890 double acceleration_y
;
891 bool has_acceleration_z
;
892 double acceleration_z
;
893 bool has_acceleration_including_gravity_x
;
894 double acceleration_including_gravity_x
;
895 bool has_acceleration_including_gravity_y
;
896 double acceleration_including_gravity_y
;
897 bool has_acceleration_including_gravity_z
;
898 double acceleration_including_gravity_z
;
899 bool has_rotation_rate_alpha
;
900 double rotation_rate_alpha
;
901 bool has_rotation_rate_beta
;
902 double rotation_rate_beta
;
903 bool has_rotation_rate_gamma
;
904 double rotation_rate_gamma
;
907 args
->GetNext(&has_acceleration_x
);
908 args
->GetNext(& acceleration_x
);
909 args
->GetNext(&has_acceleration_y
);
910 args
->GetNext(& acceleration_y
);
911 args
->GetNext(&has_acceleration_z
);
912 args
->GetNext(& acceleration_z
);
913 args
->GetNext(&has_acceleration_including_gravity_x
);
914 args
->GetNext(& acceleration_including_gravity_x
);
915 args
->GetNext(&has_acceleration_including_gravity_y
);
916 args
->GetNext(& acceleration_including_gravity_y
);
917 args
->GetNext(&has_acceleration_including_gravity_z
);
918 args
->GetNext(& acceleration_including_gravity_z
);
919 args
->GetNext(&has_rotation_rate_alpha
);
920 args
->GetNext(& rotation_rate_alpha
);
921 args
->GetNext(&has_rotation_rate_beta
);
922 args
->GetNext(& rotation_rate_beta
);
923 args
->GetNext(&has_rotation_rate_gamma
);
924 args
->GetNext(& rotation_rate_gamma
);
925 args
->GetNext(& interval
);
927 runner_
->SetMockDeviceMotion(has_acceleration_x
, acceleration_x
,
928 has_acceleration_y
, acceleration_y
,
929 has_acceleration_z
, acceleration_z
,
930 has_acceleration_including_gravity_x
,
931 acceleration_including_gravity_x
,
932 has_acceleration_including_gravity_y
,
933 acceleration_including_gravity_y
,
934 has_acceleration_including_gravity_z
,
935 acceleration_including_gravity_z
,
936 has_rotation_rate_alpha
,
938 has_rotation_rate_beta
,
940 has_rotation_rate_gamma
,
945 void TestRunnerBindings::SetMockDeviceOrientation(gin::Arguments
* args
) {
949 bool has_alpha
= false;
951 bool has_beta
= false;
953 bool has_gamma
= false;
955 bool has_absolute
= false;
956 bool absolute
= false;
958 args
->GetNext(&has_alpha
);
959 args
->GetNext(&alpha
);
960 args
->GetNext(&has_beta
);
961 args
->GetNext(&beta
);
962 args
->GetNext(&has_gamma
);
963 args
->GetNext(&gamma
);
964 args
->GetNext(&has_absolute
);
965 args
->GetNext(&absolute
);
967 runner_
->SetMockDeviceOrientation(has_alpha
, alpha
,
970 has_absolute
, absolute
);
973 void TestRunnerBindings::SetMockScreenOrientation(
974 const std::string
& orientation
) {
978 runner_
->SetMockScreenOrientation(orientation
);
981 void TestRunnerBindings::DidChangeBatteryStatus(bool charging
,
983 double dischargingTime
,
986 runner_
->DidChangeBatteryStatus(charging
, chargingTime
,
987 dischargingTime
, level
);
991 void TestRunnerBindings::ResetBatteryStatus() {
993 runner_
->ResetBatteryStatus();
996 void TestRunnerBindings::DidAcquirePointerLock() {
998 runner_
->DidAcquirePointerLock();
1001 void TestRunnerBindings::DidNotAcquirePointerLock() {
1003 runner_
->DidNotAcquirePointerLock();
1006 void TestRunnerBindings::DidLosePointerLock() {
1008 runner_
->DidLosePointerLock();
1011 void TestRunnerBindings::SetPointerLockWillFailSynchronously() {
1013 runner_
->SetPointerLockWillFailSynchronously();
1016 void TestRunnerBindings::SetPointerLockWillRespondAsynchronously() {
1018 runner_
->SetPointerLockWillRespondAsynchronously();
1021 void TestRunnerBindings::SetPopupBlockingEnabled(bool block_popups
) {
1023 runner_
->SetPopupBlockingEnabled(block_popups
);
1026 void TestRunnerBindings::SetJavaScriptCanAccessClipboard(bool can_access
) {
1028 runner_
->SetJavaScriptCanAccessClipboard(can_access
);
1031 void TestRunnerBindings::SetXSSAuditorEnabled(bool enabled
) {
1033 runner_
->SetXSSAuditorEnabled(enabled
);
1036 void TestRunnerBindings::SetAllowUniversalAccessFromFileURLs(bool allow
) {
1038 runner_
->SetAllowUniversalAccessFromFileURLs(allow
);
1041 void TestRunnerBindings::SetAllowFileAccessFromFileURLs(bool allow
) {
1043 runner_
->SetAllowFileAccessFromFileURLs(allow
);
1046 void TestRunnerBindings::OverridePreference(const std::string key
,
1047 v8::Local
<v8::Value
> value
) {
1049 runner_
->OverridePreference(key
, value
);
1052 void TestRunnerBindings::SetAcceptLanguages(
1053 const std::string
& accept_languages
) {
1057 runner_
->SetAcceptLanguages(accept_languages
);
1060 void TestRunnerBindings::SetPluginsEnabled(bool enabled
) {
1062 runner_
->SetPluginsEnabled(enabled
);
1065 void TestRunnerBindings::DumpEditingCallbacks() {
1067 runner_
->DumpEditingCallbacks();
1070 void TestRunnerBindings::DumpAsMarkup() {
1072 runner_
->DumpAsMarkup();
1075 void TestRunnerBindings::DumpAsText() {
1077 runner_
->DumpAsText();
1080 void TestRunnerBindings::DumpAsTextWithPixelResults() {
1082 runner_
->DumpAsTextWithPixelResults();
1085 void TestRunnerBindings::DumpChildFrameScrollPositions() {
1087 runner_
->DumpChildFrameScrollPositions();
1090 void TestRunnerBindings::DumpChildFramesAsText() {
1092 runner_
->DumpChildFramesAsText();
1095 void TestRunnerBindings::DumpChildFramesAsMarkup() {
1097 runner_
->DumpChildFramesAsMarkup();
1100 void TestRunnerBindings::DumpIconChanges() {
1102 runner_
->DumpIconChanges();
1105 void TestRunnerBindings::SetAudioData(const gin::ArrayBufferView
& view
) {
1107 runner_
->SetAudioData(view
);
1110 void TestRunnerBindings::DumpFrameLoadCallbacks() {
1112 runner_
->DumpFrameLoadCallbacks();
1115 void TestRunnerBindings::DumpPingLoaderCallbacks() {
1117 runner_
->DumpPingLoaderCallbacks();
1120 void TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks() {
1122 runner_
->DumpUserGestureInFrameLoadCallbacks();
1125 void TestRunnerBindings::DumpTitleChanges() {
1127 runner_
->DumpTitleChanges();
1130 void TestRunnerBindings::DumpCreateView() {
1132 runner_
->DumpCreateView();
1135 void TestRunnerBindings::SetCanOpenWindows() {
1137 runner_
->SetCanOpenWindows();
1140 void TestRunnerBindings::DumpResourceLoadCallbacks() {
1142 runner_
->DumpResourceLoadCallbacks();
1145 void TestRunnerBindings::DumpResourceRequestCallbacks() {
1147 runner_
->DumpResourceRequestCallbacks();
1150 void TestRunnerBindings::DumpResourceResponseMIMETypes() {
1152 runner_
->DumpResourceResponseMIMETypes();
1155 void TestRunnerBindings::SetImagesAllowed(bool allowed
) {
1157 runner_
->SetImagesAllowed(allowed
);
1160 void TestRunnerBindings::SetMediaAllowed(bool allowed
) {
1162 runner_
->SetMediaAllowed(allowed
);
1165 void TestRunnerBindings::SetScriptsAllowed(bool allowed
) {
1167 runner_
->SetScriptsAllowed(allowed
);
1170 void TestRunnerBindings::SetStorageAllowed(bool allowed
) {
1172 runner_
->SetStorageAllowed(allowed
);
1175 void TestRunnerBindings::SetPluginsAllowed(bool allowed
) {
1177 runner_
->SetPluginsAllowed(allowed
);
1180 void TestRunnerBindings::SetAllowDisplayOfInsecureContent(bool allowed
) {
1182 runner_
->SetAllowDisplayOfInsecureContent(allowed
);
1185 void TestRunnerBindings::SetAllowRunningOfInsecureContent(bool allowed
) {
1187 runner_
->SetAllowRunningOfInsecureContent(allowed
);
1190 void TestRunnerBindings::DumpPermissionClientCallbacks() {
1192 runner_
->DumpPermissionClientCallbacks();
1195 void TestRunnerBindings::DumpWindowStatusChanges() {
1197 runner_
->DumpWindowStatusChanges();
1200 void TestRunnerBindings::DumpProgressFinishedCallback() {
1202 runner_
->DumpProgressFinishedCallback();
1205 void TestRunnerBindings::DumpSpellCheckCallbacks() {
1207 runner_
->DumpSpellCheckCallbacks();
1210 void TestRunnerBindings::DumpBackForwardList() {
1212 runner_
->DumpBackForwardList();
1215 void TestRunnerBindings::DumpSelectionRect() {
1217 runner_
->DumpSelectionRect();
1220 void TestRunnerBindings::SetPrinting() {
1222 runner_
->SetPrinting();
1225 void TestRunnerBindings::ClearPrinting() {
1227 runner_
->ClearPrinting();
1230 void TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload(
1233 runner_
->SetShouldStayOnPageAfterHandlingBeforeUnload(value
);
1236 void TestRunnerBindings::SetWillSendRequestClearHeader(
1237 const std::string
& header
) {
1239 runner_
->SetWillSendRequestClearHeader(header
);
1242 void TestRunnerBindings::DumpResourceRequestPriorities() {
1244 runner_
->DumpResourceRequestPriorities();
1247 void TestRunnerBindings::SetUseMockTheme(bool use
) {
1249 runner_
->SetUseMockTheme(use
);
1252 void TestRunnerBindings::WaitUntilExternalURLLoad() {
1254 runner_
->WaitUntilExternalURLLoad();
1257 void TestRunnerBindings::DumpDragImage() {
1259 runner_
->DumpDragImage();
1262 void TestRunnerBindings::DumpNavigationPolicy() {
1264 runner_
->DumpNavigationPolicy();
1267 void TestRunnerBindings::ShowWebInspector(gin::Arguments
* args
) {
1269 std::string settings
;
1270 args
->GetNext(&settings
);
1271 std::string frontend_url
;
1272 args
->GetNext(&frontend_url
);
1273 runner_
->ShowWebInspector(settings
, frontend_url
);
1277 void TestRunnerBindings::CloseWebInspector() {
1279 runner_
->CloseWebInspector();
1282 bool TestRunnerBindings::IsChooserShown() {
1284 return runner_
->IsChooserShown();
1288 void TestRunnerBindings::EvaluateInWebInspector(int call_id
,
1289 const std::string
& script
) {
1291 runner_
->EvaluateInWebInspector(call_id
, script
);
1294 void TestRunnerBindings::ClearAllDatabases() {
1296 runner_
->ClearAllDatabases();
1299 void TestRunnerBindings::SetDatabaseQuota(int quota
) {
1301 runner_
->SetDatabaseQuota(quota
);
1304 void TestRunnerBindings::SetAlwaysAcceptCookies(bool accept
) {
1306 runner_
->SetAlwaysAcceptCookies(accept
);
1309 void TestRunnerBindings::SetWindowIsKey(bool value
) {
1311 runner_
->SetWindowIsKey(value
);
1314 std::string
TestRunnerBindings::PathToLocalResource(const std::string
& path
) {
1316 return runner_
->PathToLocalResource(path
);
1317 return std::string();
1320 void TestRunnerBindings::SetBackingScaleFactor(
1321 double value
, v8::Local
<v8::Function
> callback
) {
1323 runner_
->SetBackingScaleFactor(value
, callback
);
1326 void TestRunnerBindings::SetColorProfile(
1327 const std::string
& name
, v8::Local
<v8::Function
> callback
) {
1329 runner_
->SetColorProfile(name
, callback
);
1332 void TestRunnerBindings::SetBluetoothMockDataSet(const std::string
& name
) {
1334 runner_
->SetBluetoothMockDataSet(name
);
1337 void TestRunnerBindings::SetPOSIXLocale(const std::string
& locale
) {
1339 runner_
->SetPOSIXLocale(locale
);
1342 void TestRunnerBindings::SetMIDIAccessorResult(bool result
) {
1344 runner_
->SetMIDIAccessorResult(result
);
1347 void TestRunnerBindings::SimulateWebNotificationClick(
1348 const std::string
& title
) {
1350 runner_
->SimulateWebNotificationClick(title
);
1353 void TestRunnerBindings::AddMockSpeechRecognitionResult(
1354 const std::string
& transcript
, double confidence
) {
1356 runner_
->AddMockSpeechRecognitionResult(transcript
, confidence
);
1359 void TestRunnerBindings::SetMockSpeechRecognitionError(
1360 const std::string
& error
, const std::string
& message
) {
1362 runner_
->SetMockSpeechRecognitionError(error
, message
);
1365 bool TestRunnerBindings::WasMockSpeechRecognitionAborted() {
1367 return runner_
->WasMockSpeechRecognitionAborted();
1371 void TestRunnerBindings::AddMockCredentialManagerResponse(
1372 const std::string
& id
,
1373 const std::string
& name
,
1374 const std::string
& avatar
,
1375 const std::string
& password
) {
1377 runner_
->AddMockCredentialManagerResponse(id
, name
, avatar
, password
);
1380 void TestRunnerBindings::AddWebPageOverlay() {
1382 runner_
->AddWebPageOverlay();
1385 void TestRunnerBindings::RemoveWebPageOverlay() {
1387 runner_
->RemoveWebPageOverlay();
1390 void TestRunnerBindings::LayoutAndPaintAsync() {
1392 runner_
->LayoutAndPaintAsync();
1395 void TestRunnerBindings::LayoutAndPaintAsyncThen(
1396 v8::Local
<v8::Function
> callback
) {
1398 runner_
->LayoutAndPaintAsyncThen(callback
);
1401 void TestRunnerBindings::GetManifestThen(v8::Local
<v8::Function
> callback
) {
1403 runner_
->GetManifestThen(callback
);
1406 void TestRunnerBindings::CapturePixelsAsyncThen(
1407 v8::Local
<v8::Function
> callback
) {
1409 runner_
->CapturePixelsAsyncThen(callback
);
1412 void TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen(
1413 int x
, int y
, v8::Local
<v8::Function
> callback
) {
1415 runner_
->CopyImageAtAndCapturePixelsAsyncThen(x
, y
, callback
);
1418 void TestRunnerBindings::SetCustomTextOutput(std::string output
) {
1419 runner_
->setCustomTextOutput(output
);
1422 void TestRunnerBindings::SetViewSourceForFrame(const std::string
& name
,
1424 if (runner_
&& runner_
->web_view_
) {
1425 WebFrame
* target_frame
=
1426 runner_
->web_view_
->findFrameByName(WebString::fromUTF8(name
));
1428 target_frame
->enableViewSourceMode(enabled
);
1432 void TestRunnerBindings::SetGeofencingMockProvider(bool service_available
) {
1434 runner_
->SetGeofencingMockProvider(service_available
);
1437 void TestRunnerBindings::ClearGeofencingMockProvider() {
1439 runner_
->ClearGeofencingMockProvider();
1442 void TestRunnerBindings::SetGeofencingMockPosition(double latitude
,
1445 runner_
->SetGeofencingMockPosition(latitude
, longitude
);
1448 void TestRunnerBindings::SetPermission(const std::string
& name
,
1449 const std::string
& value
,
1450 const std::string
& origin
,
1451 const std::string
& embedding_origin
) {
1455 return runner_
->SetPermission(
1456 name
, value
, GURL(origin
), GURL(embedding_origin
));
1459 void TestRunnerBindings::DispatchBeforeInstallPromptEvent(
1461 const std::vector
<std::string
>& event_platforms
,
1462 v8::Local
<v8::Function
> callback
) {
1466 return runner_
->DispatchBeforeInstallPromptEvent(request_id
, event_platforms
,
1470 void TestRunnerBindings::ResolveBeforeInstallPromptPromise(
1472 const std::string
& platform
) {
1476 return runner_
->ResolveBeforeInstallPromptPromise(request_id
, platform
);
1479 std::string
TestRunnerBindings::PlatformName() {
1481 return runner_
->platform_name_
;
1482 return std::string();
1485 std::string
TestRunnerBindings::TooltipText() {
1487 return runner_
->tooltip_text_
;
1488 return std::string();
1491 bool TestRunnerBindings::DisableNotifyDone() {
1493 return runner_
->disable_notify_done_
;
1497 int TestRunnerBindings::WebHistoryItemCount() {
1499 return runner_
->web_history_item_count_
;
1503 bool TestRunnerBindings::InterceptPostMessage() {
1505 return runner_
->intercept_post_message_
;
1509 void TestRunnerBindings::SetInterceptPostMessage(bool value
) {
1511 runner_
->intercept_post_message_
= value
;
1514 void TestRunnerBindings::ForceNextWebGLContextCreationToFail() {
1516 runner_
->ForceNextWebGLContextCreationToFail();
1519 void TestRunnerBindings::ForceNextDrawingBufferCreationToFail() {
1521 runner_
->ForceNextDrawingBufferCreationToFail();
1524 void TestRunnerBindings::NotImplemented(const gin::Arguments
& args
) {
1527 class TestPageOverlay
: public WebPageOverlay
{
1529 TestPageOverlay() {}
1530 virtual ~TestPageOverlay() {}
1532 virtual void paintPageOverlay(WebGraphicsContext
* context
,
1533 const WebSize
& webViewSize
) {
1534 gfx::Rect
rect(webViewSize
);
1535 SkCanvas
* canvas
= context
->beginDrawing(gfx::RectF(rect
));
1537 paint
.setColor(SK_ColorCYAN
);
1538 paint
.setStyle(SkPaint::kFill_Style
);
1539 canvas
->drawRect(gfx::RectToSkRect(rect
), paint
);
1540 context
->endDrawing();
1544 TestRunner::WorkQueue::WorkQueue(TestRunner
* controller
)
1546 , controller_(controller
) {}
1548 TestRunner::WorkQueue::~WorkQueue() {
1552 void TestRunner::WorkQueue::ProcessWorkSoon() {
1553 if (controller_
->topLoadingFrame())
1556 if (!queue_
.empty()) {
1557 // We delay processing queued work to avoid recursion problems.
1558 controller_
->delegate_
->PostTask(new WorkQueueTask(this));
1559 } else if (!controller_
->wait_until_done_
) {
1560 controller_
->delegate_
->TestFinished();
1564 void TestRunner::WorkQueue::Reset() {
1566 while (!queue_
.empty()) {
1567 delete queue_
.front();
1572 void TestRunner::WorkQueue::AddWork(WorkItem
* work
) {
1577 queue_
.push_back(work
);
1580 void TestRunner::WorkQueue::ProcessWork() {
1581 // Quit doing work once a load is in progress.
1582 while (!queue_
.empty()) {
1583 bool startedLoad
= queue_
.front()->Run(controller_
->delegate_
,
1584 controller_
->web_view_
);
1585 delete queue_
.front();
1591 if (!controller_
->wait_until_done_
&& !controller_
->topLoadingFrame())
1592 controller_
->delegate_
->TestFinished();
1595 void TestRunner::WorkQueue::WorkQueueTask::RunIfValid() {
1596 object_
->ProcessWork();
1599 TestRunner::TestRunner(TestInterfaces
* interfaces
)
1600 : test_is_running_(false),
1601 close_remaining_windows_(false),
1603 disable_notify_done_(false),
1604 web_history_item_count_(0),
1605 intercept_post_message_(false),
1606 test_interfaces_(interfaces
),
1609 page_overlay_(nullptr),
1610 web_content_settings_(new WebContentSettings()),
1611 weak_factory_(this) {}
1613 TestRunner::~TestRunner() {}
1615 void TestRunner::Install(WebFrame
* frame
) {
1616 TestRunnerBindings::Install(weak_factory_
.GetWeakPtr(), frame
);
1619 void TestRunner::SetDelegate(WebTestDelegate
* delegate
) {
1620 delegate_
= delegate
;
1621 web_content_settings_
->SetDelegate(delegate
);
1624 void TestRunner::SetWebView(WebView
* webView
, WebTestProxyBase
* proxy
) {
1625 web_view_
= webView
;
1629 void TestRunner::Reset() {
1631 web_view_
->setZoomLevel(0);
1632 web_view_
->setTextZoomFactor(1);
1633 web_view_
->setTabKeyCyclesThroughElements(true);
1634 #if !defined(__APPLE__) && !defined(WIN32) // Actually, TOOLKIT_GTK
1635 // (Constants copied because we can't depend on the header that defined
1636 // them from this file.)
1637 web_view_
->setSelectionColors(
1638 0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232);
1640 web_view_
->setVisibilityState(WebPageVisibilityStateVisible
, true);
1641 web_view_
->mainFrame()->enableViewSourceMode(false);
1643 if (page_overlay_
) {
1644 web_view_
->removePageOverlay(page_overlay_
);
1645 delete page_overlay_
;
1646 page_overlay_
= nullptr;
1650 top_loading_frame_
= nullptr;
1651 wait_until_done_
= false;
1652 wait_until_external_url_load_
= false;
1653 policy_delegate_enabled_
= false;
1654 policy_delegate_is_permissive_
= false;
1655 policy_delegate_should_notify_done_
= false;
1657 WebSecurityPolicy::resetOriginAccessWhitelists();
1658 #if defined(__linux__) || defined(ANDROID)
1659 WebFontRendering::setSubpixelPositioning(false);
1663 // Reset the default quota for each origin to 5MB
1664 delegate_
->SetDatabaseQuota(5 * 1024 * 1024);
1665 delegate_
->SetDeviceColorProfile("reset");
1666 delegate_
->SetDeviceScaleFactor(1);
1667 delegate_
->SetAcceptAllCookies(false);
1668 delegate_
->SetLocale("");
1669 delegate_
->UseUnfortunateSynchronousResizeMode(false);
1670 delegate_
->DisableAutoResizeMode(WebSize());
1671 delegate_
->DeleteAllCookies();
1672 delegate_
->ResetScreenOrientation();
1673 delegate_
->SetBluetoothMockDataSet("");
1674 delegate_
->ClearGeofencingMockProvider();
1675 delegate_
->ResetPermissions();
1676 ResetBatteryStatus();
1680 dump_editting_callbacks_
= false;
1681 dump_as_text_
= false;
1682 dump_as_markup_
= false;
1683 generate_pixel_results_
= true;
1684 dump_child_frame_scroll_positions_
= false;
1685 dump_child_frames_as_markup_
= false;
1686 dump_child_frames_as_text_
= false;
1687 dump_icon_changes_
= false;
1688 dump_as_audio_
= false;
1689 dump_frame_load_callbacks_
= false;
1690 dump_ping_loader_callbacks_
= false;
1691 dump_user_gesture_in_frame_load_callbacks_
= false;
1692 dump_title_changes_
= false;
1693 dump_create_view_
= false;
1694 can_open_windows_
= false;
1695 dump_resource_load_callbacks_
= false;
1696 dump_resource_request_callbacks_
= false;
1697 dump_resource_response_mime_types_
= false;
1698 dump_window_status_changes_
= false;
1699 dump_progress_finished_callback_
= false;
1700 dump_spell_check_callbacks_
= false;
1701 dump_back_forward_list_
= false;
1702 dump_selection_rect_
= false;
1703 dump_drag_image_
= false;
1704 dump_navigation_policy_
= false;
1705 test_repaint_
= false;
1706 sweep_horizontally_
= false;
1707 is_printing_
= false;
1708 midi_accessor_result_
= true;
1709 should_stay_on_page_after_handling_before_unload_
= false;
1710 should_dump_resource_priorities_
= false;
1711 has_custom_text_output_
= false;
1712 custom_text_output_
.clear();
1714 http_headers_to_clear_
.clear();
1716 platform_name_
= "chromium";
1717 tooltip_text_
= std::string();
1718 disable_notify_done_
= false;
1719 web_history_item_count_
= 0;
1720 intercept_post_message_
= false;
1722 web_content_settings_
->Reset();
1724 use_mock_theme_
= true;
1725 pointer_locked_
= false;
1726 pointer_lock_planned_result_
= PointerLockWillSucceed
;
1728 task_list_
.RevokeAll();
1729 work_queue_
.Reset();
1731 if (close_remaining_windows_
&& delegate_
)
1732 delegate_
->CloseRemainingWindows();
1734 close_remaining_windows_
= true;
1737 void TestRunner::SetTestIsRunning(bool running
) {
1738 test_is_running_
= running
;
1741 void TestRunner::InvokeCallback(scoped_ptr
<InvokeCallbackTask
> task
) {
1742 delegate_
->PostTask(task
.release());
1745 bool TestRunner::shouldDumpEditingCallbacks() const {
1746 return dump_editting_callbacks_
;
1749 bool TestRunner::shouldDumpAsText() {
1750 CheckResponseMimeType();
1751 return dump_as_text_
;
1754 void TestRunner::setShouldDumpAsText(bool value
) {
1755 dump_as_text_
= value
;
1758 bool TestRunner::shouldDumpAsMarkup() {
1759 return dump_as_markup_
;
1762 void TestRunner::setShouldDumpAsMarkup(bool value
) {
1763 dump_as_markup_
= value
;
1766 bool TestRunner::shouldDumpAsCustomText() const {
1767 return has_custom_text_output_
;
1770 std::string
TestRunner::customDumpText() const {
1771 return custom_text_output_
;
1774 void TestRunner::setCustomTextOutput(std::string text
) {
1775 custom_text_output_
= text
;
1776 has_custom_text_output_
= true;
1779 bool TestRunner::ShouldGeneratePixelResults() {
1780 CheckResponseMimeType();
1781 return generate_pixel_results_
;
1784 bool TestRunner::ShouldStayOnPageAfterHandlingBeforeUnload() const {
1785 return should_stay_on_page_after_handling_before_unload_
;
1789 void TestRunner::setShouldGeneratePixelResults(bool value
) {
1790 generate_pixel_results_
= value
;
1793 bool TestRunner::shouldDumpChildFrameScrollPositions() const {
1794 return dump_child_frame_scroll_positions_
;
1797 bool TestRunner::shouldDumpChildFramesAsMarkup() const {
1798 return dump_child_frames_as_markup_
;
1801 bool TestRunner::shouldDumpChildFramesAsText() const {
1802 return dump_child_frames_as_text_
;
1805 bool TestRunner::ShouldDumpAsAudio() const {
1806 return dump_as_audio_
;
1809 void TestRunner::GetAudioData(std::vector
<unsigned char>* buffer_view
) const {
1810 *buffer_view
= audio_data_
;
1813 bool TestRunner::shouldDumpFrameLoadCallbacks() const {
1814 return test_is_running_
&& dump_frame_load_callbacks_
;
1817 void TestRunner::setShouldDumpFrameLoadCallbacks(bool value
) {
1818 dump_frame_load_callbacks_
= value
;
1821 bool TestRunner::shouldDumpPingLoaderCallbacks() const {
1822 return test_is_running_
&& dump_ping_loader_callbacks_
;
1825 void TestRunner::setShouldDumpPingLoaderCallbacks(bool value
) {
1826 dump_ping_loader_callbacks_
= value
;
1829 void TestRunner::setShouldEnableViewSource(bool value
) {
1830 web_view_
->mainFrame()->enableViewSourceMode(value
);
1833 bool TestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const {
1834 return test_is_running_
&& dump_user_gesture_in_frame_load_callbacks_
;
1837 bool TestRunner::shouldDumpTitleChanges() const {
1838 return dump_title_changes_
;
1841 bool TestRunner::shouldDumpIconChanges() const {
1842 return dump_icon_changes_
;
1845 bool TestRunner::shouldDumpCreateView() const {
1846 return dump_create_view_
;
1849 bool TestRunner::canOpenWindows() const {
1850 return can_open_windows_
;
1853 bool TestRunner::shouldDumpResourceLoadCallbacks() const {
1854 return test_is_running_
&& dump_resource_load_callbacks_
;
1857 bool TestRunner::shouldDumpResourceRequestCallbacks() const {
1858 return test_is_running_
&& dump_resource_request_callbacks_
;
1861 bool TestRunner::shouldDumpResourceResponseMIMETypes() const {
1862 return test_is_running_
&& dump_resource_response_mime_types_
;
1865 WebContentSettingsClient
* TestRunner::GetWebContentSettings() const {
1866 return web_content_settings_
.get();
1869 bool TestRunner::shouldDumpStatusCallbacks() const {
1870 return dump_window_status_changes_
;
1873 bool TestRunner::shouldDumpProgressFinishedCallback() const {
1874 return dump_progress_finished_callback_
;
1877 bool TestRunner::shouldDumpSpellCheckCallbacks() const {
1878 return dump_spell_check_callbacks_
;
1881 bool TestRunner::ShouldDumpBackForwardList() const {
1882 return dump_back_forward_list_
;
1885 bool TestRunner::shouldDumpSelectionRect() const {
1886 return dump_selection_rect_
;
1889 bool TestRunner::isPrinting() const {
1890 return is_printing_
;
1893 bool TestRunner::shouldWaitUntilExternalURLLoad() const {
1894 return wait_until_external_url_load_
;
1897 const std::set
<std::string
>* TestRunner::httpHeadersToClear() const {
1898 return &http_headers_to_clear_
;
1901 void TestRunner::setTopLoadingFrame(WebFrame
* frame
, bool clear
) {
1902 if (frame
->top()->view() != web_view_
)
1904 if (!test_is_running_
)
1907 top_loading_frame_
= nullptr;
1908 LocationChangeDone();
1909 } else if (!top_loading_frame_
) {
1910 top_loading_frame_
= frame
;
1914 WebFrame
* TestRunner::topLoadingFrame() const {
1915 return top_loading_frame_
;
1918 void TestRunner::policyDelegateDone() {
1919 DCHECK(wait_until_done_
);
1920 delegate_
->TestFinished();
1921 wait_until_done_
= false;
1924 bool TestRunner::policyDelegateEnabled() const {
1925 return policy_delegate_enabled_
;
1928 bool TestRunner::policyDelegateIsPermissive() const {
1929 return policy_delegate_is_permissive_
;
1932 bool TestRunner::policyDelegateShouldNotifyDone() const {
1933 return policy_delegate_should_notify_done_
;
1936 bool TestRunner::shouldInterceptPostMessage() const {
1937 return intercept_post_message_
;
1940 bool TestRunner::shouldDumpResourcePriorities() const {
1941 return should_dump_resource_priorities_
;
1944 bool TestRunner::RequestPointerLock() {
1945 switch (pointer_lock_planned_result_
) {
1946 case PointerLockWillSucceed
:
1947 delegate_
->PostDelayedTask(
1948 new HostMethodTask(this, &TestRunner::DidAcquirePointerLockInternal
),
1951 case PointerLockWillRespondAsync
:
1952 DCHECK(!pointer_locked_
);
1954 case PointerLockWillFailSync
:
1955 DCHECK(!pointer_locked_
);
1963 void TestRunner::RequestPointerUnlock() {
1964 delegate_
->PostDelayedTask(
1965 new HostMethodTask(this, &TestRunner::DidLosePointerLockInternal
), 0);
1968 bool TestRunner::isPointerLocked() {
1969 return pointer_locked_
;
1972 void TestRunner::setToolTipText(const WebString
& text
) {
1973 tooltip_text_
= text
.utf8();
1976 bool TestRunner::shouldDumpDragImage() {
1977 return dump_drag_image_
;
1980 bool TestRunner::shouldDumpNavigationPolicy() const {
1981 return dump_navigation_policy_
;
1984 bool TestRunner::midiAccessorResult() {
1985 return midi_accessor_result_
;
1988 void TestRunner::ClearDevToolsLocalStorage() {
1989 delegate_
->ClearDevToolsLocalStorage();
1992 void TestRunner::ShowDevTools(const std::string
& settings
,
1993 const std::string
& frontend_url
) {
1994 delegate_
->ShowDevTools(settings
, frontend_url
);
1997 class WorkItemBackForward
: public TestRunner::WorkItem
{
1999 WorkItemBackForward(int distance
) : distance_(distance
) {}
2001 bool Run(WebTestDelegate
* delegate
, WebView
*) override
{
2002 delegate
->GoToOffset(distance_
);
2003 return true; // FIXME: Did it really start a navigation?
2010 void TestRunner::NotifyDone() {
2011 if (disable_notify_done_
)
2014 // Test didn't timeout. Kill the timeout timer.
2015 task_list_
.RevokeAll();
2017 CompleteNotifyDone();
2020 void TestRunner::WaitUntilDone() {
2021 wait_until_done_
= true;
2024 void TestRunner::QueueBackNavigation(int how_far_back
) {
2025 work_queue_
.AddWork(new WorkItemBackForward(-how_far_back
));
2028 void TestRunner::QueueForwardNavigation(int how_far_forward
) {
2029 work_queue_
.AddWork(new WorkItemBackForward(how_far_forward
));
2032 class WorkItemReload
: public TestRunner::WorkItem
{
2034 bool Run(WebTestDelegate
* delegate
, WebView
*) override
{
2040 void TestRunner::QueueReload() {
2041 work_queue_
.AddWork(new WorkItemReload());
2044 class WorkItemLoadingScript
: public TestRunner::WorkItem
{
2046 WorkItemLoadingScript(const std::string
& script
)
2047 : script_(script
) {}
2049 bool Run(WebTestDelegate
*, WebView
* web_view
) override
{
2050 web_view
->mainFrame()->executeScript(
2051 WebScriptSource(WebString::fromUTF8(script_
)));
2052 return true; // FIXME: Did it really start a navigation?
2056 std::string script_
;
2059 void TestRunner::QueueLoadingScript(const std::string
& script
) {
2060 work_queue_
.AddWork(new WorkItemLoadingScript(script
));
2063 class WorkItemNonLoadingScript
: public TestRunner::WorkItem
{
2065 WorkItemNonLoadingScript(const std::string
& script
)
2066 : script_(script
) {}
2068 bool Run(WebTestDelegate
*, WebView
* web_view
) override
{
2069 web_view
->mainFrame()->executeScript(
2070 WebScriptSource(WebString::fromUTF8(script_
)));
2075 std::string script_
;
2078 void TestRunner::QueueNonLoadingScript(const std::string
& script
) {
2079 work_queue_
.AddWork(new WorkItemNonLoadingScript(script
));
2082 class WorkItemLoad
: public TestRunner::WorkItem
{
2084 WorkItemLoad(const WebURL
& url
, const std::string
& target
)
2085 : url_(url
), target_(target
) {}
2087 bool Run(WebTestDelegate
* delegate
, WebView
*) override
{
2088 delegate
->LoadURLForFrame(url_
, target_
);
2089 return true; // FIXME: Did it really start a navigation?
2094 std::string target_
;
2097 void TestRunner::QueueLoad(const std::string
& url
, const std::string
& target
) {
2098 // FIXME: Implement WebURL::resolve() and avoid GURL.
2099 GURL current_url
= web_view_
->mainFrame()->document().url();
2100 GURL full_url
= current_url
.Resolve(url
);
2101 work_queue_
.AddWork(new WorkItemLoad(full_url
, target
));
2104 class WorkItemLoadHTMLString
: public TestRunner::WorkItem
{
2106 WorkItemLoadHTMLString(const std::string
& html
, const WebURL
& base_url
)
2107 : html_(html
), base_url_(base_url
) {}
2109 WorkItemLoadHTMLString(const std::string
& html
, const WebURL
& base_url
,
2110 const WebURL
& unreachable_url
)
2111 : html_(html
), base_url_(base_url
), unreachable_url_(unreachable_url
) {}
2113 bool Run(WebTestDelegate
*, WebView
* web_view
) override
{
2114 web_view
->mainFrame()->loadHTMLString(
2115 WebData(html_
.data(), html_
.length()),
2116 base_url_
, unreachable_url_
);
2123 WebURL unreachable_url_
;
2126 void TestRunner::QueueLoadHTMLString(gin::Arguments
* args
) {
2128 args
->GetNext(&html
);
2130 std::string base_url_str
;
2131 args
->GetNext(&base_url_str
);
2132 WebURL base_url
= WebURL(GURL(base_url_str
));
2134 if (args
->PeekNext()->IsString()) {
2135 std::string unreachable_url_str
;
2136 args
->GetNext(&unreachable_url_str
);
2137 WebURL unreachable_url
= WebURL(GURL(unreachable_url_str
));
2138 work_queue_
.AddWork(new WorkItemLoadHTMLString(html
, base_url
,
2141 work_queue_
.AddWork(new WorkItemLoadHTMLString(html
, base_url
));
2145 void TestRunner::SetCustomPolicyDelegate(gin::Arguments
* args
) {
2146 args
->GetNext(&policy_delegate_enabled_
);
2147 if (!args
->PeekNext().IsEmpty() && args
->PeekNext()->IsBoolean())
2148 args
->GetNext(&policy_delegate_is_permissive_
);
2151 void TestRunner::WaitForPolicyDelegate() {
2152 policy_delegate_enabled_
= true;
2153 policy_delegate_should_notify_done_
= true;
2154 wait_until_done_
= true;
2157 int TestRunner::WindowCount() {
2158 return test_interfaces_
->GetWindowList().size();
2161 void TestRunner::SetCloseRemainingWindowsWhenComplete(
2162 bool close_remaining_windows
) {
2163 close_remaining_windows_
= close_remaining_windows
;
2166 void TestRunner::ResetTestHelperControllers() {
2167 test_interfaces_
->ResetTestHelperControllers();
2170 void TestRunner::SetTabKeyCyclesThroughElements(
2171 bool tab_key_cycles_through_elements
) {
2172 web_view_
->setTabKeyCyclesThroughElements(tab_key_cycles_through_elements
);
2175 void TestRunner::ExecCommand(gin::Arguments
* args
) {
2176 std::string command
;
2177 args
->GetNext(&command
);
2180 if (args
->Length() >= 3) {
2181 // Ignore the second parameter (which is userInterface)
2182 // since this command emulates a manual action.
2184 args
->GetNext(&value
);
2187 // Note: webkit's version does not return the boolean, so neither do we.
2188 web_view_
->focusedFrame()->executeCommand(WebString::fromUTF8(command
),
2189 WebString::fromUTF8(value
));
2192 bool TestRunner::IsCommandEnabled(const std::string
& command
) {
2193 return web_view_
->focusedFrame()->isCommandEnabled(
2194 WebString::fromUTF8(command
));
2197 bool TestRunner::CallShouldCloseOnWebView() {
2198 return web_view_
->mainFrame()->dispatchBeforeUnloadEvent();
2201 void TestRunner::SetDomainRelaxationForbiddenForURLScheme(
2202 bool forbidden
, const std::string
& scheme
) {
2203 web_view_
->setDomainRelaxationForbidden(forbidden
,
2204 WebString::fromUTF8(scheme
));
2207 v8::Local
<v8::Value
> TestRunner::EvaluateScriptInIsolatedWorldAndReturnValue(
2209 const std::string
& script
) {
2210 WebVector
<v8::Local
<v8::Value
>> values
;
2211 WebScriptSource
source(WebString::fromUTF8(script
));
2212 // This relies on the iframe focusing itself when it loads. This is a bit
2213 // sketchy, but it seems to be what other tests do.
2214 web_view_
->focusedFrame()->executeScriptInIsolatedWorld(
2215 world_id
, &source
, 1, 1, &values
);
2216 // Since only one script was added, only one result is expected
2217 if (values
.size() == 1 && !values
[0].IsEmpty())
2219 return v8::Local
<v8::Value
>();
2222 void TestRunner::EvaluateScriptInIsolatedWorld(int world_id
,
2223 const std::string
& script
) {
2224 WebScriptSource
source(WebString::fromUTF8(script
));
2225 web_view_
->focusedFrame()->executeScriptInIsolatedWorld(
2226 world_id
, &source
, 1, 1);
2229 void TestRunner::SetIsolatedWorldSecurityOrigin(int world_id
,
2230 v8::Local
<v8::Value
> origin
) {
2231 if (!(origin
->IsString() || !origin
->IsNull()))
2234 WebSecurityOrigin web_origin
;
2235 if (origin
->IsString()) {
2236 web_origin
= WebSecurityOrigin::createFromString(
2237 V8StringToWebString(origin
.As
<v8::String
>()));
2239 web_view_
->focusedFrame()->setIsolatedWorldSecurityOrigin(world_id
,
2243 void TestRunner::SetIsolatedWorldContentSecurityPolicy(
2245 const std::string
& policy
) {
2246 web_view_
->focusedFrame()->setIsolatedWorldContentSecurityPolicy(
2247 world_id
, WebString::fromUTF8(policy
));
2250 void TestRunner::AddOriginAccessWhitelistEntry(
2251 const std::string
& source_origin
,
2252 const std::string
& destination_protocol
,
2253 const std::string
& destination_host
,
2254 bool allow_destination_subdomains
) {
2255 WebURL
url((GURL(source_origin
)));
2259 WebSecurityPolicy::addOriginAccessWhitelistEntry(
2261 WebString::fromUTF8(destination_protocol
),
2262 WebString::fromUTF8(destination_host
),
2263 allow_destination_subdomains
);
2266 void TestRunner::RemoveOriginAccessWhitelistEntry(
2267 const std::string
& source_origin
,
2268 const std::string
& destination_protocol
,
2269 const std::string
& destination_host
,
2270 bool allow_destination_subdomains
) {
2271 WebURL
url((GURL(source_origin
)));
2275 WebSecurityPolicy::removeOriginAccessWhitelistEntry(
2277 WebString::fromUTF8(destination_protocol
),
2278 WebString::fromUTF8(destination_host
),
2279 allow_destination_subdomains
);
2282 bool TestRunner::HasCustomPageSizeStyle(int page_index
) {
2283 WebFrame
* frame
= web_view_
->mainFrame();
2286 return frame
->hasCustomPageSizeStyle(page_index
);
2289 void TestRunner::ForceRedSelectionColors() {
2290 web_view_
->setSelectionColors(0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0);
2293 void TestRunner::InsertStyleSheet(const std::string
& source_code
) {
2294 WebLocalFrame::frameForCurrentContext()->document().insertStyleSheet(
2295 WebString::fromUTF8(source_code
));
2298 bool TestRunner::FindString(const std::string
& search_text
,
2299 const std::vector
<std::string
>& options_array
) {
2300 WebFindOptions find_options
;
2301 bool wrap_around
= false;
2302 find_options
.matchCase
= true;
2303 find_options
.findNext
= true;
2305 for (const std::string
& option
: options_array
) {
2306 if (option
== "CaseInsensitive")
2307 find_options
.matchCase
= false;
2308 else if (option
== "Backwards")
2309 find_options
.forward
= false;
2310 else if (option
== "StartInSelection")
2311 find_options
.findNext
= false;
2312 else if (option
== "AtWordStarts")
2313 find_options
.wordStart
= true;
2314 else if (option
== "TreatMedialCapitalAsWordStart")
2315 find_options
.medialCapitalAsWordStart
= true;
2316 else if (option
== "WrapAround")
2320 WebFrame
* frame
= web_view_
->mainFrame();
2321 const bool find_result
= frame
->find(0, WebString::fromUTF8(search_text
),
2322 find_options
, wrap_around
, 0);
2323 frame
->stopFinding(false);
2327 std::string
TestRunner::SelectionAsMarkup() {
2328 return web_view_
->mainFrame()->selectionAsMarkup().utf8();
2331 void TestRunner::SetTextSubpixelPositioning(bool value
) {
2332 #if defined(__linux__) || defined(ANDROID)
2333 // Since FontConfig doesn't provide a variable to control subpixel
2334 // positioning, we'll fall back to setting it globally for all fonts.
2335 WebFontRendering::setSubpixelPositioning(value
);
2339 void TestRunner::SetPageVisibility(const std::string
& new_visibility
) {
2340 if (new_visibility
== "visible")
2341 web_view_
->setVisibilityState(WebPageVisibilityStateVisible
, false);
2342 else if (new_visibility
== "hidden")
2343 web_view_
->setVisibilityState(WebPageVisibilityStateHidden
, false);
2344 else if (new_visibility
== "prerender")
2345 web_view_
->setVisibilityState(WebPageVisibilityStatePrerender
, false);
2348 void TestRunner::SetTextDirection(const std::string
& direction_name
) {
2349 // Map a direction name to a WebTextDirection value.
2350 WebTextDirection direction
;
2351 if (direction_name
== "auto")
2352 direction
= WebTextDirectionDefault
;
2353 else if (direction_name
== "rtl")
2354 direction
= WebTextDirectionRightToLeft
;
2355 else if (direction_name
== "ltr")
2356 direction
= WebTextDirectionLeftToRight
;
2360 web_view_
->setTextDirection(direction
);
2363 void TestRunner::UseUnfortunateSynchronousResizeMode() {
2364 delegate_
->UseUnfortunateSynchronousResizeMode(true);
2367 bool TestRunner::EnableAutoResizeMode(int min_width
,
2371 WebSize
min_size(min_width
, min_height
);
2372 WebSize
max_size(max_width
, max_height
);
2373 delegate_
->EnableAutoResizeMode(min_size
, max_size
);
2377 bool TestRunner::DisableAutoResizeMode(int new_width
, int new_height
) {
2378 WebSize
new_size(new_width
, new_height
);
2379 delegate_
->DisableAutoResizeMode(new_size
);
2383 void TestRunner::SetMockDeviceLight(double value
) {
2384 delegate_
->SetDeviceLightData(value
);
2387 void TestRunner::ResetDeviceLight() {
2388 delegate_
->SetDeviceLightData(-1);
2391 void TestRunner::SetMockDeviceMotion(
2392 bool has_acceleration_x
, double acceleration_x
,
2393 bool has_acceleration_y
, double acceleration_y
,
2394 bool has_acceleration_z
, double acceleration_z
,
2395 bool has_acceleration_including_gravity_x
,
2396 double acceleration_including_gravity_x
,
2397 bool has_acceleration_including_gravity_y
,
2398 double acceleration_including_gravity_y
,
2399 bool has_acceleration_including_gravity_z
,
2400 double acceleration_including_gravity_z
,
2401 bool has_rotation_rate_alpha
, double rotation_rate_alpha
,
2402 bool has_rotation_rate_beta
, double rotation_rate_beta
,
2403 bool has_rotation_rate_gamma
, double rotation_rate_gamma
,
2405 WebDeviceMotionData motion
;
2408 motion
.hasAccelerationX
= has_acceleration_x
;
2409 motion
.accelerationX
= acceleration_x
;
2410 motion
.hasAccelerationY
= has_acceleration_y
;
2411 motion
.accelerationY
= acceleration_y
;
2412 motion
.hasAccelerationZ
= has_acceleration_z
;
2413 motion
.accelerationZ
= acceleration_z
;
2415 // accelerationIncludingGravity
2416 motion
.hasAccelerationIncludingGravityX
=
2417 has_acceleration_including_gravity_x
;
2418 motion
.accelerationIncludingGravityX
= acceleration_including_gravity_x
;
2419 motion
.hasAccelerationIncludingGravityY
=
2420 has_acceleration_including_gravity_y
;
2421 motion
.accelerationIncludingGravityY
= acceleration_including_gravity_y
;
2422 motion
.hasAccelerationIncludingGravityZ
=
2423 has_acceleration_including_gravity_z
;
2424 motion
.accelerationIncludingGravityZ
= acceleration_including_gravity_z
;
2427 motion
.hasRotationRateAlpha
= has_rotation_rate_alpha
;
2428 motion
.rotationRateAlpha
= rotation_rate_alpha
;
2429 motion
.hasRotationRateBeta
= has_rotation_rate_beta
;
2430 motion
.rotationRateBeta
= rotation_rate_beta
;
2431 motion
.hasRotationRateGamma
= has_rotation_rate_gamma
;
2432 motion
.rotationRateGamma
= rotation_rate_gamma
;
2435 motion
.interval
= interval
;
2437 delegate_
->SetDeviceMotionData(motion
);
2440 void TestRunner::SetMockDeviceOrientation(bool has_alpha
, double alpha
,
2441 bool has_beta
, double beta
,
2442 bool has_gamma
, double gamma
,
2443 bool has_absolute
, bool absolute
) {
2444 WebDeviceOrientationData orientation
;
2447 orientation
.hasAlpha
= has_alpha
;
2448 orientation
.alpha
= alpha
;
2451 orientation
.hasBeta
= has_beta
;
2452 orientation
.beta
= beta
;
2455 orientation
.hasGamma
= has_gamma
;
2456 orientation
.gamma
= gamma
;
2459 orientation
.hasAbsolute
= has_absolute
;
2460 orientation
.absolute
= absolute
;
2462 delegate_
->SetDeviceOrientationData(orientation
);
2465 void TestRunner::SetMockScreenOrientation(const std::string
& orientation_str
) {
2466 blink::WebScreenOrientationType orientation
;
2468 if (orientation_str
== "portrait-primary") {
2469 orientation
= WebScreenOrientationPortraitPrimary
;
2470 } else if (orientation_str
== "portrait-secondary") {
2471 orientation
= WebScreenOrientationPortraitSecondary
;
2472 } else if (orientation_str
== "landscape-primary") {
2473 orientation
= WebScreenOrientationLandscapePrimary
;
2474 } else if (orientation_str
== "landscape-secondary") {
2475 orientation
= WebScreenOrientationLandscapeSecondary
;
2478 delegate_
->SetScreenOrientation(orientation
);
2481 void TestRunner::DidChangeBatteryStatus(bool charging
,
2482 double chargingTime
,
2483 double dischargingTime
,
2485 blink::WebBatteryStatus status
;
2486 status
.charging
= charging
;
2487 status
.chargingTime
= chargingTime
;
2488 status
.dischargingTime
= dischargingTime
;
2489 status
.level
= level
;
2490 delegate_
->DidChangeBatteryStatus(status
);
2493 void TestRunner::ResetBatteryStatus() {
2494 blink::WebBatteryStatus status
;
2495 delegate_
->DidChangeBatteryStatus(status
);
2498 void TestRunner::DidAcquirePointerLock() {
2499 DidAcquirePointerLockInternal();
2502 void TestRunner::DidNotAcquirePointerLock() {
2503 DidNotAcquirePointerLockInternal();
2506 void TestRunner::DidLosePointerLock() {
2507 DidLosePointerLockInternal();
2510 void TestRunner::SetPointerLockWillFailSynchronously() {
2511 pointer_lock_planned_result_
= PointerLockWillFailSync
;
2514 void TestRunner::SetPointerLockWillRespondAsynchronously() {
2515 pointer_lock_planned_result_
= PointerLockWillRespondAsync
;
2518 void TestRunner::SetPopupBlockingEnabled(bool block_popups
) {
2519 delegate_
->Preferences()->java_script_can_open_windows_automatically
=
2521 delegate_
->ApplyPreferences();
2524 void TestRunner::SetJavaScriptCanAccessClipboard(bool can_access
) {
2525 delegate_
->Preferences()->java_script_can_access_clipboard
= can_access
;
2526 delegate_
->ApplyPreferences();
2529 void TestRunner::SetXSSAuditorEnabled(bool enabled
) {
2530 delegate_
->Preferences()->xss_auditor_enabled
= enabled
;
2531 delegate_
->ApplyPreferences();
2534 void TestRunner::SetAllowUniversalAccessFromFileURLs(bool allow
) {
2535 delegate_
->Preferences()->allow_universal_access_from_file_urls
= allow
;
2536 delegate_
->ApplyPreferences();
2539 void TestRunner::SetAllowFileAccessFromFileURLs(bool allow
) {
2540 delegate_
->Preferences()->allow_file_access_from_file_urls
= allow
;
2541 delegate_
->ApplyPreferences();
2544 void TestRunner::OverridePreference(const std::string key
,
2545 v8::Local
<v8::Value
> value
) {
2546 TestPreferences
* prefs
= delegate_
->Preferences();
2547 if (key
== "WebKitDefaultFontSize") {
2548 prefs
->default_font_size
= value
->Int32Value();
2549 } else if (key
== "WebKitMinimumFontSize") {
2550 prefs
->minimum_font_size
= value
->Int32Value();
2551 } else if (key
== "WebKitDefaultTextEncodingName") {
2552 v8::Isolate
* isolate
= blink::mainThreadIsolate();
2553 prefs
->default_text_encoding_name
=
2554 V8StringToWebString(value
->ToString(isolate
));
2555 } else if (key
== "WebKitJavaScriptEnabled") {
2556 prefs
->java_script_enabled
= value
->BooleanValue();
2557 } else if (key
== "WebKitSupportsMultipleWindows") {
2558 prefs
->supports_multiple_windows
= value
->BooleanValue();
2559 } else if (key
== "WebKitDisplayImagesKey") {
2560 prefs
->loads_images_automatically
= value
->BooleanValue();
2561 } else if (key
== "WebKitPluginsEnabled") {
2562 prefs
->plugins_enabled
= value
->BooleanValue();
2563 } else if (key
== "WebKitJavaEnabled") {
2564 prefs
->java_enabled
= value
->BooleanValue();
2565 } else if (key
== "WebKitOfflineWebApplicationCacheEnabled") {
2566 prefs
->offline_web_application_cache_enabled
= value
->BooleanValue();
2567 } else if (key
== "WebKitTabToLinksPreferenceKey") {
2568 prefs
->tabs_to_links
= value
->BooleanValue();
2569 } else if (key
== "WebKitWebGLEnabled") {
2570 prefs
->experimental_webgl_enabled
= value
->BooleanValue();
2571 } else if (key
== "WebKitCSSRegionsEnabled") {
2572 prefs
->experimental_css_regions_enabled
= value
->BooleanValue();
2573 } else if (key
== "WebKitCSSGridLayoutEnabled") {
2574 prefs
->experimental_css_grid_layout_enabled
= value
->BooleanValue();
2575 } else if (key
== "WebKitHyperlinkAuditingEnabled") {
2576 prefs
->hyperlink_auditing_enabled
= value
->BooleanValue();
2577 } else if (key
== "WebKitEnableCaretBrowsing") {
2578 prefs
->caret_browsing_enabled
= value
->BooleanValue();
2579 } else if (key
== "WebKitAllowDisplayingInsecureContent") {
2580 prefs
->allow_display_of_insecure_content
= value
->BooleanValue();
2581 } else if (key
== "WebKitAllowRunningInsecureContent") {
2582 prefs
->allow_running_of_insecure_content
= value
->BooleanValue();
2583 } else if (key
== "WebKitDisableReadingFromCanvas") {
2584 prefs
->disable_reading_from_canvas
= value
->BooleanValue();
2585 } else if (key
== "WebKitStrictMixedContentChecking") {
2586 prefs
->strict_mixed_content_checking
= value
->BooleanValue();
2587 } else if (key
== "WebKitStrictPowerfulFeatureRestrictions") {
2588 prefs
->strict_powerful_feature_restrictions
= value
->BooleanValue();
2589 } else if (key
== "WebKitShouldRespectImageOrientation") {
2590 prefs
->should_respect_image_orientation
= value
->BooleanValue();
2591 } else if (key
== "WebKitWebAudioEnabled") {
2592 DCHECK(value
->BooleanValue());
2593 } else if (key
== "WebKitWebSecurityEnabled") {
2594 prefs
->web_security_enabled
= value
->BooleanValue();
2596 std::string
message("Invalid name for preference: ");
2597 message
.append(key
);
2598 delegate_
->PrintMessage(std::string("CONSOLE MESSAGE: ") + message
+ "\n");
2600 delegate_
->ApplyPreferences();
2603 void TestRunner::SetAcceptLanguages(const std::string
& accept_languages
) {
2604 proxy_
->SetAcceptLanguages(accept_languages
);
2607 void TestRunner::SetPluginsEnabled(bool enabled
) {
2608 delegate_
->Preferences()->plugins_enabled
= enabled
;
2609 delegate_
->ApplyPreferences();
2612 void TestRunner::DumpEditingCallbacks() {
2613 dump_editting_callbacks_
= true;
2616 void TestRunner::DumpAsMarkup() {
2617 dump_as_markup_
= true;
2618 generate_pixel_results_
= false;
2621 void TestRunner::DumpAsText() {
2622 dump_as_text_
= true;
2623 generate_pixel_results_
= false;
2626 void TestRunner::DumpAsTextWithPixelResults() {
2627 dump_as_text_
= true;
2628 generate_pixel_results_
= true;
2631 void TestRunner::DumpChildFrameScrollPositions() {
2632 dump_child_frame_scroll_positions_
= true;
2635 void TestRunner::DumpChildFramesAsMarkup() {
2636 dump_child_frames_as_markup_
= true;
2639 void TestRunner::DumpChildFramesAsText() {
2640 dump_child_frames_as_text_
= true;
2643 void TestRunner::DumpIconChanges() {
2644 dump_icon_changes_
= true;
2647 void TestRunner::SetAudioData(const gin::ArrayBufferView
& view
) {
2648 unsigned char* bytes
= static_cast<unsigned char*>(view
.bytes());
2649 audio_data_
.resize(view
.num_bytes());
2650 std::copy(bytes
, bytes
+ view
.num_bytes(), audio_data_
.begin());
2651 dump_as_audio_
= true;
2654 void TestRunner::DumpFrameLoadCallbacks() {
2655 dump_frame_load_callbacks_
= true;
2658 void TestRunner::DumpPingLoaderCallbacks() {
2659 dump_ping_loader_callbacks_
= true;
2662 void TestRunner::DumpUserGestureInFrameLoadCallbacks() {
2663 dump_user_gesture_in_frame_load_callbacks_
= true;
2666 void TestRunner::DumpTitleChanges() {
2667 dump_title_changes_
= true;
2670 void TestRunner::DumpCreateView() {
2671 dump_create_view_
= true;
2674 void TestRunner::SetCanOpenWindows() {
2675 can_open_windows_
= true;
2678 void TestRunner::DumpResourceLoadCallbacks() {
2679 dump_resource_load_callbacks_
= true;
2682 void TestRunner::DumpResourceRequestCallbacks() {
2683 dump_resource_request_callbacks_
= true;
2686 void TestRunner::DumpResourceResponseMIMETypes() {
2687 dump_resource_response_mime_types_
= true;
2690 void TestRunner::SetImagesAllowed(bool allowed
) {
2691 web_content_settings_
->SetImagesAllowed(allowed
);
2694 void TestRunner::SetMediaAllowed(bool allowed
) {
2695 web_content_settings_
->SetMediaAllowed(allowed
);
2698 void TestRunner::SetScriptsAllowed(bool allowed
) {
2699 web_content_settings_
->SetScriptsAllowed(allowed
);
2702 void TestRunner::SetStorageAllowed(bool allowed
) {
2703 web_content_settings_
->SetStorageAllowed(allowed
);
2706 void TestRunner::SetPluginsAllowed(bool allowed
) {
2707 web_content_settings_
->SetPluginsAllowed(allowed
);
2710 void TestRunner::SetAllowDisplayOfInsecureContent(bool allowed
) {
2711 web_content_settings_
->SetDisplayingInsecureContentAllowed(allowed
);
2714 void TestRunner::SetAllowRunningOfInsecureContent(bool allowed
) {
2715 web_content_settings_
->SetRunningInsecureContentAllowed(allowed
);
2718 void TestRunner::DumpPermissionClientCallbacks() {
2719 web_content_settings_
->SetDumpCallbacks(true);
2722 void TestRunner::DumpWindowStatusChanges() {
2723 dump_window_status_changes_
= true;
2726 void TestRunner::DumpProgressFinishedCallback() {
2727 dump_progress_finished_callback_
= true;
2730 void TestRunner::DumpSpellCheckCallbacks() {
2731 dump_spell_check_callbacks_
= true;
2734 void TestRunner::DumpBackForwardList() {
2735 dump_back_forward_list_
= true;
2738 void TestRunner::DumpSelectionRect() {
2739 dump_selection_rect_
= true;
2742 void TestRunner::SetPrinting() {
2743 is_printing_
= true;
2746 void TestRunner::ClearPrinting() {
2747 is_printing_
= false;
2750 void TestRunner::SetShouldStayOnPageAfterHandlingBeforeUnload(bool value
) {
2751 should_stay_on_page_after_handling_before_unload_
= value
;
2754 void TestRunner::SetWillSendRequestClearHeader(const std::string
& header
) {
2755 if (!header
.empty())
2756 http_headers_to_clear_
.insert(header
);
2759 void TestRunner::DumpResourceRequestPriorities() {
2760 should_dump_resource_priorities_
= true;
2763 void TestRunner::SetUseMockTheme(bool use
) {
2764 use_mock_theme_
= use
;
2767 void TestRunner::ShowWebInspector(const std::string
& str
,
2768 const std::string
& frontend_url
) {
2769 ShowDevTools(str
, frontend_url
);
2772 void TestRunner::WaitUntilExternalURLLoad() {
2773 wait_until_external_url_load_
= true;
2776 void TestRunner::DumpDragImage() {
2777 DumpAsTextWithPixelResults();
2778 dump_drag_image_
= true;
2781 void TestRunner::DumpNavigationPolicy() {
2782 dump_navigation_policy_
= true;
2785 void TestRunner::CloseWebInspector() {
2786 delegate_
->CloseDevTools();
2789 bool TestRunner::IsChooserShown() {
2790 return proxy_
->IsChooserShown();
2793 void TestRunner::EvaluateInWebInspector(int call_id
,
2794 const std::string
& script
) {
2795 delegate_
->EvaluateInWebInspector(call_id
, script
);
2798 void TestRunner::ClearAllDatabases() {
2799 delegate_
->ClearAllDatabases();
2802 void TestRunner::SetDatabaseQuota(int quota
) {
2803 delegate_
->SetDatabaseQuota(quota
);
2806 void TestRunner::SetAlwaysAcceptCookies(bool accept
) {
2807 delegate_
->SetAcceptAllCookies(accept
);
2810 void TestRunner::SetWindowIsKey(bool value
) {
2811 delegate_
->SetFocus(proxy_
, value
);
2814 std::string
TestRunner::PathToLocalResource(const std::string
& path
) {
2815 return delegate_
->PathToLocalResource(path
);
2818 void TestRunner::SetBackingScaleFactor(double value
,
2819 v8::Local
<v8::Function
> callback
) {
2820 delegate_
->SetDeviceScaleFactor(value
);
2821 delegate_
->PostTask(new InvokeCallbackTask(this, callback
));
2824 void TestRunner::SetColorProfile(const std::string
& name
,
2825 v8::Local
<v8::Function
> callback
) {
2826 delegate_
->SetDeviceColorProfile(name
);
2827 delegate_
->PostTask(new InvokeCallbackTask(this, callback
));
2830 void TestRunner::SetBluetoothMockDataSet(const std::string
& name
) {
2831 delegate_
->SetBluetoothMockDataSet(name
);
2834 void TestRunner::SetGeofencingMockProvider(bool service_available
) {
2835 delegate_
->SetGeofencingMockProvider(service_available
);
2838 void TestRunner::ClearGeofencingMockProvider() {
2839 delegate_
->ClearGeofencingMockProvider();
2842 void TestRunner::SetGeofencingMockPosition(double latitude
, double longitude
) {
2843 delegate_
->SetGeofencingMockPosition(latitude
, longitude
);
2846 void TestRunner::SetPermission(const std::string
& name
,
2847 const std::string
& value
,
2849 const GURL
& embedding_origin
) {
2850 delegate_
->SetPermission(name
, value
, origin
, embedding_origin
);
2853 void TestRunner::DispatchBeforeInstallPromptEvent(
2855 const std::vector
<std::string
>& event_platforms
,
2856 v8::Local
<v8::Function
> callback
) {
2857 scoped_ptr
<InvokeCallbackTask
> task(
2858 new InvokeCallbackTask(this, callback
));
2860 delegate_
->DispatchBeforeInstallPromptEvent(
2861 request_id
, event_platforms
,
2862 base::Bind(&TestRunner::DispatchBeforeInstallPromptCallback
,
2863 weak_factory_
.GetWeakPtr(), base::Passed(&task
)));
2866 void TestRunner::ResolveBeforeInstallPromptPromise(
2868 const std::string
& platform
) {
2869 delegate_
->ResolveBeforeInstallPromptPromise(request_id
, platform
);
2872 void TestRunner::SetPOSIXLocale(const std::string
& locale
) {
2873 delegate_
->SetLocale(locale
);
2876 void TestRunner::SetMIDIAccessorResult(bool result
) {
2877 midi_accessor_result_
= result
;
2880 void TestRunner::SimulateWebNotificationClick(const std::string
& title
) {
2881 delegate_
->SimulateWebNotificationClick(title
);
2884 void TestRunner::AddMockSpeechRecognitionResult(const std::string
& transcript
,
2885 double confidence
) {
2886 proxy_
->GetSpeechRecognizerMock()->AddMockResult(
2887 WebString::fromUTF8(transcript
), confidence
);
2890 void TestRunner::SetMockSpeechRecognitionError(const std::string
& error
,
2891 const std::string
& message
) {
2892 proxy_
->GetSpeechRecognizerMock()->SetError(WebString::fromUTF8(error
),
2893 WebString::fromUTF8(message
));
2896 bool TestRunner::WasMockSpeechRecognitionAborted() {
2897 return proxy_
->GetSpeechRecognizerMock()->WasAborted();
2900 void TestRunner::AddMockCredentialManagerResponse(const std::string
& id
,
2901 const std::string
& name
,
2902 const std::string
& avatar
,
2903 const std::string
& password
) {
2904 proxy_
->GetCredentialManagerClientMock()->SetResponse(
2905 new WebPasswordCredential(WebString::fromUTF8(id
),
2906 WebString::fromUTF8(password
),
2907 WebString::fromUTF8(name
),
2908 WebURL(GURL(avatar
))));
2911 void TestRunner::AddWebPageOverlay() {
2912 if (web_view_
&& !page_overlay_
) {
2913 page_overlay_
= new TestPageOverlay
;
2914 web_view_
->addPageOverlay(page_overlay_
, 0);
2918 void TestRunner::RemoveWebPageOverlay() {
2919 if (web_view_
&& page_overlay_
) {
2920 web_view_
->removePageOverlay(page_overlay_
);
2921 delete page_overlay_
;
2922 page_overlay_
= nullptr;
2926 void TestRunner::LayoutAndPaintAsync() {
2927 proxy_
->LayoutAndPaintAsyncThen(base::Closure());
2930 void TestRunner::LayoutAndPaintAsyncThen(v8::Local
<v8::Function
> callback
) {
2931 scoped_ptr
<InvokeCallbackTask
> task(
2932 new InvokeCallbackTask(this, callback
));
2933 proxy_
->LayoutAndPaintAsyncThen(base::Bind(&TestRunner::InvokeCallback
,
2934 weak_factory_
.GetWeakPtr(),
2935 base::Passed(&task
)));
2938 void TestRunner::GetManifestThen(v8::Local
<v8::Function
> callback
) {
2939 scoped_ptr
<InvokeCallbackTask
> task(
2940 new InvokeCallbackTask(this, callback
));
2942 delegate_
->FetchManifest(
2943 web_view_
, web_view_
->mainFrame()->document().manifestURL(),
2944 base::Bind(&TestRunner::GetManifestCallback
, weak_factory_
.GetWeakPtr(),
2945 base::Passed(&task
)));
2948 void TestRunner::CapturePixelsAsyncThen(v8::Local
<v8::Function
> callback
) {
2949 scoped_ptr
<InvokeCallbackTask
> task(
2950 new InvokeCallbackTask(this, callback
));
2951 proxy_
->CapturePixelsAsync(base::Bind(&TestRunner::CapturePixelsCallback
,
2952 weak_factory_
.GetWeakPtr(),
2953 base::Passed(&task
)));
2956 void TestRunner::ForceNextWebGLContextCreationToFail() {
2958 web_view_
->forceNextWebGLContextCreationToFail();
2961 void TestRunner::ForceNextDrawingBufferCreationToFail() {
2963 web_view_
->forceNextDrawingBufferCreationToFail();
2966 void TestRunner::CopyImageAtAndCapturePixelsAsyncThen(
2967 int x
, int y
, v8::Local
<v8::Function
> callback
) {
2968 scoped_ptr
<InvokeCallbackTask
> task(
2969 new InvokeCallbackTask(this, callback
));
2970 proxy_
->CopyImageAtAndCapturePixels(
2971 x
, y
, base::Bind(&TestRunner::CapturePixelsCallback
,
2972 weak_factory_
.GetWeakPtr(),
2973 base::Passed(&task
)));
2976 void TestRunner::GetManifestCallback(scoped_ptr
<InvokeCallbackTask
> task
,
2977 const blink::WebURLResponse
& response
,
2978 const std::string
& data
) {
2979 InvokeCallback(task
.Pass());
2982 void TestRunner::CapturePixelsCallback(scoped_ptr
<InvokeCallbackTask
> task
,
2983 const SkBitmap
& snapshot
) {
2984 v8::Isolate
* isolate
= blink::mainThreadIsolate();
2985 v8::HandleScope
handle_scope(isolate
);
2987 v8::Local
<v8::Context
> context
=
2988 web_view_
->mainFrame()->mainWorldScriptContext();
2989 if (context
.IsEmpty())
2992 v8::Context::Scope
context_scope(context
);
2993 v8::Local
<v8::Value
> argv
[3];
2994 SkAutoLockPixels
snapshot_lock(snapshot
);
2996 // Size can be 0 for cases where copyImageAt was called on position
2997 // that doesn't have an image.
2998 int width
= snapshot
.info().width();
2999 argv
[0] = v8::Number::New(isolate
, width
);
3001 int height
= snapshot
.info().height();
3002 argv
[1] = v8::Number::New(isolate
, height
);
3004 blink::WebArrayBuffer buffer
=
3005 blink::WebArrayBuffer::create(snapshot
.getSize(), 1);
3006 memcpy(buffer
.data(), snapshot
.getPixels(), buffer
.byteLength());
3007 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT
3009 // Skia's internal byte order is BGRA. Must swap the B and R channels in
3010 // order to provide a consistent ordering to the layout tests.
3011 unsigned char* pixels
= static_cast<unsigned char*>(buffer
.data());
3012 unsigned len
= buffer
.byteLength();
3013 for (unsigned i
= 0; i
< len
; i
+= 4) {
3014 std::swap(pixels
[i
], pixels
[i
+ 2]);
3019 argv
[2] = blink::WebArrayBufferConverter::toV8Value(
3020 &buffer
, context
->Global(), isolate
);
3022 task
->SetArguments(3, argv
);
3023 InvokeCallback(task
.Pass());
3026 void TestRunner::DispatchBeforeInstallPromptCallback(
3027 scoped_ptr
<InvokeCallbackTask
> task
,
3029 v8::Isolate
* isolate
= blink::mainThreadIsolate();
3030 v8::HandleScope
handle_scope(isolate
);
3032 v8::Local
<v8::Context
> context
=
3033 web_view_
->mainFrame()->mainWorldScriptContext();
3034 if (context
.IsEmpty())
3037 v8::Context::Scope
context_scope(context
);
3038 v8::Local
<v8::Value
> argv
[1];
3039 argv
[0] = v8::Boolean::New(isolate
, canceled
);
3041 task
->SetArguments(1, argv
);
3042 InvokeCallback(task
.Pass());
3045 void TestRunner::LocationChangeDone() {
3046 web_history_item_count_
= delegate_
->NavigationEntryCount();
3048 // No more new work after the first complete load.
3049 work_queue_
.set_frozen(true);
3051 if (!wait_until_done_
)
3052 work_queue_
.ProcessWorkSoon();
3055 void TestRunner::CheckResponseMimeType() {
3056 // Text output: the test page can request different types of output which we
3058 if (!dump_as_text_
) {
3059 std::string mimeType
=
3060 web_view_
->mainFrame()->dataSource()->response().mimeType().utf8();
3061 if (mimeType
== "text/plain") {
3062 dump_as_text_
= true;
3063 generate_pixel_results_
= false;
3068 void TestRunner::CompleteNotifyDone() {
3069 if (wait_until_done_
&& !topLoadingFrame() && work_queue_
.is_empty())
3070 delegate_
->TestFinished();
3071 wait_until_done_
= false;
3074 void TestRunner::DidAcquirePointerLockInternal() {
3075 pointer_locked_
= true;
3076 web_view_
->didAcquirePointerLock();
3078 // Reset planned result to default.
3079 pointer_lock_planned_result_
= PointerLockWillSucceed
;
3082 void TestRunner::DidNotAcquirePointerLockInternal() {
3083 DCHECK(!pointer_locked_
);
3084 pointer_locked_
= false;
3085 web_view_
->didNotAcquirePointerLock();
3087 // Reset planned result to default.
3088 pointer_lock_planned_result_
= PointerLockWillSucceed
;
3091 void TestRunner::DidLosePointerLockInternal() {
3092 bool was_locked
= pointer_locked_
;
3093 pointer_locked_
= false;
3095 web_view_
->didLosePointerLock();
3098 } // namespace test_runner