1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/shell/renderer/test_runner/test_runner.h"
9 #include "content/shell/common/test_runner/WebPreferences.h"
10 #include "content/shell/renderer/test_runner/MockWebSpeechInputController.h"
11 #include "content/shell/renderer/test_runner/MockWebSpeechRecognizer.h"
12 #include "content/shell/renderer/test_runner/TestInterfaces.h"
13 #include "content/shell/renderer/test_runner/WebPermissions.h"
14 #include "content/shell/renderer/test_runner/WebTestDelegate.h"
15 #include "content/shell/renderer/test_runner/WebTestProxy.h"
16 #include "content/shell/renderer/test_runner/notification_presenter.h"
17 #include "gin/arguments.h"
18 #include "gin/array_buffer.h"
19 #include "gin/handle.h"
20 #include "gin/object_template_builder.h"
21 #include "gin/wrappable.h"
22 #include "third_party/WebKit/public/platform/WebCanvas.h"
23 #include "third_party/WebKit/public/platform/WebData.h"
24 #include "third_party/WebKit/public/platform/WebDeviceMotionData.h"
25 #include "third_party/WebKit/public/platform/WebDeviceOrientationData.h"
26 #include "third_party/WebKit/public/platform/WebPoint.h"
27 #include "third_party/WebKit/public/platform/WebURLResponse.h"
28 #include "third_party/WebKit/public/web/WebBindings.h"
29 #include "third_party/WebKit/public/web/WebDataSource.h"
30 #include "third_party/WebKit/public/web/WebDocument.h"
31 #include "third_party/WebKit/public/web/WebFindOptions.h"
32 #include "third_party/WebKit/public/web/WebFrame.h"
33 #include "third_party/WebKit/public/web/WebInputElement.h"
34 #include "third_party/WebKit/public/web/WebKit.h"
35 #include "third_party/WebKit/public/web/WebMIDIClientMock.h"
36 #include "third_party/WebKit/public/web/WebPageOverlay.h"
37 #include "third_party/WebKit/public/web/WebScriptSource.h"
38 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
39 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
40 #include "third_party/WebKit/public/web/WebSettings.h"
41 #include "third_party/WebKit/public/web/WebSurroundingText.h"
42 #include "third_party/WebKit/public/web/WebView.h"
43 #include "third_party/skia/include/core/SkCanvas.h"
45 #if defined(__linux__) || defined(ANDROID)
46 #include "third_party/WebKit/public/web/linux/WebFontRendering.h"
49 using namespace blink;
50 using namespace WebTestRunner;
54 WebString V8StringToWebString(v8::Handle<v8::String> v8_str) {
55 int length = v8_str->Utf8Length() + 1;
56 scoped_ptr<char[]> chars(new char[length]);
57 v8_str->WriteUtf8(chars.get(), length);
58 return WebString::fromUTF8(chars.get());
61 class HostMethodTask :
62 public ::WebTestRunner::WebMethodTask<content::TestRunner> {
64 typedef void (content::TestRunner::*CallbackMethodType)();
65 HostMethodTask(content::TestRunner* object, CallbackMethodType callback)
66 : WebMethodTask<content::TestRunner>(object), callback_(callback) {}
68 virtual void runIfValid() OVERRIDE {
69 (m_object->*callback_)();
73 CallbackMethodType callback_;
80 class InvokeCallbackTask : public WebMethodTask<content::TestRunner> {
82 InvokeCallbackTask(content::TestRunner* object,
83 v8::Handle<v8::Function> callback)
84 : WebMethodTask<content::TestRunner>(object),
85 callback_(blink::mainThreadIsolate(), callback) {}
87 virtual void runIfValid() OVERRIDE {
88 v8::Isolate* isolate = blink::mainThreadIsolate();
89 v8::HandleScope handle_scope(isolate);
90 WebFrame* frame = m_object->web_view_->mainFrame();
92 v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
93 if (context.IsEmpty())
96 v8::Context::Scope context_scope(context);
98 frame->callFunctionEvenIfScriptDisabled(
99 v8::Local<v8::Function>::New(isolate, callback_),
106 v8::Persistent<v8::Function> callback_;
109 class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
111 static gin::WrapperInfo kWrapperInfo;
113 static void Install(base::WeakPtr<TestRunner> controller,
117 explicit TestRunnerBindings(
118 base::WeakPtr<TestRunner> controller);
119 virtual ~TestRunnerBindings();
122 virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
123 v8::Isolate* isolate) OVERRIDE;
126 void WaitUntilDone();
127 void QueueBackNavigation(int how_far_back);
128 void QueueForwardNavigation(int how_far_forward);
130 void QueueLoadingScript(const std::string& script);
131 void QueueNonLoadingScript(const std::string& script);
132 void QueueLoad(gin::Arguments* args);
133 void QueueLoadHTMLString(gin::Arguments* args);
134 void SetCustomPolicyDelegate(gin::Arguments* args);
135 void WaitForPolicyDelegate();
137 void SetCloseRemainingWindowsWhenComplete(gin::Arguments* args);
138 void ResetTestHelperControllers();
139 void SetTabKeyCyclesThroughElements(bool tab_key_cycles_through_elements);
140 void ExecCommand(gin::Arguments* args);
141 bool IsCommandEnabled(const std::string& command);
142 bool CallShouldCloseOnWebView();
143 void SetDomainRelaxationForbiddenForURLScheme(bool forbidden,
144 const std::string& scheme);
145 v8::Handle<v8::Value> EvaluateScriptInIsolatedWorldAndReturnValue(
146 int world_id, const std::string& script);
147 void EvaluateScriptInIsolatedWorld(int world_id, const std::string& script);
148 void SetIsolatedWorldSecurityOrigin(int world_id,
149 v8::Handle<v8::Value> origin);
150 void SetIsolatedWorldContentSecurityPolicy(int world_id,
151 const std::string& policy);
152 void AddOriginAccessWhitelistEntry(const std::string& source_origin,
153 const std::string& destination_protocol,
154 const std::string& destination_host,
155 bool allow_destination_subdomains);
156 void RemoveOriginAccessWhitelistEntry(const std::string& source_origin,
157 const std::string& destination_protocol,
158 const std::string& destination_host,
159 bool allow_destination_subdomains);
160 bool HasCustomPageSizeStyle(int page_index);
161 void ForceRedSelectionColors();
162 void InjectStyleSheet(const std::string& source_code, bool all_frames);
163 bool FindString(const std::string& search_text,
164 const std::vector<std::string>& options_array);
165 std::string SelectionAsMarkup();
166 void SetTextSubpixelPositioning(bool value);
167 void SetPageVisibility(const std::string& new_visibility);
168 void SetTextDirection(const std::string& direction_name);
169 void UseUnfortunateSynchronousResizeMode();
170 bool EnableAutoResizeMode(int min_width,
174 bool DisableAutoResizeMode(int new_width, int new_height);
175 void SetMockDeviceMotion(gin::Arguments* args);
176 void SetMockDeviceOrientation(gin::Arguments* args);
177 void SetMockScreenOrientation(const std::string& orientation);
178 void DidAcquirePointerLock();
179 void DidNotAcquirePointerLock();
180 void DidLosePointerLock();
181 void SetPointerLockWillFailSynchronously();
182 void SetPointerLockWillRespondAsynchronously();
183 void SetPopupBlockingEnabled(bool block_popups);
184 void SetJavaScriptCanAccessClipboard(bool can_access);
185 void SetXSSAuditorEnabled(bool enabled);
186 void SetAllowUniversalAccessFromFileURLs(bool allow);
187 void SetAllowFileAccessFromFileURLs(bool allow);
188 void OverridePreference(const std::string key, v8::Handle<v8::Value> value);
189 void SetPluginsEnabled(bool enabled);
190 void DumpEditingCallbacks();
192 void DumpAsTextWithPixelResults();
193 void DumpChildFrameScrollPositions();
194 void DumpChildFramesAsText();
195 void DumpIconChanges();
196 void SetAudioData(const gin::ArrayBufferView& view);
197 void DumpFrameLoadCallbacks();
198 void DumpPingLoaderCallbacks();
199 void DumpUserGestureInFrameLoadCallbacks();
200 void DumpTitleChanges();
201 void DumpCreateView();
202 void SetCanOpenWindows();
203 void DumpResourceLoadCallbacks();
204 void DumpResourceRequestCallbacks();
205 void DumpResourceResponseMIMETypes();
206 void SetImagesAllowed(bool allowed);
207 void SetScriptsAllowed(bool allowed);
208 void SetStorageAllowed(bool allowed);
209 void SetPluginsAllowed(bool allowed);
210 void SetAllowDisplayOfInsecureContent(bool allowed);
211 void SetAllowRunningOfInsecureContent(bool allowed);
212 void DumpPermissionClientCallbacks();
213 void DumpWindowStatusChanges();
214 void DumpProgressFinishedCallback();
215 void DumpSpellCheckCallbacks();
216 void DumpBackForwardList();
217 void DumpSelectionRect();
219 void RepaintSweepHorizontally();
221 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
222 void SetWillSendRequestClearHeader(const std::string& header);
223 void DumpResourceRequestPriorities();
224 void SetUseMockTheme(bool use);
225 void ShowWebInspector(gin::Arguments* args);
226 void CloseWebInspector();
227 bool IsChooserShown();
228 void EvaluateInWebInspector(int call_id, const std::string& script);
229 void ClearAllDatabases();
230 void SetDatabaseQuota(int quota);
231 void SetAlwaysAcceptCookies(bool accept);
232 void SetWindowIsKey(bool value);
233 std::string PathToLocalResource(const std::string& path);
234 void SetBackingScaleFactor(double value, v8::Handle<v8::Function> callback);
235 void SetPOSIXLocale(const std::string& locale);
236 void SetMIDIAccessorResult(bool result);
237 void SetMIDISysexPermission(bool value);
238 void GrantWebNotificationPermission(gin::Arguments* args);
239 bool SimulateWebNotificationClick(const std::string& value);
240 void AddMockSpeechInputResult(const std::string& result,
242 const std::string& language);
243 void SetMockSpeechInputDumpRect(bool value);
244 void AddMockSpeechRecognitionResult(const std::string& transcript,
246 void SetMockSpeechRecognitionError(const std::string& error,
247 const std::string& message);
248 bool WasMockSpeechRecognitionAborted();
249 void AddWebPageOverlay();
250 void RemoveWebPageOverlay();
252 void DisplayInvalidatedRegion();
255 void SetGlobalFlag(bool value);
256 std::string PlatformName();
257 std::string TooltipText();
258 bool DisableNotifyDone();
259 int WebHistoryItemCount();
260 bool InterceptPostMessage();
261 void SetInterceptPostMessage(bool value);
263 void NotImplemented(const gin::Arguments& args);
265 base::WeakPtr<TestRunner> runner_;
267 DISALLOW_COPY_AND_ASSIGN(TestRunnerBindings);
270 gin::WrapperInfo TestRunnerBindings::kWrapperInfo = {
271 gin::kEmbedderNativeGin};
274 void TestRunnerBindings::Install(base::WeakPtr<TestRunner> runner,
276 v8::Isolate* isolate = blink::mainThreadIsolate();
277 v8::HandleScope handle_scope(isolate);
278 v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
279 if (context.IsEmpty())
282 v8::Context::Scope context_scope(context);
284 gin::Handle<TestRunnerBindings> bindings =
285 gin::CreateHandle(isolate, new TestRunnerBindings(runner));
286 v8::Handle<v8::Object> global = context->Global();
287 v8::Handle<v8::Value> v8_bindings = bindings.ToV8();
288 global->Set(gin::StringToV8(isolate, "testRunner"), v8_bindings);
289 global->Set(gin::StringToV8(isolate, "layoutTestController"), v8_bindings);
292 TestRunnerBindings::TestRunnerBindings(base::WeakPtr<TestRunner> runner)
295 TestRunnerBindings::~TestRunnerBindings() {}
297 gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
298 v8::Isolate* isolate) {
299 return gin::Wrappable<TestRunnerBindings>::GetObjectTemplateBuilder(
301 // Methods controlling test execution.
302 .SetMethod("notifyDone", &TestRunnerBindings::NotifyDone)
303 .SetMethod("waitUntilDone", &TestRunnerBindings::WaitUntilDone)
304 .SetMethod("queueBackNavigation",
305 &TestRunnerBindings::QueueBackNavigation)
306 .SetMethod("queueForwardNavigation",
307 &TestRunnerBindings::QueueForwardNavigation)
308 .SetMethod("queueReload", &TestRunnerBindings::QueueReload)
309 .SetMethod("queueLoadingScript", &TestRunnerBindings::QueueLoadingScript)
310 .SetMethod("queueNonLoadingScript",
311 &TestRunnerBindings::QueueNonLoadingScript)
312 .SetMethod("queueLoad", &TestRunnerBindings::QueueLoad)
313 .SetMethod("queueLoadHTMLString",
314 &TestRunnerBindings::QueueLoadHTMLString)
315 .SetMethod("setCustomPolicyDelegate",
316 &TestRunnerBindings::SetCustomPolicyDelegate)
317 .SetMethod("waitForPolicyDelegate",
318 &TestRunnerBindings::WaitForPolicyDelegate)
319 .SetMethod("windowCount", &TestRunnerBindings::WindowCount)
320 .SetMethod("setCloseRemainingWindowsWhenComplete",
321 &TestRunnerBindings::SetCloseRemainingWindowsWhenComplete)
322 .SetMethod("resetTestHelperControllers",
323 &TestRunnerBindings::ResetTestHelperControllers)
324 .SetMethod("setTabKeyCyclesThroughElements",
325 &TestRunnerBindings::SetTabKeyCyclesThroughElements)
326 .SetMethod("execCommand", &TestRunnerBindings::ExecCommand)
327 .SetMethod("isCommandEnabled", &TestRunnerBindings::IsCommandEnabled)
328 .SetMethod("callShouldCloseOnWebView",
329 &TestRunnerBindings::CallShouldCloseOnWebView)
330 .SetMethod("setDomainRelaxationForbiddenForURLScheme",
331 &TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme)
332 .SetMethod("evaluateScriptInIsolatedWorldAndReturnValue",
333 &TestRunnerBindings::
334 EvaluateScriptInIsolatedWorldAndReturnValue)
335 .SetMethod("evaluateScriptInIsolatedWorld",
336 &TestRunnerBindings::EvaluateScriptInIsolatedWorld)
337 .SetMethod("setIsolatedWorldSecurityOrigin",
338 &TestRunnerBindings::SetIsolatedWorldSecurityOrigin)
339 .SetMethod("setIsolatedWorldContentSecurityPolicy",
340 &TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy)
341 .SetMethod("addOriginAccessWhitelistEntry",
342 &TestRunnerBindings::AddOriginAccessWhitelistEntry)
343 .SetMethod("removeOriginAccessWhitelistEntry",
344 &TestRunnerBindings::RemoveOriginAccessWhitelistEntry)
345 .SetMethod("hasCustomPageSizeStyle",
346 &TestRunnerBindings::HasCustomPageSizeStyle)
347 .SetMethod("forceRedSelectionColors",
348 &TestRunnerBindings::ForceRedSelectionColors)
349 .SetMethod("injectStyleSheet", &TestRunnerBindings::InjectStyleSheet)
350 .SetMethod("findString", &TestRunnerBindings::FindString)
351 .SetMethod("selectionAsMarkup", &TestRunnerBindings::SelectionAsMarkup)
352 .SetMethod("setTextSubpixelPositioning",
353 &TestRunnerBindings::SetTextSubpixelPositioning)
354 .SetMethod("setPageVisibility", &TestRunnerBindings::SetPageVisibility)
355 .SetMethod("setTextDirection", &TestRunnerBindings::SetTextDirection)
356 .SetMethod("useUnfortunateSynchronousResizeMode",
357 &TestRunnerBindings::UseUnfortunateSynchronousResizeMode)
358 .SetMethod("enableAutoResizeMode",
359 &TestRunnerBindings::EnableAutoResizeMode)
360 .SetMethod("disableAutoResizeMode",
361 &TestRunnerBindings::DisableAutoResizeMode)
362 .SetMethod("setMockDeviceMotion",
363 &TestRunnerBindings::SetMockDeviceMotion)
364 .SetMethod("setMockDeviceOrientation",
365 &TestRunnerBindings::SetMockDeviceOrientation)
366 .SetMethod("setMockScreenOrientation",
367 &TestRunnerBindings::SetMockScreenOrientation)
368 .SetMethod("didAcquirePointerLock",
369 &TestRunnerBindings::DidAcquirePointerLock)
370 .SetMethod("didNotAcquirePointerLock",
371 &TestRunnerBindings::DidNotAcquirePointerLock)
372 .SetMethod("didLosePointerLock", &TestRunnerBindings::DidLosePointerLock)
373 .SetMethod("setPointerLockWillFailSynchronously",
374 &TestRunnerBindings::SetPointerLockWillFailSynchronously)
375 .SetMethod("setPointerLockWillRespondAsynchronously",
376 &TestRunnerBindings::SetPointerLockWillRespondAsynchronously)
377 .SetMethod("setPopupBlockingEnabled",
378 &TestRunnerBindings::SetPopupBlockingEnabled)
379 .SetMethod("setJavaScriptCanAccessClipboard",
380 &TestRunnerBindings::SetJavaScriptCanAccessClipboard)
381 .SetMethod("setXSSAuditorEnabled",
382 &TestRunnerBindings::SetXSSAuditorEnabled)
383 .SetMethod("setAllowUniversalAccessFromFileURLs",
384 &TestRunnerBindings::SetAllowUniversalAccessFromFileURLs)
385 .SetMethod("setAllowFileAccessFromFileURLs",
386 &TestRunnerBindings::SetAllowFileAccessFromFileURLs)
387 .SetMethod("overridePreference", &TestRunnerBindings::OverridePreference)
388 .SetMethod("setPluginsEnabled", &TestRunnerBindings::SetPluginsEnabled)
389 .SetMethod("dumpEditingCallbacks",
390 &TestRunnerBindings::DumpEditingCallbacks)
391 .SetMethod("dumpAsText", &TestRunnerBindings::DumpAsText)
392 .SetMethod("dumpAsTextWithPixelResults",
393 &TestRunnerBindings::DumpAsTextWithPixelResults)
394 .SetMethod("dumpChildFrameScrollPositions",
395 &TestRunnerBindings::DumpChildFrameScrollPositions)
396 .SetMethod("dumpChildFramesAsText",
397 &TestRunnerBindings::DumpChildFramesAsText)
398 .SetMethod("dumpIconChanges", &TestRunnerBindings::DumpIconChanges)
399 .SetMethod("setAudioData", &TestRunnerBindings::SetAudioData)
400 .SetMethod("dumpFrameLoadCallbacks",
401 &TestRunnerBindings::DumpFrameLoadCallbacks)
402 .SetMethod("dumpPingLoaderCallbacks",
403 &TestRunnerBindings::DumpPingLoaderCallbacks)
404 .SetMethod("dumpUserGestureInFrameLoadCallbacks",
405 &TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks)
406 .SetMethod("dumpTitleChanges", &TestRunnerBindings::DumpTitleChanges)
407 .SetMethod("dumpCreateView", &TestRunnerBindings::DumpCreateView)
408 .SetMethod("setCanOpenWindows", &TestRunnerBindings::SetCanOpenWindows)
409 .SetMethod("dumpResourceLoadCallbacks",
410 &TestRunnerBindings::DumpResourceLoadCallbacks)
411 .SetMethod("dumpResourceRequestCallbacks",
412 &TestRunnerBindings::DumpResourceRequestCallbacks)
413 .SetMethod("dumpResourceResponseMIMETypes",
414 &TestRunnerBindings::DumpResourceResponseMIMETypes)
415 .SetMethod("setImagesAllowed", &TestRunnerBindings::SetImagesAllowed)
416 .SetMethod("setScriptsAllowed", &TestRunnerBindings::SetScriptsAllowed)
417 .SetMethod("setStorageAllowed", &TestRunnerBindings::SetStorageAllowed)
418 .SetMethod("setPluginsAllowed", &TestRunnerBindings::SetPluginsAllowed)
419 .SetMethod("setAllowDisplayOfInsecureContent",
420 &TestRunnerBindings::SetAllowDisplayOfInsecureContent)
421 .SetMethod("setAllowRunningOfInsecureContent",
422 &TestRunnerBindings::SetAllowRunningOfInsecureContent)
423 .SetMethod("dumpPermissionClientCallbacks",
424 &TestRunnerBindings::DumpPermissionClientCallbacks)
425 .SetMethod("dumpWindowStatusChanges",
426 &TestRunnerBindings::DumpWindowStatusChanges)
427 .SetMethod("dumpProgressFinishedCallback",
428 &TestRunnerBindings::DumpProgressFinishedCallback)
429 .SetMethod("dumpSpellCheckCallbacks",
430 &TestRunnerBindings::DumpSpellCheckCallbacks)
431 .SetMethod("dumpBackForwardList",
432 &TestRunnerBindings::DumpBackForwardList)
433 .SetMethod("dumpSelectionRect", &TestRunnerBindings::DumpSelectionRect)
434 .SetMethod("testRepaint", &TestRunnerBindings::TestRepaint)
435 .SetMethod("repaintSweepHorizontally",
436 &TestRunnerBindings::RepaintSweepHorizontally)
437 .SetMethod("setPrinting", &TestRunnerBindings::SetPrinting)
438 .SetMethod("setShouldStayOnPageAfterHandlingBeforeUnload",
439 &TestRunnerBindings::
440 SetShouldStayOnPageAfterHandlingBeforeUnload)
441 .SetMethod("setWillSendRequestClearHeader",
442 &TestRunnerBindings::SetWillSendRequestClearHeader)
443 .SetMethod("dumpResourceRequestPriorities",
444 &TestRunnerBindings::DumpResourceRequestPriorities)
445 .SetMethod("setUseMockTheme", &TestRunnerBindings::SetUseMockTheme)
446 .SetMethod("showWebInspector", &TestRunnerBindings::ShowWebInspector)
447 .SetMethod("closeWebInspector", &TestRunnerBindings::CloseWebInspector)
448 .SetMethod("isChooserShown", &TestRunnerBindings::IsChooserShown)
449 .SetMethod("evaluateInWebInspector",
450 &TestRunnerBindings::EvaluateInWebInspector)
451 .SetMethod("clearAllDatabases", &TestRunnerBindings::ClearAllDatabases)
452 .SetMethod("setDatabaseQuota", &TestRunnerBindings::SetDatabaseQuota)
453 .SetMethod("setAlwaysAcceptCookies",
454 &TestRunnerBindings::SetAlwaysAcceptCookies)
455 .SetMethod("setWindowIsKey", &TestRunnerBindings::SetWindowIsKey)
456 .SetMethod("pathToLocalResource",
457 &TestRunnerBindings::PathToLocalResource)
458 .SetMethod("setBackingScaleFactor",
459 &TestRunnerBindings::SetBackingScaleFactor)
460 .SetMethod("setPOSIXLocale", &TestRunnerBindings::SetPOSIXLocale)
461 .SetMethod("setMIDIAccessorResult",
462 &TestRunnerBindings::SetMIDIAccessorResult)
463 .SetMethod("setMIDISysexPermission",
464 &TestRunnerBindings::SetMIDISysexPermission)
465 .SetMethod("grantWebNotificationPermission",
466 &TestRunnerBindings::GrantWebNotificationPermission)
467 .SetMethod("simulateWebNotificationClick",
468 &TestRunnerBindings::SimulateWebNotificationClick)
469 .SetMethod("addMockSpeechInputResult",
470 &TestRunnerBindings::AddMockSpeechInputResult)
471 .SetMethod("setMockSpeechInputDumpRect",
472 &TestRunnerBindings::SetMockSpeechInputDumpRect)
473 .SetMethod("addMockSpeechRecognitionResult",
474 &TestRunnerBindings::AddMockSpeechRecognitionResult)
475 .SetMethod("setMockSpeechRecognitionError",
476 &TestRunnerBindings::SetMockSpeechRecognitionError)
477 .SetMethod("wasMockSpeechRecognitionAborted",
478 &TestRunnerBindings::WasMockSpeechRecognitionAborted)
479 .SetMethod("addWebPageOverlay", &TestRunnerBindings::AddWebPageOverlay)
480 .SetMethod("removeWebPageOverlay",
481 &TestRunnerBindings::RemoveWebPageOverlay)
482 .SetMethod("display", &TestRunnerBindings::Display)
483 .SetMethod("displayInvalidatedRegion",
484 &TestRunnerBindings::DisplayInvalidatedRegion)
487 .SetProperty("globalFlag", &TestRunnerBindings::GlobalFlag,
488 &TestRunnerBindings::SetGlobalFlag)
489 .SetProperty("platformName", &TestRunnerBindings::PlatformName)
490 .SetProperty("tooltipText", &TestRunnerBindings::TooltipText)
491 .SetProperty("disableNotifyDone", &TestRunnerBindings::DisableNotifyDone)
492 // webHistoryItemCount is used by tests in LayoutTests\http\tests\history
493 .SetProperty("webHistoryItemCount",
494 &TestRunnerBindings::WebHistoryItemCount)
495 .SetProperty("interceptPostMessage",
496 &TestRunnerBindings::InterceptPostMessage,
497 &TestRunnerBindings::SetInterceptPostMessage)
499 // The following are stubs.
500 .SetMethod("dumpDatabaseCallbacks", &TestRunnerBindings::NotImplemented)
501 .SetMethod("setIconDatabaseEnabled", &TestRunnerBindings::NotImplemented)
502 .SetMethod("setScrollbarPolicy", &TestRunnerBindings::NotImplemented)
503 .SetMethod("clearAllApplicationCaches",
504 &TestRunnerBindings::NotImplemented)
505 .SetMethod("clearApplicationCacheForOrigin",
506 &TestRunnerBindings::NotImplemented)
507 .SetMethod("clearBackForwardList", &TestRunnerBindings::NotImplemented)
508 .SetMethod("keepWebHistory", &TestRunnerBindings::NotImplemented)
509 .SetMethod("setApplicationCacheOriginQuota",
510 &TestRunnerBindings::NotImplemented)
511 .SetMethod("setCallCloseOnWebViews", &TestRunnerBindings::NotImplemented)
512 .SetMethod("setMainFrameIsFirstResponder",
513 &TestRunnerBindings::NotImplemented)
514 .SetMethod("setUseDashboardCompatibilityMode",
515 &TestRunnerBindings::NotImplemented)
516 .SetMethod("deleteAllLocalStorage", &TestRunnerBindings::NotImplemented)
517 .SetMethod("localStorageDiskUsageForOrigin",
518 &TestRunnerBindings::NotImplemented)
519 .SetMethod("originsWithLocalStorage", &TestRunnerBindings::NotImplemented)
520 .SetMethod("deleteLocalStorageForOrigin",
521 &TestRunnerBindings::NotImplemented)
522 .SetMethod("observeStorageTrackerNotifications",
523 &TestRunnerBindings::NotImplemented)
524 .SetMethod("syncLocalStorage", &TestRunnerBindings::NotImplemented)
525 .SetMethod("addDisallowedURL", &TestRunnerBindings::NotImplemented)
526 .SetMethod("applicationCacheDiskUsageForOrigin",
527 &TestRunnerBindings::NotImplemented)
528 .SetMethod("abortModal", &TestRunnerBindings::NotImplemented)
531 // Used at fast/dom/assign-to-window-status.html
532 .SetMethod("dumpStatusCallbacks",
533 &TestRunnerBindings::DumpWindowStatusChanges);
537 void TestRunnerBindings::NotifyDone() {
539 runner_->NotifyDone();
542 void TestRunnerBindings::WaitUntilDone() {
544 runner_->WaitUntilDone();
547 void TestRunnerBindings::QueueBackNavigation(int how_far_back) {
549 runner_->QueueBackNavigation(how_far_back);
552 void TestRunnerBindings::QueueForwardNavigation(int how_far_forward) {
554 runner_->QueueForwardNavigation(how_far_forward);
557 void TestRunnerBindings::QueueReload() {
559 runner_->QueueReload();
562 void TestRunnerBindings::QueueLoadingScript(const std::string& script) {
564 runner_->QueueLoadingScript(script);
567 void TestRunnerBindings::QueueNonLoadingScript(const std::string& script) {
569 runner_->QueueNonLoadingScript(script);
572 void TestRunnerBindings::QueueLoad(gin::Arguments* args) {
577 args->GetNext(&target);
578 runner_->QueueLoad(url, target);
582 void TestRunnerBindings::QueueLoadHTMLString(gin::Arguments* args) {
584 runner_->QueueLoadHTMLString(args);
587 void TestRunnerBindings::SetCustomPolicyDelegate(gin::Arguments* args) {
589 runner_->SetCustomPolicyDelegate(args);
592 void TestRunnerBindings::WaitForPolicyDelegate() {
594 runner_->WaitForPolicyDelegate();
597 int TestRunnerBindings::WindowCount() {
599 return runner_->WindowCount();
603 void TestRunnerBindings::SetCloseRemainingWindowsWhenComplete(
604 gin::Arguments* args) {
608 // In the original implementation, nothing happens if the argument is
610 bool close_remaining_windows = false;
611 if (args->GetNext(&close_remaining_windows))
612 runner_->SetCloseRemainingWindowsWhenComplete(close_remaining_windows);
615 void TestRunnerBindings::ResetTestHelperControllers() {
617 runner_->ResetTestHelperControllers();
620 void TestRunnerBindings::SetTabKeyCyclesThroughElements(
621 bool tab_key_cycles_through_elements) {
623 runner_->SetTabKeyCyclesThroughElements(tab_key_cycles_through_elements);
626 void TestRunnerBindings::ExecCommand(gin::Arguments* args) {
628 runner_->ExecCommand(args);
631 bool TestRunnerBindings::IsCommandEnabled(const std::string& command) {
633 return runner_->IsCommandEnabled(command);
637 bool TestRunnerBindings::CallShouldCloseOnWebView() {
639 return runner_->CallShouldCloseOnWebView();
643 void TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme(
644 bool forbidden, const std::string& scheme) {
646 runner_->SetDomainRelaxationForbiddenForURLScheme(forbidden, scheme);
649 v8::Handle<v8::Value>
650 TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue(
651 int world_id, const std::string& script) {
653 return v8::Handle<v8::Value>();
654 return runner_->EvaluateScriptInIsolatedWorldAndReturnValue(world_id,
658 void TestRunnerBindings::EvaluateScriptInIsolatedWorld(
659 int world_id, const std::string& script) {
661 runner_->EvaluateScriptInIsolatedWorld(world_id, script);
664 void TestRunnerBindings::SetIsolatedWorldSecurityOrigin(
665 int world_id, v8::Handle<v8::Value> origin) {
667 runner_->SetIsolatedWorldSecurityOrigin(world_id, origin);
670 void TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy(
671 int world_id, const std::string& policy) {
673 runner_->SetIsolatedWorldContentSecurityPolicy(world_id, policy);
676 void TestRunnerBindings::AddOriginAccessWhitelistEntry(
677 const std::string& source_origin,
678 const std::string& destination_protocol,
679 const std::string& destination_host,
680 bool allow_destination_subdomains) {
682 runner_->AddOriginAccessWhitelistEntry(source_origin,
683 destination_protocol,
685 allow_destination_subdomains);
689 void TestRunnerBindings::RemoveOriginAccessWhitelistEntry(
690 const std::string& source_origin,
691 const std::string& destination_protocol,
692 const std::string& destination_host,
693 bool allow_destination_subdomains) {
695 runner_->RemoveOriginAccessWhitelistEntry(source_origin,
696 destination_protocol,
698 allow_destination_subdomains);
702 bool TestRunnerBindings::HasCustomPageSizeStyle(int page_index) {
704 return runner_->HasCustomPageSizeStyle(page_index);
708 void TestRunnerBindings::ForceRedSelectionColors() {
710 runner_->ForceRedSelectionColors();
713 void TestRunnerBindings::InjectStyleSheet(const std::string& source_code,
716 runner_->InjectStyleSheet(source_code, all_frames);
719 bool TestRunnerBindings::FindString(
720 const std::string& search_text,
721 const std::vector<std::string>& options_array) {
723 return runner_->FindString(search_text, options_array);
727 std::string TestRunnerBindings::SelectionAsMarkup() {
729 return runner_->SelectionAsMarkup();
730 return std::string();
733 void TestRunnerBindings::SetTextSubpixelPositioning(bool value) {
735 runner_->SetTextSubpixelPositioning(value);
738 void TestRunnerBindings::SetPageVisibility(const std::string& new_visibility) {
740 runner_->SetPageVisibility(new_visibility);
743 void TestRunnerBindings::SetTextDirection(const std::string& direction_name) {
745 runner_->SetTextDirection(direction_name);
748 void TestRunnerBindings::UseUnfortunateSynchronousResizeMode() {
750 runner_->UseUnfortunateSynchronousResizeMode();
753 bool TestRunnerBindings::EnableAutoResizeMode(int min_width,
758 return runner_->EnableAutoResizeMode(min_width, min_height,
759 max_width, max_height);
764 bool TestRunnerBindings::DisableAutoResizeMode(int new_width, int new_height) {
766 return runner_->DisableAutoResizeMode(new_width, new_height);
770 void TestRunnerBindings::SetMockDeviceMotion(gin::Arguments* args) {
774 bool has_acceleration_x;
775 double acceleration_x;
776 bool has_acceleration_y;
777 double acceleration_y;
778 bool has_acceleration_z;
779 double acceleration_z;
780 bool has_acceleration_including_gravity_x;
781 double acceleration_including_gravity_x;
782 bool has_acceleration_including_gravity_y;
783 double acceleration_including_gravity_y;
784 bool has_acceleration_including_gravity_z;
785 double acceleration_including_gravity_z;
786 bool has_rotation_rate_alpha;
787 double rotation_rate_alpha;
788 bool has_rotation_rate_beta;
789 double rotation_rate_beta;
790 bool has_rotation_rate_gamma;
791 double rotation_rate_gamma;
794 args->GetNext(&has_acceleration_x);
795 args->GetNext(& acceleration_x);
796 args->GetNext(&has_acceleration_y);
797 args->GetNext(& acceleration_y);
798 args->GetNext(&has_acceleration_z);
799 args->GetNext(& acceleration_z);
800 args->GetNext(&has_acceleration_including_gravity_x);
801 args->GetNext(& acceleration_including_gravity_x);
802 args->GetNext(&has_acceleration_including_gravity_y);
803 args->GetNext(& acceleration_including_gravity_y);
804 args->GetNext(&has_acceleration_including_gravity_z);
805 args->GetNext(& acceleration_including_gravity_z);
806 args->GetNext(&has_rotation_rate_alpha);
807 args->GetNext(& rotation_rate_alpha);
808 args->GetNext(&has_rotation_rate_beta);
809 args->GetNext(& rotation_rate_beta);
810 args->GetNext(&has_rotation_rate_gamma);
811 args->GetNext(& rotation_rate_gamma);
812 args->GetNext(& interval);
814 runner_->SetMockDeviceMotion(has_acceleration_x, acceleration_x,
815 has_acceleration_y, acceleration_y,
816 has_acceleration_z, acceleration_z,
817 has_acceleration_including_gravity_x,
818 acceleration_including_gravity_x,
819 has_acceleration_including_gravity_y,
820 acceleration_including_gravity_y,
821 has_acceleration_including_gravity_z,
822 acceleration_including_gravity_z,
823 has_rotation_rate_alpha,
825 has_rotation_rate_beta,
827 has_rotation_rate_gamma,
832 void TestRunnerBindings::SetMockDeviceOrientation(gin::Arguments* args) {
845 args->GetNext(&has_alpha);
846 args->GetNext(&alpha);
847 args->GetNext(&has_beta);
848 args->GetNext(&beta);
849 args->GetNext(&has_gamma);
850 args->GetNext(&gamma);
851 args->GetNext(&has_absolute);
852 args->GetNext(&absolute);
854 runner_->SetMockDeviceOrientation(has_alpha, alpha,
857 has_absolute, absolute);
860 void TestRunnerBindings::SetMockScreenOrientation(const std::string& orientation) {
864 runner_->SetMockScreenOrientation(orientation);
867 void TestRunnerBindings::DidAcquirePointerLock() {
869 runner_->DidAcquirePointerLock();
872 void TestRunnerBindings::DidNotAcquirePointerLock() {
874 runner_->DidNotAcquirePointerLock();
877 void TestRunnerBindings::DidLosePointerLock() {
879 runner_->DidLosePointerLock();
882 void TestRunnerBindings::SetPointerLockWillFailSynchronously() {
884 runner_->SetPointerLockWillFailSynchronously();
887 void TestRunnerBindings::SetPointerLockWillRespondAsynchronously() {
889 runner_->SetPointerLockWillRespondAsynchronously();
892 void TestRunnerBindings::SetPopupBlockingEnabled(bool block_popups) {
894 runner_->SetPopupBlockingEnabled(block_popups);
897 void TestRunnerBindings::SetJavaScriptCanAccessClipboard(bool can_access) {
899 runner_->SetJavaScriptCanAccessClipboard(can_access);
902 void TestRunnerBindings::SetXSSAuditorEnabled(bool enabled) {
904 runner_->SetXSSAuditorEnabled(enabled);
907 void TestRunnerBindings::SetAllowUniversalAccessFromFileURLs(bool allow) {
909 runner_->SetAllowUniversalAccessFromFileURLs(allow);
912 void TestRunnerBindings::SetAllowFileAccessFromFileURLs(bool allow) {
914 runner_->SetAllowFileAccessFromFileURLs(allow);
917 void TestRunnerBindings::OverridePreference(const std::string key,
918 v8::Handle<v8::Value> value) {
920 runner_->OverridePreference(key, value);
923 void TestRunnerBindings::SetPluginsEnabled(bool enabled) {
925 runner_->SetPluginsEnabled(enabled);
928 void TestRunnerBindings::DumpEditingCallbacks() {
930 runner_->DumpEditingCallbacks();
933 void TestRunnerBindings::DumpAsText() {
935 runner_->DumpAsText();
938 void TestRunnerBindings::DumpAsTextWithPixelResults() {
940 runner_->DumpAsTextWithPixelResults();
943 void TestRunnerBindings::DumpChildFrameScrollPositions() {
945 runner_->DumpChildFrameScrollPositions();
948 void TestRunnerBindings::DumpChildFramesAsText() {
950 runner_->DumpChildFramesAsText();
953 void TestRunnerBindings::DumpIconChanges() {
955 runner_->DumpIconChanges();
958 void TestRunnerBindings::SetAudioData(const gin::ArrayBufferView& view) {
960 runner_->SetAudioData(view);
963 void TestRunnerBindings::DumpFrameLoadCallbacks() {
965 runner_->DumpFrameLoadCallbacks();
968 void TestRunnerBindings::DumpPingLoaderCallbacks() {
970 runner_->DumpPingLoaderCallbacks();
973 void TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks() {
975 runner_->DumpUserGestureInFrameLoadCallbacks();
978 void TestRunnerBindings::DumpTitleChanges() {
980 runner_->DumpTitleChanges();
983 void TestRunnerBindings::DumpCreateView() {
985 runner_->DumpCreateView();
988 void TestRunnerBindings::SetCanOpenWindows() {
990 runner_->SetCanOpenWindows();
993 void TestRunnerBindings::DumpResourceLoadCallbacks() {
995 runner_->DumpResourceLoadCallbacks();
998 void TestRunnerBindings::DumpResourceRequestCallbacks() {
1000 runner_->DumpResourceRequestCallbacks();
1003 void TestRunnerBindings::DumpResourceResponseMIMETypes() {
1005 runner_->DumpResourceResponseMIMETypes();
1008 void TestRunnerBindings::SetImagesAllowed(bool allowed) {
1010 runner_->SetImagesAllowed(allowed);
1013 void TestRunnerBindings::SetScriptsAllowed(bool allowed) {
1015 runner_->SetScriptsAllowed(allowed);
1018 void TestRunnerBindings::SetStorageAllowed(bool allowed) {
1020 runner_->SetStorageAllowed(allowed);
1023 void TestRunnerBindings::SetPluginsAllowed(bool allowed) {
1025 runner_->SetPluginsAllowed(allowed);
1028 void TestRunnerBindings::SetAllowDisplayOfInsecureContent(bool allowed) {
1030 runner_->SetAllowDisplayOfInsecureContent(allowed);
1033 void TestRunnerBindings::SetAllowRunningOfInsecureContent(bool allowed) {
1035 runner_->SetAllowRunningOfInsecureContent(allowed);
1038 void TestRunnerBindings::DumpPermissionClientCallbacks() {
1040 runner_->DumpPermissionClientCallbacks();
1043 void TestRunnerBindings::DumpWindowStatusChanges() {
1045 runner_->DumpWindowStatusChanges();
1048 void TestRunnerBindings::DumpProgressFinishedCallback() {
1050 runner_->DumpProgressFinishedCallback();
1053 void TestRunnerBindings::DumpSpellCheckCallbacks() {
1055 runner_->DumpSpellCheckCallbacks();
1058 void TestRunnerBindings::DumpBackForwardList() {
1060 runner_->DumpBackForwardList();
1063 void TestRunnerBindings::DumpSelectionRect() {
1065 runner_->DumpSelectionRect();
1068 void TestRunnerBindings::TestRepaint() {
1070 runner_->TestRepaint();
1073 void TestRunnerBindings::RepaintSweepHorizontally() {
1075 runner_->RepaintSweepHorizontally();
1078 void TestRunnerBindings::SetPrinting() {
1080 runner_->SetPrinting();
1083 void TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload(
1086 runner_->SetShouldStayOnPageAfterHandlingBeforeUnload(value);
1089 void TestRunnerBindings::SetWillSendRequestClearHeader(
1090 const std::string& header) {
1092 runner_->SetWillSendRequestClearHeader(header);
1095 void TestRunnerBindings::DumpResourceRequestPriorities() {
1097 runner_->DumpResourceRequestPriorities();
1100 void TestRunnerBindings::SetUseMockTheme(bool use) {
1102 runner_->SetUseMockTheme(use);
1105 void TestRunnerBindings::ShowWebInspector(gin::Arguments* args) {
1108 args->GetNext(&str);
1109 runner_->ShowWebInspector(str);
1113 void TestRunnerBindings::CloseWebInspector() {
1115 runner_->CloseWebInspector();
1118 bool TestRunnerBindings::IsChooserShown() {
1120 return runner_->IsChooserShown();
1124 void TestRunnerBindings::EvaluateInWebInspector(int call_id,
1125 const std::string& script) {
1127 runner_->EvaluateInWebInspector(call_id, script);
1130 void TestRunnerBindings::ClearAllDatabases() {
1132 runner_->ClearAllDatabases();
1135 void TestRunnerBindings::SetDatabaseQuota(int quota) {
1137 runner_->SetDatabaseQuota(quota);
1140 void TestRunnerBindings::SetAlwaysAcceptCookies(bool accept) {
1142 runner_->SetAlwaysAcceptCookies(accept);
1145 void TestRunnerBindings::SetWindowIsKey(bool value) {
1147 runner_->SetWindowIsKey(value);
1150 std::string TestRunnerBindings::PathToLocalResource(const std::string& path) {
1152 return runner_->PathToLocalResource(path);
1153 return std::string();
1156 void TestRunnerBindings::SetBackingScaleFactor(
1157 double value, v8::Handle<v8::Function> callback) {
1159 runner_->SetBackingScaleFactor(value, callback);
1162 void TestRunnerBindings::SetPOSIXLocale(const std::string& locale) {
1164 runner_->SetPOSIXLocale(locale);
1167 void TestRunnerBindings::SetMIDIAccessorResult(bool result) {
1169 runner_->SetMIDIAccessorResult(result);
1172 void TestRunnerBindings::SetMIDISysexPermission(bool value) {
1174 runner_->SetMIDISysexPermission(value);
1177 void TestRunnerBindings::GrantWebNotificationPermission(gin::Arguments* args) {
1180 bool permission_granted = true;
1181 args->GetNext(&origin);
1182 args->GetNext(&permission_granted);
1183 return runner_->GrantWebNotificationPermission(origin, permission_granted);
1187 bool TestRunnerBindings::SimulateWebNotificationClick(
1188 const std::string& value) {
1190 return runner_->SimulateWebNotificationClick(value);
1194 void TestRunnerBindings::AddMockSpeechInputResult(const std::string& result,
1196 const std::string& language) {
1198 runner_->AddMockSpeechInputResult(result, confidence, language);
1201 void TestRunnerBindings::SetMockSpeechInputDumpRect(bool value) {
1203 runner_->SetMockSpeechInputDumpRect(value);
1206 void TestRunnerBindings::AddMockSpeechRecognitionResult(
1207 const std::string& transcript, double confidence) {
1209 runner_->AddMockSpeechRecognitionResult(transcript, confidence);
1212 void TestRunnerBindings::SetMockSpeechRecognitionError(
1213 const std::string& error, const std::string& message) {
1215 runner_->SetMockSpeechRecognitionError(error, message);
1218 bool TestRunnerBindings::WasMockSpeechRecognitionAborted() {
1220 return runner_->WasMockSpeechRecognitionAborted();
1224 void TestRunnerBindings::AddWebPageOverlay() {
1226 runner_->AddWebPageOverlay();
1229 void TestRunnerBindings::RemoveWebPageOverlay() {
1231 runner_->RemoveWebPageOverlay();
1234 void TestRunnerBindings::Display() {
1239 void TestRunnerBindings::DisplayInvalidatedRegion() {
1241 runner_->DisplayInvalidatedRegion();
1244 bool TestRunnerBindings::GlobalFlag() {
1246 return runner_->global_flag_;
1250 void TestRunnerBindings::SetGlobalFlag(bool value) {
1252 runner_->global_flag_ = value;
1255 std::string TestRunnerBindings::PlatformName() {
1257 return runner_->platform_name_;
1258 return std::string();
1261 std::string TestRunnerBindings::TooltipText() {
1263 return runner_->tooltip_text_;
1264 return std::string();
1267 bool TestRunnerBindings::DisableNotifyDone() {
1269 return runner_->disable_notify_done_;
1273 int TestRunnerBindings::WebHistoryItemCount() {
1275 return runner_->web_history_item_count_;
1279 bool TestRunnerBindings::InterceptPostMessage() {
1281 return runner_->intercept_post_message_;
1285 void TestRunnerBindings::SetInterceptPostMessage(bool value) {
1287 runner_->intercept_post_message_ = value;
1290 void TestRunnerBindings::NotImplemented(const gin::Arguments& args) {
1293 class TestPageOverlay : public WebPageOverlay {
1295 explicit TestPageOverlay(WebView* web_view)
1296 : web_view_(web_view) {
1298 virtual ~TestPageOverlay() {}
1300 virtual void paintPageOverlay(WebCanvas* canvas) OVERRIDE {
1301 SkRect rect = SkRect::MakeWH(web_view_->size().width,
1302 web_view_->size().height);
1304 paint.setColor(SK_ColorCYAN);
1305 paint.setStyle(SkPaint::kFill_Style);
1306 canvas->drawRect(rect, paint);
1313 TestRunner::WorkQueue::WorkQueue(TestRunner* controller)
1315 , controller_(controller) {}
1317 TestRunner::WorkQueue::~WorkQueue() {
1321 void TestRunner::WorkQueue::ProcessWorkSoon() {
1322 if (controller_->topLoadingFrame())
1325 if (!queue_.empty()) {
1326 // We delay processing queued work to avoid recursion problems.
1327 controller_->delegate_->postTask(new WorkQueueTask(this));
1328 } else if (!controller_->wait_until_done_) {
1329 controller_->delegate_->testFinished();
1333 void TestRunner::WorkQueue::Reset() {
1335 while (!queue_.empty()) {
1336 delete queue_.front();
1341 void TestRunner::WorkQueue::AddWork(WorkItem* work) {
1346 queue_.push_back(work);
1349 void TestRunner::WorkQueue::ProcessWork() {
1350 // Quit doing work once a load is in progress.
1351 while (!queue_.empty()) {
1352 bool startedLoad = queue_.front()->Run(controller_->delegate_,
1353 controller_->web_view_);
1354 delete queue_.front();
1360 if (!controller_->wait_until_done_ && !controller_->topLoadingFrame())
1361 controller_->delegate_->testFinished();
1364 void TestRunner::WorkQueue::WorkQueueTask::runIfValid() {
1365 m_object->ProcessWork();
1368 TestRunner::TestRunner(TestInterfaces* interfaces)
1369 : test_is_running_(false),
1370 close_remaining_windows_(false),
1372 disable_notify_done_(false),
1373 web_history_item_count_(0),
1374 intercept_post_message_(false),
1375 test_interfaces_(interfaces),
1378 page_overlay_(NULL),
1379 web_permissions_(new WebPermissions()),
1380 notification_presenter_(new content::NotificationPresenter()),
1381 weak_factory_(this) {}
1383 TestRunner::~TestRunner() {}
1385 void TestRunner::Install(WebFrame* frame) {
1386 TestRunnerBindings::Install(weak_factory_.GetWeakPtr(), frame);
1389 void TestRunner::SetDelegate(WebTestDelegate* delegate) {
1390 delegate_ = delegate;
1391 web_permissions_->setDelegate(delegate);
1392 notification_presenter_->set_delegate(delegate);
1395 void TestRunner::SetWebView(WebView* webView, WebTestProxyBase* proxy) {
1396 web_view_ = webView;
1400 void TestRunner::Reset() {
1402 web_view_->setZoomLevel(0);
1403 web_view_->setTextZoomFactor(1);
1404 web_view_->setTabKeyCyclesThroughElements(true);
1405 #if !defined(__APPLE__) && !defined(WIN32) // Actually, TOOLKIT_GTK
1406 // (Constants copied because we can't depend on the header that defined
1407 // them from this file.)
1408 web_view_->setSelectionColors(
1409 0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232);
1411 web_view_->removeInjectedStyleSheets();
1412 web_view_->setVisibilityState(WebPageVisibilityStateVisible, true);
1413 web_view_->mainFrame()->enableViewSourceMode(false);
1415 if (page_overlay_) {
1416 web_view_->removePageOverlay(page_overlay_);
1417 delete page_overlay_;
1418 page_overlay_ = NULL;
1422 top_loading_frame_ = NULL;
1423 wait_until_done_ = false;
1424 policy_delegate_enabled_ = false;
1425 policy_delegate_is_permissive_ = false;
1426 policy_delegate_should_notify_done_ = false;
1428 WebSecurityPolicy::resetOriginAccessWhitelists();
1429 #if defined(__linux__) || defined(ANDROID)
1430 WebFontRendering::setSubpixelPositioning(false);
1434 // Reset the default quota for each origin to 5MB
1435 delegate_->setDatabaseQuota(5 * 1024 * 1024);
1436 delegate_->setDeviceScaleFactor(1);
1437 delegate_->setAcceptAllCookies(false);
1438 delegate_->setLocale("");
1439 delegate_->useUnfortunateSynchronousResizeMode(false);
1440 delegate_->disableAutoResizeMode(WebSize());
1441 delegate_->deleteAllCookies();
1444 dump_editting_callbacks_ = false;
1445 dump_as_text_ = false;
1446 dump_as_markup_ = false;
1447 generate_pixel_results_ = true;
1448 dump_child_frame_scroll_positions_ = false;
1449 dump_child_frames_as_text_ = false;
1450 dump_icon_changes_ = false;
1451 dump_as_audio_ = false;
1452 dump_frame_load_callbacks_ = false;
1453 dump_ping_loader_callbacks_ = false;
1454 dump_user_gesture_in_frame_load_callbacks_ = false;
1455 dump_title_changes_ = false;
1456 dump_create_view_ = false;
1457 can_open_windows_ = false;
1458 dump_resource_load_callbacks_ = false;
1459 dump_resource_request_callbacks_ = false;
1460 dump_resource_reqponse_mime_types_ = false;
1461 dump_window_status_changes_ = false;
1462 dump_progress_finished_callback_ = false;
1463 dump_spell_check_callbacks_ = false;
1464 dump_back_forward_list_ = false;
1465 dump_selection_rect_ = false;
1466 test_repaint_ = false;
1467 sweep_horizontally_ = false;
1468 is_printing_ = false;
1469 midi_accessor_result_ = true;
1470 should_stay_on_page_after_handling_before_unload_ = false;
1471 should_dump_resource_priorities_ = false;
1473 http_headers_to_clear_.clear();
1475 global_flag_ = false;
1476 platform_name_ = "chromium";
1477 tooltip_text_ = std::string();
1478 disable_notify_done_ = false;
1479 web_history_item_count_ = 0;
1480 intercept_post_message_ = false;
1482 web_permissions_->reset();
1484 notification_presenter_->Reset();
1485 use_mock_theme_ = true;
1486 pointer_locked_ = false;
1487 pointer_lock_planned_result_ = PointerLockWillSucceed;
1489 task_list_.revokeAll();
1490 work_queue_.Reset();
1492 if (close_remaining_windows_ && delegate_)
1493 delegate_->closeRemainingWindows();
1495 close_remaining_windows_ = true;
1498 void TestRunner::SetTestIsRunning(bool running) {
1499 test_is_running_ = running;
1502 bool TestRunner::shouldDumpEditingCallbacks() const {
1503 return dump_editting_callbacks_;
1506 bool TestRunner::shouldDumpAsText() {
1507 CheckResponseMimeType();
1508 return dump_as_text_;
1511 void TestRunner::setShouldDumpAsText(bool value) {
1512 dump_as_text_ = value;
1515 bool TestRunner::shouldDumpAsMarkup() {
1516 return dump_as_markup_;
1519 void TestRunner::setShouldDumpAsMarkup(bool value) {
1520 dump_as_markup_ = value;
1523 bool TestRunner::shouldGeneratePixelResults() {
1524 CheckResponseMimeType();
1525 return generate_pixel_results_;
1528 void TestRunner::setShouldGeneratePixelResults(bool value) {
1529 generate_pixel_results_ = value;
1532 bool TestRunner::shouldDumpChildFrameScrollPositions() const {
1533 return dump_child_frame_scroll_positions_;
1536 bool TestRunner::shouldDumpChildFramesAsText() const {
1537 return dump_child_frames_as_text_;
1540 bool TestRunner::shouldDumpAsAudio() const {
1541 return dump_as_audio_;
1544 void TestRunner::getAudioData(std::vector<unsigned char>* bufferView) const {
1545 *bufferView = audio_data_;
1548 bool TestRunner::shouldDumpFrameLoadCallbacks() const {
1549 return test_is_running_ && dump_frame_load_callbacks_;
1552 void TestRunner::setShouldDumpFrameLoadCallbacks(bool value) {
1553 dump_frame_load_callbacks_ = value;
1556 bool TestRunner::shouldDumpPingLoaderCallbacks() const {
1557 return test_is_running_ && dump_ping_loader_callbacks_;
1560 void TestRunner::setShouldDumpPingLoaderCallbacks(bool value) {
1561 dump_ping_loader_callbacks_ = value;
1564 void TestRunner::setShouldEnableViewSource(bool value) {
1565 web_view_->mainFrame()->enableViewSourceMode(value);
1568 bool TestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const {
1569 return test_is_running_ && dump_user_gesture_in_frame_load_callbacks_;
1572 bool TestRunner::shouldDumpTitleChanges() const {
1573 return dump_title_changes_;
1576 bool TestRunner::shouldDumpIconChanges() const {
1577 return dump_icon_changes_;
1580 bool TestRunner::shouldDumpCreateView() const {
1581 return dump_create_view_;
1584 bool TestRunner::canOpenWindows() const {
1585 return can_open_windows_;
1588 bool TestRunner::shouldDumpResourceLoadCallbacks() const {
1589 return test_is_running_ && dump_resource_load_callbacks_;
1592 bool TestRunner::shouldDumpResourceRequestCallbacks() const {
1593 return test_is_running_ && dump_resource_request_callbacks_;
1596 bool TestRunner::shouldDumpResourceResponseMIMETypes() const {
1597 return test_is_running_ && dump_resource_reqponse_mime_types_;
1600 WebPermissionClient* TestRunner::webPermissions() const {
1601 return web_permissions_.get();
1604 bool TestRunner::shouldDumpStatusCallbacks() const {
1605 return dump_window_status_changes_;
1608 bool TestRunner::shouldDumpProgressFinishedCallback() const {
1609 return dump_progress_finished_callback_;
1612 bool TestRunner::shouldDumpSpellCheckCallbacks() const {
1613 return dump_spell_check_callbacks_;
1616 bool TestRunner::shouldDumpBackForwardList() const {
1617 return dump_back_forward_list_;
1620 bool TestRunner::shouldDumpSelectionRect() const {
1621 return dump_selection_rect_;
1624 bool TestRunner::testRepaint() const {
1625 return test_repaint_;
1628 bool TestRunner::sweepHorizontally() const {
1629 return sweep_horizontally_;
1632 bool TestRunner::isPrinting() const {
1633 return is_printing_;
1636 bool TestRunner::shouldStayOnPageAfterHandlingBeforeUnload() const {
1637 return should_stay_on_page_after_handling_before_unload_;
1640 const std::set<std::string>* TestRunner::httpHeadersToClear() const {
1641 return &http_headers_to_clear_;
1644 void TestRunner::setTopLoadingFrame(WebFrame* frame, bool clear) {
1645 if (frame->top()->view() != web_view_)
1647 if (!test_is_running_)
1650 top_loading_frame_ = NULL;
1651 LocationChangeDone();
1652 } else if (!top_loading_frame_) {
1653 top_loading_frame_ = frame;
1657 WebFrame* TestRunner::topLoadingFrame() const {
1658 return top_loading_frame_;
1661 void TestRunner::policyDelegateDone() {
1662 BLINK_ASSERT(wait_until_done_);
1663 delegate_->testFinished();
1664 wait_until_done_ = false;
1667 bool TestRunner::policyDelegateEnabled() const {
1668 return policy_delegate_enabled_;
1671 bool TestRunner::policyDelegateIsPermissive() const {
1672 return policy_delegate_is_permissive_;
1675 bool TestRunner::policyDelegateShouldNotifyDone() const {
1676 return policy_delegate_should_notify_done_;
1679 bool TestRunner::shouldInterceptPostMessage() const {
1680 return intercept_post_message_;
1683 bool TestRunner::shouldDumpResourcePriorities() const {
1684 return should_dump_resource_priorities_;
1687 WebNotificationPresenter* TestRunner::notification_presenter() const {
1688 return notification_presenter_.get();
1691 bool TestRunner::RequestPointerLock() {
1692 switch (pointer_lock_planned_result_) {
1693 case PointerLockWillSucceed:
1694 delegate_->postDelayedTask(
1695 new HostMethodTask(this, &TestRunner::DidAcquirePointerLockInternal),
1698 case PointerLockWillRespondAsync:
1699 BLINK_ASSERT(!pointer_locked_);
1701 case PointerLockWillFailSync:
1702 BLINK_ASSERT(!pointer_locked_);
1705 BLINK_ASSERT_NOT_REACHED();
1710 void TestRunner::RequestPointerUnlock() {
1711 delegate_->postDelayedTask(
1712 new HostMethodTask(this, &TestRunner::DidLosePointerLockInternal), 0);
1715 bool TestRunner::isPointerLocked() {
1716 return pointer_locked_;
1719 void TestRunner::setToolTipText(const WebString& text) {
1720 tooltip_text_ = text.utf8();
1723 bool TestRunner::midiAccessorResult() {
1724 return midi_accessor_result_;
1727 void TestRunner::clearDevToolsLocalStorage() {
1728 delegate_->clearDevToolsLocalStorage();
1731 void TestRunner::showDevTools(const std::string& settings) {
1732 delegate_->showDevTools(settings);
1735 class WorkItemBackForward : public TestRunner::WorkItem {
1737 WorkItemBackForward(int distance) : distance_(distance) {}
1739 virtual bool Run(WebTestDelegate* delegate, WebView*) OVERRIDE {
1740 delegate->goToOffset(distance_);
1741 return true; // FIXME: Did it really start a navigation?
1748 void TestRunner::NotifyDone() {
1749 if (disable_notify_done_)
1752 // Test didn't timeout. Kill the timeout timer.
1753 taskList()->revokeAll();
1755 CompleteNotifyDone();
1758 void TestRunner::WaitUntilDone() {
1759 wait_until_done_ = true;
1762 void TestRunner::QueueBackNavigation(int how_far_back) {
1763 work_queue_.AddWork(new WorkItemBackForward(-how_far_back));
1766 void TestRunner::QueueForwardNavigation(int how_far_forward) {
1767 work_queue_.AddWork(new WorkItemBackForward(how_far_forward));
1770 class WorkItemReload : public TestRunner::WorkItem {
1772 virtual bool Run(WebTestDelegate* delegate, WebView*) OVERRIDE {
1778 void TestRunner::QueueReload() {
1779 work_queue_.AddWork(new WorkItemReload());
1782 class WorkItemLoadingScript : public TestRunner::WorkItem {
1784 WorkItemLoadingScript(const std::string& script)
1785 : script_(script) {}
1787 virtual bool Run(WebTestDelegate*, WebView* web_view) OVERRIDE {
1788 web_view->mainFrame()->executeScript(
1789 WebScriptSource(WebString::fromUTF8(script_)));
1790 return true; // FIXME: Did it really start a navigation?
1794 std::string script_;
1797 void TestRunner::QueueLoadingScript(const std::string& script) {
1798 work_queue_.AddWork(new WorkItemLoadingScript(script));
1801 class WorkItemNonLoadingScript : public TestRunner::WorkItem {
1803 WorkItemNonLoadingScript(const std::string& script)
1804 : script_(script) {}
1806 virtual bool Run(WebTestDelegate*, WebView* web_view) OVERRIDE {
1807 web_view->mainFrame()->executeScript(
1808 WebScriptSource(WebString::fromUTF8(script_)));
1813 std::string script_;
1816 void TestRunner::QueueNonLoadingScript(const std::string& script) {
1817 work_queue_.AddWork(new WorkItemNonLoadingScript(script));
1820 class WorkItemLoad : public TestRunner::WorkItem {
1822 WorkItemLoad(const WebURL& url, const std::string& target)
1823 : url_(url), target_(target) {}
1825 virtual bool Run(WebTestDelegate* delegate, WebView*) OVERRIDE {
1826 delegate->loadURLForFrame(url_, target_);
1827 return true; // FIXME: Did it really start a navigation?
1832 std::string target_;
1835 void TestRunner::QueueLoad(const std::string& url, const std::string& target) {
1836 // FIXME: Implement WebURL::resolve() and avoid GURL.
1837 GURL current_url = web_view_->mainFrame()->document().url();
1838 GURL full_url = current_url.Resolve(url);
1839 work_queue_.AddWork(new WorkItemLoad(full_url, target));
1842 class WorkItemLoadHTMLString : public TestRunner::WorkItem {
1844 WorkItemLoadHTMLString(const std::string& html, const WebURL& base_url)
1845 : html_(html), base_url_(base_url) {}
1847 WorkItemLoadHTMLString(const std::string& html, const WebURL& base_url,
1848 const WebURL& unreachable_url)
1849 : html_(html), base_url_(base_url), unreachable_url_(unreachable_url) {}
1851 virtual bool Run(WebTestDelegate*, WebView* web_view) OVERRIDE {
1852 web_view->mainFrame()->loadHTMLString(
1853 WebData(html_.data(), html_.length()),
1854 base_url_, unreachable_url_);
1861 WebURL unreachable_url_;
1864 void TestRunner::QueueLoadHTMLString(gin::Arguments* args) {
1866 args->GetNext(&html);
1868 std::string base_url_str;
1869 args->GetNext(&base_url_str);
1870 WebURL base_url = WebURL(GURL(base_url_str));
1872 if (args->PeekNext()->IsString()) {
1873 std::string unreachable_url_str;
1874 args->GetNext(&unreachable_url_str);
1875 WebURL unreachable_url = WebURL(GURL(unreachable_url_str));
1876 work_queue_.AddWork(new WorkItemLoadHTMLString(html, base_url,
1879 work_queue_.AddWork(new WorkItemLoadHTMLString(html, base_url));
1883 void TestRunner::SetCustomPolicyDelegate(gin::Arguments* args) {
1884 args->GetNext(&policy_delegate_enabled_);
1885 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsBoolean())
1886 args->GetNext(&policy_delegate_is_permissive_);
1889 void TestRunner::WaitForPolicyDelegate() {
1890 policy_delegate_enabled_ = true;
1891 policy_delegate_should_notify_done_ = true;
1892 wait_until_done_ = true;
1895 int TestRunner::WindowCount() {
1896 return test_interfaces_->windowList().size();
1899 void TestRunner::SetCloseRemainingWindowsWhenComplete(
1900 bool close_remaining_windows) {
1901 close_remaining_windows_ = close_remaining_windows;
1904 void TestRunner::ResetTestHelperControllers() {
1905 test_interfaces_->resetTestHelperControllers();
1908 void TestRunner::SetTabKeyCyclesThroughElements(
1909 bool tab_key_cycles_through_elements) {
1910 web_view_->setTabKeyCyclesThroughElements(tab_key_cycles_through_elements);
1913 void TestRunner::ExecCommand(gin::Arguments* args) {
1914 std::string command;
1915 args->GetNext(&command);
1918 if (args->Length() >= 3) {
1919 // Ignore the second parameter (which is userInterface)
1920 // since this command emulates a manual action.
1922 args->GetNext(&value);
1925 // Note: webkit's version does not return the boolean, so neither do we.
1926 web_view_->focusedFrame()->executeCommand(WebString::fromUTF8(command),
1927 WebString::fromUTF8(value));
1930 bool TestRunner::IsCommandEnabled(const std::string& command) {
1931 return web_view_->focusedFrame()->isCommandEnabled(
1932 WebString::fromUTF8(command));
1935 bool TestRunner::CallShouldCloseOnWebView() {
1936 return web_view_->dispatchBeforeUnloadEvent();
1939 void TestRunner::SetDomainRelaxationForbiddenForURLScheme(
1940 bool forbidden, const std::string& scheme) {
1941 web_view_->setDomainRelaxationForbidden(forbidden,
1942 WebString::fromUTF8(scheme));
1945 v8::Handle<v8::Value> TestRunner::EvaluateScriptInIsolatedWorldAndReturnValue(
1947 const std::string& script) {
1948 WebVector<v8::Local<v8::Value> > values;
1949 WebScriptSource source(WebString::fromUTF8(script));
1950 // This relies on the iframe focusing itself when it loads. This is a bit
1951 // sketchy, but it seems to be what other tests do.
1952 web_view_->focusedFrame()->executeScriptInIsolatedWorld(
1953 world_id, &source, 1, 1, &values);
1954 // Since only one script was added, only one result is expected
1955 if (values.size() == 1 && !values[0].IsEmpty())
1957 return v8::Handle<v8::Value>();
1960 void TestRunner::EvaluateScriptInIsolatedWorld(int world_id,
1961 const std::string& script) {
1962 WebScriptSource source(WebString::fromUTF8(script));
1963 web_view_->focusedFrame()->executeScriptInIsolatedWorld(
1964 world_id, &source, 1, 1);
1967 void TestRunner::SetIsolatedWorldSecurityOrigin(int world_id,
1968 v8::Handle<v8::Value> origin) {
1969 if (!(origin->IsString() || !origin->IsNull()))
1972 WebSecurityOrigin web_origin;
1973 if (origin->IsString()) {
1974 web_origin = WebSecurityOrigin::createFromString(
1975 V8StringToWebString(origin->ToString()));
1977 web_view_->focusedFrame()->setIsolatedWorldSecurityOrigin(world_id,
1981 void TestRunner::SetIsolatedWorldContentSecurityPolicy(
1983 const std::string& policy) {
1984 web_view_->focusedFrame()->setIsolatedWorldContentSecurityPolicy(
1985 world_id, WebString::fromUTF8(policy));
1988 void TestRunner::AddOriginAccessWhitelistEntry(
1989 const std::string& source_origin,
1990 const std::string& destination_protocol,
1991 const std::string& destination_host,
1992 bool allow_destination_subdomains) {
1993 WebURL url((GURL(source_origin)));
1997 WebSecurityPolicy::addOriginAccessWhitelistEntry(
1999 WebString::fromUTF8(destination_protocol),
2000 WebString::fromUTF8(destination_host),
2001 allow_destination_subdomains);
2004 void TestRunner::RemoveOriginAccessWhitelistEntry(
2005 const std::string& source_origin,
2006 const std::string& destination_protocol,
2007 const std::string& destination_host,
2008 bool allow_destination_subdomains) {
2009 WebURL url((GURL(source_origin)));
2013 WebSecurityPolicy::removeOriginAccessWhitelistEntry(
2015 WebString::fromUTF8(destination_protocol),
2016 WebString::fromUTF8(destination_host),
2017 allow_destination_subdomains);
2020 bool TestRunner::HasCustomPageSizeStyle(int page_index) {
2021 WebFrame* frame = web_view_->mainFrame();
2024 return frame->hasCustomPageSizeStyle(page_index);
2027 void TestRunner::ForceRedSelectionColors() {
2028 web_view_->setSelectionColors(0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0);
2031 void TestRunner::InjectStyleSheet(const std::string& source_code,
2033 WebView::injectStyleSheet(
2034 WebString::fromUTF8(source_code),
2035 WebVector<WebString>(),
2036 all_frames ? WebView::InjectStyleInAllFrames
2037 : WebView::InjectStyleInTopFrameOnly);
2040 bool TestRunner::FindString(const std::string& search_text,
2041 const std::vector<std::string>& options_array) {
2042 WebFindOptions find_options;
2043 bool wrap_around = false;
2044 find_options.matchCase = true;
2045 find_options.findNext = true;
2047 for (size_t i = 0; i < options_array.size(); ++i) {
2048 const std::string& option = options_array[i];
2049 if (option == "CaseInsensitive")
2050 find_options.matchCase = false;
2051 else if (option == "Backwards")
2052 find_options.forward = false;
2053 else if (option == "StartInSelection")
2054 find_options.findNext = false;
2055 else if (option == "AtWordStarts")
2056 find_options.wordStart = true;
2057 else if (option == "TreatMedialCapitalAsWordStart")
2058 find_options.medialCapitalAsWordStart = true;
2059 else if (option == "WrapAround")
2063 WebFrame* frame = web_view_->mainFrame();
2064 const bool find_result = frame->find(0, WebString::fromUTF8(search_text),
2065 find_options, wrap_around, 0);
2066 frame->stopFinding(false);
2070 std::string TestRunner::SelectionAsMarkup() {
2071 return web_view_->mainFrame()->selectionAsMarkup().utf8();
2074 void TestRunner::SetTextSubpixelPositioning(bool value) {
2075 #if defined(__linux__) || defined(ANDROID)
2076 // Since FontConfig doesn't provide a variable to control subpixel
2077 // positioning, we'll fall back to setting it globally for all fonts.
2078 WebFontRendering::setSubpixelPositioning(value);
2082 void TestRunner::SetPageVisibility(const std::string& new_visibility) {
2083 if (new_visibility == "visible")
2084 web_view_->setVisibilityState(WebPageVisibilityStateVisible, false);
2085 else if (new_visibility == "hidden")
2086 web_view_->setVisibilityState(WebPageVisibilityStateHidden, false);
2087 else if (new_visibility == "prerender")
2088 web_view_->setVisibilityState(WebPageVisibilityStatePrerender, false);
2091 void TestRunner::SetTextDirection(const std::string& direction_name) {
2092 // Map a direction name to a WebTextDirection value.
2093 WebTextDirection direction;
2094 if (direction_name == "auto")
2095 direction = WebTextDirectionDefault;
2096 else if (direction_name == "rtl")
2097 direction = WebTextDirectionRightToLeft;
2098 else if (direction_name == "ltr")
2099 direction = WebTextDirectionLeftToRight;
2103 web_view_->setTextDirection(direction);
2106 void TestRunner::UseUnfortunateSynchronousResizeMode() {
2107 delegate_->useUnfortunateSynchronousResizeMode(true);
2110 bool TestRunner::EnableAutoResizeMode(int min_width,
2114 WebSize min_size(min_width, min_height);
2115 WebSize max_size(max_width, max_height);
2116 delegate_->enableAutoResizeMode(min_size, max_size);
2120 bool TestRunner::DisableAutoResizeMode(int new_width, int new_height) {
2121 WebSize new_size(new_width, new_height);
2122 delegate_->disableAutoResizeMode(new_size);
2126 void TestRunner::SetMockDeviceMotion(
2127 bool has_acceleration_x, double acceleration_x,
2128 bool has_acceleration_y, double acceleration_y,
2129 bool has_acceleration_z, double acceleration_z,
2130 bool has_acceleration_including_gravity_x,
2131 double acceleration_including_gravity_x,
2132 bool has_acceleration_including_gravity_y,
2133 double acceleration_including_gravity_y,
2134 bool has_acceleration_including_gravity_z,
2135 double acceleration_including_gravity_z,
2136 bool has_rotation_rate_alpha, double rotation_rate_alpha,
2137 bool has_rotation_rate_beta, double rotation_rate_beta,
2138 bool has_rotation_rate_gamma, double rotation_rate_gamma,
2140 WebDeviceMotionData motion;
2143 motion.hasAccelerationX = has_acceleration_x;
2144 motion.accelerationX = acceleration_x;
2145 motion.hasAccelerationY = has_acceleration_y;
2146 motion.accelerationY = acceleration_y;
2147 motion.hasAccelerationZ = has_acceleration_z;
2148 motion.accelerationZ = acceleration_z;
2150 // accelerationIncludingGravity
2151 motion.hasAccelerationIncludingGravityX =
2152 has_acceleration_including_gravity_x;
2153 motion.accelerationIncludingGravityX = acceleration_including_gravity_x;
2154 motion.hasAccelerationIncludingGravityY =
2155 has_acceleration_including_gravity_y;
2156 motion.accelerationIncludingGravityY = acceleration_including_gravity_y;
2157 motion.hasAccelerationIncludingGravityZ =
2158 has_acceleration_including_gravity_z;
2159 motion.accelerationIncludingGravityZ = acceleration_including_gravity_z;
2162 motion.hasRotationRateAlpha = has_rotation_rate_alpha;
2163 motion.rotationRateAlpha = rotation_rate_alpha;
2164 motion.hasRotationRateBeta = has_rotation_rate_beta;
2165 motion.rotationRateBeta = rotation_rate_beta;
2166 motion.hasRotationRateGamma = has_rotation_rate_gamma;
2167 motion.rotationRateGamma = rotation_rate_gamma;
2170 motion.interval = interval;
2172 delegate_->setDeviceMotionData(motion);
2175 void TestRunner::SetMockDeviceOrientation(bool has_alpha, double alpha,
2176 bool has_beta, double beta,
2177 bool has_gamma, double gamma,
2178 bool has_absolute, bool absolute) {
2179 WebDeviceOrientationData orientation;
2182 orientation.hasAlpha = has_alpha;
2183 orientation.alpha = alpha;
2186 orientation.hasBeta = has_beta;
2187 orientation.beta = beta;
2190 orientation.hasGamma = has_gamma;
2191 orientation.gamma = gamma;
2194 orientation.hasAbsolute = has_absolute;
2195 orientation.absolute = absolute;
2197 delegate_->setDeviceOrientationData(orientation);
2200 void TestRunner::SetMockScreenOrientation(const std::string& orientation_str) {
2201 blink::WebScreenOrientation orientation;
2203 if (orientation_str == "portrait-primary") {
2204 orientation = WebScreenOrientationPortraitPrimary;
2205 } else if (orientation_str == "portrait-secondary") {
2206 orientation = WebScreenOrientationPortraitSecondary;
2207 } else if (orientation_str == "landscape-primary") {
2208 orientation = WebScreenOrientationLandscapePrimary;
2209 } else if (orientation_str == "landscape-secondary") {
2210 orientation = WebScreenOrientationLandscapeSecondary;
2213 delegate_->setScreenOrientation(orientation);
2216 void TestRunner::DidAcquirePointerLock() {
2217 DidAcquirePointerLockInternal();
2220 void TestRunner::DidNotAcquirePointerLock() {
2221 DidNotAcquirePointerLockInternal();
2224 void TestRunner::DidLosePointerLock() {
2225 DidLosePointerLockInternal();
2228 void TestRunner::SetPointerLockWillFailSynchronously() {
2229 pointer_lock_planned_result_ = PointerLockWillFailSync;
2232 void TestRunner::SetPointerLockWillRespondAsynchronously() {
2233 pointer_lock_planned_result_ = PointerLockWillRespondAsync;
2236 void TestRunner::SetPopupBlockingEnabled(bool block_popups) {
2237 delegate_->preferences()->javaScriptCanOpenWindowsAutomatically =
2239 delegate_->applyPreferences();
2242 void TestRunner::SetJavaScriptCanAccessClipboard(bool can_access) {
2243 delegate_->preferences()->javaScriptCanAccessClipboard = can_access;
2244 delegate_->applyPreferences();
2247 void TestRunner::SetXSSAuditorEnabled(bool enabled) {
2248 delegate_->preferences()->XSSAuditorEnabled = enabled;
2249 delegate_->applyPreferences();
2252 void TestRunner::SetAllowUniversalAccessFromFileURLs(bool allow) {
2253 delegate_->preferences()->allowUniversalAccessFromFileURLs = allow;
2254 delegate_->applyPreferences();
2257 void TestRunner::SetAllowFileAccessFromFileURLs(bool allow) {
2258 delegate_->preferences()->allowFileAccessFromFileURLs = allow;
2259 delegate_->applyPreferences();
2262 void TestRunner::OverridePreference(const std::string key,
2263 v8::Handle<v8::Value> value) {
2264 WebPreferences* prefs = delegate_->preferences();
2265 if (key == "WebKitDefaultFontSize") {
2266 prefs->defaultFontSize = value->Int32Value();
2267 } else if (key == "WebKitMinimumFontSize") {
2268 prefs->minimumFontSize = value->Int32Value();
2269 } else if (key == "WebKitDefaultTextEncodingName") {
2270 prefs->defaultTextEncodingName = V8StringToWebString(value->ToString());
2271 } else if (key == "WebKitJavaScriptEnabled") {
2272 prefs->javaScriptEnabled = value->BooleanValue();
2273 } else if (key == "WebKitSupportsMultipleWindows") {
2274 prefs->supportsMultipleWindows = value->BooleanValue();
2275 } else if (key == "WebKitDisplayImagesKey") {
2276 prefs->loadsImagesAutomatically = value->BooleanValue();
2277 } else if (key == "WebKitPluginsEnabled") {
2278 prefs->pluginsEnabled = value->BooleanValue();
2279 } else if (key == "WebKitJavaEnabled") {
2280 prefs->javaEnabled = value->BooleanValue();
2281 } else if (key == "WebKitOfflineWebApplicationCacheEnabled") {
2282 prefs->offlineWebApplicationCacheEnabled = value->BooleanValue();
2283 } else if (key == "WebKitTabToLinksPreferenceKey") {
2284 prefs->tabsToLinks = value->BooleanValue();
2285 } else if (key == "WebKitWebGLEnabled") {
2286 prefs->experimentalWebGLEnabled = value->BooleanValue();
2287 } else if (key == "WebKitCSSRegionsEnabled") {
2288 prefs->experimentalCSSRegionsEnabled = value->BooleanValue();
2289 } else if (key == "WebKitCSSGridLayoutEnabled") {
2290 prefs->experimentalCSSGridLayoutEnabled = value->BooleanValue();
2291 } else if (key == "WebKitHyperlinkAuditingEnabled") {
2292 prefs->hyperlinkAuditingEnabled = value->BooleanValue();
2293 } else if (key == "WebKitEnableCaretBrowsing") {
2294 prefs->caretBrowsingEnabled = value->BooleanValue();
2295 } else if (key == "WebKitAllowDisplayingInsecureContent") {
2296 prefs->allowDisplayOfInsecureContent = value->BooleanValue();
2297 } else if (key == "WebKitAllowRunningInsecureContent") {
2298 prefs->allowRunningOfInsecureContent = value->BooleanValue();
2299 } else if (key == "WebKitShouldRespectImageOrientation") {
2300 prefs->shouldRespectImageOrientation = value->BooleanValue();
2301 } else if (key == "WebKitWebAudioEnabled") {
2302 BLINK_ASSERT(value->BooleanValue());
2304 std::string message("Invalid name for preference: ");
2305 message.append(key);
2306 delegate_->printMessage(std::string("CONSOLE MESSAGE: ") + message + "\n");
2308 delegate_->applyPreferences();
2311 void TestRunner::SetPluginsEnabled(bool enabled) {
2312 delegate_->preferences()->pluginsEnabled = enabled;
2313 delegate_->applyPreferences();
2316 void TestRunner::DumpEditingCallbacks() {
2317 dump_editting_callbacks_ = true;
2320 void TestRunner::DumpAsText() {
2321 dump_as_text_ = true;
2322 generate_pixel_results_ = false;
2325 void TestRunner::DumpAsTextWithPixelResults() {
2326 dump_as_text_ = true;
2327 generate_pixel_results_ = true;
2330 void TestRunner::DumpChildFrameScrollPositions() {
2331 dump_child_frame_scroll_positions_ = true;
2334 void TestRunner::DumpChildFramesAsText() {
2335 dump_child_frames_as_text_ = true;
2338 void TestRunner::DumpIconChanges() {
2339 dump_icon_changes_ = true;
2342 void TestRunner::SetAudioData(const gin::ArrayBufferView& view) {
2343 unsigned char* bytes = static_cast<unsigned char*>(view.bytes());
2344 audio_data_.resize(view.num_bytes());
2345 std::copy(bytes, bytes + view.num_bytes(), audio_data_.begin());
2346 dump_as_audio_ = true;
2349 void TestRunner::DumpFrameLoadCallbacks() {
2350 dump_frame_load_callbacks_ = true;
2353 void TestRunner::DumpPingLoaderCallbacks() {
2354 dump_ping_loader_callbacks_ = true;
2357 void TestRunner::DumpUserGestureInFrameLoadCallbacks() {
2358 dump_user_gesture_in_frame_load_callbacks_ = true;
2361 void TestRunner::DumpTitleChanges() {
2362 dump_title_changes_ = true;
2365 void TestRunner::DumpCreateView() {
2366 dump_create_view_ = true;
2369 void TestRunner::SetCanOpenWindows() {
2370 can_open_windows_ = true;
2373 void TestRunner::DumpResourceLoadCallbacks() {
2374 dump_resource_load_callbacks_ = true;
2377 void TestRunner::DumpResourceRequestCallbacks() {
2378 dump_resource_request_callbacks_ = true;
2381 void TestRunner::DumpResourceResponseMIMETypes() {
2382 dump_resource_reqponse_mime_types_ = true;
2385 void TestRunner::SetImagesAllowed(bool allowed) {
2386 web_permissions_->setImagesAllowed(allowed);
2389 void TestRunner::SetScriptsAllowed(bool allowed) {
2390 web_permissions_->setScriptsAllowed(allowed);
2393 void TestRunner::SetStorageAllowed(bool allowed) {
2394 web_permissions_->setStorageAllowed(allowed);
2397 void TestRunner::SetPluginsAllowed(bool allowed) {
2398 web_permissions_->setPluginsAllowed(allowed);
2401 void TestRunner::SetAllowDisplayOfInsecureContent(bool allowed) {
2402 web_permissions_->setDisplayingInsecureContentAllowed(allowed);
2405 void TestRunner::SetAllowRunningOfInsecureContent(bool allowed) {
2406 web_permissions_->setRunningInsecureContentAllowed(allowed);
2409 void TestRunner::DumpPermissionClientCallbacks() {
2410 web_permissions_->setDumpCallbacks(true);
2413 void TestRunner::DumpWindowStatusChanges() {
2414 dump_window_status_changes_ = true;
2417 void TestRunner::DumpProgressFinishedCallback() {
2418 dump_progress_finished_callback_ = true;
2421 void TestRunner::DumpSpellCheckCallbacks() {
2422 dump_spell_check_callbacks_ = true;
2425 void TestRunner::DumpBackForwardList() {
2426 dump_back_forward_list_ = true;
2429 void TestRunner::DumpSelectionRect() {
2430 dump_selection_rect_ = true;
2433 void TestRunner::TestRepaint() {
2434 test_repaint_ = true;
2437 void TestRunner::RepaintSweepHorizontally() {
2438 sweep_horizontally_ = true;
2441 void TestRunner::SetPrinting() {
2442 is_printing_ = true;
2445 void TestRunner::SetShouldStayOnPageAfterHandlingBeforeUnload(bool value) {
2446 should_stay_on_page_after_handling_before_unload_ = value;
2449 void TestRunner::SetWillSendRequestClearHeader(const std::string& header) {
2450 if (!header.empty())
2451 http_headers_to_clear_.insert(header);
2454 void TestRunner::DumpResourceRequestPriorities() {
2455 should_dump_resource_priorities_ = true;
2458 void TestRunner::SetUseMockTheme(bool use) {
2459 use_mock_theme_ = use;
2462 void TestRunner::ShowWebInspector(const std::string& str) {
2466 void TestRunner::CloseWebInspector() {
2467 delegate_->closeDevTools();
2470 bool TestRunner::IsChooserShown() {
2471 return proxy_->isChooserShown();
2474 void TestRunner::EvaluateInWebInspector(int call_id,
2475 const std::string& script) {
2476 delegate_->evaluateInWebInspector(call_id, script);
2479 void TestRunner::ClearAllDatabases() {
2480 delegate_->clearAllDatabases();
2483 void TestRunner::SetDatabaseQuota(int quota) {
2484 delegate_->setDatabaseQuota(quota);
2487 void TestRunner::SetAlwaysAcceptCookies(bool accept) {
2488 delegate_->setAcceptAllCookies(accept);
2491 void TestRunner::SetWindowIsKey(bool value) {
2492 delegate_->setFocus(proxy_, value);
2495 std::string TestRunner::PathToLocalResource(const std::string& path) {
2496 return delegate_->pathToLocalResource(path);
2499 void TestRunner::SetBackingScaleFactor(double value,
2500 v8::Handle<v8::Function> callback) {
2501 delegate_->setDeviceScaleFactor(value);
2502 proxy_->discardBackingStore();
2503 delegate_->postTask(new InvokeCallbackTask(this, callback));
2506 void TestRunner::SetPOSIXLocale(const std::string& locale) {
2507 delegate_->setLocale(locale);
2510 void TestRunner::SetMIDIAccessorResult(bool result) {
2511 midi_accessor_result_ = result;
2514 void TestRunner::SetMIDISysexPermission(bool value) {
2515 const std::vector<WebTestProxyBase*>& windowList =
2516 test_interfaces_->windowList();
2517 for (unsigned i = 0; i < windowList.size(); ++i)
2518 windowList.at(i)->midiClientMock()->setSysexPermission(value);
2521 void TestRunner::GrantWebNotificationPermission(const std::string& origin,
2522 bool permission_granted) {
2523 notification_presenter_->GrantPermission(origin, permission_granted);
2526 bool TestRunner::SimulateWebNotificationClick(const std::string& value) {
2527 return notification_presenter_->SimulateClick(value);
2530 void TestRunner::AddMockSpeechInputResult(const std::string& result,
2532 const std::string& language) {
2533 #if ENABLE_INPUT_SPEECH
2534 proxy_->speechInputControllerMock()->addMockRecognitionResult(
2535 WebString::fromUTF8(result), confidence, WebString::fromUTF8(language));
2539 void TestRunner::SetMockSpeechInputDumpRect(bool value) {
2540 #if ENABLE_INPUT_SPEECH
2541 proxy_->speechInputControllerMock()->setDumpRect(value);
2545 void TestRunner::AddMockSpeechRecognitionResult(const std::string& transcript,
2546 double confidence) {
2547 proxy_->speechRecognizerMock()->addMockResult(
2548 WebString::fromUTF8(transcript), confidence);
2551 void TestRunner::SetMockSpeechRecognitionError(const std::string& error,
2552 const std::string& message) {
2553 proxy_->speechRecognizerMock()->setError(WebString::fromUTF8(error),
2554 WebString::fromUTF8(message));
2557 bool TestRunner::WasMockSpeechRecognitionAborted() {
2558 return proxy_->speechRecognizerMock()->wasAborted();
2561 void TestRunner::AddWebPageOverlay() {
2562 if (web_view_ && !page_overlay_) {
2563 page_overlay_ = new TestPageOverlay(web_view_);
2564 web_view_->addPageOverlay(page_overlay_, 0);
2568 void TestRunner::RemoveWebPageOverlay() {
2569 if (web_view_ && page_overlay_) {
2570 web_view_->removePageOverlay(page_overlay_);
2571 delete page_overlay_;
2572 page_overlay_ = NULL;
2576 void TestRunner::Display() {
2580 void TestRunner::DisplayInvalidatedRegion() {
2581 proxy_->displayInvalidatedRegion();
2584 void TestRunner::LocationChangeDone() {
2585 web_history_item_count_ = delegate_->navigationEntryCount();
2587 // No more new work after the first complete load.
2588 work_queue_.set_frozen(true);
2590 if (!wait_until_done_)
2591 work_queue_.ProcessWorkSoon();
2594 void TestRunner::CheckResponseMimeType() {
2595 // Text output: the test page can request different types of output which we
2597 if (!dump_as_text_) {
2598 std::string mimeType =
2599 web_view_->mainFrame()->dataSource()->response().mimeType().utf8();
2600 if (mimeType == "text/plain") {
2601 dump_as_text_ = true;
2602 generate_pixel_results_ = false;
2607 void TestRunner::CompleteNotifyDone() {
2608 if (wait_until_done_ && !topLoadingFrame() && work_queue_.is_empty())
2609 delegate_->testFinished();
2610 wait_until_done_ = false;
2613 void TestRunner::DidAcquirePointerLockInternal() {
2614 pointer_locked_ = true;
2615 web_view_->didAcquirePointerLock();
2617 // Reset planned result to default.
2618 pointer_lock_planned_result_ = PointerLockWillSucceed;
2621 void TestRunner::DidNotAcquirePointerLockInternal() {
2622 BLINK_ASSERT(!pointer_locked_);
2623 pointer_locked_ = false;
2624 web_view_->didNotAcquirePointerLock();
2626 // Reset planned result to default.
2627 pointer_lock_planned_result_ = PointerLockWillSucceed;
2630 void TestRunner::DidLosePointerLockInternal() {
2631 bool was_locked = pointer_locked_;
2632 pointer_locked_ = false;
2634 web_view_->didLosePointerLock();
2637 } // namespace content