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