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

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

Issue 1931833003: Moving TestRunnerForSpecificView into a separate compilation unit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing... Created 4 years, 7 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/test_runner/test_runner.h" 5 #include "components/test_runner/test_runner_for_specific_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "components/test_runner/app_banner_client.h" 17 #include "components/test_runner/app_banner_client.h"
18 #include "components/test_runner/layout_and_paint_async_then.h" 18 #include "components/test_runner/layout_and_paint_async_then.h"
19 #include "components/test_runner/layout_dump.h" 19 #include "components/test_runner/layout_dump.h"
20 #include "components/test_runner/mock_content_settings_client.h" 20 #include "components/test_runner/mock_content_settings_client.h"
21 #include "components/test_runner/mock_credential_manager_client.h" 21 #include "components/test_runner/mock_credential_manager_client.h"
22 #include "components/test_runner/mock_screen_orientation_client.h" 22 #include "components/test_runner/mock_screen_orientation_client.h"
23 #include "components/test_runner/mock_web_speech_recognizer.h" 23 #include "components/test_runner/mock_web_speech_recognizer.h"
24 #include "components/test_runner/mock_web_user_media_client.h" 24 #include "components/test_runner/mock_web_user_media_client.h"
25 #include "components/test_runner/pixel_dump.h" 25 #include "components/test_runner/pixel_dump.h"
26 #include "components/test_runner/spell_check_client.h" 26 #include "components/test_runner/spell_check_client.h"
27 #include "components/test_runner/test_common.h"
27 #include "components/test_runner/test_interfaces.h" 28 #include "components/test_runner/test_interfaces.h"
28 #include "components/test_runner/test_preferences.h" 29 #include "components/test_runner/test_preferences.h"
30 #include "components/test_runner/test_runner.h"
29 #include "components/test_runner/web_task.h" 31 #include "components/test_runner/web_task.h"
30 #include "components/test_runner/web_test_delegate.h" 32 #include "components/test_runner/web_test_delegate.h"
31 #include "components/test_runner/web_test_proxy.h" 33 #include "components/test_runner/web_test_proxy.h"
32 #include "gin/arguments.h" 34 #include "gin/arguments.h"
33 #include "gin/array_buffer.h" 35 #include "gin/array_buffer.h"
34 #include "gin/handle.h" 36 #include "gin/handle.h"
35 #include "gin/object_template_builder.h" 37 #include "gin/object_template_builder.h"
36 #include "gin/wrappable.h" 38 #include "gin/wrappable.h"
37 #include "third_party/WebKit/public/platform/WebCanvas.h" 39 #include "third_party/WebKit/public/platform/WebCanvas.h"
38 #include "third_party/WebKit/public/platform/WebData.h" 40 #include "third_party/WebKit/public/platform/WebData.h"
(...skipping 28 matching lines...) Expand all
67 #include "ui/gfx/switches.h" 69 #include "ui/gfx/switches.h"
68 70
69 #if defined(__linux__) || defined(ANDROID) 71 #if defined(__linux__) || defined(ANDROID)
70 #include "third_party/WebKit/public/web/linux/WebFontRendering.h" 72 #include "third_party/WebKit/public/web/linux/WebFontRendering.h"
71 #endif 73 #endif
72 74
73 using namespace blink; 75 using namespace blink;
74 76
75 namespace test_runner { 77 namespace test_runner {
76 78
77 namespace { 79 TestRunnerForSpecificView::TestRunnerForSpecificView(
78 80 WebTestProxyBase* web_test_proxy_base)
79 WebString V8StringToWebString(v8::Local<v8::String> v8_str) { 81 : web_test_proxy_base_(web_test_proxy_base), weak_factory_(this) {
80 int length = v8_str->Utf8Length() + 1;
81 std::unique_ptr<char[]> chars(new char[length]);
82 v8_str->WriteUtf8(chars.get(), length);
83 return WebString::fromUTF8(chars.get());
84 }
85
86 double GetDefaultDeviceScaleFactor() {
87 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
88 if (command_line->HasSwitch(switches::kForceDeviceScaleFactor)) {
89 double scale;
90 std::string value =
91 command_line->GetSwitchValueASCII(switches::kForceDeviceScaleFactor);
92 if (base::StringToDouble(value, &scale))
93 return scale;
94 }
95 return 1.f;
96 }
97
98 } // namespace
99
100 class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
101 public:
102 static gin::WrapperInfo kWrapperInfo;
103
104 static void Install(base::WeakPtr<TestRunner> test_runner,
105 base::WeakPtr<TestRunnerForSpecificView> view_test_runner,
106 WebLocalFrame* frame);
107
108 private:
109 explicit TestRunnerBindings(
110 base::WeakPtr<TestRunner> test_runner,
111 base::WeakPtr<TestRunnerForSpecificView> view_test_runner);
112 ~TestRunnerBindings() override;
113
114 // gin::Wrappable:
115 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
116 v8::Isolate* isolate) override;
117
118 void AddMockSpeechRecognitionResult(const std::string& transcript,
119 double confidence);
120 void AddOriginAccessWhitelistEntry(const std::string& source_origin,
121 const std::string& destination_protocol,
122 const std::string& destination_host,
123 bool allow_destination_subdomains);
124 void AddWebPageOverlay();
125 void CapturePixelsAsyncThen(v8::Local<v8::Function> callback);
126 void ClearAllDatabases();
127 void ClearGeofencingMockProvider();
128 void ClearPrinting();
129 void CloseWebInspector();
130 void CopyImageAtAndCapturePixelsAsyncThen(int x,
131 int y,
132 v8::Local<v8::Function> callback);
133 void DidAcquirePointerLock();
134 void DidLosePointerLock();
135 void DidNotAcquirePointerLock();
136 void DisableMockScreenOrientation();
137 void DispatchBeforeInstallPromptEvent(
138 int request_id,
139 const std::vector<std::string>& event_platforms,
140 v8::Local<v8::Function> callback);
141 void DumpAsMarkup();
142 void DumpAsText();
143 void DumpAsTextWithPixelResults();
144 void DumpBackForwardList();
145 void DumpChildFrameScrollPositions();
146 void DumpChildFramesAsMarkup();
147 void DumpChildFramesAsText();
148 void DumpCreateView();
149 void DumpDragImage();
150 void DumpEditingCallbacks();
151 void DumpFrameLoadCallbacks();
152 void DumpIconChanges();
153 void DumpNavigationPolicy();
154 void DumpPageImportanceSignals();
155 void DumpPermissionClientCallbacks();
156 void DumpPingLoaderCallbacks();
157 void DumpResourceLoadCallbacks();
158 void DumpResourceRequestPriorities();
159 void DumpResourceResponseMIMETypes();
160 void DumpSelectionRect();
161 void DumpSpellCheckCallbacks();
162 void DumpTitleChanges();
163 void DumpUserGestureInFrameLoadCallbacks();
164 void DumpWindowStatusChanges();
165 void EnableUseZoomForDSF(v8::Local<v8::Function> callback);
166 void EvaluateInWebInspector(int call_id, const std::string& script);
167 void EvaluateScriptInIsolatedWorld(int world_id, const std::string& script);
168 void ExecCommand(gin::Arguments* args);
169 void ForceNextDrawingBufferCreationToFail();
170 void ForceNextWebGLContextCreationToFail();
171 void ForceRedSelectionColors();
172 void GetBluetoothManualChooserEvents(v8::Local<v8::Function> callback);
173 void GetManifestThen(v8::Local<v8::Function> callback);
174 void InsertStyleSheet(const std::string& source_code);
175 void LayoutAndPaintAsync();
176 void LayoutAndPaintAsyncThen(v8::Local<v8::Function> callback);
177 void LogToStderr(const std::string& output);
178 void NotImplemented(const gin::Arguments& args);
179 void NotifyDone();
180 void OverridePreference(const std::string& key, v8::Local<v8::Value> value);
181 void QueueBackNavigation(int how_far_back);
182 void QueueForwardNavigation(int how_far_forward);
183 void QueueLoad(gin::Arguments* args);
184 void QueueLoadingScript(const std::string& script);
185 void QueueNonLoadingScript(const std::string& script);
186 void QueueReload();
187 void RemoveOriginAccessWhitelistEntry(const std::string& source_origin,
188 const std::string& destination_protocol,
189 const std::string& destination_host,
190 bool allow_destination_subdomains);
191 void RemoveWebPageOverlay();
192 void ResetDeviceLight();
193 void ResetTestHelperControllers();
194 void ResolveBeforeInstallPromptPromise(int request_id,
195 const std::string& platform);
196 void RunIdleTasks(v8::Local<v8::Function> callback);
197 void SendBluetoothManualChooserEvent(const std::string& event,
198 const std::string& argument);
199 void SetAcceptLanguages(const std::string& accept_languages);
200 void SetAllowDisplayOfInsecureContent(bool allowed);
201 void SetAllowFileAccessFromFileURLs(bool allow);
202 void SetAllowRunningOfInsecureContent(bool allowed);
203 void SetAutoplayAllowed(bool allowed);
204 void SetAllowUniversalAccessFromFileURLs(bool allow);
205 void SetAlwaysAcceptCookies(bool accept);
206 void SetAudioData(const gin::ArrayBufferView& view);
207 void SetBackingScaleFactor(double value, v8::Local<v8::Function> callback);
208 void SetBluetoothFakeAdapter(const std::string& adapter_name,
209 v8::Local<v8::Function> callback);
210 void SetBluetoothManualChooser(bool enable);
211 void SetCanOpenWindows();
212 void SetCloseRemainingWindowsWhenComplete(gin::Arguments* args);
213 void SetColorProfile(const std::string& name,
214 v8::Local<v8::Function> callback);
215 void SetCustomPolicyDelegate(gin::Arguments* args);
216 void SetCustomTextOutput(const std::string& output);
217 void SetDatabaseQuota(int quota);
218 void SetDomainRelaxationForbiddenForURLScheme(bool forbidden,
219 const std::string& scheme);
220 void SetGeofencingMockPosition(double latitude, double longitude);
221 void SetGeofencingMockProvider(bool service_available);
222 void SetImagesAllowed(bool allowed);
223 void SetInterceptPostMessage(bool value);
224 void SetIsolatedWorldContentSecurityPolicy(int world_id,
225 const std::string& policy);
226 void SetIsolatedWorldSecurityOrigin(int world_id,
227 v8::Local<v8::Value> origin);
228 void SetJavaScriptCanAccessClipboard(bool can_access);
229 void SetMIDIAccessorResult(bool result);
230 void SetMediaAllowed(bool allowed);
231 void SetMockDeviceLight(double value);
232 void SetMockDeviceMotion(gin::Arguments* args);
233 void SetMockDeviceOrientation(gin::Arguments* args);
234 void SetMockScreenOrientation(const std::string& orientation);
235 void SetMockSpeechRecognitionError(const std::string& error,
236 const std::string& message);
237 void SetPOSIXLocale(const std::string& locale);
238 void SetPageVisibility(const std::string& new_visibility);
239 void SetPermission(const std::string& name,
240 const std::string& value,
241 const std::string& origin,
242 const std::string& embedding_origin);
243 void SetPluginsAllowed(bool allowed);
244 void SetPluginsEnabled(bool enabled);
245 void SetPointerLockWillFailSynchronously();
246 void SetPointerLockWillRespondAsynchronously();
247 void SetPopupBlockingEnabled(bool block_popups);
248 void SetPrinting();
249 void SetScriptsAllowed(bool allowed);
250 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
251 void SetStorageAllowed(bool allowed);
252 void SetTabKeyCyclesThroughElements(bool tab_key_cycles_through_elements);
253 void SetTextDirection(const std::string& direction_name);
254 void SetTextSubpixelPositioning(bool value);
255 void SetUseMockTheme(bool use);
256 void SetViewSourceForFrame(const std::string& name, bool enabled);
257 void SetWillSendRequestClearHeader(const std::string& header);
258 void SetWindowIsKey(bool value);
259 void SetXSSAuditorEnabled(bool enabled);
260 void ShowWebInspector(gin::Arguments* args);
261 void SimulateWebNotificationClick(const std::string& title, int action_index);
262 void SimulateWebNotificationClose(const std::string& title, bool by_user);
263 void UseUnfortunateSynchronousResizeMode();
264 void WaitForPolicyDelegate();
265 void WaitUntilDone();
266 void WaitUntilExternalURLLoad();
267 void AddMockCredentialManagerError(const std::string& error);
268 void AddMockCredentialManagerResponse(const std::string& id,
269 const std::string& name,
270 const std::string& avatar,
271 const std::string& password);
272 bool AnimationScheduled();
273 bool CallShouldCloseOnWebView();
274 bool DisableAutoResizeMode(int new_width, int new_height);
275 bool EnableAutoResizeMode(int min_width,
276 int min_height,
277 int max_width,
278 int max_height);
279 std::string EvaluateInWebInspectorOverlay(const std::string& script);
280 v8::Local<v8::Value> EvaluateScriptInIsolatedWorldAndReturnValue(
281 int world_id, const std::string& script);
282 bool FindString(const std::string& search_text,
283 const std::vector<std::string>& options_array);
284 bool HasCustomPageSizeStyle(int page_index);
285 bool InterceptPostMessage();
286 bool IsChooserShown();
287
288 bool IsCommandEnabled(const std::string& command);
289 std::string PathToLocalResource(const std::string& path);
290 std::string PlatformName();
291 std::string SelectionAsMarkup();
292 std::string TooltipText();
293
294 int WebHistoryItemCount();
295 int WindowCount();
296
297 base::WeakPtr<TestRunner> runner_;
298 base::WeakPtr<TestRunnerForSpecificView> view_runner_;
299
300 DISALLOW_COPY_AND_ASSIGN(TestRunnerBindings);
301 };
302
303 gin::WrapperInfo TestRunnerBindings::kWrapperInfo = {
304 gin::kEmbedderNativeGin};
305
306 // static
307 void TestRunnerBindings::Install(
308 base::WeakPtr<TestRunner> test_runner,
309 base::WeakPtr<TestRunnerForSpecificView> view_test_runner,
310 WebLocalFrame* frame) {
311 v8::Isolate* isolate = blink::mainThreadIsolate();
312 v8::HandleScope handle_scope(isolate);
313 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
314 if (context.IsEmpty())
315 return;
316
317 v8::Context::Scope context_scope(context);
318
319 TestRunnerBindings* wrapped =
320 new TestRunnerBindings(test_runner, view_test_runner);
321 gin::Handle<TestRunnerBindings> bindings =
322 gin::CreateHandle(isolate, wrapped);
323 if (bindings.IsEmpty())
324 return;
325 v8::Local<v8::Object> global = context->Global();
326 v8::Local<v8::Value> v8_bindings = bindings.ToV8();
327
328 std::vector<std::string> names;
329 names.push_back("testRunner");
330 names.push_back("layoutTestController");
331 for (size_t i = 0; i < names.size(); ++i)
332 global->Set(gin::StringToV8(isolate, names[i].c_str()), v8_bindings);
333 }
334
335 TestRunnerBindings::TestRunnerBindings(
336 base::WeakPtr<TestRunner> runner,
337 base::WeakPtr<TestRunnerForSpecificView> view_runner)
338 : runner_(runner), view_runner_(view_runner) {}
339
340 TestRunnerBindings::~TestRunnerBindings() {}
341
342 gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
343 v8::Isolate* isolate) {
344 return gin::Wrappable<TestRunnerBindings>::GetObjectTemplateBuilder(isolate)
345 .SetMethod("abortModal", &TestRunnerBindings::NotImplemented)
346 .SetMethod("addDisallowedURL", &TestRunnerBindings::NotImplemented)
347 .SetMethod("addMockCredentialManagerError",
348 &TestRunnerBindings::AddMockCredentialManagerError)
349 .SetMethod("addMockCredentialManagerResponse",
350 &TestRunnerBindings::AddMockCredentialManagerResponse)
351 .SetMethod("addMockSpeechRecognitionResult",
352 &TestRunnerBindings::AddMockSpeechRecognitionResult)
353 .SetMethod("addOriginAccessWhitelistEntry",
354 &TestRunnerBindings::AddOriginAccessWhitelistEntry)
355 .SetMethod("addWebPageOverlay", &TestRunnerBindings::AddWebPageOverlay)
356 .SetMethod("animationScheduled", &TestRunnerBindings::AnimationScheduled)
357 .SetMethod("callShouldCloseOnWebView",
358 &TestRunnerBindings::CallShouldCloseOnWebView)
359 .SetMethod("capturePixelsAsyncThen",
360 &TestRunnerBindings::CapturePixelsAsyncThen)
361 .SetMethod("clearAllDatabases", &TestRunnerBindings::ClearAllDatabases)
362 .SetMethod("clearBackForwardList", &TestRunnerBindings::NotImplemented)
363 .SetMethod("clearGeofencingMockProvider",
364 &TestRunnerBindings::ClearGeofencingMockProvider)
365 .SetMethod("clearPrinting", &TestRunnerBindings::ClearPrinting)
366 .SetMethod("closeWebInspector", &TestRunnerBindings::CloseWebInspector)
367 .SetMethod("copyImageAtAndCapturePixelsAsyncThen",
368 &TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen)
369 .SetMethod("didAcquirePointerLock",
370 &TestRunnerBindings::DidAcquirePointerLock)
371 .SetMethod("didLosePointerLock", &TestRunnerBindings::DidLosePointerLock)
372 .SetMethod("didNotAcquirePointerLock",
373 &TestRunnerBindings::DidNotAcquirePointerLock)
374 .SetMethod("disableAutoResizeMode",
375 &TestRunnerBindings::DisableAutoResizeMode)
376 .SetMethod("disableMockScreenOrientation",
377 &TestRunnerBindings::DisableMockScreenOrientation)
378 .SetMethod("dispatchBeforeInstallPromptEvent",
379 &TestRunnerBindings::DispatchBeforeInstallPromptEvent)
380 .SetMethod("dumpAsMarkup", &TestRunnerBindings::DumpAsMarkup)
381 .SetMethod("dumpAsText", &TestRunnerBindings::DumpAsText)
382 .SetMethod("dumpAsTextWithPixelResults",
383 &TestRunnerBindings::DumpAsTextWithPixelResults)
384 .SetMethod("dumpBackForwardList",
385 &TestRunnerBindings::DumpBackForwardList)
386 .SetMethod("dumpChildFrameScrollPositions",
387 &TestRunnerBindings::DumpChildFrameScrollPositions)
388 .SetMethod("dumpChildFramesAsMarkup",
389 &TestRunnerBindings::DumpChildFramesAsMarkup)
390 .SetMethod("dumpChildFramesAsText",
391 &TestRunnerBindings::DumpChildFramesAsText)
392 .SetMethod("dumpCreateView", &TestRunnerBindings::DumpCreateView)
393 .SetMethod("dumpDatabaseCallbacks", &TestRunnerBindings::NotImplemented)
394 .SetMethod("dumpDragImage", &TestRunnerBindings::DumpDragImage)
395 .SetMethod("dumpEditingCallbacks",
396 &TestRunnerBindings::DumpEditingCallbacks)
397 .SetMethod("dumpFrameLoadCallbacks",
398 &TestRunnerBindings::DumpFrameLoadCallbacks)
399 .SetMethod("dumpIconChanges", &TestRunnerBindings::DumpIconChanges)
400 .SetMethod("dumpNavigationPolicy",
401 &TestRunnerBindings::DumpNavigationPolicy)
402 .SetMethod("dumpPageImportanceSignals",
403 &TestRunnerBindings::DumpPageImportanceSignals)
404 .SetMethod("dumpPermissionClientCallbacks",
405 &TestRunnerBindings::DumpPermissionClientCallbacks)
406 .SetMethod("dumpPingLoaderCallbacks",
407 &TestRunnerBindings::DumpPingLoaderCallbacks)
408 .SetMethod("dumpResourceLoadCallbacks",
409 &TestRunnerBindings::DumpResourceLoadCallbacks)
410 .SetMethod("dumpResourceRequestPriorities",
411 &TestRunnerBindings::DumpResourceRequestPriorities)
412 .SetMethod("dumpResourceResponseMIMETypes",
413 &TestRunnerBindings::DumpResourceResponseMIMETypes)
414 .SetMethod("dumpSelectionRect", &TestRunnerBindings::DumpSelectionRect)
415 .SetMethod("dumpSpellCheckCallbacks",
416 &TestRunnerBindings::DumpSpellCheckCallbacks)
417
418 // Used at fast/dom/assign-to-window-status.html
419 .SetMethod("dumpStatusCallbacks",
420 &TestRunnerBindings::DumpWindowStatusChanges)
421 .SetMethod("dumpTitleChanges", &TestRunnerBindings::DumpTitleChanges)
422 .SetMethod("dumpUserGestureInFrameLoadCallbacks",
423 &TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks)
424 .SetMethod("enableAutoResizeMode",
425 &TestRunnerBindings::EnableAutoResizeMode)
426 .SetMethod("enableUseZoomForDSF",
427 &TestRunnerBindings::EnableUseZoomForDSF)
428 .SetMethod("evaluateInWebInspector",
429 &TestRunnerBindings::EvaluateInWebInspector)
430 .SetMethod("evaluateInWebInspectorOverlay",
431 &TestRunnerBindings::EvaluateInWebInspectorOverlay)
432 .SetMethod("evaluateScriptInIsolatedWorld",
433 &TestRunnerBindings::EvaluateScriptInIsolatedWorld)
434 .SetMethod(
435 "evaluateScriptInIsolatedWorldAndReturnValue",
436 &TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue)
437 .SetMethod("execCommand", &TestRunnerBindings::ExecCommand)
438 .SetMethod("findString", &TestRunnerBindings::FindString)
439 .SetMethod("forceNextDrawingBufferCreationToFail",
440 &TestRunnerBindings::ForceNextDrawingBufferCreationToFail)
441 .SetMethod("forceNextWebGLContextCreationToFail",
442 &TestRunnerBindings::ForceNextWebGLContextCreationToFail)
443 .SetMethod("forceRedSelectionColors",
444 &TestRunnerBindings::ForceRedSelectionColors)
445
446 // The Bluetooth functions are specified at
447 // https://webbluetoothcg.github.io/web-bluetooth/tests/.
448 .SetMethod("getBluetoothManualChooserEvents",
449 &TestRunnerBindings::GetBluetoothManualChooserEvents)
450 .SetMethod("getManifestThen", &TestRunnerBindings::GetManifestThen)
451 .SetMethod("hasCustomPageSizeStyle",
452 &TestRunnerBindings::HasCustomPageSizeStyle)
453 .SetMethod("insertStyleSheet", &TestRunnerBindings::InsertStyleSheet)
454 .SetProperty("interceptPostMessage",
455 &TestRunnerBindings::InterceptPostMessage,
456 &TestRunnerBindings::SetInterceptPostMessage)
457 .SetMethod("isChooserShown", &TestRunnerBindings::IsChooserShown)
458 .SetMethod("isCommandEnabled", &TestRunnerBindings::IsCommandEnabled)
459 .SetMethod("keepWebHistory", &TestRunnerBindings::NotImplemented)
460 .SetMethod("layoutAndPaintAsync",
461 &TestRunnerBindings::LayoutAndPaintAsync)
462 .SetMethod("layoutAndPaintAsyncThen",
463 &TestRunnerBindings::LayoutAndPaintAsyncThen)
464 .SetMethod("logToStderr", &TestRunnerBindings::LogToStderr)
465 .SetMethod("notifyDone", &TestRunnerBindings::NotifyDone)
466 .SetMethod("overridePreference", &TestRunnerBindings::OverridePreference)
467 .SetMethod("pathToLocalResource",
468 &TestRunnerBindings::PathToLocalResource)
469 .SetProperty("platformName", &TestRunnerBindings::PlatformName)
470 .SetMethod("queueBackNavigation",
471 &TestRunnerBindings::QueueBackNavigation)
472 .SetMethod("queueForwardNavigation",
473 &TestRunnerBindings::QueueForwardNavigation)
474 .SetMethod("queueLoad", &TestRunnerBindings::QueueLoad)
475 .SetMethod("queueLoadingScript", &TestRunnerBindings::QueueLoadingScript)
476 .SetMethod("queueNonLoadingScript",
477 &TestRunnerBindings::QueueNonLoadingScript)
478 .SetMethod("queueReload", &TestRunnerBindings::QueueReload)
479 .SetMethod("removeOriginAccessWhitelistEntry",
480 &TestRunnerBindings::RemoveOriginAccessWhitelistEntry)
481 .SetMethod("removeWebPageOverlay",
482 &TestRunnerBindings::RemoveWebPageOverlay)
483 .SetMethod("resetDeviceLight", &TestRunnerBindings::ResetDeviceLight)
484 .SetMethod("resetTestHelperControllers",
485 &TestRunnerBindings::ResetTestHelperControllers)
486 .SetMethod("resolveBeforeInstallPromptPromise",
487 &TestRunnerBindings::ResolveBeforeInstallPromptPromise)
488 .SetMethod("runIdleTasks",
489 &TestRunnerBindings::RunIdleTasks)
490 .SetMethod("selectionAsMarkup", &TestRunnerBindings::SelectionAsMarkup)
491
492 // The Bluetooth functions are specified at
493 // https://webbluetoothcg.github.io/web-bluetooth/tests/.
494 .SetMethod("sendBluetoothManualChooserEvent",
495 &TestRunnerBindings::SendBluetoothManualChooserEvent)
496 .SetMethod("setAcceptLanguages", &TestRunnerBindings::SetAcceptLanguages)
497 .SetMethod("setAllowDisplayOfInsecureContent",
498 &TestRunnerBindings::SetAllowDisplayOfInsecureContent)
499 .SetMethod("setAllowFileAccessFromFileURLs",
500 &TestRunnerBindings::SetAllowFileAccessFromFileURLs)
501 .SetMethod("setAllowRunningOfInsecureContent",
502 &TestRunnerBindings::SetAllowRunningOfInsecureContent)
503 .SetMethod("setAutoplayAllowed",
504 &TestRunnerBindings::SetAutoplayAllowed)
505 .SetMethod("setAllowUniversalAccessFromFileURLs",
506 &TestRunnerBindings::SetAllowUniversalAccessFromFileURLs)
507 .SetMethod("setAlwaysAcceptCookies",
508 &TestRunnerBindings::SetAlwaysAcceptCookies)
509 .SetMethod("setAudioData", &TestRunnerBindings::SetAudioData)
510 .SetMethod("setBackingScaleFactor",
511 &TestRunnerBindings::SetBackingScaleFactor)
512 // The Bluetooth functions are specified at
513 // https://webbluetoothcg.github.io/web-bluetooth/tests/.
514 .SetMethod("setBluetoothFakeAdapter",
515 &TestRunnerBindings::SetBluetoothFakeAdapter)
516 .SetMethod("setBluetoothManualChooser",
517 &TestRunnerBindings::SetBluetoothManualChooser)
518 .SetMethod("setCallCloseOnWebViews", &TestRunnerBindings::NotImplemented)
519 .SetMethod("setCanOpenWindows", &TestRunnerBindings::SetCanOpenWindows)
520 .SetMethod("setCloseRemainingWindowsWhenComplete",
521 &TestRunnerBindings::SetCloseRemainingWindowsWhenComplete)
522 .SetMethod("setColorProfile", &TestRunnerBindings::SetColorProfile)
523 .SetMethod("setCustomPolicyDelegate",
524 &TestRunnerBindings::SetCustomPolicyDelegate)
525 .SetMethod("setCustomTextOutput",
526 &TestRunnerBindings::SetCustomTextOutput)
527 .SetMethod("setDatabaseQuota", &TestRunnerBindings::SetDatabaseQuota)
528 .SetMethod("setDomainRelaxationForbiddenForURLScheme",
529 &TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme)
530 .SetMethod("setGeofencingMockPosition",
531 &TestRunnerBindings::SetGeofencingMockPosition)
532 .SetMethod("setGeofencingMockProvider",
533 &TestRunnerBindings::SetGeofencingMockProvider)
534 .SetMethod("setIconDatabaseEnabled", &TestRunnerBindings::NotImplemented)
535 .SetMethod("setImagesAllowed", &TestRunnerBindings::SetImagesAllowed)
536 .SetMethod("setIsolatedWorldContentSecurityPolicy",
537 &TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy)
538 .SetMethod("setIsolatedWorldSecurityOrigin",
539 &TestRunnerBindings::SetIsolatedWorldSecurityOrigin)
540 .SetMethod("setJavaScriptCanAccessClipboard",
541 &TestRunnerBindings::SetJavaScriptCanAccessClipboard)
542 .SetMethod("setMIDIAccessorResult",
543 &TestRunnerBindings::SetMIDIAccessorResult)
544 .SetMethod("setMainFrameIsFirstResponder",
545 &TestRunnerBindings::NotImplemented)
546 .SetMethod("setMediaAllowed", &TestRunnerBindings::SetMediaAllowed)
547 .SetMethod("setMockDeviceLight", &TestRunnerBindings::SetMockDeviceLight)
548 .SetMethod("setMockDeviceMotion",
549 &TestRunnerBindings::SetMockDeviceMotion)
550 .SetMethod("setMockDeviceOrientation",
551 &TestRunnerBindings::SetMockDeviceOrientation)
552 .SetMethod("setMockScreenOrientation",
553 &TestRunnerBindings::SetMockScreenOrientation)
554 .SetMethod("setMockSpeechRecognitionError",
555 &TestRunnerBindings::SetMockSpeechRecognitionError)
556 .SetMethod("setPOSIXLocale", &TestRunnerBindings::SetPOSIXLocale)
557 .SetMethod("setPageVisibility", &TestRunnerBindings::SetPageVisibility)
558 .SetMethod("setPermission", &TestRunnerBindings::SetPermission)
559 .SetMethod("setPluginsAllowed", &TestRunnerBindings::SetPluginsAllowed)
560 .SetMethod("setPluginsEnabled", &TestRunnerBindings::SetPluginsEnabled)
561 .SetMethod("setPointerLockWillFailSynchronously",
562 &TestRunnerBindings::SetPointerLockWillFailSynchronously)
563 .SetMethod("setPointerLockWillRespondAsynchronously",
564 &TestRunnerBindings::SetPointerLockWillRespondAsynchronously)
565 .SetMethod("setPopupBlockingEnabled",
566 &TestRunnerBindings::SetPopupBlockingEnabled)
567 .SetMethod("setPrinting", &TestRunnerBindings::SetPrinting)
568 .SetMethod("setScriptsAllowed", &TestRunnerBindings::SetScriptsAllowed)
569 .SetMethod("setScrollbarPolicy", &TestRunnerBindings::NotImplemented)
570 .SetMethod(
571 "setShouldStayOnPageAfterHandlingBeforeUnload",
572 &TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload)
573 .SetMethod("setStorageAllowed", &TestRunnerBindings::SetStorageAllowed)
574 .SetMethod("setTabKeyCyclesThroughElements",
575 &TestRunnerBindings::SetTabKeyCyclesThroughElements)
576 .SetMethod("setTextDirection", &TestRunnerBindings::SetTextDirection)
577 .SetMethod("setTextSubpixelPositioning",
578 &TestRunnerBindings::SetTextSubpixelPositioning)
579 .SetMethod("setUseDashboardCompatibilityMode",
580 &TestRunnerBindings::NotImplemented)
581 .SetMethod("setUseMockTheme", &TestRunnerBindings::SetUseMockTheme)
582 .SetMethod("setViewSourceForFrame",
583 &TestRunnerBindings::SetViewSourceForFrame)
584 .SetMethod("setWillSendRequestClearHeader",
585 &TestRunnerBindings::SetWillSendRequestClearHeader)
586 .SetMethod("setWindowIsKey", &TestRunnerBindings::SetWindowIsKey)
587 .SetMethod("setXSSAuditorEnabled",
588 &TestRunnerBindings::SetXSSAuditorEnabled)
589 .SetMethod("showWebInspector", &TestRunnerBindings::ShowWebInspector)
590 .SetMethod("simulateWebNotificationClick",
591 &TestRunnerBindings::SimulateWebNotificationClick)
592 .SetMethod("simulateWebNotificationClose",
593 &TestRunnerBindings::SimulateWebNotificationClose)
594 .SetProperty("tooltipText", &TestRunnerBindings::TooltipText)
595 .SetMethod("useUnfortunateSynchronousResizeMode",
596 &TestRunnerBindings::UseUnfortunateSynchronousResizeMode)
597 .SetMethod("waitForPolicyDelegate",
598 &TestRunnerBindings::WaitForPolicyDelegate)
599 .SetMethod("waitUntilDone", &TestRunnerBindings::WaitUntilDone)
600 .SetMethod("waitUntilExternalURLLoad",
601 &TestRunnerBindings::WaitUntilExternalURLLoad)
602
603 // webHistoryItemCount is used by tests in LayoutTests\http\tests\history
604 .SetProperty("webHistoryItemCount",
605 &TestRunnerBindings::WebHistoryItemCount)
606 .SetMethod("windowCount", &TestRunnerBindings::WindowCount);
607 }
608
609 void TestRunnerBindings::LogToStderr(const std::string& output) {
610 LOG(ERROR) << output;
611 }
612
613 void TestRunnerBindings::NotifyDone() {
614 if (runner_)
615 runner_->NotifyDone();
616 }
617
618 void TestRunnerBindings::WaitUntilDone() {
619 if (runner_)
620 runner_->WaitUntilDone();
621 }
622
623 void TestRunnerBindings::QueueBackNavigation(int how_far_back) {
624 if (runner_)
625 runner_->QueueBackNavigation(how_far_back);
626 }
627
628 void TestRunnerBindings::QueueForwardNavigation(int how_far_forward) {
629 if (runner_)
630 runner_->QueueForwardNavigation(how_far_forward);
631 }
632
633 void TestRunnerBindings::QueueReload() {
634 if (runner_)
635 runner_->QueueReload();
636 }
637
638 void TestRunnerBindings::QueueLoadingScript(const std::string& script) {
639 if (runner_)
640 runner_->QueueLoadingScript(script);
641 }
642
643 void TestRunnerBindings::QueueNonLoadingScript(const std::string& script) {
644 if (runner_)
645 runner_->QueueNonLoadingScript(script);
646 }
647
648 void TestRunnerBindings::QueueLoad(gin::Arguments* args) {
649 if (runner_) {
650 std::string url;
651 std::string target;
652 args->GetNext(&url);
653 args->GetNext(&target);
654 runner_->QueueLoad(url, target);
655 }
656 }
657
658 void TestRunnerBindings::SetCustomPolicyDelegate(gin::Arguments* args) {
659 if (runner_)
660 runner_->SetCustomPolicyDelegate(args);
661 }
662
663 void TestRunnerBindings::WaitForPolicyDelegate() {
664 if (runner_)
665 runner_->WaitForPolicyDelegate();
666 }
667
668 int TestRunnerBindings::WindowCount() {
669 if (runner_)
670 return runner_->WindowCount();
671 return 0;
672 }
673
674 void TestRunnerBindings::SetCloseRemainingWindowsWhenComplete(
675 gin::Arguments* args) {
676 if (!runner_)
677 return;
678
679 // In the original implementation, nothing happens if the argument is
680 // ommitted.
681 bool close_remaining_windows = false;
682 if (args->GetNext(&close_remaining_windows))
683 runner_->SetCloseRemainingWindowsWhenComplete(close_remaining_windows);
684 }
685
686 void TestRunnerBindings::ResetTestHelperControllers() {
687 if (runner_)
688 runner_->ResetTestHelperControllers();
689 }
690
691 void TestRunnerBindings::SetTabKeyCyclesThroughElements(
692 bool tab_key_cycles_through_elements) {
693 if (view_runner_)
694 view_runner_->SetTabKeyCyclesThroughElements(
695 tab_key_cycles_through_elements);
696 }
697
698 void TestRunnerBindings::ExecCommand(gin::Arguments* args) {
699 if (view_runner_)
700 view_runner_->ExecCommand(args);
701 }
702
703 bool TestRunnerBindings::IsCommandEnabled(const std::string& command) {
704 if (view_runner_)
705 return view_runner_->IsCommandEnabled(command);
706 return false;
707 }
708
709 bool TestRunnerBindings::CallShouldCloseOnWebView() {
710 if (view_runner_)
711 return view_runner_->CallShouldCloseOnWebView();
712 return false;
713 }
714
715 void TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme(
716 bool forbidden, const std::string& scheme) {
717 if (view_runner_)
718 view_runner_->SetDomainRelaxationForbiddenForURLScheme(forbidden, scheme);
719 }
720
721 v8::Local<v8::Value>
722 TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue(
723 int world_id, const std::string& script) {
724 if (!view_runner_ || world_id <= 0 || world_id >= (1 << 29))
725 return v8::Local<v8::Value>();
726 return view_runner_->EvaluateScriptInIsolatedWorldAndReturnValue(world_id,
727 script);
728 }
729
730 void TestRunnerBindings::EvaluateScriptInIsolatedWorld(
731 int world_id, const std::string& script) {
732 if (view_runner_ && world_id > 0 && world_id < (1 << 29))
733 view_runner_->EvaluateScriptInIsolatedWorld(world_id, script);
734 }
735
736 void TestRunnerBindings::SetIsolatedWorldSecurityOrigin(
737 int world_id, v8::Local<v8::Value> origin) {
738 if (view_runner_)
739 view_runner_->SetIsolatedWorldSecurityOrigin(world_id, origin);
740 }
741
742 void TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy(
743 int world_id, const std::string& policy) {
744 if (view_runner_)
745 view_runner_->SetIsolatedWorldContentSecurityPolicy(world_id, policy);
746 }
747
748 void TestRunnerBindings::AddOriginAccessWhitelistEntry(
749 const std::string& source_origin,
750 const std::string& destination_protocol,
751 const std::string& destination_host,
752 bool allow_destination_subdomains) {
753 if (runner_) {
754 runner_->AddOriginAccessWhitelistEntry(source_origin,
755 destination_protocol,
756 destination_host,
757 allow_destination_subdomains);
758 }
759 }
760
761 void TestRunnerBindings::RemoveOriginAccessWhitelistEntry(
762 const std::string& source_origin,
763 const std::string& destination_protocol,
764 const std::string& destination_host,
765 bool allow_destination_subdomains) {
766 if (runner_) {
767 runner_->RemoveOriginAccessWhitelistEntry(source_origin,
768 destination_protocol,
769 destination_host,
770 allow_destination_subdomains);
771 }
772 }
773
774 bool TestRunnerBindings::HasCustomPageSizeStyle(int page_index) {
775 if (view_runner_)
776 return view_runner_->HasCustomPageSizeStyle(page_index);
777 return false;
778 }
779
780 void TestRunnerBindings::ForceRedSelectionColors() {
781 if (view_runner_)
782 view_runner_->ForceRedSelectionColors();
783 }
784
785 void TestRunnerBindings::InsertStyleSheet(const std::string& source_code) {
786 if (runner_)
787 runner_->InsertStyleSheet(source_code);
788 }
789
790 bool TestRunnerBindings::FindString(
791 const std::string& search_text,
792 const std::vector<std::string>& options_array) {
793 if (view_runner_)
794 return view_runner_->FindString(search_text, options_array);
795 return false;
796 }
797
798 std::string TestRunnerBindings::SelectionAsMarkup() {
799 if (view_runner_)
800 return view_runner_->SelectionAsMarkup();
801 return std::string();
802 }
803
804 void TestRunnerBindings::SetTextSubpixelPositioning(bool value) {
805 if (runner_)
806 runner_->SetTextSubpixelPositioning(value);
807 }
808
809 void TestRunnerBindings::SetPageVisibility(const std::string& new_visibility) {
810 if (view_runner_)
811 view_runner_->SetPageVisibility(new_visibility);
812 }
813
814 void TestRunnerBindings::SetTextDirection(const std::string& direction_name) {
815 if (view_runner_)
816 view_runner_->SetTextDirection(direction_name);
817 }
818
819 void TestRunnerBindings::UseUnfortunateSynchronousResizeMode() {
820 if (runner_)
821 runner_->UseUnfortunateSynchronousResizeMode();
822 }
823
824 bool TestRunnerBindings::EnableAutoResizeMode(int min_width,
825 int min_height,
826 int max_width,
827 int max_height) {
828 if (runner_) {
829 return runner_->EnableAutoResizeMode(min_width, min_height,
830 max_width, max_height);
831 }
832 return false;
833 }
834
835 bool TestRunnerBindings::DisableAutoResizeMode(int new_width, int new_height) {
836 if (runner_)
837 return runner_->DisableAutoResizeMode(new_width, new_height);
838 return false;
839 }
840
841 void TestRunnerBindings::SetMockDeviceLight(double value) {
842 if (!runner_)
843 return;
844 runner_->SetMockDeviceLight(value);
845 }
846
847 void TestRunnerBindings::ResetDeviceLight() {
848 if (runner_)
849 runner_->ResetDeviceLight();
850 }
851
852 void TestRunnerBindings::SetMockDeviceMotion(gin::Arguments* args) {
853 if (!runner_)
854 return;
855
856 bool has_acceleration_x;
857 double acceleration_x;
858 bool has_acceleration_y;
859 double acceleration_y;
860 bool has_acceleration_z;
861 double acceleration_z;
862 bool has_acceleration_including_gravity_x;
863 double acceleration_including_gravity_x;
864 bool has_acceleration_including_gravity_y;
865 double acceleration_including_gravity_y;
866 bool has_acceleration_including_gravity_z;
867 double acceleration_including_gravity_z;
868 bool has_rotation_rate_alpha;
869 double rotation_rate_alpha;
870 bool has_rotation_rate_beta;
871 double rotation_rate_beta;
872 bool has_rotation_rate_gamma;
873 double rotation_rate_gamma;
874 double interval;
875
876 args->GetNext(&has_acceleration_x);
877 args->GetNext(& acceleration_x);
878 args->GetNext(&has_acceleration_y);
879 args->GetNext(& acceleration_y);
880 args->GetNext(&has_acceleration_z);
881 args->GetNext(& acceleration_z);
882 args->GetNext(&has_acceleration_including_gravity_x);
883 args->GetNext(& acceleration_including_gravity_x);
884 args->GetNext(&has_acceleration_including_gravity_y);
885 args->GetNext(& acceleration_including_gravity_y);
886 args->GetNext(&has_acceleration_including_gravity_z);
887 args->GetNext(& acceleration_including_gravity_z);
888 args->GetNext(&has_rotation_rate_alpha);
889 args->GetNext(& rotation_rate_alpha);
890 args->GetNext(&has_rotation_rate_beta);
891 args->GetNext(& rotation_rate_beta);
892 args->GetNext(&has_rotation_rate_gamma);
893 args->GetNext(& rotation_rate_gamma);
894 args->GetNext(& interval);
895
896 runner_->SetMockDeviceMotion(has_acceleration_x, acceleration_x,
897 has_acceleration_y, acceleration_y,
898 has_acceleration_z, acceleration_z,
899 has_acceleration_including_gravity_x,
900 acceleration_including_gravity_x,
901 has_acceleration_including_gravity_y,
902 acceleration_including_gravity_y,
903 has_acceleration_including_gravity_z,
904 acceleration_including_gravity_z,
905 has_rotation_rate_alpha,
906 rotation_rate_alpha,
907 has_rotation_rate_beta,
908 rotation_rate_beta,
909 has_rotation_rate_gamma,
910 rotation_rate_gamma,
911 interval);
912 }
913
914 void TestRunnerBindings::SetMockDeviceOrientation(gin::Arguments* args) {
915 if (!runner_)
916 return;
917
918 bool has_alpha = false;
919 double alpha = 0.0;
920 bool has_beta = false;
921 double beta = 0.0;
922 bool has_gamma = false;
923 double gamma = 0.0;
924 bool absolute = false;
925
926 args->GetNext(&has_alpha);
927 args->GetNext(&alpha);
928 args->GetNext(&has_beta);
929 args->GetNext(&beta);
930 args->GetNext(&has_gamma);
931 args->GetNext(&gamma);
932 args->GetNext(&absolute);
933
934 runner_->SetMockDeviceOrientation(has_alpha, alpha,
935 has_beta, beta,
936 has_gamma, gamma,
937 absolute);
938 }
939
940 void TestRunnerBindings::SetMockScreenOrientation(
941 const std::string& orientation) {
942 if (!runner_)
943 return;
944
945 runner_->SetMockScreenOrientation(orientation);
946 }
947
948 void TestRunnerBindings::DisableMockScreenOrientation() {
949 if (runner_)
950 runner_->DisableMockScreenOrientation();
951 }
952
953 void TestRunnerBindings::DidAcquirePointerLock() {
954 if (view_runner_)
955 view_runner_->DidAcquirePointerLock();
956 }
957
958 void TestRunnerBindings::DidNotAcquirePointerLock() {
959 if (view_runner_)
960 view_runner_->DidNotAcquirePointerLock();
961 }
962
963 void TestRunnerBindings::DidLosePointerLock() {
964 if (view_runner_)
965 view_runner_->DidLosePointerLock();
966 }
967
968 void TestRunnerBindings::SetPointerLockWillFailSynchronously() {
969 if (view_runner_)
970 view_runner_->SetPointerLockWillFailSynchronously();
971 }
972
973 void TestRunnerBindings::SetPointerLockWillRespondAsynchronously() {
974 if (view_runner_)
975 view_runner_->SetPointerLockWillRespondAsynchronously();
976 }
977
978 void TestRunnerBindings::SetPopupBlockingEnabled(bool block_popups) {
979 if (runner_)
980 runner_->SetPopupBlockingEnabled(block_popups);
981 }
982
983 void TestRunnerBindings::SetJavaScriptCanAccessClipboard(bool can_access) {
984 if (runner_)
985 runner_->SetJavaScriptCanAccessClipboard(can_access);
986 }
987
988 void TestRunnerBindings::SetXSSAuditorEnabled(bool enabled) {
989 if (runner_)
990 runner_->SetXSSAuditorEnabled(enabled);
991 }
992
993 void TestRunnerBindings::SetAllowUniversalAccessFromFileURLs(bool allow) {
994 if (runner_)
995 runner_->SetAllowUniversalAccessFromFileURLs(allow);
996 }
997
998 void TestRunnerBindings::SetAllowFileAccessFromFileURLs(bool allow) {
999 if (runner_)
1000 runner_->SetAllowFileAccessFromFileURLs(allow);
1001 }
1002
1003 void TestRunnerBindings::OverridePreference(const std::string& key,
1004 v8::Local<v8::Value> value) {
1005 if (runner_)
1006 runner_->OverridePreference(key, value);
1007 }
1008
1009 void TestRunnerBindings::SetAcceptLanguages(
1010 const std::string& accept_languages) {
1011 if (!runner_)
1012 return;
1013
1014 runner_->SetAcceptLanguages(accept_languages);
1015 }
1016
1017 void TestRunnerBindings::SetPluginsEnabled(bool enabled) {
1018 if (runner_)
1019 runner_->SetPluginsEnabled(enabled);
1020 }
1021
1022 bool TestRunnerBindings::AnimationScheduled() {
1023 if (runner_)
1024 return runner_->GetAnimationScheduled();
1025 else
1026 return false;
1027 }
1028
1029 void TestRunnerBindings::DumpEditingCallbacks() {
1030 if (runner_)
1031 runner_->DumpEditingCallbacks();
1032 }
1033
1034 void TestRunnerBindings::DumpAsMarkup() {
1035 if (runner_)
1036 runner_->DumpAsMarkup();
1037 }
1038
1039 void TestRunnerBindings::DumpAsText() {
1040 if (runner_)
1041 runner_->DumpAsText();
1042 }
1043
1044 void TestRunnerBindings::DumpAsTextWithPixelResults() {
1045 if (runner_)
1046 runner_->DumpAsTextWithPixelResults();
1047 }
1048
1049 void TestRunnerBindings::DumpChildFrameScrollPositions() {
1050 if (runner_)
1051 runner_->DumpChildFrameScrollPositions();
1052 }
1053
1054 void TestRunnerBindings::DumpChildFramesAsText() {
1055 if (runner_)
1056 runner_->DumpChildFramesAsText();
1057 }
1058
1059 void TestRunnerBindings::DumpChildFramesAsMarkup() {
1060 if (runner_)
1061 runner_->DumpChildFramesAsMarkup();
1062 }
1063
1064 void TestRunnerBindings::DumpIconChanges() {
1065 if (runner_)
1066 runner_->DumpIconChanges();
1067 }
1068
1069 void TestRunnerBindings::SetAudioData(const gin::ArrayBufferView& view) {
1070 if (runner_)
1071 runner_->SetAudioData(view);
1072 }
1073
1074 void TestRunnerBindings::DumpFrameLoadCallbacks() {
1075 if (runner_)
1076 runner_->DumpFrameLoadCallbacks();
1077 }
1078
1079 void TestRunnerBindings::DumpPingLoaderCallbacks() {
1080 if (runner_)
1081 runner_->DumpPingLoaderCallbacks();
1082 }
1083
1084 void TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks() {
1085 if (runner_)
1086 runner_->DumpUserGestureInFrameLoadCallbacks();
1087 }
1088
1089 void TestRunnerBindings::DumpTitleChanges() {
1090 if (runner_)
1091 runner_->DumpTitleChanges();
1092 }
1093
1094 void TestRunnerBindings::DumpCreateView() {
1095 if (runner_)
1096 runner_->DumpCreateView();
1097 }
1098
1099 void TestRunnerBindings::SetCanOpenWindows() {
1100 if (runner_)
1101 runner_->SetCanOpenWindows();
1102 }
1103
1104 void TestRunnerBindings::DumpResourceLoadCallbacks() {
1105 if (runner_)
1106 runner_->DumpResourceLoadCallbacks();
1107 }
1108
1109 void TestRunnerBindings::DumpResourceResponseMIMETypes() {
1110 if (runner_)
1111 runner_->DumpResourceResponseMIMETypes();
1112 }
1113
1114 void TestRunnerBindings::SetImagesAllowed(bool allowed) {
1115 if (runner_)
1116 runner_->SetImagesAllowed(allowed);
1117 }
1118
1119 void TestRunnerBindings::SetMediaAllowed(bool allowed) {
1120 if (runner_)
1121 runner_->SetMediaAllowed(allowed);
1122 }
1123
1124 void TestRunnerBindings::SetScriptsAllowed(bool allowed) {
1125 if (runner_)
1126 runner_->SetScriptsAllowed(allowed);
1127 }
1128
1129 void TestRunnerBindings::SetStorageAllowed(bool allowed) {
1130 if (runner_)
1131 runner_->SetStorageAllowed(allowed);
1132 }
1133
1134 void TestRunnerBindings::SetPluginsAllowed(bool allowed) {
1135 if (runner_)
1136 runner_->SetPluginsAllowed(allowed);
1137 }
1138
1139 void TestRunnerBindings::SetAllowDisplayOfInsecureContent(bool allowed) {
1140 if (runner_)
1141 runner_->SetAllowDisplayOfInsecureContent(allowed);
1142 }
1143
1144 void TestRunnerBindings::SetAllowRunningOfInsecureContent(bool allowed) {
1145 if (runner_)
1146 runner_->SetAllowRunningOfInsecureContent(allowed);
1147 }
1148
1149 void TestRunnerBindings::SetAutoplayAllowed(bool allowed) {
1150 if (runner_)
1151 runner_->SetAutoplayAllowed(allowed);
1152 }
1153
1154 void TestRunnerBindings::DumpPermissionClientCallbacks() {
1155 if (runner_)
1156 runner_->DumpPermissionClientCallbacks();
1157 }
1158
1159 void TestRunnerBindings::DumpWindowStatusChanges() {
1160 if (runner_)
1161 runner_->DumpWindowStatusChanges();
1162 }
1163
1164 void TestRunnerBindings::DumpSpellCheckCallbacks() {
1165 if (runner_)
1166 runner_->DumpSpellCheckCallbacks();
1167 }
1168
1169 void TestRunnerBindings::DumpBackForwardList() {
1170 if (runner_)
1171 runner_->DumpBackForwardList();
1172 }
1173
1174 void TestRunnerBindings::DumpSelectionRect() {
1175 if (runner_)
1176 runner_->DumpSelectionRect();
1177 }
1178
1179 void TestRunnerBindings::SetPrinting() {
1180 if (runner_)
1181 runner_->SetPrinting();
1182 }
1183
1184 void TestRunnerBindings::ClearPrinting() {
1185 if (runner_)
1186 runner_->ClearPrinting();
1187 }
1188
1189 void TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload(
1190 bool value) {
1191 if (runner_)
1192 runner_->SetShouldStayOnPageAfterHandlingBeforeUnload(value);
1193 }
1194
1195 void TestRunnerBindings::SetWillSendRequestClearHeader(
1196 const std::string& header) {
1197 if (runner_)
1198 runner_->SetWillSendRequestClearHeader(header);
1199 }
1200
1201 void TestRunnerBindings::DumpResourceRequestPriorities() {
1202 if (runner_)
1203 runner_->DumpResourceRequestPriorities();
1204 }
1205
1206 void TestRunnerBindings::SetUseMockTheme(bool use) {
1207 if (runner_)
1208 runner_->SetUseMockTheme(use);
1209 }
1210
1211 void TestRunnerBindings::WaitUntilExternalURLLoad() {
1212 if (runner_)
1213 runner_->WaitUntilExternalURLLoad();
1214 }
1215
1216 void TestRunnerBindings::DumpDragImage() {
1217 if (runner_)
1218 runner_->DumpDragImage();
1219 }
1220
1221 void TestRunnerBindings::DumpNavigationPolicy() {
1222 if (runner_)
1223 runner_->DumpNavigationPolicy();
1224 }
1225
1226 void TestRunnerBindings::DumpPageImportanceSignals() {
1227 if (view_runner_)
1228 view_runner_->DumpPageImportanceSignals();
1229 }
1230
1231 void TestRunnerBindings::ShowWebInspector(gin::Arguments* args) {
1232 if (runner_) {
1233 std::string settings;
1234 args->GetNext(&settings);
1235 std::string frontend_url;
1236 args->GetNext(&frontend_url);
1237 runner_->ShowWebInspector(settings, frontend_url);
1238 }
1239 }
1240
1241 void TestRunnerBindings::CloseWebInspector() {
1242 if (runner_)
1243 runner_->CloseWebInspector();
1244 }
1245
1246 bool TestRunnerBindings::IsChooserShown() {
1247 if (runner_)
1248 return runner_->IsChooserShown();
1249 return false;
1250 }
1251
1252 void TestRunnerBindings::EvaluateInWebInspector(int call_id,
1253 const std::string& script) {
1254 if (runner_)
1255 runner_->EvaluateInWebInspector(call_id, script);
1256 }
1257
1258 std::string TestRunnerBindings::EvaluateInWebInspectorOverlay(
1259 const std::string& script) {
1260 if (runner_)
1261 return runner_->EvaluateInWebInspectorOverlay(script);
1262
1263 return std::string();
1264 }
1265
1266 void TestRunnerBindings::ClearAllDatabases() {
1267 if (runner_)
1268 runner_->ClearAllDatabases();
1269 }
1270
1271 void TestRunnerBindings::SetDatabaseQuota(int quota) {
1272 if (runner_)
1273 runner_->SetDatabaseQuota(quota);
1274 }
1275
1276 void TestRunnerBindings::SetAlwaysAcceptCookies(bool accept) {
1277 if (runner_)
1278 runner_->SetAlwaysAcceptCookies(accept);
1279 }
1280
1281 void TestRunnerBindings::SetWindowIsKey(bool value) {
1282 if (view_runner_)
1283 view_runner_->SetWindowIsKey(value);
1284 }
1285
1286 std::string TestRunnerBindings::PathToLocalResource(const std::string& path) {
1287 if (runner_)
1288 return runner_->PathToLocalResource(path);
1289 return std::string();
1290 }
1291
1292 void TestRunnerBindings::SetBackingScaleFactor(
1293 double value, v8::Local<v8::Function> callback) {
1294 if (view_runner_)
1295 view_runner_->SetBackingScaleFactor(value, callback);
1296 }
1297
1298 void TestRunnerBindings::EnableUseZoomForDSF(
1299 v8::Local<v8::Function> callback) {
1300 if (view_runner_)
1301 view_runner_->EnableUseZoomForDSF(callback);
1302 }
1303
1304 void TestRunnerBindings::SetColorProfile(
1305 const std::string& name, v8::Local<v8::Function> callback) {
1306 if (view_runner_)
1307 view_runner_->SetColorProfile(name, callback);
1308 }
1309
1310 void TestRunnerBindings::SetBluetoothFakeAdapter(
1311 const std::string& adapter_name,
1312 v8::Local<v8::Function> callback) {
1313 if (view_runner_)
1314 view_runner_->SetBluetoothFakeAdapter(adapter_name, callback);
1315 }
1316
1317 void TestRunnerBindings::SetBluetoothManualChooser(bool enable) {
1318 if (view_runner_)
1319 view_runner_->SetBluetoothManualChooser(enable);
1320 }
1321
1322 void TestRunnerBindings::GetBluetoothManualChooserEvents(
1323 v8::Local<v8::Function> callback) {
1324 if (view_runner_)
1325 return view_runner_->GetBluetoothManualChooserEvents(callback);
1326 }
1327
1328 void TestRunnerBindings::SendBluetoothManualChooserEvent(
1329 const std::string& event,
1330 const std::string& argument) {
1331 if (view_runner_)
1332 view_runner_->SendBluetoothManualChooserEvent(event, argument);
1333 }
1334
1335 void TestRunnerBindings::SetPOSIXLocale(const std::string& locale) {
1336 if (runner_)
1337 runner_->SetPOSIXLocale(locale);
1338 }
1339
1340 void TestRunnerBindings::SetMIDIAccessorResult(bool result) {
1341 if (runner_)
1342 runner_->SetMIDIAccessorResult(result);
1343 }
1344
1345 void TestRunnerBindings::SimulateWebNotificationClick(const std::string& title,
1346 int action_index) {
1347 if (!runner_)
1348 return;
1349 runner_->SimulateWebNotificationClick(title, action_index);
1350 }
1351
1352 void TestRunnerBindings::SimulateWebNotificationClose(const std::string& title,
1353 bool by_user) {
1354 if (!runner_)
1355 return;
1356 runner_->SimulateWebNotificationClose(title, by_user);
1357 }
1358
1359 void TestRunnerBindings::AddMockSpeechRecognitionResult(
1360 const std::string& transcript, double confidence) {
1361 if (runner_)
1362 runner_->AddMockSpeechRecognitionResult(transcript, confidence);
1363 }
1364
1365 void TestRunnerBindings::SetMockSpeechRecognitionError(
1366 const std::string& error, const std::string& message) {
1367 if (runner_)
1368 runner_->SetMockSpeechRecognitionError(error, message);
1369 }
1370
1371 void TestRunnerBindings::AddMockCredentialManagerResponse(
1372 const std::string& id,
1373 const std::string& name,
1374 const std::string& avatar,
1375 const std::string& password) {
1376 if (runner_)
1377 runner_->AddMockCredentialManagerResponse(id, name, avatar, password);
1378 }
1379
1380 void TestRunnerBindings::AddMockCredentialManagerError(
1381 const std::string& error) {
1382 if (runner_)
1383 runner_->AddMockCredentialManagerError(error);
1384 }
1385
1386 void TestRunnerBindings::AddWebPageOverlay() {
1387 if (view_runner_)
1388 view_runner_->AddWebPageOverlay();
1389 }
1390
1391 void TestRunnerBindings::RemoveWebPageOverlay() {
1392 if (view_runner_)
1393 view_runner_->RemoveWebPageOverlay();
1394 }
1395
1396 void TestRunnerBindings::LayoutAndPaintAsync() {
1397 if (view_runner_)
1398 view_runner_->LayoutAndPaintAsync();
1399 }
1400
1401 void TestRunnerBindings::LayoutAndPaintAsyncThen(
1402 v8::Local<v8::Function> callback) {
1403 if (view_runner_)
1404 view_runner_->LayoutAndPaintAsyncThen(callback);
1405 }
1406
1407 void TestRunnerBindings::GetManifestThen(v8::Local<v8::Function> callback) {
1408 if (view_runner_)
1409 view_runner_->GetManifestThen(callback);
1410 }
1411
1412 void TestRunnerBindings::CapturePixelsAsyncThen(
1413 v8::Local<v8::Function> callback) {
1414 if (view_runner_)
1415 view_runner_->CapturePixelsAsyncThen(callback);
1416 }
1417
1418 void TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen(
1419 int x, int y, v8::Local<v8::Function> callback) {
1420 if (view_runner_)
1421 view_runner_->CopyImageAtAndCapturePixelsAsyncThen(x, y, callback);
1422 }
1423
1424 void TestRunnerBindings::SetCustomTextOutput(const std::string& output) {
1425 if (runner_)
1426 runner_->setCustomTextOutput(output);
1427 }
1428
1429 void TestRunnerBindings::SetViewSourceForFrame(const std::string& name,
1430 bool enabled) {
1431 if (view_runner_)
1432 view_runner_->SetViewSourceForFrame(name, enabled);
1433 }
1434
1435 void TestRunnerBindings::SetGeofencingMockProvider(bool service_available) {
1436 if (runner_)
1437 runner_->SetGeofencingMockProvider(service_available);
1438 }
1439
1440 void TestRunnerBindings::ClearGeofencingMockProvider() {
1441 if (runner_)
1442 runner_->ClearGeofencingMockProvider();
1443 }
1444
1445 void TestRunnerBindings::SetGeofencingMockPosition(double latitude,
1446 double longitude) {
1447 if (runner_)
1448 runner_->SetGeofencingMockPosition(latitude, longitude);
1449 }
1450
1451 void TestRunnerBindings::SetPermission(const std::string& name,
1452 const std::string& value,
1453 const std::string& origin,
1454 const std::string& embedding_origin) {
1455 if (!runner_)
1456 return;
1457
1458 return runner_->SetPermission(
1459 name, value, GURL(origin), GURL(embedding_origin));
1460 }
1461
1462 void TestRunnerBindings::DispatchBeforeInstallPromptEvent(
1463 int request_id,
1464 const std::vector<std::string>& event_platforms,
1465 v8::Local<v8::Function> callback) {
1466 if (!view_runner_)
1467 return;
1468
1469 return view_runner_->DispatchBeforeInstallPromptEvent(
1470 request_id, event_platforms, callback);
1471 }
1472
1473 void TestRunnerBindings::ResolveBeforeInstallPromptPromise(
1474 int request_id,
1475 const std::string& platform) {
1476 if (!runner_)
1477 return;
1478
1479 runner_->ResolveBeforeInstallPromptPromise(request_id, platform);
1480 }
1481
1482 void TestRunnerBindings::RunIdleTasks(v8::Local<v8::Function> callback) {
1483 if (!view_runner_)
1484 return;
1485 view_runner_->RunIdleTasks(callback);
1486 }
1487
1488 std::string TestRunnerBindings::PlatformName() {
1489 if (runner_)
1490 return runner_->platform_name_;
1491 return std::string();
1492 }
1493
1494 std::string TestRunnerBindings::TooltipText() {
1495 if (runner_)
1496 return runner_->tooltip_text_;
1497 return std::string();
1498 }
1499
1500 int TestRunnerBindings::WebHistoryItemCount() {
1501 if (runner_)
1502 return runner_->web_history_item_count_;
1503 return false;
1504 }
1505
1506 bool TestRunnerBindings::InterceptPostMessage() {
1507 if (runner_)
1508 return runner_->shouldInterceptPostMessage();
1509 return false;
1510 }
1511
1512 void TestRunnerBindings::SetInterceptPostMessage(bool value) {
1513 if (runner_) {
1514 runner_->layout_test_runtime_flags_.set_intercept_post_message(value);
1515 runner_->OnLayoutTestRuntimeFlagsChanged();
1516 }
1517 }
1518
1519 void TestRunnerBindings::ForceNextWebGLContextCreationToFail() {
1520 if (view_runner_)
1521 view_runner_->ForceNextWebGLContextCreationToFail();
1522 }
1523
1524 void TestRunnerBindings::ForceNextDrawingBufferCreationToFail() {
1525 if (view_runner_)
1526 view_runner_->ForceNextDrawingBufferCreationToFail();
1527 }
1528
1529 void TestRunnerBindings::NotImplemented(const gin::Arguments& args) {
1530 }
1531
1532 TestRunner::WorkQueue::WorkQueue(TestRunner* controller)
1533 : frozen_(false), controller_(controller), weak_factory_(this) {}
1534
1535 TestRunner::WorkQueue::~WorkQueue() {
1536 Reset(); 82 Reset();
1537 } 83 }
1538 84
1539 void TestRunner::WorkQueue::ProcessWorkSoon() { 85 TestRunnerForSpecificView::~TestRunnerForSpecificView() {}
1540 if (controller_->topLoadingFrame()) 86
1541 return; 87 void TestRunnerForSpecificView::Install(blink::WebLocalFrame* frame) {
1542 88 web_test_proxy_base_->test_interfaces()->GetTestRunner()->Install(
1543 if (!queue_.empty()) { 89 frame, weak_factory_.GetWeakPtr());
1544 // We delay processing queued work to avoid recursion problems. 90 }
1545 controller_->delegate_->PostTask(new WebCallbackTask(base::Bind( 91
1546 &TestRunner::WorkQueue::ProcessWork, weak_factory_.GetWeakPtr()))); 92 void TestRunnerForSpecificView::Reset() {
1547 } else if (!controller_->layout_test_runtime_flags_.wait_until_done()) { 93 pointer_locked_ = false;
1548 controller_->delegate_->TestFinished(); 94 pointer_lock_planned_result_ = PointerLockWillSucceed;
1549 } 95
1550 } 96 if (web_view() && web_view()->mainFrame()) {
1551 97 RemoveWebPageOverlay();
1552 void TestRunner::WorkQueue::Reset() { 98 SetTabKeyCyclesThroughElements(true);
1553 frozen_ = false; 99
1554 while (!queue_.empty()) { 100 #if !defined(OS_MACOSX) && !defined(OS_WIN)
1555 delete queue_.front(); 101 // (Constants copied because we can't depend on the header that defined
1556 queue_.pop_front(); 102 // them from this file.)
1557 } 103 web_view()->setSelectionColors(
1558 } 104 0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232);
1559 105 #endif
1560 void TestRunner::WorkQueue::AddWork(WorkItem* work) { 106 web_view()->setVisibilityState(WebPageVisibilityStateVisible, true);
1561 if (frozen_) { 107 if (web_view()->mainFrame()->isWebLocalFrame()) {
1562 delete work; 108 web_view()->mainFrame()->enableViewSourceMode(false);
1563 return; 109 web_view()->setTextZoomFactor(1);
1564 } 110 web_view()->setZoomLevel(0);
1565 queue_.push_back(work);
1566 }
1567
1568 void TestRunner::WorkQueue::ProcessWork() {
1569 // Quit doing work once a load is in progress.
1570 if (controller_->main_view_) {
1571 while (!queue_.empty()) {
1572 bool startedLoad =
1573 queue_.front()->Run(controller_->delegate_, controller_->main_view_);
1574 delete queue_.front();
1575 queue_.pop_front();
1576 if (startedLoad)
1577 return;
1578 } 111 }
1579 } 112 }
1580
1581 if (!controller_->layout_test_runtime_flags_.wait_until_done() &&
1582 !controller_->topLoadingFrame())
1583 controller_->delegate_->TestFinished();
1584 }
1585
1586 TestRunner::TestRunner(TestInterfaces* interfaces)
1587 : test_is_running_(false),
1588 close_remaining_windows_(false),
1589 work_queue_(this),
1590 web_history_item_count_(0),
1591 test_interfaces_(interfaces),
1592 delegate_(nullptr),
1593 main_view_(nullptr),
1594 mock_content_settings_client_(
1595 new MockContentSettingsClient(&layout_test_runtime_flags_)),
1596 credential_manager_client_(new MockCredentialManagerClient),
1597 mock_screen_orientation_client_(new MockScreenOrientationClient),
1598 spellcheck_(new SpellCheckClient(this)),
1599 chooser_count_(0),
1600 previously_focused_view_(nullptr),
1601 weak_factory_(this) {}
1602
1603 TestRunner::~TestRunner() {}
1604
1605 void TestRunner::Install(
1606 WebLocalFrame* frame,
1607 base::WeakPtr<TestRunnerForSpecificView> view_test_runner) {
1608 TestRunnerBindings::Install(weak_factory_.GetWeakPtr(), view_test_runner,
1609 frame);
1610 }
1611
1612 void TestRunner::SetDelegate(WebTestDelegate* delegate) {
1613 delegate_ = delegate;
1614 mock_content_settings_client_->SetDelegate(delegate);
1615 spellcheck_->SetDelegate(delegate);
1616 if (speech_recognizer_)
1617 speech_recognizer_->SetDelegate(delegate);
1618 }
1619
1620 void TestRunner::SetMainView(WebView* web_view) {
1621 main_view_ = web_view;
1622 }
1623
1624 void TestRunner::Reset() {
1625 top_loading_frame_ = nullptr;
1626 layout_test_runtime_flags_.Reset();
1627 mock_screen_orientation_client_->ResetData();
1628 drag_image_.reset();
1629 views_with_scheduled_animations_.clear();
1630
1631 WebSecurityPolicy::resetOriginAccessWhitelists();
1632 #if defined(__linux__) || defined(ANDROID)
1633 WebFontRendering::setSubpixelPositioning(false);
1634 #endif
1635
1636 if (delegate_) {
1637 // Reset the default quota for each origin to 5MB
1638 delegate_->SetDatabaseQuota(5 * 1024 * 1024);
1639 delegate_->SetDeviceColorProfile("reset");
1640 delegate_->SetDeviceScaleFactor(GetDefaultDeviceScaleFactor());
1641 delegate_->SetAcceptAllCookies(false);
1642 delegate_->SetLocale("");
1643 delegate_->UseUnfortunateSynchronousResizeMode(false);
1644 delegate_->DisableAutoResizeMode(WebSize());
1645 delegate_->DeleteAllCookies();
1646 delegate_->SetBluetoothManualChooser(false);
1647 delegate_->ClearGeofencingMockProvider();
1648 delegate_->ResetPermissions();
1649 ResetDeviceLight();
1650 }
1651
1652 dump_as_audio_ = false;
1653 dump_create_view_ = false;
1654 can_open_windows_ = false;
1655 dump_window_status_changes_ = false;
1656 dump_spell_check_callbacks_ = false;
1657 dump_back_forward_list_ = false;
1658 test_repaint_ = false;
1659 sweep_horizontally_ = false;
1660 midi_accessor_result_ = true;
1661 has_custom_text_output_ = false;
1662 custom_text_output_.clear();
1663
1664 http_headers_to_clear_.clear();
1665
1666 platform_name_ = "chromium";
1667 tooltip_text_ = std::string();
1668 web_history_item_count_ = 0;
1669
1670 SetUseMockTheme(true);
1671
1672 weak_factory_.InvalidateWeakPtrs();
1673 work_queue_.Reset();
1674
1675 if (close_remaining_windows_ && delegate_)
1676 delegate_->CloseRemainingWindows();
1677 else
1678 close_remaining_windows_ = true;
1679 }
1680
1681 void TestRunner::SetTestIsRunning(bool running) {
1682 test_is_running_ = running;
1683 }
1684
1685 void TestRunnerForSpecificView::PostTask(const base::Closure& callback) {
1686 delegate()->PostTask(new WebCallbackTask(callback));
1687 }
1688
1689 void TestRunnerForSpecificView::PostDelayedTask(long long delay,
1690 const base::Closure& callback) {
1691 delegate()->PostDelayedTask(new WebCallbackTask(callback), delay);
1692 }
1693
1694 void TestRunnerForSpecificView::PostV8Callback(
1695 const v8::Local<v8::Function>& callback) {
1696 PostTask(base::Bind(&TestRunnerForSpecificView::InvokeV8Callback,
1697 weak_factory_.GetWeakPtr(),
1698 v8::UniquePersistent<v8::Function>(
1699 blink::mainThreadIsolate(), callback)));
1700 }
1701
1702 void TestRunnerForSpecificView::PostV8CallbackWithArgs(
1703 v8::UniquePersistent<v8::Function> callback,
1704 int argc,
1705 v8::Local<v8::Value> argv[]) {
1706 std::vector<v8::UniquePersistent<v8::Value>> args;
1707 for (int i = 0; i < argc; i++) {
1708 args.push_back(
1709 v8::UniquePersistent<v8::Value>(blink::mainThreadIsolate(), argv[i]));
1710 }
1711
1712 PostTask(base::Bind(&TestRunnerForSpecificView::InvokeV8CallbackWithArgs,
1713 weak_factory_.GetWeakPtr(), std::move(callback),
1714 std::move(args)));
1715 }
1716
1717 void TestRunnerForSpecificView::InvokeV8Callback(
1718 const v8::UniquePersistent<v8::Function>& callback) {
1719 std::vector<v8::UniquePersistent<v8::Value>> empty_args;
1720 InvokeV8CallbackWithArgs(callback, std::move(empty_args));
1721 }
1722
1723 void TestRunnerForSpecificView::InvokeV8CallbackWithArgs(
1724 const v8::UniquePersistent<v8::Function>& callback,
1725 const std::vector<v8::UniquePersistent<v8::Value>>& args) {
1726 v8::Isolate* isolate = blink::mainThreadIsolate();
1727 v8::HandleScope handle_scope(isolate);
1728
1729 WebFrame* frame = web_view()->mainFrame();
1730 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
1731 if (context.IsEmpty())
1732 return;
1733 v8::Context::Scope context_scope(context);
1734
1735 std::vector<v8::Local<v8::Value>> local_args;
1736 for (const auto& arg : args) {
1737 local_args.push_back(v8::Local<v8::Value>::New(isolate, arg));
1738 }
1739
1740 frame->callFunctionEvenIfScriptDisabled(
1741 v8::Local<v8::Function>::New(isolate, callback), context->Global(),
1742 local_args.size(), local_args.data());
1743 }
1744
1745 base::Closure TestRunnerForSpecificView::CreateClosureThatPostsV8Callback(
1746 const v8::Local<v8::Function>& callback) {
1747 return base::Bind(&TestRunnerForSpecificView::PostTask,
1748 weak_factory_.GetWeakPtr(),
1749 base::Bind(&TestRunnerForSpecificView::InvokeV8Callback,
1750 weak_factory_.GetWeakPtr(),
1751 v8::UniquePersistent<v8::Function>(
1752 blink::mainThreadIsolate(), callback)));
1753 }
1754
1755 bool TestRunner::shouldDumpEditingCallbacks() const {
1756 return layout_test_runtime_flags_.dump_editting_callbacks();
1757 }
1758
1759 void TestRunner::setShouldDumpAsText(bool value) {
1760 layout_test_runtime_flags_.set_dump_as_text(value);
1761 OnLayoutTestRuntimeFlagsChanged();
1762 }
1763
1764 void TestRunner::setShouldDumpAsMarkup(bool value) {
1765 layout_test_runtime_flags_.set_dump_as_markup(value);
1766 OnLayoutTestRuntimeFlagsChanged();
1767 }
1768
1769 bool TestRunner::shouldDumpAsCustomText() const {
1770 return has_custom_text_output_;
1771 }
1772
1773 std::string TestRunner::customDumpText() const {
1774 return custom_text_output_;
1775 }
1776
1777 void TestRunner::setCustomTextOutput(const std::string& text) {
1778 custom_text_output_ = text;
1779 has_custom_text_output_ = true;
1780 }
1781
1782 bool TestRunner::ShouldGeneratePixelResults() {
1783 CheckResponseMimeType();
1784 return layout_test_runtime_flags_.generate_pixel_results();
1785 }
1786
1787 bool TestRunner::shouldStayOnPageAfterHandlingBeforeUnload() const {
1788 return layout_test_runtime_flags_.stay_on_page_after_handling_before_unload();
1789 }
1790
1791
1792 void TestRunner::setShouldGeneratePixelResults(bool value) {
1793 layout_test_runtime_flags_.set_generate_pixel_results(value);
1794 OnLayoutTestRuntimeFlagsChanged();
1795 }
1796
1797 bool TestRunner::ShouldDumpAsAudio() const {
1798 return dump_as_audio_;
1799 }
1800
1801 void TestRunner::GetAudioData(std::vector<unsigned char>* buffer_view) const {
1802 *buffer_view = audio_data_;
1803 }
1804
1805 bool TestRunner::IsRecursiveLayoutDumpRequested() {
1806 CheckResponseMimeType();
1807 return layout_test_runtime_flags_.dump_child_frames();
1808 }
1809
1810 std::string TestRunner::DumpLayout(blink::WebLocalFrame* frame) {
1811 CheckResponseMimeType();
1812 return ::test_runner::DumpLayout(frame, layout_test_runtime_flags_);
1813 }
1814
1815 void TestRunner::DumpPixelsAsync(
1816 blink::WebView* web_view,
1817 const base::Callback<void(const SkBitmap&)>& callback) {
1818 if (layout_test_runtime_flags_.dump_drag_image()) {
1819 if (drag_image_.isNull()) {
1820 // This means the test called dumpDragImage but did not initiate a drag.
1821 // Return a blank image so that the test fails.
1822 SkBitmap bitmap;
1823 bitmap.allocN32Pixels(1, 1);
1824 {
1825 SkAutoLockPixels lock(bitmap);
1826 bitmap.eraseColor(0);
1827 }
1828 callback.Run(bitmap);
1829 return;
1830 }
1831
1832 callback.Run(drag_image_.getSkBitmap());
1833 return;
1834 }
1835
1836 test_runner::DumpPixelsAsync(web_view, layout_test_runtime_flags_,
1837 delegate_->GetDeviceScaleFactorForTest(),
1838 callback);
1839 }
1840
1841 void TestRunner::ReplicateLayoutTestRuntimeFlagsChanges(
1842 const base::DictionaryValue& changed_values) {
1843 if (test_is_running_)
1844 layout_test_runtime_flags_.tracked_dictionary().ApplyUntrackedChanges(
1845 changed_values);
1846 }
1847
1848 bool TestRunner::HasCustomTextDump(std::string* custom_text_dump) const {
1849 if (shouldDumpAsCustomText()) {
1850 *custom_text_dump = customDumpText();
1851 return true;
1852 }
1853
1854 return false;
1855 }
1856
1857 bool TestRunner::shouldDumpFrameLoadCallbacks() const {
1858 return test_is_running_ &&
1859 layout_test_runtime_flags_.dump_frame_load_callbacks();
1860 }
1861
1862 void TestRunner::setShouldDumpFrameLoadCallbacks(bool value) {
1863 layout_test_runtime_flags_.set_dump_frame_load_callbacks(value);
1864 OnLayoutTestRuntimeFlagsChanged();
1865 }
1866
1867 bool TestRunner::shouldDumpPingLoaderCallbacks() const {
1868 return test_is_running_ &&
1869 layout_test_runtime_flags_.dump_ping_loader_callbacks();
1870 }
1871
1872 void TestRunner::setShouldEnableViewSource(bool value) {
1873 // TODO(lukasza): This flag should be 1) replicated across OOPIFs and
1874 // 2) applied to all views, not just the main window view.
1875
1876 // Path-based test config is trigerred by BlinkTestRunner, when |main_view_|
1877 // is guaranteed to exist at this point.
1878 DCHECK(main_view_);
1879
1880 main_view_->mainFrame()->enableViewSourceMode(value);
1881 }
1882
1883 bool TestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const {
1884 return test_is_running_ &&
1885 layout_test_runtime_flags_.dump_user_gesture_in_frame_load_callbacks();
1886 }
1887
1888 bool TestRunner::shouldDumpTitleChanges() const {
1889 return layout_test_runtime_flags_.dump_title_changes();
1890 }
1891
1892 bool TestRunner::shouldDumpIconChanges() const {
1893 return layout_test_runtime_flags_.dump_icon_changes();
1894 }
1895
1896 bool TestRunner::shouldDumpCreateView() const {
1897 return dump_create_view_;
1898 }
1899
1900 bool TestRunner::canOpenWindows() const {
1901 return can_open_windows_;
1902 }
1903
1904 bool TestRunner::shouldDumpResourceLoadCallbacks() const {
1905 return test_is_running_ &&
1906 layout_test_runtime_flags_.dump_resource_load_callbacks();
1907 }
1908
1909 bool TestRunner::shouldDumpResourceResponseMIMETypes() const {
1910 return test_is_running_ &&
1911 layout_test_runtime_flags_.dump_resource_response_mime_types();
1912 }
1913
1914 WebContentSettingsClient* TestRunner::GetWebContentSettings() const {
1915 return mock_content_settings_client_.get();
1916 }
1917
1918 void TestRunner::InitializeWebViewWithMocks(blink::WebView* web_view) {
1919 web_view->setSpellCheckClient(spellcheck_.get());
1920 web_view->setCredentialManagerClient(credential_manager_client_.get());
1921 }
1922
1923 bool TestRunner::shouldDumpStatusCallbacks() const {
1924 return dump_window_status_changes_;
1925 }
1926
1927 bool TestRunner::shouldDumpSpellCheckCallbacks() const {
1928 return dump_spell_check_callbacks_;
1929 }
1930
1931 bool TestRunner::ShouldDumpBackForwardList() const {
1932 return dump_back_forward_list_;
1933 }
1934
1935 bool TestRunner::isPrinting() const {
1936 return layout_test_runtime_flags_.is_printing();
1937 }
1938
1939 bool TestRunner::shouldWaitUntilExternalURLLoad() const {
1940 return layout_test_runtime_flags_.wait_until_external_url_load();
1941 }
1942
1943 const std::set<std::string>* TestRunner::httpHeadersToClear() const {
1944 return &http_headers_to_clear_;
1945 }
1946
1947 bool TestRunner::IsFramePartOfMainTestWindow(blink::WebFrame* frame) const {
1948 return test_is_running_ && frame->top()->view() == main_view_;
1949 }
1950
1951 bool TestRunner::tryToSetTopLoadingFrame(WebFrame* frame) {
1952 if (!IsFramePartOfMainTestWindow(frame))
1953 return false;
1954
1955 if (top_loading_frame_ || layout_test_runtime_flags_.have_top_loading_frame())
1956 return false;
1957
1958 top_loading_frame_ = frame;
1959 layout_test_runtime_flags_.set_have_top_loading_frame(true);
1960 OnLayoutTestRuntimeFlagsChanged();
1961 return true;
1962 }
1963
1964 bool TestRunner::tryToClearTopLoadingFrame(WebFrame* frame) {
1965 if (!IsFramePartOfMainTestWindow(frame))
1966 return false;
1967
1968 if (frame != top_loading_frame_)
1969 return false;
1970
1971 top_loading_frame_ = nullptr;
1972 DCHECK(layout_test_runtime_flags_.have_top_loading_frame());
1973 layout_test_runtime_flags_.set_have_top_loading_frame(false);
1974 OnLayoutTestRuntimeFlagsChanged();
1975
1976 LocationChangeDone();
1977 return true;
1978 }
1979
1980 WebFrame* TestRunner::topLoadingFrame() const {
1981 return top_loading_frame_;
1982 }
1983
1984 void TestRunner::policyDelegateDone() {
1985 DCHECK(layout_test_runtime_flags_.wait_until_done());
1986 delegate_->TestFinished();
1987 layout_test_runtime_flags_.set_wait_until_done(false);
1988 OnLayoutTestRuntimeFlagsChanged();
1989 }
1990
1991 bool TestRunner::policyDelegateEnabled() const {
1992 return layout_test_runtime_flags_.policy_delegate_enabled();
1993 }
1994
1995 bool TestRunner::policyDelegateIsPermissive() const {
1996 return layout_test_runtime_flags_.policy_delegate_is_permissive();
1997 }
1998
1999 bool TestRunner::policyDelegateShouldNotifyDone() const {
2000 return layout_test_runtime_flags_.policy_delegate_should_notify_done();
2001 }
2002
2003 bool TestRunner::shouldInterceptPostMessage() const {
2004 return layout_test_runtime_flags_.intercept_post_message();
2005 }
2006
2007 bool TestRunner::shouldDumpResourcePriorities() const {
2008 return layout_test_runtime_flags_.dump_resource_priorities();
2009 } 113 }
2010 114
2011 bool TestRunnerForSpecificView::RequestPointerLock() { 115 bool TestRunnerForSpecificView::RequestPointerLock() {
2012 switch (pointer_lock_planned_result_) { 116 switch (pointer_lock_planned_result_) {
2013 case PointerLockWillSucceed: 117 case PointerLockWillSucceed:
2014 PostDelayedTask( 118 PostDelayedTask(
2015 0, 119 0,
2016 base::Bind(&TestRunnerForSpecificView::DidAcquirePointerLockInternal, 120 base::Bind(&TestRunnerForSpecificView::DidAcquirePointerLockInternal,
2017 weak_factory_.GetWeakPtr())); 121 weak_factory_.GetWeakPtr()));
2018 return true; 122 return true;
(...skipping 12 matching lines...) Expand all
2031 void TestRunnerForSpecificView::RequestPointerUnlock() { 135 void TestRunnerForSpecificView::RequestPointerUnlock() {
2032 PostDelayedTask( 136 PostDelayedTask(
2033 0, base::Bind(&TestRunnerForSpecificView::DidLosePointerLockInternal, 137 0, base::Bind(&TestRunnerForSpecificView::DidLosePointerLockInternal,
2034 weak_factory_.GetWeakPtr())); 138 weak_factory_.GetWeakPtr()));
2035 } 139 }
2036 140
2037 bool TestRunnerForSpecificView::isPointerLocked() { 141 bool TestRunnerForSpecificView::isPointerLocked() {
2038 return pointer_locked_; 142 return pointer_locked_;
2039 } 143 }
2040 144
2041 void TestRunner::setToolTipText(const WebString& text) { 145 void TestRunnerForSpecificView::PostTask(const base::Closure& callback) {
2042 tooltip_text_ = text.utf8(); 146 delegate()->PostTask(new WebCallbackTask(callback));
2043 } 147 }
2044 148
2045 void TestRunner::setDragImage( 149 void TestRunnerForSpecificView::PostDelayedTask(long long delay,
2046 const blink::WebImage& drag_image) { 150 const base::Closure& callback) {
2047 if (layout_test_runtime_flags_.dump_drag_image()) { 151 delegate()->PostDelayedTask(new WebCallbackTask(callback), delay);
2048 if (drag_image_.isNull()) 152 }
2049 drag_image_ = drag_image; 153
2050 } 154 void TestRunnerForSpecificView::PostV8Callback(
2051 } 155 const v8::Local<v8::Function>& callback) {
2052 156 PostTask(base::Bind(&TestRunnerForSpecificView::InvokeV8Callback,
2053 bool TestRunner::shouldDumpNavigationPolicy() const { 157 weak_factory_.GetWeakPtr(),
2054 return layout_test_runtime_flags_.dump_navigation_policy(); 158 v8::UniquePersistent<v8::Function>(
2055 } 159 blink::mainThreadIsolate(), callback)));
2056 160 }
2057 bool TestRunner::midiAccessorResult() { 161
2058 return midi_accessor_result_; 162 void TestRunnerForSpecificView::PostV8CallbackWithArgs(
2059 } 163 v8::UniquePersistent<v8::Function> callback,
2060 164 int argc,
2061 void TestRunner::ClearDevToolsLocalStorage() { 165 v8::Local<v8::Value> argv[]) {
2062 delegate_->ClearDevToolsLocalStorage(); 166 std::vector<v8::UniquePersistent<v8::Value>> args;
2063 } 167 for (int i = 0; i < argc; i++) {
2064 168 args.push_back(
2065 void TestRunner::ShowDevTools(const std::string& settings, 169 v8::UniquePersistent<v8::Value>(blink::mainThreadIsolate(), argv[i]));
2066 const std::string& frontend_url) { 170 }
2067 delegate_->ShowDevTools(settings, frontend_url); 171
2068 } 172 PostTask(base::Bind(&TestRunnerForSpecificView::InvokeV8CallbackWithArgs,
2069 173 weak_factory_.GetWeakPtr(), std::move(callback),
2070 class WorkItemBackForward : public TestRunner::WorkItem { 174 std::move(args)));
2071 public: 175 }
2072 WorkItemBackForward(int distance) : distance_(distance) {} 176
2073 177 void TestRunnerForSpecificView::InvokeV8Callback(
2074 bool Run(WebTestDelegate* delegate, WebView*) override { 178 const v8::UniquePersistent<v8::Function>& callback) {
2075 delegate->GoToOffset(distance_); 179 std::vector<v8::UniquePersistent<v8::Value>> empty_args;
2076 return true; // FIXME: Did it really start a navigation? 180 InvokeV8CallbackWithArgs(callback, std::move(empty_args));
2077 } 181 }
2078 182
2079 private: 183 void TestRunnerForSpecificView::InvokeV8CallbackWithArgs(
2080 int distance_; 184 const v8::UniquePersistent<v8::Function>& callback,
2081 }; 185 const std::vector<v8::UniquePersistent<v8::Value>>& args) {
2082 186 v8::Isolate* isolate = blink::mainThreadIsolate();
2083 void TestRunner::NotifyDone() { 187 v8::HandleScope handle_scope(isolate);
2084 // Test didn't timeout. Kill the pending callbacks. 188
2085 weak_factory_.InvalidateWeakPtrs(); 189 WebFrame* frame = web_view()->mainFrame();
2086 190 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
2087 CompleteNotifyDone(); 191 if (context.IsEmpty())
2088 } 192 return;
2089 193 v8::Context::Scope context_scope(context);
2090 void TestRunner::WaitUntilDone() { 194
2091 layout_test_runtime_flags_.set_wait_until_done(true); 195 std::vector<v8::Local<v8::Value>> local_args;
2092 OnLayoutTestRuntimeFlagsChanged(); 196 for (const auto& arg : args) {
2093 } 197 local_args.push_back(v8::Local<v8::Value>::New(isolate, arg));
2094 198 }
2095 void TestRunner::QueueBackNavigation(int how_far_back) { 199
2096 work_queue_.AddWork(new WorkItemBackForward(-how_far_back)); 200 frame->callFunctionEvenIfScriptDisabled(
2097 } 201 v8::Local<v8::Function>::New(isolate, callback), context->Global(),
2098 202 local_args.size(), local_args.data());
2099 void TestRunner::QueueForwardNavigation(int how_far_forward) { 203 }
2100 work_queue_.AddWork(new WorkItemBackForward(how_far_forward)); 204
2101 } 205 base::Closure TestRunnerForSpecificView::CreateClosureThatPostsV8Callback(
2102 206 const v8::Local<v8::Function>& callback) {
2103 class WorkItemReload : public TestRunner::WorkItem { 207 return base::Bind(&TestRunnerForSpecificView::PostTask,
2104 public: 208 weak_factory_.GetWeakPtr(),
2105 bool Run(WebTestDelegate* delegate, WebView*) override { 209 base::Bind(&TestRunnerForSpecificView::InvokeV8Callback,
2106 delegate->Reload(); 210 weak_factory_.GetWeakPtr(),
2107 return true; 211 v8::UniquePersistent<v8::Function>(
2108 } 212 blink::mainThreadIsolate(), callback)));
2109 }; 213 }
2110 214
2111 void TestRunner::QueueReload() { 215 void TestRunnerForSpecificView::LayoutAndPaintAsync() {
2112 work_queue_.AddWork(new WorkItemReload()); 216 test_runner::LayoutAndPaintAsyncThen(web_view(), base::Closure());
2113 } 217 }
2114 218
2115 class WorkItemLoadingScript : public TestRunner::WorkItem { 219 void TestRunnerForSpecificView::LayoutAndPaintAsyncThen(
2116 public: 220 v8::Local<v8::Function> callback) {
2117 WorkItemLoadingScript(const std::string& script) 221 test_runner::LayoutAndPaintAsyncThen(
2118 : script_(script) {} 222 web_view(), CreateClosureThatPostsV8Callback(callback));
2119 223 }
2120 bool Run(WebTestDelegate*, WebView* web_view) override { 224
2121 web_view->mainFrame()->executeScript( 225 void TestRunnerForSpecificView::CapturePixelsAsyncThen(
2122 WebScriptSource(WebString::fromUTF8(script_))); 226 v8::Local<v8::Function> callback) {
2123 return true; // FIXME: Did it really start a navigation? 227 v8::UniquePersistent<v8::Function> persistent_callback(
2124 } 228 blink::mainThreadIsolate(), callback);
2125 229
2126 private: 230 web_test_proxy_base_->test_interfaces()->GetTestRunner()->DumpPixelsAsync(
2127 std::string script_; 231 web_view(), base::Bind(&TestRunnerForSpecificView::CapturePixelsCallback,
2128 }; 232 weak_factory_.GetWeakPtr(),
2129 233 base::Passed(std::move(persistent_callback))));
2130 void TestRunner::QueueLoadingScript(const std::string& script) { 234 }
2131 work_queue_.AddWork(new WorkItemLoadingScript(script)); 235
2132 } 236 void TestRunnerForSpecificView::CapturePixelsCallback(
2133 237 v8::UniquePersistent<v8::Function> callback,
2134 class WorkItemNonLoadingScript : public TestRunner::WorkItem { 238 const SkBitmap& snapshot) {
2135 public: 239 v8::Isolate* isolate = blink::mainThreadIsolate();
2136 WorkItemNonLoadingScript(const std::string& script) 240 v8::HandleScope handle_scope(isolate);
2137 : script_(script) {} 241
2138 242 v8::Local<v8::Context> context =
2139 bool Run(WebTestDelegate*, WebView* web_view) override { 243 web_view()->mainFrame()->mainWorldScriptContext();
2140 web_view->mainFrame()->executeScript( 244 if (context.IsEmpty())
2141 WebScriptSource(WebString::fromUTF8(script_))); 245 return;
2142 return false; 246
2143 } 247 v8::Context::Scope context_scope(context);
2144 248 v8::Local<v8::Value> argv[3];
2145 private: 249 SkAutoLockPixels snapshot_lock(snapshot);
2146 std::string script_; 250
2147 }; 251 // Size can be 0 for cases where copyImageAt was called on position
2148 252 // that doesn't have an image.
2149 void TestRunner::QueueNonLoadingScript(const std::string& script) { 253 int width = snapshot.info().width();
2150 work_queue_.AddWork(new WorkItemNonLoadingScript(script)); 254 argv[0] = v8::Number::New(isolate, width);
2151 } 255
2152 256 int height = snapshot.info().height();
2153 class WorkItemLoad : public TestRunner::WorkItem { 257 argv[1] = v8::Number::New(isolate, height);
2154 public: 258
2155 WorkItemLoad(const WebURL& url, const std::string& target) 259 // Skia's internal byte order is platform-dependent. Always convert to RGBA
2156 : url_(url), target_(target) {} 260 // in order to provide a consistent ordering to the layout tests.
2157 261 const SkImageInfo bufferInfo =
2158 bool Run(WebTestDelegate* delegate, WebView*) override { 262 snapshot.info().makeColorType(kRGBA_8888_SkColorType);
2159 delegate->LoadURLForFrame(url_, target_); 263 const size_t bufferRowBytes = bufferInfo.minRowBytes();
2160 return true; // FIXME: Did it really start a navigation? 264 blink::WebArrayBuffer buffer =
2161 } 265 blink::WebArrayBuffer::create(bufferInfo.getSafeSize(bufferRowBytes), 1);
2162 266 if (!snapshot.readPixels(bufferInfo,
2163 private: 267 buffer.data(),
2164 WebURL url_; 268 bufferRowBytes,
2165 std::string target_; 269 0, 0)) {
2166 }; 270 // We only expect readPixels to fail for null bitmaps.
2167 271 DCHECK(snapshot.isNull());
2168 void TestRunner::QueueLoad(const std::string& url, const std::string& target) { 272 }
2169 if (!main_view_) 273
2170 return; 274 argv[2] = blink::WebArrayBufferConverter::toV8Value(
2171 275 &buffer, context->Global(), isolate);
2172 // FIXME: Implement WebURL::resolve() and avoid GURL. 276
2173 GURL current_url = main_view_->mainFrame()->document().url(); 277 PostV8CallbackWithArgs(std::move(callback), arraysize(argv), argv);
2174 GURL full_url = current_url.Resolve(url); 278 }
2175 work_queue_.AddWork(new WorkItemLoad(full_url, target)); 279
2176 } 280 void TestRunnerForSpecificView::CopyImageAtAndCapturePixelsAsyncThen(
2177 281 int x,
2178 void TestRunner::SetCustomPolicyDelegate(gin::Arguments* args) { 282 int y,
2179 bool value; 283 v8::Local<v8::Function> callback) {
2180 args->GetNext(&value); 284 v8::UniquePersistent<v8::Function> persistent_callback(
2181 layout_test_runtime_flags_.set_policy_delegate_enabled(value); 285 blink::mainThreadIsolate(), callback);
2182 286
2183 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsBoolean()) { 287 CopyImageAtAndCapturePixels(
2184 args->GetNext(&value); 288 web_view(), x, y,
2185 layout_test_runtime_flags_.set_policy_delegate_is_permissive(value); 289 base::Bind(&TestRunnerForSpecificView::CapturePixelsCallback,
2186 } 290 weak_factory_.GetWeakPtr(),
2187 291 base::Passed(std::move(persistent_callback))));
2188 OnLayoutTestRuntimeFlagsChanged(); 292 }
2189 } 293
2190 294 void TestRunnerForSpecificView::GetManifestThen(
2191 void TestRunner::WaitForPolicyDelegate() { 295 v8::Local<v8::Function> callback) {
2192 layout_test_runtime_flags_.set_policy_delegate_enabled(true); 296 v8::UniquePersistent<v8::Function> persistent_callback(
2193 layout_test_runtime_flags_.set_policy_delegate_should_notify_done(true); 297 blink::mainThreadIsolate(), callback);
2194 layout_test_runtime_flags_.set_wait_until_done(true); 298
2195 OnLayoutTestRuntimeFlagsChanged(); 299 delegate()->FetchManifest(
2196 } 300 web_view(), web_view()->mainFrame()->document().manifestURL(),
2197 301 base::Bind(&TestRunnerForSpecificView::GetManifestCallback,
2198 int TestRunner::WindowCount() { 302 weak_factory_.GetWeakPtr(),
2199 return test_interfaces_->GetWindowList().size(); 303 base::Passed(std::move(persistent_callback))));
2200 } 304 }
2201 305
2202 void TestRunner::SetCloseRemainingWindowsWhenComplete( 306 void TestRunnerForSpecificView::GetManifestCallback(
2203 bool close_remaining_windows) { 307 v8::UniquePersistent<v8::Function> callback,
2204 close_remaining_windows_ = close_remaining_windows; 308 const blink::WebURLResponse& response,
2205 } 309 const std::string& data) {
2206 310 PostV8CallbackWithArgs(std::move(callback), 0, nullptr);
2207 void TestRunner::ResetTestHelperControllers() { 311 }
2208 test_interfaces_->ResetTestHelperControllers(); 312
313 void TestRunnerForSpecificView::GetBluetoothManualChooserEvents(
314 v8::Local<v8::Function> callback) {
315 return delegate()->GetBluetoothManualChooserEvents(base::Bind(
316 &TestRunnerForSpecificView::GetBluetoothManualChooserEventsCallback,
317 weak_factory_.GetWeakPtr(),
318 base::Passed(v8::UniquePersistent<v8::Function>(
319 blink::mainThreadIsolate(), callback))));
320 }
321
322 void TestRunnerForSpecificView::GetBluetoothManualChooserEventsCallback(
323 v8::UniquePersistent<v8::Function> callback,
324 const std::vector<std::string>& events) {
325 // Build the V8 context.
326 v8::Isolate* isolate = blink::mainThreadIsolate();
327 v8::HandleScope handle_scope(isolate);
328 v8::Local<v8::Context> context =
329 web_view()->mainFrame()->mainWorldScriptContext();
330 if (context.IsEmpty())
331 return;
332 v8::Context::Scope context_scope(context);
333
334 // Convert the argument.
335 v8::Local<v8::Value> arg;
336 if (!gin::TryConvertToV8(isolate, events, &arg))
337 return;
338
339 // Call the callback.
340 PostV8CallbackWithArgs(std::move(callback), 1, &arg);
341 }
342
343 void TestRunnerForSpecificView::SetBluetoothFakeAdapter(
344 const std::string& adapter_name,
345 v8::Local<v8::Function> callback) {
346 delegate()->SetBluetoothFakeAdapter(
347 adapter_name, CreateClosureThatPostsV8Callback(callback));
348 }
349
350 void TestRunnerForSpecificView::SetBluetoothManualChooser(bool enable) {
351 delegate()->SetBluetoothManualChooser(enable);
352 }
353
354 void TestRunnerForSpecificView::SendBluetoothManualChooserEvent(
355 const std::string& event,
356 const std::string& argument) {
357 delegate()->SendBluetoothManualChooserEvent(event, argument);
358 }
359
360 void TestRunnerForSpecificView::SetBackingScaleFactor(
361 double value,
362 v8::Local<v8::Function> callback) {
363 delegate()->SetDeviceScaleFactor(value);
364 PostV8Callback(callback);
365 }
366
367 void TestRunnerForSpecificView::EnableUseZoomForDSF(
368 v8::Local<v8::Function> callback) {
369 delegate()->EnableUseZoomForDSF();
370 PostV8Callback(callback);
371 }
372
373 void TestRunnerForSpecificView::SetColorProfile(
374 const std::string& name,
375 v8::Local<v8::Function> callback) {
376 delegate()->SetDeviceColorProfile(name);
377 PostV8Callback(callback);
378 }
379
380 void TestRunnerForSpecificView::DispatchBeforeInstallPromptEvent(
381 int request_id,
382 const std::vector<std::string>& event_platforms,
383 v8::Local<v8::Function> callback) {
384 delegate()->DispatchBeforeInstallPromptEvent(
385 request_id, event_platforms,
386 base::Bind(
387 &TestRunnerForSpecificView::DispatchBeforeInstallPromptCallback,
388 weak_factory_.GetWeakPtr(),
389 base::Passed(v8::UniquePersistent<v8::Function>(
390 blink::mainThreadIsolate(), callback))));
391 }
392
393 void TestRunnerForSpecificView::DispatchBeforeInstallPromptCallback(
394 v8::UniquePersistent<v8::Function> callback,
395 bool canceled) {
396 v8::Isolate* isolate = blink::mainThreadIsolate();
397 v8::HandleScope handle_scope(isolate);
398
399 v8::Local<v8::Context> context =
400 web_view()->mainFrame()->mainWorldScriptContext();
401 if (context.IsEmpty())
402 return;
403
404 v8::Context::Scope context_scope(context);
405 v8::Local<v8::Value> arg;
406 arg = v8::Boolean::New(isolate, canceled);
407
408 PostV8CallbackWithArgs(std::move(callback), 1, &arg);
409 }
410
411 void TestRunnerForSpecificView::RunIdleTasks(v8::Local<v8::Function> callback) {
412 delegate()->RunIdleTasks(CreateClosureThatPostsV8Callback(callback));
2209 } 413 }
2210 414
2211 void TestRunnerForSpecificView::SetTabKeyCyclesThroughElements( 415 void TestRunnerForSpecificView::SetTabKeyCyclesThroughElements(
2212 bool tab_key_cycles_through_elements) { 416 bool tab_key_cycles_through_elements) {
2213 web_view()->setTabKeyCyclesThroughElements(tab_key_cycles_through_elements); 417 web_view()->setTabKeyCyclesThroughElements(tab_key_cycles_through_elements);
2214 } 418 }
2215 419
2216 void TestRunnerForSpecificView::ExecCommand(gin::Arguments* args) { 420 void TestRunnerForSpecificView::ExecCommand(gin::Arguments* args) {
2217 std::string command; 421 std::string command;
2218 args->GetNext(&command); 422 args->GetNext(&command);
2219 423
2220 std::string value; 424 std::string value;
2221 if (args->Length() >= 3) { 425 if (args->Length() >= 3) {
2222 // Ignore the second parameter (which is userInterface) 426 // Ignore the second parameter (which is userInterface)
2223 // since this command emulates a manual action. 427 // since this command emulates a manual action.
2224 args->Skip(); 428 args->Skip();
2225 args->GetNext(&value); 429 args->GetNext(&value);
2226 } 430 }
2227 431
2228 // Note: webkit's version does not return the boolean, so neither do we. 432 // Note: webkit's version does not return the boolean, so neither do we.
2229 web_view()->focusedFrame()->executeCommand(WebString::fromUTF8(command), 433 web_view()->focusedFrame()->executeCommand(WebString::fromUTF8(command),
2230 WebString::fromUTF8(value)); 434 WebString::fromUTF8(value));
2231 } 435 }
2232 436
2233 bool TestRunnerForSpecificView::IsCommandEnabled(const std::string& command) { 437 bool TestRunnerForSpecificView::IsCommandEnabled(const std::string& command) {
2234 return web_view()->focusedFrame()->isCommandEnabled( 438 return web_view()->focusedFrame()->isCommandEnabled(
2235 WebString::fromUTF8(command)); 439 WebString::fromUTF8(command));
2236 } 440 }
2237 441
442 bool TestRunnerForSpecificView::HasCustomPageSizeStyle(int page_index) {
443 WebFrame* frame = web_view()->mainFrame();
444 if (!frame)
445 return false;
446 return frame->hasCustomPageSizeStyle(page_index);
447 }
448
449 void TestRunnerForSpecificView::ForceRedSelectionColors() {
450 web_view()->setSelectionColors(
451 0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0);
452 }
453
454 void TestRunnerForSpecificView::SetPageVisibility(
455 const std::string& new_visibility) {
456 if (new_visibility == "visible")
457 web_view()->setVisibilityState(WebPageVisibilityStateVisible, false);
458 else if (new_visibility == "hidden")
459 web_view()->setVisibilityState(WebPageVisibilityStateHidden, false);
460 else if (new_visibility == "prerender")
461 web_view()->setVisibilityState(WebPageVisibilityStatePrerender, false);
462 }
463
464 void TestRunnerForSpecificView::SetTextDirection(
465 const std::string& direction_name) {
466 // Map a direction name to a WebTextDirection value.
467 WebTextDirection direction;
468 if (direction_name == "auto")
469 direction = WebTextDirectionDefault;
470 else if (direction_name == "rtl")
471 direction = WebTextDirectionRightToLeft;
472 else if (direction_name == "ltr")
473 direction = WebTextDirectionLeftToRight;
474 else
475 return;
476
477 web_view()->setTextDirection(direction);
478 }
479
480 void TestRunnerForSpecificView::DumpPageImportanceSignals() {
481 blink::WebPageImportanceSignals* signals =
482 web_view()->pageImportanceSignals();
483 if (!signals)
484 return;
485
486 std::string message = base::StringPrintf(
487 "WebPageImportanceSignals:\n"
488 " hadFormInteraction: %s\n"
489 " issuedNonGetFetchFromScript: %s\n",
490 signals->hadFormInteraction() ? "true" : "false",
491 signals->issuedNonGetFetchFromScript() ? "true" : "false");
492 if (delegate())
493 delegate()->PrintMessage(message);
494 }
495
496 void TestRunnerForSpecificView::AddWebPageOverlay() {
497 web_view()->setPageOverlayColor(SK_ColorCYAN);
498 }
499
500 void TestRunnerForSpecificView::RemoveWebPageOverlay() {
501 web_view()->setPageOverlayColor(SK_ColorTRANSPARENT);
502 }
503
504 void TestRunnerForSpecificView::ForceNextWebGLContextCreationToFail() {
505 web_view()->forceNextWebGLContextCreationToFail();
506 }
507
508 void TestRunnerForSpecificView::ForceNextDrawingBufferCreationToFail() {
509 web_view()->forceNextDrawingBufferCreationToFail();
510 }
511
512 void TestRunnerForSpecificView::SetWindowIsKey(bool value) {
513 web_test_proxy_base_->test_interfaces()->GetTestRunner()->SetFocus(web_view(),
514 value);
515 }
516
517 void TestRunnerForSpecificView::DidAcquirePointerLock() {
518 DidAcquirePointerLockInternal();
519 }
520
521 void TestRunnerForSpecificView::DidNotAcquirePointerLock() {
522 DidNotAcquirePointerLockInternal();
523 }
524
525 void TestRunnerForSpecificView::DidLosePointerLock() {
526 DidLosePointerLockInternal();
527 }
528
529 void TestRunnerForSpecificView::SetPointerLockWillFailSynchronously() {
530 pointer_lock_planned_result_ = PointerLockWillFailSync;
531 }
532
533 void TestRunnerForSpecificView::SetPointerLockWillRespondAsynchronously() {
534 pointer_lock_planned_result_ = PointerLockWillRespondAsync;
535 }
536
537 void TestRunnerForSpecificView::DidAcquirePointerLockInternal() {
538 pointer_locked_ = true;
539 web_view()->didAcquirePointerLock();
540
541 // Reset planned result to default.
542 pointer_lock_planned_result_ = PointerLockWillSucceed;
543 }
544
545 void TestRunnerForSpecificView::DidNotAcquirePointerLockInternal() {
546 DCHECK(!pointer_locked_);
547 pointer_locked_ = false;
548 web_view()->didNotAcquirePointerLock();
549
550 // Reset planned result to default.
551 pointer_lock_planned_result_ = PointerLockWillSucceed;
552 }
553
554 void TestRunnerForSpecificView::DidLosePointerLockInternal() {
555 bool was_locked = pointer_locked_;
556 pointer_locked_ = false;
557 if (was_locked)
558 web_view()->didLosePointerLock();
559 }
560
2238 bool TestRunnerForSpecificView::CallShouldCloseOnWebView() { 561 bool TestRunnerForSpecificView::CallShouldCloseOnWebView() {
2239 return web_view()->mainFrame()->dispatchBeforeUnloadEvent(); 562 return web_view()->mainFrame()->dispatchBeforeUnloadEvent();
2240 } 563 }
2241 564
2242 void TestRunnerForSpecificView::SetDomainRelaxationForbiddenForURLScheme( 565 void TestRunnerForSpecificView::SetDomainRelaxationForbiddenForURLScheme(
2243 bool forbidden, 566 bool forbidden,
2244 const std::string& scheme) { 567 const std::string& scheme) {
2245 web_view()->setDomainRelaxationForbidden(forbidden, 568 web_view()->setDomainRelaxationForbidden(forbidden,
2246 WebString::fromUTF8(scheme)); 569 WebString::fromUTF8(scheme));
2247 } 570 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2285 web_origin); 608 web_origin);
2286 } 609 }
2287 610
2288 void TestRunnerForSpecificView::SetIsolatedWorldContentSecurityPolicy( 611 void TestRunnerForSpecificView::SetIsolatedWorldContentSecurityPolicy(
2289 int world_id, 612 int world_id,
2290 const std::string& policy) { 613 const std::string& policy) {
2291 web_view()->focusedFrame()->setIsolatedWorldContentSecurityPolicy( 614 web_view()->focusedFrame()->setIsolatedWorldContentSecurityPolicy(
2292 world_id, WebString::fromUTF8(policy)); 615 world_id, WebString::fromUTF8(policy));
2293 } 616 }
2294 617
2295 void TestRunner::AddOriginAccessWhitelistEntry(
2296 const std::string& source_origin,
2297 const std::string& destination_protocol,
2298 const std::string& destination_host,
2299 bool allow_destination_subdomains) {
2300 WebURL url((GURL(source_origin)));
2301 if (!url.isValid())
2302 return;
2303
2304 WebSecurityPolicy::addOriginAccessWhitelistEntry(
2305 url,
2306 WebString::fromUTF8(destination_protocol),
2307 WebString::fromUTF8(destination_host),
2308 allow_destination_subdomains);
2309 }
2310
2311 void TestRunner::RemoveOriginAccessWhitelistEntry(
2312 const std::string& source_origin,
2313 const std::string& destination_protocol,
2314 const std::string& destination_host,
2315 bool allow_destination_subdomains) {
2316 WebURL url((GURL(source_origin)));
2317 if (!url.isValid())
2318 return;
2319
2320 WebSecurityPolicy::removeOriginAccessWhitelistEntry(
2321 url,
2322 WebString::fromUTF8(destination_protocol),
2323 WebString::fromUTF8(destination_host),
2324 allow_destination_subdomains);
2325 }
2326
2327 bool TestRunnerForSpecificView::HasCustomPageSizeStyle(int page_index) {
2328 WebFrame* frame = web_view()->mainFrame();
2329 if (!frame)
2330 return false;
2331 return frame->hasCustomPageSizeStyle(page_index);
2332 }
2333
2334 void TestRunnerForSpecificView::ForceRedSelectionColors() {
2335 web_view()->setSelectionColors(
2336 0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0);
2337 }
2338
2339 void TestRunner::InsertStyleSheet(const std::string& source_code) { 618 void TestRunner::InsertStyleSheet(const std::string& source_code) {
2340 WebLocalFrame::frameForCurrentContext()->document().insertStyleSheet( 619 WebLocalFrame::frameForCurrentContext()->document().insertStyleSheet(
2341 WebString::fromUTF8(source_code)); 620 WebString::fromUTF8(source_code));
2342 } 621 }
2343 622
2344 bool TestRunnerForSpecificView::FindString( 623 bool TestRunnerForSpecificView::FindString(
2345 const std::string& search_text, 624 const std::string& search_text,
2346 const std::vector<std::string>& options_array) { 625 const std::vector<std::string>& options_array) {
2347 WebFindOptions find_options; 626 WebFindOptions find_options;
2348 bool wrap_around = false; 627 bool wrap_around = false;
(...skipping 19 matching lines...) Expand all
2368 const bool find_result = frame->find(0, WebString::fromUTF8(search_text), 647 const bool find_result = frame->find(0, WebString::fromUTF8(search_text),
2369 find_options, wrap_around, 0); 648 find_options, wrap_around, 0);
2370 frame->stopFinding(false); 649 frame->stopFinding(false);
2371 return find_result; 650 return find_result;
2372 } 651 }
2373 652
2374 std::string TestRunnerForSpecificView::SelectionAsMarkup() { 653 std::string TestRunnerForSpecificView::SelectionAsMarkup() {
2375 return web_view()->mainFrame()->selectionAsMarkup().utf8(); 654 return web_view()->mainFrame()->selectionAsMarkup().utf8();
2376 } 655 }
2377 656
2378 void TestRunner::SetTextSubpixelPositioning(bool value) {
2379 #if defined(__linux__) || defined(ANDROID)
2380 // Since FontConfig doesn't provide a variable to control subpixel
2381 // positioning, we'll fall back to setting it globally for all fonts.
2382 WebFontRendering::setSubpixelPositioning(value);
2383 #endif
2384 }
2385
2386 void TestRunnerForSpecificView::SetPageVisibility(
2387 const std::string& new_visibility) {
2388 if (new_visibility == "visible")
2389 web_view()->setVisibilityState(WebPageVisibilityStateVisible, false);
2390 else if (new_visibility == "hidden")
2391 web_view()->setVisibilityState(WebPageVisibilityStateHidden, false);
2392 else if (new_visibility == "prerender")
2393 web_view()->setVisibilityState(WebPageVisibilityStatePrerender, false);
2394 }
2395
2396 void TestRunnerForSpecificView::SetTextDirection(
2397 const std::string& direction_name) {
2398 // Map a direction name to a WebTextDirection value.
2399 WebTextDirection direction;
2400 if (direction_name == "auto")
2401 direction = WebTextDirectionDefault;
2402 else if (direction_name == "rtl")
2403 direction = WebTextDirectionRightToLeft;
2404 else if (direction_name == "ltr")
2405 direction = WebTextDirectionLeftToRight;
2406 else
2407 return;
2408
2409 web_view()->setTextDirection(direction);
2410 }
2411
2412 void TestRunner::UseUnfortunateSynchronousResizeMode() {
2413 delegate_->UseUnfortunateSynchronousResizeMode(true);
2414 }
2415
2416 bool TestRunner::EnableAutoResizeMode(int min_width,
2417 int min_height,
2418 int max_width,
2419 int max_height) {
2420 WebSize min_size(min_width, min_height);
2421 WebSize max_size(max_width, max_height);
2422 delegate_->EnableAutoResizeMode(min_size, max_size);
2423 return true;
2424 }
2425
2426 bool TestRunner::DisableAutoResizeMode(int new_width, int new_height) {
2427 WebSize new_size(new_width, new_height);
2428 delegate_->DisableAutoResizeMode(new_size);
2429 return true;
2430 }
2431
2432 void TestRunner::SetMockDeviceLight(double value) {
2433 delegate_->SetDeviceLightData(value);
2434 }
2435
2436 void TestRunner::ResetDeviceLight() {
2437 delegate_->SetDeviceLightData(-1);
2438 }
2439
2440 void TestRunner::SetMockDeviceMotion(
2441 bool has_acceleration_x, double acceleration_x,
2442 bool has_acceleration_y, double acceleration_y,
2443 bool has_acceleration_z, double acceleration_z,
2444 bool has_acceleration_including_gravity_x,
2445 double acceleration_including_gravity_x,
2446 bool has_acceleration_including_gravity_y,
2447 double acceleration_including_gravity_y,
2448 bool has_acceleration_including_gravity_z,
2449 double acceleration_including_gravity_z,
2450 bool has_rotation_rate_alpha, double rotation_rate_alpha,
2451 bool has_rotation_rate_beta, double rotation_rate_beta,
2452 bool has_rotation_rate_gamma, double rotation_rate_gamma,
2453 double interval) {
2454 WebDeviceMotionData motion;
2455
2456 // acceleration
2457 motion.hasAccelerationX = has_acceleration_x;
2458 motion.accelerationX = acceleration_x;
2459 motion.hasAccelerationY = has_acceleration_y;
2460 motion.accelerationY = acceleration_y;
2461 motion.hasAccelerationZ = has_acceleration_z;
2462 motion.accelerationZ = acceleration_z;
2463
2464 // accelerationIncludingGravity
2465 motion.hasAccelerationIncludingGravityX =
2466 has_acceleration_including_gravity_x;
2467 motion.accelerationIncludingGravityX = acceleration_including_gravity_x;
2468 motion.hasAccelerationIncludingGravityY =
2469 has_acceleration_including_gravity_y;
2470 motion.accelerationIncludingGravityY = acceleration_including_gravity_y;
2471 motion.hasAccelerationIncludingGravityZ =
2472 has_acceleration_including_gravity_z;
2473 motion.accelerationIncludingGravityZ = acceleration_including_gravity_z;
2474
2475 // rotationRate
2476 motion.hasRotationRateAlpha = has_rotation_rate_alpha;
2477 motion.rotationRateAlpha = rotation_rate_alpha;
2478 motion.hasRotationRateBeta = has_rotation_rate_beta;
2479 motion.rotationRateBeta = rotation_rate_beta;
2480 motion.hasRotationRateGamma = has_rotation_rate_gamma;
2481 motion.rotationRateGamma = rotation_rate_gamma;
2482
2483 // interval
2484 motion.interval = interval;
2485
2486 delegate_->SetDeviceMotionData(motion);
2487 }
2488
2489 void TestRunner::SetMockDeviceOrientation(bool has_alpha, double alpha,
2490 bool has_beta, double beta,
2491 bool has_gamma, double gamma,
2492 bool absolute) {
2493 WebDeviceOrientationData orientation;
2494
2495 // alpha
2496 orientation.hasAlpha = has_alpha;
2497 orientation.alpha = alpha;
2498
2499 // beta
2500 orientation.hasBeta = has_beta;
2501 orientation.beta = beta;
2502
2503 // gamma
2504 orientation.hasGamma = has_gamma;
2505 orientation.gamma = gamma;
2506
2507 // absolute
2508 orientation.absolute = absolute;
2509
2510 delegate_->SetDeviceOrientationData(orientation);
2511 }
2512
2513 MockScreenOrientationClient* TestRunner::getMockScreenOrientationClient() {
2514 return mock_screen_orientation_client_.get();
2515 }
2516
2517 MockWebUserMediaClient* TestRunner::getMockWebUserMediaClient() {
2518 if (!user_media_client_.get())
2519 user_media_client_.reset(new MockWebUserMediaClient(delegate_));
2520 return user_media_client_.get();
2521 }
2522
2523 MockWebSpeechRecognizer* TestRunner::getMockWebSpeechRecognizer() {
2524 if (!speech_recognizer_.get()) {
2525 speech_recognizer_.reset(new MockWebSpeechRecognizer());
2526 speech_recognizer_->SetDelegate(delegate_);
2527 }
2528 return speech_recognizer_.get();
2529 }
2530
2531 void TestRunner::SetMockScreenOrientation(const std::string& orientation_str) {
2532 blink::WebScreenOrientationType orientation;
2533
2534 if (orientation_str == "portrait-primary") {
2535 orientation = WebScreenOrientationPortraitPrimary;
2536 } else if (orientation_str == "portrait-secondary") {
2537 orientation = WebScreenOrientationPortraitSecondary;
2538 } else if (orientation_str == "landscape-primary") {
2539 orientation = WebScreenOrientationLandscapePrimary;
2540 } else {
2541 DCHECK_EQ("landscape-secondary", orientation_str);
2542 orientation = WebScreenOrientationLandscapeSecondary;
2543 }
2544
2545 for (WebTestProxyBase* window : test_interfaces_->GetWindowList()) {
2546 WebFrame* main_frame = window->web_view()->mainFrame();
2547 // TODO(lukasza): Need to make this work for remote frames.
2548 if (main_frame->isWebLocalFrame()) {
2549 mock_screen_orientation_client_->UpdateDeviceOrientation(
2550 main_frame->toWebLocalFrame(), orientation);
2551 }
2552 }
2553 }
2554
2555 void TestRunner::DisableMockScreenOrientation() {
2556 mock_screen_orientation_client_->SetDisabled(true);
2557 }
2558
2559 void TestRunner::DidOpenChooser() {
2560 chooser_count_++;
2561 }
2562
2563 void TestRunner::DidCloseChooser() {
2564 chooser_count_--;
2565 DCHECK_LE(0, chooser_count_);
2566 }
2567
2568 void TestRunnerForSpecificView::DidAcquirePointerLock() {
2569 DidAcquirePointerLockInternal();
2570 }
2571
2572 void TestRunnerForSpecificView::DidNotAcquirePointerLock() {
2573 DidNotAcquirePointerLockInternal();
2574 }
2575
2576 void TestRunnerForSpecificView::DidLosePointerLock() {
2577 DidLosePointerLockInternal();
2578 }
2579
2580 void TestRunnerForSpecificView::SetPointerLockWillFailSynchronously() {
2581 pointer_lock_planned_result_ = PointerLockWillFailSync;
2582 }
2583
2584 void TestRunnerForSpecificView::SetPointerLockWillRespondAsynchronously() {
2585 pointer_lock_planned_result_ = PointerLockWillRespondAsync;
2586 }
2587
2588 void TestRunner::SetPopupBlockingEnabled(bool block_popups) {
2589 delegate_->Preferences()->java_script_can_open_windows_automatically =
2590 !block_popups;
2591 delegate_->ApplyPreferences();
2592 }
2593
2594 void TestRunner::SetJavaScriptCanAccessClipboard(bool can_access) {
2595 delegate_->Preferences()->java_script_can_access_clipboard = can_access;
2596 delegate_->ApplyPreferences();
2597 }
2598
2599 void TestRunner::SetXSSAuditorEnabled(bool enabled) {
2600 delegate_->Preferences()->xss_auditor_enabled = enabled;
2601 delegate_->ApplyPreferences();
2602 }
2603
2604 void TestRunner::SetAllowUniversalAccessFromFileURLs(bool allow) {
2605 delegate_->Preferences()->allow_universal_access_from_file_urls = allow;
2606 delegate_->ApplyPreferences();
2607 }
2608
2609 void TestRunner::SetAllowFileAccessFromFileURLs(bool allow) {
2610 delegate_->Preferences()->allow_file_access_from_file_urls = allow;
2611 delegate_->ApplyPreferences();
2612 }
2613
2614 void TestRunner::OverridePreference(const std::string& key,
2615 v8::Local<v8::Value> value) {
2616 TestPreferences* prefs = delegate_->Preferences();
2617 if (key == "WebKitDefaultFontSize") {
2618 prefs->default_font_size = value->Int32Value();
2619 } else if (key == "WebKitMinimumFontSize") {
2620 prefs->minimum_font_size = value->Int32Value();
2621 } else if (key == "WebKitDefaultTextEncodingName") {
2622 v8::Isolate* isolate = blink::mainThreadIsolate();
2623 prefs->default_text_encoding_name =
2624 V8StringToWebString(value->ToString(isolate));
2625 } else if (key == "WebKitJavaScriptEnabled") {
2626 prefs->java_script_enabled = value->BooleanValue();
2627 } else if (key == "WebKitSupportsMultipleWindows") {
2628 prefs->supports_multiple_windows = value->BooleanValue();
2629 } else if (key == "WebKitDisplayImagesKey") {
2630 prefs->loads_images_automatically = value->BooleanValue();
2631 } else if (key == "WebKitPluginsEnabled") {
2632 prefs->plugins_enabled = value->BooleanValue();
2633 } else if (key == "WebKitTabToLinksPreferenceKey") {
2634 prefs->tabs_to_links = value->BooleanValue();
2635 } else if (key == "WebKitWebGLEnabled") {
2636 prefs->experimental_webgl_enabled = value->BooleanValue();
2637 } else if (key == "WebKitCSSGridLayoutEnabled") {
2638 prefs->experimental_css_grid_layout_enabled = value->BooleanValue();
2639 } else if (key == "WebKitHyperlinkAuditingEnabled") {
2640 prefs->hyperlink_auditing_enabled = value->BooleanValue();
2641 } else if (key == "WebKitEnableCaretBrowsing") {
2642 prefs->caret_browsing_enabled = value->BooleanValue();
2643 } else if (key == "WebKitAllowDisplayingInsecureContent") {
2644 prefs->allow_display_of_insecure_content = value->BooleanValue();
2645 } else if (key == "WebKitAllowRunningInsecureContent") {
2646 prefs->allow_running_of_insecure_content = value->BooleanValue();
2647 } else if (key == "WebKitDisableReadingFromCanvas") {
2648 prefs->disable_reading_from_canvas = value->BooleanValue();
2649 } else if (key == "WebKitStrictMixedContentChecking") {
2650 prefs->strict_mixed_content_checking = value->BooleanValue();
2651 } else if (key == "WebKitStrictPowerfulFeatureRestrictions") {
2652 prefs->strict_powerful_feature_restrictions = value->BooleanValue();
2653 } else if (key == "WebKitShouldRespectImageOrientation") {
2654 prefs->should_respect_image_orientation = value->BooleanValue();
2655 } else if (key == "WebKitWebSecurityEnabled") {
2656 prefs->web_security_enabled = value->BooleanValue();
2657 } else {
2658 std::string message("Invalid name for preference: ");
2659 message.append(key);
2660 delegate_->PrintMessage(std::string("CONSOLE MESSAGE: ") + message + "\n");
2661 }
2662 delegate_->ApplyPreferences();
2663 }
2664
2665 std::string TestRunner::GetAcceptLanguages() const {
2666 return layout_test_runtime_flags_.accept_languages();
2667 }
2668
2669 void TestRunner::SetAcceptLanguages(const std::string& accept_languages) {
2670 if (accept_languages == GetAcceptLanguages())
2671 return;
2672
2673 layout_test_runtime_flags_.set_accept_languages(accept_languages);
2674 OnLayoutTestRuntimeFlagsChanged();
2675
2676 for (WebTestProxyBase* window : test_interfaces_->GetWindowList())
2677 window->web_view()->acceptLanguagesChanged();
2678 }
2679
2680 void TestRunner::SetPluginsEnabled(bool enabled) {
2681 delegate_->Preferences()->plugins_enabled = enabled;
2682 delegate_->ApplyPreferences();
2683 }
2684
2685 bool TestRunner::GetAnimationScheduled() const {
2686 bool is_animation_scheduled = !views_with_scheduled_animations_.empty();
2687 return is_animation_scheduled;
2688 }
2689
2690 void TestRunner::OnAnimationScheduled(blink::WebView* view) {
2691 views_with_scheduled_animations_.insert(view);
2692 }
2693
2694 void TestRunner::OnAnimationBegun(blink::WebView* view) {
2695 views_with_scheduled_animations_.erase(view);
2696 }
2697
2698 void TestRunner::DumpEditingCallbacks() {
2699 layout_test_runtime_flags_.set_dump_editting_callbacks(true);
2700 OnLayoutTestRuntimeFlagsChanged();
2701 }
2702
2703 void TestRunner::DumpAsMarkup() {
2704 layout_test_runtime_flags_.set_dump_as_markup(true);
2705 layout_test_runtime_flags_.set_generate_pixel_results(false);
2706 OnLayoutTestRuntimeFlagsChanged();
2707 }
2708
2709 void TestRunner::DumpAsText() {
2710 layout_test_runtime_flags_.set_dump_as_text(true);
2711 layout_test_runtime_flags_.set_generate_pixel_results(false);
2712 OnLayoutTestRuntimeFlagsChanged();
2713 }
2714
2715 void TestRunner::DumpAsTextWithPixelResults() {
2716 layout_test_runtime_flags_.set_dump_as_text(true);
2717 layout_test_runtime_flags_.set_generate_pixel_results(true);
2718 OnLayoutTestRuntimeFlagsChanged();
2719 }
2720
2721 void TestRunner::DumpChildFrameScrollPositions() {
2722 layout_test_runtime_flags_.set_dump_child_frame_scroll_positions(true);
2723 OnLayoutTestRuntimeFlagsChanged();
2724 }
2725
2726 void TestRunner::DumpChildFramesAsMarkup() {
2727 layout_test_runtime_flags_.set_dump_child_frames_as_markup(true);
2728 OnLayoutTestRuntimeFlagsChanged();
2729 }
2730
2731 void TestRunner::DumpChildFramesAsText() {
2732 layout_test_runtime_flags_.set_dump_child_frames_as_text(true);
2733 OnLayoutTestRuntimeFlagsChanged();
2734 }
2735
2736 void TestRunner::DumpIconChanges() {
2737 layout_test_runtime_flags_.set_dump_icon_changes(true);
2738 OnLayoutTestRuntimeFlagsChanged();
2739 }
2740
2741 void TestRunner::SetAudioData(const gin::ArrayBufferView& view) {
2742 unsigned char* bytes = static_cast<unsigned char*>(view.bytes());
2743 audio_data_.resize(view.num_bytes());
2744 std::copy(bytes, bytes + view.num_bytes(), audio_data_.begin());
2745 dump_as_audio_ = true;
2746 }
2747
2748 void TestRunner::DumpFrameLoadCallbacks() {
2749 layout_test_runtime_flags_.set_dump_frame_load_callbacks(true);
2750 OnLayoutTestRuntimeFlagsChanged();
2751 }
2752
2753 void TestRunner::DumpPingLoaderCallbacks() {
2754 layout_test_runtime_flags_.set_dump_ping_loader_callbacks(true);
2755 OnLayoutTestRuntimeFlagsChanged();
2756 }
2757
2758 void TestRunner::DumpUserGestureInFrameLoadCallbacks() {
2759 layout_test_runtime_flags_.set_dump_user_gesture_in_frame_load_callbacks(
2760 true);
2761 OnLayoutTestRuntimeFlagsChanged();
2762 }
2763
2764 void TestRunner::DumpTitleChanges() {
2765 layout_test_runtime_flags_.set_dump_title_changes(true);
2766 OnLayoutTestRuntimeFlagsChanged();
2767 }
2768
2769 void TestRunner::DumpCreateView() {
2770 dump_create_view_ = true;
2771 }
2772
2773 void TestRunner::SetCanOpenWindows() {
2774 can_open_windows_ = true;
2775 }
2776
2777 void TestRunner::DumpResourceLoadCallbacks() {
2778 layout_test_runtime_flags_.set_dump_resource_load_callbacks(true);
2779 OnLayoutTestRuntimeFlagsChanged();
2780 }
2781
2782 void TestRunner::DumpResourceResponseMIMETypes() {
2783 layout_test_runtime_flags_.set_dump_resource_response_mime_types(true);
2784 OnLayoutTestRuntimeFlagsChanged();
2785 }
2786
2787 void TestRunner::SetImagesAllowed(bool allowed) {
2788 layout_test_runtime_flags_.set_images_allowed(allowed);
2789 OnLayoutTestRuntimeFlagsChanged();
2790 }
2791
2792 void TestRunner::SetMediaAllowed(bool allowed) {
2793 layout_test_runtime_flags_.set_media_allowed(allowed);
2794 OnLayoutTestRuntimeFlagsChanged();
2795 }
2796
2797 void TestRunner::SetScriptsAllowed(bool allowed) {
2798 layout_test_runtime_flags_.set_scripts_allowed(allowed);
2799 OnLayoutTestRuntimeFlagsChanged();
2800 }
2801
2802 void TestRunner::SetStorageAllowed(bool allowed) {
2803 layout_test_runtime_flags_.set_storage_allowed(allowed);
2804 OnLayoutTestRuntimeFlagsChanged();
2805 }
2806
2807 void TestRunner::SetPluginsAllowed(bool allowed) {
2808 layout_test_runtime_flags_.set_plugins_allowed(allowed);
2809 OnLayoutTestRuntimeFlagsChanged();
2810 }
2811
2812 void TestRunner::SetAllowDisplayOfInsecureContent(bool allowed) {
2813 layout_test_runtime_flags_.set_displaying_insecure_content_allowed(allowed);
2814 OnLayoutTestRuntimeFlagsChanged();
2815 }
2816
2817 void TestRunner::SetAllowRunningOfInsecureContent(bool allowed) {
2818 layout_test_runtime_flags_.set_running_insecure_content_allowed(allowed);
2819 OnLayoutTestRuntimeFlagsChanged();
2820 }
2821
2822 void TestRunner::SetAutoplayAllowed(bool allowed) {
2823 layout_test_runtime_flags_.set_autoplay_allowed(allowed);
2824 OnLayoutTestRuntimeFlagsChanged();
2825 }
2826
2827 void TestRunner::DumpPermissionClientCallbacks() {
2828 layout_test_runtime_flags_.set_dump_web_content_settings_client_callbacks(
2829 true);
2830 OnLayoutTestRuntimeFlagsChanged();
2831 }
2832
2833 void TestRunner::DumpWindowStatusChanges() {
2834 dump_window_status_changes_ = true;
2835 }
2836
2837 void TestRunner::DumpSpellCheckCallbacks() {
2838 dump_spell_check_callbacks_ = true;
2839 }
2840
2841 void TestRunner::DumpBackForwardList() {
2842 dump_back_forward_list_ = true;
2843 }
2844
2845 void TestRunner::DumpSelectionRect() {
2846 layout_test_runtime_flags_.set_dump_selection_rect(true);
2847 OnLayoutTestRuntimeFlagsChanged();
2848 }
2849
2850 void TestRunner::SetPrinting() {
2851 layout_test_runtime_flags_.set_is_printing(true);
2852 OnLayoutTestRuntimeFlagsChanged();
2853 }
2854
2855 void TestRunner::ClearPrinting() {
2856 layout_test_runtime_flags_.set_is_printing(false);
2857 OnLayoutTestRuntimeFlagsChanged();
2858 }
2859
2860 void TestRunner::SetShouldStayOnPageAfterHandlingBeforeUnload(bool value) {
2861 layout_test_runtime_flags_.set_stay_on_page_after_handling_before_unload(
2862 value);
2863 OnLayoutTestRuntimeFlagsChanged();
2864 }
2865
2866 void TestRunner::SetWillSendRequestClearHeader(const std::string& header) {
2867 if (!header.empty())
2868 http_headers_to_clear_.insert(header);
2869 }
2870
2871 void TestRunner::DumpResourceRequestPriorities() {
2872 layout_test_runtime_flags_.set_dump_resource_priorities(true);
2873 OnLayoutTestRuntimeFlagsChanged();
2874 }
2875
2876 void TestRunner::SetUseMockTheme(bool use) {
2877 use_mock_theme_ = use;
2878 blink::setMockThemeEnabledForTest(use);
2879 }
2880
2881 void TestRunner::ShowWebInspector(const std::string& str,
2882 const std::string& frontend_url) {
2883 ShowDevTools(str, frontend_url);
2884 }
2885
2886 void TestRunner::WaitUntilExternalURLLoad() {
2887 layout_test_runtime_flags_.set_wait_until_external_url_load(true);
2888 OnLayoutTestRuntimeFlagsChanged();
2889 }
2890
2891 void TestRunner::DumpDragImage() {
2892 layout_test_runtime_flags_.set_dump_drag_image(true);
2893 DumpAsTextWithPixelResults();
2894 OnLayoutTestRuntimeFlagsChanged();
2895 }
2896
2897 void TestRunner::DumpNavigationPolicy() {
2898 layout_test_runtime_flags_.set_dump_navigation_policy(true);
2899 OnLayoutTestRuntimeFlagsChanged();
2900 }
2901
2902 void TestRunnerForSpecificView::DumpPageImportanceSignals() {
2903 blink::WebPageImportanceSignals* signals =
2904 web_view()->pageImportanceSignals();
2905 if (!signals)
2906 return;
2907
2908 std::string message = base::StringPrintf(
2909 "WebPageImportanceSignals:\n"
2910 " hadFormInteraction: %s\n"
2911 " issuedNonGetFetchFromScript: %s\n",
2912 signals->hadFormInteraction() ? "true" : "false",
2913 signals->issuedNonGetFetchFromScript() ? "true" : "false");
2914 if (delegate())
2915 delegate()->PrintMessage(message);
2916 }
2917
2918 void TestRunner::CloseWebInspector() {
2919 delegate_->CloseDevTools();
2920 }
2921
2922 bool TestRunner::IsChooserShown() {
2923 return 0 < chooser_count_;
2924 }
2925
2926 void TestRunner::EvaluateInWebInspector(int call_id,
2927 const std::string& script) {
2928 delegate_->EvaluateInWebInspector(call_id, script);
2929 }
2930
2931 std::string TestRunner::EvaluateInWebInspectorOverlay(
2932 const std::string& script) {
2933 return delegate_->EvaluateInWebInspectorOverlay(script);
2934 }
2935
2936 void TestRunner::ClearAllDatabases() {
2937 delegate_->ClearAllDatabases();
2938 }
2939
2940 void TestRunner::SetDatabaseQuota(int quota) {
2941 delegate_->SetDatabaseQuota(quota);
2942 }
2943
2944 void TestRunner::SetAlwaysAcceptCookies(bool accept) {
2945 delegate_->SetAcceptAllCookies(accept);
2946 }
2947
2948 void TestRunnerForSpecificView::SetWindowIsKey(bool value) {
2949 web_test_proxy_base_->test_interfaces()->GetTestRunner()->SetFocus(web_view(),
2950 value);
2951 }
2952
2953 void TestRunner::SetFocus(blink::WebView* web_view, bool focus) {
2954 if (focus) {
2955 if (previously_focused_view_ != web_view) {
2956 delegate_->SetFocus(previously_focused_view_, false);
2957 delegate_->SetFocus(web_view, true);
2958 previously_focused_view_ = web_view;
2959 }
2960 } else {
2961 if (previously_focused_view_ == web_view) {
2962 delegate_->SetFocus(web_view, false);
2963 previously_focused_view_ = nullptr;
2964 }
2965 }
2966 }
2967
2968 std::string TestRunner::PathToLocalResource(const std::string& path) {
2969 return delegate_->PathToLocalResource(path);
2970 }
2971
2972 void TestRunnerForSpecificView::SetBackingScaleFactor(
2973 double value,
2974 v8::Local<v8::Function> callback) {
2975 delegate()->SetDeviceScaleFactor(value);
2976 PostV8Callback(callback);
2977 }
2978
2979 void TestRunnerForSpecificView::EnableUseZoomForDSF(
2980 v8::Local<v8::Function> callback) {
2981 delegate()->EnableUseZoomForDSF();
2982 PostV8Callback(callback);
2983 }
2984
2985 void TestRunnerForSpecificView::SetColorProfile(
2986 const std::string& name,
2987 v8::Local<v8::Function> callback) {
2988 delegate()->SetDeviceColorProfile(name);
2989 PostV8Callback(callback);
2990 }
2991
2992 void TestRunnerForSpecificView::SetBluetoothFakeAdapter(
2993 const std::string& adapter_name,
2994 v8::Local<v8::Function> callback) {
2995 delegate()->SetBluetoothFakeAdapter(
2996 adapter_name, CreateClosureThatPostsV8Callback(callback));
2997 }
2998
2999 void TestRunnerForSpecificView::SetBluetoothManualChooser(bool enable) {
3000 delegate()->SetBluetoothManualChooser(enable);
3001 }
3002
3003 void TestRunnerForSpecificView::GetBluetoothManualChooserEvents(
3004 v8::Local<v8::Function> callback) {
3005 return delegate()->GetBluetoothManualChooserEvents(base::Bind(
3006 &TestRunnerForSpecificView::GetBluetoothManualChooserEventsCallback,
3007 weak_factory_.GetWeakPtr(),
3008 base::Passed(v8::UniquePersistent<v8::Function>(
3009 blink::mainThreadIsolate(), callback))));
3010 }
3011
3012 void TestRunnerForSpecificView::SendBluetoothManualChooserEvent(
3013 const std::string& event,
3014 const std::string& argument) {
3015 delegate()->SendBluetoothManualChooserEvent(event, argument);
3016 }
3017
3018 void TestRunner::SetGeofencingMockProvider(bool service_available) {
3019 delegate_->SetGeofencingMockProvider(service_available);
3020 }
3021
3022 void TestRunner::ClearGeofencingMockProvider() {
3023 delegate_->ClearGeofencingMockProvider();
3024 }
3025
3026 void TestRunner::SetGeofencingMockPosition(double latitude, double longitude) {
3027 delegate_->SetGeofencingMockPosition(latitude, longitude);
3028 }
3029
3030 void TestRunner::SetPermission(const std::string& name,
3031 const std::string& value,
3032 const GURL& origin,
3033 const GURL& embedding_origin) {
3034 delegate_->SetPermission(name, value, origin, embedding_origin);
3035 }
3036
3037 void TestRunnerForSpecificView::DispatchBeforeInstallPromptEvent(
3038 int request_id,
3039 const std::vector<std::string>& event_platforms,
3040 v8::Local<v8::Function> callback) {
3041 delegate()->DispatchBeforeInstallPromptEvent(
3042 request_id, event_platforms,
3043 base::Bind(
3044 &TestRunnerForSpecificView::DispatchBeforeInstallPromptCallback,
3045 weak_factory_.GetWeakPtr(),
3046 base::Passed(v8::UniquePersistent<v8::Function>(
3047 blink::mainThreadIsolate(), callback))));
3048 }
3049
3050 void TestRunner::ResolveBeforeInstallPromptPromise(
3051 int request_id,
3052 const std::string& platform) {
3053 if (!test_interfaces_->GetAppBannerClient())
3054 return;
3055 test_interfaces_->GetAppBannerClient()->ResolvePromise(request_id, platform);
3056 }
3057
3058 void TestRunnerForSpecificView::RunIdleTasks(v8::Local<v8::Function> callback) {
3059 delegate()->RunIdleTasks(CreateClosureThatPostsV8Callback(callback));
3060 }
3061
3062 void TestRunner::SetPOSIXLocale(const std::string& locale) {
3063 delegate_->SetLocale(locale);
3064 }
3065
3066 void TestRunner::SetMIDIAccessorResult(bool result) {
3067 midi_accessor_result_ = result;
3068 }
3069
3070 void TestRunner::SimulateWebNotificationClick(const std::string& title,
3071 int action_index) {
3072 delegate_->SimulateWebNotificationClick(title, action_index);
3073 }
3074
3075 void TestRunner::SimulateWebNotificationClose(const std::string& title,
3076 bool by_user) {
3077 delegate_->SimulateWebNotificationClose(title, by_user);
3078 }
3079
3080 void TestRunner::AddMockSpeechRecognitionResult(const std::string& transcript,
3081 double confidence) {
3082 getMockWebSpeechRecognizer()->AddMockResult(WebString::fromUTF8(transcript),
3083 confidence);
3084 }
3085
3086 void TestRunner::SetMockSpeechRecognitionError(const std::string& error,
3087 const std::string& message) {
3088 getMockWebSpeechRecognizer()->SetError(WebString::fromUTF8(error),
3089 WebString::fromUTF8(message));
3090 }
3091
3092 void TestRunner::AddMockCredentialManagerResponse(const std::string& id,
3093 const std::string& name,
3094 const std::string& avatar,
3095 const std::string& password) {
3096 credential_manager_client_->SetResponse(new WebPasswordCredential(
3097 WebString::fromUTF8(id), WebString::fromUTF8(password),
3098 WebString::fromUTF8(name), WebURL(GURL(avatar))));
3099 }
3100
3101 void TestRunner::AddMockCredentialManagerError(const std::string& error) {
3102 credential_manager_client_->SetError(error);
3103 }
3104
3105 void TestRunnerForSpecificView::AddWebPageOverlay() {
3106 web_view()->setPageOverlayColor(SK_ColorCYAN);
3107 }
3108
3109 void TestRunnerForSpecificView::RemoveWebPageOverlay() {
3110 web_view()->setPageOverlayColor(SK_ColorTRANSPARENT);
3111 }
3112
3113 void TestRunnerForSpecificView::LayoutAndPaintAsync() {
3114 test_runner::LayoutAndPaintAsyncThen(web_view(), base::Closure());
3115 }
3116
3117 void TestRunnerForSpecificView::LayoutAndPaintAsyncThen(
3118 v8::Local<v8::Function> callback) {
3119 test_runner::LayoutAndPaintAsyncThen(
3120 web_view(), CreateClosureThatPostsV8Callback(callback));
3121 }
3122
3123 void TestRunnerForSpecificView::GetManifestThen(
3124 v8::Local<v8::Function> callback) {
3125 v8::UniquePersistent<v8::Function> persistent_callback(
3126 blink::mainThreadIsolate(), callback);
3127
3128 delegate()->FetchManifest(
3129 web_view(), web_view()->mainFrame()->document().manifestURL(),
3130 base::Bind(&TestRunnerForSpecificView::GetManifestCallback,
3131 weak_factory_.GetWeakPtr(),
3132 base::Passed(std::move(persistent_callback))));
3133 }
3134
3135 void TestRunnerForSpecificView::CapturePixelsAsyncThen(
3136 v8::Local<v8::Function> callback) {
3137 v8::UniquePersistent<v8::Function> persistent_callback(
3138 blink::mainThreadIsolate(), callback);
3139
3140 web_test_proxy_base_->test_interfaces()->GetTestRunner()->DumpPixelsAsync(
3141 web_view(), base::Bind(&TestRunnerForSpecificView::CapturePixelsCallback,
3142 weak_factory_.GetWeakPtr(),
3143 base::Passed(std::move(persistent_callback))));
3144 }
3145
3146 void TestRunner::OnLayoutTestRuntimeFlagsChanged() {
3147 if (layout_test_runtime_flags_.tracked_dictionary().changed_values().empty())
3148 return;
3149 if (!test_is_running_)
3150 return;
3151
3152 delegate_->OnLayoutTestRuntimeFlagsChanged(
3153 layout_test_runtime_flags_.tracked_dictionary().changed_values());
3154 layout_test_runtime_flags_.tracked_dictionary().ResetChangeTracking();
3155 }
3156
3157 void TestRunnerForSpecificView::ForceNextWebGLContextCreationToFail() {
3158 web_view()->forceNextWebGLContextCreationToFail();
3159 }
3160
3161 void TestRunnerForSpecificView::ForceNextDrawingBufferCreationToFail() {
3162 web_view()->forceNextDrawingBufferCreationToFail();
3163 }
3164
3165 void TestRunnerForSpecificView::CopyImageAtAndCapturePixelsAsyncThen(
3166 int x,
3167 int y,
3168 v8::Local<v8::Function> callback) {
3169 v8::UniquePersistent<v8::Function> persistent_callback(
3170 blink::mainThreadIsolate(), callback);
3171
3172 CopyImageAtAndCapturePixels(
3173 web_view(), x, y,
3174 base::Bind(&TestRunnerForSpecificView::CapturePixelsCallback,
3175 weak_factory_.GetWeakPtr(),
3176 base::Passed(std::move(persistent_callback))));
3177 }
3178
3179 void TestRunnerForSpecificView::GetManifestCallback(
3180 v8::UniquePersistent<v8::Function> callback,
3181 const blink::WebURLResponse& response,
3182 const std::string& data) {
3183 PostV8CallbackWithArgs(std::move(callback), 0, nullptr);
3184 }
3185
3186 void TestRunnerForSpecificView::CapturePixelsCallback(
3187 v8::UniquePersistent<v8::Function> callback,
3188 const SkBitmap& snapshot) {
3189 v8::Isolate* isolate = blink::mainThreadIsolate();
3190 v8::HandleScope handle_scope(isolate);
3191
3192 v8::Local<v8::Context> context =
3193 web_view()->mainFrame()->mainWorldScriptContext();
3194 if (context.IsEmpty())
3195 return;
3196
3197 v8::Context::Scope context_scope(context);
3198 v8::Local<v8::Value> argv[3];
3199 SkAutoLockPixels snapshot_lock(snapshot);
3200
3201 // Size can be 0 for cases where copyImageAt was called on position
3202 // that doesn't have an image.
3203 int width = snapshot.info().width();
3204 argv[0] = v8::Number::New(isolate, width);
3205
3206 int height = snapshot.info().height();
3207 argv[1] = v8::Number::New(isolate, height);
3208
3209 // Skia's internal byte order is platform-dependent. Always convert to RGBA
3210 // in order to provide a consistent ordering to the layout tests.
3211 const SkImageInfo bufferInfo =
3212 snapshot.info().makeColorType(kRGBA_8888_SkColorType);
3213 const size_t bufferRowBytes = bufferInfo.minRowBytes();
3214 blink::WebArrayBuffer buffer =
3215 blink::WebArrayBuffer::create(bufferInfo.getSafeSize(bufferRowBytes), 1);
3216 if (!snapshot.readPixels(bufferInfo,
3217 buffer.data(),
3218 bufferRowBytes,
3219 0, 0)) {
3220 // We only expect readPixels to fail for null bitmaps.
3221 DCHECK(snapshot.isNull());
3222 }
3223
3224 argv[2] = blink::WebArrayBufferConverter::toV8Value(
3225 &buffer, context->Global(), isolate);
3226
3227 PostV8CallbackWithArgs(std::move(callback), arraysize(argv), argv);
3228 }
3229
3230 void TestRunnerForSpecificView::DispatchBeforeInstallPromptCallback(
3231 v8::UniquePersistent<v8::Function> callback,
3232 bool canceled) {
3233 v8::Isolate* isolate = blink::mainThreadIsolate();
3234 v8::HandleScope handle_scope(isolate);
3235
3236 v8::Local<v8::Context> context =
3237 web_view()->mainFrame()->mainWorldScriptContext();
3238 if (context.IsEmpty())
3239 return;
3240
3241 v8::Context::Scope context_scope(context);
3242 v8::Local<v8::Value> arg;
3243 arg = v8::Boolean::New(isolate, canceled);
3244
3245 PostV8CallbackWithArgs(std::move(callback), 1, &arg);
3246 }
3247
3248 void TestRunnerForSpecificView::GetBluetoothManualChooserEventsCallback(
3249 v8::UniquePersistent<v8::Function> callback,
3250 const std::vector<std::string>& events) {
3251 // Build the V8 context.
3252 v8::Isolate* isolate = blink::mainThreadIsolate();
3253 v8::HandleScope handle_scope(isolate);
3254 v8::Local<v8::Context> context =
3255 web_view()->mainFrame()->mainWorldScriptContext();
3256 if (context.IsEmpty())
3257 return;
3258 v8::Context::Scope context_scope(context);
3259
3260 // Convert the argument.
3261 v8::Local<v8::Value> arg;
3262 if (!gin::TryConvertToV8(isolate, events, &arg))
3263 return;
3264
3265 // Call the callback.
3266 PostV8CallbackWithArgs(std::move(callback), 1, &arg);
3267 }
3268
3269 void TestRunner::LocationChangeDone() {
3270 web_history_item_count_ = delegate_->NavigationEntryCount();
3271
3272 // No more new work after the first complete load.
3273 work_queue_.set_frozen(true);
3274
3275 if (!layout_test_runtime_flags_.wait_until_done())
3276 work_queue_.ProcessWorkSoon();
3277 }
3278
3279 void TestRunner::CheckResponseMimeType() {
3280 // Text output: the test page can request different types of output which we
3281 // handle here.
3282
3283 if (layout_test_runtime_flags_.dump_as_text())
3284 return;
3285
3286 if (!main_view_)
3287 return;
3288
3289 WebDataSource* data_source = main_view_->mainFrame()->dataSource();
3290 if (!data_source)
3291 return;
3292
3293 std::string mimeType = data_source->response().mimeType().utf8();
3294 if (mimeType != "text/plain")
3295 return;
3296
3297 layout_test_runtime_flags_.set_dump_as_text(true);
3298 layout_test_runtime_flags_.set_generate_pixel_results(false);
3299 OnLayoutTestRuntimeFlagsChanged();
3300 }
3301
3302 void TestRunner::CompleteNotifyDone() {
3303 if (layout_test_runtime_flags_.wait_until_done() && !topLoadingFrame() &&
3304 work_queue_.is_empty())
3305 delegate_->TestFinished();
3306 layout_test_runtime_flags_.set_wait_until_done(false);
3307 OnLayoutTestRuntimeFlagsChanged();
3308 }
3309
3310 void TestRunnerForSpecificView::DidAcquirePointerLockInternal() {
3311 pointer_locked_ = true;
3312 web_view()->didAcquirePointerLock();
3313
3314 // Reset planned result to default.
3315 pointer_lock_planned_result_ = PointerLockWillSucceed;
3316 }
3317
3318 void TestRunnerForSpecificView::DidNotAcquirePointerLockInternal() {
3319 DCHECK(!pointer_locked_);
3320 pointer_locked_ = false;
3321 web_view()->didNotAcquirePointerLock();
3322
3323 // Reset planned result to default.
3324 pointer_lock_planned_result_ = PointerLockWillSucceed;
3325 }
3326
3327 void TestRunnerForSpecificView::DidLosePointerLockInternal() {
3328 bool was_locked = pointer_locked_;
3329 pointer_locked_ = false;
3330 if (was_locked)
3331 web_view()->didLosePointerLock();
3332 }
3333
3334 TestRunnerForSpecificView::TestRunnerForSpecificView(
3335 WebTestProxyBase* web_test_proxy_base)
3336 : web_test_proxy_base_(web_test_proxy_base), weak_factory_(this) {
3337 Reset();
3338 }
3339
3340 TestRunnerForSpecificView::~TestRunnerForSpecificView() {}
3341
3342 void TestRunnerForSpecificView::Install(blink::WebLocalFrame* frame) {
3343 web_test_proxy_base_->test_interfaces()->GetTestRunner()->Install(
3344 frame, weak_factory_.GetWeakPtr());
3345 }
3346
3347 void TestRunnerForSpecificView::Reset() {
3348 pointer_locked_ = false;
3349 pointer_lock_planned_result_ = PointerLockWillSucceed;
3350
3351 if (web_view() && web_view()->mainFrame()) {
3352 RemoveWebPageOverlay();
3353 SetTabKeyCyclesThroughElements(true);
3354
3355 #if !defined(OS_MACOSX) && !defined(OS_WIN)
3356 // (Constants copied because we can't depend on the header that defined
3357 // them from this file.)
3358 web_view()->setSelectionColors(
3359 0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232);
3360 #endif
3361 web_view()->setVisibilityState(WebPageVisibilityStateVisible, true);
3362 if (web_view()->mainFrame()->isWebLocalFrame()) {
3363 web_view()->mainFrame()->enableViewSourceMode(false);
3364 web_view()->setTextZoomFactor(1);
3365 web_view()->setZoomLevel(0);
3366 }
3367 }
3368 }
3369
3370 void TestRunnerForSpecificView::SetViewSourceForFrame(const std::string& name, 657 void TestRunnerForSpecificView::SetViewSourceForFrame(const std::string& name,
3371 bool enabled) { 658 bool enabled) {
3372 WebFrame* target_frame = 659 WebFrame* target_frame =
3373 web_view()->findFrameByName(WebString::fromUTF8(name)); 660 web_view()->findFrameByName(WebString::fromUTF8(name));
3374 if (target_frame) 661 if (target_frame)
3375 target_frame->enableViewSourceMode(enabled); 662 target_frame->enableViewSourceMode(enabled);
3376 } 663 }
3377 664
3378 blink::WebView* TestRunnerForSpecificView::web_view() { 665 blink::WebView* TestRunnerForSpecificView::web_view() {
3379 return web_test_proxy_base_->web_view(); 666 return web_test_proxy_base_->web_view();
3380 } 667 }
3381 668
3382 WebTestDelegate* TestRunnerForSpecificView::delegate() { 669 WebTestDelegate* TestRunnerForSpecificView::delegate() {
3383 return web_test_proxy_base_->delegate(); 670 return web_test_proxy_base_->delegate();
3384 } 671 }
3385 672
3386 } // namespace test_runner 673 } // namespace test_runner
OLDNEW
« no previous file with comments | « components/test_runner/test_runner_for_specific_view.h ('k') | components/test_runner/web_test_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698