Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: components/test_runner/test_runner.cc

Issue 2707183003: Move //components/test_runner back into //content/shell (Closed)
Patch Set: Trim DEPS Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "components/test_runner/test_runner.h"
6
7 #include <stddef.h>
8 #include <limits>
9 #include <utility>
10
11 #include "base/command_line.h"
12 #include "base/logging.h"
13 #include "base/macros.h"
14 #include "base/strings/nullable_string16.h"
15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h"
18 #include "build/build_config.h"
19 #include "components/test_runner/layout_and_paint_async_then.h"
20 #include "components/test_runner/layout_dump.h"
21 #include "components/test_runner/mock_content_settings_client.h"
22 #include "components/test_runner/mock_credential_manager_client.h"
23 #include "components/test_runner/mock_screen_orientation_client.h"
24 #include "components/test_runner/mock_web_document_subresource_filter.h"
25 #include "components/test_runner/mock_web_speech_recognizer.h"
26 #include "components/test_runner/mock_web_user_media_client.h"
27 #include "components/test_runner/pixel_dump.h"
28 #include "components/test_runner/spell_check_client.h"
29 #include "components/test_runner/test_common.h"
30 #include "components/test_runner/test_interfaces.h"
31 #include "components/test_runner/test_preferences.h"
32 #include "components/test_runner/test_runner_for_specific_view.h"
33 #include "components/test_runner/web_test_delegate.h"
34 #include "components/test_runner/web_view_test_proxy.h"
35 #include "gin/arguments.h"
36 #include "gin/array_buffer.h"
37 #include "gin/handle.h"
38 #include "gin/object_template_builder.h"
39 #include "gin/wrappable.h"
40 #include "third_party/WebKit/public/platform/WebCanvas.h"
41 #include "third_party/WebKit/public/platform/WebData.h"
42 #include "third_party/WebKit/public/platform/WebPasswordCredential.h"
43 #include "third_party/WebKit/public/platform/WebPoint.h"
44 #include "third_party/WebKit/public/platform/WebURLResponse.h"
45 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic eMotionData.h"
46 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic eOrientationData.h"
47 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRegistration.h"
48 #include "third_party/WebKit/public/web/WebArrayBuffer.h"
49 #include "third_party/WebKit/public/web/WebArrayBufferConverter.h"
50 #include "third_party/WebKit/public/web/WebDataSource.h"
51 #include "third_party/WebKit/public/web/WebDocument.h"
52 #include "third_party/WebKit/public/web/WebFindOptions.h"
53 #include "third_party/WebKit/public/web/WebFrame.h"
54 #include "third_party/WebKit/public/web/WebInputElement.h"
55 #include "third_party/WebKit/public/web/WebKit.h"
56 #include "third_party/WebKit/public/web/WebLocalFrame.h"
57 #include "third_party/WebKit/public/web/WebPageImportanceSignals.h"
58 #include "third_party/WebKit/public/web/WebScriptSource.h"
59 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
60 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
61 #include "third_party/WebKit/public/web/WebSettings.h"
62 #include "third_party/WebKit/public/web/WebSurroundingText.h"
63 #include "third_party/WebKit/public/web/WebView.h"
64 #include "third_party/skia/include/core/SkBitmap.h"
65 #include "third_party/skia/include/core/SkCanvas.h"
66 #include "ui/display/display_switches.h"
67 #include "ui/gfx/geometry/rect.h"
68 #include "ui/gfx/geometry/rect_f.h"
69 #include "ui/gfx/geometry/size.h"
70 #include "ui/gfx/skia_util.h"
71
72 #if defined(__linux__) || defined(ANDROID)
73 #include "third_party/WebKit/public/web/linux/WebFontRendering.h"
74 #endif
75
76 using namespace blink;
77
78 namespace test_runner {
79
80 namespace {
81
82 double GetDefaultDeviceScaleFactor() {
83 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
84 if (command_line->HasSwitch(switches::kForceDeviceScaleFactor)) {
85 double scale;
86 std::string value =
87 command_line->GetSwitchValueASCII(switches::kForceDeviceScaleFactor);
88 if (base::StringToDouble(value, &scale))
89 return scale;
90 }
91 return 1.f;
92 }
93
94 } // namespace
95
96 class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
97 public:
98 static gin::WrapperInfo kWrapperInfo;
99
100 static void Install(base::WeakPtr<TestRunner> test_runner,
101 base::WeakPtr<TestRunnerForSpecificView> view_test_runner,
102 WebLocalFrame* frame);
103
104 private:
105 explicit TestRunnerBindings(
106 base::WeakPtr<TestRunner> test_runner,
107 base::WeakPtr<TestRunnerForSpecificView> view_test_runner);
108 ~TestRunnerBindings() override;
109
110 // gin::Wrappable:
111 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
112 v8::Isolate* isolate) override;
113
114 void AddMockSpeechRecognitionResult(const std::string& transcript,
115 double confidence);
116 void AddOriginAccessWhitelistEntry(const std::string& source_origin,
117 const std::string& destination_protocol,
118 const std::string& destination_host,
119 bool allow_destination_subdomains);
120 void AddWebPageOverlay();
121 void CapturePixelsAsyncThen(v8::Local<v8::Function> callback);
122 void ClearAllDatabases();
123 void ClearPrinting();
124 void CloseWebInspector();
125 void CopyImageAtAndCapturePixelsAsyncThen(int x,
126 int y,
127 v8::Local<v8::Function> callback);
128 void DidAcquirePointerLock();
129 void DidLosePointerLock();
130 void DidNotAcquirePointerLock();
131 void DisableMockScreenOrientation();
132 void DispatchBeforeInstallPromptEvent(
133 const std::vector<std::string>& event_platforms,
134 v8::Local<v8::Function> callback);
135 void DumpAsMarkup();
136 void DumpAsText();
137 void DumpAsTextWithPixelResults();
138 void DumpBackForwardList();
139 void DumpChildFrameScrollPositions();
140 void DumpChildFramesAsMarkup();
141 void DumpChildFramesAsText();
142 void DumpCreateView();
143 void DumpDragImage();
144 void DumpEditingCallbacks();
145 void DumpFrameLoadCallbacks();
146 void DumpIconChanges();
147 void DumpNavigationPolicy();
148 void DumpPageImportanceSignals();
149 void DumpPermissionClientCallbacks();
150 void DumpPingLoaderCallbacks();
151 void DumpResourceLoadCallbacks();
152 void DumpResourceResponseMIMETypes();
153 void DumpSelectionRect();
154 void DumpSpellCheckCallbacks();
155 void DumpTitleChanges();
156 void DumpUserGestureInFrameLoadCallbacks();
157 void DumpWindowStatusChanges();
158 void EnableUseZoomForDSF(v8::Local<v8::Function> callback);
159 void EvaluateInWebInspector(int call_id, const std::string& script);
160 void EvaluateScriptInIsolatedWorld(int world_id, const std::string& script);
161 void ExecCommand(gin::Arguments* args);
162 void ForceNextDrawingBufferCreationToFail();
163 void ForceNextWebGLContextCreationToFail();
164 void ForceRedSelectionColors();
165 void GetBluetoothManualChooserEvents(v8::Local<v8::Function> callback);
166 void GetManifestThen(v8::Local<v8::Function> callback);
167 void InsertStyleSheet(const std::string& source_code);
168 void LayoutAndPaintAsync();
169 void LayoutAndPaintAsyncThen(v8::Local<v8::Function> callback);
170 void LogToStderr(const std::string& output);
171 void NotImplemented(const gin::Arguments& args);
172 void NotifyDone();
173 void OverridePreference(const std::string& key, v8::Local<v8::Value> value);
174 void QueueBackNavigation(int how_far_back);
175 void QueueForwardNavigation(int how_far_forward);
176 void QueueLoad(gin::Arguments* args);
177 void QueueLoadingScript(const std::string& script);
178 void QueueNonLoadingScript(const std::string& script);
179 void QueueReload();
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 void RemoveSpellCheckResolvedCallback();
185 void RemoveWebPageOverlay();
186 void ResetDeviceLight();
187 void ResetTestHelperControllers();
188 void ResolveBeforeInstallPromptPromise(const std::string& platform);
189 void RunIdleTasks(v8::Local<v8::Function> callback);
190 void SendBluetoothManualChooserEvent(const std::string& event,
191 const std::string& argument);
192 void SetAcceptLanguages(const std::string& accept_languages);
193 void SetAllowFileAccessFromFileURLs(bool allow);
194 void SetAllowRunningOfInsecureContent(bool allowed);
195 void SetAutoplayAllowed(bool allowed);
196 void SetAllowUniversalAccessFromFileURLs(bool allow);
197 void SetBlockThirdPartyCookies(bool block);
198 void SetAudioData(const gin::ArrayBufferView& view);
199 void SetBackingScaleFactor(double value, v8::Local<v8::Function> callback);
200 void SetBluetoothFakeAdapter(const std::string& adapter_name,
201 v8::Local<v8::Function> callback);
202 void SetBluetoothManualChooser(bool enable);
203 void SetCanOpenWindows();
204 void SetCloseRemainingWindowsWhenComplete(gin::Arguments* args);
205 void SetColorProfile(const std::string& name,
206 v8::Local<v8::Function> callback);
207 void SetCustomPolicyDelegate(gin::Arguments* args);
208 void SetCustomTextOutput(const std::string& output);
209 void SetDatabaseQuota(int quota);
210 void SetDisallowedSubresourcePathSuffixes(
211 const std::vector<std::string>& suffixes);
212 void SetDomainRelaxationForbiddenForURLScheme(bool forbidden,
213 const std::string& scheme);
214 void SetDumpConsoleMessages(bool value);
215 void SetDumpJavaScriptDialogs(bool value);
216 void SetEffectiveConnectionType(const std::string& connection_type);
217 void SetMockSpellCheckerEnabled(bool enabled);
218 void SetImagesAllowed(bool allowed);
219 void SetIsolatedWorldContentSecurityPolicy(int world_id,
220 const std::string& policy);
221 void SetIsolatedWorldSecurityOrigin(int world_id,
222 v8::Local<v8::Value> origin);
223 void SetJavaScriptCanAccessClipboard(bool can_access);
224 void SetMIDIAccessorResult(bool result);
225 void SetMockDeviceLight(double value);
226 void SetMockDeviceMotion(gin::Arguments* args);
227 void SetMockDeviceOrientation(gin::Arguments* args);
228 void SetMockScreenOrientation(const std::string& orientation);
229 void SetMockSpeechRecognitionError(const std::string& error,
230 const std::string& message);
231 void SetPOSIXLocale(const std::string& locale);
232 void SetPageVisibility(const std::string& new_visibility);
233 void SetPermission(const std::string& name,
234 const std::string& value,
235 const std::string& origin,
236 const std::string& embedding_origin);
237 void SetPluginsAllowed(bool allowed);
238 void SetPluginsEnabled(bool enabled);
239 void SetPointerLockWillFailSynchronously();
240 void SetPointerLockWillRespondAsynchronously();
241 void SetPopupBlockingEnabled(bool block_popups);
242 void SetPrinting();
243 void SetScriptsAllowed(bool allowed);
244 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
245 void SetSpellCheckResolvedCallback(v8::Local<v8::Function> callback);
246 void SetStorageAllowed(bool allowed);
247 void SetTabKeyCyclesThroughElements(bool tab_key_cycles_through_elements);
248 void SetTextDirection(const std::string& direction_name);
249 void SetTextSubpixelPositioning(bool value);
250 void SetUseMockTheme(bool use);
251 void SetViewSourceForFrame(const std::string& name, bool enabled);
252 void SetWillSendRequestClearHeader(const std::string& header);
253 void SetWindowIsKey(bool value);
254 void SetXSSAuditorEnabled(bool enabled);
255 void ShowWebInspector(gin::Arguments* args);
256 void SimulateWebNotificationClick(const std::string& title, int action_index);
257 void SimulateWebNotificationClickWithReply(const std::string& title,
258 int action_index,
259 const std::string& reply);
260 void SimulateWebNotificationClose(const std::string& title, bool by_user);
261 void UseUnfortunateSynchronousResizeMode();
262 void WaitForPolicyDelegate();
263 void WaitUntilDone();
264 void WaitUntilExternalURLLoad();
265 void SetMockCredentialManagerError(const std::string& error);
266 void SetMockCredentialManagerResponse(const std::string& id,
267 const std::string& name,
268 const std::string& avatar,
269 const std::string& password);
270 void ClearMockCredentialManagerResponse();
271 bool CallShouldCloseOnWebView();
272 bool DisableAutoResizeMode(int new_width, int new_height);
273 bool EnableAutoResizeMode(int min_width,
274 int min_height,
275 int max_width,
276 int max_height);
277 std::string EvaluateInWebInspectorOverlay(const std::string& script);
278 v8::Local<v8::Value> EvaluateScriptInIsolatedWorldAndReturnValue(
279 int world_id, const std::string& script);
280 bool FindString(const std::string& search_text,
281 const std::vector<std::string>& options_array);
282 bool HasCustomPageSizeStyle(int page_index);
283 bool IsChooserShown();
284
285 bool IsCommandEnabled(const std::string& command);
286 std::string PathToLocalResource(const std::string& path);
287 std::string PlatformName();
288 std::string SelectionAsMarkup();
289 std::string TooltipText();
290
291 int WebHistoryItemCount();
292 int WindowCount();
293
294 base::WeakPtr<TestRunner> runner_;
295 base::WeakPtr<TestRunnerForSpecificView> view_runner_;
296
297 DISALLOW_COPY_AND_ASSIGN(TestRunnerBindings);
298 };
299
300 gin::WrapperInfo TestRunnerBindings::kWrapperInfo = {
301 gin::kEmbedderNativeGin};
302
303 // static
304 void TestRunnerBindings::Install(
305 base::WeakPtr<TestRunner> test_runner,
306 base::WeakPtr<TestRunnerForSpecificView> view_test_runner,
307 WebLocalFrame* frame) {
308 v8::Isolate* isolate = blink::mainThreadIsolate();
309 v8::HandleScope handle_scope(isolate);
310 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
311 if (context.IsEmpty())
312 return;
313
314 v8::Context::Scope context_scope(context);
315
316 TestRunnerBindings* wrapped =
317 new TestRunnerBindings(test_runner, view_test_runner);
318 gin::Handle<TestRunnerBindings> bindings =
319 gin::CreateHandle(isolate, wrapped);
320 if (bindings.IsEmpty())
321 return;
322 v8::Local<v8::Object> global = context->Global();
323 v8::Local<v8::Value> v8_bindings = bindings.ToV8();
324
325 std::vector<std::string> names;
326 names.push_back("testRunner");
327 names.push_back("layoutTestController");
328 for (size_t i = 0; i < names.size(); ++i)
329 global->Set(gin::StringToV8(isolate, names[i].c_str()), v8_bindings);
330 }
331
332 TestRunnerBindings::TestRunnerBindings(
333 base::WeakPtr<TestRunner> runner,
334 base::WeakPtr<TestRunnerForSpecificView> view_runner)
335 : runner_(runner), view_runner_(view_runner) {}
336
337 TestRunnerBindings::~TestRunnerBindings() {}
338
339 gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
340 v8::Isolate* isolate) {
341 return gin::Wrappable<TestRunnerBindings>::GetObjectTemplateBuilder(isolate)
342 .SetMethod("abortModal", &TestRunnerBindings::NotImplemented)
343 .SetMethod("addDisallowedURL", &TestRunnerBindings::NotImplemented)
344 .SetMethod("setMockCredentialManagerError",
345 &TestRunnerBindings::SetMockCredentialManagerError)
346 .SetMethod("setMockCredentialManagerResponse",
347 &TestRunnerBindings::SetMockCredentialManagerResponse)
348 .SetMethod("clearMockCredentialManagerResponse",
349 &TestRunnerBindings::ClearMockCredentialManagerResponse)
350 .SetMethod("addMockSpeechRecognitionResult",
351 &TestRunnerBindings::AddMockSpeechRecognitionResult)
352 .SetMethod("addOriginAccessWhitelistEntry",
353 &TestRunnerBindings::AddOriginAccessWhitelistEntry)
354 .SetMethod("addWebPageOverlay", &TestRunnerBindings::AddWebPageOverlay)
355 .SetMethod("callShouldCloseOnWebView",
356 &TestRunnerBindings::CallShouldCloseOnWebView)
357 .SetMethod("capturePixelsAsyncThen",
358 &TestRunnerBindings::CapturePixelsAsyncThen)
359 .SetMethod("clearAllDatabases", &TestRunnerBindings::ClearAllDatabases)
360 .SetMethod("clearBackForwardList", &TestRunnerBindings::NotImplemented)
361 .SetMethod("clearPrinting", &TestRunnerBindings::ClearPrinting)
362 .SetMethod("closeWebInspector", &TestRunnerBindings::CloseWebInspector)
363 .SetMethod("copyImageAtAndCapturePixelsAsyncThen",
364 &TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen)
365 .SetMethod("didAcquirePointerLock",
366 &TestRunnerBindings::DidAcquirePointerLock)
367 .SetMethod("didLosePointerLock", &TestRunnerBindings::DidLosePointerLock)
368 .SetMethod("didNotAcquirePointerLock",
369 &TestRunnerBindings::DidNotAcquirePointerLock)
370 .SetMethod("disableAutoResizeMode",
371 &TestRunnerBindings::DisableAutoResizeMode)
372 .SetMethod("disableMockScreenOrientation",
373 &TestRunnerBindings::DisableMockScreenOrientation)
374 .SetMethod("setDisallowedSubresourcePathSuffixes",
375 &TestRunnerBindings::SetDisallowedSubresourcePathSuffixes)
376 .SetMethod("dispatchBeforeInstallPromptEvent",
377 &TestRunnerBindings::DispatchBeforeInstallPromptEvent)
378 .SetMethod("dumpAsMarkup", &TestRunnerBindings::DumpAsMarkup)
379 .SetMethod("dumpAsText", &TestRunnerBindings::DumpAsText)
380 .SetMethod("dumpAsTextWithPixelResults",
381 &TestRunnerBindings::DumpAsTextWithPixelResults)
382 .SetMethod("dumpBackForwardList",
383 &TestRunnerBindings::DumpBackForwardList)
384 .SetMethod("dumpChildFrameScrollPositions",
385 &TestRunnerBindings::DumpChildFrameScrollPositions)
386 .SetMethod("dumpChildFramesAsMarkup",
387 &TestRunnerBindings::DumpChildFramesAsMarkup)
388 .SetMethod("dumpChildFramesAsText",
389 &TestRunnerBindings::DumpChildFramesAsText)
390 .SetMethod("dumpCreateView", &TestRunnerBindings::DumpCreateView)
391 .SetMethod("dumpDatabaseCallbacks", &TestRunnerBindings::NotImplemented)
392 .SetMethod("dumpDragImage", &TestRunnerBindings::DumpDragImage)
393 .SetMethod("dumpEditingCallbacks",
394 &TestRunnerBindings::DumpEditingCallbacks)
395 .SetMethod("dumpFrameLoadCallbacks",
396 &TestRunnerBindings::DumpFrameLoadCallbacks)
397 .SetMethod("dumpIconChanges", &TestRunnerBindings::DumpIconChanges)
398 .SetMethod("dumpNavigationPolicy",
399 &TestRunnerBindings::DumpNavigationPolicy)
400 .SetMethod("dumpPageImportanceSignals",
401 &TestRunnerBindings::DumpPageImportanceSignals)
402 .SetMethod("dumpPermissionClientCallbacks",
403 &TestRunnerBindings::DumpPermissionClientCallbacks)
404 .SetMethod("dumpPingLoaderCallbacks",
405 &TestRunnerBindings::DumpPingLoaderCallbacks)
406 .SetMethod("dumpResourceLoadCallbacks",
407 &TestRunnerBindings::DumpResourceLoadCallbacks)
408 .SetMethod("dumpResourceResponseMIMETypes",
409 &TestRunnerBindings::DumpResourceResponseMIMETypes)
410 .SetMethod("dumpSelectionRect", &TestRunnerBindings::DumpSelectionRect)
411 .SetMethod("dumpSpellCheckCallbacks",
412 &TestRunnerBindings::DumpSpellCheckCallbacks)
413
414 // Used at fast/dom/assign-to-window-status.html
415 .SetMethod("dumpStatusCallbacks",
416 &TestRunnerBindings::DumpWindowStatusChanges)
417 .SetMethod("dumpTitleChanges", &TestRunnerBindings::DumpTitleChanges)
418 .SetMethod("dumpUserGestureInFrameLoadCallbacks",
419 &TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks)
420 .SetMethod("enableAutoResizeMode",
421 &TestRunnerBindings::EnableAutoResizeMode)
422 .SetMethod("enableUseZoomForDSF",
423 &TestRunnerBindings::EnableUseZoomForDSF)
424 .SetMethod("evaluateInWebInspector",
425 &TestRunnerBindings::EvaluateInWebInspector)
426 .SetMethod("evaluateInWebInspectorOverlay",
427 &TestRunnerBindings::EvaluateInWebInspectorOverlay)
428 .SetMethod("evaluateScriptInIsolatedWorld",
429 &TestRunnerBindings::EvaluateScriptInIsolatedWorld)
430 .SetMethod(
431 "evaluateScriptInIsolatedWorldAndReturnValue",
432 &TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue)
433 .SetMethod("execCommand", &TestRunnerBindings::ExecCommand)
434 .SetMethod("findString", &TestRunnerBindings::FindString)
435 .SetMethod("forceNextDrawingBufferCreationToFail",
436 &TestRunnerBindings::ForceNextDrawingBufferCreationToFail)
437 .SetMethod("forceNextWebGLContextCreationToFail",
438 &TestRunnerBindings::ForceNextWebGLContextCreationToFail)
439 .SetMethod("forceRedSelectionColors",
440 &TestRunnerBindings::ForceRedSelectionColors)
441
442 // The Bluetooth functions are specified at
443 // https://webbluetoothcg.github.io/web-bluetooth/tests/.
444 .SetMethod("getBluetoothManualChooserEvents",
445 &TestRunnerBindings::GetBluetoothManualChooserEvents)
446 .SetMethod("getManifestThen", &TestRunnerBindings::GetManifestThen)
447 .SetMethod("hasCustomPageSizeStyle",
448 &TestRunnerBindings::HasCustomPageSizeStyle)
449 .SetMethod("insertStyleSheet", &TestRunnerBindings::InsertStyleSheet)
450 .SetMethod("isChooserShown", &TestRunnerBindings::IsChooserShown)
451 .SetMethod("isCommandEnabled", &TestRunnerBindings::IsCommandEnabled)
452 .SetMethod("keepWebHistory", &TestRunnerBindings::NotImplemented)
453 .SetMethod("layoutAndPaintAsync",
454 &TestRunnerBindings::LayoutAndPaintAsync)
455 .SetMethod("layoutAndPaintAsyncThen",
456 &TestRunnerBindings::LayoutAndPaintAsyncThen)
457 .SetMethod("logToStderr", &TestRunnerBindings::LogToStderr)
458 .SetMethod("notifyDone", &TestRunnerBindings::NotifyDone)
459 .SetMethod("overridePreference", &TestRunnerBindings::OverridePreference)
460 .SetMethod("pathToLocalResource",
461 &TestRunnerBindings::PathToLocalResource)
462 .SetProperty("platformName", &TestRunnerBindings::PlatformName)
463 .SetMethod("queueBackNavigation",
464 &TestRunnerBindings::QueueBackNavigation)
465 .SetMethod("queueForwardNavigation",
466 &TestRunnerBindings::QueueForwardNavigation)
467 .SetMethod("queueLoad", &TestRunnerBindings::QueueLoad)
468 .SetMethod("queueLoadingScript", &TestRunnerBindings::QueueLoadingScript)
469 .SetMethod("queueNonLoadingScript",
470 &TestRunnerBindings::QueueNonLoadingScript)
471 .SetMethod("queueReload", &TestRunnerBindings::QueueReload)
472 .SetMethod("removeOriginAccessWhitelistEntry",
473 &TestRunnerBindings::RemoveOriginAccessWhitelistEntry)
474 .SetMethod("removeSpellCheckResolvedCallback",
475 &TestRunnerBindings::RemoveSpellCheckResolvedCallback)
476 .SetMethod("removeWebPageOverlay",
477 &TestRunnerBindings::RemoveWebPageOverlay)
478 .SetMethod("resetDeviceLight", &TestRunnerBindings::ResetDeviceLight)
479 .SetMethod("resetTestHelperControllers",
480 &TestRunnerBindings::ResetTestHelperControllers)
481 .SetMethod("resolveBeforeInstallPromptPromise",
482 &TestRunnerBindings::ResolveBeforeInstallPromptPromise)
483 .SetMethod("runIdleTasks", &TestRunnerBindings::RunIdleTasks)
484 .SetMethod("selectionAsMarkup", &TestRunnerBindings::SelectionAsMarkup)
485
486 // The Bluetooth functions are specified at
487 // https://webbluetoothcg.github.io/web-bluetooth/tests/.
488 .SetMethod("sendBluetoothManualChooserEvent",
489 &TestRunnerBindings::SendBluetoothManualChooserEvent)
490 .SetMethod("setAcceptLanguages", &TestRunnerBindings::SetAcceptLanguages)
491 .SetMethod("setAllowFileAccessFromFileURLs",
492 &TestRunnerBindings::SetAllowFileAccessFromFileURLs)
493 .SetMethod("setAllowRunningOfInsecureContent",
494 &TestRunnerBindings::SetAllowRunningOfInsecureContent)
495 .SetMethod("setAutoplayAllowed", &TestRunnerBindings::SetAutoplayAllowed)
496 .SetMethod("setAllowUniversalAccessFromFileURLs",
497 &TestRunnerBindings::SetAllowUniversalAccessFromFileURLs)
498 .SetMethod("setBlockThirdPartyCookies",
499 &TestRunnerBindings::SetBlockThirdPartyCookies)
500 .SetMethod("setAudioData", &TestRunnerBindings::SetAudioData)
501 .SetMethod("setBackingScaleFactor",
502 &TestRunnerBindings::SetBackingScaleFactor)
503 // The Bluetooth functions are specified at
504 // https://webbluetoothcg.github.io/web-bluetooth/tests/.
505 .SetMethod("setBluetoothFakeAdapter",
506 &TestRunnerBindings::SetBluetoothFakeAdapter)
507 .SetMethod("setBluetoothManualChooser",
508 &TestRunnerBindings::SetBluetoothManualChooser)
509 .SetMethod("setCallCloseOnWebViews", &TestRunnerBindings::NotImplemented)
510 .SetMethod("setCanOpenWindows", &TestRunnerBindings::SetCanOpenWindows)
511 .SetMethod("setCloseRemainingWindowsWhenComplete",
512 &TestRunnerBindings::SetCloseRemainingWindowsWhenComplete)
513 .SetMethod("setColorProfile", &TestRunnerBindings::SetColorProfile)
514 .SetMethod("setCustomPolicyDelegate",
515 &TestRunnerBindings::SetCustomPolicyDelegate)
516 .SetMethod("setCustomTextOutput",
517 &TestRunnerBindings::SetCustomTextOutput)
518 .SetMethod("setDatabaseQuota", &TestRunnerBindings::SetDatabaseQuota)
519 .SetMethod("setDomainRelaxationForbiddenForURLScheme",
520 &TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme)
521 .SetMethod("setDumpConsoleMessages",
522 &TestRunnerBindings::SetDumpConsoleMessages)
523 .SetMethod("setDumpJavaScriptDialogs",
524 &TestRunnerBindings::SetDumpJavaScriptDialogs)
525 .SetMethod("setEffectiveConnectionType",
526 &TestRunnerBindings::SetEffectiveConnectionType)
527 .SetMethod("setMockSpellCheckerEnabled",
528 &TestRunnerBindings::SetMockSpellCheckerEnabled)
529 .SetMethod("setIconDatabaseEnabled", &TestRunnerBindings::NotImplemented)
530 .SetMethod("setImagesAllowed", &TestRunnerBindings::SetImagesAllowed)
531 .SetMethod("setIsolatedWorldContentSecurityPolicy",
532 &TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy)
533 .SetMethod("setIsolatedWorldSecurityOrigin",
534 &TestRunnerBindings::SetIsolatedWorldSecurityOrigin)
535 .SetMethod("setJavaScriptCanAccessClipboard",
536 &TestRunnerBindings::SetJavaScriptCanAccessClipboard)
537 .SetMethod("setMIDIAccessorResult",
538 &TestRunnerBindings::SetMIDIAccessorResult)
539 .SetMethod("setMainFrameIsFirstResponder",
540 &TestRunnerBindings::NotImplemented)
541 .SetMethod("setMockDeviceLight", &TestRunnerBindings::SetMockDeviceLight)
542 .SetMethod("setMockDeviceMotion",
543 &TestRunnerBindings::SetMockDeviceMotion)
544 .SetMethod("setMockDeviceOrientation",
545 &TestRunnerBindings::SetMockDeviceOrientation)
546 .SetMethod("setMockScreenOrientation",
547 &TestRunnerBindings::SetMockScreenOrientation)
548 .SetMethod("setMockSpeechRecognitionError",
549 &TestRunnerBindings::SetMockSpeechRecognitionError)
550 .SetMethod("setPOSIXLocale", &TestRunnerBindings::SetPOSIXLocale)
551 .SetMethod("setPageVisibility", &TestRunnerBindings::SetPageVisibility)
552 .SetMethod("setPermission", &TestRunnerBindings::SetPermission)
553 .SetMethod("setPluginsAllowed", &TestRunnerBindings::SetPluginsAllowed)
554 .SetMethod("setPluginsEnabled", &TestRunnerBindings::SetPluginsEnabled)
555 .SetMethod("setPointerLockWillFailSynchronously",
556 &TestRunnerBindings::SetPointerLockWillFailSynchronously)
557 .SetMethod("setPointerLockWillRespondAsynchronously",
558 &TestRunnerBindings::SetPointerLockWillRespondAsynchronously)
559 .SetMethod("setPopupBlockingEnabled",
560 &TestRunnerBindings::SetPopupBlockingEnabled)
561 .SetMethod("setPrinting", &TestRunnerBindings::SetPrinting)
562 .SetMethod("setScriptsAllowed", &TestRunnerBindings::SetScriptsAllowed)
563 .SetMethod("setScrollbarPolicy", &TestRunnerBindings::NotImplemented)
564 .SetMethod(
565 "setShouldStayOnPageAfterHandlingBeforeUnload",
566 &TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload)
567 .SetMethod("setSpellCheckResolvedCallback",
568 &TestRunnerBindings::SetSpellCheckResolvedCallback)
569 .SetMethod("setStorageAllowed", &TestRunnerBindings::SetStorageAllowed)
570 .SetMethod("setTabKeyCyclesThroughElements",
571 &TestRunnerBindings::SetTabKeyCyclesThroughElements)
572 .SetMethod("setTextDirection", &TestRunnerBindings::SetTextDirection)
573 .SetMethod("setTextSubpixelPositioning",
574 &TestRunnerBindings::SetTextSubpixelPositioning)
575 .SetMethod("setUseDashboardCompatibilityMode",
576 &TestRunnerBindings::NotImplemented)
577 .SetMethod("setUseMockTheme", &TestRunnerBindings::SetUseMockTheme)
578 .SetMethod("setViewSourceForFrame",
579 &TestRunnerBindings::SetViewSourceForFrame)
580 .SetMethod("setWillSendRequestClearHeader",
581 &TestRunnerBindings::SetWillSendRequestClearHeader)
582 .SetMethod("setWindowIsKey", &TestRunnerBindings::SetWindowIsKey)
583 .SetMethod("setXSSAuditorEnabled",
584 &TestRunnerBindings::SetXSSAuditorEnabled)
585 .SetMethod("showWebInspector", &TestRunnerBindings::ShowWebInspector)
586 .SetMethod("simulateWebNotificationClick",
587 &TestRunnerBindings::SimulateWebNotificationClick)
588 .SetMethod("simulateWebNotificationClickWithReply",
589 &TestRunnerBindings::SimulateWebNotificationClickWithReply)
590 .SetMethod("simulateWebNotificationClose",
591 &TestRunnerBindings::SimulateWebNotificationClose)
592 .SetProperty("tooltipText", &TestRunnerBindings::TooltipText)
593 .SetMethod("useUnfortunateSynchronousResizeMode",
594 &TestRunnerBindings::UseUnfortunateSynchronousResizeMode)
595 .SetMethod("waitForPolicyDelegate",
596 &TestRunnerBindings::WaitForPolicyDelegate)
597 .SetMethod("waitUntilDone", &TestRunnerBindings::WaitUntilDone)
598 .SetMethod("waitUntilExternalURLLoad",
599 &TestRunnerBindings::WaitUntilExternalURLLoad)
600
601 // webHistoryItemCount is used by tests in LayoutTests\http\tests\history
602 .SetProperty("webHistoryItemCount",
603 &TestRunnerBindings::WebHistoryItemCount)
604 .SetMethod("windowCount", &TestRunnerBindings::WindowCount);
605 }
606
607 void TestRunnerBindings::LogToStderr(const std::string& output) {
608 LOG(ERROR) << output;
609 }
610
611 void TestRunnerBindings::NotifyDone() {
612 if (runner_)
613 runner_->NotifyDone();
614 }
615
616 void TestRunnerBindings::WaitUntilDone() {
617 if (runner_)
618 runner_->WaitUntilDone();
619 }
620
621 void TestRunnerBindings::QueueBackNavigation(int how_far_back) {
622 if (runner_)
623 runner_->QueueBackNavigation(how_far_back);
624 }
625
626 void TestRunnerBindings::QueueForwardNavigation(int how_far_forward) {
627 if (runner_)
628 runner_->QueueForwardNavigation(how_far_forward);
629 }
630
631 void TestRunnerBindings::QueueReload() {
632 if (runner_)
633 runner_->QueueReload();
634 }
635
636 void TestRunnerBindings::QueueLoadingScript(const std::string& script) {
637 if (runner_)
638 runner_->QueueLoadingScript(script);
639 }
640
641 void TestRunnerBindings::QueueNonLoadingScript(const std::string& script) {
642 if (runner_)
643 runner_->QueueNonLoadingScript(script);
644 }
645
646 void TestRunnerBindings::QueueLoad(gin::Arguments* args) {
647 if (runner_) {
648 std::string url;
649 std::string target;
650 args->GetNext(&url);
651 args->GetNext(&target);
652 runner_->QueueLoad(url, target);
653 }
654 }
655
656 void TestRunnerBindings::SetCustomPolicyDelegate(gin::Arguments* args) {
657 if (runner_)
658 runner_->SetCustomPolicyDelegate(args);
659 }
660
661 void TestRunnerBindings::WaitForPolicyDelegate() {
662 if (runner_)
663 runner_->WaitForPolicyDelegate();
664 }
665
666 int TestRunnerBindings::WindowCount() {
667 if (runner_)
668 return runner_->WindowCount();
669 return 0;
670 }
671
672 void TestRunnerBindings::SetCloseRemainingWindowsWhenComplete(
673 gin::Arguments* args) {
674 if (!runner_)
675 return;
676
677 // In the original implementation, nothing happens if the argument is
678 // ommitted.
679 bool close_remaining_windows = false;
680 if (args->GetNext(&close_remaining_windows))
681 runner_->SetCloseRemainingWindowsWhenComplete(close_remaining_windows);
682 }
683
684 void TestRunnerBindings::ResetTestHelperControllers() {
685 if (runner_)
686 runner_->ResetTestHelperControllers();
687 }
688
689 void TestRunnerBindings::SetTabKeyCyclesThroughElements(
690 bool tab_key_cycles_through_elements) {
691 if (view_runner_)
692 view_runner_->SetTabKeyCyclesThroughElements(
693 tab_key_cycles_through_elements);
694 }
695
696 void TestRunnerBindings::ExecCommand(gin::Arguments* args) {
697 if (view_runner_)
698 view_runner_->ExecCommand(args);
699 }
700
701 bool TestRunnerBindings::IsCommandEnabled(const std::string& command) {
702 if (view_runner_)
703 return view_runner_->IsCommandEnabled(command);
704 return false;
705 }
706
707 bool TestRunnerBindings::CallShouldCloseOnWebView() {
708 if (view_runner_)
709 return view_runner_->CallShouldCloseOnWebView();
710 return false;
711 }
712
713 void TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme(
714 bool forbidden, const std::string& scheme) {
715 if (view_runner_)
716 view_runner_->SetDomainRelaxationForbiddenForURLScheme(forbidden, scheme);
717 }
718
719 void TestRunnerBindings::SetDumpConsoleMessages(bool enabled) {
720 if (runner_)
721 runner_->SetDumpConsoleMessages(enabled);
722 }
723
724 void TestRunnerBindings::SetDumpJavaScriptDialogs(bool enabled) {
725 if (runner_)
726 runner_->SetDumpJavaScriptDialogs(enabled);
727 }
728
729 void TestRunnerBindings::SetEffectiveConnectionType(
730 const std::string& connection_type) {
731 blink::WebEffectiveConnectionType web_type =
732 blink::WebEffectiveConnectionType::TypeUnknown;
733 if (connection_type == "TypeUnknown")
734 web_type = blink::WebEffectiveConnectionType::TypeUnknown;
735 else if (connection_type == "TypeOffline")
736 web_type = blink::WebEffectiveConnectionType::TypeOffline;
737 else if (connection_type == "TypeSlow2G")
738 web_type = blink::WebEffectiveConnectionType::TypeSlow2G;
739 else if (connection_type == "Type2G")
740 web_type = blink::WebEffectiveConnectionType::Type2G;
741 else if (connection_type == "Type3G")
742 web_type = blink::WebEffectiveConnectionType::Type3G;
743 else if (connection_type == "Type4G")
744 web_type = blink::WebEffectiveConnectionType::Type4G;
745 else
746 NOTREACHED();
747
748 if (runner_)
749 runner_->SetEffectiveConnectionType(web_type);
750 }
751
752 void TestRunnerBindings::SetMockSpellCheckerEnabled(bool enabled) {
753 if (runner_)
754 runner_->SetMockSpellCheckerEnabled(enabled);
755 }
756
757 void TestRunnerBindings::SetSpellCheckResolvedCallback(
758 v8::Local<v8::Function> callback) {
759 if (runner_)
760 runner_->spellcheck_->SetSpellCheckResolvedCallback(callback);
761 }
762
763 void TestRunnerBindings::RemoveSpellCheckResolvedCallback() {
764 if (runner_)
765 runner_->spellcheck_->RemoveSpellCheckResolvedCallback();
766 }
767
768 v8::Local<v8::Value>
769 TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue(
770 int world_id, const std::string& script) {
771 if (!view_runner_ || world_id <= 0 || world_id >= (1 << 29))
772 return v8::Local<v8::Value>();
773 return view_runner_->EvaluateScriptInIsolatedWorldAndReturnValue(world_id,
774 script);
775 }
776
777 void TestRunnerBindings::EvaluateScriptInIsolatedWorld(
778 int world_id, const std::string& script) {
779 if (view_runner_ && world_id > 0 && world_id < (1 << 29))
780 view_runner_->EvaluateScriptInIsolatedWorld(world_id, script);
781 }
782
783 void TestRunnerBindings::SetIsolatedWorldSecurityOrigin(
784 int world_id, v8::Local<v8::Value> origin) {
785 if (view_runner_)
786 view_runner_->SetIsolatedWorldSecurityOrigin(world_id, origin);
787 }
788
789 void TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy(
790 int world_id, const std::string& policy) {
791 if (view_runner_)
792 view_runner_->SetIsolatedWorldContentSecurityPolicy(world_id, policy);
793 }
794
795 void TestRunnerBindings::AddOriginAccessWhitelistEntry(
796 const std::string& source_origin,
797 const std::string& destination_protocol,
798 const std::string& destination_host,
799 bool allow_destination_subdomains) {
800 if (runner_) {
801 runner_->AddOriginAccessWhitelistEntry(source_origin,
802 destination_protocol,
803 destination_host,
804 allow_destination_subdomains);
805 }
806 }
807
808 void TestRunnerBindings::RemoveOriginAccessWhitelistEntry(
809 const std::string& source_origin,
810 const std::string& destination_protocol,
811 const std::string& destination_host,
812 bool allow_destination_subdomains) {
813 if (runner_) {
814 runner_->RemoveOriginAccessWhitelistEntry(source_origin,
815 destination_protocol,
816 destination_host,
817 allow_destination_subdomains);
818 }
819 }
820
821 bool TestRunnerBindings::HasCustomPageSizeStyle(int page_index) {
822 if (view_runner_)
823 return view_runner_->HasCustomPageSizeStyle(page_index);
824 return false;
825 }
826
827 void TestRunnerBindings::ForceRedSelectionColors() {
828 if (view_runner_)
829 view_runner_->ForceRedSelectionColors();
830 }
831
832 void TestRunnerBindings::InsertStyleSheet(const std::string& source_code) {
833 if (runner_)
834 runner_->InsertStyleSheet(source_code);
835 }
836
837 bool TestRunnerBindings::FindString(
838 const std::string& search_text,
839 const std::vector<std::string>& options_array) {
840 if (view_runner_)
841 return view_runner_->FindString(search_text, options_array);
842 return false;
843 }
844
845 std::string TestRunnerBindings::SelectionAsMarkup() {
846 if (view_runner_)
847 return view_runner_->SelectionAsMarkup();
848 return std::string();
849 }
850
851 void TestRunnerBindings::SetTextSubpixelPositioning(bool value) {
852 if (runner_)
853 runner_->SetTextSubpixelPositioning(value);
854 }
855
856 void TestRunnerBindings::SetPageVisibility(const std::string& new_visibility) {
857 if (view_runner_)
858 view_runner_->SetPageVisibility(new_visibility);
859 }
860
861 void TestRunnerBindings::SetTextDirection(const std::string& direction_name) {
862 if (view_runner_)
863 view_runner_->SetTextDirection(direction_name);
864 }
865
866 void TestRunnerBindings::UseUnfortunateSynchronousResizeMode() {
867 if (runner_)
868 runner_->UseUnfortunateSynchronousResizeMode();
869 }
870
871 bool TestRunnerBindings::EnableAutoResizeMode(int min_width,
872 int min_height,
873 int max_width,
874 int max_height) {
875 if (runner_) {
876 return runner_->EnableAutoResizeMode(min_width, min_height,
877 max_width, max_height);
878 }
879 return false;
880 }
881
882 bool TestRunnerBindings::DisableAutoResizeMode(int new_width, int new_height) {
883 if (runner_)
884 return runner_->DisableAutoResizeMode(new_width, new_height);
885 return false;
886 }
887
888 void TestRunnerBindings::SetMockDeviceLight(double value) {
889 if (!runner_)
890 return;
891 runner_->SetMockDeviceLight(value);
892 }
893
894 void TestRunnerBindings::ResetDeviceLight() {
895 if (runner_)
896 runner_->ResetDeviceLight();
897 }
898
899 void TestRunnerBindings::SetMockDeviceMotion(gin::Arguments* args) {
900 if (!runner_)
901 return;
902
903 bool has_acceleration_x = false;
904 double acceleration_x = 0.0;
905 bool has_acceleration_y = false;
906 double acceleration_y = 0.0;
907 bool has_acceleration_z = false;
908 double acceleration_z = 0.0;
909 bool has_acceleration_including_gravity_x = false;
910 double acceleration_including_gravity_x = 0.0;
911 bool has_acceleration_including_gravity_y = false;
912 double acceleration_including_gravity_y = 0.0;
913 bool has_acceleration_including_gravity_z = false;
914 double acceleration_including_gravity_z = 0.0;
915 bool has_rotation_rate_alpha = false;
916 double rotation_rate_alpha = 0.0;
917 bool has_rotation_rate_beta = false;
918 double rotation_rate_beta = 0.0;
919 bool has_rotation_rate_gamma = false;
920 double rotation_rate_gamma = 0.0;
921 double interval = false;
922
923 args->GetNext(&has_acceleration_x);
924 args->GetNext(&acceleration_x);
925 args->GetNext(&has_acceleration_y);
926 args->GetNext(&acceleration_y);
927 args->GetNext(&has_acceleration_z);
928 args->GetNext(&acceleration_z);
929 args->GetNext(&has_acceleration_including_gravity_x);
930 args->GetNext(&acceleration_including_gravity_x);
931 args->GetNext(&has_acceleration_including_gravity_y);
932 args->GetNext(&acceleration_including_gravity_y);
933 args->GetNext(&has_acceleration_including_gravity_z);
934 args->GetNext(&acceleration_including_gravity_z);
935 args->GetNext(&has_rotation_rate_alpha);
936 args->GetNext(&rotation_rate_alpha);
937 args->GetNext(&has_rotation_rate_beta);
938 args->GetNext(&rotation_rate_beta);
939 args->GetNext(&has_rotation_rate_gamma);
940 args->GetNext(&rotation_rate_gamma);
941 args->GetNext(&interval);
942
943 runner_->SetMockDeviceMotion(has_acceleration_x, acceleration_x,
944 has_acceleration_y, acceleration_y,
945 has_acceleration_z, acceleration_z,
946 has_acceleration_including_gravity_x,
947 acceleration_including_gravity_x,
948 has_acceleration_including_gravity_y,
949 acceleration_including_gravity_y,
950 has_acceleration_including_gravity_z,
951 acceleration_including_gravity_z,
952 has_rotation_rate_alpha,
953 rotation_rate_alpha,
954 has_rotation_rate_beta,
955 rotation_rate_beta,
956 has_rotation_rate_gamma,
957 rotation_rate_gamma,
958 interval);
959 }
960
961 void TestRunnerBindings::SetMockDeviceOrientation(gin::Arguments* args) {
962 if (!runner_)
963 return;
964
965 bool has_alpha = false;
966 double alpha = 0.0;
967 bool has_beta = false;
968 double beta = 0.0;
969 bool has_gamma = false;
970 double gamma = 0.0;
971 bool absolute = false;
972
973 args->GetNext(&has_alpha);
974 args->GetNext(&alpha);
975 args->GetNext(&has_beta);
976 args->GetNext(&beta);
977 args->GetNext(&has_gamma);
978 args->GetNext(&gamma);
979 args->GetNext(&absolute);
980
981 runner_->SetMockDeviceOrientation(has_alpha, alpha,
982 has_beta, beta,
983 has_gamma, gamma,
984 absolute);
985 }
986
987 void TestRunnerBindings::SetMockScreenOrientation(
988 const std::string& orientation) {
989 if (!runner_)
990 return;
991
992 runner_->SetMockScreenOrientation(orientation);
993 }
994
995 void TestRunnerBindings::DisableMockScreenOrientation() {
996 if (runner_)
997 runner_->DisableMockScreenOrientation();
998 }
999
1000 void TestRunnerBindings::SetDisallowedSubresourcePathSuffixes(
1001 const std::vector<std::string>& suffixes) {
1002 if (runner_)
1003 runner_->SetDisallowedSubresourcePathSuffixes(suffixes);
1004 }
1005
1006 void TestRunnerBindings::DidAcquirePointerLock() {
1007 if (view_runner_)
1008 view_runner_->DidAcquirePointerLock();
1009 }
1010
1011 void TestRunnerBindings::DidNotAcquirePointerLock() {
1012 if (view_runner_)
1013 view_runner_->DidNotAcquirePointerLock();
1014 }
1015
1016 void TestRunnerBindings::DidLosePointerLock() {
1017 if (view_runner_)
1018 view_runner_->DidLosePointerLock();
1019 }
1020
1021 void TestRunnerBindings::SetPointerLockWillFailSynchronously() {
1022 if (view_runner_)
1023 view_runner_->SetPointerLockWillFailSynchronously();
1024 }
1025
1026 void TestRunnerBindings::SetPointerLockWillRespondAsynchronously() {
1027 if (view_runner_)
1028 view_runner_->SetPointerLockWillRespondAsynchronously();
1029 }
1030
1031 void TestRunnerBindings::SetPopupBlockingEnabled(bool block_popups) {
1032 if (runner_)
1033 runner_->SetPopupBlockingEnabled(block_popups);
1034 }
1035
1036 void TestRunnerBindings::SetJavaScriptCanAccessClipboard(bool can_access) {
1037 if (runner_)
1038 runner_->SetJavaScriptCanAccessClipboard(can_access);
1039 }
1040
1041 void TestRunnerBindings::SetXSSAuditorEnabled(bool enabled) {
1042 if (runner_)
1043 runner_->SetXSSAuditorEnabled(enabled);
1044 }
1045
1046 void TestRunnerBindings::SetAllowUniversalAccessFromFileURLs(bool allow) {
1047 if (runner_)
1048 runner_->SetAllowUniversalAccessFromFileURLs(allow);
1049 }
1050
1051 void TestRunnerBindings::SetAllowFileAccessFromFileURLs(bool allow) {
1052 if (runner_)
1053 runner_->SetAllowFileAccessFromFileURLs(allow);
1054 }
1055
1056 void TestRunnerBindings::OverridePreference(const std::string& key,
1057 v8::Local<v8::Value> value) {
1058 if (runner_)
1059 runner_->OverridePreference(key, value);
1060 }
1061
1062 void TestRunnerBindings::SetAcceptLanguages(
1063 const std::string& accept_languages) {
1064 if (!runner_)
1065 return;
1066
1067 runner_->SetAcceptLanguages(accept_languages);
1068 }
1069
1070 void TestRunnerBindings::SetPluginsEnabled(bool enabled) {
1071 if (runner_)
1072 runner_->SetPluginsEnabled(enabled);
1073 }
1074
1075 void TestRunnerBindings::DumpEditingCallbacks() {
1076 if (runner_)
1077 runner_->DumpEditingCallbacks();
1078 }
1079
1080 void TestRunnerBindings::DumpAsMarkup() {
1081 if (runner_)
1082 runner_->DumpAsMarkup();
1083 }
1084
1085 void TestRunnerBindings::DumpAsText() {
1086 if (runner_)
1087 runner_->DumpAsText();
1088 }
1089
1090 void TestRunnerBindings::DumpAsTextWithPixelResults() {
1091 if (runner_)
1092 runner_->DumpAsTextWithPixelResults();
1093 }
1094
1095 void TestRunnerBindings::DumpChildFrameScrollPositions() {
1096 if (runner_)
1097 runner_->DumpChildFrameScrollPositions();
1098 }
1099
1100 void TestRunnerBindings::DumpChildFramesAsText() {
1101 if (runner_)
1102 runner_->DumpChildFramesAsText();
1103 }
1104
1105 void TestRunnerBindings::DumpChildFramesAsMarkup() {
1106 if (runner_)
1107 runner_->DumpChildFramesAsMarkup();
1108 }
1109
1110 void TestRunnerBindings::DumpIconChanges() {
1111 if (runner_)
1112 runner_->DumpIconChanges();
1113 }
1114
1115 void TestRunnerBindings::SetAudioData(const gin::ArrayBufferView& view) {
1116 if (runner_)
1117 runner_->SetAudioData(view);
1118 }
1119
1120 void TestRunnerBindings::DumpFrameLoadCallbacks() {
1121 if (runner_)
1122 runner_->DumpFrameLoadCallbacks();
1123 }
1124
1125 void TestRunnerBindings::DumpPingLoaderCallbacks() {
1126 if (runner_)
1127 runner_->DumpPingLoaderCallbacks();
1128 }
1129
1130 void TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks() {
1131 if (runner_)
1132 runner_->DumpUserGestureInFrameLoadCallbacks();
1133 }
1134
1135 void TestRunnerBindings::DumpTitleChanges() {
1136 if (runner_)
1137 runner_->DumpTitleChanges();
1138 }
1139
1140 void TestRunnerBindings::DumpCreateView() {
1141 if (runner_)
1142 runner_->DumpCreateView();
1143 }
1144
1145 void TestRunnerBindings::SetCanOpenWindows() {
1146 if (runner_)
1147 runner_->SetCanOpenWindows();
1148 }
1149
1150 void TestRunnerBindings::DumpResourceLoadCallbacks() {
1151 if (runner_)
1152 runner_->DumpResourceLoadCallbacks();
1153 }
1154
1155 void TestRunnerBindings::DumpResourceResponseMIMETypes() {
1156 if (runner_)
1157 runner_->DumpResourceResponseMIMETypes();
1158 }
1159
1160 void TestRunnerBindings::SetImagesAllowed(bool allowed) {
1161 if (runner_)
1162 runner_->SetImagesAllowed(allowed);
1163 }
1164
1165 void TestRunnerBindings::SetScriptsAllowed(bool allowed) {
1166 if (runner_)
1167 runner_->SetScriptsAllowed(allowed);
1168 }
1169
1170 void TestRunnerBindings::SetStorageAllowed(bool allowed) {
1171 if (runner_)
1172 runner_->SetStorageAllowed(allowed);
1173 }
1174
1175 void TestRunnerBindings::SetPluginsAllowed(bool allowed) {
1176 if (runner_)
1177 runner_->SetPluginsAllowed(allowed);
1178 }
1179
1180 void TestRunnerBindings::SetAllowRunningOfInsecureContent(bool allowed) {
1181 if (runner_)
1182 runner_->SetAllowRunningOfInsecureContent(allowed);
1183 }
1184
1185 void TestRunnerBindings::SetAutoplayAllowed(bool allowed) {
1186 if (runner_)
1187 runner_->SetAutoplayAllowed(allowed);
1188 }
1189
1190 void TestRunnerBindings::DumpPermissionClientCallbacks() {
1191 if (runner_)
1192 runner_->DumpPermissionClientCallbacks();
1193 }
1194
1195 void TestRunnerBindings::DumpWindowStatusChanges() {
1196 if (runner_)
1197 runner_->DumpWindowStatusChanges();
1198 }
1199
1200 void TestRunnerBindings::DumpSpellCheckCallbacks() {
1201 if (runner_)
1202 runner_->DumpSpellCheckCallbacks();
1203 }
1204
1205 void TestRunnerBindings::DumpBackForwardList() {
1206 if (runner_)
1207 runner_->DumpBackForwardList();
1208 }
1209
1210 void TestRunnerBindings::DumpSelectionRect() {
1211 if (runner_)
1212 runner_->DumpSelectionRect();
1213 }
1214
1215 void TestRunnerBindings::SetPrinting() {
1216 if (runner_)
1217 runner_->SetPrinting();
1218 }
1219
1220 void TestRunnerBindings::ClearPrinting() {
1221 if (runner_)
1222 runner_->ClearPrinting();
1223 }
1224
1225 void TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload(
1226 bool value) {
1227 if (runner_)
1228 runner_->SetShouldStayOnPageAfterHandlingBeforeUnload(value);
1229 }
1230
1231 void TestRunnerBindings::SetWillSendRequestClearHeader(
1232 const std::string& header) {
1233 if (runner_)
1234 runner_->SetWillSendRequestClearHeader(header);
1235 }
1236
1237 void TestRunnerBindings::SetUseMockTheme(bool use) {
1238 if (runner_)
1239 runner_->SetUseMockTheme(use);
1240 }
1241
1242 void TestRunnerBindings::WaitUntilExternalURLLoad() {
1243 if (runner_)
1244 runner_->WaitUntilExternalURLLoad();
1245 }
1246
1247 void TestRunnerBindings::DumpDragImage() {
1248 if (runner_)
1249 runner_->DumpDragImage();
1250 }
1251
1252 void TestRunnerBindings::DumpNavigationPolicy() {
1253 if (runner_)
1254 runner_->DumpNavigationPolicy();
1255 }
1256
1257 void TestRunnerBindings::DumpPageImportanceSignals() {
1258 if (view_runner_)
1259 view_runner_->DumpPageImportanceSignals();
1260 }
1261
1262 void TestRunnerBindings::ShowWebInspector(gin::Arguments* args) {
1263 if (runner_) {
1264 std::string settings;
1265 args->GetNext(&settings);
1266 std::string frontend_url;
1267 args->GetNext(&frontend_url);
1268 runner_->ShowWebInspector(settings, frontend_url);
1269 }
1270 }
1271
1272 void TestRunnerBindings::CloseWebInspector() {
1273 if (runner_)
1274 runner_->CloseWebInspector();
1275 }
1276
1277 bool TestRunnerBindings::IsChooserShown() {
1278 if (runner_)
1279 return runner_->IsChooserShown();
1280 return false;
1281 }
1282
1283 void TestRunnerBindings::EvaluateInWebInspector(int call_id,
1284 const std::string& script) {
1285 if (runner_)
1286 runner_->EvaluateInWebInspector(call_id, script);
1287 }
1288
1289 std::string TestRunnerBindings::EvaluateInWebInspectorOverlay(
1290 const std::string& script) {
1291 if (runner_)
1292 return runner_->EvaluateInWebInspectorOverlay(script);
1293
1294 return std::string();
1295 }
1296
1297 void TestRunnerBindings::ClearAllDatabases() {
1298 if (runner_)
1299 runner_->ClearAllDatabases();
1300 }
1301
1302 void TestRunnerBindings::SetDatabaseQuota(int quota) {
1303 if (runner_)
1304 runner_->SetDatabaseQuota(quota);
1305 }
1306
1307 void TestRunnerBindings::SetBlockThirdPartyCookies(bool block) {
1308 if (runner_)
1309 runner_->SetBlockThirdPartyCookies(block);
1310 }
1311
1312 void TestRunnerBindings::SetWindowIsKey(bool value) {
1313 if (view_runner_)
1314 view_runner_->SetWindowIsKey(value);
1315 }
1316
1317 std::string TestRunnerBindings::PathToLocalResource(const std::string& path) {
1318 if (runner_)
1319 return runner_->PathToLocalResource(path);
1320 return std::string();
1321 }
1322
1323 void TestRunnerBindings::SetBackingScaleFactor(
1324 double value, v8::Local<v8::Function> callback) {
1325 if (view_runner_)
1326 view_runner_->SetBackingScaleFactor(value, callback);
1327 }
1328
1329 void TestRunnerBindings::EnableUseZoomForDSF(
1330 v8::Local<v8::Function> callback) {
1331 if (view_runner_)
1332 view_runner_->EnableUseZoomForDSF(callback);
1333 }
1334
1335 void TestRunnerBindings::SetColorProfile(
1336 const std::string& name, v8::Local<v8::Function> callback) {
1337 if (view_runner_)
1338 view_runner_->SetColorProfile(name, callback);
1339 }
1340
1341 void TestRunnerBindings::SetBluetoothFakeAdapter(
1342 const std::string& adapter_name,
1343 v8::Local<v8::Function> callback) {
1344 if (view_runner_)
1345 view_runner_->SetBluetoothFakeAdapter(adapter_name, callback);
1346 }
1347
1348 void TestRunnerBindings::SetBluetoothManualChooser(bool enable) {
1349 if (view_runner_)
1350 view_runner_->SetBluetoothManualChooser(enable);
1351 }
1352
1353 void TestRunnerBindings::GetBluetoothManualChooserEvents(
1354 v8::Local<v8::Function> callback) {
1355 if (view_runner_)
1356 return view_runner_->GetBluetoothManualChooserEvents(callback);
1357 }
1358
1359 void TestRunnerBindings::SendBluetoothManualChooserEvent(
1360 const std::string& event,
1361 const std::string& argument) {
1362 if (view_runner_)
1363 view_runner_->SendBluetoothManualChooserEvent(event, argument);
1364 }
1365
1366 void TestRunnerBindings::SetPOSIXLocale(const std::string& locale) {
1367 if (runner_)
1368 runner_->SetPOSIXLocale(locale);
1369 }
1370
1371 void TestRunnerBindings::SetMIDIAccessorResult(bool result) {
1372 if (runner_) {
1373 runner_->SetMIDIAccessorResult(
1374 result ? midi::mojom::Result::OK
1375 : midi::mojom::Result::INITIALIZATION_ERROR);
1376 }
1377 }
1378
1379 void TestRunnerBindings::SimulateWebNotificationClick(const std::string& title,
1380 int action_index) {
1381 if (!runner_)
1382 return;
1383 runner_->SimulateWebNotificationClick(title, action_index,
1384 base::NullableString16());
1385 }
1386
1387 void TestRunnerBindings::SimulateWebNotificationClickWithReply(
1388 const std::string& title,
1389 int action_index,
1390 const std::string& reply) {
1391 if (!runner_)
1392 return;
1393 runner_->SimulateWebNotificationClick(
1394 title, action_index,
1395 base::NullableString16(base::UTF8ToUTF16(reply), false /* is_null */));
1396 }
1397
1398 void TestRunnerBindings::SimulateWebNotificationClose(const std::string& title,
1399 bool by_user) {
1400 if (!runner_)
1401 return;
1402 runner_->SimulateWebNotificationClose(title, by_user);
1403 }
1404
1405 void TestRunnerBindings::AddMockSpeechRecognitionResult(
1406 const std::string& transcript, double confidence) {
1407 if (runner_)
1408 runner_->AddMockSpeechRecognitionResult(transcript, confidence);
1409 }
1410
1411 void TestRunnerBindings::SetMockSpeechRecognitionError(
1412 const std::string& error, const std::string& message) {
1413 if (runner_)
1414 runner_->SetMockSpeechRecognitionError(error, message);
1415 }
1416
1417 void TestRunnerBindings::SetMockCredentialManagerResponse(
1418 const std::string& id,
1419 const std::string& name,
1420 const std::string& avatar,
1421 const std::string& password) {
1422 if (runner_)
1423 runner_->SetMockCredentialManagerResponse(id, name, avatar, password);
1424 }
1425
1426 void TestRunnerBindings::ClearMockCredentialManagerResponse() {
1427 if (runner_)
1428 runner_->ClearMockCredentialManagerResponse();
1429 }
1430
1431 void TestRunnerBindings::SetMockCredentialManagerError(
1432 const std::string& error) {
1433 if (runner_)
1434 runner_->SetMockCredentialManagerError(error);
1435 }
1436
1437 void TestRunnerBindings::AddWebPageOverlay() {
1438 if (view_runner_)
1439 view_runner_->AddWebPageOverlay();
1440 }
1441
1442 void TestRunnerBindings::RemoveWebPageOverlay() {
1443 if (view_runner_)
1444 view_runner_->RemoveWebPageOverlay();
1445 }
1446
1447 void TestRunnerBindings::LayoutAndPaintAsync() {
1448 if (view_runner_)
1449 view_runner_->LayoutAndPaintAsync();
1450 }
1451
1452 void TestRunnerBindings::LayoutAndPaintAsyncThen(
1453 v8::Local<v8::Function> callback) {
1454 if (view_runner_)
1455 view_runner_->LayoutAndPaintAsyncThen(callback);
1456 }
1457
1458 void TestRunnerBindings::GetManifestThen(v8::Local<v8::Function> callback) {
1459 if (view_runner_)
1460 view_runner_->GetManifestThen(callback);
1461 }
1462
1463 void TestRunnerBindings::CapturePixelsAsyncThen(
1464 v8::Local<v8::Function> callback) {
1465 if (view_runner_)
1466 view_runner_->CapturePixelsAsyncThen(callback);
1467 }
1468
1469 void TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen(
1470 int x, int y, v8::Local<v8::Function> callback) {
1471 if (view_runner_)
1472 view_runner_->CopyImageAtAndCapturePixelsAsyncThen(x, y, callback);
1473 }
1474
1475 void TestRunnerBindings::SetCustomTextOutput(const std::string& output) {
1476 if (runner_)
1477 runner_->setCustomTextOutput(output);
1478 }
1479
1480 void TestRunnerBindings::SetViewSourceForFrame(const std::string& name,
1481 bool enabled) {
1482 if (view_runner_)
1483 view_runner_->SetViewSourceForFrame(name, enabled);
1484 }
1485
1486 void TestRunnerBindings::SetPermission(const std::string& name,
1487 const std::string& value,
1488 const std::string& origin,
1489 const std::string& embedding_origin) {
1490 if (!runner_)
1491 return;
1492
1493 return runner_->SetPermission(
1494 name, value, GURL(origin), GURL(embedding_origin));
1495 }
1496
1497 void TestRunnerBindings::DispatchBeforeInstallPromptEvent(
1498 const std::vector<std::string>& event_platforms,
1499 v8::Local<v8::Function> callback) {
1500 if (!view_runner_)
1501 return;
1502
1503 return view_runner_->DispatchBeforeInstallPromptEvent(event_platforms,
1504 callback);
1505 }
1506
1507 void TestRunnerBindings::ResolveBeforeInstallPromptPromise(
1508 const std::string& platform) {
1509 if (!runner_)
1510 return;
1511
1512 runner_->ResolveBeforeInstallPromptPromise(platform);
1513 }
1514
1515 void TestRunnerBindings::RunIdleTasks(v8::Local<v8::Function> callback) {
1516 if (!view_runner_)
1517 return;
1518 view_runner_->RunIdleTasks(callback);
1519 }
1520
1521 std::string TestRunnerBindings::PlatformName() {
1522 if (runner_)
1523 return runner_->platform_name_;
1524 return std::string();
1525 }
1526
1527 std::string TestRunnerBindings::TooltipText() {
1528 if (runner_)
1529 return runner_->tooltip_text_;
1530 return std::string();
1531 }
1532
1533 int TestRunnerBindings::WebHistoryItemCount() {
1534 if (runner_)
1535 return runner_->web_history_item_count_;
1536 return false;
1537 }
1538
1539 void TestRunnerBindings::ForceNextWebGLContextCreationToFail() {
1540 if (view_runner_)
1541 view_runner_->ForceNextWebGLContextCreationToFail();
1542 }
1543
1544 void TestRunnerBindings::ForceNextDrawingBufferCreationToFail() {
1545 if (view_runner_)
1546 view_runner_->ForceNextDrawingBufferCreationToFail();
1547 }
1548
1549 void TestRunnerBindings::NotImplemented(const gin::Arguments& args) {
1550 }
1551
1552 TestRunner::WorkQueue::WorkQueue(TestRunner* controller)
1553 : frozen_(false), controller_(controller), weak_factory_(this) {}
1554
1555 TestRunner::WorkQueue::~WorkQueue() {
1556 Reset();
1557 }
1558
1559 void TestRunner::WorkQueue::ProcessWorkSoon() {
1560 if (controller_->topLoadingFrame())
1561 return;
1562
1563 if (!queue_.empty()) {
1564 // We delay processing queued work to avoid recursion problems.
1565 controller_->delegate_->PostTask(base::Bind(
1566 &TestRunner::WorkQueue::ProcessWork, weak_factory_.GetWeakPtr()));
1567 } else if (!controller_->layout_test_runtime_flags_.wait_until_done()) {
1568 controller_->delegate_->TestFinished();
1569 }
1570 }
1571
1572 void TestRunner::WorkQueue::Reset() {
1573 frozen_ = false;
1574 while (!queue_.empty()) {
1575 delete queue_.front();
1576 queue_.pop_front();
1577 }
1578 }
1579
1580 void TestRunner::WorkQueue::AddWork(WorkItem* work) {
1581 if (frozen_) {
1582 delete work;
1583 return;
1584 }
1585 queue_.push_back(work);
1586 }
1587
1588 void TestRunner::WorkQueue::ProcessWork() {
1589 // Quit doing work once a load is in progress.
1590 if (controller_->main_view_) {
1591 while (!queue_.empty()) {
1592 bool startedLoad =
1593 queue_.front()->Run(controller_->delegate_, controller_->main_view_);
1594 delete queue_.front();
1595 queue_.pop_front();
1596 if (startedLoad)
1597 return;
1598 }
1599 }
1600
1601 if (!controller_->layout_test_runtime_flags_.wait_until_done() &&
1602 !controller_->topLoadingFrame())
1603 controller_->delegate_->TestFinished();
1604 }
1605
1606 TestRunner::TestRunner(TestInterfaces* interfaces)
1607 : test_is_running_(false),
1608 close_remaining_windows_(false),
1609 work_queue_(this),
1610 web_history_item_count_(0),
1611 test_interfaces_(interfaces),
1612 delegate_(nullptr),
1613 main_view_(nullptr),
1614 mock_content_settings_client_(
1615 new MockContentSettingsClient(&layout_test_runtime_flags_)),
1616 will_navigate_(false),
1617 credential_manager_client_(new MockCredentialManagerClient),
1618 mock_screen_orientation_client_(new MockScreenOrientationClient),
1619 spellcheck_(new SpellCheckClient(this)),
1620 chooser_count_(0),
1621 previously_focused_view_(nullptr),
1622 is_web_platform_tests_mode_(false),
1623 effective_connection_type_(
1624 blink::WebEffectiveConnectionType::TypeUnknown),
1625 weak_factory_(this) {}
1626
1627 TestRunner::~TestRunner() {}
1628
1629 void TestRunner::Install(
1630 WebLocalFrame* frame,
1631 base::WeakPtr<TestRunnerForSpecificView> view_test_runner) {
1632 TestRunnerBindings::Install(weak_factory_.GetWeakPtr(), view_test_runner,
1633 frame);
1634 }
1635
1636 void TestRunner::SetDelegate(WebTestDelegate* delegate) {
1637 delegate_ = delegate;
1638 mock_content_settings_client_->SetDelegate(delegate);
1639 spellcheck_->SetDelegate(delegate);
1640 if (speech_recognizer_)
1641 speech_recognizer_->SetDelegate(delegate);
1642 }
1643
1644 void TestRunner::SetMainView(WebView* web_view) {
1645 main_view_ = web_view;
1646 if (disable_v8_cache_)
1647 SetV8CacheDisabled(true);
1648 }
1649
1650 void TestRunner::Reset() {
1651 is_web_platform_tests_mode_ = false;
1652 will_navigate_ = false;
1653 top_loading_frame_ = nullptr;
1654 layout_test_runtime_flags_.Reset();
1655 mock_screen_orientation_client_->ResetData();
1656 drag_image_.reset();
1657
1658 WebSecurityPolicy::resetOriginAccessWhitelists();
1659 #if defined(__linux__) || defined(ANDROID)
1660 WebFontRendering::setSubpixelPositioning(false);
1661 #endif
1662
1663 if (delegate_) {
1664 // Reset the default quota for each origin to 5MB
1665 delegate_->SetDatabaseQuota(5 * 1024 * 1024);
1666 delegate_->SetDeviceColorProfile("reset");
1667 delegate_->SetDeviceScaleFactor(GetDefaultDeviceScaleFactor());
1668 delegate_->SetBlockThirdPartyCookies(true);
1669 delegate_->SetLocale("");
1670 delegate_->UseUnfortunateSynchronousResizeMode(false);
1671 delegate_->DisableAutoResizeMode(WebSize());
1672 delegate_->DeleteAllCookies();
1673 delegate_->SetBluetoothManualChooser(false);
1674 delegate_->ResetPermissions();
1675 ResetDeviceLight();
1676 }
1677
1678 dump_as_audio_ = false;
1679 dump_back_forward_list_ = false;
1680 test_repaint_ = false;
1681 sweep_horizontally_ = false;
1682 midi_accessor_result_ = midi::mojom::Result::OK;
1683
1684 http_headers_to_clear_.clear();
1685
1686 platform_name_ = "chromium";
1687 tooltip_text_ = std::string();
1688 web_history_item_count_ = 0;
1689
1690 SetUseMockTheme(true);
1691
1692 weak_factory_.InvalidateWeakPtrs();
1693 work_queue_.Reset();
1694
1695 if (close_remaining_windows_ && delegate_)
1696 delegate_->CloseRemainingWindows();
1697 else
1698 close_remaining_windows_ = true;
1699
1700 spellcheck_->Reset();
1701 }
1702
1703 void TestRunner::SetTestIsRunning(bool running) {
1704 test_is_running_ = running;
1705 }
1706
1707 bool TestRunner::shouldDumpEditingCallbacks() const {
1708 return layout_test_runtime_flags_.dump_editting_callbacks();
1709 }
1710
1711 void TestRunner::setShouldDumpAsText(bool value) {
1712 layout_test_runtime_flags_.set_dump_as_text(value);
1713 OnLayoutTestRuntimeFlagsChanged();
1714 }
1715
1716 void TestRunner::setShouldDumpAsMarkup(bool value) {
1717 layout_test_runtime_flags_.set_dump_as_markup(value);
1718 OnLayoutTestRuntimeFlagsChanged();
1719 }
1720
1721 bool TestRunner::shouldDumpAsCustomText() const {
1722 return layout_test_runtime_flags_.has_custom_text_output();
1723 }
1724
1725 std::string TestRunner::customDumpText() const {
1726 return layout_test_runtime_flags_.custom_text_output();
1727 }
1728
1729 void TestRunner::setCustomTextOutput(const std::string& text) {
1730 layout_test_runtime_flags_.set_custom_text_output(text);
1731 layout_test_runtime_flags_.set_has_custom_text_output(true);
1732 OnLayoutTestRuntimeFlagsChanged();
1733 }
1734
1735 bool TestRunner::ShouldGeneratePixelResults() {
1736 CheckResponseMimeType();
1737 return layout_test_runtime_flags_.generate_pixel_results();
1738 }
1739
1740 bool TestRunner::shouldStayOnPageAfterHandlingBeforeUnload() const {
1741 return layout_test_runtime_flags_.stay_on_page_after_handling_before_unload();
1742 }
1743
1744
1745 void TestRunner::setShouldGeneratePixelResults(bool value) {
1746 layout_test_runtime_flags_.set_generate_pixel_results(value);
1747 OnLayoutTestRuntimeFlagsChanged();
1748 }
1749
1750 bool TestRunner::ShouldDumpAsAudio() const {
1751 return dump_as_audio_;
1752 }
1753
1754 void TestRunner::GetAudioData(std::vector<unsigned char>* buffer_view) const {
1755 *buffer_view = audio_data_;
1756 }
1757
1758 bool TestRunner::IsRecursiveLayoutDumpRequested() {
1759 CheckResponseMimeType();
1760 return layout_test_runtime_flags_.dump_child_frames();
1761 }
1762
1763 std::string TestRunner::DumpLayout(blink::WebLocalFrame* frame) {
1764 CheckResponseMimeType();
1765 return ::test_runner::DumpLayout(frame, layout_test_runtime_flags_);
1766 }
1767
1768 void TestRunner::DumpPixelsAsync(
1769 blink::WebView* web_view,
1770 const base::Callback<void(const SkBitmap&)>& callback) {
1771 if (layout_test_runtime_flags_.dump_drag_image()) {
1772 if (drag_image_.isNull()) {
1773 // This means the test called dumpDragImage but did not initiate a drag.
1774 // Return a blank image so that the test fails.
1775 SkBitmap bitmap;
1776 bitmap.allocN32Pixels(1, 1);
1777 {
1778 SkAutoLockPixels lock(bitmap);
1779 bitmap.eraseColor(0);
1780 }
1781 callback.Run(bitmap);
1782 return;
1783 }
1784
1785 callback.Run(drag_image_.getSkBitmap());
1786 return;
1787 }
1788
1789 test_runner::DumpPixelsAsync(web_view, layout_test_runtime_flags_,
1790 delegate_->GetDeviceScaleFactor(), callback);
1791 }
1792
1793 void TestRunner::ReplicateLayoutTestRuntimeFlagsChanges(
1794 const base::DictionaryValue& changed_values) {
1795 if (test_is_running_)
1796 layout_test_runtime_flags_.tracked_dictionary().ApplyUntrackedChanges(
1797 changed_values);
1798 }
1799
1800 bool TestRunner::HasCustomTextDump(std::string* custom_text_dump) const {
1801 if (shouldDumpAsCustomText()) {
1802 *custom_text_dump = customDumpText();
1803 return true;
1804 }
1805
1806 return false;
1807 }
1808
1809 bool TestRunner::shouldDumpFrameLoadCallbacks() const {
1810 return test_is_running_ &&
1811 layout_test_runtime_flags_.dump_frame_load_callbacks();
1812 }
1813
1814 void TestRunner::setShouldDumpFrameLoadCallbacks(bool value) {
1815 layout_test_runtime_flags_.set_dump_frame_load_callbacks(value);
1816 OnLayoutTestRuntimeFlagsChanged();
1817 }
1818
1819 bool TestRunner::shouldDumpPingLoaderCallbacks() const {
1820 return test_is_running_ &&
1821 layout_test_runtime_flags_.dump_ping_loader_callbacks();
1822 }
1823
1824 void TestRunner::setShouldEnableViewSource(bool value) {
1825 // TODO(lukasza): This flag should be 1) replicated across OOPIFs and
1826 // 2) applied to all views, not just the main window view.
1827
1828 // Path-based test config is trigerred by BlinkTestRunner, when |main_view_|
1829 // is guaranteed to exist at this point.
1830 DCHECK(main_view_);
1831
1832 main_view_->mainFrame()->enableViewSourceMode(value);
1833 }
1834
1835 bool TestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const {
1836 return test_is_running_ &&
1837 layout_test_runtime_flags_.dump_user_gesture_in_frame_load_callbacks();
1838 }
1839
1840 bool TestRunner::shouldDumpTitleChanges() const {
1841 return layout_test_runtime_flags_.dump_title_changes();
1842 }
1843
1844 bool TestRunner::shouldDumpIconChanges() const {
1845 return layout_test_runtime_flags_.dump_icon_changes();
1846 }
1847
1848 bool TestRunner::shouldDumpCreateView() const {
1849 return layout_test_runtime_flags_.dump_create_view();
1850 }
1851
1852 bool TestRunner::canOpenWindows() const {
1853 return layout_test_runtime_flags_.can_open_windows();
1854 }
1855
1856 bool TestRunner::shouldDumpResourceLoadCallbacks() const {
1857 return test_is_running_ &&
1858 layout_test_runtime_flags_.dump_resource_load_callbacks();
1859 }
1860
1861 bool TestRunner::shouldDumpResourceResponseMIMETypes() const {
1862 return test_is_running_ &&
1863 layout_test_runtime_flags_.dump_resource_response_mime_types();
1864 }
1865
1866 WebContentSettingsClient* TestRunner::GetWebContentSettings() const {
1867 return mock_content_settings_client_.get();
1868 }
1869
1870 void TestRunner::InitializeWebViewWithMocks(blink::WebView* web_view) {
1871 web_view->setSpellCheckClient(spellcheck_.get());
1872 web_view->setCredentialManagerClient(credential_manager_client_.get());
1873 }
1874
1875 bool TestRunner::shouldDumpStatusCallbacks() const {
1876 return layout_test_runtime_flags_.dump_window_status_changes();
1877 }
1878
1879 bool TestRunner::shouldDumpSpellCheckCallbacks() const {
1880 return layout_test_runtime_flags_.dump_spell_check_callbacks();
1881 }
1882
1883 bool TestRunner::ShouldDumpBackForwardList() const {
1884 return dump_back_forward_list_;
1885 }
1886
1887 bool TestRunner::isPrinting() const {
1888 return layout_test_runtime_flags_.is_printing();
1889 }
1890
1891 bool TestRunner::shouldWaitUntilExternalURLLoad() const {
1892 return layout_test_runtime_flags_.wait_until_external_url_load();
1893 }
1894
1895 const std::set<std::string>* TestRunner::httpHeadersToClear() const {
1896 return &http_headers_to_clear_;
1897 }
1898
1899 bool TestRunner::IsFramePartOfMainTestWindow(blink::WebFrame* frame) const {
1900 return test_is_running_ && frame->top()->view() == main_view_;
1901 }
1902
1903 void TestRunner::OnNavigationBegin(WebFrame* frame) {
1904 if (IsFramePartOfMainTestWindow(frame))
1905 will_navigate_ = true;
1906 }
1907
1908 bool TestRunner::tryToSetTopLoadingFrame(WebFrame* frame) {
1909 will_navigate_ = false;
1910 if (!IsFramePartOfMainTestWindow(frame))
1911 return false;
1912
1913 if (top_loading_frame_ || layout_test_runtime_flags_.have_top_loading_frame())
1914 return false;
1915
1916 top_loading_frame_ = frame;
1917 layout_test_runtime_flags_.set_have_top_loading_frame(true);
1918 OnLayoutTestRuntimeFlagsChanged();
1919 return true;
1920 }
1921
1922 bool TestRunner::tryToClearTopLoadingFrame(WebFrame* frame) {
1923 will_navigate_ = false;
1924 if (!IsFramePartOfMainTestWindow(frame))
1925 return false;
1926
1927 if (frame != top_loading_frame_)
1928 return false;
1929
1930 top_loading_frame_ = nullptr;
1931 DCHECK(layout_test_runtime_flags_.have_top_loading_frame());
1932 layout_test_runtime_flags_.set_have_top_loading_frame(false);
1933 OnLayoutTestRuntimeFlagsChanged();
1934
1935 LocationChangeDone();
1936 return true;
1937 }
1938
1939 WebFrame* TestRunner::topLoadingFrame() const {
1940 return top_loading_frame_;
1941 }
1942
1943 WebFrame* TestRunner::mainFrame() const {
1944 return main_view_->mainFrame();
1945 }
1946
1947 void TestRunner::policyDelegateDone() {
1948 DCHECK(layout_test_runtime_flags_.wait_until_done());
1949 delegate_->TestFinished();
1950 layout_test_runtime_flags_.set_wait_until_done(false);
1951 OnLayoutTestRuntimeFlagsChanged();
1952 }
1953
1954 bool TestRunner::policyDelegateEnabled() const {
1955 return layout_test_runtime_flags_.policy_delegate_enabled();
1956 }
1957
1958 bool TestRunner::policyDelegateIsPermissive() const {
1959 return layout_test_runtime_flags_.policy_delegate_is_permissive();
1960 }
1961
1962 bool TestRunner::policyDelegateShouldNotifyDone() const {
1963 return layout_test_runtime_flags_.policy_delegate_should_notify_done();
1964 }
1965
1966 void TestRunner::setToolTipText(const WebString& text) {
1967 tooltip_text_ = text.utf8();
1968 }
1969
1970 void TestRunner::setDragImage(
1971 const blink::WebImage& drag_image) {
1972 if (layout_test_runtime_flags_.dump_drag_image()) {
1973 if (drag_image_.isNull())
1974 drag_image_ = drag_image;
1975 }
1976 }
1977
1978 bool TestRunner::shouldDumpNavigationPolicy() const {
1979 return layout_test_runtime_flags_.dump_navigation_policy();
1980 }
1981
1982 midi::mojom::Result TestRunner::midiAccessorResult() {
1983 return midi_accessor_result_;
1984 }
1985
1986 void TestRunner::ClearDevToolsLocalStorage() {
1987 delegate_->ClearDevToolsLocalStorage();
1988 }
1989
1990 void TestRunner::SetV8CacheDisabled(bool disabled) {
1991 if (!main_view_) {
1992 disable_v8_cache_ = disabled;
1993 return;
1994 }
1995 main_view_->settings()->setV8CacheOptions(disabled ?
1996 blink::WebSettings::V8CacheOptionsNone :
1997 blink::WebSettings::V8CacheOptionsDefault);
1998 }
1999
2000 void TestRunner::ShowDevTools(const std::string& settings,
2001 const std::string& frontend_url) {
2002 delegate_->ShowDevTools(settings, frontend_url);
2003 }
2004
2005 class WorkItemBackForward : public TestRunner::WorkItem {
2006 public:
2007 WorkItemBackForward(int distance) : distance_(distance) {}
2008
2009 bool Run(WebTestDelegate* delegate, WebView*) override {
2010 delegate->GoToOffset(distance_);
2011 return true; // FIXME: Did it really start a navigation?
2012 }
2013
2014 private:
2015 int distance_;
2016 };
2017
2018 void TestRunner::WaitUntilDone() {
2019 layout_test_runtime_flags_.set_wait_until_done(true);
2020 OnLayoutTestRuntimeFlagsChanged();
2021 }
2022
2023 void TestRunner::QueueBackNavigation(int how_far_back) {
2024 work_queue_.AddWork(new WorkItemBackForward(-how_far_back));
2025 }
2026
2027 void TestRunner::QueueForwardNavigation(int how_far_forward) {
2028 work_queue_.AddWork(new WorkItemBackForward(how_far_forward));
2029 }
2030
2031 class WorkItemReload : public TestRunner::WorkItem {
2032 public:
2033 bool Run(WebTestDelegate* delegate, WebView*) override {
2034 delegate->Reload();
2035 return true;
2036 }
2037 };
2038
2039 void TestRunner::QueueReload() {
2040 work_queue_.AddWork(new WorkItemReload());
2041 }
2042
2043 class WorkItemLoadingScript : public TestRunner::WorkItem {
2044 public:
2045 WorkItemLoadingScript(const std::string& script)
2046 : script_(script) {}
2047
2048 bool Run(WebTestDelegate*, WebView* web_view) override {
2049 web_view->mainFrame()->executeScript(
2050 WebScriptSource(WebString::fromUTF8(script_)));
2051 return true; // FIXME: Did it really start a navigation?
2052 }
2053
2054 private:
2055 std::string script_;
2056 };
2057
2058 void TestRunner::QueueLoadingScript(const std::string& script) {
2059 work_queue_.AddWork(new WorkItemLoadingScript(script));
2060 }
2061
2062 class WorkItemNonLoadingScript : public TestRunner::WorkItem {
2063 public:
2064 WorkItemNonLoadingScript(const std::string& script)
2065 : script_(script) {}
2066
2067 bool Run(WebTestDelegate*, WebView* web_view) override {
2068 web_view->mainFrame()->executeScript(
2069 WebScriptSource(WebString::fromUTF8(script_)));
2070 return false;
2071 }
2072
2073 private:
2074 std::string script_;
2075 };
2076
2077 void TestRunner::QueueNonLoadingScript(const std::string& script) {
2078 work_queue_.AddWork(new WorkItemNonLoadingScript(script));
2079 }
2080
2081 class WorkItemLoad : public TestRunner::WorkItem {
2082 public:
2083 WorkItemLoad(const WebURL& url, const std::string& target)
2084 : url_(url), target_(target) {}
2085
2086 bool Run(WebTestDelegate* delegate, WebView*) override {
2087 delegate->LoadURLForFrame(url_, target_);
2088 return true; // FIXME: Did it really start a navigation?
2089 }
2090
2091 private:
2092 WebURL url_;
2093 std::string target_;
2094 };
2095
2096 void TestRunner::QueueLoad(const std::string& url, const std::string& target) {
2097 if (!main_view_)
2098 return;
2099
2100 // FIXME: Implement WebURL::resolve() and avoid GURL.
2101 GURL current_url = main_view_->mainFrame()->document().url();
2102 GURL full_url = current_url.Resolve(url);
2103 work_queue_.AddWork(new WorkItemLoad(full_url, target));
2104 }
2105
2106 void TestRunner::SetCustomPolicyDelegate(gin::Arguments* args) {
2107 bool value;
2108 args->GetNext(&value);
2109 layout_test_runtime_flags_.set_policy_delegate_enabled(value);
2110
2111 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsBoolean()) {
2112 args->GetNext(&value);
2113 layout_test_runtime_flags_.set_policy_delegate_is_permissive(value);
2114 }
2115
2116 OnLayoutTestRuntimeFlagsChanged();
2117 }
2118
2119 void TestRunner::WaitForPolicyDelegate() {
2120 layout_test_runtime_flags_.set_policy_delegate_enabled(true);
2121 layout_test_runtime_flags_.set_policy_delegate_should_notify_done(true);
2122 layout_test_runtime_flags_.set_wait_until_done(true);
2123 OnLayoutTestRuntimeFlagsChanged();
2124 }
2125
2126 int TestRunner::WindowCount() {
2127 return test_interfaces_->GetWindowList().size();
2128 }
2129
2130 void TestRunner::SetCloseRemainingWindowsWhenComplete(
2131 bool close_remaining_windows) {
2132 close_remaining_windows_ = close_remaining_windows;
2133 }
2134
2135 void TestRunner::ResetTestHelperControllers() {
2136 test_interfaces_->ResetTestHelperControllers();
2137 }
2138
2139 void TestRunner::AddOriginAccessWhitelistEntry(
2140 const std::string& source_origin,
2141 const std::string& destination_protocol,
2142 const std::string& destination_host,
2143 bool allow_destination_subdomains) {
2144 WebURL url((GURL(source_origin)));
2145 if (!url.isValid())
2146 return;
2147
2148 WebSecurityPolicy::addOriginAccessWhitelistEntry(
2149 url,
2150 WebString::fromUTF8(destination_protocol),
2151 WebString::fromUTF8(destination_host),
2152 allow_destination_subdomains);
2153 }
2154
2155 void TestRunner::RemoveOriginAccessWhitelistEntry(
2156 const std::string& source_origin,
2157 const std::string& destination_protocol,
2158 const std::string& destination_host,
2159 bool allow_destination_subdomains) {
2160 WebURL url((GURL(source_origin)));
2161 if (!url.isValid())
2162 return;
2163
2164 WebSecurityPolicy::removeOriginAccessWhitelistEntry(
2165 url,
2166 WebString::fromUTF8(destination_protocol),
2167 WebString::fromUTF8(destination_host),
2168 allow_destination_subdomains);
2169 }
2170
2171 void TestRunner::SetTextSubpixelPositioning(bool value) {
2172 #if defined(__linux__) || defined(ANDROID)
2173 // Since FontConfig doesn't provide a variable to control subpixel
2174 // positioning, we'll fall back to setting it globally for all fonts.
2175 WebFontRendering::setSubpixelPositioning(value);
2176 #endif
2177 }
2178
2179 void TestRunner::UseUnfortunateSynchronousResizeMode() {
2180 delegate_->UseUnfortunateSynchronousResizeMode(true);
2181 }
2182
2183 bool TestRunner::EnableAutoResizeMode(int min_width,
2184 int min_height,
2185 int max_width,
2186 int max_height) {
2187 WebSize min_size(min_width, min_height);
2188 WebSize max_size(max_width, max_height);
2189 delegate_->EnableAutoResizeMode(min_size, max_size);
2190 return true;
2191 }
2192
2193 bool TestRunner::DisableAutoResizeMode(int new_width, int new_height) {
2194 WebSize new_size(new_width, new_height);
2195 delegate_->DisableAutoResizeMode(new_size);
2196 return true;
2197 }
2198
2199 void TestRunner::SetMockDeviceLight(double value) {
2200 delegate_->SetDeviceLightData(value);
2201 }
2202
2203 void TestRunner::ResetDeviceLight() {
2204 delegate_->SetDeviceLightData(-1);
2205 }
2206
2207 void TestRunner::SetMockDeviceMotion(
2208 bool has_acceleration_x, double acceleration_x,
2209 bool has_acceleration_y, double acceleration_y,
2210 bool has_acceleration_z, double acceleration_z,
2211 bool has_acceleration_including_gravity_x,
2212 double acceleration_including_gravity_x,
2213 bool has_acceleration_including_gravity_y,
2214 double acceleration_including_gravity_y,
2215 bool has_acceleration_including_gravity_z,
2216 double acceleration_including_gravity_z,
2217 bool has_rotation_rate_alpha, double rotation_rate_alpha,
2218 bool has_rotation_rate_beta, double rotation_rate_beta,
2219 bool has_rotation_rate_gamma, double rotation_rate_gamma,
2220 double interval) {
2221 WebDeviceMotionData motion;
2222
2223 // acceleration
2224 motion.hasAccelerationX = has_acceleration_x;
2225 motion.accelerationX = acceleration_x;
2226 motion.hasAccelerationY = has_acceleration_y;
2227 motion.accelerationY = acceleration_y;
2228 motion.hasAccelerationZ = has_acceleration_z;
2229 motion.accelerationZ = acceleration_z;
2230
2231 // accelerationIncludingGravity
2232 motion.hasAccelerationIncludingGravityX =
2233 has_acceleration_including_gravity_x;
2234 motion.accelerationIncludingGravityX = acceleration_including_gravity_x;
2235 motion.hasAccelerationIncludingGravityY =
2236 has_acceleration_including_gravity_y;
2237 motion.accelerationIncludingGravityY = acceleration_including_gravity_y;
2238 motion.hasAccelerationIncludingGravityZ =
2239 has_acceleration_including_gravity_z;
2240 motion.accelerationIncludingGravityZ = acceleration_including_gravity_z;
2241
2242 // rotationRate
2243 motion.hasRotationRateAlpha = has_rotation_rate_alpha;
2244 motion.rotationRateAlpha = rotation_rate_alpha;
2245 motion.hasRotationRateBeta = has_rotation_rate_beta;
2246 motion.rotationRateBeta = rotation_rate_beta;
2247 motion.hasRotationRateGamma = has_rotation_rate_gamma;
2248 motion.rotationRateGamma = rotation_rate_gamma;
2249
2250 // interval
2251 motion.interval = interval;
2252
2253 delegate_->SetDeviceMotionData(motion);
2254 }
2255
2256 void TestRunner::SetMockDeviceOrientation(bool has_alpha, double alpha,
2257 bool has_beta, double beta,
2258 bool has_gamma, double gamma,
2259 bool absolute) {
2260 WebDeviceOrientationData orientation;
2261
2262 // alpha
2263 orientation.hasAlpha = has_alpha;
2264 orientation.alpha = alpha;
2265
2266 // beta
2267 orientation.hasBeta = has_beta;
2268 orientation.beta = beta;
2269
2270 // gamma
2271 orientation.hasGamma = has_gamma;
2272 orientation.gamma = gamma;
2273
2274 // absolute
2275 orientation.absolute = absolute;
2276
2277 delegate_->SetDeviceOrientationData(orientation);
2278 }
2279
2280 MockScreenOrientationClient* TestRunner::getMockScreenOrientationClient() {
2281 return mock_screen_orientation_client_.get();
2282 }
2283
2284 MockWebUserMediaClient* TestRunner::getMockWebUserMediaClient() {
2285 if (!user_media_client_.get())
2286 user_media_client_.reset(new MockWebUserMediaClient(delegate_));
2287 return user_media_client_.get();
2288 }
2289
2290 MockWebSpeechRecognizer* TestRunner::getMockWebSpeechRecognizer() {
2291 if (!speech_recognizer_.get()) {
2292 speech_recognizer_.reset(new MockWebSpeechRecognizer());
2293 speech_recognizer_->SetDelegate(delegate_);
2294 }
2295 return speech_recognizer_.get();
2296 }
2297
2298 void TestRunner::SetMockScreenOrientation(const std::string& orientation_str) {
2299 blink::WebScreenOrientationType orientation;
2300
2301 if (orientation_str == "portrait-primary") {
2302 orientation = WebScreenOrientationPortraitPrimary;
2303 } else if (orientation_str == "portrait-secondary") {
2304 orientation = WebScreenOrientationPortraitSecondary;
2305 } else if (orientation_str == "landscape-primary") {
2306 orientation = WebScreenOrientationLandscapePrimary;
2307 } else {
2308 DCHECK_EQ("landscape-secondary", orientation_str);
2309 orientation = WebScreenOrientationLandscapeSecondary;
2310 }
2311
2312 for (WebViewTestProxyBase* window : test_interfaces_->GetWindowList()) {
2313 WebFrame* main_frame = window->web_view()->mainFrame();
2314 // TODO(lukasza): Need to make this work for remote frames.
2315 if (main_frame->isWebLocalFrame()) {
2316 mock_screen_orientation_client_->UpdateDeviceOrientation(
2317 main_frame->toWebLocalFrame(), orientation);
2318 }
2319 }
2320 }
2321
2322 void TestRunner::DisableMockScreenOrientation() {
2323 mock_screen_orientation_client_->SetDisabled(true);
2324 }
2325
2326 void TestRunner::DidOpenChooser() {
2327 chooser_count_++;
2328 }
2329
2330 void TestRunner::DidCloseChooser() {
2331 chooser_count_--;
2332 DCHECK_LE(0, chooser_count_);
2333 }
2334
2335 void TestRunner::SetPopupBlockingEnabled(bool block_popups) {
2336 delegate_->Preferences()->java_script_can_open_windows_automatically =
2337 !block_popups;
2338 delegate_->ApplyPreferences();
2339 }
2340
2341 void TestRunner::SetJavaScriptCanAccessClipboard(bool can_access) {
2342 delegate_->Preferences()->java_script_can_access_clipboard = can_access;
2343 delegate_->ApplyPreferences();
2344 }
2345
2346 void TestRunner::SetXSSAuditorEnabled(bool enabled) {
2347 delegate_->Preferences()->xss_auditor_enabled = enabled;
2348 delegate_->ApplyPreferences();
2349 }
2350
2351 void TestRunner::SetAllowUniversalAccessFromFileURLs(bool allow) {
2352 delegate_->Preferences()->allow_universal_access_from_file_urls = allow;
2353 delegate_->ApplyPreferences();
2354 }
2355
2356 void TestRunner::SetAllowFileAccessFromFileURLs(bool allow) {
2357 delegate_->Preferences()->allow_file_access_from_file_urls = allow;
2358 delegate_->ApplyPreferences();
2359 }
2360
2361 void TestRunner::OverridePreference(const std::string& key,
2362 v8::Local<v8::Value> value) {
2363 TestPreferences* prefs = delegate_->Preferences();
2364 if (key == "WebKitDefaultFontSize") {
2365 prefs->default_font_size = value->Int32Value();
2366 } else if (key == "WebKitMinimumFontSize") {
2367 prefs->minimum_font_size = value->Int32Value();
2368 } else if (key == "WebKitDefaultTextEncodingName") {
2369 v8::Isolate* isolate = blink::mainThreadIsolate();
2370 prefs->default_text_encoding_name =
2371 V8StringToWebString(value->ToString(isolate));
2372 } else if (key == "WebKitJavaScriptEnabled") {
2373 prefs->java_script_enabled = value->BooleanValue();
2374 } else if (key == "WebKitSupportsMultipleWindows") {
2375 prefs->supports_multiple_windows = value->BooleanValue();
2376 } else if (key == "WebKitDisplayImagesKey") {
2377 prefs->loads_images_automatically = value->BooleanValue();
2378 } else if (key == "WebKitPluginsEnabled") {
2379 prefs->plugins_enabled = value->BooleanValue();
2380 } else if (key == "WebKitTabToLinksPreferenceKey") {
2381 prefs->tabs_to_links = value->BooleanValue();
2382 } else if (key == "WebKitWebGLEnabled") {
2383 prefs->experimental_webgl_enabled = value->BooleanValue();
2384 } else if (key == "WebKitCSSGridLayoutEnabled") {
2385 prefs->experimental_css_grid_layout_enabled = value->BooleanValue();
2386 } else if (key == "WebKitHyperlinkAuditingEnabled") {
2387 prefs->hyperlink_auditing_enabled = value->BooleanValue();
2388 } else if (key == "WebKitEnableCaretBrowsing") {
2389 prefs->caret_browsing_enabled = value->BooleanValue();
2390 } else if (key == "WebKitAllowRunningInsecureContent") {
2391 prefs->allow_running_of_insecure_content = value->BooleanValue();
2392 } else if (key == "WebKitDisableReadingFromCanvas") {
2393 prefs->disable_reading_from_canvas = value->BooleanValue();
2394 } else if (key == "WebKitStrictMixedContentChecking") {
2395 prefs->strict_mixed_content_checking = value->BooleanValue();
2396 } else if (key == "WebKitStrictPowerfulFeatureRestrictions") {
2397 prefs->strict_powerful_feature_restrictions = value->BooleanValue();
2398 } else if (key == "WebKitShouldRespectImageOrientation") {
2399 prefs->should_respect_image_orientation = value->BooleanValue();
2400 } else if (key == "WebKitWebSecurityEnabled") {
2401 prefs->web_security_enabled = value->BooleanValue();
2402 } else if (key == "WebKitSpatialNavigationEnabled") {
2403 prefs->spatial_navigation_enabled = value->BooleanValue();
2404 } else {
2405 std::string message("Invalid name for preference: ");
2406 message.append(key);
2407 delegate_->PrintMessage(std::string("CONSOLE MESSAGE: ") + message + "\n");
2408 }
2409 delegate_->ApplyPreferences();
2410 }
2411
2412 std::string TestRunner::GetAcceptLanguages() const {
2413 return layout_test_runtime_flags_.accept_languages();
2414 }
2415
2416 void TestRunner::SetAcceptLanguages(const std::string& accept_languages) {
2417 if (accept_languages == GetAcceptLanguages())
2418 return;
2419
2420 layout_test_runtime_flags_.set_accept_languages(accept_languages);
2421 OnLayoutTestRuntimeFlagsChanged();
2422
2423 for (WebViewTestProxyBase* window : test_interfaces_->GetWindowList())
2424 window->web_view()->acceptLanguagesChanged();
2425 }
2426
2427 void TestRunner::SetPluginsEnabled(bool enabled) {
2428 delegate_->Preferences()->plugins_enabled = enabled;
2429 delegate_->ApplyPreferences();
2430 }
2431
2432 void TestRunner::DumpEditingCallbacks() {
2433 layout_test_runtime_flags_.set_dump_editting_callbacks(true);
2434 OnLayoutTestRuntimeFlagsChanged();
2435 }
2436
2437 void TestRunner::DumpAsMarkup() {
2438 layout_test_runtime_flags_.set_dump_as_markup(true);
2439 layout_test_runtime_flags_.set_generate_pixel_results(false);
2440 OnLayoutTestRuntimeFlagsChanged();
2441 }
2442
2443 void TestRunner::DumpAsText() {
2444 layout_test_runtime_flags_.set_dump_as_text(true);
2445 layout_test_runtime_flags_.set_generate_pixel_results(false);
2446 OnLayoutTestRuntimeFlagsChanged();
2447 }
2448
2449 void TestRunner::DumpAsTextWithPixelResults() {
2450 layout_test_runtime_flags_.set_dump_as_text(true);
2451 layout_test_runtime_flags_.set_generate_pixel_results(true);
2452 OnLayoutTestRuntimeFlagsChanged();
2453 }
2454
2455 void TestRunner::DumpChildFrameScrollPositions() {
2456 layout_test_runtime_flags_.set_dump_child_frame_scroll_positions(true);
2457 OnLayoutTestRuntimeFlagsChanged();
2458 }
2459
2460 void TestRunner::DumpChildFramesAsMarkup() {
2461 layout_test_runtime_flags_.set_dump_child_frames_as_markup(true);
2462 OnLayoutTestRuntimeFlagsChanged();
2463 }
2464
2465 void TestRunner::DumpChildFramesAsText() {
2466 layout_test_runtime_flags_.set_dump_child_frames_as_text(true);
2467 OnLayoutTestRuntimeFlagsChanged();
2468 }
2469
2470 void TestRunner::DumpIconChanges() {
2471 layout_test_runtime_flags_.set_dump_icon_changes(true);
2472 OnLayoutTestRuntimeFlagsChanged();
2473 }
2474
2475 void TestRunner::SetAudioData(const gin::ArrayBufferView& view) {
2476 unsigned char* bytes = static_cast<unsigned char*>(view.bytes());
2477 audio_data_.resize(view.num_bytes());
2478 std::copy(bytes, bytes + view.num_bytes(), audio_data_.begin());
2479 dump_as_audio_ = true;
2480 }
2481
2482 void TestRunner::DumpFrameLoadCallbacks() {
2483 layout_test_runtime_flags_.set_dump_frame_load_callbacks(true);
2484 OnLayoutTestRuntimeFlagsChanged();
2485 }
2486
2487 void TestRunner::DumpPingLoaderCallbacks() {
2488 layout_test_runtime_flags_.set_dump_ping_loader_callbacks(true);
2489 OnLayoutTestRuntimeFlagsChanged();
2490 }
2491
2492 void TestRunner::DumpUserGestureInFrameLoadCallbacks() {
2493 layout_test_runtime_flags_.set_dump_user_gesture_in_frame_load_callbacks(
2494 true);
2495 OnLayoutTestRuntimeFlagsChanged();
2496 }
2497
2498 void TestRunner::DumpTitleChanges() {
2499 layout_test_runtime_flags_.set_dump_title_changes(true);
2500 OnLayoutTestRuntimeFlagsChanged();
2501 }
2502
2503 void TestRunner::DumpCreateView() {
2504 layout_test_runtime_flags_.set_dump_create_view(true);
2505 OnLayoutTestRuntimeFlagsChanged();
2506 }
2507
2508 void TestRunner::SetCanOpenWindows() {
2509 layout_test_runtime_flags_.set_can_open_windows(true);
2510 OnLayoutTestRuntimeFlagsChanged();
2511 }
2512
2513 void TestRunner::DumpResourceLoadCallbacks() {
2514 layout_test_runtime_flags_.set_dump_resource_load_callbacks(true);
2515 OnLayoutTestRuntimeFlagsChanged();
2516 }
2517
2518 void TestRunner::DumpResourceResponseMIMETypes() {
2519 layout_test_runtime_flags_.set_dump_resource_response_mime_types(true);
2520 OnLayoutTestRuntimeFlagsChanged();
2521 }
2522
2523 void TestRunner::SetImagesAllowed(bool allowed) {
2524 layout_test_runtime_flags_.set_images_allowed(allowed);
2525 OnLayoutTestRuntimeFlagsChanged();
2526 }
2527
2528 void TestRunner::SetScriptsAllowed(bool allowed) {
2529 layout_test_runtime_flags_.set_scripts_allowed(allowed);
2530 OnLayoutTestRuntimeFlagsChanged();
2531 }
2532
2533 void TestRunner::SetStorageAllowed(bool allowed) {
2534 layout_test_runtime_flags_.set_storage_allowed(allowed);
2535 OnLayoutTestRuntimeFlagsChanged();
2536 }
2537
2538 void TestRunner::SetPluginsAllowed(bool allowed) {
2539 layout_test_runtime_flags_.set_plugins_allowed(allowed);
2540 OnLayoutTestRuntimeFlagsChanged();
2541 }
2542
2543 void TestRunner::SetAllowRunningOfInsecureContent(bool allowed) {
2544 layout_test_runtime_flags_.set_running_insecure_content_allowed(allowed);
2545 OnLayoutTestRuntimeFlagsChanged();
2546 }
2547
2548 void TestRunner::SetAutoplayAllowed(bool allowed) {
2549 layout_test_runtime_flags_.set_autoplay_allowed(allowed);
2550 OnLayoutTestRuntimeFlagsChanged();
2551 }
2552
2553 void TestRunner::DumpPermissionClientCallbacks() {
2554 layout_test_runtime_flags_.set_dump_web_content_settings_client_callbacks(
2555 true);
2556 OnLayoutTestRuntimeFlagsChanged();
2557 }
2558
2559 void TestRunner::SetDisallowedSubresourcePathSuffixes(
2560 const std::vector<std::string>& suffixes) {
2561 DCHECK(main_view_);
2562 main_view_->mainFrame()->dataSource()->setSubresourceFilter(
2563 new MockWebDocumentSubresourceFilter(suffixes));
2564 }
2565
2566 void TestRunner::DumpWindowStatusChanges() {
2567 layout_test_runtime_flags_.set_dump_window_status_changes(true);
2568 OnLayoutTestRuntimeFlagsChanged();
2569 }
2570
2571 void TestRunner::DumpSpellCheckCallbacks() {
2572 layout_test_runtime_flags_.set_dump_spell_check_callbacks(true);
2573 OnLayoutTestRuntimeFlagsChanged();
2574 }
2575
2576 void TestRunner::DumpBackForwardList() {
2577 dump_back_forward_list_ = true;
2578 }
2579
2580 void TestRunner::DumpSelectionRect() {
2581 layout_test_runtime_flags_.set_dump_selection_rect(true);
2582 OnLayoutTestRuntimeFlagsChanged();
2583 }
2584
2585 void TestRunner::SetPrinting() {
2586 layout_test_runtime_flags_.set_is_printing(true);
2587 OnLayoutTestRuntimeFlagsChanged();
2588 }
2589
2590 void TestRunner::ClearPrinting() {
2591 layout_test_runtime_flags_.set_is_printing(false);
2592 OnLayoutTestRuntimeFlagsChanged();
2593 }
2594
2595 void TestRunner::SetShouldStayOnPageAfterHandlingBeforeUnload(bool value) {
2596 layout_test_runtime_flags_.set_stay_on_page_after_handling_before_unload(
2597 value);
2598 OnLayoutTestRuntimeFlagsChanged();
2599 }
2600
2601 void TestRunner::SetWillSendRequestClearHeader(const std::string& header) {
2602 if (!header.empty())
2603 http_headers_to_clear_.insert(header);
2604 }
2605
2606 void TestRunner::SetUseMockTheme(bool use) {
2607 use_mock_theme_ = use;
2608 blink::setMockThemeEnabledForTest(use);
2609 }
2610
2611 void TestRunner::ShowWebInspector(const std::string& str,
2612 const std::string& frontend_url) {
2613 ShowDevTools(str, frontend_url);
2614 }
2615
2616 void TestRunner::WaitUntilExternalURLLoad() {
2617 layout_test_runtime_flags_.set_wait_until_external_url_load(true);
2618 OnLayoutTestRuntimeFlagsChanged();
2619 }
2620
2621 void TestRunner::DumpDragImage() {
2622 layout_test_runtime_flags_.set_dump_drag_image(true);
2623 DumpAsTextWithPixelResults();
2624 OnLayoutTestRuntimeFlagsChanged();
2625 }
2626
2627 void TestRunner::DumpNavigationPolicy() {
2628 layout_test_runtime_flags_.set_dump_navigation_policy(true);
2629 OnLayoutTestRuntimeFlagsChanged();
2630 }
2631
2632 void TestRunner::SetDumpConsoleMessages(bool value) {
2633 layout_test_runtime_flags_.set_dump_console_messages(value);
2634 OnLayoutTestRuntimeFlagsChanged();
2635 }
2636
2637 void TestRunner::SetDumpJavaScriptDialogs(bool value) {
2638 layout_test_runtime_flags_.set_dump_javascript_dialogs(value);
2639 OnLayoutTestRuntimeFlagsChanged();
2640 }
2641
2642 void TestRunner::SetEffectiveConnectionType(
2643 blink::WebEffectiveConnectionType connection_type) {
2644 effective_connection_type_ = connection_type;
2645 }
2646
2647 void TestRunner::SetMockSpellCheckerEnabled(bool enabled) {
2648 spellcheck_->SetEnabled(enabled);
2649 }
2650
2651 bool TestRunner::ShouldDumpConsoleMessages() const {
2652 return layout_test_runtime_flags_.dump_console_messages();
2653 }
2654
2655 bool TestRunner::ShouldDumpJavaScriptDialogs() const {
2656 return layout_test_runtime_flags_.dump_javascript_dialogs();
2657 }
2658
2659 void TestRunner::CloseWebInspector() {
2660 delegate_->CloseDevTools();
2661 }
2662
2663 bool TestRunner::IsChooserShown() {
2664 return 0 < chooser_count_;
2665 }
2666
2667 void TestRunner::EvaluateInWebInspector(int call_id,
2668 const std::string& script) {
2669 delegate_->EvaluateInWebInspector(call_id, script);
2670 }
2671
2672 std::string TestRunner::EvaluateInWebInspectorOverlay(
2673 const std::string& script) {
2674 return delegate_->EvaluateInWebInspectorOverlay(script);
2675 }
2676
2677 void TestRunner::ClearAllDatabases() {
2678 delegate_->ClearAllDatabases();
2679 }
2680
2681 void TestRunner::SetDatabaseQuota(int quota) {
2682 delegate_->SetDatabaseQuota(quota);
2683 }
2684
2685 void TestRunner::SetBlockThirdPartyCookies(bool block) {
2686 delegate_->SetBlockThirdPartyCookies(block);
2687 }
2688
2689 void TestRunner::SetFocus(blink::WebView* web_view, bool focus) {
2690 if (focus) {
2691 if (previously_focused_view_ != web_view) {
2692 delegate_->SetFocus(previously_focused_view_, false);
2693 delegate_->SetFocus(web_view, true);
2694 previously_focused_view_ = web_view;
2695 }
2696 } else {
2697 if (previously_focused_view_ == web_view) {
2698 delegate_->SetFocus(web_view, false);
2699 previously_focused_view_ = nullptr;
2700 }
2701 }
2702 }
2703
2704 std::string TestRunner::PathToLocalResource(const std::string& path) {
2705 return delegate_->PathToLocalResource(path);
2706 }
2707
2708 void TestRunner::SetPermission(const std::string& name,
2709 const std::string& value,
2710 const GURL& origin,
2711 const GURL& embedding_origin) {
2712 delegate_->SetPermission(name, value, origin, embedding_origin);
2713 }
2714
2715 void TestRunner::ResolveBeforeInstallPromptPromise(
2716 const std::string& platform) {
2717 delegate_->ResolveBeforeInstallPromptPromise(platform);
2718 }
2719
2720 void TestRunner::SetPOSIXLocale(const std::string& locale) {
2721 delegate_->SetLocale(locale);
2722 }
2723
2724 void TestRunner::SetMIDIAccessorResult(midi::mojom::Result result) {
2725 midi_accessor_result_ = result;
2726 }
2727
2728 void TestRunner::SimulateWebNotificationClick(
2729 const std::string& title,
2730 int action_index,
2731 const base::NullableString16& reply) {
2732 delegate_->SimulateWebNotificationClick(title, action_index, reply);
2733 }
2734
2735 void TestRunner::SimulateWebNotificationClose(const std::string& title,
2736 bool by_user) {
2737 delegate_->SimulateWebNotificationClose(title, by_user);
2738 }
2739
2740 void TestRunner::AddMockSpeechRecognitionResult(const std::string& transcript,
2741 double confidence) {
2742 getMockWebSpeechRecognizer()->AddMockResult(WebString::fromUTF8(transcript),
2743 confidence);
2744 }
2745
2746 void TestRunner::SetMockSpeechRecognitionError(const std::string& error,
2747 const std::string& message) {
2748 getMockWebSpeechRecognizer()->SetError(WebString::fromUTF8(error),
2749 WebString::fromUTF8(message));
2750 }
2751
2752 void TestRunner::SetMockCredentialManagerResponse(const std::string& id,
2753 const std::string& name,
2754 const std::string& avatar,
2755 const std::string& password) {
2756 credential_manager_client_->SetResponse(new WebPasswordCredential(
2757 WebString::fromUTF8(id), WebString::fromUTF8(password),
2758 WebString::fromUTF8(name), WebURL(GURL(avatar))));
2759 }
2760
2761 void TestRunner::ClearMockCredentialManagerResponse() {
2762 credential_manager_client_->SetResponse(nullptr);
2763 }
2764
2765 void TestRunner::SetMockCredentialManagerError(const std::string& error) {
2766 credential_manager_client_->SetError(error);
2767 }
2768
2769 void TestRunner::OnLayoutTestRuntimeFlagsChanged() {
2770 if (layout_test_runtime_flags_.tracked_dictionary().changed_values().empty())
2771 return;
2772 if (!test_is_running_)
2773 return;
2774
2775 delegate_->OnLayoutTestRuntimeFlagsChanged(
2776 layout_test_runtime_flags_.tracked_dictionary().changed_values());
2777 layout_test_runtime_flags_.tracked_dictionary().ResetChangeTracking();
2778 }
2779
2780 void TestRunner::LocationChangeDone() {
2781 web_history_item_count_ = delegate_->NavigationEntryCount();
2782
2783 // No more new work after the first complete load.
2784 work_queue_.set_frozen(true);
2785
2786 if (!layout_test_runtime_flags_.wait_until_done())
2787 work_queue_.ProcessWorkSoon();
2788 }
2789
2790 void TestRunner::CheckResponseMimeType() {
2791 // Text output: the test page can request different types of output which we
2792 // handle here.
2793
2794 if (layout_test_runtime_flags_.dump_as_text())
2795 return;
2796
2797 if (!main_view_)
2798 return;
2799
2800 WebDataSource* data_source = main_view_->mainFrame()->dataSource();
2801 if (!data_source)
2802 return;
2803
2804 std::string mimeType = data_source->response().mimeType().utf8();
2805 if (mimeType != "text/plain")
2806 return;
2807
2808 layout_test_runtime_flags_.set_dump_as_text(true);
2809 layout_test_runtime_flags_.set_generate_pixel_results(false);
2810 OnLayoutTestRuntimeFlagsChanged();
2811 }
2812
2813 void TestRunner::NotifyDone() {
2814 if (layout_test_runtime_flags_.wait_until_done() && !topLoadingFrame() &&
2815 !will_navigate_ && work_queue_.is_empty())
2816 delegate_->TestFinished();
2817 layout_test_runtime_flags_.set_wait_until_done(false);
2818 OnLayoutTestRuntimeFlagsChanged();
2819 }
2820
2821 } // namespace test_runner
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698