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 "base/logging.h"
10 #include "content/shell/common/test_runner/test_preferences.h"
11 #include "content/shell/renderer/test_runner/MockWebSpeechInputController.h"
12 #include "content/shell/renderer/test_runner/MockWebSpeechRecognizer.h"
13 #include "content/shell/renderer/test_runner/TestInterfaces.h"
14 #include "content/shell/renderer/test_runner/WebPermissions.h"
15 #include "content/shell/renderer/test_runner/WebTestDelegate.h"
16 #include "content/shell/renderer/test_runner/WebTestProxy.h"
17 #include "content/shell/renderer/test_runner/notification_presenter.h"
18 #include "gin/arguments.h"
19 #include "gin/array_buffer.h"
20 #include "gin/handle.h"
21 #include "gin/object_template_builder.h"
22 #include "gin/wrappable.h"
23 #include "third_party/WebKit/public/platform/WebCanvas.h"
24 #include "third_party/WebKit/public/platform/WebData.h"
25 #include "third_party/WebKit/public/platform/WebDeviceMotionData.h"
26 #include "third_party/WebKit/public/platform/WebDeviceOrientationData.h"
27 #include "third_party/WebKit/public/platform/WebPoint.h"
28 #include "third_party/WebKit/public/platform/WebURLResponse.h"
29 #include "third_party/WebKit/public/web/WebBindings.h"
30 #include "third_party/WebKit/public/web/WebDataSource.h"
31 #include "third_party/WebKit/public/web/WebDocument.h"
32 #include "third_party/WebKit/public/web/WebFindOptions.h"
33 #include "third_party/WebKit/public/web/WebFrame.h"
34 #include "third_party/WebKit/public/web/WebInputElement.h"
35 #include "third_party/WebKit/public/web/WebKit.h"
36 #include "third_party/WebKit/public/web/WebMIDIClientMock.h"
37 #include "third_party/WebKit/public/web/WebPageOverlay.h"
38 #include "third_party/WebKit/public/web/WebScriptSource.h"
39 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
40 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
41 #include "third_party/WebKit/public/web/WebSettings.h"
42 #include "third_party/WebKit/public/web/WebSurroundingText.h"
43 #include "third_party/WebKit/public/web/WebView.h"
44 #include "third_party/skia/include/core/SkCanvas.h"
46 #if defined(__linux__) || defined(ANDROID)
47 #include "third_party/WebKit/public/web/linux/WebFontRendering.h"
50 using namespace blink
;
51 using namespace WebTestRunner
;
55 WebString
V8StringToWebString(v8::Handle
<v8::String
> v8_str
) {
56 int length
= v8_str
->Utf8Length() + 1;
57 scoped_ptr
<char[]> chars(new char[length
]);
58 v8_str
->WriteUtf8(chars
.get(), length
);
59 return WebString::fromUTF8(chars
.get());
62 class HostMethodTask
:
63 public ::WebTestRunner::WebMethodTask
<content::TestRunner
> {
65 typedef void (content::TestRunner::*CallbackMethodType
)();
66 HostMethodTask(content::TestRunner
* object
, CallbackMethodType callback
)
67 : WebMethodTask
<content::TestRunner
>(object
), callback_(callback
) {}
69 virtual void runIfValid() OVERRIDE
{
70 (m_object
->*callback_
)();
74 CallbackMethodType callback_
;
81 class InvokeCallbackTask
: public WebMethodTask
<content::TestRunner
> {
83 InvokeCallbackTask(content::TestRunner
* object
,
84 v8::Handle
<v8::Function
> callback
)
85 : WebMethodTask
<content::TestRunner
>(object
),
86 callback_(blink::mainThreadIsolate(), callback
) {}
88 virtual void runIfValid() OVERRIDE
{
89 v8::Isolate
* isolate
= blink::mainThreadIsolate();
90 v8::HandleScope
handle_scope(isolate
);
91 WebFrame
* frame
= m_object
->web_view_
->mainFrame();
93 v8::Handle
<v8::Context
> context
= frame
->mainWorldScriptContext();
94 if (context
.IsEmpty())
97 v8::Context::Scope
context_scope(context
);
99 frame
->callFunctionEvenIfScriptDisabled(
100 v8::Local
<v8::Function
>::New(isolate
, callback_
),
107 v8::UniquePersistent
<v8::Function
> callback_
;
110 class TestRunnerBindings
: public gin::Wrappable
<TestRunnerBindings
> {
112 static gin::WrapperInfo kWrapperInfo
;
114 static void Install(base::WeakPtr
<TestRunner
> controller
,
118 explicit TestRunnerBindings(
119 base::WeakPtr
<TestRunner
> controller
);
120 virtual ~TestRunnerBindings();
123 virtual gin::ObjectTemplateBuilder
GetObjectTemplateBuilder(
124 v8::Isolate
* isolate
) OVERRIDE
;
127 void WaitUntilDone();
128 void QueueBackNavigation(int how_far_back
);
129 void QueueForwardNavigation(int how_far_forward
);
131 void QueueLoadingScript(const std::string
& script
);
132 void QueueNonLoadingScript(const std::string
& script
);
133 void QueueLoad(gin::Arguments
* args
);
134 void QueueLoadHTMLString(gin::Arguments
* args
);
135 void SetCustomPolicyDelegate(gin::Arguments
* args
);
136 void WaitForPolicyDelegate();
138 void SetCloseRemainingWindowsWhenComplete(gin::Arguments
* args
);
139 void ResetTestHelperControllers();
140 void SetTabKeyCyclesThroughElements(bool tab_key_cycles_through_elements
);
141 void ExecCommand(gin::Arguments
* args
);
142 bool IsCommandEnabled(const std::string
& command
);
143 bool CallShouldCloseOnWebView();
144 void SetDomainRelaxationForbiddenForURLScheme(bool forbidden
,
145 const std::string
& scheme
);
146 v8::Handle
<v8::Value
> EvaluateScriptInIsolatedWorldAndReturnValue(
147 int world_id
, const std::string
& script
);
148 void EvaluateScriptInIsolatedWorld(int world_id
, const std::string
& script
);
149 void SetIsolatedWorldSecurityOrigin(int world_id
,
150 v8::Handle
<v8::Value
> origin
);
151 void SetIsolatedWorldContentSecurityPolicy(int world_id
,
152 const std::string
& policy
);
153 void AddOriginAccessWhitelistEntry(const std::string
& source_origin
,
154 const std::string
& destination_protocol
,
155 const std::string
& destination_host
,
156 bool allow_destination_subdomains
);
157 void RemoveOriginAccessWhitelistEntry(const std::string
& source_origin
,
158 const std::string
& destination_protocol
,
159 const std::string
& destination_host
,
160 bool allow_destination_subdomains
);
161 bool HasCustomPageSizeStyle(int page_index
);
162 void ForceRedSelectionColors();
163 void InjectStyleSheet(const std::string
& source_code
, bool all_frames
);
164 bool FindString(const std::string
& search_text
,
165 const std::vector
<std::string
>& options_array
);
166 std::string
SelectionAsMarkup();
167 void SetTextSubpixelPositioning(bool value
);
168 void SetPageVisibility(const std::string
& new_visibility
);
169 void SetTextDirection(const std::string
& direction_name
);
170 void UseUnfortunateSynchronousResizeMode();
171 bool EnableAutoResizeMode(int min_width
,
175 bool DisableAutoResizeMode(int new_width
, int new_height
);
176 void SetMockDeviceMotion(gin::Arguments
* args
);
177 void SetMockDeviceOrientation(gin::Arguments
* args
);
178 void SetMockScreenOrientation(const std::string
& orientation
);
179 void DidAcquirePointerLock();
180 void DidNotAcquirePointerLock();
181 void DidLosePointerLock();
182 void SetPointerLockWillFailSynchronously();
183 void SetPointerLockWillRespondAsynchronously();
184 void SetPopupBlockingEnabled(bool block_popups
);
185 void SetJavaScriptCanAccessClipboard(bool can_access
);
186 void SetXSSAuditorEnabled(bool enabled
);
187 void SetAllowUniversalAccessFromFileURLs(bool allow
);
188 void SetAllowFileAccessFromFileURLs(bool allow
);
189 void OverridePreference(const std::string key
, v8::Handle
<v8::Value
> value
);
190 void SetPluginsEnabled(bool enabled
);
191 void DumpEditingCallbacks();
193 void DumpAsTextWithPixelResults();
194 void DumpChildFrameScrollPositions();
195 void DumpChildFramesAsText();
196 void DumpIconChanges();
197 void SetAudioData(const gin::ArrayBufferView
& view
);
198 void DumpFrameLoadCallbacks();
199 void DumpPingLoaderCallbacks();
200 void DumpUserGestureInFrameLoadCallbacks();
201 void DumpTitleChanges();
202 void DumpCreateView();
203 void SetCanOpenWindows();
204 void DumpResourceLoadCallbacks();
205 void DumpResourceRequestCallbacks();
206 void DumpResourceResponseMIMETypes();
207 void SetImagesAllowed(bool allowed
);
208 void SetScriptsAllowed(bool allowed
);
209 void SetStorageAllowed(bool allowed
);
210 void SetPluginsAllowed(bool allowed
);
211 void SetAllowDisplayOfInsecureContent(bool allowed
);
212 void SetAllowRunningOfInsecureContent(bool allowed
);
213 void DumpPermissionClientCallbacks();
214 void DumpWindowStatusChanges();
215 void DumpProgressFinishedCallback();
216 void DumpSpellCheckCallbacks();
217 void DumpBackForwardList();
218 void DumpSelectionRect();
220 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value
);
221 void SetWillSendRequestClearHeader(const std::string
& header
);
222 void DumpResourceRequestPriorities();
223 void SetUseMockTheme(bool use
);
224 void WaitUntilExternalURLLoad();
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 DisplayAsyncThen(v8::Handle
<v8::Function
> callback
);
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 if (bindings
.IsEmpty())
288 v8::Handle
<v8::Object
> global
= context
->Global();
289 v8::Handle
<v8::Value
> v8_bindings
= bindings
.ToV8();
290 global
->Set(gin::StringToV8(isolate
, "testRunner"), v8_bindings
);
291 global
->Set(gin::StringToV8(isolate
, "layoutTestController"), v8_bindings
);
294 TestRunnerBindings::TestRunnerBindings(base::WeakPtr
<TestRunner
> runner
)
297 TestRunnerBindings::~TestRunnerBindings() {}
299 gin::ObjectTemplateBuilder
TestRunnerBindings::GetObjectTemplateBuilder(
300 v8::Isolate
* isolate
) {
301 return gin::Wrappable
<TestRunnerBindings
>::GetObjectTemplateBuilder(
303 // Methods controlling test execution.
304 .SetMethod("notifyDone", &TestRunnerBindings::NotifyDone
)
305 .SetMethod("waitUntilDone", &TestRunnerBindings::WaitUntilDone
)
306 .SetMethod("queueBackNavigation",
307 &TestRunnerBindings::QueueBackNavigation
)
308 .SetMethod("queueForwardNavigation",
309 &TestRunnerBindings::QueueForwardNavigation
)
310 .SetMethod("queueReload", &TestRunnerBindings::QueueReload
)
311 .SetMethod("queueLoadingScript", &TestRunnerBindings::QueueLoadingScript
)
312 .SetMethod("queueNonLoadingScript",
313 &TestRunnerBindings::QueueNonLoadingScript
)
314 .SetMethod("queueLoad", &TestRunnerBindings::QueueLoad
)
315 .SetMethod("queueLoadHTMLString",
316 &TestRunnerBindings::QueueLoadHTMLString
)
317 .SetMethod("setCustomPolicyDelegate",
318 &TestRunnerBindings::SetCustomPolicyDelegate
)
319 .SetMethod("waitForPolicyDelegate",
320 &TestRunnerBindings::WaitForPolicyDelegate
)
321 .SetMethod("windowCount", &TestRunnerBindings::WindowCount
)
322 .SetMethod("setCloseRemainingWindowsWhenComplete",
323 &TestRunnerBindings::SetCloseRemainingWindowsWhenComplete
)
324 .SetMethod("resetTestHelperControllers",
325 &TestRunnerBindings::ResetTestHelperControllers
)
326 .SetMethod("setTabKeyCyclesThroughElements",
327 &TestRunnerBindings::SetTabKeyCyclesThroughElements
)
328 .SetMethod("execCommand", &TestRunnerBindings::ExecCommand
)
329 .SetMethod("isCommandEnabled", &TestRunnerBindings::IsCommandEnabled
)
330 .SetMethod("callShouldCloseOnWebView",
331 &TestRunnerBindings::CallShouldCloseOnWebView
)
332 .SetMethod("setDomainRelaxationForbiddenForURLScheme",
333 &TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme
)
334 .SetMethod("evaluateScriptInIsolatedWorldAndReturnValue",
335 &TestRunnerBindings::
336 EvaluateScriptInIsolatedWorldAndReturnValue
)
337 .SetMethod("evaluateScriptInIsolatedWorld",
338 &TestRunnerBindings::EvaluateScriptInIsolatedWorld
)
339 .SetMethod("setIsolatedWorldSecurityOrigin",
340 &TestRunnerBindings::SetIsolatedWorldSecurityOrigin
)
341 .SetMethod("setIsolatedWorldContentSecurityPolicy",
342 &TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy
)
343 .SetMethod("addOriginAccessWhitelistEntry",
344 &TestRunnerBindings::AddOriginAccessWhitelistEntry
)
345 .SetMethod("removeOriginAccessWhitelistEntry",
346 &TestRunnerBindings::RemoveOriginAccessWhitelistEntry
)
347 .SetMethod("hasCustomPageSizeStyle",
348 &TestRunnerBindings::HasCustomPageSizeStyle
)
349 .SetMethod("forceRedSelectionColors",
350 &TestRunnerBindings::ForceRedSelectionColors
)
351 .SetMethod("injectStyleSheet", &TestRunnerBindings::InjectStyleSheet
)
352 .SetMethod("findString", &TestRunnerBindings::FindString
)
353 .SetMethod("selectionAsMarkup", &TestRunnerBindings::SelectionAsMarkup
)
354 .SetMethod("setTextSubpixelPositioning",
355 &TestRunnerBindings::SetTextSubpixelPositioning
)
356 .SetMethod("setPageVisibility", &TestRunnerBindings::SetPageVisibility
)
357 .SetMethod("setTextDirection", &TestRunnerBindings::SetTextDirection
)
358 .SetMethod("useUnfortunateSynchronousResizeMode",
359 &TestRunnerBindings::UseUnfortunateSynchronousResizeMode
)
360 .SetMethod("enableAutoResizeMode",
361 &TestRunnerBindings::EnableAutoResizeMode
)
362 .SetMethod("disableAutoResizeMode",
363 &TestRunnerBindings::DisableAutoResizeMode
)
364 .SetMethod("setMockDeviceMotion",
365 &TestRunnerBindings::SetMockDeviceMotion
)
366 .SetMethod("setMockDeviceOrientation",
367 &TestRunnerBindings::SetMockDeviceOrientation
)
368 .SetMethod("setMockScreenOrientation",
369 &TestRunnerBindings::SetMockScreenOrientation
)
370 .SetMethod("didAcquirePointerLock",
371 &TestRunnerBindings::DidAcquirePointerLock
)
372 .SetMethod("didNotAcquirePointerLock",
373 &TestRunnerBindings::DidNotAcquirePointerLock
)
374 .SetMethod("didLosePointerLock", &TestRunnerBindings::DidLosePointerLock
)
375 .SetMethod("setPointerLockWillFailSynchronously",
376 &TestRunnerBindings::SetPointerLockWillFailSynchronously
)
377 .SetMethod("setPointerLockWillRespondAsynchronously",
378 &TestRunnerBindings::SetPointerLockWillRespondAsynchronously
)
379 .SetMethod("setPopupBlockingEnabled",
380 &TestRunnerBindings::SetPopupBlockingEnabled
)
381 .SetMethod("setJavaScriptCanAccessClipboard",
382 &TestRunnerBindings::SetJavaScriptCanAccessClipboard
)
383 .SetMethod("setXSSAuditorEnabled",
384 &TestRunnerBindings::SetXSSAuditorEnabled
)
385 .SetMethod("setAllowUniversalAccessFromFileURLs",
386 &TestRunnerBindings::SetAllowUniversalAccessFromFileURLs
)
387 .SetMethod("setAllowFileAccessFromFileURLs",
388 &TestRunnerBindings::SetAllowFileAccessFromFileURLs
)
389 .SetMethod("overridePreference", &TestRunnerBindings::OverridePreference
)
390 .SetMethod("setPluginsEnabled", &TestRunnerBindings::SetPluginsEnabled
)
391 .SetMethod("dumpEditingCallbacks",
392 &TestRunnerBindings::DumpEditingCallbacks
)
393 .SetMethod("dumpAsText", &TestRunnerBindings::DumpAsText
)
394 .SetMethod("dumpAsTextWithPixelResults",
395 &TestRunnerBindings::DumpAsTextWithPixelResults
)
396 .SetMethod("dumpChildFrameScrollPositions",
397 &TestRunnerBindings::DumpChildFrameScrollPositions
)
398 .SetMethod("dumpChildFramesAsText",
399 &TestRunnerBindings::DumpChildFramesAsText
)
400 .SetMethod("dumpIconChanges", &TestRunnerBindings::DumpIconChanges
)
401 .SetMethod("setAudioData", &TestRunnerBindings::SetAudioData
)
402 .SetMethod("dumpFrameLoadCallbacks",
403 &TestRunnerBindings::DumpFrameLoadCallbacks
)
404 .SetMethod("dumpPingLoaderCallbacks",
405 &TestRunnerBindings::DumpPingLoaderCallbacks
)
406 .SetMethod("dumpUserGestureInFrameLoadCallbacks",
407 &TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks
)
408 .SetMethod("dumpTitleChanges", &TestRunnerBindings::DumpTitleChanges
)
409 .SetMethod("dumpCreateView", &TestRunnerBindings::DumpCreateView
)
410 .SetMethod("setCanOpenWindows", &TestRunnerBindings::SetCanOpenWindows
)
411 .SetMethod("dumpResourceLoadCallbacks",
412 &TestRunnerBindings::DumpResourceLoadCallbacks
)
413 .SetMethod("dumpResourceRequestCallbacks",
414 &TestRunnerBindings::DumpResourceRequestCallbacks
)
415 .SetMethod("dumpResourceResponseMIMETypes",
416 &TestRunnerBindings::DumpResourceResponseMIMETypes
)
417 .SetMethod("setImagesAllowed", &TestRunnerBindings::SetImagesAllowed
)
418 .SetMethod("setScriptsAllowed", &TestRunnerBindings::SetScriptsAllowed
)
419 .SetMethod("setStorageAllowed", &TestRunnerBindings::SetStorageAllowed
)
420 .SetMethod("setPluginsAllowed", &TestRunnerBindings::SetPluginsAllowed
)
421 .SetMethod("setAllowDisplayOfInsecureContent",
422 &TestRunnerBindings::SetAllowDisplayOfInsecureContent
)
423 .SetMethod("setAllowRunningOfInsecureContent",
424 &TestRunnerBindings::SetAllowRunningOfInsecureContent
)
425 .SetMethod("dumpPermissionClientCallbacks",
426 &TestRunnerBindings::DumpPermissionClientCallbacks
)
427 .SetMethod("dumpWindowStatusChanges",
428 &TestRunnerBindings::DumpWindowStatusChanges
)
429 .SetMethod("dumpProgressFinishedCallback",
430 &TestRunnerBindings::DumpProgressFinishedCallback
)
431 .SetMethod("dumpSpellCheckCallbacks",
432 &TestRunnerBindings::DumpSpellCheckCallbacks
)
433 .SetMethod("dumpBackForwardList",
434 &TestRunnerBindings::DumpBackForwardList
)
435 .SetMethod("dumpSelectionRect", &TestRunnerBindings::DumpSelectionRect
)
436 .SetMethod("setPrinting", &TestRunnerBindings::SetPrinting
)
437 .SetMethod("setShouldStayOnPageAfterHandlingBeforeUnload",
438 &TestRunnerBindings::
439 SetShouldStayOnPageAfterHandlingBeforeUnload
)
440 .SetMethod("setWillSendRequestClearHeader",
441 &TestRunnerBindings::SetWillSendRequestClearHeader
)
442 .SetMethod("dumpResourceRequestPriorities",
443 &TestRunnerBindings::DumpResourceRequestPriorities
)
444 .SetMethod("setUseMockTheme", &TestRunnerBindings::SetUseMockTheme
)
445 .SetMethod("waitUntilExternalURLLoad",
446 &TestRunnerBindings::WaitUntilExternalURLLoad
)
447 .SetMethod("showWebInspector", &TestRunnerBindings::ShowWebInspector
)
448 .SetMethod("closeWebInspector", &TestRunnerBindings::CloseWebInspector
)
449 .SetMethod("isChooserShown", &TestRunnerBindings::IsChooserShown
)
450 .SetMethod("evaluateInWebInspector",
451 &TestRunnerBindings::EvaluateInWebInspector
)
452 .SetMethod("clearAllDatabases", &TestRunnerBindings::ClearAllDatabases
)
453 .SetMethod("setDatabaseQuota", &TestRunnerBindings::SetDatabaseQuota
)
454 .SetMethod("setAlwaysAcceptCookies",
455 &TestRunnerBindings::SetAlwaysAcceptCookies
)
456 .SetMethod("setWindowIsKey", &TestRunnerBindings::SetWindowIsKey
)
457 .SetMethod("pathToLocalResource",
458 &TestRunnerBindings::PathToLocalResource
)
459 .SetMethod("setBackingScaleFactor",
460 &TestRunnerBindings::SetBackingScaleFactor
)
461 .SetMethod("setPOSIXLocale", &TestRunnerBindings::SetPOSIXLocale
)
462 .SetMethod("setMIDIAccessorResult",
463 &TestRunnerBindings::SetMIDIAccessorResult
)
464 .SetMethod("setMIDISysexPermission",
465 &TestRunnerBindings::SetMIDISysexPermission
)
466 .SetMethod("grantWebNotificationPermission",
467 &TestRunnerBindings::GrantWebNotificationPermission
)
468 .SetMethod("simulateWebNotificationClick",
469 &TestRunnerBindings::SimulateWebNotificationClick
)
470 .SetMethod("addMockSpeechInputResult",
471 &TestRunnerBindings::AddMockSpeechInputResult
)
472 .SetMethod("setMockSpeechInputDumpRect",
473 &TestRunnerBindings::SetMockSpeechInputDumpRect
)
474 .SetMethod("addMockSpeechRecognitionResult",
475 &TestRunnerBindings::AddMockSpeechRecognitionResult
)
476 .SetMethod("setMockSpeechRecognitionError",
477 &TestRunnerBindings::SetMockSpeechRecognitionError
)
478 .SetMethod("wasMockSpeechRecognitionAborted",
479 &TestRunnerBindings::WasMockSpeechRecognitionAborted
)
480 .SetMethod("addWebPageOverlay", &TestRunnerBindings::AddWebPageOverlay
)
481 .SetMethod("removeWebPageOverlay",
482 &TestRunnerBindings::RemoveWebPageOverlay
)
483 .SetMethod("displayAsync", &TestRunnerBindings::DisplayAsync
)
484 .SetMethod("displayAsyncThen", &TestRunnerBindings::DisplayAsyncThen
)
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::SetPrinting() {
1070 runner_
->SetPrinting();
1073 void TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload(
1076 runner_
->SetShouldStayOnPageAfterHandlingBeforeUnload(value
);
1079 void TestRunnerBindings::SetWillSendRequestClearHeader(
1080 const std::string
& header
) {
1082 runner_
->SetWillSendRequestClearHeader(header
);
1085 void TestRunnerBindings::DumpResourceRequestPriorities() {
1087 runner_
->DumpResourceRequestPriorities();
1090 void TestRunnerBindings::SetUseMockTheme(bool use
) {
1092 runner_
->SetUseMockTheme(use
);
1095 void TestRunnerBindings::WaitUntilExternalURLLoad() {
1097 runner_
->WaitUntilExternalURLLoad();
1100 void TestRunnerBindings::ShowWebInspector(gin::Arguments
* args
) {
1102 std::string settings
;
1103 args
->GetNext(&settings
);
1104 std::string frontend_url
;
1105 args
->GetNext(&frontend_url
);
1106 runner_
->ShowWebInspector(settings
, frontend_url
);
1110 void TestRunnerBindings::CloseWebInspector() {
1112 runner_
->CloseWebInspector();
1115 bool TestRunnerBindings::IsChooserShown() {
1117 return runner_
->IsChooserShown();
1121 void TestRunnerBindings::EvaluateInWebInspector(int call_id
,
1122 const std::string
& script
) {
1124 runner_
->EvaluateInWebInspector(call_id
, script
);
1127 void TestRunnerBindings::ClearAllDatabases() {
1129 runner_
->ClearAllDatabases();
1132 void TestRunnerBindings::SetDatabaseQuota(int quota
) {
1134 runner_
->SetDatabaseQuota(quota
);
1137 void TestRunnerBindings::SetAlwaysAcceptCookies(bool accept
) {
1139 runner_
->SetAlwaysAcceptCookies(accept
);
1142 void TestRunnerBindings::SetWindowIsKey(bool value
) {
1144 runner_
->SetWindowIsKey(value
);
1147 std::string
TestRunnerBindings::PathToLocalResource(const std::string
& path
) {
1149 return runner_
->PathToLocalResource(path
);
1150 return std::string();
1153 void TestRunnerBindings::SetBackingScaleFactor(
1154 double value
, v8::Handle
<v8::Function
> callback
) {
1156 runner_
->SetBackingScaleFactor(value
, callback
);
1159 void TestRunnerBindings::SetPOSIXLocale(const std::string
& locale
) {
1161 runner_
->SetPOSIXLocale(locale
);
1164 void TestRunnerBindings::SetMIDIAccessorResult(bool result
) {
1166 runner_
->SetMIDIAccessorResult(result
);
1169 void TestRunnerBindings::SetMIDISysexPermission(bool value
) {
1171 runner_
->SetMIDISysexPermission(value
);
1174 void TestRunnerBindings::GrantWebNotificationPermission(gin::Arguments
* args
) {
1177 bool permission_granted
= true;
1178 args
->GetNext(&origin
);
1179 args
->GetNext(&permission_granted
);
1180 return runner_
->GrantWebNotificationPermission(origin
, permission_granted
);
1184 bool TestRunnerBindings::SimulateWebNotificationClick(
1185 const std::string
& value
) {
1187 return runner_
->SimulateWebNotificationClick(value
);
1191 void TestRunnerBindings::AddMockSpeechInputResult(const std::string
& result
,
1193 const std::string
& language
) {
1195 runner_
->AddMockSpeechInputResult(result
, confidence
, language
);
1198 void TestRunnerBindings::SetMockSpeechInputDumpRect(bool value
) {
1200 runner_
->SetMockSpeechInputDumpRect(value
);
1203 void TestRunnerBindings::AddMockSpeechRecognitionResult(
1204 const std::string
& transcript
, double confidence
) {
1206 runner_
->AddMockSpeechRecognitionResult(transcript
, confidence
);
1209 void TestRunnerBindings::SetMockSpeechRecognitionError(
1210 const std::string
& error
, const std::string
& message
) {
1212 runner_
->SetMockSpeechRecognitionError(error
, message
);
1215 bool TestRunnerBindings::WasMockSpeechRecognitionAborted() {
1217 return runner_
->WasMockSpeechRecognitionAborted();
1221 void TestRunnerBindings::AddWebPageOverlay() {
1223 runner_
->AddWebPageOverlay();
1226 void TestRunnerBindings::RemoveWebPageOverlay() {
1228 runner_
->RemoveWebPageOverlay();
1231 void TestRunnerBindings::DisplayAsync() {
1233 runner_
->DisplayAsync();
1236 void TestRunnerBindings::DisplayAsyncThen(v8::Handle
<v8::Function
> callback
) {
1238 runner_
->DisplayAsyncThen(callback
);
1241 bool TestRunnerBindings::GlobalFlag() {
1243 return runner_
->global_flag_
;
1247 void TestRunnerBindings::SetGlobalFlag(bool value
) {
1249 runner_
->global_flag_
= value
;
1252 std::string
TestRunnerBindings::PlatformName() {
1254 return runner_
->platform_name_
;
1255 return std::string();
1258 std::string
TestRunnerBindings::TooltipText() {
1260 return runner_
->tooltip_text_
;
1261 return std::string();
1264 bool TestRunnerBindings::DisableNotifyDone() {
1266 return runner_
->disable_notify_done_
;
1270 int TestRunnerBindings::WebHistoryItemCount() {
1272 return runner_
->web_history_item_count_
;
1276 bool TestRunnerBindings::InterceptPostMessage() {
1278 return runner_
->intercept_post_message_
;
1282 void TestRunnerBindings::SetInterceptPostMessage(bool value
) {
1284 runner_
->intercept_post_message_
= value
;
1287 void TestRunnerBindings::NotImplemented(const gin::Arguments
& args
) {
1290 class TestPageOverlay
: public WebPageOverlay
{
1292 explicit TestPageOverlay(WebView
* web_view
)
1293 : web_view_(web_view
) {
1295 virtual ~TestPageOverlay() {}
1297 virtual void paintPageOverlay(WebCanvas
* canvas
) OVERRIDE
{
1298 SkRect rect
= SkRect::MakeWH(web_view_
->size().width
,
1299 web_view_
->size().height
);
1301 paint
.setColor(SK_ColorCYAN
);
1302 paint
.setStyle(SkPaint::kFill_Style
);
1303 canvas
->drawRect(rect
, paint
);
1310 TestRunner::WorkQueue::WorkQueue(TestRunner
* controller
)
1312 , controller_(controller
) {}
1314 TestRunner::WorkQueue::~WorkQueue() {
1318 void TestRunner::WorkQueue::ProcessWorkSoon() {
1319 if (controller_
->topLoadingFrame())
1322 if (!queue_
.empty()) {
1323 // We delay processing queued work to avoid recursion problems.
1324 controller_
->delegate_
->postTask(new WorkQueueTask(this));
1325 } else if (!controller_
->wait_until_done_
) {
1326 controller_
->delegate_
->testFinished();
1330 void TestRunner::WorkQueue::Reset() {
1332 while (!queue_
.empty()) {
1333 delete queue_
.front();
1338 void TestRunner::WorkQueue::AddWork(WorkItem
* work
) {
1343 queue_
.push_back(work
);
1346 void TestRunner::WorkQueue::ProcessWork() {
1347 // Quit doing work once a load is in progress.
1348 while (!queue_
.empty()) {
1349 bool startedLoad
= queue_
.front()->Run(controller_
->delegate_
,
1350 controller_
->web_view_
);
1351 delete queue_
.front();
1357 if (!controller_
->wait_until_done_
&& !controller_
->topLoadingFrame())
1358 controller_
->delegate_
->testFinished();
1361 void TestRunner::WorkQueue::WorkQueueTask::runIfValid() {
1362 m_object
->ProcessWork();
1365 TestRunner::TestRunner(TestInterfaces
* interfaces
)
1366 : test_is_running_(false),
1367 close_remaining_windows_(false),
1369 disable_notify_done_(false),
1370 web_history_item_count_(0),
1371 intercept_post_message_(false),
1372 test_interfaces_(interfaces
),
1375 page_overlay_(NULL
),
1376 web_permissions_(new WebPermissions()),
1377 notification_presenter_(new content::NotificationPresenter()),
1378 weak_factory_(this) {}
1380 TestRunner::~TestRunner() {}
1382 void TestRunner::Install(WebFrame
* frame
) {
1383 TestRunnerBindings::Install(weak_factory_
.GetWeakPtr(), frame
);
1386 void TestRunner::SetDelegate(WebTestDelegate
* delegate
) {
1387 delegate_
= delegate
;
1388 web_permissions_
->setDelegate(delegate
);
1389 notification_presenter_
->set_delegate(delegate
);
1392 void TestRunner::SetWebView(WebView
* webView
, WebTestProxyBase
* proxy
) {
1393 web_view_
= webView
;
1397 void TestRunner::Reset() {
1399 web_view_
->setZoomLevel(0);
1400 web_view_
->setTextZoomFactor(1);
1401 web_view_
->setTabKeyCyclesThroughElements(true);
1402 #if !defined(__APPLE__) && !defined(WIN32) // Actually, TOOLKIT_GTK
1403 // (Constants copied because we can't depend on the header that defined
1404 // them from this file.)
1405 web_view_
->setSelectionColors(
1406 0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232);
1408 web_view_
->removeInjectedStyleSheets();
1409 web_view_
->setVisibilityState(WebPageVisibilityStateVisible
, true);
1410 web_view_
->mainFrame()->enableViewSourceMode(false);
1412 if (page_overlay_
) {
1413 web_view_
->removePageOverlay(page_overlay_
);
1414 delete page_overlay_
;
1415 page_overlay_
= NULL
;
1419 top_loading_frame_
= NULL
;
1420 wait_until_done_
= false;
1421 wait_until_external_url_load_
= false;
1422 policy_delegate_enabled_
= false;
1423 policy_delegate_is_permissive_
= false;
1424 policy_delegate_should_notify_done_
= false;
1426 WebSecurityPolicy::resetOriginAccessWhitelists();
1427 #if defined(__linux__) || defined(ANDROID)
1428 WebFontRendering::setSubpixelPositioning(false);
1432 // Reset the default quota for each origin to 5MB
1433 delegate_
->setDatabaseQuota(5 * 1024 * 1024);
1434 delegate_
->setDeviceScaleFactor(1);
1435 delegate_
->setAcceptAllCookies(false);
1436 delegate_
->setLocale("");
1437 delegate_
->useUnfortunateSynchronousResizeMode(false);
1438 delegate_
->disableAutoResizeMode(WebSize());
1439 delegate_
->deleteAllCookies();
1442 dump_editting_callbacks_
= false;
1443 dump_as_text_
= false;
1444 dump_as_markup_
= false;
1445 generate_pixel_results_
= true;
1446 dump_child_frame_scroll_positions_
= false;
1447 dump_child_frames_as_text_
= false;
1448 dump_icon_changes_
= false;
1449 dump_as_audio_
= false;
1450 dump_frame_load_callbacks_
= false;
1451 dump_ping_loader_callbacks_
= false;
1452 dump_user_gesture_in_frame_load_callbacks_
= false;
1453 dump_title_changes_
= false;
1454 dump_create_view_
= false;
1455 can_open_windows_
= false;
1456 dump_resource_load_callbacks_
= false;
1457 dump_resource_request_callbacks_
= false;
1458 dump_resource_reqponse_mime_types_
= false;
1459 dump_window_status_changes_
= false;
1460 dump_progress_finished_callback_
= false;
1461 dump_spell_check_callbacks_
= false;
1462 dump_back_forward_list_
= false;
1463 dump_selection_rect_
= false;
1464 test_repaint_
= false;
1465 sweep_horizontally_
= false;
1466 is_printing_
= false;
1467 midi_accessor_result_
= true;
1468 should_stay_on_page_after_handling_before_unload_
= false;
1469 should_dump_resource_priorities_
= false;
1471 http_headers_to_clear_
.clear();
1473 global_flag_
= false;
1474 platform_name_
= "chromium";
1475 tooltip_text_
= std::string();
1476 disable_notify_done_
= false;
1477 web_history_item_count_
= 0;
1478 intercept_post_message_
= false;
1480 web_permissions_
->reset();
1482 notification_presenter_
->Reset();
1483 use_mock_theme_
= true;
1484 pointer_locked_
= false;
1485 pointer_lock_planned_result_
= PointerLockWillSucceed
;
1487 task_list_
.revokeAll();
1488 work_queue_
.Reset();
1490 if (close_remaining_windows_
&& delegate_
)
1491 delegate_
->closeRemainingWindows();
1493 close_remaining_windows_
= true;
1496 void TestRunner::SetTestIsRunning(bool running
) {
1497 test_is_running_
= running
;
1500 void TestRunner::InvokeCallback(scoped_ptr
<InvokeCallbackTask
> task
) {
1501 delegate_
->postTask(task
.release());
1504 bool TestRunner::shouldDumpEditingCallbacks() const {
1505 return dump_editting_callbacks_
;
1508 bool TestRunner::shouldDumpAsText() {
1509 CheckResponseMimeType();
1510 return dump_as_text_
;
1513 void TestRunner::setShouldDumpAsText(bool value
) {
1514 dump_as_text_
= value
;
1517 bool TestRunner::shouldDumpAsMarkup() {
1518 return dump_as_markup_
;
1521 void TestRunner::setShouldDumpAsMarkup(bool value
) {
1522 dump_as_markup_
= value
;
1525 bool TestRunner::shouldGeneratePixelResults() {
1526 CheckResponseMimeType();
1527 return generate_pixel_results_
;
1530 void TestRunner::setShouldGeneratePixelResults(bool value
) {
1531 generate_pixel_results_
= value
;
1534 bool TestRunner::shouldDumpChildFrameScrollPositions() const {
1535 return dump_child_frame_scroll_positions_
;
1538 bool TestRunner::shouldDumpChildFramesAsText() const {
1539 return dump_child_frames_as_text_
;
1542 bool TestRunner::shouldDumpAsAudio() const {
1543 return dump_as_audio_
;
1546 void TestRunner::getAudioData(std::vector
<unsigned char>* bufferView
) const {
1547 *bufferView
= audio_data_
;
1550 bool TestRunner::shouldDumpFrameLoadCallbacks() const {
1551 return test_is_running_
&& dump_frame_load_callbacks_
;
1554 void TestRunner::setShouldDumpFrameLoadCallbacks(bool value
) {
1555 dump_frame_load_callbacks_
= value
;
1558 bool TestRunner::shouldDumpPingLoaderCallbacks() const {
1559 return test_is_running_
&& dump_ping_loader_callbacks_
;
1562 void TestRunner::setShouldDumpPingLoaderCallbacks(bool value
) {
1563 dump_ping_loader_callbacks_
= value
;
1566 void TestRunner::setShouldEnableViewSource(bool value
) {
1567 web_view_
->mainFrame()->enableViewSourceMode(value
);
1570 bool TestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const {
1571 return test_is_running_
&& dump_user_gesture_in_frame_load_callbacks_
;
1574 bool TestRunner::shouldDumpTitleChanges() const {
1575 return dump_title_changes_
;
1578 bool TestRunner::shouldDumpIconChanges() const {
1579 return dump_icon_changes_
;
1582 bool TestRunner::shouldDumpCreateView() const {
1583 return dump_create_view_
;
1586 bool TestRunner::canOpenWindows() const {
1587 return can_open_windows_
;
1590 bool TestRunner::shouldDumpResourceLoadCallbacks() const {
1591 return test_is_running_
&& dump_resource_load_callbacks_
;
1594 bool TestRunner::shouldDumpResourceRequestCallbacks() const {
1595 return test_is_running_
&& dump_resource_request_callbacks_
;
1598 bool TestRunner::shouldDumpResourceResponseMIMETypes() const {
1599 return test_is_running_
&& dump_resource_reqponse_mime_types_
;
1602 WebPermissionClient
* TestRunner::webPermissions() const {
1603 return web_permissions_
.get();
1606 bool TestRunner::shouldDumpStatusCallbacks() const {
1607 return dump_window_status_changes_
;
1610 bool TestRunner::shouldDumpProgressFinishedCallback() const {
1611 return dump_progress_finished_callback_
;
1614 bool TestRunner::shouldDumpSpellCheckCallbacks() const {
1615 return dump_spell_check_callbacks_
;
1618 bool TestRunner::shouldDumpBackForwardList() const {
1619 return dump_back_forward_list_
;
1622 bool TestRunner::shouldDumpSelectionRect() const {
1623 return dump_selection_rect_
;
1626 bool TestRunner::isPrinting() const {
1627 return is_printing_
;
1630 bool TestRunner::shouldStayOnPageAfterHandlingBeforeUnload() const {
1631 return should_stay_on_page_after_handling_before_unload_
;
1634 bool TestRunner::shouldWaitUntilExternalURLLoad() const {
1635 return wait_until_external_url_load_
;
1638 const std::set
<std::string
>* TestRunner::httpHeadersToClear() const {
1639 return &http_headers_to_clear_
;
1642 void TestRunner::setTopLoadingFrame(WebFrame
* frame
, bool clear
) {
1643 if (frame
->top()->view() != web_view_
)
1645 if (!test_is_running_
)
1648 top_loading_frame_
= NULL
;
1649 LocationChangeDone();
1650 } else if (!top_loading_frame_
) {
1651 top_loading_frame_
= frame
;
1655 WebFrame
* TestRunner::topLoadingFrame() const {
1656 return top_loading_frame_
;
1659 void TestRunner::policyDelegateDone() {
1660 DCHECK(wait_until_done_
);
1661 delegate_
->testFinished();
1662 wait_until_done_
= false;
1665 bool TestRunner::policyDelegateEnabled() const {
1666 return policy_delegate_enabled_
;
1669 bool TestRunner::policyDelegateIsPermissive() const {
1670 return policy_delegate_is_permissive_
;
1673 bool TestRunner::policyDelegateShouldNotifyDone() const {
1674 return policy_delegate_should_notify_done_
;
1677 bool TestRunner::shouldInterceptPostMessage() const {
1678 return intercept_post_message_
;
1681 bool TestRunner::shouldDumpResourcePriorities() const {
1682 return should_dump_resource_priorities_
;
1685 WebNotificationPresenter
* TestRunner::notification_presenter() const {
1686 return notification_presenter_
.get();
1689 bool TestRunner::RequestPointerLock() {
1690 switch (pointer_lock_planned_result_
) {
1691 case PointerLockWillSucceed
:
1692 delegate_
->postDelayedTask(
1693 new HostMethodTask(this, &TestRunner::DidAcquirePointerLockInternal
),
1696 case PointerLockWillRespondAsync
:
1697 DCHECK(!pointer_locked_
);
1699 case PointerLockWillFailSync
:
1700 DCHECK(!pointer_locked_
);
1708 void TestRunner::RequestPointerUnlock() {
1709 delegate_
->postDelayedTask(
1710 new HostMethodTask(this, &TestRunner::DidLosePointerLockInternal
), 0);
1713 bool TestRunner::isPointerLocked() {
1714 return pointer_locked_
;
1717 void TestRunner::setToolTipText(const WebString
& text
) {
1718 tooltip_text_
= text
.utf8();
1721 bool TestRunner::midiAccessorResult() {
1722 return midi_accessor_result_
;
1725 void TestRunner::clearDevToolsLocalStorage() {
1726 delegate_
->clearDevToolsLocalStorage();
1729 void TestRunner::showDevTools(const std::string
& settings
,
1730 const std::string
& frontend_url
) {
1731 delegate_
->showDevTools(settings
, frontend_url
);
1734 class WorkItemBackForward
: public TestRunner::WorkItem
{
1736 WorkItemBackForward(int distance
) : distance_(distance
) {}
1738 virtual bool Run(WebTestDelegate
* delegate
, WebView
*) OVERRIDE
{
1739 delegate
->goToOffset(distance_
);
1740 return true; // FIXME: Did it really start a navigation?
1747 void TestRunner::NotifyDone() {
1748 if (disable_notify_done_
)
1751 // Test didn't timeout. Kill the timeout timer.
1752 taskList()->revokeAll();
1754 CompleteNotifyDone();
1757 void TestRunner::WaitUntilDone() {
1758 wait_until_done_
= true;
1761 void TestRunner::QueueBackNavigation(int how_far_back
) {
1762 work_queue_
.AddWork(new WorkItemBackForward(-how_far_back
));
1765 void TestRunner::QueueForwardNavigation(int how_far_forward
) {
1766 work_queue_
.AddWork(new WorkItemBackForward(how_far_forward
));
1769 class WorkItemReload
: public TestRunner::WorkItem
{
1771 virtual bool Run(WebTestDelegate
* delegate
, WebView
*) OVERRIDE
{
1777 void TestRunner::QueueReload() {
1778 work_queue_
.AddWork(new WorkItemReload());
1781 class WorkItemLoadingScript
: public TestRunner::WorkItem
{
1783 WorkItemLoadingScript(const std::string
& script
)
1784 : script_(script
) {}
1786 virtual bool Run(WebTestDelegate
*, WebView
* web_view
) OVERRIDE
{
1787 web_view
->mainFrame()->executeScript(
1788 WebScriptSource(WebString::fromUTF8(script_
)));
1789 return true; // FIXME: Did it really start a navigation?
1793 std::string script_
;
1796 void TestRunner::QueueLoadingScript(const std::string
& script
) {
1797 work_queue_
.AddWork(new WorkItemLoadingScript(script
));
1800 class WorkItemNonLoadingScript
: public TestRunner::WorkItem
{
1802 WorkItemNonLoadingScript(const std::string
& script
)
1803 : script_(script
) {}
1805 virtual bool Run(WebTestDelegate
*, WebView
* web_view
) OVERRIDE
{
1806 web_view
->mainFrame()->executeScript(
1807 WebScriptSource(WebString::fromUTF8(script_
)));
1812 std::string script_
;
1815 void TestRunner::QueueNonLoadingScript(const std::string
& script
) {
1816 work_queue_
.AddWork(new WorkItemNonLoadingScript(script
));
1819 class WorkItemLoad
: public TestRunner::WorkItem
{
1821 WorkItemLoad(const WebURL
& url
, const std::string
& target
)
1822 : url_(url
), target_(target
) {}
1824 virtual bool Run(WebTestDelegate
* delegate
, WebView
*) OVERRIDE
{
1825 delegate
->loadURLForFrame(url_
, target_
);
1826 return true; // FIXME: Did it really start a navigation?
1831 std::string target_
;
1834 void TestRunner::QueueLoad(const std::string
& url
, const std::string
& target
) {
1835 // FIXME: Implement WebURL::resolve() and avoid GURL.
1836 GURL current_url
= web_view_
->mainFrame()->document().url();
1837 GURL full_url
= current_url
.Resolve(url
);
1838 work_queue_
.AddWork(new WorkItemLoad(full_url
, target
));
1841 class WorkItemLoadHTMLString
: public TestRunner::WorkItem
{
1843 WorkItemLoadHTMLString(const std::string
& html
, const WebURL
& base_url
)
1844 : html_(html
), base_url_(base_url
) {}
1846 WorkItemLoadHTMLString(const std::string
& html
, const WebURL
& base_url
,
1847 const WebURL
& unreachable_url
)
1848 : html_(html
), base_url_(base_url
), unreachable_url_(unreachable_url
) {}
1850 virtual bool Run(WebTestDelegate
*, WebView
* web_view
) OVERRIDE
{
1851 web_view
->mainFrame()->loadHTMLString(
1852 WebData(html_
.data(), html_
.length()),
1853 base_url_
, unreachable_url_
);
1860 WebURL unreachable_url_
;
1863 void TestRunner::QueueLoadHTMLString(gin::Arguments
* args
) {
1865 args
->GetNext(&html
);
1867 std::string base_url_str
;
1868 args
->GetNext(&base_url_str
);
1869 WebURL base_url
= WebURL(GURL(base_url_str
));
1871 if (args
->PeekNext()->IsString()) {
1872 std::string unreachable_url_str
;
1873 args
->GetNext(&unreachable_url_str
);
1874 WebURL unreachable_url
= WebURL(GURL(unreachable_url_str
));
1875 work_queue_
.AddWork(new WorkItemLoadHTMLString(html
, base_url
,
1878 work_queue_
.AddWork(new WorkItemLoadHTMLString(html
, base_url
));
1882 void TestRunner::SetCustomPolicyDelegate(gin::Arguments
* args
) {
1883 args
->GetNext(&policy_delegate_enabled_
);
1884 if (!args
->PeekNext().IsEmpty() && args
->PeekNext()->IsBoolean())
1885 args
->GetNext(&policy_delegate_is_permissive_
);
1888 void TestRunner::WaitForPolicyDelegate() {
1889 policy_delegate_enabled_
= true;
1890 policy_delegate_should_notify_done_
= true;
1891 wait_until_done_
= true;
1894 int TestRunner::WindowCount() {
1895 return test_interfaces_
->windowList().size();
1898 void TestRunner::SetCloseRemainingWindowsWhenComplete(
1899 bool close_remaining_windows
) {
1900 close_remaining_windows_
= close_remaining_windows
;
1903 void TestRunner::ResetTestHelperControllers() {
1904 test_interfaces_
->resetTestHelperControllers();
1907 void TestRunner::SetTabKeyCyclesThroughElements(
1908 bool tab_key_cycles_through_elements
) {
1909 web_view_
->setTabKeyCyclesThroughElements(tab_key_cycles_through_elements
);
1912 void TestRunner::ExecCommand(gin::Arguments
* args
) {
1913 std::string command
;
1914 args
->GetNext(&command
);
1917 if (args
->Length() >= 3) {
1918 // Ignore the second parameter (which is userInterface)
1919 // since this command emulates a manual action.
1921 args
->GetNext(&value
);
1924 // Note: webkit's version does not return the boolean, so neither do we.
1925 web_view_
->focusedFrame()->executeCommand(WebString::fromUTF8(command
),
1926 WebString::fromUTF8(value
));
1929 bool TestRunner::IsCommandEnabled(const std::string
& command
) {
1930 return web_view_
->focusedFrame()->isCommandEnabled(
1931 WebString::fromUTF8(command
));
1934 bool TestRunner::CallShouldCloseOnWebView() {
1935 return web_view_
->mainFrame()->dispatchBeforeUnloadEvent();
1938 void TestRunner::SetDomainRelaxationForbiddenForURLScheme(
1939 bool forbidden
, const std::string
& scheme
) {
1940 web_view_
->setDomainRelaxationForbidden(forbidden
,
1941 WebString::fromUTF8(scheme
));
1944 v8::Handle
<v8::Value
> TestRunner::EvaluateScriptInIsolatedWorldAndReturnValue(
1946 const std::string
& script
) {
1947 WebVector
<v8::Local
<v8::Value
> > values
;
1948 WebScriptSource
source(WebString::fromUTF8(script
));
1949 // This relies on the iframe focusing itself when it loads. This is a bit
1950 // sketchy, but it seems to be what other tests do.
1951 web_view_
->focusedFrame()->executeScriptInIsolatedWorld(
1952 world_id
, &source
, 1, 1, &values
);
1953 // Since only one script was added, only one result is expected
1954 if (values
.size() == 1 && !values
[0].IsEmpty())
1956 return v8::Handle
<v8::Value
>();
1959 void TestRunner::EvaluateScriptInIsolatedWorld(int world_id
,
1960 const std::string
& script
) {
1961 WebScriptSource
source(WebString::fromUTF8(script
));
1962 web_view_
->focusedFrame()->executeScriptInIsolatedWorld(
1963 world_id
, &source
, 1, 1);
1966 void TestRunner::SetIsolatedWorldSecurityOrigin(int world_id
,
1967 v8::Handle
<v8::Value
> origin
) {
1968 if (!(origin
->IsString() || !origin
->IsNull()))
1971 WebSecurityOrigin web_origin
;
1972 if (origin
->IsString()) {
1973 web_origin
= WebSecurityOrigin::createFromString(
1974 V8StringToWebString(origin
->ToString()));
1976 web_view_
->focusedFrame()->setIsolatedWorldSecurityOrigin(world_id
,
1980 void TestRunner::SetIsolatedWorldContentSecurityPolicy(
1982 const std::string
& policy
) {
1983 web_view_
->focusedFrame()->setIsolatedWorldContentSecurityPolicy(
1984 world_id
, WebString::fromUTF8(policy
));
1987 void TestRunner::AddOriginAccessWhitelistEntry(
1988 const std::string
& source_origin
,
1989 const std::string
& destination_protocol
,
1990 const std::string
& destination_host
,
1991 bool allow_destination_subdomains
) {
1992 WebURL
url((GURL(source_origin
)));
1996 WebSecurityPolicy::addOriginAccessWhitelistEntry(
1998 WebString::fromUTF8(destination_protocol
),
1999 WebString::fromUTF8(destination_host
),
2000 allow_destination_subdomains
);
2003 void TestRunner::RemoveOriginAccessWhitelistEntry(
2004 const std::string
& source_origin
,
2005 const std::string
& destination_protocol
,
2006 const std::string
& destination_host
,
2007 bool allow_destination_subdomains
) {
2008 WebURL
url((GURL(source_origin
)));
2012 WebSecurityPolicy::removeOriginAccessWhitelistEntry(
2014 WebString::fromUTF8(destination_protocol
),
2015 WebString::fromUTF8(destination_host
),
2016 allow_destination_subdomains
);
2019 bool TestRunner::HasCustomPageSizeStyle(int page_index
) {
2020 WebFrame
* frame
= web_view_
->mainFrame();
2023 return frame
->hasCustomPageSizeStyle(page_index
);
2026 void TestRunner::ForceRedSelectionColors() {
2027 web_view_
->setSelectionColors(0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0);
2030 void TestRunner::InjectStyleSheet(const std::string
& source_code
,
2032 WebView::injectStyleSheet(
2033 WebString::fromUTF8(source_code
),
2034 WebVector
<WebString
>(),
2035 all_frames
? WebView::InjectStyleInAllFrames
2036 : WebView::InjectStyleInTopFrameOnly
);
2039 bool TestRunner::FindString(const std::string
& search_text
,
2040 const std::vector
<std::string
>& options_array
) {
2041 WebFindOptions find_options
;
2042 bool wrap_around
= false;
2043 find_options
.matchCase
= true;
2044 find_options
.findNext
= true;
2046 for (size_t i
= 0; i
< options_array
.size(); ++i
) {
2047 const std::string
& option
= options_array
[i
];
2048 if (option
== "CaseInsensitive")
2049 find_options
.matchCase
= false;
2050 else if (option
== "Backwards")
2051 find_options
.forward
= false;
2052 else if (option
== "StartInSelection")
2053 find_options
.findNext
= false;
2054 else if (option
== "AtWordStarts")
2055 find_options
.wordStart
= true;
2056 else if (option
== "TreatMedialCapitalAsWordStart")
2057 find_options
.medialCapitalAsWordStart
= true;
2058 else if (option
== "WrapAround")
2062 WebFrame
* frame
= web_view_
->mainFrame();
2063 const bool find_result
= frame
->find(0, WebString::fromUTF8(search_text
),
2064 find_options
, wrap_around
, 0);
2065 frame
->stopFinding(false);
2069 std::string
TestRunner::SelectionAsMarkup() {
2070 return web_view_
->mainFrame()->selectionAsMarkup().utf8();
2073 void TestRunner::SetTextSubpixelPositioning(bool value
) {
2074 #if defined(__linux__) || defined(ANDROID)
2075 // Since FontConfig doesn't provide a variable to control subpixel
2076 // positioning, we'll fall back to setting it globally for all fonts.
2077 WebFontRendering::setSubpixelPositioning(value
);
2081 void TestRunner::SetPageVisibility(const std::string
& new_visibility
) {
2082 if (new_visibility
== "visible")
2083 web_view_
->setVisibilityState(WebPageVisibilityStateVisible
, false);
2084 else if (new_visibility
== "hidden")
2085 web_view_
->setVisibilityState(WebPageVisibilityStateHidden
, false);
2086 else if (new_visibility
== "prerender")
2087 web_view_
->setVisibilityState(WebPageVisibilityStatePrerender
, false);
2090 void TestRunner::SetTextDirection(const std::string
& direction_name
) {
2091 // Map a direction name to a WebTextDirection value.
2092 WebTextDirection direction
;
2093 if (direction_name
== "auto")
2094 direction
= WebTextDirectionDefault
;
2095 else if (direction_name
== "rtl")
2096 direction
= WebTextDirectionRightToLeft
;
2097 else if (direction_name
== "ltr")
2098 direction
= WebTextDirectionLeftToRight
;
2102 web_view_
->setTextDirection(direction
);
2105 void TestRunner::UseUnfortunateSynchronousResizeMode() {
2106 delegate_
->useUnfortunateSynchronousResizeMode(true);
2109 bool TestRunner::EnableAutoResizeMode(int min_width
,
2113 WebSize
min_size(min_width
, min_height
);
2114 WebSize
max_size(max_width
, max_height
);
2115 delegate_
->enableAutoResizeMode(min_size
, max_size
);
2119 bool TestRunner::DisableAutoResizeMode(int new_width
, int new_height
) {
2120 WebSize
new_size(new_width
, new_height
);
2121 delegate_
->disableAutoResizeMode(new_size
);
2125 void TestRunner::SetMockDeviceMotion(
2126 bool has_acceleration_x
, double acceleration_x
,
2127 bool has_acceleration_y
, double acceleration_y
,
2128 bool has_acceleration_z
, double acceleration_z
,
2129 bool has_acceleration_including_gravity_x
,
2130 double acceleration_including_gravity_x
,
2131 bool has_acceleration_including_gravity_y
,
2132 double acceleration_including_gravity_y
,
2133 bool has_acceleration_including_gravity_z
,
2134 double acceleration_including_gravity_z
,
2135 bool has_rotation_rate_alpha
, double rotation_rate_alpha
,
2136 bool has_rotation_rate_beta
, double rotation_rate_beta
,
2137 bool has_rotation_rate_gamma
, double rotation_rate_gamma
,
2139 WebDeviceMotionData motion
;
2142 motion
.hasAccelerationX
= has_acceleration_x
;
2143 motion
.accelerationX
= acceleration_x
;
2144 motion
.hasAccelerationY
= has_acceleration_y
;
2145 motion
.accelerationY
= acceleration_y
;
2146 motion
.hasAccelerationZ
= has_acceleration_z
;
2147 motion
.accelerationZ
= acceleration_z
;
2149 // accelerationIncludingGravity
2150 motion
.hasAccelerationIncludingGravityX
=
2151 has_acceleration_including_gravity_x
;
2152 motion
.accelerationIncludingGravityX
= acceleration_including_gravity_x
;
2153 motion
.hasAccelerationIncludingGravityY
=
2154 has_acceleration_including_gravity_y
;
2155 motion
.accelerationIncludingGravityY
= acceleration_including_gravity_y
;
2156 motion
.hasAccelerationIncludingGravityZ
=
2157 has_acceleration_including_gravity_z
;
2158 motion
.accelerationIncludingGravityZ
= acceleration_including_gravity_z
;
2161 motion
.hasRotationRateAlpha
= has_rotation_rate_alpha
;
2162 motion
.rotationRateAlpha
= rotation_rate_alpha
;
2163 motion
.hasRotationRateBeta
= has_rotation_rate_beta
;
2164 motion
.rotationRateBeta
= rotation_rate_beta
;
2165 motion
.hasRotationRateGamma
= has_rotation_rate_gamma
;
2166 motion
.rotationRateGamma
= rotation_rate_gamma
;
2169 motion
.interval
= interval
;
2171 delegate_
->setDeviceMotionData(motion
);
2174 void TestRunner::SetMockDeviceOrientation(bool has_alpha
, double alpha
,
2175 bool has_beta
, double beta
,
2176 bool has_gamma
, double gamma
,
2177 bool has_absolute
, bool absolute
) {
2178 WebDeviceOrientationData orientation
;
2181 orientation
.hasAlpha
= has_alpha
;
2182 orientation
.alpha
= alpha
;
2185 orientation
.hasBeta
= has_beta
;
2186 orientation
.beta
= beta
;
2189 orientation
.hasGamma
= has_gamma
;
2190 orientation
.gamma
= gamma
;
2193 orientation
.hasAbsolute
= has_absolute
;
2194 orientation
.absolute
= absolute
;
2196 delegate_
->setDeviceOrientationData(orientation
);
2199 void TestRunner::SetMockScreenOrientation(const std::string
& orientation_str
) {
2200 blink::WebScreenOrientationType orientation
;
2202 if (orientation_str
== "portrait-primary") {
2203 orientation
= WebScreenOrientationPortraitPrimary
;
2204 } else if (orientation_str
== "portrait-secondary") {
2205 orientation
= WebScreenOrientationPortraitSecondary
;
2206 } else if (orientation_str
== "landscape-primary") {
2207 orientation
= WebScreenOrientationLandscapePrimary
;
2208 } else if (orientation_str
== "landscape-secondary") {
2209 orientation
= WebScreenOrientationLandscapeSecondary
;
2212 delegate_
->setScreenOrientation(orientation
);
2215 void TestRunner::DidAcquirePointerLock() {
2216 DidAcquirePointerLockInternal();
2219 void TestRunner::DidNotAcquirePointerLock() {
2220 DidNotAcquirePointerLockInternal();
2223 void TestRunner::DidLosePointerLock() {
2224 DidLosePointerLockInternal();
2227 void TestRunner::SetPointerLockWillFailSynchronously() {
2228 pointer_lock_planned_result_
= PointerLockWillFailSync
;
2231 void TestRunner::SetPointerLockWillRespondAsynchronously() {
2232 pointer_lock_planned_result_
= PointerLockWillRespondAsync
;
2235 void TestRunner::SetPopupBlockingEnabled(bool block_popups
) {
2236 delegate_
->preferences()->java_script_can_open_windows_automatically
=
2238 delegate_
->applyPreferences();
2241 void TestRunner::SetJavaScriptCanAccessClipboard(bool can_access
) {
2242 delegate_
->preferences()->java_script_can_access_clipboard
= can_access
;
2243 delegate_
->applyPreferences();
2246 void TestRunner::SetXSSAuditorEnabled(bool enabled
) {
2247 delegate_
->preferences()->xss_auditor_enabled
= enabled
;
2248 delegate_
->applyPreferences();
2251 void TestRunner::SetAllowUniversalAccessFromFileURLs(bool allow
) {
2252 delegate_
->preferences()->allow_universal_access_from_file_urls
= allow
;
2253 delegate_
->applyPreferences();
2256 void TestRunner::SetAllowFileAccessFromFileURLs(bool allow
) {
2257 delegate_
->preferences()->allow_file_access_from_file_urls
= allow
;
2258 delegate_
->applyPreferences();
2261 void TestRunner::OverridePreference(const std::string key
,
2262 v8::Handle
<v8::Value
> value
) {
2263 TestPreferences
* prefs
= delegate_
->preferences();
2264 if (key
== "WebKitDefaultFontSize") {
2265 prefs
->default_font_size
= value
->Int32Value();
2266 } else if (key
== "WebKitMinimumFontSize") {
2267 prefs
->minimum_font_size
= value
->Int32Value();
2268 } else if (key
== "WebKitDefaultTextEncodingName") {
2269 prefs
->default_text_encoding_name
= V8StringToWebString(value
->ToString());
2270 } else if (key
== "WebKitJavaScriptEnabled") {
2271 prefs
->java_script_enabled
= value
->BooleanValue();
2272 } else if (key
== "WebKitSupportsMultipleWindows") {
2273 prefs
->supports_multiple_windows
= value
->BooleanValue();
2274 } else if (key
== "WebKitDisplayImagesKey") {
2275 prefs
->loads_images_automatically
= value
->BooleanValue();
2276 } else if (key
== "WebKitPluginsEnabled") {
2277 prefs
->plugins_enabled
= value
->BooleanValue();
2278 } else if (key
== "WebKitJavaEnabled") {
2279 prefs
->java_enabled
= value
->BooleanValue();
2280 } else if (key
== "WebKitOfflineWebApplicationCacheEnabled") {
2281 prefs
->offline_web_application_cache_enabled
= value
->BooleanValue();
2282 } else if (key
== "WebKitTabToLinksPreferenceKey") {
2283 prefs
->tabs_to_links
= value
->BooleanValue();
2284 } else if (key
== "WebKitWebGLEnabled") {
2285 prefs
->experimental_webgl_enabled
= value
->BooleanValue();
2286 } else if (key
== "WebKitCSSRegionsEnabled") {
2287 prefs
->experimental_css_regions_enabled
= value
->BooleanValue();
2288 } else if (key
== "WebKitCSSGridLayoutEnabled") {
2289 prefs
->experimental_css_grid_layout_enabled
= value
->BooleanValue();
2290 } else if (key
== "WebKitHyperlinkAuditingEnabled") {
2291 prefs
->hyperlink_auditing_enabled
= value
->BooleanValue();
2292 } else if (key
== "WebKitEnableCaretBrowsing") {
2293 prefs
->caret_browsing_enabled
= value
->BooleanValue();
2294 } else if (key
== "WebKitAllowDisplayingInsecureContent") {
2295 prefs
->allow_display_of_insecure_content
= value
->BooleanValue();
2296 } else if (key
== "WebKitAllowRunningInsecureContent") {
2297 prefs
->allow_running_of_insecure_content
= value
->BooleanValue();
2298 } else if (key
== "WebKitShouldRespectImageOrientation") {
2299 prefs
->should_respect_image_orientation
= value
->BooleanValue();
2300 } else if (key
== "WebKitWebAudioEnabled") {
2301 DCHECK(value
->BooleanValue());
2303 std::string
message("Invalid name for preference: ");
2304 message
.append(key
);
2305 delegate_
->printMessage(std::string("CONSOLE MESSAGE: ") + message
+ "\n");
2307 delegate_
->applyPreferences();
2310 void TestRunner::SetPluginsEnabled(bool enabled
) {
2311 delegate_
->preferences()->plugins_enabled
= enabled
;
2312 delegate_
->applyPreferences();
2315 void TestRunner::DumpEditingCallbacks() {
2316 dump_editting_callbacks_
= true;
2319 void TestRunner::DumpAsText() {
2320 dump_as_text_
= true;
2321 generate_pixel_results_
= false;
2324 void TestRunner::DumpAsTextWithPixelResults() {
2325 dump_as_text_
= true;
2326 generate_pixel_results_
= true;
2329 void TestRunner::DumpChildFrameScrollPositions() {
2330 dump_child_frame_scroll_positions_
= true;
2333 void TestRunner::DumpChildFramesAsText() {
2334 dump_child_frames_as_text_
= true;
2337 void TestRunner::DumpIconChanges() {
2338 dump_icon_changes_
= true;
2341 void TestRunner::SetAudioData(const gin::ArrayBufferView
& view
) {
2342 unsigned char* bytes
= static_cast<unsigned char*>(view
.bytes());
2343 audio_data_
.resize(view
.num_bytes());
2344 std::copy(bytes
, bytes
+ view
.num_bytes(), audio_data_
.begin());
2345 dump_as_audio_
= true;
2348 void TestRunner::DumpFrameLoadCallbacks() {
2349 dump_frame_load_callbacks_
= true;
2352 void TestRunner::DumpPingLoaderCallbacks() {
2353 dump_ping_loader_callbacks_
= true;
2356 void TestRunner::DumpUserGestureInFrameLoadCallbacks() {
2357 dump_user_gesture_in_frame_load_callbacks_
= true;
2360 void TestRunner::DumpTitleChanges() {
2361 dump_title_changes_
= true;
2364 void TestRunner::DumpCreateView() {
2365 dump_create_view_
= true;
2368 void TestRunner::SetCanOpenWindows() {
2369 can_open_windows_
= true;
2372 void TestRunner::DumpResourceLoadCallbacks() {
2373 dump_resource_load_callbacks_
= true;
2376 void TestRunner::DumpResourceRequestCallbacks() {
2377 dump_resource_request_callbacks_
= true;
2380 void TestRunner::DumpResourceResponseMIMETypes() {
2381 dump_resource_reqponse_mime_types_
= true;
2384 void TestRunner::SetImagesAllowed(bool allowed
) {
2385 web_permissions_
->setImagesAllowed(allowed
);
2388 void TestRunner::SetScriptsAllowed(bool allowed
) {
2389 web_permissions_
->setScriptsAllowed(allowed
);
2392 void TestRunner::SetStorageAllowed(bool allowed
) {
2393 web_permissions_
->setStorageAllowed(allowed
);
2396 void TestRunner::SetPluginsAllowed(bool allowed
) {
2397 web_permissions_
->setPluginsAllowed(allowed
);
2400 void TestRunner::SetAllowDisplayOfInsecureContent(bool allowed
) {
2401 web_permissions_
->setDisplayingInsecureContentAllowed(allowed
);
2404 void TestRunner::SetAllowRunningOfInsecureContent(bool allowed
) {
2405 web_permissions_
->setRunningInsecureContentAllowed(allowed
);
2408 void TestRunner::DumpPermissionClientCallbacks() {
2409 web_permissions_
->setDumpCallbacks(true);
2412 void TestRunner::DumpWindowStatusChanges() {
2413 dump_window_status_changes_
= true;
2416 void TestRunner::DumpProgressFinishedCallback() {
2417 dump_progress_finished_callback_
= true;
2420 void TestRunner::DumpSpellCheckCallbacks() {
2421 dump_spell_check_callbacks_
= true;
2424 void TestRunner::DumpBackForwardList() {
2425 dump_back_forward_list_
= true;
2428 void TestRunner::DumpSelectionRect() {
2429 dump_selection_rect_
= true;
2432 void TestRunner::SetPrinting() {
2433 is_printing_
= true;
2436 void TestRunner::SetShouldStayOnPageAfterHandlingBeforeUnload(bool value
) {
2437 should_stay_on_page_after_handling_before_unload_
= value
;
2440 void TestRunner::SetWillSendRequestClearHeader(const std::string
& header
) {
2441 if (!header
.empty())
2442 http_headers_to_clear_
.insert(header
);
2445 void TestRunner::DumpResourceRequestPriorities() {
2446 should_dump_resource_priorities_
= true;
2449 void TestRunner::SetUseMockTheme(bool use
) {
2450 use_mock_theme_
= use
;
2453 void TestRunner::ShowWebInspector(const std::string
& str
,
2454 const std::string
& frontend_url
) {
2455 showDevTools(str
, frontend_url
);
2458 void TestRunner::WaitUntilExternalURLLoad() {
2459 wait_until_external_url_load_
= true;
2462 void TestRunner::CloseWebInspector() {
2463 delegate_
->closeDevTools();
2466 bool TestRunner::IsChooserShown() {
2467 return proxy_
->isChooserShown();
2470 void TestRunner::EvaluateInWebInspector(int call_id
,
2471 const std::string
& script
) {
2472 delegate_
->evaluateInWebInspector(call_id
, script
);
2475 void TestRunner::ClearAllDatabases() {
2476 delegate_
->clearAllDatabases();
2479 void TestRunner::SetDatabaseQuota(int quota
) {
2480 delegate_
->setDatabaseQuota(quota
);
2483 void TestRunner::SetAlwaysAcceptCookies(bool accept
) {
2484 delegate_
->setAcceptAllCookies(accept
);
2487 void TestRunner::SetWindowIsKey(bool value
) {
2488 delegate_
->setFocus(proxy_
, value
);
2491 std::string
TestRunner::PathToLocalResource(const std::string
& path
) {
2492 return delegate_
->pathToLocalResource(path
);
2495 void TestRunner::SetBackingScaleFactor(double value
,
2496 v8::Handle
<v8::Function
> callback
) {
2497 delegate_
->setDeviceScaleFactor(value
);
2498 proxy_
->discardBackingStore();
2499 delegate_
->postTask(new InvokeCallbackTask(this, callback
));
2502 void TestRunner::SetPOSIXLocale(const std::string
& locale
) {
2503 delegate_
->setLocale(locale
);
2506 void TestRunner::SetMIDIAccessorResult(bool result
) {
2507 midi_accessor_result_
= result
;
2510 void TestRunner::SetMIDISysexPermission(bool value
) {
2511 const std::vector
<WebTestProxyBase
*>& windowList
=
2512 test_interfaces_
->windowList();
2513 for (unsigned i
= 0; i
< windowList
.size(); ++i
)
2514 windowList
.at(i
)->midiClientMock()->setSysexPermission(value
);
2517 void TestRunner::GrantWebNotificationPermission(const std::string
& origin
,
2518 bool permission_granted
) {
2519 notification_presenter_
->GrantPermission(origin
, permission_granted
);
2522 bool TestRunner::SimulateWebNotificationClick(const std::string
& value
) {
2523 return notification_presenter_
->SimulateClick(value
);
2526 void TestRunner::AddMockSpeechInputResult(const std::string
& result
,
2528 const std::string
& language
) {
2529 #if ENABLE_INPUT_SPEECH
2530 proxy_
->speechInputControllerMock()->addMockRecognitionResult(
2531 WebString::fromUTF8(result
), confidence
, WebString::fromUTF8(language
));
2535 void TestRunner::SetMockSpeechInputDumpRect(bool value
) {
2536 #if ENABLE_INPUT_SPEECH
2537 proxy_
->speechInputControllerMock()->setDumpRect(value
);
2541 void TestRunner::AddMockSpeechRecognitionResult(const std::string
& transcript
,
2542 double confidence
) {
2543 proxy_
->speechRecognizerMock()->addMockResult(
2544 WebString::fromUTF8(transcript
), confidence
);
2547 void TestRunner::SetMockSpeechRecognitionError(const std::string
& error
,
2548 const std::string
& message
) {
2549 proxy_
->speechRecognizerMock()->setError(WebString::fromUTF8(error
),
2550 WebString::fromUTF8(message
));
2553 bool TestRunner::WasMockSpeechRecognitionAborted() {
2554 return proxy_
->speechRecognizerMock()->wasAborted();
2557 void TestRunner::AddWebPageOverlay() {
2558 if (web_view_
&& !page_overlay_
) {
2559 page_overlay_
= new TestPageOverlay(web_view_
);
2560 web_view_
->addPageOverlay(page_overlay_
, 0);
2564 void TestRunner::RemoveWebPageOverlay() {
2565 if (web_view_
&& page_overlay_
) {
2566 web_view_
->removePageOverlay(page_overlay_
);
2567 delete page_overlay_
;
2568 page_overlay_
= NULL
;
2572 void TestRunner::DisplayAsync() {
2573 proxy_
->displayAsyncThen(base::Closure());
2576 void TestRunner::DisplayAsyncThen(v8::Handle
<v8::Function
> callback
) {
2577 scoped_ptr
<InvokeCallbackTask
> task(
2578 new InvokeCallbackTask(this, callback
));
2579 proxy_
->displayAsyncThen(base::Bind(&TestRunner::InvokeCallback
,
2580 base::Unretained(this),
2581 base::Passed(&task
)));
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 DCHECK(!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