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

Side by Side Diff: content/shell/renderer/test_runner/test_runner.cc

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

Powered by Google App Engine
This is Rietveld 408576698