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