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 WaitUntilExternalURLLoad();
226 void ShowWebInspector(gin::Arguments* args);
227 void CloseWebInspector();
228 bool IsChooserShown();
229 void EvaluateInWebInspector(int call_id, const std::string& script);
230 void ClearAllDatabases();
231 void SetDatabaseQuota(int quota);
232 void SetAlwaysAcceptCookies(bool accept);
233 void SetWindowIsKey(bool value);
234 std::string PathToLocalResource(const std::string& path);
235 void SetBackingScaleFactor(double value, v8::Handle<v8::Function> callback);
236 void SetPOSIXLocale(const std::string& locale);
237 void SetMIDIAccessorResult(bool result);
238 void SetMIDISysexPermission(bool value);
239 void GrantWebNotificationPermission(gin::Arguments* args);
240 bool SimulateWebNotificationClick(const std::string& value);
241 void AddMockSpeechInputResult(const std::string& result,
243 const std::string& language);
244 void SetMockSpeechInputDumpRect(bool value);
245 void AddMockSpeechRecognitionResult(const std::string& transcript,
247 void SetMockSpeechRecognitionError(const std::string& error,
248 const std::string& message);
249 bool WasMockSpeechRecognitionAborted();
250 void AddWebPageOverlay();
251 void RemoveWebPageOverlay();
253 void DisplayInvalidatedRegion();
256 void SetGlobalFlag(bool value);
257 std::string PlatformName();
258 std::string TooltipText();
259 bool DisableNotifyDone();
260 int WebHistoryItemCount();
261 bool InterceptPostMessage();
262 void SetInterceptPostMessage(bool value);
264 void NotImplemented(const gin::Arguments& args);
266 base::WeakPtr<TestRunner> runner_;
268 DISALLOW_COPY_AND_ASSIGN(TestRunnerBindings);
271 gin::WrapperInfo TestRunnerBindings::kWrapperInfo = {
272 gin::kEmbedderNativeGin};
275 void TestRunnerBindings::Install(base::WeakPtr<TestRunner> runner,
277 v8::Isolate* isolate = blink::mainThreadIsolate();
278 v8::HandleScope handle_scope(isolate);
279 v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
280 if (context.IsEmpty())
283 v8::Context::Scope context_scope(context);
285 gin::Handle<TestRunnerBindings> bindings =
286 gin::CreateHandle(isolate, new TestRunnerBindings(runner));
287 v8::Handle<v8::Object> global = context->Global();
288 v8::Handle<v8::Value> v8_bindings = bindings.ToV8();
289 global->Set(gin::StringToV8(isolate, "testRunner"), v8_bindings);
290 global->Set(gin::StringToV8(isolate, "layoutTestController"), v8_bindings);
293 TestRunnerBindings::TestRunnerBindings(base::WeakPtr<TestRunner> runner)
296 TestRunnerBindings::~TestRunnerBindings() {}
298 gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
299 v8::Isolate* isolate) {
300 return gin::Wrappable<TestRunnerBindings>::GetObjectTemplateBuilder(
302 // Methods controlling test execution.
303 .SetMethod("notifyDone", &TestRunnerBindings::NotifyDone)
304 .SetMethod("waitUntilDone", &TestRunnerBindings::WaitUntilDone)
305 .SetMethod("queueBackNavigation",
306 &TestRunnerBindings::QueueBackNavigation)
307 .SetMethod("queueForwardNavigation",
308 &TestRunnerBindings::QueueForwardNavigation)
309 .SetMethod("queueReload", &TestRunnerBindings::QueueReload)
310 .SetMethod("queueLoadingScript", &TestRunnerBindings::QueueLoadingScript)
311 .SetMethod("queueNonLoadingScript",
312 &TestRunnerBindings::QueueNonLoadingScript)
313 .SetMethod("queueLoad", &TestRunnerBindings::QueueLoad)
314 .SetMethod("queueLoadHTMLString",
315 &TestRunnerBindings::QueueLoadHTMLString)
316 .SetMethod("setCustomPolicyDelegate",
317 &TestRunnerBindings::SetCustomPolicyDelegate)
318 .SetMethod("waitForPolicyDelegate",
319 &TestRunnerBindings::WaitForPolicyDelegate)
320 .SetMethod("windowCount", &TestRunnerBindings::WindowCount)
321 .SetMethod("setCloseRemainingWindowsWhenComplete",
322 &TestRunnerBindings::SetCloseRemainingWindowsWhenComplete)
323 .SetMethod("resetTestHelperControllers",
324 &TestRunnerBindings::ResetTestHelperControllers)
325 .SetMethod("setTabKeyCyclesThroughElements",
326 &TestRunnerBindings::SetTabKeyCyclesThroughElements)
327 .SetMethod("execCommand", &TestRunnerBindings::ExecCommand)
328 .SetMethod("isCommandEnabled", &TestRunnerBindings::IsCommandEnabled)
329 .SetMethod("callShouldCloseOnWebView",
330 &TestRunnerBindings::CallShouldCloseOnWebView)
331 .SetMethod("setDomainRelaxationForbiddenForURLScheme",
332 &TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme)
333 .SetMethod("evaluateScriptInIsolatedWorldAndReturnValue",
334 &TestRunnerBindings::
335 EvaluateScriptInIsolatedWorldAndReturnValue)
336 .SetMethod("evaluateScriptInIsolatedWorld",
337 &TestRunnerBindings::EvaluateScriptInIsolatedWorld)
338 .SetMethod("setIsolatedWorldSecurityOrigin",
339 &TestRunnerBindings::SetIsolatedWorldSecurityOrigin)
340 .SetMethod("setIsolatedWorldContentSecurityPolicy",
341 &TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy)
342 .SetMethod("addOriginAccessWhitelistEntry",
343 &TestRunnerBindings::AddOriginAccessWhitelistEntry)
344 .SetMethod("removeOriginAccessWhitelistEntry",
345 &TestRunnerBindings::RemoveOriginAccessWhitelistEntry)
346 .SetMethod("hasCustomPageSizeStyle",
347 &TestRunnerBindings::HasCustomPageSizeStyle)
348 .SetMethod("forceRedSelectionColors",
349 &TestRunnerBindings::ForceRedSelectionColors)
350 .SetMethod("injectStyleSheet", &TestRunnerBindings::InjectStyleSheet)
351 .SetMethod("findString", &TestRunnerBindings::FindString)
352 .SetMethod("selectionAsMarkup", &TestRunnerBindings::SelectionAsMarkup)
353 .SetMethod("setTextSubpixelPositioning",
354 &TestRunnerBindings::SetTextSubpixelPositioning)
355 .SetMethod("setPageVisibility", &TestRunnerBindings::SetPageVisibility)
356 .SetMethod("setTextDirection", &TestRunnerBindings::SetTextDirection)
357 .SetMethod("useUnfortunateSynchronousResizeMode",
358 &TestRunnerBindings::UseUnfortunateSynchronousResizeMode)
359 .SetMethod("enableAutoResizeMode",
360 &TestRunnerBindings::EnableAutoResizeMode)
361 .SetMethod("disableAutoResizeMode",
362 &TestRunnerBindings::DisableAutoResizeMode)
363 .SetMethod("setMockDeviceMotion",
364 &TestRunnerBindings::SetMockDeviceMotion)
365 .SetMethod("setMockDeviceOrientation",
366 &TestRunnerBindings::SetMockDeviceOrientation)
367 .SetMethod("setMockScreenOrientation",
368 &TestRunnerBindings::SetMockScreenOrientation)
369 .SetMethod("didAcquirePointerLock",
370 &TestRunnerBindings::DidAcquirePointerLock)
371 .SetMethod("didNotAcquirePointerLock",
372 &TestRunnerBindings::DidNotAcquirePointerLock)
373 .SetMethod("didLosePointerLock", &TestRunnerBindings::DidLosePointerLock)
374 .SetMethod("setPointerLockWillFailSynchronously",
375 &TestRunnerBindings::SetPointerLockWillFailSynchronously)
376 .SetMethod("setPointerLockWillRespondAsynchronously",
377 &TestRunnerBindings::SetPointerLockWillRespondAsynchronously)
378 .SetMethod("setPopupBlockingEnabled",
379 &TestRunnerBindings::SetPopupBlockingEnabled)
380 .SetMethod("setJavaScriptCanAccessClipboard",
381 &TestRunnerBindings::SetJavaScriptCanAccessClipboard)
382 .SetMethod("setXSSAuditorEnabled",
383 &TestRunnerBindings::SetXSSAuditorEnabled)
384 .SetMethod("setAllowUniversalAccessFromFileURLs",
385 &TestRunnerBindings::SetAllowUniversalAccessFromFileURLs)
386 .SetMethod("setAllowFileAccessFromFileURLs",
387 &TestRunnerBindings::SetAllowFileAccessFromFileURLs)
388 .SetMethod("overridePreference", &TestRunnerBindings::OverridePreference)
389 .SetMethod("setPluginsEnabled", &TestRunnerBindings::SetPluginsEnabled)
390 .SetMethod("dumpEditingCallbacks",
391 &TestRunnerBindings::DumpEditingCallbacks)
392 .SetMethod("dumpAsText", &TestRunnerBindings::DumpAsText)
393 .SetMethod("dumpAsTextWithPixelResults",
394 &TestRunnerBindings::DumpAsTextWithPixelResults)
395 .SetMethod("dumpChildFrameScrollPositions",
396 &TestRunnerBindings::DumpChildFrameScrollPositions)
397 .SetMethod("dumpChildFramesAsText",
398 &TestRunnerBindings::DumpChildFramesAsText)
399 .SetMethod("dumpIconChanges", &TestRunnerBindings::DumpIconChanges)
400 .SetMethod("setAudioData", &TestRunnerBindings::SetAudioData)
401 .SetMethod("dumpFrameLoadCallbacks",
402 &TestRunnerBindings::DumpFrameLoadCallbacks)
403 .SetMethod("dumpPingLoaderCallbacks",
404 &TestRunnerBindings::DumpPingLoaderCallbacks)
405 .SetMethod("dumpUserGestureInFrameLoadCallbacks",
406 &TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks)
407 .SetMethod("dumpTitleChanges", &TestRunnerBindings::DumpTitleChanges)
408 .SetMethod("dumpCreateView", &TestRunnerBindings::DumpCreateView)
409 .SetMethod("setCanOpenWindows", &TestRunnerBindings::SetCanOpenWindows)
410 .SetMethod("dumpResourceLoadCallbacks",
411 &TestRunnerBindings::DumpResourceLoadCallbacks)
412 .SetMethod("dumpResourceRequestCallbacks",
413 &TestRunnerBindings::DumpResourceRequestCallbacks)
414 .SetMethod("dumpResourceResponseMIMETypes",
415 &TestRunnerBindings::DumpResourceResponseMIMETypes)
416 .SetMethod("setImagesAllowed", &TestRunnerBindings::SetImagesAllowed)
417 .SetMethod("setScriptsAllowed", &TestRunnerBindings::SetScriptsAllowed)
418 .SetMethod("setStorageAllowed", &TestRunnerBindings::SetStorageAllowed)
419 .SetMethod("setPluginsAllowed", &TestRunnerBindings::SetPluginsAllowed)
420 .SetMethod("setAllowDisplayOfInsecureContent",
421 &TestRunnerBindings::SetAllowDisplayOfInsecureContent)
422 .SetMethod("setAllowRunningOfInsecureContent",
423 &TestRunnerBindings::SetAllowRunningOfInsecureContent)
424 .SetMethod("dumpPermissionClientCallbacks",
425 &TestRunnerBindings::DumpPermissionClientCallbacks)
426 .SetMethod("dumpWindowStatusChanges",
427 &TestRunnerBindings::DumpWindowStatusChanges)
428 .SetMethod("dumpProgressFinishedCallback",
429 &TestRunnerBindings::DumpProgressFinishedCallback)
430 .SetMethod("dumpSpellCheckCallbacks",
431 &TestRunnerBindings::DumpSpellCheckCallbacks)
432 .SetMethod("dumpBackForwardList",
433 &TestRunnerBindings::DumpBackForwardList)
434 .SetMethod("dumpSelectionRect", &TestRunnerBindings::DumpSelectionRect)
435 .SetMethod("testRepaint", &TestRunnerBindings::TestRepaint)
436 .SetMethod("repaintSweepHorizontally",
437 &TestRunnerBindings::RepaintSweepHorizontally)
438 .SetMethod("setPrinting", &TestRunnerBindings::SetPrinting)
439 .SetMethod("setShouldStayOnPageAfterHandlingBeforeUnload",
440 &TestRunnerBindings::
441 SetShouldStayOnPageAfterHandlingBeforeUnload)
442 .SetMethod("setWillSendRequestClearHeader",
443 &TestRunnerBindings::SetWillSendRequestClearHeader)
444 .SetMethod("dumpResourceRequestPriorities",
445 &TestRunnerBindings::DumpResourceRequestPriorities)
446 .SetMethod("setUseMockTheme", &TestRunnerBindings::SetUseMockTheme)
447 .SetMethod("waitUntilExternalURLLoad",
448 &TestRunnerBindings::WaitUntilExternalURLLoad)
449 .SetMethod("showWebInspector", &TestRunnerBindings::ShowWebInspector)
450 .SetMethod("closeWebInspector", &TestRunnerBindings::CloseWebInspector)
451 .SetMethod("isChooserShown", &TestRunnerBindings::IsChooserShown)
452 .SetMethod("evaluateInWebInspector",
453 &TestRunnerBindings::EvaluateInWebInspector)
454 .SetMethod("clearAllDatabases", &TestRunnerBindings::ClearAllDatabases)
455 .SetMethod("setDatabaseQuota", &TestRunnerBindings::SetDatabaseQuota)
456 .SetMethod("setAlwaysAcceptCookies",
457 &TestRunnerBindings::SetAlwaysAcceptCookies)
458 .SetMethod("setWindowIsKey", &TestRunnerBindings::SetWindowIsKey)
459 .SetMethod("pathToLocalResource",
460 &TestRunnerBindings::PathToLocalResource)
461 .SetMethod("setBackingScaleFactor",
462 &TestRunnerBindings::SetBackingScaleFactor)
463 .SetMethod("setPOSIXLocale", &TestRunnerBindings::SetPOSIXLocale)
464 .SetMethod("setMIDIAccessorResult",
465 &TestRunnerBindings::SetMIDIAccessorResult)
466 .SetMethod("setMIDISysexPermission",
467 &TestRunnerBindings::SetMIDISysexPermission)
468 .SetMethod("grantWebNotificationPermission",
469 &TestRunnerBindings::GrantWebNotificationPermission)
470 .SetMethod("simulateWebNotificationClick",
471 &TestRunnerBindings::SimulateWebNotificationClick)
472 .SetMethod("addMockSpeechInputResult",
473 &TestRunnerBindings::AddMockSpeechInputResult)
474 .SetMethod("setMockSpeechInputDumpRect",
475 &TestRunnerBindings::SetMockSpeechInputDumpRect)
476 .SetMethod("addMockSpeechRecognitionResult",
477 &TestRunnerBindings::AddMockSpeechRecognitionResult)
478 .SetMethod("setMockSpeechRecognitionError",
479 &TestRunnerBindings::SetMockSpeechRecognitionError)
480 .SetMethod("wasMockSpeechRecognitionAborted",
481 &TestRunnerBindings::WasMockSpeechRecognitionAborted)
482 .SetMethod("addWebPageOverlay", &TestRunnerBindings::AddWebPageOverlay)
483 .SetMethod("removeWebPageOverlay",
484 &TestRunnerBindings::RemoveWebPageOverlay)
485 .SetMethod("display", &TestRunnerBindings::Display)
486 .SetMethod("displayInvalidatedRegion",
487 &TestRunnerBindings::DisplayInvalidatedRegion)
490 .SetProperty("globalFlag", &TestRunnerBindings::GlobalFlag,
491 &TestRunnerBindings::SetGlobalFlag)
492 .SetProperty("platformName", &TestRunnerBindings::PlatformName)
493 .SetProperty("tooltipText", &TestRunnerBindings::TooltipText)
494 .SetProperty("disableNotifyDone", &TestRunnerBindings::DisableNotifyDone)
495 // webHistoryItemCount is used by tests in LayoutTests\http\tests\history
496 .SetProperty("webHistoryItemCount",
497 &TestRunnerBindings::WebHistoryItemCount)
498 .SetProperty("interceptPostMessage",
499 &TestRunnerBindings::InterceptPostMessage,
500 &TestRunnerBindings::SetInterceptPostMessage)
502 // The following are stubs.
503 .SetMethod("dumpDatabaseCallbacks", &TestRunnerBindings::NotImplemented)
504 .SetMethod("setIconDatabaseEnabled", &TestRunnerBindings::NotImplemented)
505 .SetMethod("setScrollbarPolicy", &TestRunnerBindings::NotImplemented)
506 .SetMethod("clearAllApplicationCaches",
507 &TestRunnerBindings::NotImplemented)
508 .SetMethod("clearApplicationCacheForOrigin",
509 &TestRunnerBindings::NotImplemented)
510 .SetMethod("clearBackForwardList", &TestRunnerBindings::NotImplemented)
511 .SetMethod("keepWebHistory", &TestRunnerBindings::NotImplemented)
512 .SetMethod("setApplicationCacheOriginQuota",
513 &TestRunnerBindings::NotImplemented)
514 .SetMethod("setCallCloseOnWebViews", &TestRunnerBindings::NotImplemented)
515 .SetMethod("setMainFrameIsFirstResponder",
516 &TestRunnerBindings::NotImplemented)
517 .SetMethod("setUseDashboardCompatibilityMode",
518 &TestRunnerBindings::NotImplemented)
519 .SetMethod("deleteAllLocalStorage", &TestRunnerBindings::NotImplemented)
520 .SetMethod("localStorageDiskUsageForOrigin",
521 &TestRunnerBindings::NotImplemented)
522 .SetMethod("originsWithLocalStorage", &TestRunnerBindings::NotImplemented)
523 .SetMethod("deleteLocalStorageForOrigin",
524 &TestRunnerBindings::NotImplemented)
525 .SetMethod("observeStorageTrackerNotifications",
526 &TestRunnerBindings::NotImplemented)
527 .SetMethod("syncLocalStorage", &TestRunnerBindings::NotImplemented)
528 .SetMethod("addDisallowedURL", &TestRunnerBindings::NotImplemented)
529 .SetMethod("applicationCacheDiskUsageForOrigin",
530 &TestRunnerBindings::NotImplemented)
531 .SetMethod("abortModal", &TestRunnerBindings::NotImplemented)
534 // Used at fast/dom/assign-to-window-status.html
535 .SetMethod("dumpStatusCallbacks",
536 &TestRunnerBindings::DumpWindowStatusChanges);
540 void TestRunnerBindings::NotifyDone() {
542 runner_->NotifyDone();
545 void TestRunnerBindings::WaitUntilDone() {
547 runner_->WaitUntilDone();
550 void TestRunnerBindings::QueueBackNavigation(int how_far_back) {
552 runner_->QueueBackNavigation(how_far_back);
555 void TestRunnerBindings::QueueForwardNavigation(int how_far_forward) {
557 runner_->QueueForwardNavigation(how_far_forward);
560 void TestRunnerBindings::QueueReload() {
562 runner_->QueueReload();
565 void TestRunnerBindings::QueueLoadingScript(const std::string& script) {
567 runner_->QueueLoadingScript(script);
570 void TestRunnerBindings::QueueNonLoadingScript(const std::string& script) {
572 runner_->QueueNonLoadingScript(script);
575 void TestRunnerBindings::QueueLoad(gin::Arguments* args) {
580 args->GetNext(&target);
581 runner_->QueueLoad(url, target);
585 void TestRunnerBindings::QueueLoadHTMLString(gin::Arguments* args) {
587 runner_->QueueLoadHTMLString(args);
590 void TestRunnerBindings::SetCustomPolicyDelegate(gin::Arguments* args) {
592 runner_->SetCustomPolicyDelegate(args);
595 void TestRunnerBindings::WaitForPolicyDelegate() {
597 runner_->WaitForPolicyDelegate();
600 int TestRunnerBindings::WindowCount() {
602 return runner_->WindowCount();
606 void TestRunnerBindings::SetCloseRemainingWindowsWhenComplete(
607 gin::Arguments* args) {
611 // In the original implementation, nothing happens if the argument is
613 bool close_remaining_windows = false;
614 if (args->GetNext(&close_remaining_windows))
615 runner_->SetCloseRemainingWindowsWhenComplete(close_remaining_windows);
618 void TestRunnerBindings::ResetTestHelperControllers() {
620 runner_->ResetTestHelperControllers();
623 void TestRunnerBindings::SetTabKeyCyclesThroughElements(
624 bool tab_key_cycles_through_elements) {
626 runner_->SetTabKeyCyclesThroughElements(tab_key_cycles_through_elements);
629 void TestRunnerBindings::ExecCommand(gin::Arguments* args) {
631 runner_->ExecCommand(args);
634 bool TestRunnerBindings::IsCommandEnabled(const std::string& command) {
636 return runner_->IsCommandEnabled(command);
640 bool TestRunnerBindings::CallShouldCloseOnWebView() {
642 return runner_->CallShouldCloseOnWebView();
646 void TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme(
647 bool forbidden, const std::string& scheme) {
649 runner_->SetDomainRelaxationForbiddenForURLScheme(forbidden, scheme);
652 v8::Handle<v8::Value>
653 TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue(
654 int world_id, const std::string& script) {
656 return v8::Handle<v8::Value>();
657 return runner_->EvaluateScriptInIsolatedWorldAndReturnValue(world_id,
661 void TestRunnerBindings::EvaluateScriptInIsolatedWorld(
662 int world_id, const std::string& script) {
664 runner_->EvaluateScriptInIsolatedWorld(world_id, script);
667 void TestRunnerBindings::SetIsolatedWorldSecurityOrigin(
668 int world_id, v8::Handle<v8::Value> origin) {
670 runner_->SetIsolatedWorldSecurityOrigin(world_id, origin);
673 void TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy(
674 int world_id, const std::string& policy) {
676 runner_->SetIsolatedWorldContentSecurityPolicy(world_id, policy);
679 void TestRunnerBindings::AddOriginAccessWhitelistEntry(
680 const std::string& source_origin,
681 const std::string& destination_protocol,
682 const std::string& destination_host,
683 bool allow_destination_subdomains) {
685 runner_->AddOriginAccessWhitelistEntry(source_origin,
686 destination_protocol,
688 allow_destination_subdomains);
692 void TestRunnerBindings::RemoveOriginAccessWhitelistEntry(
693 const std::string& source_origin,
694 const std::string& destination_protocol,
695 const std::string& destination_host,
696 bool allow_destination_subdomains) {
698 runner_->RemoveOriginAccessWhitelistEntry(source_origin,
699 destination_protocol,
701 allow_destination_subdomains);
705 bool TestRunnerBindings::HasCustomPageSizeStyle(int page_index) {
707 return runner_->HasCustomPageSizeStyle(page_index);
711 void TestRunnerBindings::ForceRedSelectionColors() {
713 runner_->ForceRedSelectionColors();
716 void TestRunnerBindings::InjectStyleSheet(const std::string& source_code,
719 runner_->InjectStyleSheet(source_code, all_frames);
722 bool TestRunnerBindings::FindString(
723 const std::string& search_text,
724 const std::vector<std::string>& options_array) {
726 return runner_->FindString(search_text, options_array);
730 std::string TestRunnerBindings::SelectionAsMarkup() {
732 return runner_->SelectionAsMarkup();
733 return std::string();
736 void TestRunnerBindings::SetTextSubpixelPositioning(bool value) {
738 runner_->SetTextSubpixelPositioning(value);
741 void TestRunnerBindings::SetPageVisibility(const std::string& new_visibility) {
743 runner_->SetPageVisibility(new_visibility);
746 void TestRunnerBindings::SetTextDirection(const std::string& direction_name) {
748 runner_->SetTextDirection(direction_name);
751 void TestRunnerBindings::UseUnfortunateSynchronousResizeMode() {
753 runner_->UseUnfortunateSynchronousResizeMode();
756 bool TestRunnerBindings::EnableAutoResizeMode(int min_width,
761 return runner_->EnableAutoResizeMode(min_width, min_height,
762 max_width, max_height);
767 bool TestRunnerBindings::DisableAutoResizeMode(int new_width, int new_height) {
769 return runner_->DisableAutoResizeMode(new_width, new_height);
773 void TestRunnerBindings::SetMockDeviceMotion(gin::Arguments* args) {
777 bool has_acceleration_x;
778 double acceleration_x;
779 bool has_acceleration_y;
780 double acceleration_y;
781 bool has_acceleration_z;
782 double acceleration_z;
783 bool has_acceleration_including_gravity_x;
784 double acceleration_including_gravity_x;
785 bool has_acceleration_including_gravity_y;
786 double acceleration_including_gravity_y;
787 bool has_acceleration_including_gravity_z;
788 double acceleration_including_gravity_z;
789 bool has_rotation_rate_alpha;
790 double rotation_rate_alpha;
791 bool has_rotation_rate_beta;
792 double rotation_rate_beta;
793 bool has_rotation_rate_gamma;
794 double rotation_rate_gamma;
797 args->GetNext(&has_acceleration_x);
798 args->GetNext(& acceleration_x);
799 args->GetNext(&has_acceleration_y);
800 args->GetNext(& acceleration_y);
801 args->GetNext(&has_acceleration_z);
802 args->GetNext(& acceleration_z);
803 args->GetNext(&has_acceleration_including_gravity_x);
804 args->GetNext(& acceleration_including_gravity_x);
805 args->GetNext(&has_acceleration_including_gravity_y);
806 args->GetNext(& acceleration_including_gravity_y);
807 args->GetNext(&has_acceleration_including_gravity_z);
808 args->GetNext(& acceleration_including_gravity_z);
809 args->GetNext(&has_rotation_rate_alpha);
810 args->GetNext(& rotation_rate_alpha);
811 args->GetNext(&has_rotation_rate_beta);
812 args->GetNext(& rotation_rate_beta);
813 args->GetNext(&has_rotation_rate_gamma);
814 args->GetNext(& rotation_rate_gamma);
815 args->GetNext(& interval);
817 runner_->SetMockDeviceMotion(has_acceleration_x, acceleration_x,
818 has_acceleration_y, acceleration_y,
819 has_acceleration_z, acceleration_z,
820 has_acceleration_including_gravity_x,
821 acceleration_including_gravity_x,
822 has_acceleration_including_gravity_y,
823 acceleration_including_gravity_y,
824 has_acceleration_including_gravity_z,
825 acceleration_including_gravity_z,
826 has_rotation_rate_alpha,
828 has_rotation_rate_beta,
830 has_rotation_rate_gamma,
835 void TestRunnerBindings::SetMockDeviceOrientation(gin::Arguments* args) {
848 args->GetNext(&has_alpha);
849 args->GetNext(&alpha);
850 args->GetNext(&has_beta);
851 args->GetNext(&beta);
852 args->GetNext(&has_gamma);
853 args->GetNext(&gamma);
854 args->GetNext(&has_absolute);
855 args->GetNext(&absolute);
857 runner_->SetMockDeviceOrientation(has_alpha, alpha,
860 has_absolute, absolute);
863 void TestRunnerBindings::SetMockScreenOrientation(const std::string& orientation) {
867 runner_->SetMockScreenOrientation(orientation);
870 void TestRunnerBindings::DidAcquirePointerLock() {
872 runner_->DidAcquirePointerLock();
875 void TestRunnerBindings::DidNotAcquirePointerLock() {
877 runner_->DidNotAcquirePointerLock();
880 void TestRunnerBindings::DidLosePointerLock() {
882 runner_->DidLosePointerLock();
885 void TestRunnerBindings::SetPointerLockWillFailSynchronously() {
887 runner_->SetPointerLockWillFailSynchronously();
890 void TestRunnerBindings::SetPointerLockWillRespondAsynchronously() {
892 runner_->SetPointerLockWillRespondAsynchronously();
895 void TestRunnerBindings::SetPopupBlockingEnabled(bool block_popups) {
897 runner_->SetPopupBlockingEnabled(block_popups);
900 void TestRunnerBindings::SetJavaScriptCanAccessClipboard(bool can_access) {
902 runner_->SetJavaScriptCanAccessClipboard(can_access);
905 void TestRunnerBindings::SetXSSAuditorEnabled(bool enabled) {
907 runner_->SetXSSAuditorEnabled(enabled);
910 void TestRunnerBindings::SetAllowUniversalAccessFromFileURLs(bool allow) {
912 runner_->SetAllowUniversalAccessFromFileURLs(allow);
915 void TestRunnerBindings::SetAllowFileAccessFromFileURLs(bool allow) {
917 runner_->SetAllowFileAccessFromFileURLs(allow);
920 void TestRunnerBindings::OverridePreference(const std::string key,
921 v8::Handle<v8::Value> value) {
923 runner_->OverridePreference(key, value);
926 void TestRunnerBindings::SetPluginsEnabled(bool enabled) {
928 runner_->SetPluginsEnabled(enabled);
931 void TestRunnerBindings::DumpEditingCallbacks() {
933 runner_->DumpEditingCallbacks();
936 void TestRunnerBindings::DumpAsText() {
938 runner_->DumpAsText();
941 void TestRunnerBindings::DumpAsTextWithPixelResults() {
943 runner_->DumpAsTextWithPixelResults();
946 void TestRunnerBindings::DumpChildFrameScrollPositions() {
948 runner_->DumpChildFrameScrollPositions();
951 void TestRunnerBindings::DumpChildFramesAsText() {
953 runner_->DumpChildFramesAsText();
956 void TestRunnerBindings::DumpIconChanges() {
958 runner_->DumpIconChanges();
961 void TestRunnerBindings::SetAudioData(const gin::ArrayBufferView& view) {
963 runner_->SetAudioData(view);
966 void TestRunnerBindings::DumpFrameLoadCallbacks() {
968 runner_->DumpFrameLoadCallbacks();
971 void TestRunnerBindings::DumpPingLoaderCallbacks() {
973 runner_->DumpPingLoaderCallbacks();
976 void TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks() {
978 runner_->DumpUserGestureInFrameLoadCallbacks();
981 void TestRunnerBindings::DumpTitleChanges() {
983 runner_->DumpTitleChanges();
986 void TestRunnerBindings::DumpCreateView() {
988 runner_->DumpCreateView();
991 void TestRunnerBindings::SetCanOpenWindows() {
993 runner_->SetCanOpenWindows();
996 void TestRunnerBindings::DumpResourceLoadCallbacks() {
998 runner_->DumpResourceLoadCallbacks();
1001 void TestRunnerBindings::DumpResourceRequestCallbacks() {
1003 runner_->DumpResourceRequestCallbacks();
1006 void TestRunnerBindings::DumpResourceResponseMIMETypes() {
1008 runner_->DumpResourceResponseMIMETypes();
1011 void TestRunnerBindings::SetImagesAllowed(bool allowed) {
1013 runner_->SetImagesAllowed(allowed);
1016 void TestRunnerBindings::SetScriptsAllowed(bool allowed) {
1018 runner_->SetScriptsAllowed(allowed);
1021 void TestRunnerBindings::SetStorageAllowed(bool allowed) {
1023 runner_->SetStorageAllowed(allowed);
1026 void TestRunnerBindings::SetPluginsAllowed(bool allowed) {
1028 runner_->SetPluginsAllowed(allowed);
1031 void TestRunnerBindings::SetAllowDisplayOfInsecureContent(bool allowed) {
1033 runner_->SetAllowDisplayOfInsecureContent(allowed);
1036 void TestRunnerBindings::SetAllowRunningOfInsecureContent(bool allowed) {
1038 runner_->SetAllowRunningOfInsecureContent(allowed);
1041 void TestRunnerBindings::DumpPermissionClientCallbacks() {
1043 runner_->DumpPermissionClientCallbacks();
1046 void TestRunnerBindings::DumpWindowStatusChanges() {
1048 runner_->DumpWindowStatusChanges();
1051 void TestRunnerBindings::DumpProgressFinishedCallback() {
1053 runner_->DumpProgressFinishedCallback();
1056 void TestRunnerBindings::DumpSpellCheckCallbacks() {
1058 runner_->DumpSpellCheckCallbacks();
1061 void TestRunnerBindings::DumpBackForwardList() {
1063 runner_->DumpBackForwardList();
1066 void TestRunnerBindings::DumpSelectionRect() {
1068 runner_->DumpSelectionRect();
1071 void TestRunnerBindings::TestRepaint() {
1073 runner_->TestRepaint();
1076 void TestRunnerBindings::RepaintSweepHorizontally() {
1078 runner_->RepaintSweepHorizontally();
1081 void TestRunnerBindings::SetPrinting() {
1083 runner_->SetPrinting();
1086 void TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload(
1089 runner_->SetShouldStayOnPageAfterHandlingBeforeUnload(value);
1092 void TestRunnerBindings::SetWillSendRequestClearHeader(
1093 const std::string& header) {
1095 runner_->SetWillSendRequestClearHeader(header);
1098 void TestRunnerBindings::DumpResourceRequestPriorities() {
1100 runner_->DumpResourceRequestPriorities();
1103 void TestRunnerBindings::SetUseMockTheme(bool use) {
1105 runner_->SetUseMockTheme(use);
1108 void TestRunnerBindings::WaitUntilExternalURLLoad() {
1110 runner_->WaitUntilExternalURLLoad();
1113 void TestRunnerBindings::ShowWebInspector(gin::Arguments* args) {
1116 args->GetNext(&str);
1117 runner_->ShowWebInspector(str);
1121 void TestRunnerBindings::CloseWebInspector() {
1123 runner_->CloseWebInspector();
1126 bool TestRunnerBindings::IsChooserShown() {
1128 return runner_->IsChooserShown();
1132 void TestRunnerBindings::EvaluateInWebInspector(int call_id,
1133 const std::string& script) {
1135 runner_->EvaluateInWebInspector(call_id, script);
1138 void TestRunnerBindings::ClearAllDatabases() {
1140 runner_->ClearAllDatabases();
1143 void TestRunnerBindings::SetDatabaseQuota(int quota) {
1145 runner_->SetDatabaseQuota(quota);
1148 void TestRunnerBindings::SetAlwaysAcceptCookies(bool accept) {
1150 runner_->SetAlwaysAcceptCookies(accept);
1153 void TestRunnerBindings::SetWindowIsKey(bool value) {
1155 runner_->SetWindowIsKey(value);
1158 std::string TestRunnerBindings::PathToLocalResource(const std::string& path) {
1160 return runner_->PathToLocalResource(path);
1161 return std::string();
1164 void TestRunnerBindings::SetBackingScaleFactor(
1165 double value, v8::Handle<v8::Function> callback) {
1167 runner_->SetBackingScaleFactor(value, callback);
1170 void TestRunnerBindings::SetPOSIXLocale(const std::string& locale) {
1172 runner_->SetPOSIXLocale(locale);
1175 void TestRunnerBindings::SetMIDIAccessorResult(bool result) {
1177 runner_->SetMIDIAccessorResult(result);
1180 void TestRunnerBindings::SetMIDISysexPermission(bool value) {
1182 runner_->SetMIDISysexPermission(value);
1185 void TestRunnerBindings::GrantWebNotificationPermission(gin::Arguments* args) {
1188 bool permission_granted = true;
1189 args->GetNext(&origin);
1190 args->GetNext(&permission_granted);
1191 return runner_->GrantWebNotificationPermission(origin, permission_granted);
1195 bool TestRunnerBindings::SimulateWebNotificationClick(
1196 const std::string& value) {
1198 return runner_->SimulateWebNotificationClick(value);
1202 void TestRunnerBindings::AddMockSpeechInputResult(const std::string& result,
1204 const std::string& language) {
1206 runner_->AddMockSpeechInputResult(result, confidence, language);
1209 void TestRunnerBindings::SetMockSpeechInputDumpRect(bool value) {
1211 runner_->SetMockSpeechInputDumpRect(value);
1214 void TestRunnerBindings::AddMockSpeechRecognitionResult(
1215 const std::string& transcript, double confidence) {
1217 runner_->AddMockSpeechRecognitionResult(transcript, confidence);
1220 void TestRunnerBindings::SetMockSpeechRecognitionError(
1221 const std::string& error, const std::string& message) {
1223 runner_->SetMockSpeechRecognitionError(error, message);
1226 bool TestRunnerBindings::WasMockSpeechRecognitionAborted() {
1228 return runner_->WasMockSpeechRecognitionAborted();
1232 void TestRunnerBindings::AddWebPageOverlay() {
1234 runner_->AddWebPageOverlay();
1237 void TestRunnerBindings::RemoveWebPageOverlay() {
1239 runner_->RemoveWebPageOverlay();
1242 void TestRunnerBindings::Display() {
1247 void TestRunnerBindings::DisplayInvalidatedRegion() {
1249 runner_->DisplayInvalidatedRegion();
1252 bool TestRunnerBindings::GlobalFlag() {
1254 return runner_->global_flag_;
1258 void TestRunnerBindings::SetGlobalFlag(bool value) {
1260 runner_->global_flag_ = value;
1263 std::string TestRunnerBindings::PlatformName() {
1265 return runner_->platform_name_;
1266 return std::string();
1269 std::string TestRunnerBindings::TooltipText() {
1271 return runner_->tooltip_text_;
1272 return std::string();
1275 bool TestRunnerBindings::DisableNotifyDone() {
1277 return runner_->disable_notify_done_;
1281 int TestRunnerBindings::WebHistoryItemCount() {
1283 return runner_->web_history_item_count_;
1287 bool TestRunnerBindings::InterceptPostMessage() {
1289 return runner_->intercept_post_message_;
1293 void TestRunnerBindings::SetInterceptPostMessage(bool value) {
1295 runner_->intercept_post_message_ = value;
1298 void TestRunnerBindings::NotImplemented(const gin::Arguments& args) {
1301 class TestPageOverlay : public WebPageOverlay {
1303 explicit TestPageOverlay(WebView* web_view)
1304 : web_view_(web_view) {
1306 virtual ~TestPageOverlay() {}
1308 virtual void paintPageOverlay(WebCanvas* canvas) OVERRIDE {
1309 SkRect rect = SkRect::MakeWH(web_view_->size().width,
1310 web_view_->size().height);
1312 paint.setColor(SK_ColorCYAN);
1313 paint.setStyle(SkPaint::kFill_Style);
1314 canvas->drawRect(rect, paint);
1321 TestRunner::WorkQueue::WorkQueue(TestRunner* controller)
1323 , controller_(controller) {}
1325 TestRunner::WorkQueue::~WorkQueue() {
1329 void TestRunner::WorkQueue::ProcessWorkSoon() {
1330 if (controller_->topLoadingFrame())
1333 if (!queue_.empty()) {
1334 // We delay processing queued work to avoid recursion problems.
1335 controller_->delegate_->postTask(new WorkQueueTask(this));
1336 } else if (!controller_->wait_until_done_) {
1337 controller_->delegate_->testFinished();
1341 void TestRunner::WorkQueue::Reset() {
1343 while (!queue_.empty()) {
1344 delete queue_.front();
1349 void TestRunner::WorkQueue::AddWork(WorkItem* work) {
1354 queue_.push_back(work);
1357 void TestRunner::WorkQueue::ProcessWork() {
1358 // Quit doing work once a load is in progress.
1359 while (!queue_.empty()) {
1360 bool startedLoad = queue_.front()->Run(controller_->delegate_,
1361 controller_->web_view_);
1362 delete queue_.front();
1368 if (!controller_->wait_until_done_ && !controller_->topLoadingFrame())
1369 controller_->delegate_->testFinished();
1372 void TestRunner::WorkQueue::WorkQueueTask::runIfValid() {
1373 m_object->ProcessWork();
1376 TestRunner::TestRunner(TestInterfaces* interfaces)
1377 : test_is_running_(false),
1378 close_remaining_windows_(false),
1380 disable_notify_done_(false),
1381 web_history_item_count_(0),
1382 intercept_post_message_(false),
1383 test_interfaces_(interfaces),
1386 page_overlay_(NULL),
1387 web_permissions_(new WebPermissions()),
1388 notification_presenter_(new content::NotificationPresenter()),
1389 weak_factory_(this) {}
1391 TestRunner::~TestRunner() {}
1393 void TestRunner::Install(WebFrame* frame) {
1394 TestRunnerBindings::Install(weak_factory_.GetWeakPtr(), frame);
1397 void TestRunner::SetDelegate(WebTestDelegate* delegate) {
1398 delegate_ = delegate;
1399 web_permissions_->setDelegate(delegate);
1400 notification_presenter_->set_delegate(delegate);
1403 void TestRunner::SetWebView(WebView* webView, WebTestProxyBase* proxy) {
1404 web_view_ = webView;
1408 void TestRunner::Reset() {
1410 web_view_->setZoomLevel(0);
1411 web_view_->setTextZoomFactor(1);
1412 web_view_->setTabKeyCyclesThroughElements(true);
1413 #if !defined(__APPLE__) && !defined(WIN32) // Actually, TOOLKIT_GTK
1414 // (Constants copied because we can't depend on the header that defined
1415 // them from this file.)
1416 web_view_->setSelectionColors(
1417 0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232);
1419 web_view_->removeInjectedStyleSheets();
1420 web_view_->setVisibilityState(WebPageVisibilityStateVisible, true);
1421 web_view_->mainFrame()->enableViewSourceMode(false);
1423 if (page_overlay_) {
1424 web_view_->removePageOverlay(page_overlay_);
1425 delete page_overlay_;
1426 page_overlay_ = NULL;
1430 top_loading_frame_ = NULL;
1431 wait_until_done_ = false;
1432 wait_until_external_url_load_ = false;
1433 policy_delegate_enabled_ = false;
1434 policy_delegate_is_permissive_ = false;
1435 policy_delegate_should_notify_done_ = false;
1437 WebSecurityPolicy::resetOriginAccessWhitelists();
1438 #if defined(__linux__) || defined(ANDROID)
1439 WebFontRendering::setSubpixelPositioning(false);
1443 // Reset the default quota for each origin to 5MB
1444 delegate_->setDatabaseQuota(5 * 1024 * 1024);
1445 delegate_->setDeviceScaleFactor(1);
1446 delegate_->setAcceptAllCookies(false);
1447 delegate_->setLocale("");
1448 delegate_->useUnfortunateSynchronousResizeMode(false);
1449 delegate_->disableAutoResizeMode(WebSize());
1450 delegate_->deleteAllCookies();
1453 dump_editting_callbacks_ = false;
1454 dump_as_text_ = false;
1455 dump_as_markup_ = false;
1456 generate_pixel_results_ = true;
1457 dump_child_frame_scroll_positions_ = false;
1458 dump_child_frames_as_text_ = false;
1459 dump_icon_changes_ = false;
1460 dump_as_audio_ = false;
1461 dump_frame_load_callbacks_ = false;
1462 dump_ping_loader_callbacks_ = false;
1463 dump_user_gesture_in_frame_load_callbacks_ = false;
1464 dump_title_changes_ = false;
1465 dump_create_view_ = false;
1466 can_open_windows_ = false;
1467 dump_resource_load_callbacks_ = false;
1468 dump_resource_request_callbacks_ = false;
1469 dump_resource_reqponse_mime_types_ = false;
1470 dump_window_status_changes_ = false;
1471 dump_progress_finished_callback_ = false;
1472 dump_spell_check_callbacks_ = false;
1473 dump_back_forward_list_ = false;
1474 dump_selection_rect_ = false;
1475 test_repaint_ = false;
1476 sweep_horizontally_ = false;
1477 is_printing_ = false;
1478 midi_accessor_result_ = true;
1479 should_stay_on_page_after_handling_before_unload_ = false;
1480 should_dump_resource_priorities_ = false;
1482 http_headers_to_clear_.clear();
1484 global_flag_ = false;
1485 platform_name_ = "chromium";
1486 tooltip_text_ = std::string();
1487 disable_notify_done_ = false;
1488 web_history_item_count_ = 0;
1489 intercept_post_message_ = false;
1491 web_permissions_->reset();
1493 notification_presenter_->Reset();
1494 use_mock_theme_ = true;
1495 pointer_locked_ = false;
1496 pointer_lock_planned_result_ = PointerLockWillSucceed;
1498 task_list_.revokeAll();
1499 work_queue_.Reset();
1501 if (close_remaining_windows_ && delegate_)
1502 delegate_->closeRemainingWindows();
1504 close_remaining_windows_ = true;
1507 void TestRunner::SetTestIsRunning(bool running) {
1508 test_is_running_ = running;
1511 bool TestRunner::shouldDumpEditingCallbacks() const {
1512 return dump_editting_callbacks_;
1515 bool TestRunner::shouldDumpAsText() {
1516 CheckResponseMimeType();
1517 return dump_as_text_;
1520 void TestRunner::setShouldDumpAsText(bool value) {
1521 dump_as_text_ = value;
1524 bool TestRunner::shouldDumpAsMarkup() {
1525 return dump_as_markup_;
1528 void TestRunner::setShouldDumpAsMarkup(bool value) {
1529 dump_as_markup_ = value;
1532 bool TestRunner::shouldGeneratePixelResults() {
1533 CheckResponseMimeType();
1534 return generate_pixel_results_;
1537 void TestRunner::setShouldGeneratePixelResults(bool value) {
1538 generate_pixel_results_ = value;
1541 bool TestRunner::shouldDumpChildFrameScrollPositions() const {
1542 return dump_child_frame_scroll_positions_;
1545 bool TestRunner::shouldDumpChildFramesAsText() const {
1546 return dump_child_frames_as_text_;
1549 bool TestRunner::shouldDumpAsAudio() const {
1550 return dump_as_audio_;
1553 void TestRunner::getAudioData(std::vector<unsigned char>* bufferView) const {
1554 *bufferView = audio_data_;
1557 bool TestRunner::shouldDumpFrameLoadCallbacks() const {
1558 return test_is_running_ && dump_frame_load_callbacks_;
1561 void TestRunner::setShouldDumpFrameLoadCallbacks(bool value) {
1562 dump_frame_load_callbacks_ = value;
1565 bool TestRunner::shouldDumpPingLoaderCallbacks() const {
1566 return test_is_running_ && dump_ping_loader_callbacks_;
1569 void TestRunner::setShouldDumpPingLoaderCallbacks(bool value) {
1570 dump_ping_loader_callbacks_ = value;
1573 void TestRunner::setShouldEnableViewSource(bool value) {
1574 web_view_->mainFrame()->enableViewSourceMode(value);
1577 bool TestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const {
1578 return test_is_running_ && dump_user_gesture_in_frame_load_callbacks_;
1581 bool TestRunner::shouldDumpTitleChanges() const {
1582 return dump_title_changes_;
1585 bool TestRunner::shouldDumpIconChanges() const {
1586 return dump_icon_changes_;
1589 bool TestRunner::shouldDumpCreateView() const {
1590 return dump_create_view_;
1593 bool TestRunner::canOpenWindows() const {
1594 return can_open_windows_;
1597 bool TestRunner::shouldDumpResourceLoadCallbacks() const {
1598 return test_is_running_ && dump_resource_load_callbacks_;
1601 bool TestRunner::shouldDumpResourceRequestCallbacks() const {
1602 return test_is_running_ && dump_resource_request_callbacks_;
1605 bool TestRunner::shouldDumpResourceResponseMIMETypes() const {
1606 return test_is_running_ && dump_resource_reqponse_mime_types_;
1609 WebPermissionClient* TestRunner::webPermissions() const {
1610 return web_permissions_.get();
1613 bool TestRunner::shouldDumpStatusCallbacks() const {
1614 return dump_window_status_changes_;
1617 bool TestRunner::shouldDumpProgressFinishedCallback() const {
1618 return dump_progress_finished_callback_;
1621 bool TestRunner::shouldDumpSpellCheckCallbacks() const {
1622 return dump_spell_check_callbacks_;
1625 bool TestRunner::shouldDumpBackForwardList() const {
1626 return dump_back_forward_list_;
1629 bool TestRunner::shouldDumpSelectionRect() const {
1630 return dump_selection_rect_;
1633 bool TestRunner::testRepaint() const {
1634 return test_repaint_;
1637 bool TestRunner::sweepHorizontally() const {
1638 return sweep_horizontally_;
1641 bool TestRunner::isPrinting() const {
1642 return is_printing_;
1645 bool TestRunner::shouldStayOnPageAfterHandlingBeforeUnload() const {
1646 return should_stay_on_page_after_handling_before_unload_;
1649 bool TestRunner::shouldWaitUntilExternalURLLoad() const {
1650 return wait_until_external_url_load_;
1653 const std::set<std::string>* TestRunner::httpHeadersToClear() const {
1654 return &http_headers_to_clear_;
1657 void TestRunner::setTopLoadingFrame(WebFrame* frame, bool clear) {
1658 if (frame->top()->view() != web_view_)
1660 if (!test_is_running_)
1663 top_loading_frame_ = NULL;
1664 LocationChangeDone();
1665 } else if (!top_loading_frame_) {
1666 top_loading_frame_ = frame;
1670 WebFrame* TestRunner::topLoadingFrame() const {
1671 return top_loading_frame_;
1674 void TestRunner::policyDelegateDone() {
1675 BLINK_ASSERT(wait_until_done_);
1676 delegate_->testFinished();
1677 wait_until_done_ = false;
1680 bool TestRunner::policyDelegateEnabled() const {
1681 return policy_delegate_enabled_;
1684 bool TestRunner::policyDelegateIsPermissive() const {
1685 return policy_delegate_is_permissive_;
1688 bool TestRunner::policyDelegateShouldNotifyDone() const {
1689 return policy_delegate_should_notify_done_;
1692 bool TestRunner::shouldInterceptPostMessage() const {
1693 return intercept_post_message_;
1696 bool TestRunner::shouldDumpResourcePriorities() const {
1697 return should_dump_resource_priorities_;
1700 WebNotificationPresenter* TestRunner::notification_presenter() const {
1701 return notification_presenter_.get();
1704 bool TestRunner::RequestPointerLock() {
1705 switch (pointer_lock_planned_result_) {
1706 case PointerLockWillSucceed:
1707 delegate_->postDelayedTask(
1708 new HostMethodTask(this, &TestRunner::DidAcquirePointerLockInternal),
1711 case PointerLockWillRespondAsync:
1712 BLINK_ASSERT(!pointer_locked_);
1714 case PointerLockWillFailSync:
1715 BLINK_ASSERT(!pointer_locked_);
1718 BLINK_ASSERT_NOT_REACHED();
1723 void TestRunner::RequestPointerUnlock() {
1724 delegate_->postDelayedTask(
1725 new HostMethodTask(this, &TestRunner::DidLosePointerLockInternal), 0);
1728 bool TestRunner::isPointerLocked() {
1729 return pointer_locked_;
1732 void TestRunner::setToolTipText(const WebString& text) {
1733 tooltip_text_ = text.utf8();
1736 bool TestRunner::midiAccessorResult() {
1737 return midi_accessor_result_;
1740 void TestRunner::clearDevToolsLocalStorage() {
1741 delegate_->clearDevToolsLocalStorage();
1744 void TestRunner::showDevTools(const std::string& settings) {
1745 delegate_->showDevTools(settings);
1748 class WorkItemBackForward : public TestRunner::WorkItem {
1750 WorkItemBackForward(int distance) : distance_(distance) {}
1752 virtual bool Run(WebTestDelegate* delegate, WebView*) OVERRIDE {
1753 delegate->goToOffset(distance_);
1754 return true; // FIXME: Did it really start a navigation?
1761 void TestRunner::NotifyDone() {
1762 if (disable_notify_done_)
1765 // Test didn't timeout. Kill the timeout timer.
1766 taskList()->revokeAll();
1768 CompleteNotifyDone();
1771 void TestRunner::WaitUntilDone() {
1772 wait_until_done_ = true;
1775 void TestRunner::QueueBackNavigation(int how_far_back) {
1776 work_queue_.AddWork(new WorkItemBackForward(-how_far_back));
1779 void TestRunner::QueueForwardNavigation(int how_far_forward) {
1780 work_queue_.AddWork(new WorkItemBackForward(how_far_forward));
1783 class WorkItemReload : public TestRunner::WorkItem {
1785 virtual bool Run(WebTestDelegate* delegate, WebView*) OVERRIDE {
1791 void TestRunner::QueueReload() {
1792 work_queue_.AddWork(new WorkItemReload());
1795 class WorkItemLoadingScript : public TestRunner::WorkItem {
1797 WorkItemLoadingScript(const std::string& script)
1798 : script_(script) {}
1800 virtual bool Run(WebTestDelegate*, WebView* web_view) OVERRIDE {
1801 web_view->mainFrame()->executeScript(
1802 WebScriptSource(WebString::fromUTF8(script_)));
1803 return true; // FIXME: Did it really start a navigation?
1807 std::string script_;
1810 void TestRunner::QueueLoadingScript(const std::string& script) {
1811 work_queue_.AddWork(new WorkItemLoadingScript(script));
1814 class WorkItemNonLoadingScript : public TestRunner::WorkItem {
1816 WorkItemNonLoadingScript(const std::string& script)
1817 : script_(script) {}
1819 virtual bool Run(WebTestDelegate*, WebView* web_view) OVERRIDE {
1820 web_view->mainFrame()->executeScript(
1821 WebScriptSource(WebString::fromUTF8(script_)));
1826 std::string script_;
1829 void TestRunner::QueueNonLoadingScript(const std::string& script) {
1830 work_queue_.AddWork(new WorkItemNonLoadingScript(script));
1833 class WorkItemLoad : public TestRunner::WorkItem {
1835 WorkItemLoad(const WebURL& url, const std::string& target)
1836 : url_(url), target_(target) {}
1838 virtual bool Run(WebTestDelegate* delegate, WebView*) OVERRIDE {
1839 delegate->loadURLForFrame(url_, target_);
1840 return true; // FIXME: Did it really start a navigation?
1845 std::string target_;
1848 void TestRunner::QueueLoad(const std::string& url, const std::string& target) {
1849 // FIXME: Implement WebURL::resolve() and avoid GURL.
1850 GURL current_url = web_view_->mainFrame()->document().url();
1851 GURL full_url = current_url.Resolve(url);
1852 work_queue_.AddWork(new WorkItemLoad(full_url, target));
1855 class WorkItemLoadHTMLString : public TestRunner::WorkItem {
1857 WorkItemLoadHTMLString(const std::string& html, const WebURL& base_url)
1858 : html_(html), base_url_(base_url) {}
1860 WorkItemLoadHTMLString(const std::string& html, const WebURL& base_url,
1861 const WebURL& unreachable_url)
1862 : html_(html), base_url_(base_url), unreachable_url_(unreachable_url) {}
1864 virtual bool Run(WebTestDelegate*, WebView* web_view) OVERRIDE {
1865 web_view->mainFrame()->loadHTMLString(
1866 WebData(html_.data(), html_.length()),
1867 base_url_, unreachable_url_);
1874 WebURL unreachable_url_;
1877 void TestRunner::QueueLoadHTMLString(gin::Arguments* args) {
1879 args->GetNext(&html);
1881 std::string base_url_str;
1882 args->GetNext(&base_url_str);
1883 WebURL base_url = WebURL(GURL(base_url_str));
1885 if (args->PeekNext()->IsString()) {
1886 std::string unreachable_url_str;
1887 args->GetNext(&unreachable_url_str);
1888 WebURL unreachable_url = WebURL(GURL(unreachable_url_str));
1889 work_queue_.AddWork(new WorkItemLoadHTMLString(html, base_url,
1892 work_queue_.AddWork(new WorkItemLoadHTMLString(html, base_url));
1896 void TestRunner::SetCustomPolicyDelegate(gin::Arguments* args) {
1897 args->GetNext(&policy_delegate_enabled_);
1898 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsBoolean())
1899 args->GetNext(&policy_delegate_is_permissive_);
1902 void TestRunner::WaitForPolicyDelegate() {
1903 policy_delegate_enabled_ = true;
1904 policy_delegate_should_notify_done_ = true;
1905 wait_until_done_ = true;
1908 int TestRunner::WindowCount() {
1909 return test_interfaces_->windowList().size();
1912 void TestRunner::SetCloseRemainingWindowsWhenComplete(
1913 bool close_remaining_windows) {
1914 close_remaining_windows_ = close_remaining_windows;
1917 void TestRunner::ResetTestHelperControllers() {
1918 test_interfaces_->resetTestHelperControllers();
1921 void TestRunner::SetTabKeyCyclesThroughElements(
1922 bool tab_key_cycles_through_elements) {
1923 web_view_->setTabKeyCyclesThroughElements(tab_key_cycles_through_elements);
1926 void TestRunner::ExecCommand(gin::Arguments* args) {
1927 std::string command;
1928 args->GetNext(&command);
1931 if (args->Length() >= 3) {
1932 // Ignore the second parameter (which is userInterface)
1933 // since this command emulates a manual action.
1935 args->GetNext(&value);
1938 // Note: webkit's version does not return the boolean, so neither do we.
1939 web_view_->focusedFrame()->executeCommand(WebString::fromUTF8(command),
1940 WebString::fromUTF8(value));
1943 bool TestRunner::IsCommandEnabled(const std::string& command) {
1944 return web_view_->focusedFrame()->isCommandEnabled(
1945 WebString::fromUTF8(command));
1948 bool TestRunner::CallShouldCloseOnWebView() {
1949 return web_view_->dispatchBeforeUnloadEvent();
1952 void TestRunner::SetDomainRelaxationForbiddenForURLScheme(
1953 bool forbidden, const std::string& scheme) {
1954 web_view_->setDomainRelaxationForbidden(forbidden,
1955 WebString::fromUTF8(scheme));
1958 v8::Handle<v8::Value> TestRunner::EvaluateScriptInIsolatedWorldAndReturnValue(
1960 const std::string& script) {
1961 WebVector<v8::Local<v8::Value> > values;
1962 WebScriptSource source(WebString::fromUTF8(script));
1963 // This relies on the iframe focusing itself when it loads. This is a bit
1964 // sketchy, but it seems to be what other tests do.
1965 web_view_->focusedFrame()->executeScriptInIsolatedWorld(
1966 world_id, &source, 1, 1, &values);
1967 // Since only one script was added, only one result is expected
1968 if (values.size() == 1 && !values[0].IsEmpty())
1970 return v8::Handle<v8::Value>();
1973 void TestRunner::EvaluateScriptInIsolatedWorld(int world_id,
1974 const std::string& script) {
1975 WebScriptSource source(WebString::fromUTF8(script));
1976 web_view_->focusedFrame()->executeScriptInIsolatedWorld(
1977 world_id, &source, 1, 1);
1980 void TestRunner::SetIsolatedWorldSecurityOrigin(int world_id,
1981 v8::Handle<v8::Value> origin) {
1982 if (!(origin->IsString() || !origin->IsNull()))
1985 WebSecurityOrigin web_origin;
1986 if (origin->IsString()) {
1987 web_origin = WebSecurityOrigin::createFromString(
1988 V8StringToWebString(origin->ToString()));
1990 web_view_->focusedFrame()->setIsolatedWorldSecurityOrigin(world_id,
1994 void TestRunner::SetIsolatedWorldContentSecurityPolicy(
1996 const std::string& policy) {
1997 web_view_->focusedFrame()->setIsolatedWorldContentSecurityPolicy(
1998 world_id, WebString::fromUTF8(policy));
2001 void TestRunner::AddOriginAccessWhitelistEntry(
2002 const std::string& source_origin,
2003 const std::string& destination_protocol,
2004 const std::string& destination_host,
2005 bool allow_destination_subdomains) {
2006 WebURL url((GURL(source_origin)));
2010 WebSecurityPolicy::addOriginAccessWhitelistEntry(
2012 WebString::fromUTF8(destination_protocol),
2013 WebString::fromUTF8(destination_host),
2014 allow_destination_subdomains);
2017 void TestRunner::RemoveOriginAccessWhitelistEntry(
2018 const std::string& source_origin,
2019 const std::string& destination_protocol,
2020 const std::string& destination_host,
2021 bool allow_destination_subdomains) {
2022 WebURL url((GURL(source_origin)));
2026 WebSecurityPolicy::removeOriginAccessWhitelistEntry(
2028 WebString::fromUTF8(destination_protocol),
2029 WebString::fromUTF8(destination_host),
2030 allow_destination_subdomains);
2033 bool TestRunner::HasCustomPageSizeStyle(int page_index) {
2034 WebFrame* frame = web_view_->mainFrame();
2037 return frame->hasCustomPageSizeStyle(page_index);
2040 void TestRunner::ForceRedSelectionColors() {
2041 web_view_->setSelectionColors(0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0);
2044 void TestRunner::InjectStyleSheet(const std::string& source_code,
2046 WebView::injectStyleSheet(
2047 WebString::fromUTF8(source_code),
2048 WebVector<WebString>(),
2049 all_frames ? WebView::InjectStyleInAllFrames
2050 : WebView::InjectStyleInTopFrameOnly);
2053 bool TestRunner::FindString(const std::string& search_text,
2054 const std::vector<std::string>& options_array) {
2055 WebFindOptions find_options;
2056 bool wrap_around = false;
2057 find_options.matchCase = true;
2058 find_options.findNext = true;
2060 for (size_t i = 0; i < options_array.size(); ++i) {
2061 const std::string& option = options_array[i];
2062 if (option == "CaseInsensitive")
2063 find_options.matchCase = false;
2064 else if (option == "Backwards")
2065 find_options.forward = false;
2066 else if (option == "StartInSelection")
2067 find_options.findNext = false;
2068 else if (option == "AtWordStarts")
2069 find_options.wordStart = true;
2070 else if (option == "TreatMedialCapitalAsWordStart")
2071 find_options.medialCapitalAsWordStart = true;
2072 else if (option == "WrapAround")
2076 WebFrame* frame = web_view_->mainFrame();
2077 const bool find_result = frame->find(0, WebString::fromUTF8(search_text),
2078 find_options, wrap_around, 0);
2079 frame->stopFinding(false);
2083 std::string TestRunner::SelectionAsMarkup() {
2084 return web_view_->mainFrame()->selectionAsMarkup().utf8();
2087 void TestRunner::SetTextSubpixelPositioning(bool value) {
2088 #if defined(__linux__) || defined(ANDROID)
2089 // Since FontConfig doesn't provide a variable to control subpixel
2090 // positioning, we'll fall back to setting it globally for all fonts.
2091 WebFontRendering::setSubpixelPositioning(value);
2095 void TestRunner::SetPageVisibility(const std::string& new_visibility) {
2096 if (new_visibility == "visible")
2097 web_view_->setVisibilityState(WebPageVisibilityStateVisible, false);
2098 else if (new_visibility == "hidden")
2099 web_view_->setVisibilityState(WebPageVisibilityStateHidden, false);
2100 else if (new_visibility == "prerender")
2101 web_view_->setVisibilityState(WebPageVisibilityStatePrerender, false);
2104 void TestRunner::SetTextDirection(const std::string& direction_name) {
2105 // Map a direction name to a WebTextDirection value.
2106 WebTextDirection direction;
2107 if (direction_name == "auto")
2108 direction = WebTextDirectionDefault;
2109 else if (direction_name == "rtl")
2110 direction = WebTextDirectionRightToLeft;
2111 else if (direction_name == "ltr")
2112 direction = WebTextDirectionLeftToRight;
2116 web_view_->setTextDirection(direction);
2119 void TestRunner::UseUnfortunateSynchronousResizeMode() {
2120 delegate_->useUnfortunateSynchronousResizeMode(true);
2123 bool TestRunner::EnableAutoResizeMode(int min_width,
2127 WebSize min_size(min_width, min_height);
2128 WebSize max_size(max_width, max_height);
2129 delegate_->enableAutoResizeMode(min_size, max_size);
2133 bool TestRunner::DisableAutoResizeMode(int new_width, int new_height) {
2134 WebSize new_size(new_width, new_height);
2135 delegate_->disableAutoResizeMode(new_size);
2139 void TestRunner::SetMockDeviceMotion(
2140 bool has_acceleration_x, double acceleration_x,
2141 bool has_acceleration_y, double acceleration_y,
2142 bool has_acceleration_z, double acceleration_z,
2143 bool has_acceleration_including_gravity_x,
2144 double acceleration_including_gravity_x,
2145 bool has_acceleration_including_gravity_y,
2146 double acceleration_including_gravity_y,
2147 bool has_acceleration_including_gravity_z,
2148 double acceleration_including_gravity_z,
2149 bool has_rotation_rate_alpha, double rotation_rate_alpha,
2150 bool has_rotation_rate_beta, double rotation_rate_beta,
2151 bool has_rotation_rate_gamma, double rotation_rate_gamma,
2153 WebDeviceMotionData motion;
2156 motion.hasAccelerationX = has_acceleration_x;
2157 motion.accelerationX = acceleration_x;
2158 motion.hasAccelerationY = has_acceleration_y;
2159 motion.accelerationY = acceleration_y;
2160 motion.hasAccelerationZ = has_acceleration_z;
2161 motion.accelerationZ = acceleration_z;
2163 // accelerationIncludingGravity
2164 motion.hasAccelerationIncludingGravityX =
2165 has_acceleration_including_gravity_x;
2166 motion.accelerationIncludingGravityX = acceleration_including_gravity_x;
2167 motion.hasAccelerationIncludingGravityY =
2168 has_acceleration_including_gravity_y;
2169 motion.accelerationIncludingGravityY = acceleration_including_gravity_y;
2170 motion.hasAccelerationIncludingGravityZ =
2171 has_acceleration_including_gravity_z;
2172 motion.accelerationIncludingGravityZ = acceleration_including_gravity_z;
2175 motion.hasRotationRateAlpha = has_rotation_rate_alpha;
2176 motion.rotationRateAlpha = rotation_rate_alpha;
2177 motion.hasRotationRateBeta = has_rotation_rate_beta;
2178 motion.rotationRateBeta = rotation_rate_beta;
2179 motion.hasRotationRateGamma = has_rotation_rate_gamma;
2180 motion.rotationRateGamma = rotation_rate_gamma;
2183 motion.interval = interval;
2185 delegate_->setDeviceMotionData(motion);
2188 void TestRunner::SetMockDeviceOrientation(bool has_alpha, double alpha,
2189 bool has_beta, double beta,
2190 bool has_gamma, double gamma,
2191 bool has_absolute, bool absolute) {
2192 WebDeviceOrientationData orientation;
2195 orientation.hasAlpha = has_alpha;
2196 orientation.alpha = alpha;
2199 orientation.hasBeta = has_beta;
2200 orientation.beta = beta;
2203 orientation.hasGamma = has_gamma;
2204 orientation.gamma = gamma;
2207 orientation.hasAbsolute = has_absolute;
2208 orientation.absolute = absolute;
2210 delegate_->setDeviceOrientationData(orientation);
2213 void TestRunner::SetMockScreenOrientation(const std::string& orientation_str) {
2214 blink::WebScreenOrientation orientation;
2216 if (orientation_str == "portrait-primary") {
2217 orientation = WebScreenOrientationPortraitPrimary;
2218 } else if (orientation_str == "portrait-secondary") {
2219 orientation = WebScreenOrientationPortraitSecondary;
2220 } else if (orientation_str == "landscape-primary") {
2221 orientation = WebScreenOrientationLandscapePrimary;
2222 } else if (orientation_str == "landscape-secondary") {
2223 orientation = WebScreenOrientationLandscapeSecondary;
2226 delegate_->setScreenOrientation(orientation);
2229 void TestRunner::DidAcquirePointerLock() {
2230 DidAcquirePointerLockInternal();
2233 void TestRunner::DidNotAcquirePointerLock() {
2234 DidNotAcquirePointerLockInternal();
2237 void TestRunner::DidLosePointerLock() {
2238 DidLosePointerLockInternal();
2241 void TestRunner::SetPointerLockWillFailSynchronously() {
2242 pointer_lock_planned_result_ = PointerLockWillFailSync;
2245 void TestRunner::SetPointerLockWillRespondAsynchronously() {
2246 pointer_lock_planned_result_ = PointerLockWillRespondAsync;
2249 void TestRunner::SetPopupBlockingEnabled(bool block_popups) {
2250 delegate_->preferences()->javaScriptCanOpenWindowsAutomatically =
2252 delegate_->applyPreferences();
2255 void TestRunner::SetJavaScriptCanAccessClipboard(bool can_access) {
2256 delegate_->preferences()->javaScriptCanAccessClipboard = can_access;
2257 delegate_->applyPreferences();
2260 void TestRunner::SetXSSAuditorEnabled(bool enabled) {
2261 delegate_->preferences()->XSSAuditorEnabled = enabled;
2262 delegate_->applyPreferences();
2265 void TestRunner::SetAllowUniversalAccessFromFileURLs(bool allow) {
2266 delegate_->preferences()->allowUniversalAccessFromFileURLs = allow;
2267 delegate_->applyPreferences();
2270 void TestRunner::SetAllowFileAccessFromFileURLs(bool allow) {
2271 delegate_->preferences()->allowFileAccessFromFileURLs = allow;
2272 delegate_->applyPreferences();
2275 void TestRunner::OverridePreference(const std::string key,
2276 v8::Handle<v8::Value> value) {
2277 WebPreferences* prefs = delegate_->preferences();
2278 if (key == "WebKitDefaultFontSize") {
2279 prefs->defaultFontSize = value->Int32Value();
2280 } else if (key == "WebKitMinimumFontSize") {
2281 prefs->minimumFontSize = value->Int32Value();
2282 } else if (key == "WebKitDefaultTextEncodingName") {
2283 prefs->defaultTextEncodingName = V8StringToWebString(value->ToString());
2284 } else if (key == "WebKitJavaScriptEnabled") {
2285 prefs->javaScriptEnabled = value->BooleanValue();
2286 } else if (key == "WebKitSupportsMultipleWindows") {
2287 prefs->supportsMultipleWindows = value->BooleanValue();
2288 } else if (key == "WebKitDisplayImagesKey") {
2289 prefs->loadsImagesAutomatically = value->BooleanValue();
2290 } else if (key == "WebKitPluginsEnabled") {
2291 prefs->pluginsEnabled = value->BooleanValue();
2292 } else if (key == "WebKitJavaEnabled") {
2293 prefs->javaEnabled = value->BooleanValue();
2294 } else if (key == "WebKitOfflineWebApplicationCacheEnabled") {
2295 prefs->offlineWebApplicationCacheEnabled = value->BooleanValue();
2296 } else if (key == "WebKitTabToLinksPreferenceKey") {
2297 prefs->tabsToLinks = value->BooleanValue();
2298 } else if (key == "WebKitWebGLEnabled") {
2299 prefs->experimentalWebGLEnabled = value->BooleanValue();
2300 } else if (key == "WebKitCSSRegionsEnabled") {
2301 prefs->experimentalCSSRegionsEnabled = value->BooleanValue();
2302 } else if (key == "WebKitCSSGridLayoutEnabled") {
2303 prefs->experimentalCSSGridLayoutEnabled = value->BooleanValue();
2304 } else if (key == "WebKitHyperlinkAuditingEnabled") {
2305 prefs->hyperlinkAuditingEnabled = value->BooleanValue();
2306 } else if (key == "WebKitEnableCaretBrowsing") {
2307 prefs->caretBrowsingEnabled = value->BooleanValue();
2308 } else if (key == "WebKitAllowDisplayingInsecureContent") {
2309 prefs->allowDisplayOfInsecureContent = value->BooleanValue();
2310 } else if (key == "WebKitAllowRunningInsecureContent") {
2311 prefs->allowRunningOfInsecureContent = value->BooleanValue();
2312 } else if (key == "WebKitShouldRespectImageOrientation") {
2313 prefs->shouldRespectImageOrientation = value->BooleanValue();
2314 } else if (key == "WebKitWebAudioEnabled") {
2315 BLINK_ASSERT(value->BooleanValue());
2317 std::string message("Invalid name for preference: ");
2318 message.append(key);
2319 delegate_->printMessage(std::string("CONSOLE MESSAGE: ") + message + "\n");
2321 delegate_->applyPreferences();
2324 void TestRunner::SetPluginsEnabled(bool enabled) {
2325 delegate_->preferences()->pluginsEnabled = enabled;
2326 delegate_->applyPreferences();
2329 void TestRunner::DumpEditingCallbacks() {
2330 dump_editting_callbacks_ = true;
2333 void TestRunner::DumpAsText() {
2334 dump_as_text_ = true;
2335 generate_pixel_results_ = false;
2338 void TestRunner::DumpAsTextWithPixelResults() {
2339 dump_as_text_ = true;
2340 generate_pixel_results_ = true;
2343 void TestRunner::DumpChildFrameScrollPositions() {
2344 dump_child_frame_scroll_positions_ = true;
2347 void TestRunner::DumpChildFramesAsText() {
2348 dump_child_frames_as_text_ = true;
2351 void TestRunner::DumpIconChanges() {
2352 dump_icon_changes_ = true;
2355 void TestRunner::SetAudioData(const gin::ArrayBufferView& view) {
2356 unsigned char* bytes = static_cast<unsigned char*>(view.bytes());
2357 audio_data_.resize(view.num_bytes());
2358 std::copy(bytes, bytes + view.num_bytes(), audio_data_.begin());
2359 dump_as_audio_ = true;
2362 void TestRunner::DumpFrameLoadCallbacks() {
2363 dump_frame_load_callbacks_ = true;
2366 void TestRunner::DumpPingLoaderCallbacks() {
2367 dump_ping_loader_callbacks_ = true;
2370 void TestRunner::DumpUserGestureInFrameLoadCallbacks() {
2371 dump_user_gesture_in_frame_load_callbacks_ = true;
2374 void TestRunner::DumpTitleChanges() {
2375 dump_title_changes_ = true;
2378 void TestRunner::DumpCreateView() {
2379 dump_create_view_ = true;
2382 void TestRunner::SetCanOpenWindows() {
2383 can_open_windows_ = true;
2386 void TestRunner::DumpResourceLoadCallbacks() {
2387 dump_resource_load_callbacks_ = true;
2390 void TestRunner::DumpResourceRequestCallbacks() {
2391 dump_resource_request_callbacks_ = true;
2394 void TestRunner::DumpResourceResponseMIMETypes() {
2395 dump_resource_reqponse_mime_types_ = true;
2398 void TestRunner::SetImagesAllowed(bool allowed) {
2399 web_permissions_->setImagesAllowed(allowed);
2402 void TestRunner::SetScriptsAllowed(bool allowed) {
2403 web_permissions_->setScriptsAllowed(allowed);
2406 void TestRunner::SetStorageAllowed(bool allowed) {
2407 web_permissions_->setStorageAllowed(allowed);
2410 void TestRunner::SetPluginsAllowed(bool allowed) {
2411 web_permissions_->setPluginsAllowed(allowed);
2414 void TestRunner::SetAllowDisplayOfInsecureContent(bool allowed) {
2415 web_permissions_->setDisplayingInsecureContentAllowed(allowed);
2418 void TestRunner::SetAllowRunningOfInsecureContent(bool allowed) {
2419 web_permissions_->setRunningInsecureContentAllowed(allowed);
2422 void TestRunner::DumpPermissionClientCallbacks() {
2423 web_permissions_->setDumpCallbacks(true);
2426 void TestRunner::DumpWindowStatusChanges() {
2427 dump_window_status_changes_ = true;
2430 void TestRunner::DumpProgressFinishedCallback() {
2431 dump_progress_finished_callback_ = true;
2434 void TestRunner::DumpSpellCheckCallbacks() {
2435 dump_spell_check_callbacks_ = true;
2438 void TestRunner::DumpBackForwardList() {
2439 dump_back_forward_list_ = true;
2442 void TestRunner::DumpSelectionRect() {
2443 dump_selection_rect_ = true;
2446 void TestRunner::TestRepaint() {
2447 test_repaint_ = true;
2450 void TestRunner::RepaintSweepHorizontally() {
2451 sweep_horizontally_ = true;
2454 void TestRunner::SetPrinting() {
2455 is_printing_ = true;
2458 void TestRunner::SetShouldStayOnPageAfterHandlingBeforeUnload(bool value) {
2459 should_stay_on_page_after_handling_before_unload_ = value;
2462 void TestRunner::SetWillSendRequestClearHeader(const std::string& header) {
2463 if (!header.empty())
2464 http_headers_to_clear_.insert(header);
2467 void TestRunner::DumpResourceRequestPriorities() {
2468 should_dump_resource_priorities_ = true;
2471 void TestRunner::SetUseMockTheme(bool use) {
2472 use_mock_theme_ = use;
2475 void TestRunner::ShowWebInspector(const std::string& str) {
2479 void TestRunner::WaitUntilExternalURLLoad() {
2480 wait_until_external_url_load_ = true;
2483 void TestRunner::CloseWebInspector() {
2484 delegate_->closeDevTools();
2487 bool TestRunner::IsChooserShown() {
2488 return proxy_->isChooserShown();
2491 void TestRunner::EvaluateInWebInspector(int call_id,
2492 const std::string& script) {
2493 delegate_->evaluateInWebInspector(call_id, script);
2496 void TestRunner::ClearAllDatabases() {
2497 delegate_->clearAllDatabases();
2500 void TestRunner::SetDatabaseQuota(int quota) {
2501 delegate_->setDatabaseQuota(quota);
2504 void TestRunner::SetAlwaysAcceptCookies(bool accept) {
2505 delegate_->setAcceptAllCookies(accept);
2508 void TestRunner::SetWindowIsKey(bool value) {
2509 delegate_->setFocus(proxy_, value);
2512 std::string TestRunner::PathToLocalResource(const std::string& path) {
2513 return delegate_->pathToLocalResource(path);
2516 void TestRunner::SetBackingScaleFactor(double value,
2517 v8::Handle<v8::Function> callback) {
2518 delegate_->setDeviceScaleFactor(value);
2519 proxy_->discardBackingStore();
2520 delegate_->postTask(new InvokeCallbackTask(this, callback));
2523 void TestRunner::SetPOSIXLocale(const std::string& locale) {
2524 delegate_->setLocale(locale);
2527 void TestRunner::SetMIDIAccessorResult(bool result) {
2528 midi_accessor_result_ = result;
2531 void TestRunner::SetMIDISysexPermission(bool value) {
2532 const std::vector<WebTestProxyBase*>& windowList =
2533 test_interfaces_->windowList();
2534 for (unsigned i = 0; i < windowList.size(); ++i)
2535 windowList.at(i)->midiClientMock()->setSysexPermission(value);
2538 void TestRunner::GrantWebNotificationPermission(const std::string& origin,
2539 bool permission_granted) {
2540 notification_presenter_->GrantPermission(origin, permission_granted);
2543 bool TestRunner::SimulateWebNotificationClick(const std::string& value) {
2544 return notification_presenter_->SimulateClick(value);
2547 void TestRunner::AddMockSpeechInputResult(const std::string& result,
2549 const std::string& language) {
2550 #if ENABLE_INPUT_SPEECH
2551 proxy_->speechInputControllerMock()->addMockRecognitionResult(
2552 WebString::fromUTF8(result), confidence, WebString::fromUTF8(language));
2556 void TestRunner::SetMockSpeechInputDumpRect(bool value) {
2557 #if ENABLE_INPUT_SPEECH
2558 proxy_->speechInputControllerMock()->setDumpRect(value);
2562 void TestRunner::AddMockSpeechRecognitionResult(const std::string& transcript,
2563 double confidence) {
2564 proxy_->speechRecognizerMock()->addMockResult(
2565 WebString::fromUTF8(transcript), confidence);
2568 void TestRunner::SetMockSpeechRecognitionError(const std::string& error,
2569 const std::string& message) {
2570 proxy_->speechRecognizerMock()->setError(WebString::fromUTF8(error),
2571 WebString::fromUTF8(message));
2574 bool TestRunner::WasMockSpeechRecognitionAborted() {
2575 return proxy_->speechRecognizerMock()->wasAborted();
2578 void TestRunner::AddWebPageOverlay() {
2579 if (web_view_ && !page_overlay_) {
2580 page_overlay_ = new TestPageOverlay(web_view_);
2581 web_view_->addPageOverlay(page_overlay_, 0);
2585 void TestRunner::RemoveWebPageOverlay() {
2586 if (web_view_ && page_overlay_) {
2587 web_view_->removePageOverlay(page_overlay_);
2588 delete page_overlay_;
2589 page_overlay_ = NULL;
2593 void TestRunner::Display() {
2597 void TestRunner::DisplayInvalidatedRegion() {
2598 proxy_->displayInvalidatedRegion();
2601 void TestRunner::LocationChangeDone() {
2602 web_history_item_count_ = delegate_->navigationEntryCount();
2604 // No more new work after the first complete load.
2605 work_queue_.set_frozen(true);
2607 if (!wait_until_done_)
2608 work_queue_.ProcessWorkSoon();
2611 void TestRunner::CheckResponseMimeType() {
2612 // Text output: the test page can request different types of output which we
2614 if (!dump_as_text_) {
2615 std::string mimeType =
2616 web_view_->mainFrame()->dataSource()->response().mimeType().utf8();
2617 if (mimeType == "text/plain") {
2618 dump_as_text_ = true;
2619 generate_pixel_results_ = false;
2624 void TestRunner::CompleteNotifyDone() {
2625 if (wait_until_done_ && !topLoadingFrame() && work_queue_.is_empty())
2626 delegate_->testFinished();
2627 wait_until_done_ = false;
2630 void TestRunner::DidAcquirePointerLockInternal() {
2631 pointer_locked_ = true;
2632 web_view_->didAcquirePointerLock();
2634 // Reset planned result to default.
2635 pointer_lock_planned_result_ = PointerLockWillSucceed;
2638 void TestRunner::DidNotAcquirePointerLockInternal() {
2639 BLINK_ASSERT(!pointer_locked_);
2640 pointer_locked_ = false;
2641 web_view_->didNotAcquirePointerLock();
2643 // Reset planned result to default.
2644 pointer_lock_planned_result_ = PointerLockWillSucceed;
2647 void TestRunner::DidLosePointerLockInternal() {
2648 bool was_locked = pointer_locked_;
2649 pointer_locked_ = false;
2651 web_view_->didLosePointerLock();
2654 } // namespace content