Stack sampling profiler: add fire-and-forget interface
[chromium-blink-merge.git] / components / test_runner / test_runner.cc
blob1f156c68436a6441793b7a91523f0b2dc1b5de53
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/WebServiceWorkerRegistration.h"
28 #include "third_party/WebKit/public/platform/WebURLResponse.h"
29 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceMotionData.h"
30 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceOrientationData.h"
31 #include "third_party/WebKit/public/web/WebArrayBuffer.h"
32 #include "third_party/WebKit/public/web/WebArrayBufferConverter.h"
33 #include "third_party/WebKit/public/web/WebBindings.h"
34 #include "third_party/WebKit/public/web/WebDataSource.h"
35 #include "third_party/WebKit/public/web/WebDocument.h"
36 #include "third_party/WebKit/public/web/WebFindOptions.h"
37 #include "third_party/WebKit/public/web/WebFrame.h"
38 #include "third_party/WebKit/public/web/WebGraphicsContext.h"
39 #include "third_party/WebKit/public/web/WebInputElement.h"
40 #include "third_party/WebKit/public/web/WebKit.h"
41 #include "third_party/WebKit/public/web/WebLocalFrame.h"
42 #include "third_party/WebKit/public/web/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(const std::string& title);
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 SetGeofencingMockProvider(bool service_available);
299 void ClearGeofencingMockProvider();
300 void SetGeofencingMockPosition(double latitude, double longitude);
301 void SetPermission(const std::string& name,
302 const std::string& value,
303 const std::string& origin,
304 const std::string& embedding_origin);
305 void DispatchBeforeInstallPromptEvent(
306 int request_id,
307 const std::vector<std::string>& event_platforms,
308 v8::Local<v8::Function> callback);
309 void ResolveBeforeInstallPromptPromise(int request_id,
310 const std::string& platform);
312 std::string PlatformName();
313 std::string TooltipText();
314 bool DisableNotifyDone();
315 int WebHistoryItemCount();
316 bool InterceptPostMessage();
317 void SetInterceptPostMessage(bool value);
319 void NotImplemented(const gin::Arguments& args);
321 void ForceNextWebGLContextCreationToFail();
322 void ForceNextDrawingBufferCreationToFail();
324 base::WeakPtr<TestRunner> runner_;
326 DISALLOW_COPY_AND_ASSIGN(TestRunnerBindings);
329 gin::WrapperInfo TestRunnerBindings::kWrapperInfo = {
330 gin::kEmbedderNativeGin};
332 // static
333 void TestRunnerBindings::Install(base::WeakPtr<TestRunner> runner,
334 WebFrame* frame) {
335 v8::Isolate* isolate = blink::mainThreadIsolate();
336 v8::HandleScope handle_scope(isolate);
337 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
338 if (context.IsEmpty())
339 return;
341 v8::Context::Scope context_scope(context);
343 TestRunnerBindings* wrapped = new TestRunnerBindings(runner);
344 gin::Handle<TestRunnerBindings> bindings =
345 gin::CreateHandle(isolate, wrapped);
346 if (bindings.IsEmpty())
347 return;
348 v8::Local<v8::Object> global = context->Global();
349 v8::Local<v8::Value> v8_bindings = bindings.ToV8();
351 std::vector<std::string> names;
352 names.push_back("testRunner");
353 names.push_back("layoutTestController");
354 for (size_t i = 0; i < names.size(); ++i)
355 global->Set(gin::StringToV8(isolate, names[i].c_str()), v8_bindings);
358 TestRunnerBindings::TestRunnerBindings(base::WeakPtr<TestRunner> runner)
359 : runner_(runner) {}
361 TestRunnerBindings::~TestRunnerBindings() {}
363 gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
364 v8::Isolate* isolate) {
365 return gin::Wrappable<TestRunnerBindings>::GetObjectTemplateBuilder(isolate)
366 // Methods controlling test execution.
367 .SetMethod("logToStderr", &TestRunnerBindings::LogToStderr)
368 .SetMethod("notifyDone", &TestRunnerBindings::NotifyDone)
369 .SetMethod("waitUntilDone", &TestRunnerBindings::WaitUntilDone)
370 .SetMethod("queueBackNavigation",
371 &TestRunnerBindings::QueueBackNavigation)
372 .SetMethod("queueForwardNavigation",
373 &TestRunnerBindings::QueueForwardNavigation)
374 .SetMethod("queueReload", &TestRunnerBindings::QueueReload)
375 .SetMethod("queueLoadingScript", &TestRunnerBindings::QueueLoadingScript)
376 .SetMethod("queueNonLoadingScript",
377 &TestRunnerBindings::QueueNonLoadingScript)
378 .SetMethod("queueLoad", &TestRunnerBindings::QueueLoad)
379 .SetMethod("queueLoadHTMLString",
380 &TestRunnerBindings::QueueLoadHTMLString)
381 .SetMethod("setCustomPolicyDelegate",
382 &TestRunnerBindings::SetCustomPolicyDelegate)
383 .SetMethod("waitForPolicyDelegate",
384 &TestRunnerBindings::WaitForPolicyDelegate)
385 .SetMethod("windowCount", &TestRunnerBindings::WindowCount)
386 .SetMethod("setCloseRemainingWindowsWhenComplete",
387 &TestRunnerBindings::SetCloseRemainingWindowsWhenComplete)
388 .SetMethod("resetTestHelperControllers",
389 &TestRunnerBindings::ResetTestHelperControllers)
390 .SetMethod("setTabKeyCyclesThroughElements",
391 &TestRunnerBindings::SetTabKeyCyclesThroughElements)
392 .SetMethod("execCommand", &TestRunnerBindings::ExecCommand)
393 .SetMethod("isCommandEnabled", &TestRunnerBindings::IsCommandEnabled)
394 .SetMethod("callShouldCloseOnWebView",
395 &TestRunnerBindings::CallShouldCloseOnWebView)
396 .SetMethod("setDomainRelaxationForbiddenForURLScheme",
397 &TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme)
398 .SetMethod(
399 "evaluateScriptInIsolatedWorldAndReturnValue",
400 &TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue)
401 .SetMethod("evaluateScriptInIsolatedWorld",
402 &TestRunnerBindings::EvaluateScriptInIsolatedWorld)
403 .SetMethod("setIsolatedWorldSecurityOrigin",
404 &TestRunnerBindings::SetIsolatedWorldSecurityOrigin)
405 .SetMethod("setIsolatedWorldContentSecurityPolicy",
406 &TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy)
407 .SetMethod("addOriginAccessWhitelistEntry",
408 &TestRunnerBindings::AddOriginAccessWhitelistEntry)
409 .SetMethod("removeOriginAccessWhitelistEntry",
410 &TestRunnerBindings::RemoveOriginAccessWhitelistEntry)
411 .SetMethod("hasCustomPageSizeStyle",
412 &TestRunnerBindings::HasCustomPageSizeStyle)
413 .SetMethod("forceRedSelectionColors",
414 &TestRunnerBindings::ForceRedSelectionColors)
415 .SetMethod("insertStyleSheet", &TestRunnerBindings::InsertStyleSheet)
416 .SetMethod("findString", &TestRunnerBindings::FindString)
417 .SetMethod("selectionAsMarkup", &TestRunnerBindings::SelectionAsMarkup)
418 .SetMethod("setTextSubpixelPositioning",
419 &TestRunnerBindings::SetTextSubpixelPositioning)
420 .SetMethod("setPageVisibility", &TestRunnerBindings::SetPageVisibility)
421 .SetMethod("setTextDirection", &TestRunnerBindings::SetTextDirection)
422 .SetMethod("useUnfortunateSynchronousResizeMode",
423 &TestRunnerBindings::UseUnfortunateSynchronousResizeMode)
424 .SetMethod("enableAutoResizeMode",
425 &TestRunnerBindings::EnableAutoResizeMode)
426 .SetMethod("disableAutoResizeMode",
427 &TestRunnerBindings::DisableAutoResizeMode)
428 .SetMethod("setMockDeviceLight", &TestRunnerBindings::SetMockDeviceLight)
429 .SetMethod("resetDeviceLight", &TestRunnerBindings::ResetDeviceLight)
430 .SetMethod("setMockDeviceMotion",
431 &TestRunnerBindings::SetMockDeviceMotion)
432 .SetMethod("setMockDeviceOrientation",
433 &TestRunnerBindings::SetMockDeviceOrientation)
434 .SetMethod("setMockScreenOrientation",
435 &TestRunnerBindings::SetMockScreenOrientation)
436 .SetMethod("didChangeBatteryStatus",
437 &TestRunnerBindings::DidChangeBatteryStatus)
438 .SetMethod("resetBatteryStatus", &TestRunnerBindings::ResetBatteryStatus)
439 .SetMethod("didAcquirePointerLock",
440 &TestRunnerBindings::DidAcquirePointerLock)
441 .SetMethod("didNotAcquirePointerLock",
442 &TestRunnerBindings::DidNotAcquirePointerLock)
443 .SetMethod("didLosePointerLock", &TestRunnerBindings::DidLosePointerLock)
444 .SetMethod("setPointerLockWillFailSynchronously",
445 &TestRunnerBindings::SetPointerLockWillFailSynchronously)
446 .SetMethod("setPointerLockWillRespondAsynchronously",
447 &TestRunnerBindings::SetPointerLockWillRespondAsynchronously)
448 .SetMethod("setPopupBlockingEnabled",
449 &TestRunnerBindings::SetPopupBlockingEnabled)
450 .SetMethod("setJavaScriptCanAccessClipboard",
451 &TestRunnerBindings::SetJavaScriptCanAccessClipboard)
452 .SetMethod("setXSSAuditorEnabled",
453 &TestRunnerBindings::SetXSSAuditorEnabled)
454 .SetMethod("setAllowUniversalAccessFromFileURLs",
455 &TestRunnerBindings::SetAllowUniversalAccessFromFileURLs)
456 .SetMethod("setAllowFileAccessFromFileURLs",
457 &TestRunnerBindings::SetAllowFileAccessFromFileURLs)
458 .SetMethod("overridePreference", &TestRunnerBindings::OverridePreference)
459 .SetMethod("setAcceptLanguages", &TestRunnerBindings::SetAcceptLanguages)
460 .SetMethod("setPluginsEnabled", &TestRunnerBindings::SetPluginsEnabled)
461 .SetMethod("dumpEditingCallbacks",
462 &TestRunnerBindings::DumpEditingCallbacks)
463 .SetMethod("dumpAsMarkup", &TestRunnerBindings::DumpAsMarkup)
464 .SetMethod("dumpAsText", &TestRunnerBindings::DumpAsText)
465 .SetMethod("dumpAsTextWithPixelResults",
466 &TestRunnerBindings::DumpAsTextWithPixelResults)
467 .SetMethod("dumpChildFrameScrollPositions",
468 &TestRunnerBindings::DumpChildFrameScrollPositions)
469 .SetMethod("dumpChildFramesAsText",
470 &TestRunnerBindings::DumpChildFramesAsText)
471 .SetMethod("dumpChildFramesAsMarkup",
472 &TestRunnerBindings::DumpChildFramesAsMarkup)
473 .SetMethod("dumpIconChanges", &TestRunnerBindings::DumpIconChanges)
474 .SetMethod("setAudioData", &TestRunnerBindings::SetAudioData)
475 .SetMethod("dumpFrameLoadCallbacks",
476 &TestRunnerBindings::DumpFrameLoadCallbacks)
477 .SetMethod("dumpPingLoaderCallbacks",
478 &TestRunnerBindings::DumpPingLoaderCallbacks)
479 .SetMethod("dumpUserGestureInFrameLoadCallbacks",
480 &TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks)
481 .SetMethod("dumpTitleChanges", &TestRunnerBindings::DumpTitleChanges)
482 .SetMethod("dumpCreateView", &TestRunnerBindings::DumpCreateView)
483 .SetMethod("setCanOpenWindows", &TestRunnerBindings::SetCanOpenWindows)
484 .SetMethod("dumpResourceLoadCallbacks",
485 &TestRunnerBindings::DumpResourceLoadCallbacks)
486 .SetMethod("dumpResourceRequestCallbacks",
487 &TestRunnerBindings::DumpResourceRequestCallbacks)
488 .SetMethod("dumpResourceResponseMIMETypes",
489 &TestRunnerBindings::DumpResourceResponseMIMETypes)
490 .SetMethod("setImagesAllowed", &TestRunnerBindings::SetImagesAllowed)
491 .SetMethod("setMediaAllowed", &TestRunnerBindings::SetMediaAllowed)
492 .SetMethod("setScriptsAllowed", &TestRunnerBindings::SetScriptsAllowed)
493 .SetMethod("setStorageAllowed", &TestRunnerBindings::SetStorageAllowed)
494 .SetMethod("setPluginsAllowed", &TestRunnerBindings::SetPluginsAllowed)
495 .SetMethod("setAllowDisplayOfInsecureContent",
496 &TestRunnerBindings::SetAllowDisplayOfInsecureContent)
497 .SetMethod("setAllowRunningOfInsecureContent",
498 &TestRunnerBindings::SetAllowRunningOfInsecureContent)
499 .SetMethod("dumpPermissionClientCallbacks",
500 &TestRunnerBindings::DumpPermissionClientCallbacks)
501 .SetMethod("dumpWindowStatusChanges",
502 &TestRunnerBindings::DumpWindowStatusChanges)
503 .SetMethod("dumpProgressFinishedCallback",
504 &TestRunnerBindings::DumpProgressFinishedCallback)
505 .SetMethod("dumpSpellCheckCallbacks",
506 &TestRunnerBindings::DumpSpellCheckCallbacks)
507 .SetMethod("dumpBackForwardList",
508 &TestRunnerBindings::DumpBackForwardList)
509 .SetMethod("dumpSelectionRect", &TestRunnerBindings::DumpSelectionRect)
510 .SetMethod("setPrinting", &TestRunnerBindings::SetPrinting)
511 .SetMethod("clearPrinting", &TestRunnerBindings::ClearPrinting)
512 .SetMethod(
513 "setShouldStayOnPageAfterHandlingBeforeUnload",
514 &TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload)
515 .SetMethod("setWillSendRequestClearHeader",
516 &TestRunnerBindings::SetWillSendRequestClearHeader)
517 .SetMethod("dumpResourceRequestPriorities",
518 &TestRunnerBindings::DumpResourceRequestPriorities)
519 .SetMethod("setUseMockTheme", &TestRunnerBindings::SetUseMockTheme)
520 .SetMethod("waitUntilExternalURLLoad",
521 &TestRunnerBindings::WaitUntilExternalURLLoad)
522 .SetMethod("dumpDragImage", &TestRunnerBindings::DumpDragImage)
523 .SetMethod("dumpNavigationPolicy",
524 &TestRunnerBindings::DumpNavigationPolicy)
525 .SetMethod("showWebInspector", &TestRunnerBindings::ShowWebInspector)
526 .SetMethod("closeWebInspector", &TestRunnerBindings::CloseWebInspector)
527 .SetMethod("isChooserShown", &TestRunnerBindings::IsChooserShown)
528 .SetMethod("evaluateInWebInspector",
529 &TestRunnerBindings::EvaluateInWebInspector)
530 .SetMethod("clearAllDatabases", &TestRunnerBindings::ClearAllDatabases)
531 .SetMethod("setDatabaseQuota", &TestRunnerBindings::SetDatabaseQuota)
532 .SetMethod("setAlwaysAcceptCookies",
533 &TestRunnerBindings::SetAlwaysAcceptCookies)
534 .SetMethod("setWindowIsKey", &TestRunnerBindings::SetWindowIsKey)
535 .SetMethod("pathToLocalResource",
536 &TestRunnerBindings::PathToLocalResource)
537 .SetMethod("setBackingScaleFactor",
538 &TestRunnerBindings::SetBackingScaleFactor)
539 .SetMethod("setColorProfile", &TestRunnerBindings::SetColorProfile)
540 .SetMethod("setPOSIXLocale", &TestRunnerBindings::SetPOSIXLocale)
541 .SetMethod("setMIDIAccessorResult",
542 &TestRunnerBindings::SetMIDIAccessorResult)
543 .SetMethod("simulateWebNotificationClick",
544 &TestRunnerBindings::SimulateWebNotificationClick)
545 .SetMethod("addMockSpeechRecognitionResult",
546 &TestRunnerBindings::AddMockSpeechRecognitionResult)
547 .SetMethod("setMockSpeechRecognitionError",
548 &TestRunnerBindings::SetMockSpeechRecognitionError)
549 .SetMethod("wasMockSpeechRecognitionAborted",
550 &TestRunnerBindings::WasMockSpeechRecognitionAborted)
551 .SetMethod("addMockCredentialManagerResponse",
552 &TestRunnerBindings::AddMockCredentialManagerResponse)
553 .SetMethod("addWebPageOverlay", &TestRunnerBindings::AddWebPageOverlay)
554 .SetMethod("removeWebPageOverlay",
555 &TestRunnerBindings::RemoveWebPageOverlay)
556 .SetMethod("layoutAndPaintAsync",
557 &TestRunnerBindings::LayoutAndPaintAsync)
558 .SetMethod("layoutAndPaintAsyncThen",
559 &TestRunnerBindings::LayoutAndPaintAsyncThen)
560 .SetMethod("getManifestThen", &TestRunnerBindings::GetManifestThen)
561 .SetMethod("capturePixelsAsyncThen",
562 &TestRunnerBindings::CapturePixelsAsyncThen)
563 .SetMethod("copyImageAtAndCapturePixelsAsyncThen",
564 &TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen)
565 .SetMethod("setCustomTextOutput",
566 &TestRunnerBindings::SetCustomTextOutput)
567 .SetMethod("setViewSourceForFrame",
568 &TestRunnerBindings::SetViewSourceForFrame)
569 .SetMethod("setBluetoothMockDataSet",
570 &TestRunnerBindings::SetBluetoothMockDataSet)
571 .SetMethod("forceNextWebGLContextCreationToFail",
572 &TestRunnerBindings::ForceNextWebGLContextCreationToFail)
573 .SetMethod("forceNextDrawingBufferCreationToFail",
574 &TestRunnerBindings::ForceNextDrawingBufferCreationToFail)
575 .SetMethod("setGeofencingMockProvider",
576 &TestRunnerBindings::SetGeofencingMockProvider)
577 .SetMethod("clearGeofencingMockProvider",
578 &TestRunnerBindings::ClearGeofencingMockProvider)
579 .SetMethod("setGeofencingMockPosition",
580 &TestRunnerBindings::SetGeofencingMockPosition)
581 .SetMethod("setPermission", &TestRunnerBindings::SetPermission)
582 .SetMethod("dispatchBeforeInstallPromptEvent",
583 &TestRunnerBindings::DispatchBeforeInstallPromptEvent)
584 .SetMethod("resolveBeforeInstallPromptPromise",
585 &TestRunnerBindings::ResolveBeforeInstallPromptPromise)
587 // Properties.
588 .SetProperty("platformName", &TestRunnerBindings::PlatformName)
589 .SetProperty("tooltipText", &TestRunnerBindings::TooltipText)
590 .SetProperty("disableNotifyDone", &TestRunnerBindings::DisableNotifyDone)
591 // webHistoryItemCount is used by tests in LayoutTests\http\tests\history
592 .SetProperty("webHistoryItemCount",
593 &TestRunnerBindings::WebHistoryItemCount)
594 .SetProperty("interceptPostMessage",
595 &TestRunnerBindings::InterceptPostMessage,
596 &TestRunnerBindings::SetInterceptPostMessage)
598 // The following are stubs.
599 .SetMethod("dumpDatabaseCallbacks", &TestRunnerBindings::NotImplemented)
600 .SetMethod("setIconDatabaseEnabled", &TestRunnerBindings::NotImplemented)
601 .SetMethod("setScrollbarPolicy", &TestRunnerBindings::NotImplemented)
602 .SetMethod("clearAllApplicationCaches",
603 &TestRunnerBindings::NotImplemented)
604 .SetMethod("clearApplicationCacheForOrigin",
605 &TestRunnerBindings::NotImplemented)
606 .SetMethod("clearBackForwardList", &TestRunnerBindings::NotImplemented)
607 .SetMethod("keepWebHistory", &TestRunnerBindings::NotImplemented)
608 .SetMethod("setApplicationCacheOriginQuota",
609 &TestRunnerBindings::NotImplemented)
610 .SetMethod("setCallCloseOnWebViews", &TestRunnerBindings::NotImplemented)
611 .SetMethod("setMainFrameIsFirstResponder",
612 &TestRunnerBindings::NotImplemented)
613 .SetMethod("setUseDashboardCompatibilityMode",
614 &TestRunnerBindings::NotImplemented)
615 .SetMethod("deleteAllLocalStorage", &TestRunnerBindings::NotImplemented)
616 .SetMethod("localStorageDiskUsageForOrigin",
617 &TestRunnerBindings::NotImplemented)
618 .SetMethod("originsWithLocalStorage", &TestRunnerBindings::NotImplemented)
619 .SetMethod("deleteLocalStorageForOrigin",
620 &TestRunnerBindings::NotImplemented)
621 .SetMethod("observeStorageTrackerNotifications",
622 &TestRunnerBindings::NotImplemented)
623 .SetMethod("syncLocalStorage", &TestRunnerBindings::NotImplemented)
624 .SetMethod("addDisallowedURL", &TestRunnerBindings::NotImplemented)
625 .SetMethod("applicationCacheDiskUsageForOrigin",
626 &TestRunnerBindings::NotImplemented)
627 .SetMethod("abortModal", &TestRunnerBindings::NotImplemented)
629 // Aliases.
630 // Used at fast/dom/assign-to-window-status.html
631 .SetMethod("dumpStatusCallbacks",
632 &TestRunnerBindings::DumpWindowStatusChanges);
635 void TestRunnerBindings::LogToStderr(const std::string& output) {
636 LOG(ERROR) << output;
639 void TestRunnerBindings::NotifyDone() {
640 if (runner_)
641 runner_->NotifyDone();
644 void TestRunnerBindings::WaitUntilDone() {
645 if (runner_)
646 runner_->WaitUntilDone();
649 void TestRunnerBindings::QueueBackNavigation(int how_far_back) {
650 if (runner_)
651 runner_->QueueBackNavigation(how_far_back);
654 void TestRunnerBindings::QueueForwardNavigation(int how_far_forward) {
655 if (runner_)
656 runner_->QueueForwardNavigation(how_far_forward);
659 void TestRunnerBindings::QueueReload() {
660 if (runner_)
661 runner_->QueueReload();
664 void TestRunnerBindings::QueueLoadingScript(const std::string& script) {
665 if (runner_)
666 runner_->QueueLoadingScript(script);
669 void TestRunnerBindings::QueueNonLoadingScript(const std::string& script) {
670 if (runner_)
671 runner_->QueueNonLoadingScript(script);
674 void TestRunnerBindings::QueueLoad(gin::Arguments* args) {
675 if (runner_) {
676 std::string url;
677 std::string target;
678 args->GetNext(&url);
679 args->GetNext(&target);
680 runner_->QueueLoad(url, target);
684 void TestRunnerBindings::QueueLoadHTMLString(gin::Arguments* args) {
685 if (runner_)
686 runner_->QueueLoadHTMLString(args);
689 void TestRunnerBindings::SetCustomPolicyDelegate(gin::Arguments* args) {
690 if (runner_)
691 runner_->SetCustomPolicyDelegate(args);
694 void TestRunnerBindings::WaitForPolicyDelegate() {
695 if (runner_)
696 runner_->WaitForPolicyDelegate();
699 int TestRunnerBindings::WindowCount() {
700 if (runner_)
701 return runner_->WindowCount();
702 return 0;
705 void TestRunnerBindings::SetCloseRemainingWindowsWhenComplete(
706 gin::Arguments* args) {
707 if (!runner_)
708 return;
710 // In the original implementation, nothing happens if the argument is
711 // ommitted.
712 bool close_remaining_windows = false;
713 if (args->GetNext(&close_remaining_windows))
714 runner_->SetCloseRemainingWindowsWhenComplete(close_remaining_windows);
717 void TestRunnerBindings::ResetTestHelperControllers() {
718 if (runner_)
719 runner_->ResetTestHelperControllers();
722 void TestRunnerBindings::SetTabKeyCyclesThroughElements(
723 bool tab_key_cycles_through_elements) {
724 if (runner_)
725 runner_->SetTabKeyCyclesThroughElements(tab_key_cycles_through_elements);
728 void TestRunnerBindings::ExecCommand(gin::Arguments* args) {
729 if (runner_)
730 runner_->ExecCommand(args);
733 bool TestRunnerBindings::IsCommandEnabled(const std::string& command) {
734 if (runner_)
735 return runner_->IsCommandEnabled(command);
736 return false;
739 bool TestRunnerBindings::CallShouldCloseOnWebView() {
740 if (runner_)
741 return runner_->CallShouldCloseOnWebView();
742 return false;
745 void TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme(
746 bool forbidden, const std::string& scheme) {
747 if (runner_)
748 runner_->SetDomainRelaxationForbiddenForURLScheme(forbidden, scheme);
751 v8::Local<v8::Value>
752 TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue(
753 int world_id, const std::string& script) {
754 if (!runner_ || world_id <= 0 || world_id >= (1 << 29))
755 return v8::Local<v8::Value>();
756 return runner_->EvaluateScriptInIsolatedWorldAndReturnValue(world_id,
757 script);
760 void TestRunnerBindings::EvaluateScriptInIsolatedWorld(
761 int world_id, const std::string& script) {
762 if (runner_ && world_id > 0 && world_id < (1 << 29))
763 runner_->EvaluateScriptInIsolatedWorld(world_id, script);
766 void TestRunnerBindings::SetIsolatedWorldSecurityOrigin(
767 int world_id, v8::Local<v8::Value> origin) {
768 if (runner_)
769 runner_->SetIsolatedWorldSecurityOrigin(world_id, origin);
772 void TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy(
773 int world_id, const std::string& policy) {
774 if (runner_)
775 runner_->SetIsolatedWorldContentSecurityPolicy(world_id, policy);
778 void TestRunnerBindings::AddOriginAccessWhitelistEntry(
779 const std::string& source_origin,
780 const std::string& destination_protocol,
781 const std::string& destination_host,
782 bool allow_destination_subdomains) {
783 if (runner_) {
784 runner_->AddOriginAccessWhitelistEntry(source_origin,
785 destination_protocol,
786 destination_host,
787 allow_destination_subdomains);
791 void TestRunnerBindings::RemoveOriginAccessWhitelistEntry(
792 const std::string& source_origin,
793 const std::string& destination_protocol,
794 const std::string& destination_host,
795 bool allow_destination_subdomains) {
796 if (runner_) {
797 runner_->RemoveOriginAccessWhitelistEntry(source_origin,
798 destination_protocol,
799 destination_host,
800 allow_destination_subdomains);
804 bool TestRunnerBindings::HasCustomPageSizeStyle(int page_index) {
805 if (runner_)
806 return runner_->HasCustomPageSizeStyle(page_index);
807 return false;
810 void TestRunnerBindings::ForceRedSelectionColors() {
811 if (runner_)
812 runner_->ForceRedSelectionColors();
815 void TestRunnerBindings::InsertStyleSheet(const std::string& source_code) {
816 if (runner_)
817 runner_->InsertStyleSheet(source_code);
820 bool TestRunnerBindings::FindString(
821 const std::string& search_text,
822 const std::vector<std::string>& options_array) {
823 if (runner_)
824 return runner_->FindString(search_text, options_array);
825 return false;
828 std::string TestRunnerBindings::SelectionAsMarkup() {
829 if (runner_)
830 return runner_->SelectionAsMarkup();
831 return std::string();
834 void TestRunnerBindings::SetTextSubpixelPositioning(bool value) {
835 if (runner_)
836 runner_->SetTextSubpixelPositioning(value);
839 void TestRunnerBindings::SetPageVisibility(const std::string& new_visibility) {
840 if (runner_)
841 runner_->SetPageVisibility(new_visibility);
844 void TestRunnerBindings::SetTextDirection(const std::string& direction_name) {
845 if (runner_)
846 runner_->SetTextDirection(direction_name);
849 void TestRunnerBindings::UseUnfortunateSynchronousResizeMode() {
850 if (runner_)
851 runner_->UseUnfortunateSynchronousResizeMode();
854 bool TestRunnerBindings::EnableAutoResizeMode(int min_width,
855 int min_height,
856 int max_width,
857 int max_height) {
858 if (runner_) {
859 return runner_->EnableAutoResizeMode(min_width, min_height,
860 max_width, max_height);
862 return false;
865 bool TestRunnerBindings::DisableAutoResizeMode(int new_width, int new_height) {
866 if (runner_)
867 return runner_->DisableAutoResizeMode(new_width, new_height);
868 return false;
871 void TestRunnerBindings::SetMockDeviceLight(double value) {
872 if (!runner_)
873 return;
874 runner_->SetMockDeviceLight(value);
877 void TestRunnerBindings::ResetDeviceLight() {
878 if (runner_)
879 runner_->ResetDeviceLight();
882 void TestRunnerBindings::SetMockDeviceMotion(gin::Arguments* args) {
883 if (!runner_)
884 return;
886 bool has_acceleration_x;
887 double acceleration_x;
888 bool has_acceleration_y;
889 double acceleration_y;
890 bool has_acceleration_z;
891 double acceleration_z;
892 bool has_acceleration_including_gravity_x;
893 double acceleration_including_gravity_x;
894 bool has_acceleration_including_gravity_y;
895 double acceleration_including_gravity_y;
896 bool has_acceleration_including_gravity_z;
897 double acceleration_including_gravity_z;
898 bool has_rotation_rate_alpha;
899 double rotation_rate_alpha;
900 bool has_rotation_rate_beta;
901 double rotation_rate_beta;
902 bool has_rotation_rate_gamma;
903 double rotation_rate_gamma;
904 double interval;
906 args->GetNext(&has_acceleration_x);
907 args->GetNext(& acceleration_x);
908 args->GetNext(&has_acceleration_y);
909 args->GetNext(& acceleration_y);
910 args->GetNext(&has_acceleration_z);
911 args->GetNext(& acceleration_z);
912 args->GetNext(&has_acceleration_including_gravity_x);
913 args->GetNext(& acceleration_including_gravity_x);
914 args->GetNext(&has_acceleration_including_gravity_y);
915 args->GetNext(& acceleration_including_gravity_y);
916 args->GetNext(&has_acceleration_including_gravity_z);
917 args->GetNext(& acceleration_including_gravity_z);
918 args->GetNext(&has_rotation_rate_alpha);
919 args->GetNext(& rotation_rate_alpha);
920 args->GetNext(&has_rotation_rate_beta);
921 args->GetNext(& rotation_rate_beta);
922 args->GetNext(&has_rotation_rate_gamma);
923 args->GetNext(& rotation_rate_gamma);
924 args->GetNext(& interval);
926 runner_->SetMockDeviceMotion(has_acceleration_x, acceleration_x,
927 has_acceleration_y, acceleration_y,
928 has_acceleration_z, acceleration_z,
929 has_acceleration_including_gravity_x,
930 acceleration_including_gravity_x,
931 has_acceleration_including_gravity_y,
932 acceleration_including_gravity_y,
933 has_acceleration_including_gravity_z,
934 acceleration_including_gravity_z,
935 has_rotation_rate_alpha,
936 rotation_rate_alpha,
937 has_rotation_rate_beta,
938 rotation_rate_beta,
939 has_rotation_rate_gamma,
940 rotation_rate_gamma,
941 interval);
944 void TestRunnerBindings::SetMockDeviceOrientation(gin::Arguments* args) {
945 if (!runner_)
946 return;
948 bool has_alpha = false;
949 double alpha = 0.0;
950 bool has_beta = false;
951 double beta = 0.0;
952 bool has_gamma = false;
953 double gamma = 0.0;
954 bool has_absolute = false;
955 bool absolute = false;
957 args->GetNext(&has_alpha);
958 args->GetNext(&alpha);
959 args->GetNext(&has_beta);
960 args->GetNext(&beta);
961 args->GetNext(&has_gamma);
962 args->GetNext(&gamma);
963 args->GetNext(&has_absolute);
964 args->GetNext(&absolute);
966 runner_->SetMockDeviceOrientation(has_alpha, alpha,
967 has_beta, beta,
968 has_gamma, gamma,
969 has_absolute, absolute);
972 void TestRunnerBindings::SetMockScreenOrientation(
973 const std::string& orientation) {
974 if (!runner_)
975 return;
977 runner_->SetMockScreenOrientation(orientation);
980 void TestRunnerBindings::DidChangeBatteryStatus(bool charging,
981 double chargingTime,
982 double dischargingTime,
983 double level) {
984 if (runner_) {
985 runner_->DidChangeBatteryStatus(charging, chargingTime,
986 dischargingTime, level);
990 void TestRunnerBindings::ResetBatteryStatus() {
991 if (runner_)
992 runner_->ResetBatteryStatus();
995 void TestRunnerBindings::DidAcquirePointerLock() {
996 if (runner_)
997 runner_->DidAcquirePointerLock();
1000 void TestRunnerBindings::DidNotAcquirePointerLock() {
1001 if (runner_)
1002 runner_->DidNotAcquirePointerLock();
1005 void TestRunnerBindings::DidLosePointerLock() {
1006 if (runner_)
1007 runner_->DidLosePointerLock();
1010 void TestRunnerBindings::SetPointerLockWillFailSynchronously() {
1011 if (runner_)
1012 runner_->SetPointerLockWillFailSynchronously();
1015 void TestRunnerBindings::SetPointerLockWillRespondAsynchronously() {
1016 if (runner_)
1017 runner_->SetPointerLockWillRespondAsynchronously();
1020 void TestRunnerBindings::SetPopupBlockingEnabled(bool block_popups) {
1021 if (runner_)
1022 runner_->SetPopupBlockingEnabled(block_popups);
1025 void TestRunnerBindings::SetJavaScriptCanAccessClipboard(bool can_access) {
1026 if (runner_)
1027 runner_->SetJavaScriptCanAccessClipboard(can_access);
1030 void TestRunnerBindings::SetXSSAuditorEnabled(bool enabled) {
1031 if (runner_)
1032 runner_->SetXSSAuditorEnabled(enabled);
1035 void TestRunnerBindings::SetAllowUniversalAccessFromFileURLs(bool allow) {
1036 if (runner_)
1037 runner_->SetAllowUniversalAccessFromFileURLs(allow);
1040 void TestRunnerBindings::SetAllowFileAccessFromFileURLs(bool allow) {
1041 if (runner_)
1042 runner_->SetAllowFileAccessFromFileURLs(allow);
1045 void TestRunnerBindings::OverridePreference(const std::string key,
1046 v8::Local<v8::Value> value) {
1047 if (runner_)
1048 runner_->OverridePreference(key, value);
1051 void TestRunnerBindings::SetAcceptLanguages(
1052 const std::string& accept_languages) {
1053 if (!runner_)
1054 return;
1056 runner_->SetAcceptLanguages(accept_languages);
1059 void TestRunnerBindings::SetPluginsEnabled(bool enabled) {
1060 if (runner_)
1061 runner_->SetPluginsEnabled(enabled);
1064 void TestRunnerBindings::DumpEditingCallbacks() {
1065 if (runner_)
1066 runner_->DumpEditingCallbacks();
1069 void TestRunnerBindings::DumpAsMarkup() {
1070 if (runner_)
1071 runner_->DumpAsMarkup();
1074 void TestRunnerBindings::DumpAsText() {
1075 if (runner_)
1076 runner_->DumpAsText();
1079 void TestRunnerBindings::DumpAsTextWithPixelResults() {
1080 if (runner_)
1081 runner_->DumpAsTextWithPixelResults();
1084 void TestRunnerBindings::DumpChildFrameScrollPositions() {
1085 if (runner_)
1086 runner_->DumpChildFrameScrollPositions();
1089 void TestRunnerBindings::DumpChildFramesAsText() {
1090 if (runner_)
1091 runner_->DumpChildFramesAsText();
1094 void TestRunnerBindings::DumpChildFramesAsMarkup() {
1095 if (runner_)
1096 runner_->DumpChildFramesAsMarkup();
1099 void TestRunnerBindings::DumpIconChanges() {
1100 if (runner_)
1101 runner_->DumpIconChanges();
1104 void TestRunnerBindings::SetAudioData(const gin::ArrayBufferView& view) {
1105 if (runner_)
1106 runner_->SetAudioData(view);
1109 void TestRunnerBindings::DumpFrameLoadCallbacks() {
1110 if (runner_)
1111 runner_->DumpFrameLoadCallbacks();
1114 void TestRunnerBindings::DumpPingLoaderCallbacks() {
1115 if (runner_)
1116 runner_->DumpPingLoaderCallbacks();
1119 void TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks() {
1120 if (runner_)
1121 runner_->DumpUserGestureInFrameLoadCallbacks();
1124 void TestRunnerBindings::DumpTitleChanges() {
1125 if (runner_)
1126 runner_->DumpTitleChanges();
1129 void TestRunnerBindings::DumpCreateView() {
1130 if (runner_)
1131 runner_->DumpCreateView();
1134 void TestRunnerBindings::SetCanOpenWindows() {
1135 if (runner_)
1136 runner_->SetCanOpenWindows();
1139 void TestRunnerBindings::DumpResourceLoadCallbacks() {
1140 if (runner_)
1141 runner_->DumpResourceLoadCallbacks();
1144 void TestRunnerBindings::DumpResourceRequestCallbacks() {
1145 if (runner_)
1146 runner_->DumpResourceRequestCallbacks();
1149 void TestRunnerBindings::DumpResourceResponseMIMETypes() {
1150 if (runner_)
1151 runner_->DumpResourceResponseMIMETypes();
1154 void TestRunnerBindings::SetImagesAllowed(bool allowed) {
1155 if (runner_)
1156 runner_->SetImagesAllowed(allowed);
1159 void TestRunnerBindings::SetMediaAllowed(bool allowed) {
1160 if (runner_)
1161 runner_->SetMediaAllowed(allowed);
1164 void TestRunnerBindings::SetScriptsAllowed(bool allowed) {
1165 if (runner_)
1166 runner_->SetScriptsAllowed(allowed);
1169 void TestRunnerBindings::SetStorageAllowed(bool allowed) {
1170 if (runner_)
1171 runner_->SetStorageAllowed(allowed);
1174 void TestRunnerBindings::SetPluginsAllowed(bool allowed) {
1175 if (runner_)
1176 runner_->SetPluginsAllowed(allowed);
1179 void TestRunnerBindings::SetAllowDisplayOfInsecureContent(bool allowed) {
1180 if (runner_)
1181 runner_->SetAllowDisplayOfInsecureContent(allowed);
1184 void TestRunnerBindings::SetAllowRunningOfInsecureContent(bool allowed) {
1185 if (runner_)
1186 runner_->SetAllowRunningOfInsecureContent(allowed);
1189 void TestRunnerBindings::DumpPermissionClientCallbacks() {
1190 if (runner_)
1191 runner_->DumpPermissionClientCallbacks();
1194 void TestRunnerBindings::DumpWindowStatusChanges() {
1195 if (runner_)
1196 runner_->DumpWindowStatusChanges();
1199 void TestRunnerBindings::DumpProgressFinishedCallback() {
1200 if (runner_)
1201 runner_->DumpProgressFinishedCallback();
1204 void TestRunnerBindings::DumpSpellCheckCallbacks() {
1205 if (runner_)
1206 runner_->DumpSpellCheckCallbacks();
1209 void TestRunnerBindings::DumpBackForwardList() {
1210 if (runner_)
1211 runner_->DumpBackForwardList();
1214 void TestRunnerBindings::DumpSelectionRect() {
1215 if (runner_)
1216 runner_->DumpSelectionRect();
1219 void TestRunnerBindings::SetPrinting() {
1220 if (runner_)
1221 runner_->SetPrinting();
1224 void TestRunnerBindings::ClearPrinting() {
1225 if (runner_)
1226 runner_->ClearPrinting();
1229 void TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload(
1230 bool value) {
1231 if (runner_)
1232 runner_->SetShouldStayOnPageAfterHandlingBeforeUnload(value);
1235 void TestRunnerBindings::SetWillSendRequestClearHeader(
1236 const std::string& header) {
1237 if (runner_)
1238 runner_->SetWillSendRequestClearHeader(header);
1241 void TestRunnerBindings::DumpResourceRequestPriorities() {
1242 if (runner_)
1243 runner_->DumpResourceRequestPriorities();
1246 void TestRunnerBindings::SetUseMockTheme(bool use) {
1247 if (runner_)
1248 runner_->SetUseMockTheme(use);
1251 void TestRunnerBindings::WaitUntilExternalURLLoad() {
1252 if (runner_)
1253 runner_->WaitUntilExternalURLLoad();
1256 void TestRunnerBindings::DumpDragImage() {
1257 if (runner_)
1258 runner_->DumpDragImage();
1261 void TestRunnerBindings::DumpNavigationPolicy() {
1262 if (runner_)
1263 runner_->DumpNavigationPolicy();
1266 void TestRunnerBindings::ShowWebInspector(gin::Arguments* args) {
1267 if (runner_) {
1268 std::string settings;
1269 args->GetNext(&settings);
1270 std::string frontend_url;
1271 args->GetNext(&frontend_url);
1272 runner_->ShowWebInspector(settings, frontend_url);
1276 void TestRunnerBindings::CloseWebInspector() {
1277 if (runner_)
1278 runner_->CloseWebInspector();
1281 bool TestRunnerBindings::IsChooserShown() {
1282 if (runner_)
1283 return runner_->IsChooserShown();
1284 return false;
1287 void TestRunnerBindings::EvaluateInWebInspector(int call_id,
1288 const std::string& script) {
1289 if (runner_)
1290 runner_->EvaluateInWebInspector(call_id, script);
1293 void TestRunnerBindings::ClearAllDatabases() {
1294 if (runner_)
1295 runner_->ClearAllDatabases();
1298 void TestRunnerBindings::SetDatabaseQuota(int quota) {
1299 if (runner_)
1300 runner_->SetDatabaseQuota(quota);
1303 void TestRunnerBindings::SetAlwaysAcceptCookies(bool accept) {
1304 if (runner_)
1305 runner_->SetAlwaysAcceptCookies(accept);
1308 void TestRunnerBindings::SetWindowIsKey(bool value) {
1309 if (runner_)
1310 runner_->SetWindowIsKey(value);
1313 std::string TestRunnerBindings::PathToLocalResource(const std::string& path) {
1314 if (runner_)
1315 return runner_->PathToLocalResource(path);
1316 return std::string();
1319 void TestRunnerBindings::SetBackingScaleFactor(
1320 double value, v8::Local<v8::Function> callback) {
1321 if (runner_)
1322 runner_->SetBackingScaleFactor(value, callback);
1325 void TestRunnerBindings::SetColorProfile(
1326 const std::string& name, v8::Local<v8::Function> callback) {
1327 if (runner_)
1328 runner_->SetColorProfile(name, callback);
1331 void TestRunnerBindings::SetBluetoothMockDataSet(const std::string& name) {
1332 if (runner_)
1333 runner_->SetBluetoothMockDataSet(name);
1336 void TestRunnerBindings::SetPOSIXLocale(const std::string& locale) {
1337 if (runner_)
1338 runner_->SetPOSIXLocale(locale);
1341 void TestRunnerBindings::SetMIDIAccessorResult(bool result) {
1342 if (runner_)
1343 runner_->SetMIDIAccessorResult(result);
1346 void TestRunnerBindings::SimulateWebNotificationClick(
1347 const std::string& title) {
1348 if (runner_)
1349 runner_->SimulateWebNotificationClick(title);
1352 void TestRunnerBindings::AddMockSpeechRecognitionResult(
1353 const std::string& transcript, double confidence) {
1354 if (runner_)
1355 runner_->AddMockSpeechRecognitionResult(transcript, confidence);
1358 void TestRunnerBindings::SetMockSpeechRecognitionError(
1359 const std::string& error, const std::string& message) {
1360 if (runner_)
1361 runner_->SetMockSpeechRecognitionError(error, message);
1364 bool TestRunnerBindings::WasMockSpeechRecognitionAborted() {
1365 if (runner_)
1366 return runner_->WasMockSpeechRecognitionAborted();
1367 return false;
1370 void TestRunnerBindings::AddMockCredentialManagerResponse(
1371 const std::string& id,
1372 const std::string& name,
1373 const std::string& avatar,
1374 const std::string& password) {
1375 if (runner_)
1376 runner_->AddMockCredentialManagerResponse(id, name, avatar, password);
1379 void TestRunnerBindings::AddWebPageOverlay() {
1380 if (runner_)
1381 runner_->AddWebPageOverlay();
1384 void TestRunnerBindings::RemoveWebPageOverlay() {
1385 if (runner_)
1386 runner_->RemoveWebPageOverlay();
1389 void TestRunnerBindings::LayoutAndPaintAsync() {
1390 if (runner_)
1391 runner_->LayoutAndPaintAsync();
1394 void TestRunnerBindings::LayoutAndPaintAsyncThen(
1395 v8::Local<v8::Function> callback) {
1396 if (runner_)
1397 runner_->LayoutAndPaintAsyncThen(callback);
1400 void TestRunnerBindings::GetManifestThen(v8::Local<v8::Function> callback) {
1401 if (runner_)
1402 runner_->GetManifestThen(callback);
1405 void TestRunnerBindings::CapturePixelsAsyncThen(
1406 v8::Local<v8::Function> callback) {
1407 if (runner_)
1408 runner_->CapturePixelsAsyncThen(callback);
1411 void TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen(
1412 int x, int y, v8::Local<v8::Function> callback) {
1413 if (runner_)
1414 runner_->CopyImageAtAndCapturePixelsAsyncThen(x, y, callback);
1417 void TestRunnerBindings::SetCustomTextOutput(std::string output) {
1418 runner_->setCustomTextOutput(output);
1421 void TestRunnerBindings::SetViewSourceForFrame(const std::string& name,
1422 bool enabled) {
1423 if (runner_ && runner_->web_view_) {
1424 WebFrame* target_frame =
1425 runner_->web_view_->findFrameByName(WebString::fromUTF8(name));
1426 if (target_frame)
1427 target_frame->enableViewSourceMode(enabled);
1431 void TestRunnerBindings::SetGeofencingMockProvider(bool service_available) {
1432 if (runner_)
1433 runner_->SetGeofencingMockProvider(service_available);
1436 void TestRunnerBindings::ClearGeofencingMockProvider() {
1437 if (runner_)
1438 runner_->ClearGeofencingMockProvider();
1441 void TestRunnerBindings::SetGeofencingMockPosition(double latitude,
1442 double longitude) {
1443 if (runner_)
1444 runner_->SetGeofencingMockPosition(latitude, longitude);
1447 void TestRunnerBindings::SetPermission(const std::string& name,
1448 const std::string& value,
1449 const std::string& origin,
1450 const std::string& embedding_origin) {
1451 if (!runner_)
1452 return;
1454 return runner_->SetPermission(
1455 name, value, GURL(origin), GURL(embedding_origin));
1458 void TestRunnerBindings::DispatchBeforeInstallPromptEvent(
1459 int request_id,
1460 const std::vector<std::string>& event_platforms,
1461 v8::Local<v8::Function> callback) {
1462 if (!runner_)
1463 return;
1465 return runner_->DispatchBeforeInstallPromptEvent(request_id, event_platforms,
1466 callback);
1469 void TestRunnerBindings::ResolveBeforeInstallPromptPromise(
1470 int request_id,
1471 const std::string& platform) {
1472 if (!runner_)
1473 return;
1475 return runner_->ResolveBeforeInstallPromptPromise(request_id, platform);
1478 std::string TestRunnerBindings::PlatformName() {
1479 if (runner_)
1480 return runner_->platform_name_;
1481 return std::string();
1484 std::string TestRunnerBindings::TooltipText() {
1485 if (runner_)
1486 return runner_->tooltip_text_;
1487 return std::string();
1490 bool TestRunnerBindings::DisableNotifyDone() {
1491 if (runner_)
1492 return runner_->disable_notify_done_;
1493 return false;
1496 int TestRunnerBindings::WebHistoryItemCount() {
1497 if (runner_)
1498 return runner_->web_history_item_count_;
1499 return false;
1502 bool TestRunnerBindings::InterceptPostMessage() {
1503 if (runner_)
1504 return runner_->intercept_post_message_;
1505 return false;
1508 void TestRunnerBindings::SetInterceptPostMessage(bool value) {
1509 if (runner_)
1510 runner_->intercept_post_message_ = value;
1513 void TestRunnerBindings::ForceNextWebGLContextCreationToFail() {
1514 if (runner_)
1515 runner_->ForceNextWebGLContextCreationToFail();
1518 void TestRunnerBindings::ForceNextDrawingBufferCreationToFail() {
1519 if (runner_)
1520 runner_->ForceNextDrawingBufferCreationToFail();
1523 void TestRunnerBindings::NotImplemented(const gin::Arguments& args) {
1526 TestRunner::WorkQueue::WorkQueue(TestRunner* controller)
1527 : frozen_(false)
1528 , controller_(controller) {}
1530 TestRunner::WorkQueue::~WorkQueue() {
1531 Reset();
1534 void TestRunner::WorkQueue::ProcessWorkSoon() {
1535 if (controller_->topLoadingFrame())
1536 return;
1538 if (!queue_.empty()) {
1539 // We delay processing queued work to avoid recursion problems.
1540 controller_->delegate_->PostTask(new WorkQueueTask(this));
1541 } else if (!controller_->wait_until_done_) {
1542 controller_->delegate_->TestFinished();
1546 void TestRunner::WorkQueue::Reset() {
1547 frozen_ = false;
1548 while (!queue_.empty()) {
1549 delete queue_.front();
1550 queue_.pop_front();
1554 void TestRunner::WorkQueue::AddWork(WorkItem* work) {
1555 if (frozen_) {
1556 delete work;
1557 return;
1559 queue_.push_back(work);
1562 void TestRunner::WorkQueue::ProcessWork() {
1563 // Quit doing work once a load is in progress.
1564 while (!queue_.empty()) {
1565 bool startedLoad = queue_.front()->Run(controller_->delegate_,
1566 controller_->web_view_);
1567 delete queue_.front();
1568 queue_.pop_front();
1569 if (startedLoad)
1570 return;
1573 if (!controller_->wait_until_done_ && !controller_->topLoadingFrame())
1574 controller_->delegate_->TestFinished();
1577 void TestRunner::WorkQueue::WorkQueueTask::RunIfValid() {
1578 object_->ProcessWork();
1581 TestRunner::TestRunner(TestInterfaces* interfaces)
1582 : test_is_running_(false),
1583 close_remaining_windows_(false),
1584 work_queue_(this),
1585 disable_notify_done_(false),
1586 web_history_item_count_(0),
1587 intercept_post_message_(false),
1588 test_interfaces_(interfaces),
1589 delegate_(nullptr),
1590 web_view_(nullptr),
1591 web_content_settings_(new WebContentSettings()),
1592 weak_factory_(this) {}
1594 TestRunner::~TestRunner() {}
1596 void TestRunner::Install(WebFrame* frame) {
1597 TestRunnerBindings::Install(weak_factory_.GetWeakPtr(), frame);
1600 void TestRunner::SetDelegate(WebTestDelegate* delegate) {
1601 delegate_ = delegate;
1602 web_content_settings_->SetDelegate(delegate);
1605 void TestRunner::SetWebView(WebView* webView, WebTestProxyBase* proxy) {
1606 web_view_ = webView;
1607 proxy_ = proxy;
1610 void TestRunner::Reset() {
1611 if (web_view_) {
1612 web_view_->setZoomLevel(0);
1613 web_view_->setTextZoomFactor(1);
1614 web_view_->setTabKeyCyclesThroughElements(true);
1615 #if !defined(__APPLE__) && !defined(WIN32) // Actually, TOOLKIT_GTK
1616 // (Constants copied because we can't depend on the header that defined
1617 // them from this file.)
1618 web_view_->setSelectionColors(
1619 0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232);
1620 #endif
1621 web_view_->setVisibilityState(WebPageVisibilityStateVisible, true);
1622 web_view_->mainFrame()->enableViewSourceMode(false);
1624 web_view_->setPageOverlayColor(SK_ColorTRANSPARENT);
1627 top_loading_frame_ = nullptr;
1628 wait_until_done_ = false;
1629 wait_until_external_url_load_ = false;
1630 policy_delegate_enabled_ = false;
1631 policy_delegate_is_permissive_ = false;
1632 policy_delegate_should_notify_done_ = false;
1634 WebSecurityPolicy::resetOriginAccessWhitelists();
1635 #if defined(__linux__) || defined(ANDROID)
1636 WebFontRendering::setSubpixelPositioning(false);
1637 #endif
1639 if (delegate_) {
1640 // Reset the default quota for each origin to 5MB
1641 delegate_->SetDatabaseQuota(5 * 1024 * 1024);
1642 delegate_->SetDeviceColorProfile("reset");
1643 delegate_->SetDeviceScaleFactor(1);
1644 delegate_->SetAcceptAllCookies(false);
1645 delegate_->SetLocale("");
1646 delegate_->UseUnfortunateSynchronousResizeMode(false);
1647 delegate_->DisableAutoResizeMode(WebSize());
1648 delegate_->DeleteAllCookies();
1649 delegate_->ResetScreenOrientation();
1650 delegate_->SetBluetoothMockDataSet("");
1651 delegate_->ClearGeofencingMockProvider();
1652 delegate_->ResetPermissions();
1653 ResetBatteryStatus();
1654 ResetDeviceLight();
1657 dump_editting_callbacks_ = false;
1658 dump_as_text_ = false;
1659 dump_as_markup_ = false;
1660 generate_pixel_results_ = true;
1661 dump_child_frame_scroll_positions_ = false;
1662 dump_child_frames_as_markup_ = false;
1663 dump_child_frames_as_text_ = false;
1664 dump_icon_changes_ = false;
1665 dump_as_audio_ = false;
1666 dump_frame_load_callbacks_ = false;
1667 dump_ping_loader_callbacks_ = false;
1668 dump_user_gesture_in_frame_load_callbacks_ = false;
1669 dump_title_changes_ = false;
1670 dump_create_view_ = false;
1671 can_open_windows_ = false;
1672 dump_resource_load_callbacks_ = false;
1673 dump_resource_request_callbacks_ = false;
1674 dump_resource_response_mime_types_ = false;
1675 dump_window_status_changes_ = false;
1676 dump_progress_finished_callback_ = false;
1677 dump_spell_check_callbacks_ = false;
1678 dump_back_forward_list_ = false;
1679 dump_selection_rect_ = false;
1680 dump_drag_image_ = false;
1681 dump_navigation_policy_ = false;
1682 test_repaint_ = false;
1683 sweep_horizontally_ = false;
1684 is_printing_ = false;
1685 midi_accessor_result_ = true;
1686 should_stay_on_page_after_handling_before_unload_ = false;
1687 should_dump_resource_priorities_ = false;
1688 has_custom_text_output_ = false;
1689 custom_text_output_.clear();
1691 http_headers_to_clear_.clear();
1693 platform_name_ = "chromium";
1694 tooltip_text_ = std::string();
1695 disable_notify_done_ = false;
1696 web_history_item_count_ = 0;
1697 intercept_post_message_ = false;
1699 web_content_settings_->Reset();
1701 use_mock_theme_ = true;
1702 pointer_locked_ = false;
1703 pointer_lock_planned_result_ = PointerLockWillSucceed;
1705 task_list_.RevokeAll();
1706 work_queue_.Reset();
1708 if (close_remaining_windows_ && delegate_)
1709 delegate_->CloseRemainingWindows();
1710 else
1711 close_remaining_windows_ = true;
1714 void TestRunner::SetTestIsRunning(bool running) {
1715 test_is_running_ = running;
1718 void TestRunner::InvokeCallback(scoped_ptr<InvokeCallbackTask> task) {
1719 delegate_->PostTask(task.release());
1722 bool TestRunner::shouldDumpEditingCallbacks() const {
1723 return dump_editting_callbacks_;
1726 bool TestRunner::shouldDumpAsText() {
1727 CheckResponseMimeType();
1728 return dump_as_text_;
1731 void TestRunner::setShouldDumpAsText(bool value) {
1732 dump_as_text_ = value;
1735 bool TestRunner::shouldDumpAsMarkup() {
1736 return dump_as_markup_;
1739 void TestRunner::setShouldDumpAsMarkup(bool value) {
1740 dump_as_markup_ = value;
1743 bool TestRunner::shouldDumpAsCustomText() const {
1744 return has_custom_text_output_;
1747 std::string TestRunner::customDumpText() const {
1748 return custom_text_output_;
1751 void TestRunner::setCustomTextOutput(std::string text) {
1752 custom_text_output_ = text;
1753 has_custom_text_output_ = true;
1756 bool TestRunner::ShouldGeneratePixelResults() {
1757 CheckResponseMimeType();
1758 return generate_pixel_results_;
1761 bool TestRunner::ShouldStayOnPageAfterHandlingBeforeUnload() const {
1762 return should_stay_on_page_after_handling_before_unload_;
1766 void TestRunner::setShouldGeneratePixelResults(bool value) {
1767 generate_pixel_results_ = value;
1770 bool TestRunner::shouldDumpChildFrameScrollPositions() const {
1771 return dump_child_frame_scroll_positions_;
1774 bool TestRunner::shouldDumpChildFramesAsMarkup() const {
1775 return dump_child_frames_as_markup_;
1778 bool TestRunner::shouldDumpChildFramesAsText() const {
1779 return dump_child_frames_as_text_;
1782 bool TestRunner::ShouldDumpAsAudio() const {
1783 return dump_as_audio_;
1786 void TestRunner::GetAudioData(std::vector<unsigned char>* buffer_view) const {
1787 *buffer_view = audio_data_;
1790 bool TestRunner::shouldDumpFrameLoadCallbacks() const {
1791 return test_is_running_ && dump_frame_load_callbacks_;
1794 void TestRunner::setShouldDumpFrameLoadCallbacks(bool value) {
1795 dump_frame_load_callbacks_ = value;
1798 bool TestRunner::shouldDumpPingLoaderCallbacks() const {
1799 return test_is_running_ && dump_ping_loader_callbacks_;
1802 void TestRunner::setShouldDumpPingLoaderCallbacks(bool value) {
1803 dump_ping_loader_callbacks_ = value;
1806 void TestRunner::setShouldEnableViewSource(bool value) {
1807 web_view_->mainFrame()->enableViewSourceMode(value);
1810 bool TestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const {
1811 return test_is_running_ && dump_user_gesture_in_frame_load_callbacks_;
1814 bool TestRunner::shouldDumpTitleChanges() const {
1815 return dump_title_changes_;
1818 bool TestRunner::shouldDumpIconChanges() const {
1819 return dump_icon_changes_;
1822 bool TestRunner::shouldDumpCreateView() const {
1823 return dump_create_view_;
1826 bool TestRunner::canOpenWindows() const {
1827 return can_open_windows_;
1830 bool TestRunner::shouldDumpResourceLoadCallbacks() const {
1831 return test_is_running_ && dump_resource_load_callbacks_;
1834 bool TestRunner::shouldDumpResourceRequestCallbacks() const {
1835 return test_is_running_ && dump_resource_request_callbacks_;
1838 bool TestRunner::shouldDumpResourceResponseMIMETypes() const {
1839 return test_is_running_ && dump_resource_response_mime_types_;
1842 WebContentSettingsClient* TestRunner::GetWebContentSettings() const {
1843 return web_content_settings_.get();
1846 bool TestRunner::shouldDumpStatusCallbacks() const {
1847 return dump_window_status_changes_;
1850 bool TestRunner::shouldDumpProgressFinishedCallback() const {
1851 return dump_progress_finished_callback_;
1854 bool TestRunner::shouldDumpSpellCheckCallbacks() const {
1855 return dump_spell_check_callbacks_;
1858 bool TestRunner::ShouldDumpBackForwardList() const {
1859 return dump_back_forward_list_;
1862 bool TestRunner::shouldDumpSelectionRect() const {
1863 return dump_selection_rect_;
1866 bool TestRunner::isPrinting() const {
1867 return is_printing_;
1870 bool TestRunner::shouldWaitUntilExternalURLLoad() const {
1871 return wait_until_external_url_load_;
1874 const std::set<std::string>* TestRunner::httpHeadersToClear() const {
1875 return &http_headers_to_clear_;
1878 void TestRunner::setTopLoadingFrame(WebFrame* frame, bool clear) {
1879 if (frame->top()->view() != web_view_)
1880 return;
1881 if (!test_is_running_)
1882 return;
1883 if (clear) {
1884 top_loading_frame_ = nullptr;
1885 LocationChangeDone();
1886 } else if (!top_loading_frame_) {
1887 top_loading_frame_ = frame;
1891 WebFrame* TestRunner::topLoadingFrame() const {
1892 return top_loading_frame_;
1895 void TestRunner::policyDelegateDone() {
1896 DCHECK(wait_until_done_);
1897 delegate_->TestFinished();
1898 wait_until_done_ = false;
1901 bool TestRunner::policyDelegateEnabled() const {
1902 return policy_delegate_enabled_;
1905 bool TestRunner::policyDelegateIsPermissive() const {
1906 return policy_delegate_is_permissive_;
1909 bool TestRunner::policyDelegateShouldNotifyDone() const {
1910 return policy_delegate_should_notify_done_;
1913 bool TestRunner::shouldInterceptPostMessage() const {
1914 return intercept_post_message_;
1917 bool TestRunner::shouldDumpResourcePriorities() const {
1918 return should_dump_resource_priorities_;
1921 bool TestRunner::RequestPointerLock() {
1922 switch (pointer_lock_planned_result_) {
1923 case PointerLockWillSucceed:
1924 delegate_->PostDelayedTask(
1925 new HostMethodTask(this, &TestRunner::DidAcquirePointerLockInternal),
1927 return true;
1928 case PointerLockWillRespondAsync:
1929 DCHECK(!pointer_locked_);
1930 return true;
1931 case PointerLockWillFailSync:
1932 DCHECK(!pointer_locked_);
1933 return false;
1934 default:
1935 NOTREACHED();
1936 return false;
1940 void TestRunner::RequestPointerUnlock() {
1941 delegate_->PostDelayedTask(
1942 new HostMethodTask(this, &TestRunner::DidLosePointerLockInternal), 0);
1945 bool TestRunner::isPointerLocked() {
1946 return pointer_locked_;
1949 void TestRunner::setToolTipText(const WebString& text) {
1950 tooltip_text_ = text.utf8();
1953 bool TestRunner::shouldDumpDragImage() {
1954 return dump_drag_image_;
1957 bool TestRunner::shouldDumpNavigationPolicy() const {
1958 return dump_navigation_policy_;
1961 bool TestRunner::midiAccessorResult() {
1962 return midi_accessor_result_;
1965 void TestRunner::ClearDevToolsLocalStorage() {
1966 delegate_->ClearDevToolsLocalStorage();
1969 void TestRunner::ShowDevTools(const std::string& settings,
1970 const std::string& frontend_url) {
1971 delegate_->ShowDevTools(settings, frontend_url);
1974 class WorkItemBackForward : public TestRunner::WorkItem {
1975 public:
1976 WorkItemBackForward(int distance) : distance_(distance) {}
1978 bool Run(WebTestDelegate* delegate, WebView*) override {
1979 delegate->GoToOffset(distance_);
1980 return true; // FIXME: Did it really start a navigation?
1983 private:
1984 int distance_;
1987 void TestRunner::NotifyDone() {
1988 if (disable_notify_done_)
1989 return;
1991 // Test didn't timeout. Kill the timeout timer.
1992 task_list_.RevokeAll();
1994 CompleteNotifyDone();
1997 void TestRunner::WaitUntilDone() {
1998 wait_until_done_ = true;
2001 void TestRunner::QueueBackNavigation(int how_far_back) {
2002 work_queue_.AddWork(new WorkItemBackForward(-how_far_back));
2005 void TestRunner::QueueForwardNavigation(int how_far_forward) {
2006 work_queue_.AddWork(new WorkItemBackForward(how_far_forward));
2009 class WorkItemReload : public TestRunner::WorkItem {
2010 public:
2011 bool Run(WebTestDelegate* delegate, WebView*) override {
2012 delegate->Reload();
2013 return true;
2017 void TestRunner::QueueReload() {
2018 work_queue_.AddWork(new WorkItemReload());
2021 class WorkItemLoadingScript : public TestRunner::WorkItem {
2022 public:
2023 WorkItemLoadingScript(const std::string& script)
2024 : script_(script) {}
2026 bool Run(WebTestDelegate*, WebView* web_view) override {
2027 web_view->mainFrame()->executeScript(
2028 WebScriptSource(WebString::fromUTF8(script_)));
2029 return true; // FIXME: Did it really start a navigation?
2032 private:
2033 std::string script_;
2036 void TestRunner::QueueLoadingScript(const std::string& script) {
2037 work_queue_.AddWork(new WorkItemLoadingScript(script));
2040 class WorkItemNonLoadingScript : public TestRunner::WorkItem {
2041 public:
2042 WorkItemNonLoadingScript(const std::string& script)
2043 : script_(script) {}
2045 bool Run(WebTestDelegate*, WebView* web_view) override {
2046 web_view->mainFrame()->executeScript(
2047 WebScriptSource(WebString::fromUTF8(script_)));
2048 return false;
2051 private:
2052 std::string script_;
2055 void TestRunner::QueueNonLoadingScript(const std::string& script) {
2056 work_queue_.AddWork(new WorkItemNonLoadingScript(script));
2059 class WorkItemLoad : public TestRunner::WorkItem {
2060 public:
2061 WorkItemLoad(const WebURL& url, const std::string& target)
2062 : url_(url), target_(target) {}
2064 bool Run(WebTestDelegate* delegate, WebView*) override {
2065 delegate->LoadURLForFrame(url_, target_);
2066 return true; // FIXME: Did it really start a navigation?
2069 private:
2070 WebURL url_;
2071 std::string target_;
2074 void TestRunner::QueueLoad(const std::string& url, const std::string& target) {
2075 // FIXME: Implement WebURL::resolve() and avoid GURL.
2076 GURL current_url = web_view_->mainFrame()->document().url();
2077 GURL full_url = current_url.Resolve(url);
2078 work_queue_.AddWork(new WorkItemLoad(full_url, target));
2081 class WorkItemLoadHTMLString : public TestRunner::WorkItem {
2082 public:
2083 WorkItemLoadHTMLString(const std::string& html, const WebURL& base_url)
2084 : html_(html), base_url_(base_url) {}
2086 WorkItemLoadHTMLString(const std::string& html, const WebURL& base_url,
2087 const WebURL& unreachable_url)
2088 : html_(html), base_url_(base_url), unreachable_url_(unreachable_url) {}
2090 bool Run(WebTestDelegate*, WebView* web_view) override {
2091 web_view->mainFrame()->loadHTMLString(
2092 WebData(html_.data(), html_.length()),
2093 base_url_, unreachable_url_);
2094 return true;
2097 private:
2098 std::string html_;
2099 WebURL base_url_;
2100 WebURL unreachable_url_;
2103 void TestRunner::QueueLoadHTMLString(gin::Arguments* args) {
2104 std::string html;
2105 args->GetNext(&html);
2107 std::string base_url_str;
2108 args->GetNext(&base_url_str);
2109 WebURL base_url = WebURL(GURL(base_url_str));
2111 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsString()) {
2112 std::string unreachable_url_str;
2113 args->GetNext(&unreachable_url_str);
2114 WebURL unreachable_url = WebURL(GURL(unreachable_url_str));
2115 work_queue_.AddWork(new WorkItemLoadHTMLString(html, base_url,
2116 unreachable_url));
2117 } else {
2118 work_queue_.AddWork(new WorkItemLoadHTMLString(html, base_url));
2122 void TestRunner::SetCustomPolicyDelegate(gin::Arguments* args) {
2123 args->GetNext(&policy_delegate_enabled_);
2124 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsBoolean())
2125 args->GetNext(&policy_delegate_is_permissive_);
2128 void TestRunner::WaitForPolicyDelegate() {
2129 policy_delegate_enabled_ = true;
2130 policy_delegate_should_notify_done_ = true;
2131 wait_until_done_ = true;
2134 int TestRunner::WindowCount() {
2135 return test_interfaces_->GetWindowList().size();
2138 void TestRunner::SetCloseRemainingWindowsWhenComplete(
2139 bool close_remaining_windows) {
2140 close_remaining_windows_ = close_remaining_windows;
2143 void TestRunner::ResetTestHelperControllers() {
2144 test_interfaces_->ResetTestHelperControllers();
2147 void TestRunner::SetTabKeyCyclesThroughElements(
2148 bool tab_key_cycles_through_elements) {
2149 web_view_->setTabKeyCyclesThroughElements(tab_key_cycles_through_elements);
2152 void TestRunner::ExecCommand(gin::Arguments* args) {
2153 std::string command;
2154 args->GetNext(&command);
2156 std::string value;
2157 if (args->Length() >= 3) {
2158 // Ignore the second parameter (which is userInterface)
2159 // since this command emulates a manual action.
2160 args->Skip();
2161 args->GetNext(&value);
2164 // Note: webkit's version does not return the boolean, so neither do we.
2165 web_view_->focusedFrame()->executeCommand(WebString::fromUTF8(command),
2166 WebString::fromUTF8(value));
2169 bool TestRunner::IsCommandEnabled(const std::string& command) {
2170 return web_view_->focusedFrame()->isCommandEnabled(
2171 WebString::fromUTF8(command));
2174 bool TestRunner::CallShouldCloseOnWebView() {
2175 return web_view_->mainFrame()->dispatchBeforeUnloadEvent();
2178 void TestRunner::SetDomainRelaxationForbiddenForURLScheme(
2179 bool forbidden, const std::string& scheme) {
2180 web_view_->setDomainRelaxationForbidden(forbidden,
2181 WebString::fromUTF8(scheme));
2184 v8::Local<v8::Value> TestRunner::EvaluateScriptInIsolatedWorldAndReturnValue(
2185 int world_id,
2186 const std::string& script) {
2187 WebVector<v8::Local<v8::Value>> values;
2188 WebScriptSource source(WebString::fromUTF8(script));
2189 // This relies on the iframe focusing itself when it loads. This is a bit
2190 // sketchy, but it seems to be what other tests do.
2191 web_view_->focusedFrame()->executeScriptInIsolatedWorld(
2192 world_id, &source, 1, 1, &values);
2193 // Since only one script was added, only one result is expected
2194 if (values.size() == 1 && !values[0].IsEmpty())
2195 return values[0];
2196 return v8::Local<v8::Value>();
2199 void TestRunner::EvaluateScriptInIsolatedWorld(int world_id,
2200 const std::string& script) {
2201 WebScriptSource source(WebString::fromUTF8(script));
2202 web_view_->focusedFrame()->executeScriptInIsolatedWorld(
2203 world_id, &source, 1, 1);
2206 void TestRunner::SetIsolatedWorldSecurityOrigin(int world_id,
2207 v8::Local<v8::Value> origin) {
2208 if (!(origin->IsString() || !origin->IsNull()))
2209 return;
2211 WebSecurityOrigin web_origin;
2212 if (origin->IsString()) {
2213 web_origin = WebSecurityOrigin::createFromString(
2214 V8StringToWebString(origin.As<v8::String>()));
2216 web_view_->focusedFrame()->setIsolatedWorldSecurityOrigin(world_id,
2217 web_origin);
2220 void TestRunner::SetIsolatedWorldContentSecurityPolicy(
2221 int world_id,
2222 const std::string& policy) {
2223 web_view_->focusedFrame()->setIsolatedWorldContentSecurityPolicy(
2224 world_id, WebString::fromUTF8(policy));
2227 void TestRunner::AddOriginAccessWhitelistEntry(
2228 const std::string& source_origin,
2229 const std::string& destination_protocol,
2230 const std::string& destination_host,
2231 bool allow_destination_subdomains) {
2232 WebURL url((GURL(source_origin)));
2233 if (!url.isValid())
2234 return;
2236 WebSecurityPolicy::addOriginAccessWhitelistEntry(
2237 url,
2238 WebString::fromUTF8(destination_protocol),
2239 WebString::fromUTF8(destination_host),
2240 allow_destination_subdomains);
2243 void TestRunner::RemoveOriginAccessWhitelistEntry(
2244 const std::string& source_origin,
2245 const std::string& destination_protocol,
2246 const std::string& destination_host,
2247 bool allow_destination_subdomains) {
2248 WebURL url((GURL(source_origin)));
2249 if (!url.isValid())
2250 return;
2252 WebSecurityPolicy::removeOriginAccessWhitelistEntry(
2253 url,
2254 WebString::fromUTF8(destination_protocol),
2255 WebString::fromUTF8(destination_host),
2256 allow_destination_subdomains);
2259 bool TestRunner::HasCustomPageSizeStyle(int page_index) {
2260 WebFrame* frame = web_view_->mainFrame();
2261 if (!frame)
2262 return false;
2263 return frame->hasCustomPageSizeStyle(page_index);
2266 void TestRunner::ForceRedSelectionColors() {
2267 web_view_->setSelectionColors(0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0);
2270 void TestRunner::InsertStyleSheet(const std::string& source_code) {
2271 WebLocalFrame::frameForCurrentContext()->document().insertStyleSheet(
2272 WebString::fromUTF8(source_code));
2275 bool TestRunner::FindString(const std::string& search_text,
2276 const std::vector<std::string>& options_array) {
2277 WebFindOptions find_options;
2278 bool wrap_around = false;
2279 find_options.matchCase = true;
2280 find_options.findNext = true;
2282 for (const std::string& option : options_array) {
2283 if (option == "CaseInsensitive")
2284 find_options.matchCase = false;
2285 else if (option == "Backwards")
2286 find_options.forward = false;
2287 else if (option == "StartInSelection")
2288 find_options.findNext = false;
2289 else if (option == "AtWordStarts")
2290 find_options.wordStart = true;
2291 else if (option == "TreatMedialCapitalAsWordStart")
2292 find_options.medialCapitalAsWordStart = true;
2293 else if (option == "WrapAround")
2294 wrap_around = true;
2297 WebFrame* frame = web_view_->mainFrame();
2298 const bool find_result = frame->find(0, WebString::fromUTF8(search_text),
2299 find_options, wrap_around, 0);
2300 frame->stopFinding(false);
2301 return find_result;
2304 std::string TestRunner::SelectionAsMarkup() {
2305 return web_view_->mainFrame()->selectionAsMarkup().utf8();
2308 void TestRunner::SetTextSubpixelPositioning(bool value) {
2309 #if defined(__linux__) || defined(ANDROID)
2310 // Since FontConfig doesn't provide a variable to control subpixel
2311 // positioning, we'll fall back to setting it globally for all fonts.
2312 WebFontRendering::setSubpixelPositioning(value);
2313 #endif
2316 void TestRunner::SetPageVisibility(const std::string& new_visibility) {
2317 if (new_visibility == "visible")
2318 web_view_->setVisibilityState(WebPageVisibilityStateVisible, false);
2319 else if (new_visibility == "hidden")
2320 web_view_->setVisibilityState(WebPageVisibilityStateHidden, false);
2321 else if (new_visibility == "prerender")
2322 web_view_->setVisibilityState(WebPageVisibilityStatePrerender, false);
2325 void TestRunner::SetTextDirection(const std::string& direction_name) {
2326 // Map a direction name to a WebTextDirection value.
2327 WebTextDirection direction;
2328 if (direction_name == "auto")
2329 direction = WebTextDirectionDefault;
2330 else if (direction_name == "rtl")
2331 direction = WebTextDirectionRightToLeft;
2332 else if (direction_name == "ltr")
2333 direction = WebTextDirectionLeftToRight;
2334 else
2335 return;
2337 web_view_->setTextDirection(direction);
2340 void TestRunner::UseUnfortunateSynchronousResizeMode() {
2341 delegate_->UseUnfortunateSynchronousResizeMode(true);
2344 bool TestRunner::EnableAutoResizeMode(int min_width,
2345 int min_height,
2346 int max_width,
2347 int max_height) {
2348 WebSize min_size(min_width, min_height);
2349 WebSize max_size(max_width, max_height);
2350 delegate_->EnableAutoResizeMode(min_size, max_size);
2351 return true;
2354 bool TestRunner::DisableAutoResizeMode(int new_width, int new_height) {
2355 WebSize new_size(new_width, new_height);
2356 delegate_->DisableAutoResizeMode(new_size);
2357 return true;
2360 void TestRunner::SetMockDeviceLight(double value) {
2361 delegate_->SetDeviceLightData(value);
2364 void TestRunner::ResetDeviceLight() {
2365 delegate_->SetDeviceLightData(-1);
2368 void TestRunner::SetMockDeviceMotion(
2369 bool has_acceleration_x, double acceleration_x,
2370 bool has_acceleration_y, double acceleration_y,
2371 bool has_acceleration_z, double acceleration_z,
2372 bool has_acceleration_including_gravity_x,
2373 double acceleration_including_gravity_x,
2374 bool has_acceleration_including_gravity_y,
2375 double acceleration_including_gravity_y,
2376 bool has_acceleration_including_gravity_z,
2377 double acceleration_including_gravity_z,
2378 bool has_rotation_rate_alpha, double rotation_rate_alpha,
2379 bool has_rotation_rate_beta, double rotation_rate_beta,
2380 bool has_rotation_rate_gamma, double rotation_rate_gamma,
2381 double interval) {
2382 WebDeviceMotionData motion;
2384 // acceleration
2385 motion.hasAccelerationX = has_acceleration_x;
2386 motion.accelerationX = acceleration_x;
2387 motion.hasAccelerationY = has_acceleration_y;
2388 motion.accelerationY = acceleration_y;
2389 motion.hasAccelerationZ = has_acceleration_z;
2390 motion.accelerationZ = acceleration_z;
2392 // accelerationIncludingGravity
2393 motion.hasAccelerationIncludingGravityX =
2394 has_acceleration_including_gravity_x;
2395 motion.accelerationIncludingGravityX = acceleration_including_gravity_x;
2396 motion.hasAccelerationIncludingGravityY =
2397 has_acceleration_including_gravity_y;
2398 motion.accelerationIncludingGravityY = acceleration_including_gravity_y;
2399 motion.hasAccelerationIncludingGravityZ =
2400 has_acceleration_including_gravity_z;
2401 motion.accelerationIncludingGravityZ = acceleration_including_gravity_z;
2403 // rotationRate
2404 motion.hasRotationRateAlpha = has_rotation_rate_alpha;
2405 motion.rotationRateAlpha = rotation_rate_alpha;
2406 motion.hasRotationRateBeta = has_rotation_rate_beta;
2407 motion.rotationRateBeta = rotation_rate_beta;
2408 motion.hasRotationRateGamma = has_rotation_rate_gamma;
2409 motion.rotationRateGamma = rotation_rate_gamma;
2411 // interval
2412 motion.interval = interval;
2414 delegate_->SetDeviceMotionData(motion);
2417 void TestRunner::SetMockDeviceOrientation(bool has_alpha, double alpha,
2418 bool has_beta, double beta,
2419 bool has_gamma, double gamma,
2420 bool has_absolute, bool absolute) {
2421 WebDeviceOrientationData orientation;
2423 // alpha
2424 orientation.hasAlpha = has_alpha;
2425 orientation.alpha = alpha;
2427 // beta
2428 orientation.hasBeta = has_beta;
2429 orientation.beta = beta;
2431 // gamma
2432 orientation.hasGamma = has_gamma;
2433 orientation.gamma = gamma;
2435 // absolute
2436 orientation.hasAbsolute = has_absolute;
2437 orientation.absolute = absolute;
2439 delegate_->SetDeviceOrientationData(orientation);
2442 void TestRunner::SetMockScreenOrientation(const std::string& orientation_str) {
2443 blink::WebScreenOrientationType orientation;
2445 if (orientation_str == "portrait-primary") {
2446 orientation = WebScreenOrientationPortraitPrimary;
2447 } else if (orientation_str == "portrait-secondary") {
2448 orientation = WebScreenOrientationPortraitSecondary;
2449 } else if (orientation_str == "landscape-primary") {
2450 orientation = WebScreenOrientationLandscapePrimary;
2451 } else if (orientation_str == "landscape-secondary") {
2452 orientation = WebScreenOrientationLandscapeSecondary;
2455 delegate_->SetScreenOrientation(orientation);
2458 void TestRunner::DidChangeBatteryStatus(bool charging,
2459 double chargingTime,
2460 double dischargingTime,
2461 double level) {
2462 blink::WebBatteryStatus status;
2463 status.charging = charging;
2464 status.chargingTime = chargingTime;
2465 status.dischargingTime = dischargingTime;
2466 status.level = level;
2467 delegate_->DidChangeBatteryStatus(status);
2470 void TestRunner::ResetBatteryStatus() {
2471 blink::WebBatteryStatus status;
2472 delegate_->DidChangeBatteryStatus(status);
2475 void TestRunner::DidAcquirePointerLock() {
2476 DidAcquirePointerLockInternal();
2479 void TestRunner::DidNotAcquirePointerLock() {
2480 DidNotAcquirePointerLockInternal();
2483 void TestRunner::DidLosePointerLock() {
2484 DidLosePointerLockInternal();
2487 void TestRunner::SetPointerLockWillFailSynchronously() {
2488 pointer_lock_planned_result_ = PointerLockWillFailSync;
2491 void TestRunner::SetPointerLockWillRespondAsynchronously() {
2492 pointer_lock_planned_result_ = PointerLockWillRespondAsync;
2495 void TestRunner::SetPopupBlockingEnabled(bool block_popups) {
2496 delegate_->Preferences()->java_script_can_open_windows_automatically =
2497 !block_popups;
2498 delegate_->ApplyPreferences();
2501 void TestRunner::SetJavaScriptCanAccessClipboard(bool can_access) {
2502 delegate_->Preferences()->java_script_can_access_clipboard = can_access;
2503 delegate_->ApplyPreferences();
2506 void TestRunner::SetXSSAuditorEnabled(bool enabled) {
2507 delegate_->Preferences()->xss_auditor_enabled = enabled;
2508 delegate_->ApplyPreferences();
2511 void TestRunner::SetAllowUniversalAccessFromFileURLs(bool allow) {
2512 delegate_->Preferences()->allow_universal_access_from_file_urls = allow;
2513 delegate_->ApplyPreferences();
2516 void TestRunner::SetAllowFileAccessFromFileURLs(bool allow) {
2517 delegate_->Preferences()->allow_file_access_from_file_urls = allow;
2518 delegate_->ApplyPreferences();
2521 void TestRunner::OverridePreference(const std::string key,
2522 v8::Local<v8::Value> value) {
2523 TestPreferences* prefs = delegate_->Preferences();
2524 if (key == "WebKitDefaultFontSize") {
2525 prefs->default_font_size = value->Int32Value();
2526 } else if (key == "WebKitMinimumFontSize") {
2527 prefs->minimum_font_size = value->Int32Value();
2528 } else if (key == "WebKitDefaultTextEncodingName") {
2529 v8::Isolate* isolate = blink::mainThreadIsolate();
2530 prefs->default_text_encoding_name =
2531 V8StringToWebString(value->ToString(isolate));
2532 } else if (key == "WebKitJavaScriptEnabled") {
2533 prefs->java_script_enabled = value->BooleanValue();
2534 } else if (key == "WebKitSupportsMultipleWindows") {
2535 prefs->supports_multiple_windows = value->BooleanValue();
2536 } else if (key == "WebKitDisplayImagesKey") {
2537 prefs->loads_images_automatically = value->BooleanValue();
2538 } else if (key == "WebKitPluginsEnabled") {
2539 prefs->plugins_enabled = value->BooleanValue();
2540 } else if (key == "WebKitJavaEnabled") {
2541 prefs->java_enabled = value->BooleanValue();
2542 } else if (key == "WebKitOfflineWebApplicationCacheEnabled") {
2543 prefs->offline_web_application_cache_enabled = value->BooleanValue();
2544 } else if (key == "WebKitTabToLinksPreferenceKey") {
2545 prefs->tabs_to_links = value->BooleanValue();
2546 } else if (key == "WebKitWebGLEnabled") {
2547 prefs->experimental_webgl_enabled = value->BooleanValue();
2548 } else if (key == "WebKitCSSRegionsEnabled") {
2549 prefs->experimental_css_regions_enabled = value->BooleanValue();
2550 } else if (key == "WebKitCSSGridLayoutEnabled") {
2551 prefs->experimental_css_grid_layout_enabled = value->BooleanValue();
2552 } else if (key == "WebKitHyperlinkAuditingEnabled") {
2553 prefs->hyperlink_auditing_enabled = value->BooleanValue();
2554 } else if (key == "WebKitEnableCaretBrowsing") {
2555 prefs->caret_browsing_enabled = value->BooleanValue();
2556 } else if (key == "WebKitAllowDisplayingInsecureContent") {
2557 prefs->allow_display_of_insecure_content = value->BooleanValue();
2558 } else if (key == "WebKitAllowRunningInsecureContent") {
2559 prefs->allow_running_of_insecure_content = value->BooleanValue();
2560 } else if (key == "WebKitDisableReadingFromCanvas") {
2561 prefs->disable_reading_from_canvas = value->BooleanValue();
2562 } else if (key == "WebKitStrictMixedContentChecking") {
2563 prefs->strict_mixed_content_checking = value->BooleanValue();
2564 } else if (key == "WebKitStrictPowerfulFeatureRestrictions") {
2565 prefs->strict_powerful_feature_restrictions = value->BooleanValue();
2566 } else if (key == "WebKitShouldRespectImageOrientation") {
2567 prefs->should_respect_image_orientation = value->BooleanValue();
2568 } else if (key == "WebKitWebAudioEnabled") {
2569 DCHECK(value->BooleanValue());
2570 } else if (key == "WebKitWebSecurityEnabled") {
2571 prefs->web_security_enabled = value->BooleanValue();
2572 } else {
2573 std::string message("Invalid name for preference: ");
2574 message.append(key);
2575 delegate_->PrintMessage(std::string("CONSOLE MESSAGE: ") + message + "\n");
2577 delegate_->ApplyPreferences();
2580 void TestRunner::SetAcceptLanguages(const std::string& accept_languages) {
2581 proxy_->SetAcceptLanguages(accept_languages);
2584 void TestRunner::SetPluginsEnabled(bool enabled) {
2585 delegate_->Preferences()->plugins_enabled = enabled;
2586 delegate_->ApplyPreferences();
2589 void TestRunner::DumpEditingCallbacks() {
2590 dump_editting_callbacks_ = true;
2593 void TestRunner::DumpAsMarkup() {
2594 dump_as_markup_ = true;
2595 generate_pixel_results_ = false;
2598 void TestRunner::DumpAsText() {
2599 dump_as_text_ = true;
2600 generate_pixel_results_ = false;
2603 void TestRunner::DumpAsTextWithPixelResults() {
2604 dump_as_text_ = true;
2605 generate_pixel_results_ = true;
2608 void TestRunner::DumpChildFrameScrollPositions() {
2609 dump_child_frame_scroll_positions_ = true;
2612 void TestRunner::DumpChildFramesAsMarkup() {
2613 dump_child_frames_as_markup_ = true;
2616 void TestRunner::DumpChildFramesAsText() {
2617 dump_child_frames_as_text_ = true;
2620 void TestRunner::DumpIconChanges() {
2621 dump_icon_changes_ = true;
2624 void TestRunner::SetAudioData(const gin::ArrayBufferView& view) {
2625 unsigned char* bytes = static_cast<unsigned char*>(view.bytes());
2626 audio_data_.resize(view.num_bytes());
2627 std::copy(bytes, bytes + view.num_bytes(), audio_data_.begin());
2628 dump_as_audio_ = true;
2631 void TestRunner::DumpFrameLoadCallbacks() {
2632 dump_frame_load_callbacks_ = true;
2635 void TestRunner::DumpPingLoaderCallbacks() {
2636 dump_ping_loader_callbacks_ = true;
2639 void TestRunner::DumpUserGestureInFrameLoadCallbacks() {
2640 dump_user_gesture_in_frame_load_callbacks_ = true;
2643 void TestRunner::DumpTitleChanges() {
2644 dump_title_changes_ = true;
2647 void TestRunner::DumpCreateView() {
2648 dump_create_view_ = true;
2651 void TestRunner::SetCanOpenWindows() {
2652 can_open_windows_ = true;
2655 void TestRunner::DumpResourceLoadCallbacks() {
2656 dump_resource_load_callbacks_ = true;
2659 void TestRunner::DumpResourceRequestCallbacks() {
2660 dump_resource_request_callbacks_ = true;
2663 void TestRunner::DumpResourceResponseMIMETypes() {
2664 dump_resource_response_mime_types_ = true;
2667 void TestRunner::SetImagesAllowed(bool allowed) {
2668 web_content_settings_->SetImagesAllowed(allowed);
2671 void TestRunner::SetMediaAllowed(bool allowed) {
2672 web_content_settings_->SetMediaAllowed(allowed);
2675 void TestRunner::SetScriptsAllowed(bool allowed) {
2676 web_content_settings_->SetScriptsAllowed(allowed);
2679 void TestRunner::SetStorageAllowed(bool allowed) {
2680 web_content_settings_->SetStorageAllowed(allowed);
2683 void TestRunner::SetPluginsAllowed(bool allowed) {
2684 web_content_settings_->SetPluginsAllowed(allowed);
2687 void TestRunner::SetAllowDisplayOfInsecureContent(bool allowed) {
2688 web_content_settings_->SetDisplayingInsecureContentAllowed(allowed);
2691 void TestRunner::SetAllowRunningOfInsecureContent(bool allowed) {
2692 web_content_settings_->SetRunningInsecureContentAllowed(allowed);
2695 void TestRunner::DumpPermissionClientCallbacks() {
2696 web_content_settings_->SetDumpCallbacks(true);
2699 void TestRunner::DumpWindowStatusChanges() {
2700 dump_window_status_changes_ = true;
2703 void TestRunner::DumpProgressFinishedCallback() {
2704 dump_progress_finished_callback_ = true;
2707 void TestRunner::DumpSpellCheckCallbacks() {
2708 dump_spell_check_callbacks_ = true;
2711 void TestRunner::DumpBackForwardList() {
2712 dump_back_forward_list_ = true;
2715 void TestRunner::DumpSelectionRect() {
2716 dump_selection_rect_ = true;
2719 void TestRunner::SetPrinting() {
2720 is_printing_ = true;
2723 void TestRunner::ClearPrinting() {
2724 is_printing_ = false;
2727 void TestRunner::SetShouldStayOnPageAfterHandlingBeforeUnload(bool value) {
2728 should_stay_on_page_after_handling_before_unload_ = value;
2731 void TestRunner::SetWillSendRequestClearHeader(const std::string& header) {
2732 if (!header.empty())
2733 http_headers_to_clear_.insert(header);
2736 void TestRunner::DumpResourceRequestPriorities() {
2737 should_dump_resource_priorities_ = true;
2740 void TestRunner::SetUseMockTheme(bool use) {
2741 use_mock_theme_ = use;
2744 void TestRunner::ShowWebInspector(const std::string& str,
2745 const std::string& frontend_url) {
2746 ShowDevTools(str, frontend_url);
2749 void TestRunner::WaitUntilExternalURLLoad() {
2750 wait_until_external_url_load_ = true;
2753 void TestRunner::DumpDragImage() {
2754 DumpAsTextWithPixelResults();
2755 dump_drag_image_ = true;
2758 void TestRunner::DumpNavigationPolicy() {
2759 dump_navigation_policy_ = true;
2762 void TestRunner::CloseWebInspector() {
2763 delegate_->CloseDevTools();
2766 bool TestRunner::IsChooserShown() {
2767 return proxy_->IsChooserShown();
2770 void TestRunner::EvaluateInWebInspector(int call_id,
2771 const std::string& script) {
2772 delegate_->EvaluateInWebInspector(call_id, script);
2775 void TestRunner::ClearAllDatabases() {
2776 delegate_->ClearAllDatabases();
2779 void TestRunner::SetDatabaseQuota(int quota) {
2780 delegate_->SetDatabaseQuota(quota);
2783 void TestRunner::SetAlwaysAcceptCookies(bool accept) {
2784 delegate_->SetAcceptAllCookies(accept);
2787 void TestRunner::SetWindowIsKey(bool value) {
2788 delegate_->SetFocus(proxy_, value);
2791 std::string TestRunner::PathToLocalResource(const std::string& path) {
2792 return delegate_->PathToLocalResource(path);
2795 void TestRunner::SetBackingScaleFactor(double value,
2796 v8::Local<v8::Function> callback) {
2797 delegate_->SetDeviceScaleFactor(value);
2798 delegate_->PostTask(new InvokeCallbackTask(this, callback));
2801 void TestRunner::SetColorProfile(const std::string& name,
2802 v8::Local<v8::Function> callback) {
2803 delegate_->SetDeviceColorProfile(name);
2804 delegate_->PostTask(new InvokeCallbackTask(this, callback));
2807 void TestRunner::SetBluetoothMockDataSet(const std::string& name) {
2808 delegate_->SetBluetoothMockDataSet(name);
2811 void TestRunner::SetGeofencingMockProvider(bool service_available) {
2812 delegate_->SetGeofencingMockProvider(service_available);
2815 void TestRunner::ClearGeofencingMockProvider() {
2816 delegate_->ClearGeofencingMockProvider();
2819 void TestRunner::SetGeofencingMockPosition(double latitude, double longitude) {
2820 delegate_->SetGeofencingMockPosition(latitude, longitude);
2823 void TestRunner::SetPermission(const std::string& name,
2824 const std::string& value,
2825 const GURL& origin,
2826 const GURL& embedding_origin) {
2827 delegate_->SetPermission(name, value, origin, embedding_origin);
2830 void TestRunner::DispatchBeforeInstallPromptEvent(
2831 int request_id,
2832 const std::vector<std::string>& event_platforms,
2833 v8::Local<v8::Function> callback) {
2834 scoped_ptr<InvokeCallbackTask> task(
2835 new InvokeCallbackTask(this, callback));
2837 delegate_->DispatchBeforeInstallPromptEvent(
2838 request_id, event_platforms,
2839 base::Bind(&TestRunner::DispatchBeforeInstallPromptCallback,
2840 weak_factory_.GetWeakPtr(), base::Passed(&task)));
2843 void TestRunner::ResolveBeforeInstallPromptPromise(
2844 int request_id,
2845 const std::string& platform) {
2846 delegate_->ResolveBeforeInstallPromptPromise(request_id, platform);
2849 void TestRunner::SetPOSIXLocale(const std::string& locale) {
2850 delegate_->SetLocale(locale);
2853 void TestRunner::SetMIDIAccessorResult(bool result) {
2854 midi_accessor_result_ = result;
2857 void TestRunner::SimulateWebNotificationClick(const std::string& title) {
2858 delegate_->SimulateWebNotificationClick(title);
2861 void TestRunner::AddMockSpeechRecognitionResult(const std::string& transcript,
2862 double confidence) {
2863 proxy_->GetSpeechRecognizerMock()->AddMockResult(
2864 WebString::fromUTF8(transcript), confidence);
2867 void TestRunner::SetMockSpeechRecognitionError(const std::string& error,
2868 const std::string& message) {
2869 proxy_->GetSpeechRecognizerMock()->SetError(WebString::fromUTF8(error),
2870 WebString::fromUTF8(message));
2873 bool TestRunner::WasMockSpeechRecognitionAborted() {
2874 return proxy_->GetSpeechRecognizerMock()->WasAborted();
2877 void TestRunner::AddMockCredentialManagerResponse(const std::string& id,
2878 const std::string& name,
2879 const std::string& avatar,
2880 const std::string& password) {
2881 proxy_->GetCredentialManagerClientMock()->SetResponse(
2882 new WebPasswordCredential(WebString::fromUTF8(id),
2883 WebString::fromUTF8(password),
2884 WebString::fromUTF8(name),
2885 WebURL(GURL(avatar))));
2888 void TestRunner::AddWebPageOverlay() {
2889 if (web_view_)
2890 web_view_->setPageOverlayColor(SK_ColorCYAN);
2893 void TestRunner::RemoveWebPageOverlay() {
2894 if (web_view_)
2895 web_view_->setPageOverlayColor(SK_ColorTRANSPARENT);
2898 void TestRunner::LayoutAndPaintAsync() {
2899 proxy_->LayoutAndPaintAsyncThen(base::Closure());
2902 void TestRunner::LayoutAndPaintAsyncThen(v8::Local<v8::Function> callback) {
2903 scoped_ptr<InvokeCallbackTask> task(
2904 new InvokeCallbackTask(this, callback));
2905 proxy_->LayoutAndPaintAsyncThen(base::Bind(&TestRunner::InvokeCallback,
2906 weak_factory_.GetWeakPtr(),
2907 base::Passed(&task)));
2910 void TestRunner::GetManifestThen(v8::Local<v8::Function> callback) {
2911 scoped_ptr<InvokeCallbackTask> task(
2912 new InvokeCallbackTask(this, callback));
2914 delegate_->FetchManifest(
2915 web_view_, web_view_->mainFrame()->document().manifestURL(),
2916 base::Bind(&TestRunner::GetManifestCallback, weak_factory_.GetWeakPtr(),
2917 base::Passed(&task)));
2920 void TestRunner::CapturePixelsAsyncThen(v8::Local<v8::Function> callback) {
2921 scoped_ptr<InvokeCallbackTask> task(
2922 new InvokeCallbackTask(this, callback));
2923 proxy_->CapturePixelsAsync(base::Bind(&TestRunner::CapturePixelsCallback,
2924 weak_factory_.GetWeakPtr(),
2925 base::Passed(&task)));
2928 void TestRunner::ForceNextWebGLContextCreationToFail() {
2929 if (web_view_)
2930 web_view_->forceNextWebGLContextCreationToFail();
2933 void TestRunner::ForceNextDrawingBufferCreationToFail() {
2934 if (web_view_)
2935 web_view_->forceNextDrawingBufferCreationToFail();
2938 void TestRunner::CopyImageAtAndCapturePixelsAsyncThen(
2939 int x, int y, v8::Local<v8::Function> callback) {
2940 scoped_ptr<InvokeCallbackTask> task(
2941 new InvokeCallbackTask(this, callback));
2942 proxy_->CopyImageAtAndCapturePixels(
2943 x, y, base::Bind(&TestRunner::CapturePixelsCallback,
2944 weak_factory_.GetWeakPtr(),
2945 base::Passed(&task)));
2948 void TestRunner::GetManifestCallback(scoped_ptr<InvokeCallbackTask> task,
2949 const blink::WebURLResponse& response,
2950 const std::string& data) {
2951 InvokeCallback(task.Pass());
2954 void TestRunner::CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task,
2955 const SkBitmap& snapshot) {
2956 v8::Isolate* isolate = blink::mainThreadIsolate();
2957 v8::HandleScope handle_scope(isolate);
2959 v8::Local<v8::Context> context =
2960 web_view_->mainFrame()->mainWorldScriptContext();
2961 if (context.IsEmpty())
2962 return;
2964 v8::Context::Scope context_scope(context);
2965 v8::Local<v8::Value> argv[3];
2966 SkAutoLockPixels snapshot_lock(snapshot);
2968 // Size can be 0 for cases where copyImageAt was called on position
2969 // that doesn't have an image.
2970 int width = snapshot.info().width();
2971 argv[0] = v8::Number::New(isolate, width);
2973 int height = snapshot.info().height();
2974 argv[1] = v8::Number::New(isolate, height);
2976 blink::WebArrayBuffer buffer =
2977 blink::WebArrayBuffer::create(snapshot.getSize(), 1);
2978 memcpy(buffer.data(), snapshot.getPixels(), buffer.byteLength());
2979 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT
2981 // Skia's internal byte order is BGRA. Must swap the B and R channels in
2982 // order to provide a consistent ordering to the layout tests.
2983 unsigned char* pixels = static_cast<unsigned char*>(buffer.data());
2984 unsigned len = buffer.byteLength();
2985 for (unsigned i = 0; i < len; i += 4) {
2986 std::swap(pixels[i], pixels[i + 2]);
2989 #endif
2991 argv[2] = blink::WebArrayBufferConverter::toV8Value(
2992 &buffer, context->Global(), isolate);
2994 task->SetArguments(3, argv);
2995 InvokeCallback(task.Pass());
2998 void TestRunner::DispatchBeforeInstallPromptCallback(
2999 scoped_ptr<InvokeCallbackTask> task,
3000 bool canceled) {
3001 v8::Isolate* isolate = blink::mainThreadIsolate();
3002 v8::HandleScope handle_scope(isolate);
3004 v8::Local<v8::Context> context =
3005 web_view_->mainFrame()->mainWorldScriptContext();
3006 if (context.IsEmpty())
3007 return;
3009 v8::Context::Scope context_scope(context);
3010 v8::Local<v8::Value> argv[1];
3011 argv[0] = v8::Boolean::New(isolate, canceled);
3013 task->SetArguments(1, argv);
3014 InvokeCallback(task.Pass());
3017 void TestRunner::LocationChangeDone() {
3018 web_history_item_count_ = delegate_->NavigationEntryCount();
3020 // No more new work after the first complete load.
3021 work_queue_.set_frozen(true);
3023 if (!wait_until_done_)
3024 work_queue_.ProcessWorkSoon();
3027 void TestRunner::CheckResponseMimeType() {
3028 // Text output: the test page can request different types of output which we
3029 // handle here.
3030 if (!dump_as_text_) {
3031 std::string mimeType =
3032 web_view_->mainFrame()->dataSource()->response().mimeType().utf8();
3033 if (mimeType == "text/plain") {
3034 dump_as_text_ = true;
3035 generate_pixel_results_ = false;
3040 void TestRunner::CompleteNotifyDone() {
3041 if (wait_until_done_ && !topLoadingFrame() && work_queue_.is_empty())
3042 delegate_->TestFinished();
3043 wait_until_done_ = false;
3046 void TestRunner::DidAcquirePointerLockInternal() {
3047 pointer_locked_ = true;
3048 web_view_->didAcquirePointerLock();
3050 // Reset planned result to default.
3051 pointer_lock_planned_result_ = PointerLockWillSucceed;
3054 void TestRunner::DidNotAcquirePointerLockInternal() {
3055 DCHECK(!pointer_locked_);
3056 pointer_locked_ = false;
3057 web_view_->didNotAcquirePointerLock();
3059 // Reset planned result to default.
3060 pointer_lock_planned_result_ = PointerLockWillSucceed;
3063 void TestRunner::DidLosePointerLockInternal() {
3064 bool was_locked = pointer_locked_;
3065 pointer_locked_ = false;
3066 if (was_locked)
3067 web_view_->didLosePointerLock();
3070 } // namespace test_runner