Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / components / test_runner / test_runner.cc
blob0d1315789a530d5f3e18753177e223deedc47dd7
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"
7 #include <limits>
9 #include "base/logging.h"
10 #include "components/test_runner/mock_credential_manager_client.h"
11 #include "components/test_runner/mock_web_speech_recognizer.h"
12 #include "components/test_runner/test_interfaces.h"
13 #include "components/test_runner/test_preferences.h"
14 #include "components/test_runner/web_content_settings.h"
15 #include "components/test_runner/web_test_delegate.h"
16 #include "components/test_runner/web_test_proxy.h"
17 #include "gin/arguments.h"
18 #include "gin/array_buffer.h"
19 #include "gin/handle.h"
20 #include "gin/object_template_builder.h"
21 #include "gin/wrappable.h"
22 #include "third_party/WebKit/public/platform/WebBatteryStatus.h"
23 #include "third_party/WebKit/public/platform/WebCanvas.h"
24 #include "third_party/WebKit/public/platform/WebData.h"
25 #include "third_party/WebKit/public/platform/WebPasswordCredential.h"
26 #include "third_party/WebKit/public/platform/WebPoint.h"
27 #include "third_party/WebKit/public/platform/WebURLResponse.h"
28 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceMotionData.h"
29 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceOrientationData.h"
30 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWorkerRegistration.h"
31 #include "third_party/WebKit/public/web/WebArrayBuffer.h"
32 #include "third_party/WebKit/public/web/WebArrayBufferConverter.h"
33 #include "third_party/WebKit/public/web/WebBindings.h"
34 #include "third_party/WebKit/public/web/WebDataSource.h"
35 #include "third_party/WebKit/public/web/WebDocument.h"
36 #include "third_party/WebKit/public/web/WebFindOptions.h"
37 #include "third_party/WebKit/public/web/WebFrame.h"
38 #include "third_party/WebKit/public/web/WebGraphicsContext.h"
39 #include "third_party/WebKit/public/web/WebInputElement.h"
40 #include "third_party/WebKit/public/web/WebKit.h"
41 #include "third_party/WebKit/public/web/WebLocalFrame.h"
42 #include "third_party/WebKit/public/web/WebScriptSource.h"
43 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
44 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
45 #include "third_party/WebKit/public/web/WebSettings.h"
46 #include "third_party/WebKit/public/web/WebSurroundingText.h"
47 #include "third_party/WebKit/public/web/WebView.h"
48 #include "third_party/skia/include/core/SkBitmap.h"
49 #include "third_party/skia/include/core/SkCanvas.h"
50 #include "ui/gfx/geometry/rect.h"
51 #include "ui/gfx/geometry/rect_f.h"
52 #include "ui/gfx/geometry/size.h"
53 #include "ui/gfx/skia_util.h"
55 #if defined(__linux__) || defined(ANDROID)
56 #include "third_party/WebKit/public/web/linux/WebFontRendering.h"
57 #endif
59 using namespace blink;
61 namespace test_runner {
63 namespace {
65 WebString V8StringToWebString(v8::Local<v8::String> v8_str) {
66 int length = v8_str->Utf8Length() + 1;
67 scoped_ptr<char[]> chars(new char[length]);
68 v8_str->WriteUtf8(chars.get(), length);
69 return WebString::fromUTF8(chars.get());
72 class HostMethodTask : public WebMethodTask<TestRunner> {
73 public:
74 typedef void (TestRunner::*CallbackMethodType)();
75 HostMethodTask(TestRunner* object, CallbackMethodType callback)
76 : WebMethodTask<TestRunner>(object), callback_(callback) {}
78 void RunIfValid() override { (object_->*callback_)(); }
80 private:
81 CallbackMethodType callback_;
84 } // namespace
86 class InvokeCallbackTask : public WebMethodTask<TestRunner> {
87 public:
88 InvokeCallbackTask(TestRunner* object, v8::Local<v8::Function> callback)
89 : WebMethodTask<TestRunner>(object),
90 callback_(blink::mainThreadIsolate(), callback),
91 argc_(0) {}
93 void RunIfValid() override {
94 v8::Isolate* isolate = blink::mainThreadIsolate();
95 v8::HandleScope handle_scope(isolate);
96 WebFrame* frame = object_->web_view_->mainFrame();
98 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
99 if (context.IsEmpty())
100 return;
102 v8::Context::Scope context_scope(context);
104 scoped_ptr<v8::Local<v8::Value>[]> local_argv;
105 if (argc_) {
106 local_argv.reset(new v8::Local<v8::Value>[argc_]);
107 for (int i = 0; i < argc_; ++i)
108 local_argv[i] = v8::Local<v8::Value>::New(isolate, argv_[i]);
111 frame->callFunctionEvenIfScriptDisabled(
112 v8::Local<v8::Function>::New(isolate, callback_),
113 context->Global(),
114 argc_,
115 local_argv.get());
118 void SetArguments(int argc, v8::Local<v8::Value> argv[]) {
119 v8::Isolate* isolate = blink::mainThreadIsolate();
120 argc_ = argc;
121 argv_.reset(new v8::UniquePersistent<v8::Value>[argc]);
122 for (int i = 0; i < argc; ++i)
123 argv_[i] = v8::UniquePersistent<v8::Value>(isolate, argv[i]);
126 private:
127 v8::UniquePersistent<v8::Function> callback_;
128 int argc_;
129 scoped_ptr<v8::UniquePersistent<v8::Value>[]> argv_;
132 class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
133 public:
134 static gin::WrapperInfo kWrapperInfo;
136 static void Install(base::WeakPtr<TestRunner> controller,
137 WebFrame* frame);
139 private:
140 explicit TestRunnerBindings(
141 base::WeakPtr<TestRunner> controller);
142 ~TestRunnerBindings() override;
144 // gin::Wrappable:
145 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
146 v8::Isolate* isolate) override;
148 void LogToStderr(const std::string& output);
149 void NotifyDone();
150 void WaitUntilDone();
151 void QueueBackNavigation(int how_far_back);
152 void QueueForwardNavigation(int how_far_forward);
153 void QueueReload();
154 void QueueLoadingScript(const std::string& script);
155 void QueueNonLoadingScript(const std::string& script);
156 void QueueLoad(gin::Arguments* args);
157 void QueueLoadHTMLString(gin::Arguments* args);
158 void SetCustomPolicyDelegate(gin::Arguments* args);
159 void WaitForPolicyDelegate();
160 int WindowCount();
161 void SetCloseRemainingWindowsWhenComplete(gin::Arguments* args);
162 void ResetTestHelperControllers();
163 void SetTabKeyCyclesThroughElements(bool tab_key_cycles_through_elements);
164 void ExecCommand(gin::Arguments* args);
165 bool IsCommandEnabled(const std::string& command);
166 bool CallShouldCloseOnWebView();
167 void SetDomainRelaxationForbiddenForURLScheme(bool forbidden,
168 const std::string& scheme);
169 v8::Local<v8::Value> EvaluateScriptInIsolatedWorldAndReturnValue(
170 int world_id, const std::string& script);
171 void EvaluateScriptInIsolatedWorld(int world_id, const std::string& script);
172 void SetIsolatedWorldSecurityOrigin(int world_id,
173 v8::Local<v8::Value> origin);
174 void SetIsolatedWorldContentSecurityPolicy(int world_id,
175 const std::string& policy);
176 void AddOriginAccessWhitelistEntry(const std::string& source_origin,
177 const std::string& destination_protocol,
178 const std::string& destination_host,
179 bool allow_destination_subdomains);
180 void RemoveOriginAccessWhitelistEntry(const std::string& source_origin,
181 const std::string& destination_protocol,
182 const std::string& destination_host,
183 bool allow_destination_subdomains);
184 bool HasCustomPageSizeStyle(int page_index);
185 void ForceRedSelectionColors();
186 void InsertStyleSheet(const std::string& source_code);
187 bool FindString(const std::string& search_text,
188 const std::vector<std::string>& options_array);
189 std::string SelectionAsMarkup();
190 void SetTextSubpixelPositioning(bool value);
191 void SetPageVisibility(const std::string& new_visibility);
192 void SetTextDirection(const std::string& direction_name);
193 void UseUnfortunateSynchronousResizeMode();
194 bool EnableAutoResizeMode(int min_width,
195 int min_height,
196 int max_width,
197 int max_height);
198 bool DisableAutoResizeMode(int new_width, int new_height);
199 void SetMockDeviceLight(double value);
200 void ResetDeviceLight();
201 void SetMockDeviceMotion(gin::Arguments* args);
202 void SetMockDeviceOrientation(gin::Arguments* args);
203 void SetMockScreenOrientation(const std::string& orientation);
204 void DidChangeBatteryStatus(bool charging,
205 double chargingTime,
206 double dischargingTime,
207 double level);
208 void ResetBatteryStatus();
209 void DidAcquirePointerLock();
210 void DidNotAcquirePointerLock();
211 void DidLosePointerLock();
212 void SetPointerLockWillFailSynchronously();
213 void SetPointerLockWillRespondAsynchronously();
214 void SetPopupBlockingEnabled(bool block_popups);
215 void SetJavaScriptCanAccessClipboard(bool can_access);
216 void SetXSSAuditorEnabled(bool enabled);
217 void SetAllowUniversalAccessFromFileURLs(bool allow);
218 void SetAllowFileAccessFromFileURLs(bool allow);
219 void OverridePreference(const std::string key, v8::Local<v8::Value> value);
220 void SetAcceptLanguages(const std::string& accept_languages);
221 void SetPluginsEnabled(bool enabled);
222 void DumpEditingCallbacks();
223 void DumpAsMarkup();
224 void DumpAsText();
225 void DumpAsTextWithPixelResults();
226 void DumpChildFrameScrollPositions();
227 void DumpChildFramesAsMarkup();
228 void DumpChildFramesAsText();
229 void DumpIconChanges();
230 void SetAudioData(const gin::ArrayBufferView& view);
231 void DumpFrameLoadCallbacks();
232 void DumpPingLoaderCallbacks();
233 void DumpUserGestureInFrameLoadCallbacks();
234 void DumpTitleChanges();
235 void DumpCreateView();
236 void SetCanOpenWindows();
237 void DumpResourceLoadCallbacks();
238 void DumpResourceRequestCallbacks();
239 void DumpResourceResponseMIMETypes();
240 void SetImagesAllowed(bool allowed);
241 void SetMediaAllowed(bool allowed);
242 void SetScriptsAllowed(bool allowed);
243 void SetStorageAllowed(bool allowed);
244 void SetPluginsAllowed(bool allowed);
245 void SetAllowDisplayOfInsecureContent(bool allowed);
246 void SetAllowRunningOfInsecureContent(bool allowed);
247 void DumpPermissionClientCallbacks();
248 void DumpWindowStatusChanges();
249 void DumpProgressFinishedCallback();
250 void DumpSpellCheckCallbacks();
251 void DumpBackForwardList();
252 void DumpSelectionRect();
253 void SetPrinting();
254 void ClearPrinting();
255 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
256 void SetWillSendRequestClearHeader(const std::string& header);
257 void DumpResourceRequestPriorities();
258 void SetUseMockTheme(bool use);
259 void WaitUntilExternalURLLoad();
260 void DumpDragImage();
261 void DumpNavigationPolicy();
262 void ShowWebInspector(gin::Arguments* args);
263 void CloseWebInspector();
264 bool IsChooserShown();
265 void EvaluateInWebInspector(int call_id, const std::string& script);
266 void ClearAllDatabases();
267 void SetDatabaseQuota(int quota);
268 void SetAlwaysAcceptCookies(bool accept);
269 void SetWindowIsKey(bool value);
270 std::string PathToLocalResource(const std::string& path);
271 void SetBackingScaleFactor(double value, v8::Local<v8::Function> callback);
272 void SetColorProfile(const std::string& name,
273 v8::Local<v8::Function> callback);
274 void SetPOSIXLocale(const std::string& locale);
275 void SetMIDIAccessorResult(bool result);
276 void SimulateWebNotificationClick(gin::Arguments* args);
277 void AddMockSpeechRecognitionResult(const std::string& transcript,
278 double confidence);
279 void SetMockSpeechRecognitionError(const std::string& error,
280 const std::string& message);
281 bool WasMockSpeechRecognitionAborted();
282 void AddMockCredentialManagerResponse(const std::string& id,
283 const std::string& name,
284 const std::string& avatar,
285 const std::string& password);
286 void AddWebPageOverlay();
287 void RemoveWebPageOverlay();
288 void LayoutAndPaintAsync();
289 void LayoutAndPaintAsyncThen(v8::Local<v8::Function> callback);
290 void GetManifestThen(v8::Local<v8::Function> callback);
291 void CapturePixelsAsyncThen(v8::Local<v8::Function> callback);
292 void CopyImageAtAndCapturePixelsAsyncThen(int x,
293 int y,
294 v8::Local<v8::Function> callback);
295 void SetCustomTextOutput(std::string output);
296 void SetViewSourceForFrame(const std::string& name, bool enabled);
297 void SetBluetoothMockDataSet(const std::string& dataset_name);
298 void SetBluetoothManualChooser();
299 std::vector<std::string> GetBluetoothManualChooserEvents();
300 void SendBluetoothManualChooserEvent(const std::string& event,
301 const std::string& argument);
302 void SetGeofencingMockProvider(bool service_available);
303 void ClearGeofencingMockProvider();
304 void SetGeofencingMockPosition(double latitude, double longitude);
305 void SetPermission(const std::string& name,
306 const std::string& value,
307 const std::string& origin,
308 const std::string& embedding_origin);
309 void DispatchBeforeInstallPromptEvent(
310 int request_id,
311 const std::vector<std::string>& event_platforms,
312 v8::Local<v8::Function> callback);
313 void ResolveBeforeInstallPromptPromise(int request_id,
314 const std::string& platform);
316 std::string PlatformName();
317 std::string TooltipText();
318 bool DisableNotifyDone();
319 int WebHistoryItemCount();
320 bool InterceptPostMessage();
321 void SetInterceptPostMessage(bool value);
323 void NotImplemented(const gin::Arguments& args);
325 void ForceNextWebGLContextCreationToFail();
326 void ForceNextDrawingBufferCreationToFail();
328 base::WeakPtr<TestRunner> runner_;
330 DISALLOW_COPY_AND_ASSIGN(TestRunnerBindings);
333 gin::WrapperInfo TestRunnerBindings::kWrapperInfo = {
334 gin::kEmbedderNativeGin};
336 // static
337 void TestRunnerBindings::Install(base::WeakPtr<TestRunner> runner,
338 WebFrame* frame) {
339 v8::Isolate* isolate = blink::mainThreadIsolate();
340 v8::HandleScope handle_scope(isolate);
341 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
342 if (context.IsEmpty())
343 return;
345 v8::Context::Scope context_scope(context);
347 TestRunnerBindings* wrapped = new TestRunnerBindings(runner);
348 gin::Handle<TestRunnerBindings> bindings =
349 gin::CreateHandle(isolate, wrapped);
350 if (bindings.IsEmpty())
351 return;
352 v8::Local<v8::Object> global = context->Global();
353 v8::Local<v8::Value> v8_bindings = bindings.ToV8();
355 std::vector<std::string> names;
356 names.push_back("testRunner");
357 names.push_back("layoutTestController");
358 for (size_t i = 0; i < names.size(); ++i)
359 global->Set(gin::StringToV8(isolate, names[i].c_str()), v8_bindings);
362 TestRunnerBindings::TestRunnerBindings(base::WeakPtr<TestRunner> runner)
363 : runner_(runner) {}
365 TestRunnerBindings::~TestRunnerBindings() {}
367 gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
368 v8::Isolate* isolate) {
369 return gin::Wrappable<TestRunnerBindings>::GetObjectTemplateBuilder(isolate)
370 // Methods controlling test execution.
371 .SetMethod("logToStderr", &TestRunnerBindings::LogToStderr)
372 .SetMethod("notifyDone", &TestRunnerBindings::NotifyDone)
373 .SetMethod("waitUntilDone", &TestRunnerBindings::WaitUntilDone)
374 .SetMethod("queueBackNavigation",
375 &TestRunnerBindings::QueueBackNavigation)
376 .SetMethod("queueForwardNavigation",
377 &TestRunnerBindings::QueueForwardNavigation)
378 .SetMethod("queueReload", &TestRunnerBindings::QueueReload)
379 .SetMethod("queueLoadingScript", &TestRunnerBindings::QueueLoadingScript)
380 .SetMethod("queueNonLoadingScript",
381 &TestRunnerBindings::QueueNonLoadingScript)
382 .SetMethod("queueLoad", &TestRunnerBindings::QueueLoad)
383 .SetMethod("queueLoadHTMLString",
384 &TestRunnerBindings::QueueLoadHTMLString)
385 .SetMethod("setCustomPolicyDelegate",
386 &TestRunnerBindings::SetCustomPolicyDelegate)
387 .SetMethod("waitForPolicyDelegate",
388 &TestRunnerBindings::WaitForPolicyDelegate)
389 .SetMethod("windowCount", &TestRunnerBindings::WindowCount)
390 .SetMethod("setCloseRemainingWindowsWhenComplete",
391 &TestRunnerBindings::SetCloseRemainingWindowsWhenComplete)
392 .SetMethod("resetTestHelperControllers",
393 &TestRunnerBindings::ResetTestHelperControllers)
394 .SetMethod("setTabKeyCyclesThroughElements",
395 &TestRunnerBindings::SetTabKeyCyclesThroughElements)
396 .SetMethod("execCommand", &TestRunnerBindings::ExecCommand)
397 .SetMethod("isCommandEnabled", &TestRunnerBindings::IsCommandEnabled)
398 .SetMethod("callShouldCloseOnWebView",
399 &TestRunnerBindings::CallShouldCloseOnWebView)
400 .SetMethod("setDomainRelaxationForbiddenForURLScheme",
401 &TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme)
402 .SetMethod(
403 "evaluateScriptInIsolatedWorldAndReturnValue",
404 &TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue)
405 .SetMethod("evaluateScriptInIsolatedWorld",
406 &TestRunnerBindings::EvaluateScriptInIsolatedWorld)
407 .SetMethod("setIsolatedWorldSecurityOrigin",
408 &TestRunnerBindings::SetIsolatedWorldSecurityOrigin)
409 .SetMethod("setIsolatedWorldContentSecurityPolicy",
410 &TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy)
411 .SetMethod("addOriginAccessWhitelistEntry",
412 &TestRunnerBindings::AddOriginAccessWhitelistEntry)
413 .SetMethod("removeOriginAccessWhitelistEntry",
414 &TestRunnerBindings::RemoveOriginAccessWhitelistEntry)
415 .SetMethod("hasCustomPageSizeStyle",
416 &TestRunnerBindings::HasCustomPageSizeStyle)
417 .SetMethod("forceRedSelectionColors",
418 &TestRunnerBindings::ForceRedSelectionColors)
419 .SetMethod("insertStyleSheet", &TestRunnerBindings::InsertStyleSheet)
420 .SetMethod("findString", &TestRunnerBindings::FindString)
421 .SetMethod("selectionAsMarkup", &TestRunnerBindings::SelectionAsMarkup)
422 .SetMethod("setTextSubpixelPositioning",
423 &TestRunnerBindings::SetTextSubpixelPositioning)
424 .SetMethod("setPageVisibility", &TestRunnerBindings::SetPageVisibility)
425 .SetMethod("setTextDirection", &TestRunnerBindings::SetTextDirection)
426 .SetMethod("useUnfortunateSynchronousResizeMode",
427 &TestRunnerBindings::UseUnfortunateSynchronousResizeMode)
428 .SetMethod("enableAutoResizeMode",
429 &TestRunnerBindings::EnableAutoResizeMode)
430 .SetMethod("disableAutoResizeMode",
431 &TestRunnerBindings::DisableAutoResizeMode)
432 .SetMethod("setMockDeviceLight", &TestRunnerBindings::SetMockDeviceLight)
433 .SetMethod("resetDeviceLight", &TestRunnerBindings::ResetDeviceLight)
434 .SetMethod("setMockDeviceMotion",
435 &TestRunnerBindings::SetMockDeviceMotion)
436 .SetMethod("setMockDeviceOrientation",
437 &TestRunnerBindings::SetMockDeviceOrientation)
438 .SetMethod("setMockScreenOrientation",
439 &TestRunnerBindings::SetMockScreenOrientation)
440 .SetMethod("didChangeBatteryStatus",
441 &TestRunnerBindings::DidChangeBatteryStatus)
442 .SetMethod("resetBatteryStatus", &TestRunnerBindings::ResetBatteryStatus)
443 .SetMethod("didAcquirePointerLock",
444 &TestRunnerBindings::DidAcquirePointerLock)
445 .SetMethod("didNotAcquirePointerLock",
446 &TestRunnerBindings::DidNotAcquirePointerLock)
447 .SetMethod("didLosePointerLock", &TestRunnerBindings::DidLosePointerLock)
448 .SetMethod("setPointerLockWillFailSynchronously",
449 &TestRunnerBindings::SetPointerLockWillFailSynchronously)
450 .SetMethod("setPointerLockWillRespondAsynchronously",
451 &TestRunnerBindings::SetPointerLockWillRespondAsynchronously)
452 .SetMethod("setPopupBlockingEnabled",
453 &TestRunnerBindings::SetPopupBlockingEnabled)
454 .SetMethod("setJavaScriptCanAccessClipboard",
455 &TestRunnerBindings::SetJavaScriptCanAccessClipboard)
456 .SetMethod("setXSSAuditorEnabled",
457 &TestRunnerBindings::SetXSSAuditorEnabled)
458 .SetMethod("setAllowUniversalAccessFromFileURLs",
459 &TestRunnerBindings::SetAllowUniversalAccessFromFileURLs)
460 .SetMethod("setAllowFileAccessFromFileURLs",
461 &TestRunnerBindings::SetAllowFileAccessFromFileURLs)
462 .SetMethod("overridePreference", &TestRunnerBindings::OverridePreference)
463 .SetMethod("setAcceptLanguages", &TestRunnerBindings::SetAcceptLanguages)
464 .SetMethod("setPluginsEnabled", &TestRunnerBindings::SetPluginsEnabled)
465 .SetMethod("dumpEditingCallbacks",
466 &TestRunnerBindings::DumpEditingCallbacks)
467 .SetMethod("dumpAsMarkup", &TestRunnerBindings::DumpAsMarkup)
468 .SetMethod("dumpAsText", &TestRunnerBindings::DumpAsText)
469 .SetMethod("dumpAsTextWithPixelResults",
470 &TestRunnerBindings::DumpAsTextWithPixelResults)
471 .SetMethod("dumpChildFrameScrollPositions",
472 &TestRunnerBindings::DumpChildFrameScrollPositions)
473 .SetMethod("dumpChildFramesAsText",
474 &TestRunnerBindings::DumpChildFramesAsText)
475 .SetMethod("dumpChildFramesAsMarkup",
476 &TestRunnerBindings::DumpChildFramesAsMarkup)
477 .SetMethod("dumpIconChanges", &TestRunnerBindings::DumpIconChanges)
478 .SetMethod("setAudioData", &TestRunnerBindings::SetAudioData)
479 .SetMethod("dumpFrameLoadCallbacks",
480 &TestRunnerBindings::DumpFrameLoadCallbacks)
481 .SetMethod("dumpPingLoaderCallbacks",
482 &TestRunnerBindings::DumpPingLoaderCallbacks)
483 .SetMethod("dumpUserGestureInFrameLoadCallbacks",
484 &TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks)
485 .SetMethod("dumpTitleChanges", &TestRunnerBindings::DumpTitleChanges)
486 .SetMethod("dumpCreateView", &TestRunnerBindings::DumpCreateView)
487 .SetMethod("setCanOpenWindows", &TestRunnerBindings::SetCanOpenWindows)
488 .SetMethod("dumpResourceLoadCallbacks",
489 &TestRunnerBindings::DumpResourceLoadCallbacks)
490 .SetMethod("dumpResourceRequestCallbacks",
491 &TestRunnerBindings::DumpResourceRequestCallbacks)
492 .SetMethod("dumpResourceResponseMIMETypes",
493 &TestRunnerBindings::DumpResourceResponseMIMETypes)
494 .SetMethod("setImagesAllowed", &TestRunnerBindings::SetImagesAllowed)
495 .SetMethod("setMediaAllowed", &TestRunnerBindings::SetMediaAllowed)
496 .SetMethod("setScriptsAllowed", &TestRunnerBindings::SetScriptsAllowed)
497 .SetMethod("setStorageAllowed", &TestRunnerBindings::SetStorageAllowed)
498 .SetMethod("setPluginsAllowed", &TestRunnerBindings::SetPluginsAllowed)
499 .SetMethod("setAllowDisplayOfInsecureContent",
500 &TestRunnerBindings::SetAllowDisplayOfInsecureContent)
501 .SetMethod("setAllowRunningOfInsecureContent",
502 &TestRunnerBindings::SetAllowRunningOfInsecureContent)
503 .SetMethod("dumpPermissionClientCallbacks",
504 &TestRunnerBindings::DumpPermissionClientCallbacks)
505 .SetMethod("dumpWindowStatusChanges",
506 &TestRunnerBindings::DumpWindowStatusChanges)
507 .SetMethod("dumpProgressFinishedCallback",
508 &TestRunnerBindings::DumpProgressFinishedCallback)
509 .SetMethod("dumpSpellCheckCallbacks",
510 &TestRunnerBindings::DumpSpellCheckCallbacks)
511 .SetMethod("dumpBackForwardList",
512 &TestRunnerBindings::DumpBackForwardList)
513 .SetMethod("dumpSelectionRect", &TestRunnerBindings::DumpSelectionRect)
514 .SetMethod("setPrinting", &TestRunnerBindings::SetPrinting)
515 .SetMethod("clearPrinting", &TestRunnerBindings::ClearPrinting)
516 .SetMethod(
517 "setShouldStayOnPageAfterHandlingBeforeUnload",
518 &TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload)
519 .SetMethod("setWillSendRequestClearHeader",
520 &TestRunnerBindings::SetWillSendRequestClearHeader)
521 .SetMethod("dumpResourceRequestPriorities",
522 &TestRunnerBindings::DumpResourceRequestPriorities)
523 .SetMethod("setUseMockTheme", &TestRunnerBindings::SetUseMockTheme)
524 .SetMethod("waitUntilExternalURLLoad",
525 &TestRunnerBindings::WaitUntilExternalURLLoad)
526 .SetMethod("dumpDragImage", &TestRunnerBindings::DumpDragImage)
527 .SetMethod("dumpNavigationPolicy",
528 &TestRunnerBindings::DumpNavigationPolicy)
529 .SetMethod("showWebInspector", &TestRunnerBindings::ShowWebInspector)
530 .SetMethod("closeWebInspector", &TestRunnerBindings::CloseWebInspector)
531 .SetMethod("isChooserShown", &TestRunnerBindings::IsChooserShown)
532 .SetMethod("evaluateInWebInspector",
533 &TestRunnerBindings::EvaluateInWebInspector)
534 .SetMethod("clearAllDatabases", &TestRunnerBindings::ClearAllDatabases)
535 .SetMethod("setDatabaseQuota", &TestRunnerBindings::SetDatabaseQuota)
536 .SetMethod("setAlwaysAcceptCookies",
537 &TestRunnerBindings::SetAlwaysAcceptCookies)
538 .SetMethod("setWindowIsKey", &TestRunnerBindings::SetWindowIsKey)
539 .SetMethod("pathToLocalResource",
540 &TestRunnerBindings::PathToLocalResource)
541 .SetMethod("setBackingScaleFactor",
542 &TestRunnerBindings::SetBackingScaleFactor)
543 .SetMethod("setColorProfile", &TestRunnerBindings::SetColorProfile)
544 .SetMethod("setPOSIXLocale", &TestRunnerBindings::SetPOSIXLocale)
545 .SetMethod("setMIDIAccessorResult",
546 &TestRunnerBindings::SetMIDIAccessorResult)
547 .SetMethod("simulateWebNotificationClick",
548 &TestRunnerBindings::SimulateWebNotificationClick)
549 .SetMethod("addMockSpeechRecognitionResult",
550 &TestRunnerBindings::AddMockSpeechRecognitionResult)
551 .SetMethod("setMockSpeechRecognitionError",
552 &TestRunnerBindings::SetMockSpeechRecognitionError)
553 .SetMethod("wasMockSpeechRecognitionAborted",
554 &TestRunnerBindings::WasMockSpeechRecognitionAborted)
555 .SetMethod("addMockCredentialManagerResponse",
556 &TestRunnerBindings::AddMockCredentialManagerResponse)
557 .SetMethod("addWebPageOverlay", &TestRunnerBindings::AddWebPageOverlay)
558 .SetMethod("removeWebPageOverlay",
559 &TestRunnerBindings::RemoveWebPageOverlay)
560 .SetMethod("layoutAndPaintAsync",
561 &TestRunnerBindings::LayoutAndPaintAsync)
562 .SetMethod("layoutAndPaintAsyncThen",
563 &TestRunnerBindings::LayoutAndPaintAsyncThen)
564 .SetMethod("getManifestThen", &TestRunnerBindings::GetManifestThen)
565 .SetMethod("capturePixelsAsyncThen",
566 &TestRunnerBindings::CapturePixelsAsyncThen)
567 .SetMethod("copyImageAtAndCapturePixelsAsyncThen",
568 &TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen)
569 .SetMethod("setCustomTextOutput",
570 &TestRunnerBindings::SetCustomTextOutput)
571 .SetMethod("setViewSourceForFrame",
572 &TestRunnerBindings::SetViewSourceForFrame)
573 // The 4 Bluetooth functions are specified at
574 // https://webbluetoothcg.github.io/web-bluetooth/tests/.
575 .SetMethod("setBluetoothMockDataSet",
576 &TestRunnerBindings::SetBluetoothMockDataSet)
577 .SetMethod("setBluetoothManualChooser",
578 &TestRunnerBindings::SetBluetoothManualChooser)
579 .SetMethod("getBluetoothManualChooserEvents",
580 &TestRunnerBindings::GetBluetoothManualChooserEvents)
581 .SetMethod("sendBluetoothManualChooserEvent",
582 &TestRunnerBindings::SendBluetoothManualChooserEvent)
583 .SetMethod("forceNextWebGLContextCreationToFail",
584 &TestRunnerBindings::ForceNextWebGLContextCreationToFail)
585 .SetMethod("forceNextDrawingBufferCreationToFail",
586 &TestRunnerBindings::ForceNextDrawingBufferCreationToFail)
587 .SetMethod("setGeofencingMockProvider",
588 &TestRunnerBindings::SetGeofencingMockProvider)
589 .SetMethod("clearGeofencingMockProvider",
590 &TestRunnerBindings::ClearGeofencingMockProvider)
591 .SetMethod("setGeofencingMockPosition",
592 &TestRunnerBindings::SetGeofencingMockPosition)
593 .SetMethod("setPermission", &TestRunnerBindings::SetPermission)
594 .SetMethod("dispatchBeforeInstallPromptEvent",
595 &TestRunnerBindings::DispatchBeforeInstallPromptEvent)
596 .SetMethod("resolveBeforeInstallPromptPromise",
597 &TestRunnerBindings::ResolveBeforeInstallPromptPromise)
599 // Properties.
600 .SetProperty("platformName", &TestRunnerBindings::PlatformName)
601 .SetProperty("tooltipText", &TestRunnerBindings::TooltipText)
602 .SetProperty("disableNotifyDone", &TestRunnerBindings::DisableNotifyDone)
603 // webHistoryItemCount is used by tests in LayoutTests\http\tests\history
604 .SetProperty("webHistoryItemCount",
605 &TestRunnerBindings::WebHistoryItemCount)
606 .SetProperty("interceptPostMessage",
607 &TestRunnerBindings::InterceptPostMessage,
608 &TestRunnerBindings::SetInterceptPostMessage)
610 // The following are stubs.
611 .SetMethod("dumpDatabaseCallbacks", &TestRunnerBindings::NotImplemented)
612 .SetMethod("setIconDatabaseEnabled", &TestRunnerBindings::NotImplemented)
613 .SetMethod("setScrollbarPolicy", &TestRunnerBindings::NotImplemented)
614 .SetMethod("clearAllApplicationCaches",
615 &TestRunnerBindings::NotImplemented)
616 .SetMethod("clearApplicationCacheForOrigin",
617 &TestRunnerBindings::NotImplemented)
618 .SetMethod("clearBackForwardList", &TestRunnerBindings::NotImplemented)
619 .SetMethod("keepWebHistory", &TestRunnerBindings::NotImplemented)
620 .SetMethod("setApplicationCacheOriginQuota",
621 &TestRunnerBindings::NotImplemented)
622 .SetMethod("setCallCloseOnWebViews", &TestRunnerBindings::NotImplemented)
623 .SetMethod("setMainFrameIsFirstResponder",
624 &TestRunnerBindings::NotImplemented)
625 .SetMethod("setUseDashboardCompatibilityMode",
626 &TestRunnerBindings::NotImplemented)
627 .SetMethod("deleteAllLocalStorage", &TestRunnerBindings::NotImplemented)
628 .SetMethod("localStorageDiskUsageForOrigin",
629 &TestRunnerBindings::NotImplemented)
630 .SetMethod("originsWithLocalStorage", &TestRunnerBindings::NotImplemented)
631 .SetMethod("deleteLocalStorageForOrigin",
632 &TestRunnerBindings::NotImplemented)
633 .SetMethod("observeStorageTrackerNotifications",
634 &TestRunnerBindings::NotImplemented)
635 .SetMethod("syncLocalStorage", &TestRunnerBindings::NotImplemented)
636 .SetMethod("addDisallowedURL", &TestRunnerBindings::NotImplemented)
637 .SetMethod("applicationCacheDiskUsageForOrigin",
638 &TestRunnerBindings::NotImplemented)
639 .SetMethod("abortModal", &TestRunnerBindings::NotImplemented)
641 // Aliases.
642 // Used at fast/dom/assign-to-window-status.html
643 .SetMethod("dumpStatusCallbacks",
644 &TestRunnerBindings::DumpWindowStatusChanges);
647 void TestRunnerBindings::LogToStderr(const std::string& output) {
648 LOG(ERROR) << output;
651 void TestRunnerBindings::NotifyDone() {
652 if (runner_)
653 runner_->NotifyDone();
656 void TestRunnerBindings::WaitUntilDone() {
657 if (runner_)
658 runner_->WaitUntilDone();
661 void TestRunnerBindings::QueueBackNavigation(int how_far_back) {
662 if (runner_)
663 runner_->QueueBackNavigation(how_far_back);
666 void TestRunnerBindings::QueueForwardNavigation(int how_far_forward) {
667 if (runner_)
668 runner_->QueueForwardNavigation(how_far_forward);
671 void TestRunnerBindings::QueueReload() {
672 if (runner_)
673 runner_->QueueReload();
676 void TestRunnerBindings::QueueLoadingScript(const std::string& script) {
677 if (runner_)
678 runner_->QueueLoadingScript(script);
681 void TestRunnerBindings::QueueNonLoadingScript(const std::string& script) {
682 if (runner_)
683 runner_->QueueNonLoadingScript(script);
686 void TestRunnerBindings::QueueLoad(gin::Arguments* args) {
687 if (runner_) {
688 std::string url;
689 std::string target;
690 args->GetNext(&url);
691 args->GetNext(&target);
692 runner_->QueueLoad(url, target);
696 void TestRunnerBindings::QueueLoadHTMLString(gin::Arguments* args) {
697 if (runner_)
698 runner_->QueueLoadHTMLString(args);
701 void TestRunnerBindings::SetCustomPolicyDelegate(gin::Arguments* args) {
702 if (runner_)
703 runner_->SetCustomPolicyDelegate(args);
706 void TestRunnerBindings::WaitForPolicyDelegate() {
707 if (runner_)
708 runner_->WaitForPolicyDelegate();
711 int TestRunnerBindings::WindowCount() {
712 if (runner_)
713 return runner_->WindowCount();
714 return 0;
717 void TestRunnerBindings::SetCloseRemainingWindowsWhenComplete(
718 gin::Arguments* args) {
719 if (!runner_)
720 return;
722 // In the original implementation, nothing happens if the argument is
723 // ommitted.
724 bool close_remaining_windows = false;
725 if (args->GetNext(&close_remaining_windows))
726 runner_->SetCloseRemainingWindowsWhenComplete(close_remaining_windows);
729 void TestRunnerBindings::ResetTestHelperControllers() {
730 if (runner_)
731 runner_->ResetTestHelperControllers();
734 void TestRunnerBindings::SetTabKeyCyclesThroughElements(
735 bool tab_key_cycles_through_elements) {
736 if (runner_)
737 runner_->SetTabKeyCyclesThroughElements(tab_key_cycles_through_elements);
740 void TestRunnerBindings::ExecCommand(gin::Arguments* args) {
741 if (runner_)
742 runner_->ExecCommand(args);
745 bool TestRunnerBindings::IsCommandEnabled(const std::string& command) {
746 if (runner_)
747 return runner_->IsCommandEnabled(command);
748 return false;
751 bool TestRunnerBindings::CallShouldCloseOnWebView() {
752 if (runner_)
753 return runner_->CallShouldCloseOnWebView();
754 return false;
757 void TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme(
758 bool forbidden, const std::string& scheme) {
759 if (runner_)
760 runner_->SetDomainRelaxationForbiddenForURLScheme(forbidden, scheme);
763 v8::Local<v8::Value>
764 TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue(
765 int world_id, const std::string& script) {
766 if (!runner_ || world_id <= 0 || world_id >= (1 << 29))
767 return v8::Local<v8::Value>();
768 return runner_->EvaluateScriptInIsolatedWorldAndReturnValue(world_id,
769 script);
772 void TestRunnerBindings::EvaluateScriptInIsolatedWorld(
773 int world_id, const std::string& script) {
774 if (runner_ && world_id > 0 && world_id < (1 << 29))
775 runner_->EvaluateScriptInIsolatedWorld(world_id, script);
778 void TestRunnerBindings::SetIsolatedWorldSecurityOrigin(
779 int world_id, v8::Local<v8::Value> origin) {
780 if (runner_)
781 runner_->SetIsolatedWorldSecurityOrigin(world_id, origin);
784 void TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy(
785 int world_id, const std::string& policy) {
786 if (runner_)
787 runner_->SetIsolatedWorldContentSecurityPolicy(world_id, policy);
790 void TestRunnerBindings::AddOriginAccessWhitelistEntry(
791 const std::string& source_origin,
792 const std::string& destination_protocol,
793 const std::string& destination_host,
794 bool allow_destination_subdomains) {
795 if (runner_) {
796 runner_->AddOriginAccessWhitelistEntry(source_origin,
797 destination_protocol,
798 destination_host,
799 allow_destination_subdomains);
803 void TestRunnerBindings::RemoveOriginAccessWhitelistEntry(
804 const std::string& source_origin,
805 const std::string& destination_protocol,
806 const std::string& destination_host,
807 bool allow_destination_subdomains) {
808 if (runner_) {
809 runner_->RemoveOriginAccessWhitelistEntry(source_origin,
810 destination_protocol,
811 destination_host,
812 allow_destination_subdomains);
816 bool TestRunnerBindings::HasCustomPageSizeStyle(int page_index) {
817 if (runner_)
818 return runner_->HasCustomPageSizeStyle(page_index);
819 return false;
822 void TestRunnerBindings::ForceRedSelectionColors() {
823 if (runner_)
824 runner_->ForceRedSelectionColors();
827 void TestRunnerBindings::InsertStyleSheet(const std::string& source_code) {
828 if (runner_)
829 runner_->InsertStyleSheet(source_code);
832 bool TestRunnerBindings::FindString(
833 const std::string& search_text,
834 const std::vector<std::string>& options_array) {
835 if (runner_)
836 return runner_->FindString(search_text, options_array);
837 return false;
840 std::string TestRunnerBindings::SelectionAsMarkup() {
841 if (runner_)
842 return runner_->SelectionAsMarkup();
843 return std::string();
846 void TestRunnerBindings::SetTextSubpixelPositioning(bool value) {
847 if (runner_)
848 runner_->SetTextSubpixelPositioning(value);
851 void TestRunnerBindings::SetPageVisibility(const std::string& new_visibility) {
852 if (runner_)
853 runner_->SetPageVisibility(new_visibility);
856 void TestRunnerBindings::SetTextDirection(const std::string& direction_name) {
857 if (runner_)
858 runner_->SetTextDirection(direction_name);
861 void TestRunnerBindings::UseUnfortunateSynchronousResizeMode() {
862 if (runner_)
863 runner_->UseUnfortunateSynchronousResizeMode();
866 bool TestRunnerBindings::EnableAutoResizeMode(int min_width,
867 int min_height,
868 int max_width,
869 int max_height) {
870 if (runner_) {
871 return runner_->EnableAutoResizeMode(min_width, min_height,
872 max_width, max_height);
874 return false;
877 bool TestRunnerBindings::DisableAutoResizeMode(int new_width, int new_height) {
878 if (runner_)
879 return runner_->DisableAutoResizeMode(new_width, new_height);
880 return false;
883 void TestRunnerBindings::SetMockDeviceLight(double value) {
884 if (!runner_)
885 return;
886 runner_->SetMockDeviceLight(value);
889 void TestRunnerBindings::ResetDeviceLight() {
890 if (runner_)
891 runner_->ResetDeviceLight();
894 void TestRunnerBindings::SetMockDeviceMotion(gin::Arguments* args) {
895 if (!runner_)
896 return;
898 bool has_acceleration_x;
899 double acceleration_x;
900 bool has_acceleration_y;
901 double acceleration_y;
902 bool has_acceleration_z;
903 double acceleration_z;
904 bool has_acceleration_including_gravity_x;
905 double acceleration_including_gravity_x;
906 bool has_acceleration_including_gravity_y;
907 double acceleration_including_gravity_y;
908 bool has_acceleration_including_gravity_z;
909 double acceleration_including_gravity_z;
910 bool has_rotation_rate_alpha;
911 double rotation_rate_alpha;
912 bool has_rotation_rate_beta;
913 double rotation_rate_beta;
914 bool has_rotation_rate_gamma;
915 double rotation_rate_gamma;
916 double interval;
918 args->GetNext(&has_acceleration_x);
919 args->GetNext(& acceleration_x);
920 args->GetNext(&has_acceleration_y);
921 args->GetNext(& acceleration_y);
922 args->GetNext(&has_acceleration_z);
923 args->GetNext(& acceleration_z);
924 args->GetNext(&has_acceleration_including_gravity_x);
925 args->GetNext(& acceleration_including_gravity_x);
926 args->GetNext(&has_acceleration_including_gravity_y);
927 args->GetNext(& acceleration_including_gravity_y);
928 args->GetNext(&has_acceleration_including_gravity_z);
929 args->GetNext(& acceleration_including_gravity_z);
930 args->GetNext(&has_rotation_rate_alpha);
931 args->GetNext(& rotation_rate_alpha);
932 args->GetNext(&has_rotation_rate_beta);
933 args->GetNext(& rotation_rate_beta);
934 args->GetNext(&has_rotation_rate_gamma);
935 args->GetNext(& rotation_rate_gamma);
936 args->GetNext(& interval);
938 runner_->SetMockDeviceMotion(has_acceleration_x, acceleration_x,
939 has_acceleration_y, acceleration_y,
940 has_acceleration_z, acceleration_z,
941 has_acceleration_including_gravity_x,
942 acceleration_including_gravity_x,
943 has_acceleration_including_gravity_y,
944 acceleration_including_gravity_y,
945 has_acceleration_including_gravity_z,
946 acceleration_including_gravity_z,
947 has_rotation_rate_alpha,
948 rotation_rate_alpha,
949 has_rotation_rate_beta,
950 rotation_rate_beta,
951 has_rotation_rate_gamma,
952 rotation_rate_gamma,
953 interval);
956 void TestRunnerBindings::SetMockDeviceOrientation(gin::Arguments* args) {
957 if (!runner_)
958 return;
960 bool has_alpha = false;
961 double alpha = 0.0;
962 bool has_beta = false;
963 double beta = 0.0;
964 bool has_gamma = false;
965 double gamma = 0.0;
966 bool has_absolute = false;
967 bool absolute = false;
969 args->GetNext(&has_alpha);
970 args->GetNext(&alpha);
971 args->GetNext(&has_beta);
972 args->GetNext(&beta);
973 args->GetNext(&has_gamma);
974 args->GetNext(&gamma);
975 args->GetNext(&has_absolute);
976 args->GetNext(&absolute);
978 runner_->SetMockDeviceOrientation(has_alpha, alpha,
979 has_beta, beta,
980 has_gamma, gamma,
981 has_absolute, absolute);
984 void TestRunnerBindings::SetMockScreenOrientation(
985 const std::string& orientation) {
986 if (!runner_)
987 return;
989 runner_->SetMockScreenOrientation(orientation);
992 void TestRunnerBindings::DidChangeBatteryStatus(bool charging,
993 double chargingTime,
994 double dischargingTime,
995 double level) {
996 if (runner_) {
997 runner_->DidChangeBatteryStatus(charging, chargingTime,
998 dischargingTime, level);
1002 void TestRunnerBindings::ResetBatteryStatus() {
1003 if (runner_)
1004 runner_->ResetBatteryStatus();
1007 void TestRunnerBindings::DidAcquirePointerLock() {
1008 if (runner_)
1009 runner_->DidAcquirePointerLock();
1012 void TestRunnerBindings::DidNotAcquirePointerLock() {
1013 if (runner_)
1014 runner_->DidNotAcquirePointerLock();
1017 void TestRunnerBindings::DidLosePointerLock() {
1018 if (runner_)
1019 runner_->DidLosePointerLock();
1022 void TestRunnerBindings::SetPointerLockWillFailSynchronously() {
1023 if (runner_)
1024 runner_->SetPointerLockWillFailSynchronously();
1027 void TestRunnerBindings::SetPointerLockWillRespondAsynchronously() {
1028 if (runner_)
1029 runner_->SetPointerLockWillRespondAsynchronously();
1032 void TestRunnerBindings::SetPopupBlockingEnabled(bool block_popups) {
1033 if (runner_)
1034 runner_->SetPopupBlockingEnabled(block_popups);
1037 void TestRunnerBindings::SetJavaScriptCanAccessClipboard(bool can_access) {
1038 if (runner_)
1039 runner_->SetJavaScriptCanAccessClipboard(can_access);
1042 void TestRunnerBindings::SetXSSAuditorEnabled(bool enabled) {
1043 if (runner_)
1044 runner_->SetXSSAuditorEnabled(enabled);
1047 void TestRunnerBindings::SetAllowUniversalAccessFromFileURLs(bool allow) {
1048 if (runner_)
1049 runner_->SetAllowUniversalAccessFromFileURLs(allow);
1052 void TestRunnerBindings::SetAllowFileAccessFromFileURLs(bool allow) {
1053 if (runner_)
1054 runner_->SetAllowFileAccessFromFileURLs(allow);
1057 void TestRunnerBindings::OverridePreference(const std::string key,
1058 v8::Local<v8::Value> value) {
1059 if (runner_)
1060 runner_->OverridePreference(key, value);
1063 void TestRunnerBindings::SetAcceptLanguages(
1064 const std::string& accept_languages) {
1065 if (!runner_)
1066 return;
1068 runner_->SetAcceptLanguages(accept_languages);
1071 void TestRunnerBindings::SetPluginsEnabled(bool enabled) {
1072 if (runner_)
1073 runner_->SetPluginsEnabled(enabled);
1076 void TestRunnerBindings::DumpEditingCallbacks() {
1077 if (runner_)
1078 runner_->DumpEditingCallbacks();
1081 void TestRunnerBindings::DumpAsMarkup() {
1082 if (runner_)
1083 runner_->DumpAsMarkup();
1086 void TestRunnerBindings::DumpAsText() {
1087 if (runner_)
1088 runner_->DumpAsText();
1091 void TestRunnerBindings::DumpAsTextWithPixelResults() {
1092 if (runner_)
1093 runner_->DumpAsTextWithPixelResults();
1096 void TestRunnerBindings::DumpChildFrameScrollPositions() {
1097 if (runner_)
1098 runner_->DumpChildFrameScrollPositions();
1101 void TestRunnerBindings::DumpChildFramesAsText() {
1102 if (runner_)
1103 runner_->DumpChildFramesAsText();
1106 void TestRunnerBindings::DumpChildFramesAsMarkup() {
1107 if (runner_)
1108 runner_->DumpChildFramesAsMarkup();
1111 void TestRunnerBindings::DumpIconChanges() {
1112 if (runner_)
1113 runner_->DumpIconChanges();
1116 void TestRunnerBindings::SetAudioData(const gin::ArrayBufferView& view) {
1117 if (runner_)
1118 runner_->SetAudioData(view);
1121 void TestRunnerBindings::DumpFrameLoadCallbacks() {
1122 if (runner_)
1123 runner_->DumpFrameLoadCallbacks();
1126 void TestRunnerBindings::DumpPingLoaderCallbacks() {
1127 if (runner_)
1128 runner_->DumpPingLoaderCallbacks();
1131 void TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks() {
1132 if (runner_)
1133 runner_->DumpUserGestureInFrameLoadCallbacks();
1136 void TestRunnerBindings::DumpTitleChanges() {
1137 if (runner_)
1138 runner_->DumpTitleChanges();
1141 void TestRunnerBindings::DumpCreateView() {
1142 if (runner_)
1143 runner_->DumpCreateView();
1146 void TestRunnerBindings::SetCanOpenWindows() {
1147 if (runner_)
1148 runner_->SetCanOpenWindows();
1151 void TestRunnerBindings::DumpResourceLoadCallbacks() {
1152 if (runner_)
1153 runner_->DumpResourceLoadCallbacks();
1156 void TestRunnerBindings::DumpResourceRequestCallbacks() {
1157 if (runner_)
1158 runner_->DumpResourceRequestCallbacks();
1161 void TestRunnerBindings::DumpResourceResponseMIMETypes() {
1162 if (runner_)
1163 runner_->DumpResourceResponseMIMETypes();
1166 void TestRunnerBindings::SetImagesAllowed(bool allowed) {
1167 if (runner_)
1168 runner_->SetImagesAllowed(allowed);
1171 void TestRunnerBindings::SetMediaAllowed(bool allowed) {
1172 if (runner_)
1173 runner_->SetMediaAllowed(allowed);
1176 void TestRunnerBindings::SetScriptsAllowed(bool allowed) {
1177 if (runner_)
1178 runner_->SetScriptsAllowed(allowed);
1181 void TestRunnerBindings::SetStorageAllowed(bool allowed) {
1182 if (runner_)
1183 runner_->SetStorageAllowed(allowed);
1186 void TestRunnerBindings::SetPluginsAllowed(bool allowed) {
1187 if (runner_)
1188 runner_->SetPluginsAllowed(allowed);
1191 void TestRunnerBindings::SetAllowDisplayOfInsecureContent(bool allowed) {
1192 if (runner_)
1193 runner_->SetAllowDisplayOfInsecureContent(allowed);
1196 void TestRunnerBindings::SetAllowRunningOfInsecureContent(bool allowed) {
1197 if (runner_)
1198 runner_->SetAllowRunningOfInsecureContent(allowed);
1201 void TestRunnerBindings::DumpPermissionClientCallbacks() {
1202 if (runner_)
1203 runner_->DumpPermissionClientCallbacks();
1206 void TestRunnerBindings::DumpWindowStatusChanges() {
1207 if (runner_)
1208 runner_->DumpWindowStatusChanges();
1211 void TestRunnerBindings::DumpProgressFinishedCallback() {
1212 if (runner_)
1213 runner_->DumpProgressFinishedCallback();
1216 void TestRunnerBindings::DumpSpellCheckCallbacks() {
1217 if (runner_)
1218 runner_->DumpSpellCheckCallbacks();
1221 void TestRunnerBindings::DumpBackForwardList() {
1222 if (runner_)
1223 runner_->DumpBackForwardList();
1226 void TestRunnerBindings::DumpSelectionRect() {
1227 if (runner_)
1228 runner_->DumpSelectionRect();
1231 void TestRunnerBindings::SetPrinting() {
1232 if (runner_)
1233 runner_->SetPrinting();
1236 void TestRunnerBindings::ClearPrinting() {
1237 if (runner_)
1238 runner_->ClearPrinting();
1241 void TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload(
1242 bool value) {
1243 if (runner_)
1244 runner_->SetShouldStayOnPageAfterHandlingBeforeUnload(value);
1247 void TestRunnerBindings::SetWillSendRequestClearHeader(
1248 const std::string& header) {
1249 if (runner_)
1250 runner_->SetWillSendRequestClearHeader(header);
1253 void TestRunnerBindings::DumpResourceRequestPriorities() {
1254 if (runner_)
1255 runner_->DumpResourceRequestPriorities();
1258 void TestRunnerBindings::SetUseMockTheme(bool use) {
1259 if (runner_)
1260 runner_->SetUseMockTheme(use);
1263 void TestRunnerBindings::WaitUntilExternalURLLoad() {
1264 if (runner_)
1265 runner_->WaitUntilExternalURLLoad();
1268 void TestRunnerBindings::DumpDragImage() {
1269 if (runner_)
1270 runner_->DumpDragImage();
1273 void TestRunnerBindings::DumpNavigationPolicy() {
1274 if (runner_)
1275 runner_->DumpNavigationPolicy();
1278 void TestRunnerBindings::ShowWebInspector(gin::Arguments* args) {
1279 if (runner_) {
1280 std::string settings;
1281 args->GetNext(&settings);
1282 std::string frontend_url;
1283 args->GetNext(&frontend_url);
1284 runner_->ShowWebInspector(settings, frontend_url);
1288 void TestRunnerBindings::CloseWebInspector() {
1289 if (runner_)
1290 runner_->CloseWebInspector();
1293 bool TestRunnerBindings::IsChooserShown() {
1294 if (runner_)
1295 return runner_->IsChooserShown();
1296 return false;
1299 void TestRunnerBindings::EvaluateInWebInspector(int call_id,
1300 const std::string& script) {
1301 if (runner_)
1302 runner_->EvaluateInWebInspector(call_id, script);
1305 void TestRunnerBindings::ClearAllDatabases() {
1306 if (runner_)
1307 runner_->ClearAllDatabases();
1310 void TestRunnerBindings::SetDatabaseQuota(int quota) {
1311 if (runner_)
1312 runner_->SetDatabaseQuota(quota);
1315 void TestRunnerBindings::SetAlwaysAcceptCookies(bool accept) {
1316 if (runner_)
1317 runner_->SetAlwaysAcceptCookies(accept);
1320 void TestRunnerBindings::SetWindowIsKey(bool value) {
1321 if (runner_)
1322 runner_->SetWindowIsKey(value);
1325 std::string TestRunnerBindings::PathToLocalResource(const std::string& path) {
1326 if (runner_)
1327 return runner_->PathToLocalResource(path);
1328 return std::string();
1331 void TestRunnerBindings::SetBackingScaleFactor(
1332 double value, v8::Local<v8::Function> callback) {
1333 if (runner_)
1334 runner_->SetBackingScaleFactor(value, callback);
1337 void TestRunnerBindings::SetColorProfile(
1338 const std::string& name, v8::Local<v8::Function> callback) {
1339 if (runner_)
1340 runner_->SetColorProfile(name, callback);
1343 void TestRunnerBindings::SetBluetoothMockDataSet(const std::string& name) {
1344 if (runner_)
1345 runner_->SetBluetoothMockDataSet(name);
1348 void TestRunnerBindings::SetBluetoothManualChooser() {
1349 if (runner_)
1350 runner_->SetBluetoothManualChooser();
1353 std::vector<std::string> TestRunnerBindings::GetBluetoothManualChooserEvents() {
1354 if (runner_)
1355 return runner_->GetBluetoothManualChooserEvents();
1356 return std::vector<std::string>(1, "No Test Runner");
1359 void TestRunnerBindings::SendBluetoothManualChooserEvent(
1360 const std::string& event,
1361 const std::string& argument) {
1362 if (runner_)
1363 runner_->SendBluetoothManualChooserEvent(event, argument);
1366 void TestRunnerBindings::SetPOSIXLocale(const std::string& locale) {
1367 if (runner_)
1368 runner_->SetPOSIXLocale(locale);
1371 void TestRunnerBindings::SetMIDIAccessorResult(bool result) {
1372 if (runner_)
1373 runner_->SetMIDIAccessorResult(result);
1376 void TestRunnerBindings::SimulateWebNotificationClick(gin::Arguments* args) {
1377 if (!runner_)
1378 return;
1379 std::string title;
1380 int action_index = -1;
1381 if (args->GetNext(&title) &&
1382 (args->PeekNext().IsEmpty() || args->GetNext(&action_index)))
1383 runner_->SimulateWebNotificationClick(title, action_index);
1384 else
1385 args->ThrowError();
1388 void TestRunnerBindings::AddMockSpeechRecognitionResult(
1389 const std::string& transcript, double confidence) {
1390 if (runner_)
1391 runner_->AddMockSpeechRecognitionResult(transcript, confidence);
1394 void TestRunnerBindings::SetMockSpeechRecognitionError(
1395 const std::string& error, const std::string& message) {
1396 if (runner_)
1397 runner_->SetMockSpeechRecognitionError(error, message);
1400 bool TestRunnerBindings::WasMockSpeechRecognitionAborted() {
1401 if (runner_)
1402 return runner_->WasMockSpeechRecognitionAborted();
1403 return false;
1406 void TestRunnerBindings::AddMockCredentialManagerResponse(
1407 const std::string& id,
1408 const std::string& name,
1409 const std::string& avatar,
1410 const std::string& password) {
1411 if (runner_)
1412 runner_->AddMockCredentialManagerResponse(id, name, avatar, password);
1415 void TestRunnerBindings::AddWebPageOverlay() {
1416 if (runner_)
1417 runner_->AddWebPageOverlay();
1420 void TestRunnerBindings::RemoveWebPageOverlay() {
1421 if (runner_)
1422 runner_->RemoveWebPageOverlay();
1425 void TestRunnerBindings::LayoutAndPaintAsync() {
1426 if (runner_)
1427 runner_->LayoutAndPaintAsync();
1430 void TestRunnerBindings::LayoutAndPaintAsyncThen(
1431 v8::Local<v8::Function> callback) {
1432 if (runner_)
1433 runner_->LayoutAndPaintAsyncThen(callback);
1436 void TestRunnerBindings::GetManifestThen(v8::Local<v8::Function> callback) {
1437 if (runner_)
1438 runner_->GetManifestThen(callback);
1441 void TestRunnerBindings::CapturePixelsAsyncThen(
1442 v8::Local<v8::Function> callback) {
1443 if (runner_)
1444 runner_->CapturePixelsAsyncThen(callback);
1447 void TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen(
1448 int x, int y, v8::Local<v8::Function> callback) {
1449 if (runner_)
1450 runner_->CopyImageAtAndCapturePixelsAsyncThen(x, y, callback);
1453 void TestRunnerBindings::SetCustomTextOutput(std::string output) {
1454 runner_->setCustomTextOutput(output);
1457 void TestRunnerBindings::SetViewSourceForFrame(const std::string& name,
1458 bool enabled) {
1459 if (runner_ && runner_->web_view_) {
1460 WebFrame* target_frame =
1461 runner_->web_view_->findFrameByName(WebString::fromUTF8(name));
1462 if (target_frame)
1463 target_frame->enableViewSourceMode(enabled);
1467 void TestRunnerBindings::SetGeofencingMockProvider(bool service_available) {
1468 if (runner_)
1469 runner_->SetGeofencingMockProvider(service_available);
1472 void TestRunnerBindings::ClearGeofencingMockProvider() {
1473 if (runner_)
1474 runner_->ClearGeofencingMockProvider();
1477 void TestRunnerBindings::SetGeofencingMockPosition(double latitude,
1478 double longitude) {
1479 if (runner_)
1480 runner_->SetGeofencingMockPosition(latitude, longitude);
1483 void TestRunnerBindings::SetPermission(const std::string& name,
1484 const std::string& value,
1485 const std::string& origin,
1486 const std::string& embedding_origin) {
1487 if (!runner_)
1488 return;
1490 return runner_->SetPermission(
1491 name, value, GURL(origin), GURL(embedding_origin));
1494 void TestRunnerBindings::DispatchBeforeInstallPromptEvent(
1495 int request_id,
1496 const std::vector<std::string>& event_platforms,
1497 v8::Local<v8::Function> callback) {
1498 if (!runner_)
1499 return;
1501 return runner_->DispatchBeforeInstallPromptEvent(request_id, event_platforms,
1502 callback);
1505 void TestRunnerBindings::ResolveBeforeInstallPromptPromise(
1506 int request_id,
1507 const std::string& platform) {
1508 if (!runner_)
1509 return;
1511 return runner_->ResolveBeforeInstallPromptPromise(request_id, platform);
1514 std::string TestRunnerBindings::PlatformName() {
1515 if (runner_)
1516 return runner_->platform_name_;
1517 return std::string();
1520 std::string TestRunnerBindings::TooltipText() {
1521 if (runner_)
1522 return runner_->tooltip_text_;
1523 return std::string();
1526 bool TestRunnerBindings::DisableNotifyDone() {
1527 if (runner_)
1528 return runner_->disable_notify_done_;
1529 return false;
1532 int TestRunnerBindings::WebHistoryItemCount() {
1533 if (runner_)
1534 return runner_->web_history_item_count_;
1535 return false;
1538 bool TestRunnerBindings::InterceptPostMessage() {
1539 if (runner_)
1540 return runner_->intercept_post_message_;
1541 return false;
1544 void TestRunnerBindings::SetInterceptPostMessage(bool value) {
1545 if (runner_)
1546 runner_->intercept_post_message_ = value;
1549 void TestRunnerBindings::ForceNextWebGLContextCreationToFail() {
1550 if (runner_)
1551 runner_->ForceNextWebGLContextCreationToFail();
1554 void TestRunnerBindings::ForceNextDrawingBufferCreationToFail() {
1555 if (runner_)
1556 runner_->ForceNextDrawingBufferCreationToFail();
1559 void TestRunnerBindings::NotImplemented(const gin::Arguments& args) {
1562 TestRunner::WorkQueue::WorkQueue(TestRunner* controller)
1563 : frozen_(false)
1564 , controller_(controller) {}
1566 TestRunner::WorkQueue::~WorkQueue() {
1567 Reset();
1570 void TestRunner::WorkQueue::ProcessWorkSoon() {
1571 if (controller_->topLoadingFrame())
1572 return;
1574 if (!queue_.empty()) {
1575 // We delay processing queued work to avoid recursion problems.
1576 controller_->delegate_->PostTask(new WorkQueueTask(this));
1577 } else if (!controller_->wait_until_done_) {
1578 controller_->delegate_->TestFinished();
1582 void TestRunner::WorkQueue::Reset() {
1583 frozen_ = false;
1584 while (!queue_.empty()) {
1585 delete queue_.front();
1586 queue_.pop_front();
1590 void TestRunner::WorkQueue::AddWork(WorkItem* work) {
1591 if (frozen_) {
1592 delete work;
1593 return;
1595 queue_.push_back(work);
1598 void TestRunner::WorkQueue::ProcessWork() {
1599 // Quit doing work once a load is in progress.
1600 while (!queue_.empty()) {
1601 bool startedLoad = queue_.front()->Run(controller_->delegate_,
1602 controller_->web_view_);
1603 delete queue_.front();
1604 queue_.pop_front();
1605 if (startedLoad)
1606 return;
1609 if (!controller_->wait_until_done_ && !controller_->topLoadingFrame())
1610 controller_->delegate_->TestFinished();
1613 void TestRunner::WorkQueue::WorkQueueTask::RunIfValid() {
1614 object_->ProcessWork();
1617 TestRunner::TestRunner(TestInterfaces* interfaces)
1618 : test_is_running_(false),
1619 close_remaining_windows_(false),
1620 work_queue_(this),
1621 disable_notify_done_(false),
1622 web_history_item_count_(0),
1623 intercept_post_message_(false),
1624 test_interfaces_(interfaces),
1625 delegate_(nullptr),
1626 web_view_(nullptr),
1627 web_content_settings_(new WebContentSettings()),
1628 weak_factory_(this) {}
1630 TestRunner::~TestRunner() {}
1632 void TestRunner::Install(WebFrame* frame) {
1633 TestRunnerBindings::Install(weak_factory_.GetWeakPtr(), frame);
1636 void TestRunner::SetDelegate(WebTestDelegate* delegate) {
1637 delegate_ = delegate;
1638 web_content_settings_->SetDelegate(delegate);
1641 void TestRunner::SetWebView(WebView* webView, WebTestProxyBase* proxy) {
1642 web_view_ = webView;
1643 proxy_ = proxy;
1646 void TestRunner::Reset() {
1647 if (web_view_) {
1648 web_view_->setZoomLevel(0);
1649 web_view_->setTextZoomFactor(1);
1650 web_view_->setTabKeyCyclesThroughElements(true);
1651 #if !defined(__APPLE__) && !defined(WIN32) // Actually, TOOLKIT_GTK
1652 // (Constants copied because we can't depend on the header that defined
1653 // them from this file.)
1654 web_view_->setSelectionColors(
1655 0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232);
1656 #endif
1657 web_view_->setVisibilityState(WebPageVisibilityStateVisible, true);
1658 web_view_->mainFrame()->enableViewSourceMode(false);
1660 web_view_->setPageOverlayColor(SK_ColorTRANSPARENT);
1663 top_loading_frame_ = nullptr;
1664 wait_until_done_ = false;
1665 wait_until_external_url_load_ = false;
1666 policy_delegate_enabled_ = false;
1667 policy_delegate_is_permissive_ = false;
1668 policy_delegate_should_notify_done_ = false;
1670 WebSecurityPolicy::resetOriginAccessWhitelists();
1671 #if defined(__linux__) || defined(ANDROID)
1672 WebFontRendering::setSubpixelPositioning(false);
1673 #endif
1675 if (delegate_) {
1676 // Reset the default quota for each origin to 5MB
1677 delegate_->SetDatabaseQuota(5 * 1024 * 1024);
1678 delegate_->SetDeviceColorProfile("reset");
1679 delegate_->SetDeviceScaleFactor(1);
1680 delegate_->SetAcceptAllCookies(false);
1681 delegate_->SetLocale("");
1682 delegate_->UseUnfortunateSynchronousResizeMode(false);
1683 delegate_->DisableAutoResizeMode(WebSize());
1684 delegate_->DeleteAllCookies();
1685 delegate_->ResetScreenOrientation();
1686 delegate_->SetBluetoothMockDataSet("");
1687 delegate_->ClearGeofencingMockProvider();
1688 delegate_->ResetPermissions();
1689 ResetBatteryStatus();
1690 ResetDeviceLight();
1693 dump_editting_callbacks_ = false;
1694 dump_as_text_ = false;
1695 dump_as_markup_ = false;
1696 generate_pixel_results_ = true;
1697 dump_child_frame_scroll_positions_ = false;
1698 dump_child_frames_as_markup_ = false;
1699 dump_child_frames_as_text_ = false;
1700 dump_icon_changes_ = false;
1701 dump_as_audio_ = false;
1702 dump_frame_load_callbacks_ = false;
1703 dump_ping_loader_callbacks_ = false;
1704 dump_user_gesture_in_frame_load_callbacks_ = false;
1705 dump_title_changes_ = false;
1706 dump_create_view_ = false;
1707 can_open_windows_ = false;
1708 dump_resource_load_callbacks_ = false;
1709 dump_resource_request_callbacks_ = false;
1710 dump_resource_response_mime_types_ = false;
1711 dump_window_status_changes_ = false;
1712 dump_progress_finished_callback_ = false;
1713 dump_spell_check_callbacks_ = false;
1714 dump_back_forward_list_ = false;
1715 dump_selection_rect_ = false;
1716 dump_drag_image_ = false;
1717 dump_navigation_policy_ = false;
1718 test_repaint_ = false;
1719 sweep_horizontally_ = false;
1720 is_printing_ = false;
1721 midi_accessor_result_ = true;
1722 should_stay_on_page_after_handling_before_unload_ = false;
1723 should_dump_resource_priorities_ = false;
1724 has_custom_text_output_ = false;
1725 custom_text_output_.clear();
1727 http_headers_to_clear_.clear();
1729 platform_name_ = "chromium";
1730 tooltip_text_ = std::string();
1731 disable_notify_done_ = false;
1732 web_history_item_count_ = 0;
1733 intercept_post_message_ = false;
1735 web_content_settings_->Reset();
1737 use_mock_theme_ = true;
1738 pointer_locked_ = false;
1739 pointer_lock_planned_result_ = PointerLockWillSucceed;
1741 task_list_.RevokeAll();
1742 work_queue_.Reset();
1744 if (close_remaining_windows_ && delegate_)
1745 delegate_->CloseRemainingWindows();
1746 else
1747 close_remaining_windows_ = true;
1750 void TestRunner::SetTestIsRunning(bool running) {
1751 test_is_running_ = running;
1754 void TestRunner::InvokeCallback(scoped_ptr<InvokeCallbackTask> task) {
1755 delegate_->PostTask(task.release());
1758 bool TestRunner::shouldDumpEditingCallbacks() const {
1759 return dump_editting_callbacks_;
1762 bool TestRunner::shouldDumpAsText() {
1763 CheckResponseMimeType();
1764 return dump_as_text_;
1767 void TestRunner::setShouldDumpAsText(bool value) {
1768 dump_as_text_ = value;
1771 bool TestRunner::shouldDumpAsMarkup() {
1772 return dump_as_markup_;
1775 void TestRunner::setShouldDumpAsMarkup(bool value) {
1776 dump_as_markup_ = value;
1779 bool TestRunner::shouldDumpAsCustomText() const {
1780 return has_custom_text_output_;
1783 std::string TestRunner::customDumpText() const {
1784 return custom_text_output_;
1787 void TestRunner::setCustomTextOutput(std::string text) {
1788 custom_text_output_ = text;
1789 has_custom_text_output_ = true;
1792 bool TestRunner::ShouldGeneratePixelResults() {
1793 CheckResponseMimeType();
1794 return generate_pixel_results_;
1797 bool TestRunner::ShouldStayOnPageAfterHandlingBeforeUnload() const {
1798 return should_stay_on_page_after_handling_before_unload_;
1802 void TestRunner::setShouldGeneratePixelResults(bool value) {
1803 generate_pixel_results_ = value;
1806 bool TestRunner::shouldDumpChildFrameScrollPositions() const {
1807 return dump_child_frame_scroll_positions_;
1810 bool TestRunner::shouldDumpChildFramesAsMarkup() const {
1811 return dump_child_frames_as_markup_;
1814 bool TestRunner::shouldDumpChildFramesAsText() const {
1815 return dump_child_frames_as_text_;
1818 bool TestRunner::ShouldDumpAsAudio() const {
1819 return dump_as_audio_;
1822 void TestRunner::GetAudioData(std::vector<unsigned char>* buffer_view) const {
1823 *buffer_view = audio_data_;
1826 bool TestRunner::shouldDumpFrameLoadCallbacks() const {
1827 return test_is_running_ && dump_frame_load_callbacks_;
1830 void TestRunner::setShouldDumpFrameLoadCallbacks(bool value) {
1831 dump_frame_load_callbacks_ = value;
1834 bool TestRunner::shouldDumpPingLoaderCallbacks() const {
1835 return test_is_running_ && dump_ping_loader_callbacks_;
1838 void TestRunner::setShouldDumpPingLoaderCallbacks(bool value) {
1839 dump_ping_loader_callbacks_ = value;
1842 void TestRunner::setShouldEnableViewSource(bool value) {
1843 web_view_->mainFrame()->enableViewSourceMode(value);
1846 bool TestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const {
1847 return test_is_running_ && dump_user_gesture_in_frame_load_callbacks_;
1850 bool TestRunner::shouldDumpTitleChanges() const {
1851 return dump_title_changes_;
1854 bool TestRunner::shouldDumpIconChanges() const {
1855 return dump_icon_changes_;
1858 bool TestRunner::shouldDumpCreateView() const {
1859 return dump_create_view_;
1862 bool TestRunner::canOpenWindows() const {
1863 return can_open_windows_;
1866 bool TestRunner::shouldDumpResourceLoadCallbacks() const {
1867 return test_is_running_ && dump_resource_load_callbacks_;
1870 bool TestRunner::shouldDumpResourceRequestCallbacks() const {
1871 return test_is_running_ && dump_resource_request_callbacks_;
1874 bool TestRunner::shouldDumpResourceResponseMIMETypes() const {
1875 return test_is_running_ && dump_resource_response_mime_types_;
1878 WebContentSettingsClient* TestRunner::GetWebContentSettings() const {
1879 return web_content_settings_.get();
1882 bool TestRunner::shouldDumpStatusCallbacks() const {
1883 return dump_window_status_changes_;
1886 bool TestRunner::shouldDumpProgressFinishedCallback() const {
1887 return dump_progress_finished_callback_;
1890 bool TestRunner::shouldDumpSpellCheckCallbacks() const {
1891 return dump_spell_check_callbacks_;
1894 bool TestRunner::ShouldDumpBackForwardList() const {
1895 return dump_back_forward_list_;
1898 bool TestRunner::shouldDumpSelectionRect() const {
1899 return dump_selection_rect_;
1902 bool TestRunner::isPrinting() const {
1903 return is_printing_;
1906 bool TestRunner::shouldWaitUntilExternalURLLoad() const {
1907 return wait_until_external_url_load_;
1910 const std::set<std::string>* TestRunner::httpHeadersToClear() const {
1911 return &http_headers_to_clear_;
1914 void TestRunner::setTopLoadingFrame(WebFrame* frame, bool clear) {
1915 if (frame->top()->view() != web_view_)
1916 return;
1917 if (!test_is_running_)
1918 return;
1919 if (clear) {
1920 top_loading_frame_ = nullptr;
1921 LocationChangeDone();
1922 } else if (!top_loading_frame_) {
1923 top_loading_frame_ = frame;
1927 WebFrame* TestRunner::topLoadingFrame() const {
1928 return top_loading_frame_;
1931 void TestRunner::policyDelegateDone() {
1932 DCHECK(wait_until_done_);
1933 delegate_->TestFinished();
1934 wait_until_done_ = false;
1937 bool TestRunner::policyDelegateEnabled() const {
1938 return policy_delegate_enabled_;
1941 bool TestRunner::policyDelegateIsPermissive() const {
1942 return policy_delegate_is_permissive_;
1945 bool TestRunner::policyDelegateShouldNotifyDone() const {
1946 return policy_delegate_should_notify_done_;
1949 bool TestRunner::shouldInterceptPostMessage() const {
1950 return intercept_post_message_;
1953 bool TestRunner::shouldDumpResourcePriorities() const {
1954 return should_dump_resource_priorities_;
1957 bool TestRunner::RequestPointerLock() {
1958 switch (pointer_lock_planned_result_) {
1959 case PointerLockWillSucceed:
1960 delegate_->PostDelayedTask(
1961 new HostMethodTask(this, &TestRunner::DidAcquirePointerLockInternal),
1963 return true;
1964 case PointerLockWillRespondAsync:
1965 DCHECK(!pointer_locked_);
1966 return true;
1967 case PointerLockWillFailSync:
1968 DCHECK(!pointer_locked_);
1969 return false;
1970 default:
1971 NOTREACHED();
1972 return false;
1976 void TestRunner::RequestPointerUnlock() {
1977 delegate_->PostDelayedTask(
1978 new HostMethodTask(this, &TestRunner::DidLosePointerLockInternal), 0);
1981 bool TestRunner::isPointerLocked() {
1982 return pointer_locked_;
1985 void TestRunner::setToolTipText(const WebString& text) {
1986 tooltip_text_ = text.utf8();
1989 bool TestRunner::shouldDumpDragImage() {
1990 return dump_drag_image_;
1993 bool TestRunner::shouldDumpNavigationPolicy() const {
1994 return dump_navigation_policy_;
1997 bool TestRunner::midiAccessorResult() {
1998 return midi_accessor_result_;
2001 void TestRunner::ClearDevToolsLocalStorage() {
2002 delegate_->ClearDevToolsLocalStorage();
2005 void TestRunner::ShowDevTools(const std::string& settings,
2006 const std::string& frontend_url) {
2007 delegate_->ShowDevTools(settings, frontend_url);
2010 class WorkItemBackForward : public TestRunner::WorkItem {
2011 public:
2012 WorkItemBackForward(int distance) : distance_(distance) {}
2014 bool Run(WebTestDelegate* delegate, WebView*) override {
2015 delegate->GoToOffset(distance_);
2016 return true; // FIXME: Did it really start a navigation?
2019 private:
2020 int distance_;
2023 void TestRunner::NotifyDone() {
2024 if (disable_notify_done_)
2025 return;
2027 // Test didn't timeout. Kill the timeout timer.
2028 task_list_.RevokeAll();
2030 CompleteNotifyDone();
2033 void TestRunner::WaitUntilDone() {
2034 wait_until_done_ = true;
2037 void TestRunner::QueueBackNavigation(int how_far_back) {
2038 work_queue_.AddWork(new WorkItemBackForward(-how_far_back));
2041 void TestRunner::QueueForwardNavigation(int how_far_forward) {
2042 work_queue_.AddWork(new WorkItemBackForward(how_far_forward));
2045 class WorkItemReload : public TestRunner::WorkItem {
2046 public:
2047 bool Run(WebTestDelegate* delegate, WebView*) override {
2048 delegate->Reload();
2049 return true;
2053 void TestRunner::QueueReload() {
2054 work_queue_.AddWork(new WorkItemReload());
2057 class WorkItemLoadingScript : public TestRunner::WorkItem {
2058 public:
2059 WorkItemLoadingScript(const std::string& script)
2060 : script_(script) {}
2062 bool Run(WebTestDelegate*, WebView* web_view) override {
2063 web_view->mainFrame()->executeScript(
2064 WebScriptSource(WebString::fromUTF8(script_)));
2065 return true; // FIXME: Did it really start a navigation?
2068 private:
2069 std::string script_;
2072 void TestRunner::QueueLoadingScript(const std::string& script) {
2073 work_queue_.AddWork(new WorkItemLoadingScript(script));
2076 class WorkItemNonLoadingScript : public TestRunner::WorkItem {
2077 public:
2078 WorkItemNonLoadingScript(const std::string& script)
2079 : script_(script) {}
2081 bool Run(WebTestDelegate*, WebView* web_view) override {
2082 web_view->mainFrame()->executeScript(
2083 WebScriptSource(WebString::fromUTF8(script_)));
2084 return false;
2087 private:
2088 std::string script_;
2091 void TestRunner::QueueNonLoadingScript(const std::string& script) {
2092 work_queue_.AddWork(new WorkItemNonLoadingScript(script));
2095 class WorkItemLoad : public TestRunner::WorkItem {
2096 public:
2097 WorkItemLoad(const WebURL& url, const std::string& target)
2098 : url_(url), target_(target) {}
2100 bool Run(WebTestDelegate* delegate, WebView*) override {
2101 delegate->LoadURLForFrame(url_, target_);
2102 return true; // FIXME: Did it really start a navigation?
2105 private:
2106 WebURL url_;
2107 std::string target_;
2110 void TestRunner::QueueLoad(const std::string& url, const std::string& target) {
2111 // FIXME: Implement WebURL::resolve() and avoid GURL.
2112 GURL current_url = web_view_->mainFrame()->document().url();
2113 GURL full_url = current_url.Resolve(url);
2114 work_queue_.AddWork(new WorkItemLoad(full_url, target));
2117 class WorkItemLoadHTMLString : public TestRunner::WorkItem {
2118 public:
2119 WorkItemLoadHTMLString(const std::string& html, const WebURL& base_url)
2120 : html_(html), base_url_(base_url) {}
2122 WorkItemLoadHTMLString(const std::string& html, const WebURL& base_url,
2123 const WebURL& unreachable_url)
2124 : html_(html), base_url_(base_url), unreachable_url_(unreachable_url) {}
2126 bool Run(WebTestDelegate*, WebView* web_view) override {
2127 web_view->mainFrame()->loadHTMLString(
2128 WebData(html_.data(), html_.length()),
2129 base_url_, unreachable_url_);
2130 return true;
2133 private:
2134 std::string html_;
2135 WebURL base_url_;
2136 WebURL unreachable_url_;
2139 void TestRunner::QueueLoadHTMLString(gin::Arguments* args) {
2140 std::string html;
2141 args->GetNext(&html);
2143 std::string base_url_str;
2144 args->GetNext(&base_url_str);
2145 WebURL base_url = WebURL(GURL(base_url_str));
2147 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsString()) {
2148 std::string unreachable_url_str;
2149 args->GetNext(&unreachable_url_str);
2150 WebURL unreachable_url = WebURL(GURL(unreachable_url_str));
2151 work_queue_.AddWork(new WorkItemLoadHTMLString(html, base_url,
2152 unreachable_url));
2153 } else {
2154 work_queue_.AddWork(new WorkItemLoadHTMLString(html, base_url));
2158 void TestRunner::SetCustomPolicyDelegate(gin::Arguments* args) {
2159 args->GetNext(&policy_delegate_enabled_);
2160 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsBoolean())
2161 args->GetNext(&policy_delegate_is_permissive_);
2164 void TestRunner::WaitForPolicyDelegate() {
2165 policy_delegate_enabled_ = true;
2166 policy_delegate_should_notify_done_ = true;
2167 wait_until_done_ = true;
2170 int TestRunner::WindowCount() {
2171 return test_interfaces_->GetWindowList().size();
2174 void TestRunner::SetCloseRemainingWindowsWhenComplete(
2175 bool close_remaining_windows) {
2176 close_remaining_windows_ = close_remaining_windows;
2179 void TestRunner::ResetTestHelperControllers() {
2180 test_interfaces_->ResetTestHelperControllers();
2183 void TestRunner::SetTabKeyCyclesThroughElements(
2184 bool tab_key_cycles_through_elements) {
2185 web_view_->setTabKeyCyclesThroughElements(tab_key_cycles_through_elements);
2188 void TestRunner::ExecCommand(gin::Arguments* args) {
2189 std::string command;
2190 args->GetNext(&command);
2192 std::string value;
2193 if (args->Length() >= 3) {
2194 // Ignore the second parameter (which is userInterface)
2195 // since this command emulates a manual action.
2196 args->Skip();
2197 args->GetNext(&value);
2200 // Note: webkit's version does not return the boolean, so neither do we.
2201 web_view_->focusedFrame()->executeCommand(WebString::fromUTF8(command),
2202 WebString::fromUTF8(value));
2205 bool TestRunner::IsCommandEnabled(const std::string& command) {
2206 return web_view_->focusedFrame()->isCommandEnabled(
2207 WebString::fromUTF8(command));
2210 bool TestRunner::CallShouldCloseOnWebView() {
2211 return web_view_->mainFrame()->dispatchBeforeUnloadEvent();
2214 void TestRunner::SetDomainRelaxationForbiddenForURLScheme(
2215 bool forbidden, const std::string& scheme) {
2216 web_view_->setDomainRelaxationForbidden(forbidden,
2217 WebString::fromUTF8(scheme));
2220 v8::Local<v8::Value> TestRunner::EvaluateScriptInIsolatedWorldAndReturnValue(
2221 int world_id,
2222 const std::string& script) {
2223 WebVector<v8::Local<v8::Value>> values;
2224 WebScriptSource source(WebString::fromUTF8(script));
2225 // This relies on the iframe focusing itself when it loads. This is a bit
2226 // sketchy, but it seems to be what other tests do.
2227 web_view_->focusedFrame()->executeScriptInIsolatedWorld(
2228 world_id, &source, 1, 1, &values);
2229 // Since only one script was added, only one result is expected
2230 if (values.size() == 1 && !values[0].IsEmpty())
2231 return values[0];
2232 return v8::Local<v8::Value>();
2235 void TestRunner::EvaluateScriptInIsolatedWorld(int world_id,
2236 const std::string& script) {
2237 WebScriptSource source(WebString::fromUTF8(script));
2238 web_view_->focusedFrame()->executeScriptInIsolatedWorld(
2239 world_id, &source, 1, 1);
2242 void TestRunner::SetIsolatedWorldSecurityOrigin(int world_id,
2243 v8::Local<v8::Value> origin) {
2244 if (!(origin->IsString() || !origin->IsNull()))
2245 return;
2247 WebSecurityOrigin web_origin;
2248 if (origin->IsString()) {
2249 web_origin = WebSecurityOrigin::createFromString(
2250 V8StringToWebString(origin.As<v8::String>()));
2252 web_view_->focusedFrame()->setIsolatedWorldSecurityOrigin(world_id,
2253 web_origin);
2256 void TestRunner::SetIsolatedWorldContentSecurityPolicy(
2257 int world_id,
2258 const std::string& policy) {
2259 web_view_->focusedFrame()->setIsolatedWorldContentSecurityPolicy(
2260 world_id, WebString::fromUTF8(policy));
2263 void TestRunner::AddOriginAccessWhitelistEntry(
2264 const std::string& source_origin,
2265 const std::string& destination_protocol,
2266 const std::string& destination_host,
2267 bool allow_destination_subdomains) {
2268 WebURL url((GURL(source_origin)));
2269 if (!url.isValid())
2270 return;
2272 WebSecurityPolicy::addOriginAccessWhitelistEntry(
2273 url,
2274 WebString::fromUTF8(destination_protocol),
2275 WebString::fromUTF8(destination_host),
2276 allow_destination_subdomains);
2279 void TestRunner::RemoveOriginAccessWhitelistEntry(
2280 const std::string& source_origin,
2281 const std::string& destination_protocol,
2282 const std::string& destination_host,
2283 bool allow_destination_subdomains) {
2284 WebURL url((GURL(source_origin)));
2285 if (!url.isValid())
2286 return;
2288 WebSecurityPolicy::removeOriginAccessWhitelistEntry(
2289 url,
2290 WebString::fromUTF8(destination_protocol),
2291 WebString::fromUTF8(destination_host),
2292 allow_destination_subdomains);
2295 bool TestRunner::HasCustomPageSizeStyle(int page_index) {
2296 WebFrame* frame = web_view_->mainFrame();
2297 if (!frame)
2298 return false;
2299 return frame->hasCustomPageSizeStyle(page_index);
2302 void TestRunner::ForceRedSelectionColors() {
2303 web_view_->setSelectionColors(0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0);
2306 void TestRunner::InsertStyleSheet(const std::string& source_code) {
2307 WebLocalFrame::frameForCurrentContext()->document().insertStyleSheet(
2308 WebString::fromUTF8(source_code));
2311 bool TestRunner::FindString(const std::string& search_text,
2312 const std::vector<std::string>& options_array) {
2313 WebFindOptions find_options;
2314 bool wrap_around = false;
2315 find_options.matchCase = true;
2316 find_options.findNext = true;
2318 for (const std::string& option : options_array) {
2319 if (option == "CaseInsensitive")
2320 find_options.matchCase = false;
2321 else if (option == "Backwards")
2322 find_options.forward = false;
2323 else if (option == "StartInSelection")
2324 find_options.findNext = false;
2325 else if (option == "AtWordStarts")
2326 find_options.wordStart = true;
2327 else if (option == "TreatMedialCapitalAsWordStart")
2328 find_options.medialCapitalAsWordStart = true;
2329 else if (option == "WrapAround")
2330 wrap_around = true;
2333 WebFrame* frame = web_view_->mainFrame();
2334 const bool find_result = frame->find(0, WebString::fromUTF8(search_text),
2335 find_options, wrap_around, 0);
2336 frame->stopFinding(false);
2337 return find_result;
2340 std::string TestRunner::SelectionAsMarkup() {
2341 return web_view_->mainFrame()->selectionAsMarkup().utf8();
2344 void TestRunner::SetTextSubpixelPositioning(bool value) {
2345 #if defined(__linux__) || defined(ANDROID)
2346 // Since FontConfig doesn't provide a variable to control subpixel
2347 // positioning, we'll fall back to setting it globally for all fonts.
2348 WebFontRendering::setSubpixelPositioning(value);
2349 #endif
2352 void TestRunner::SetPageVisibility(const std::string& new_visibility) {
2353 if (new_visibility == "visible")
2354 web_view_->setVisibilityState(WebPageVisibilityStateVisible, false);
2355 else if (new_visibility == "hidden")
2356 web_view_->setVisibilityState(WebPageVisibilityStateHidden, false);
2357 else if (new_visibility == "prerender")
2358 web_view_->setVisibilityState(WebPageVisibilityStatePrerender, false);
2361 void TestRunner::SetTextDirection(const std::string& direction_name) {
2362 // Map a direction name to a WebTextDirection value.
2363 WebTextDirection direction;
2364 if (direction_name == "auto")
2365 direction = WebTextDirectionDefault;
2366 else if (direction_name == "rtl")
2367 direction = WebTextDirectionRightToLeft;
2368 else if (direction_name == "ltr")
2369 direction = WebTextDirectionLeftToRight;
2370 else
2371 return;
2373 web_view_->setTextDirection(direction);
2376 void TestRunner::UseUnfortunateSynchronousResizeMode() {
2377 delegate_->UseUnfortunateSynchronousResizeMode(true);
2380 bool TestRunner::EnableAutoResizeMode(int min_width,
2381 int min_height,
2382 int max_width,
2383 int max_height) {
2384 WebSize min_size(min_width, min_height);
2385 WebSize max_size(max_width, max_height);
2386 delegate_->EnableAutoResizeMode(min_size, max_size);
2387 return true;
2390 bool TestRunner::DisableAutoResizeMode(int new_width, int new_height) {
2391 WebSize new_size(new_width, new_height);
2392 delegate_->DisableAutoResizeMode(new_size);
2393 return true;
2396 void TestRunner::SetMockDeviceLight(double value) {
2397 delegate_->SetDeviceLightData(value);
2400 void TestRunner::ResetDeviceLight() {
2401 delegate_->SetDeviceLightData(-1);
2404 void TestRunner::SetMockDeviceMotion(
2405 bool has_acceleration_x, double acceleration_x,
2406 bool has_acceleration_y, double acceleration_y,
2407 bool has_acceleration_z, double acceleration_z,
2408 bool has_acceleration_including_gravity_x,
2409 double acceleration_including_gravity_x,
2410 bool has_acceleration_including_gravity_y,
2411 double acceleration_including_gravity_y,
2412 bool has_acceleration_including_gravity_z,
2413 double acceleration_including_gravity_z,
2414 bool has_rotation_rate_alpha, double rotation_rate_alpha,
2415 bool has_rotation_rate_beta, double rotation_rate_beta,
2416 bool has_rotation_rate_gamma, double rotation_rate_gamma,
2417 double interval) {
2418 WebDeviceMotionData motion;
2420 // acceleration
2421 motion.hasAccelerationX = has_acceleration_x;
2422 motion.accelerationX = acceleration_x;
2423 motion.hasAccelerationY = has_acceleration_y;
2424 motion.accelerationY = acceleration_y;
2425 motion.hasAccelerationZ = has_acceleration_z;
2426 motion.accelerationZ = acceleration_z;
2428 // accelerationIncludingGravity
2429 motion.hasAccelerationIncludingGravityX =
2430 has_acceleration_including_gravity_x;
2431 motion.accelerationIncludingGravityX = acceleration_including_gravity_x;
2432 motion.hasAccelerationIncludingGravityY =
2433 has_acceleration_including_gravity_y;
2434 motion.accelerationIncludingGravityY = acceleration_including_gravity_y;
2435 motion.hasAccelerationIncludingGravityZ =
2436 has_acceleration_including_gravity_z;
2437 motion.accelerationIncludingGravityZ = acceleration_including_gravity_z;
2439 // rotationRate
2440 motion.hasRotationRateAlpha = has_rotation_rate_alpha;
2441 motion.rotationRateAlpha = rotation_rate_alpha;
2442 motion.hasRotationRateBeta = has_rotation_rate_beta;
2443 motion.rotationRateBeta = rotation_rate_beta;
2444 motion.hasRotationRateGamma = has_rotation_rate_gamma;
2445 motion.rotationRateGamma = rotation_rate_gamma;
2447 // interval
2448 motion.interval = interval;
2450 delegate_->SetDeviceMotionData(motion);
2453 void TestRunner::SetMockDeviceOrientation(bool has_alpha, double alpha,
2454 bool has_beta, double beta,
2455 bool has_gamma, double gamma,
2456 bool has_absolute, bool absolute) {
2457 WebDeviceOrientationData orientation;
2459 // alpha
2460 orientation.hasAlpha = has_alpha;
2461 orientation.alpha = alpha;
2463 // beta
2464 orientation.hasBeta = has_beta;
2465 orientation.beta = beta;
2467 // gamma
2468 orientation.hasGamma = has_gamma;
2469 orientation.gamma = gamma;
2471 // absolute
2472 orientation.hasAbsolute = has_absolute;
2473 orientation.absolute = absolute;
2475 delegate_->SetDeviceOrientationData(orientation);
2478 void TestRunner::SetMockScreenOrientation(const std::string& orientation_str) {
2479 blink::WebScreenOrientationType orientation;
2481 if (orientation_str == "portrait-primary") {
2482 orientation = WebScreenOrientationPortraitPrimary;
2483 } else if (orientation_str == "portrait-secondary") {
2484 orientation = WebScreenOrientationPortraitSecondary;
2485 } else if (orientation_str == "landscape-primary") {
2486 orientation = WebScreenOrientationLandscapePrimary;
2487 } else if (orientation_str == "landscape-secondary") {
2488 orientation = WebScreenOrientationLandscapeSecondary;
2491 delegate_->SetScreenOrientation(orientation);
2494 void TestRunner::DidChangeBatteryStatus(bool charging,
2495 double chargingTime,
2496 double dischargingTime,
2497 double level) {
2498 blink::WebBatteryStatus status;
2499 status.charging = charging;
2500 status.chargingTime = chargingTime;
2501 status.dischargingTime = dischargingTime;
2502 status.level = level;
2503 delegate_->DidChangeBatteryStatus(status);
2506 void TestRunner::ResetBatteryStatus() {
2507 blink::WebBatteryStatus status;
2508 delegate_->DidChangeBatteryStatus(status);
2511 void TestRunner::DidAcquirePointerLock() {
2512 DidAcquirePointerLockInternal();
2515 void TestRunner::DidNotAcquirePointerLock() {
2516 DidNotAcquirePointerLockInternal();
2519 void TestRunner::DidLosePointerLock() {
2520 DidLosePointerLockInternal();
2523 void TestRunner::SetPointerLockWillFailSynchronously() {
2524 pointer_lock_planned_result_ = PointerLockWillFailSync;
2527 void TestRunner::SetPointerLockWillRespondAsynchronously() {
2528 pointer_lock_planned_result_ = PointerLockWillRespondAsync;
2531 void TestRunner::SetPopupBlockingEnabled(bool block_popups) {
2532 delegate_->Preferences()->java_script_can_open_windows_automatically =
2533 !block_popups;
2534 delegate_->ApplyPreferences();
2537 void TestRunner::SetJavaScriptCanAccessClipboard(bool can_access) {
2538 delegate_->Preferences()->java_script_can_access_clipboard = can_access;
2539 delegate_->ApplyPreferences();
2542 void TestRunner::SetXSSAuditorEnabled(bool enabled) {
2543 delegate_->Preferences()->xss_auditor_enabled = enabled;
2544 delegate_->ApplyPreferences();
2547 void TestRunner::SetAllowUniversalAccessFromFileURLs(bool allow) {
2548 delegate_->Preferences()->allow_universal_access_from_file_urls = allow;
2549 delegate_->ApplyPreferences();
2552 void TestRunner::SetAllowFileAccessFromFileURLs(bool allow) {
2553 delegate_->Preferences()->allow_file_access_from_file_urls = allow;
2554 delegate_->ApplyPreferences();
2557 void TestRunner::OverridePreference(const std::string key,
2558 v8::Local<v8::Value> value) {
2559 TestPreferences* prefs = delegate_->Preferences();
2560 if (key == "WebKitDefaultFontSize") {
2561 prefs->default_font_size = value->Int32Value();
2562 } else if (key == "WebKitMinimumFontSize") {
2563 prefs->minimum_font_size = value->Int32Value();
2564 } else if (key == "WebKitDefaultTextEncodingName") {
2565 v8::Isolate* isolate = blink::mainThreadIsolate();
2566 prefs->default_text_encoding_name =
2567 V8StringToWebString(value->ToString(isolate));
2568 } else if (key == "WebKitJavaScriptEnabled") {
2569 prefs->java_script_enabled = value->BooleanValue();
2570 } else if (key == "WebKitSupportsMultipleWindows") {
2571 prefs->supports_multiple_windows = value->BooleanValue();
2572 } else if (key == "WebKitDisplayImagesKey") {
2573 prefs->loads_images_automatically = value->BooleanValue();
2574 } else if (key == "WebKitPluginsEnabled") {
2575 prefs->plugins_enabled = value->BooleanValue();
2576 } else if (key == "WebKitOfflineWebApplicationCacheEnabled") {
2577 prefs->offline_web_application_cache_enabled = value->BooleanValue();
2578 } else if (key == "WebKitTabToLinksPreferenceKey") {
2579 prefs->tabs_to_links = value->BooleanValue();
2580 } else if (key == "WebKitWebGLEnabled") {
2581 prefs->experimental_webgl_enabled = value->BooleanValue();
2582 } else if (key == "WebKitCSSRegionsEnabled") {
2583 prefs->experimental_css_regions_enabled = value->BooleanValue();
2584 } else if (key == "WebKitCSSGridLayoutEnabled") {
2585 prefs->experimental_css_grid_layout_enabled = value->BooleanValue();
2586 } else if (key == "WebKitHyperlinkAuditingEnabled") {
2587 prefs->hyperlink_auditing_enabled = value->BooleanValue();
2588 } else if (key == "WebKitEnableCaretBrowsing") {
2589 prefs->caret_browsing_enabled = value->BooleanValue();
2590 } else if (key == "WebKitAllowDisplayingInsecureContent") {
2591 prefs->allow_display_of_insecure_content = value->BooleanValue();
2592 } else if (key == "WebKitAllowRunningInsecureContent") {
2593 prefs->allow_running_of_insecure_content = value->BooleanValue();
2594 } else if (key == "WebKitDisableReadingFromCanvas") {
2595 prefs->disable_reading_from_canvas = value->BooleanValue();
2596 } else if (key == "WebKitStrictMixedContentChecking") {
2597 prefs->strict_mixed_content_checking = value->BooleanValue();
2598 } else if (key == "WebKitStrictPowerfulFeatureRestrictions") {
2599 prefs->strict_powerful_feature_restrictions = value->BooleanValue();
2600 } else if (key == "WebKitShouldRespectImageOrientation") {
2601 prefs->should_respect_image_orientation = value->BooleanValue();
2602 } else if (key == "WebKitWebAudioEnabled") {
2603 DCHECK(value->BooleanValue());
2604 } else if (key == "WebKitWebSecurityEnabled") {
2605 prefs->web_security_enabled = value->BooleanValue();
2606 } else {
2607 std::string message("Invalid name for preference: ");
2608 message.append(key);
2609 delegate_->PrintMessage(std::string("CONSOLE MESSAGE: ") + message + "\n");
2611 delegate_->ApplyPreferences();
2614 void TestRunner::SetAcceptLanguages(const std::string& accept_languages) {
2615 proxy_->SetAcceptLanguages(accept_languages);
2618 void TestRunner::SetPluginsEnabled(bool enabled) {
2619 delegate_->Preferences()->plugins_enabled = enabled;
2620 delegate_->ApplyPreferences();
2623 void TestRunner::DumpEditingCallbacks() {
2624 dump_editting_callbacks_ = true;
2627 void TestRunner::DumpAsMarkup() {
2628 dump_as_markup_ = true;
2629 generate_pixel_results_ = false;
2632 void TestRunner::DumpAsText() {
2633 dump_as_text_ = true;
2634 generate_pixel_results_ = false;
2637 void TestRunner::DumpAsTextWithPixelResults() {
2638 dump_as_text_ = true;
2639 generate_pixel_results_ = true;
2642 void TestRunner::DumpChildFrameScrollPositions() {
2643 dump_child_frame_scroll_positions_ = true;
2646 void TestRunner::DumpChildFramesAsMarkup() {
2647 dump_child_frames_as_markup_ = true;
2650 void TestRunner::DumpChildFramesAsText() {
2651 dump_child_frames_as_text_ = true;
2654 void TestRunner::DumpIconChanges() {
2655 dump_icon_changes_ = true;
2658 void TestRunner::SetAudioData(const gin::ArrayBufferView& view) {
2659 unsigned char* bytes = static_cast<unsigned char*>(view.bytes());
2660 audio_data_.resize(view.num_bytes());
2661 std::copy(bytes, bytes + view.num_bytes(), audio_data_.begin());
2662 dump_as_audio_ = true;
2665 void TestRunner::DumpFrameLoadCallbacks() {
2666 dump_frame_load_callbacks_ = true;
2669 void TestRunner::DumpPingLoaderCallbacks() {
2670 dump_ping_loader_callbacks_ = true;
2673 void TestRunner::DumpUserGestureInFrameLoadCallbacks() {
2674 dump_user_gesture_in_frame_load_callbacks_ = true;
2677 void TestRunner::DumpTitleChanges() {
2678 dump_title_changes_ = true;
2681 void TestRunner::DumpCreateView() {
2682 dump_create_view_ = true;
2685 void TestRunner::SetCanOpenWindows() {
2686 can_open_windows_ = true;
2689 void TestRunner::DumpResourceLoadCallbacks() {
2690 dump_resource_load_callbacks_ = true;
2693 void TestRunner::DumpResourceRequestCallbacks() {
2694 dump_resource_request_callbacks_ = true;
2697 void TestRunner::DumpResourceResponseMIMETypes() {
2698 dump_resource_response_mime_types_ = true;
2701 void TestRunner::SetImagesAllowed(bool allowed) {
2702 web_content_settings_->SetImagesAllowed(allowed);
2705 void TestRunner::SetMediaAllowed(bool allowed) {
2706 web_content_settings_->SetMediaAllowed(allowed);
2709 void TestRunner::SetScriptsAllowed(bool allowed) {
2710 web_content_settings_->SetScriptsAllowed(allowed);
2713 void TestRunner::SetStorageAllowed(bool allowed) {
2714 web_content_settings_->SetStorageAllowed(allowed);
2717 void TestRunner::SetPluginsAllowed(bool allowed) {
2718 web_content_settings_->SetPluginsAllowed(allowed);
2721 void TestRunner::SetAllowDisplayOfInsecureContent(bool allowed) {
2722 web_content_settings_->SetDisplayingInsecureContentAllowed(allowed);
2725 void TestRunner::SetAllowRunningOfInsecureContent(bool allowed) {
2726 web_content_settings_->SetRunningInsecureContentAllowed(allowed);
2729 void TestRunner::DumpPermissionClientCallbacks() {
2730 web_content_settings_->SetDumpCallbacks(true);
2733 void TestRunner::DumpWindowStatusChanges() {
2734 dump_window_status_changes_ = true;
2737 void TestRunner::DumpProgressFinishedCallback() {
2738 dump_progress_finished_callback_ = true;
2741 void TestRunner::DumpSpellCheckCallbacks() {
2742 dump_spell_check_callbacks_ = true;
2745 void TestRunner::DumpBackForwardList() {
2746 dump_back_forward_list_ = true;
2749 void TestRunner::DumpSelectionRect() {
2750 dump_selection_rect_ = true;
2753 void TestRunner::SetPrinting() {
2754 is_printing_ = true;
2757 void TestRunner::ClearPrinting() {
2758 is_printing_ = false;
2761 void TestRunner::SetShouldStayOnPageAfterHandlingBeforeUnload(bool value) {
2762 should_stay_on_page_after_handling_before_unload_ = value;
2765 void TestRunner::SetWillSendRequestClearHeader(const std::string& header) {
2766 if (!header.empty())
2767 http_headers_to_clear_.insert(header);
2770 void TestRunner::DumpResourceRequestPriorities() {
2771 should_dump_resource_priorities_ = true;
2774 void TestRunner::SetUseMockTheme(bool use) {
2775 use_mock_theme_ = use;
2778 void TestRunner::ShowWebInspector(const std::string& str,
2779 const std::string& frontend_url) {
2780 ShowDevTools(str, frontend_url);
2783 void TestRunner::WaitUntilExternalURLLoad() {
2784 wait_until_external_url_load_ = true;
2787 void TestRunner::DumpDragImage() {
2788 DumpAsTextWithPixelResults();
2789 dump_drag_image_ = true;
2792 void TestRunner::DumpNavigationPolicy() {
2793 dump_navigation_policy_ = true;
2796 void TestRunner::CloseWebInspector() {
2797 delegate_->CloseDevTools();
2800 bool TestRunner::IsChooserShown() {
2801 return proxy_->IsChooserShown();
2804 void TestRunner::EvaluateInWebInspector(int call_id,
2805 const std::string& script) {
2806 delegate_->EvaluateInWebInspector(call_id, script);
2809 void TestRunner::ClearAllDatabases() {
2810 delegate_->ClearAllDatabases();
2813 void TestRunner::SetDatabaseQuota(int quota) {
2814 delegate_->SetDatabaseQuota(quota);
2817 void TestRunner::SetAlwaysAcceptCookies(bool accept) {
2818 delegate_->SetAcceptAllCookies(accept);
2821 void TestRunner::SetWindowIsKey(bool value) {
2822 delegate_->SetFocus(proxy_, value);
2825 std::string TestRunner::PathToLocalResource(const std::string& path) {
2826 return delegate_->PathToLocalResource(path);
2829 void TestRunner::SetBackingScaleFactor(double value,
2830 v8::Local<v8::Function> callback) {
2831 delegate_->SetDeviceScaleFactor(value);
2832 delegate_->PostTask(new InvokeCallbackTask(this, callback));
2835 void TestRunner::SetColorProfile(const std::string& name,
2836 v8::Local<v8::Function> callback) {
2837 delegate_->SetDeviceColorProfile(name);
2838 delegate_->PostTask(new InvokeCallbackTask(this, callback));
2841 void TestRunner::SetBluetoothMockDataSet(const std::string& name) {
2842 delegate_->SetBluetoothMockDataSet(name);
2845 void TestRunner::SetBluetoothManualChooser() {
2846 delegate_->SetBluetoothManualChooser();
2849 std::vector<std::string> TestRunner::GetBluetoothManualChooserEvents() {
2850 return delegate_->GetBluetoothManualChooserEvents();
2853 void TestRunner::SendBluetoothManualChooserEvent(const std::string& event,
2854 const std::string& argument) {
2855 delegate_->SendBluetoothManualChooserEvent(event, argument);
2858 void TestRunner::SetGeofencingMockProvider(bool service_available) {
2859 delegate_->SetGeofencingMockProvider(service_available);
2862 void TestRunner::ClearGeofencingMockProvider() {
2863 delegate_->ClearGeofencingMockProvider();
2866 void TestRunner::SetGeofencingMockPosition(double latitude, double longitude) {
2867 delegate_->SetGeofencingMockPosition(latitude, longitude);
2870 void TestRunner::SetPermission(const std::string& name,
2871 const std::string& value,
2872 const GURL& origin,
2873 const GURL& embedding_origin) {
2874 delegate_->SetPermission(name, value, origin, embedding_origin);
2877 void TestRunner::DispatchBeforeInstallPromptEvent(
2878 int request_id,
2879 const std::vector<std::string>& event_platforms,
2880 v8::Local<v8::Function> callback) {
2881 scoped_ptr<InvokeCallbackTask> task(
2882 new InvokeCallbackTask(this, callback));
2884 delegate_->DispatchBeforeInstallPromptEvent(
2885 request_id, event_platforms,
2886 base::Bind(&TestRunner::DispatchBeforeInstallPromptCallback,
2887 weak_factory_.GetWeakPtr(), base::Passed(&task)));
2890 void TestRunner::ResolveBeforeInstallPromptPromise(
2891 int request_id,
2892 const std::string& platform) {
2893 delegate_->ResolveBeforeInstallPromptPromise(request_id, platform);
2896 void TestRunner::SetPOSIXLocale(const std::string& locale) {
2897 delegate_->SetLocale(locale);
2900 void TestRunner::SetMIDIAccessorResult(bool result) {
2901 midi_accessor_result_ = result;
2904 void TestRunner::SimulateWebNotificationClick(const std::string& title,
2905 int action_index) {
2906 delegate_->SimulateWebNotificationClick(title, action_index);
2909 void TestRunner::AddMockSpeechRecognitionResult(const std::string& transcript,
2910 double confidence) {
2911 proxy_->GetSpeechRecognizerMock()->AddMockResult(
2912 WebString::fromUTF8(transcript), confidence);
2915 void TestRunner::SetMockSpeechRecognitionError(const std::string& error,
2916 const std::string& message) {
2917 proxy_->GetSpeechRecognizerMock()->SetError(WebString::fromUTF8(error),
2918 WebString::fromUTF8(message));
2921 bool TestRunner::WasMockSpeechRecognitionAborted() {
2922 return proxy_->GetSpeechRecognizerMock()->WasAborted();
2925 void TestRunner::AddMockCredentialManagerResponse(const std::string& id,
2926 const std::string& name,
2927 const std::string& avatar,
2928 const std::string& password) {
2929 proxy_->GetCredentialManagerClientMock()->SetResponse(
2930 new WebPasswordCredential(WebString::fromUTF8(id),
2931 WebString::fromUTF8(password),
2932 WebString::fromUTF8(name),
2933 WebURL(GURL(avatar))));
2936 void TestRunner::AddWebPageOverlay() {
2937 if (web_view_)
2938 web_view_->setPageOverlayColor(SK_ColorCYAN);
2941 void TestRunner::RemoveWebPageOverlay() {
2942 if (web_view_)
2943 web_view_->setPageOverlayColor(SK_ColorTRANSPARENT);
2946 void TestRunner::LayoutAndPaintAsync() {
2947 proxy_->LayoutAndPaintAsyncThen(base::Closure());
2950 void TestRunner::LayoutAndPaintAsyncThen(v8::Local<v8::Function> callback) {
2951 scoped_ptr<InvokeCallbackTask> task(
2952 new InvokeCallbackTask(this, callback));
2953 proxy_->LayoutAndPaintAsyncThen(base::Bind(&TestRunner::InvokeCallback,
2954 weak_factory_.GetWeakPtr(),
2955 base::Passed(&task)));
2958 void TestRunner::GetManifestThen(v8::Local<v8::Function> callback) {
2959 scoped_ptr<InvokeCallbackTask> task(
2960 new InvokeCallbackTask(this, callback));
2962 delegate_->FetchManifest(
2963 web_view_, web_view_->mainFrame()->document().manifestURL(),
2964 base::Bind(&TestRunner::GetManifestCallback, weak_factory_.GetWeakPtr(),
2965 base::Passed(&task)));
2968 void TestRunner::CapturePixelsAsyncThen(v8::Local<v8::Function> callback) {
2969 scoped_ptr<InvokeCallbackTask> task(
2970 new InvokeCallbackTask(this, callback));
2971 proxy_->CapturePixelsAsync(base::Bind(&TestRunner::CapturePixelsCallback,
2972 weak_factory_.GetWeakPtr(),
2973 base::Passed(&task)));
2976 void TestRunner::ForceNextWebGLContextCreationToFail() {
2977 if (web_view_)
2978 web_view_->forceNextWebGLContextCreationToFail();
2981 void TestRunner::ForceNextDrawingBufferCreationToFail() {
2982 if (web_view_)
2983 web_view_->forceNextDrawingBufferCreationToFail();
2986 void TestRunner::CopyImageAtAndCapturePixelsAsyncThen(
2987 int x, int y, v8::Local<v8::Function> callback) {
2988 scoped_ptr<InvokeCallbackTask> task(
2989 new InvokeCallbackTask(this, callback));
2990 proxy_->CopyImageAtAndCapturePixels(
2991 x, y, base::Bind(&TestRunner::CapturePixelsCallback,
2992 weak_factory_.GetWeakPtr(),
2993 base::Passed(&task)));
2996 void TestRunner::GetManifestCallback(scoped_ptr<InvokeCallbackTask> task,
2997 const blink::WebURLResponse& response,
2998 const std::string& data) {
2999 InvokeCallback(task.Pass());
3002 void TestRunner::CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task,
3003 const SkBitmap& snapshot) {
3004 v8::Isolate* isolate = blink::mainThreadIsolate();
3005 v8::HandleScope handle_scope(isolate);
3007 v8::Local<v8::Context> context =
3008 web_view_->mainFrame()->mainWorldScriptContext();
3009 if (context.IsEmpty())
3010 return;
3012 v8::Context::Scope context_scope(context);
3013 v8::Local<v8::Value> argv[3];
3014 SkAutoLockPixels snapshot_lock(snapshot);
3016 // Size can be 0 for cases where copyImageAt was called on position
3017 // that doesn't have an image.
3018 int width = snapshot.info().width();
3019 argv[0] = v8::Number::New(isolate, width);
3021 int height = snapshot.info().height();
3022 argv[1] = v8::Number::New(isolate, height);
3024 blink::WebArrayBuffer buffer =
3025 blink::WebArrayBuffer::create(snapshot.getSize(), 1);
3026 memcpy(buffer.data(), snapshot.getPixels(), buffer.byteLength());
3027 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT
3029 // Skia's internal byte order is BGRA. Must swap the B and R channels in
3030 // order to provide a consistent ordering to the layout tests.
3031 unsigned char* pixels = static_cast<unsigned char*>(buffer.data());
3032 unsigned len = buffer.byteLength();
3033 for (unsigned i = 0; i < len; i += 4) {
3034 std::swap(pixels[i], pixels[i + 2]);
3037 #endif
3039 argv[2] = blink::WebArrayBufferConverter::toV8Value(
3040 &buffer, context->Global(), isolate);
3042 task->SetArguments(3, argv);
3043 InvokeCallback(task.Pass());
3046 void TestRunner::DispatchBeforeInstallPromptCallback(
3047 scoped_ptr<InvokeCallbackTask> task,
3048 bool canceled) {
3049 v8::Isolate* isolate = blink::mainThreadIsolate();
3050 v8::HandleScope handle_scope(isolate);
3052 v8::Local<v8::Context> context =
3053 web_view_->mainFrame()->mainWorldScriptContext();
3054 if (context.IsEmpty())
3055 return;
3057 v8::Context::Scope context_scope(context);
3058 v8::Local<v8::Value> argv[1];
3059 argv[0] = v8::Boolean::New(isolate, canceled);
3061 task->SetArguments(1, argv);
3062 InvokeCallback(task.Pass());
3065 void TestRunner::LocationChangeDone() {
3066 web_history_item_count_ = delegate_->NavigationEntryCount();
3068 // No more new work after the first complete load.
3069 work_queue_.set_frozen(true);
3071 if (!wait_until_done_)
3072 work_queue_.ProcessWorkSoon();
3075 void TestRunner::CheckResponseMimeType() {
3076 // Text output: the test page can request different types of output which we
3077 // handle here.
3078 if (!dump_as_text_) {
3079 std::string mimeType =
3080 web_view_->mainFrame()->dataSource()->response().mimeType().utf8();
3081 if (mimeType == "text/plain") {
3082 dump_as_text_ = true;
3083 generate_pixel_results_ = false;
3088 void TestRunner::CompleteNotifyDone() {
3089 if (wait_until_done_ && !topLoadingFrame() && work_queue_.is_empty())
3090 delegate_->TestFinished();
3091 wait_until_done_ = false;
3094 void TestRunner::DidAcquirePointerLockInternal() {
3095 pointer_locked_ = true;
3096 web_view_->didAcquirePointerLock();
3098 // Reset planned result to default.
3099 pointer_lock_planned_result_ = PointerLockWillSucceed;
3102 void TestRunner::DidNotAcquirePointerLockInternal() {
3103 DCHECK(!pointer_locked_);
3104 pointer_locked_ = false;
3105 web_view_->didNotAcquirePointerLock();
3107 // Reset planned result to default.
3108 pointer_lock_planned_result_ = PointerLockWillSucceed;
3111 void TestRunner::DidLosePointerLockInternal() {
3112 bool was_locked = pointer_locked_;
3113 pointer_locked_ = false;
3114 if (was_locked)
3115 web_view_->didLosePointerLock();
3118 } // namespace test_runner