Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: content/shell/renderer/test_runner/TestRunner.cpp

Issue 110533009: Import TestRunner library into chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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 /*
6 * Copyright (C) 2010 Google Inc. All rights reserved.
7 * Copyright (C) 2010 Pawel Hajdan (phajdan.jr@chromium.org)
8 * Copyright (C) 2012 Apple Inc. All Rights Reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are
12 * met:
13 *
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following disclaimer
18 * in the documentation and/or other materials provided with the
19 * distribution.
20 * * Neither the name of Google Inc. nor the names of its
21 * contributors may be used to endorse or promote products derived from
22 * this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 #include "content/shell/renderer/test_runner/TestRunner.h"
38
39 #include <limits>
40
41 #include "content/shell/common/test_runner/WebPreferences.h"
42 #include "content/shell/renderer/test_runner/MockWebSpeechInputController.h"
43 #include "content/shell/renderer/test_runner/MockWebSpeechRecognizer.h"
44 #include "content/shell/renderer/test_runner/NotificationPresenter.h"
45 #include "content/shell/renderer/test_runner/TestInterfaces.h"
46 #include "content/shell/renderer/test_runner/WebPermissions.h"
47 #include "content/shell/renderer/test_runner/WebTestDelegate.h"
48 #include "content/shell/renderer/test_runner/WebTestProxy.h"
49 #include "third_party/WebKit/public/platform/WebData.h"
50 #include "third_party/WebKit/public/platform/WebDeviceMotionData.h"
51 #include "third_party/WebKit/public/platform/WebDeviceOrientationData.h"
52 #include "third_party/WebKit/public/platform/WebPoint.h"
53 #include "third_party/WebKit/public/platform/WebURLResponse.h"
54 #include "third_party/WebKit/public/web/WebBindings.h"
55 #include "third_party/WebKit/public/web/WebDataSource.h"
56 #include "third_party/WebKit/public/web/WebDocument.h"
57 #include "third_party/WebKit/public/web/WebElement.h"
58 #include "third_party/WebKit/public/web/WebFindOptions.h"
59 #include "third_party/WebKit/public/web/WebFrame.h"
60 #include "third_party/WebKit/public/web/WebGeolocationClientMock.h"
61 #include "third_party/WebKit/public/web/WebInputElement.h"
62 #include "third_party/WebKit/public/web/WebMIDIClientMock.h"
63 #include "third_party/WebKit/public/web/WebScriptSource.h"
64 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
65 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
66 #include "third_party/WebKit/public/web/WebSettings.h"
67 #include "third_party/WebKit/public/web/WebSurroundingText.h"
68 #include "third_party/WebKit/public/web/WebView.h"
69 #include "v8/include/v8.h"
70
71 #if defined(__linux__) || defined(ANDROID)
72 #include "third_party/WebKit/public/web/linux/WebFontRendering.h"
73 #endif
74
75 using namespace blink;
76 using namespace std;
77
78 namespace WebTestRunner {
79
80 namespace {
81
82 class InvokeCallbackTask : public WebMethodTask<TestRunner> {
83 public:
84 InvokeCallbackTask(TestRunner* object, WebScopedPtr<CppVariant> callbackArgu ments)
85 : WebMethodTask<TestRunner>(object)
86 , m_callbackArguments(callbackArguments)
87 {
88 }
89
90 virtual void runIfValid()
91 {
92 CppVariant invokeResult;
93 m_callbackArguments->invokeDefault(m_callbackArguments.get(), 1, invokeR esult);
94 }
95
96 private:
97 WebScopedPtr<CppVariant> m_callbackArguments;
98 };
99
100 }
101
102 TestRunner::WorkQueue::~WorkQueue()
103 {
104 reset();
105 }
106
107 void TestRunner::WorkQueue::processWorkSoon()
108 {
109 if (m_controller->topLoadingFrame())
110 return;
111
112 if (!m_queue.empty()) {
113 // We delay processing queued work to avoid recursion problems.
114 m_controller->m_delegate->postTask(new WorkQueueTask(this));
115 } else if (!m_controller->m_waitUntilDone)
116 m_controller->m_delegate->testFinished();
117 }
118
119 void TestRunner::WorkQueue::processWork()
120 {
121 // Quit doing work once a load is in progress.
122 while (!m_queue.empty()) {
123 bool startedLoad = m_queue.front()->run(m_controller->m_delegate, m_cont roller->m_webView);
124 delete m_queue.front();
125 m_queue.pop_front();
126 if (startedLoad)
127 return;
128 }
129
130 if (!m_controller->m_waitUntilDone && !m_controller->topLoadingFrame())
131 m_controller->m_delegate->testFinished();
132 }
133
134 void TestRunner::WorkQueue::reset()
135 {
136 m_frozen = false;
137 while (!m_queue.empty()) {
138 delete m_queue.front();
139 m_queue.pop_front();
140 }
141 }
142
143 void TestRunner::WorkQueue::addWork(WorkItem* work)
144 {
145 if (m_frozen) {
146 delete work;
147 return;
148 }
149 m_queue.push_back(work);
150 }
151
152
153 TestRunner::TestRunner(TestInterfaces* interfaces)
154 : m_testIsRunning(false)
155 , m_closeRemainingWindows(false)
156 , m_workQueue(this)
157 , m_testInterfaces(interfaces)
158 , m_delegate(0)
159 , m_webView(0)
160 , m_pageOverlay(0)
161 , m_webPermissions(new WebPermissions)
162 , m_notificationPresenter(new NotificationPresenter)
163 {
164 // Initialize the map that associates methods of this class with the names
165 // they will use when called by JavaScript. The actual binding of those
166 // names to their methods will be done by calling bindToJavaScript() (define d
167 // by CppBoundClass, the parent to TestRunner).
168
169 // Methods controlling test execution.
170 bindMethod("notifyDone", &TestRunner::notifyDone);
171 bindMethod("queueBackNavigation", &TestRunner::queueBackNavigation);
172 bindMethod("queueForwardNavigation", &TestRunner::queueForwardNavigation);
173 bindMethod("queueLoadingScript", &TestRunner::queueLoadingScript);
174 bindMethod("queueLoad", &TestRunner::queueLoad);
175 bindMethod("queueLoadHTMLString", &TestRunner::queueLoadHTMLString);
176 bindMethod("queueNonLoadingScript", &TestRunner::queueNonLoadingScript);
177 bindMethod("queueReload", &TestRunner::queueReload);
178 bindMethod("setCloseRemainingWindowsWhenComplete", &TestRunner::setCloseRema iningWindowsWhenComplete);
179 bindMethod("resetTestHelperControllers", &TestRunner::resetTestHelperControl lers);
180 bindMethod("setCustomPolicyDelegate", &TestRunner::setCustomPolicyDelegate);
181 bindMethod("waitForPolicyDelegate", &TestRunner::waitForPolicyDelegate);
182 bindMethod("waitUntilDone", &TestRunner::waitUntilDone);
183 bindMethod("windowCount", &TestRunner::windowCount);
184 // Methods implemented in terms of chromium's public WebKit API.
185 bindMethod("setTabKeyCyclesThroughElements", &TestRunner::setTabKeyCyclesThr oughElements);
186 bindMethod("execCommand", &TestRunner::execCommand);
187 bindMethod("isCommandEnabled", &TestRunner::isCommandEnabled);
188 bindMethod("callShouldCloseOnWebView", &TestRunner::callShouldCloseOnWebView );
189 bindMethod("setDomainRelaxationForbiddenForURLScheme", &TestRunner::setDomai nRelaxationForbiddenForURLScheme);
190 bindMethod("evaluateScriptInIsolatedWorldAndReturnValue", &TestRunner::evalu ateScriptInIsolatedWorldAndReturnValue);
191 bindMethod("evaluateScriptInIsolatedWorld", &TestRunner::evaluateScriptInIso latedWorld);
192 bindMethod("setIsolatedWorldSecurityOrigin", &TestRunner::setIsolatedWorldSe curityOrigin);
193 bindMethod("setIsolatedWorldContentSecurityPolicy", &TestRunner::setIsolated WorldContentSecurityPolicy);
194 bindMethod("addOriginAccessWhitelistEntry", &TestRunner::addOriginAccessWhit elistEntry);
195 bindMethod("removeOriginAccessWhitelistEntry", &TestRunner::removeOriginAcce ssWhitelistEntry);
196 bindMethod("hasCustomPageSizeStyle", &TestRunner::hasCustomPageSizeStyle);
197 bindMethod("forceRedSelectionColors", &TestRunner::forceRedSelectionColors);
198 bindMethod("injectStyleSheet", &TestRunner::injectStyleSheet);
199 bindMethod("startSpeechInput", &TestRunner::startSpeechInput);
200 bindMethod("findString", &TestRunner::findString);
201 bindMethod("setValueForUser", &TestRunner::setValueForUser);
202 bindMethod("selectionAsMarkup", &TestRunner::selectionAsMarkup);
203 bindMethod("setTextSubpixelPositioning", &TestRunner::setTextSubpixelPositio ning);
204 bindMethod("setPageVisibility", &TestRunner::setPageVisibility);
205 bindMethod("setTextDirection", &TestRunner::setTextDirection);
206 bindMethod("textSurroundingNode", &TestRunner::textSurroundingNode);
207 bindMethod("useUnfortunateSynchronousResizeMode", &TestRunner::useUnfortunat eSynchronousResizeMode);
208 bindMethod("disableAutoResizeMode", &TestRunner::disableAutoResizeMode);
209 bindMethod("enableAutoResizeMode", &TestRunner::enableAutoResizeMode);
210 bindMethod("setMockDeviceMotion", &TestRunner::setMockDeviceMotion);
211 bindMethod("setMockDeviceOrientation", &TestRunner::setMockDeviceOrientation );
212 bindMethod("didAcquirePointerLock", &TestRunner::didAcquirePointerLock);
213 bindMethod("didLosePointerLock", &TestRunner::didLosePointerLock);
214 bindMethod("didNotAcquirePointerLock", &TestRunner::didNotAcquirePointerLock );
215 bindMethod("setPointerLockWillRespondAsynchronously", &TestRunner::setPointe rLockWillRespondAsynchronously);
216 bindMethod("setPointerLockWillFailSynchronously", &TestRunner::setPointerLoc kWillFailSynchronously);
217
218 // The following modify WebPreferences.
219 bindMethod("setPopupBlockingEnabled", &TestRunner::setPopupBlockingEnabled);
220 bindMethod("setJavaScriptCanAccessClipboard", &TestRunner::setJavaScriptCanA ccessClipboard);
221 bindMethod("setXSSAuditorEnabled", &TestRunner::setXSSAuditorEnabled);
222 bindMethod("setAllowUniversalAccessFromFileURLs", &TestRunner::setAllowUnive rsalAccessFromFileURLs);
223 bindMethod("setAllowFileAccessFromFileURLs", &TestRunner::setAllowFileAccess FromFileURLs);
224 bindMethod("overridePreference", &TestRunner::overridePreference);
225 bindMethod("setPluginsEnabled", &TestRunner::setPluginsEnabled);
226
227 // The following modify the state of the TestRunner.
228 bindMethod("dumpEditingCallbacks", &TestRunner::dumpEditingCallbacks);
229 bindMethod("dumpAsText", &TestRunner::dumpAsText);
230 bindMethod("dumpAsTextWithPixelResults", &TestRunner::dumpAsTextWithPixelRes ults);
231 bindMethod("dumpChildFramesAsText", &TestRunner::dumpChildFramesAsText);
232 bindMethod("dumpChildFrameScrollPositions", &TestRunner::dumpChildFrameScrol lPositions);
233 bindMethod("dumpIconChanges", &TestRunner::dumpIconChanges);
234 bindMethod("setAudioData", &TestRunner::setAudioData);
235 bindMethod("dumpFrameLoadCallbacks", &TestRunner::dumpFrameLoadCallbacks);
236 bindMethod("dumpPingLoaderCallbacks", &TestRunner::dumpPingLoaderCallbacks);
237 bindMethod("dumpUserGestureInFrameLoadCallbacks", &TestRunner::dumpUserGestu reInFrameLoadCallbacks);
238 bindMethod("dumpTitleChanges", &TestRunner::dumpTitleChanges);
239 bindMethod("dumpCreateView", &TestRunner::dumpCreateView);
240 bindMethod("setCanOpenWindows", &TestRunner::setCanOpenWindows);
241 bindMethod("dumpResourceLoadCallbacks", &TestRunner::dumpResourceLoadCallbac ks);
242 bindMethod("dumpResourceRequestCallbacks", &TestRunner::dumpResourceRequestC allbacks);
243 bindMethod("dumpResourceResponseMIMETypes", &TestRunner::dumpResourceRespons eMIMETypes);
244 bindMethod("dumpPermissionClientCallbacks", &TestRunner::dumpPermissionClien tCallbacks);
245 bindMethod("setImagesAllowed", &TestRunner::setImagesAllowed);
246 bindMethod("setScriptsAllowed", &TestRunner::setScriptsAllowed);
247 bindMethod("setStorageAllowed", &TestRunner::setStorageAllowed);
248 bindMethod("setPluginsAllowed", &TestRunner::setPluginsAllowed);
249 bindMethod("setAllowDisplayOfInsecureContent", &TestRunner::setAllowDisplayO fInsecureContent);
250 bindMethod("setAllowRunningOfInsecureContent", &TestRunner::setAllowRunningO fInsecureContent);
251 bindMethod("dumpStatusCallbacks", &TestRunner::dumpWindowStatusChanges);
252 bindMethod("dumpProgressFinishedCallback", &TestRunner::dumpProgressFinished Callback);
253 bindMethod("dumpSpellCheckCallbacks", &TestRunner::dumpSpellCheckCallbacks);
254 bindMethod("dumpBackForwardList", &TestRunner::dumpBackForwardList);
255 bindMethod("dumpSelectionRect", &TestRunner::dumpSelectionRect);
256 bindMethod("testRepaint", &TestRunner::testRepaint);
257 bindMethod("repaintSweepHorizontally", &TestRunner::repaintSweepHorizontally );
258 bindMethod("setPrinting", &TestRunner::setPrinting);
259 bindMethod("setShouldStayOnPageAfterHandlingBeforeUnload", &TestRunner::setS houldStayOnPageAfterHandlingBeforeUnload);
260 bindMethod("setWillSendRequestClearHeader", &TestRunner::setWillSendRequestC learHeader);
261 bindMethod("dumpResourceRequestPriorities", &TestRunner::dumpResourceRequest Priorities);
262
263 // The following methods interact with the WebTestProxy.
264 // The following methods interact with the WebTestDelegate.
265 bindMethod("showWebInspector", &TestRunner::showWebInspector);
266 bindMethod("closeWebInspector", &TestRunner::closeWebInspector);
267 bindMethod("evaluateInWebInspector", &TestRunner::evaluateInWebInspector);
268 bindMethod("clearAllDatabases", &TestRunner::clearAllDatabases);
269 bindMethod("setDatabaseQuota", &TestRunner::setDatabaseQuota);
270 bindMethod("setAlwaysAcceptCookies", &TestRunner::setAlwaysAcceptCookies);
271 bindMethod("setWindowIsKey", &TestRunner::setWindowIsKey);
272 bindMethod("pathToLocalResource", &TestRunner::pathToLocalResource);
273 bindMethod("setBackingScaleFactor", &TestRunner::setBackingScaleFactor);
274 bindMethod("setPOSIXLocale", &TestRunner::setPOSIXLocale);
275 bindMethod("numberOfPendingGeolocationPermissionRequests", &TestRunner:: num berOfPendingGeolocationPermissionRequests);
276 bindMethod("setGeolocationPermission", &TestRunner::setGeolocationPermission );
277 bindMethod("setMockGeolocationPositionUnavailableError", &TestRunner::setMoc kGeolocationPositionUnavailableError);
278 bindMethod("setMockGeolocationPosition", &TestRunner::setMockGeolocationPosi tion);
279 bindMethod("setMIDIAccessorResult", &TestRunner::setMIDIAccessorResult);
280 bindMethod("setMIDISysExPermission", &TestRunner::setMIDISysExPermission);
281 bindMethod("grantWebNotificationPermission", &TestRunner::grantWebNotificati onPermission);
282 bindMethod("simulateLegacyWebNotificationClick", &TestRunner::simulateLegacy WebNotificationClick);
283 bindMethod("cancelAllActiveNotifications", &TestRunner::cancelAllActiveNotif ications);
284 bindMethod("addMockSpeechInputResult", &TestRunner::addMockSpeechInputResult );
285 bindMethod("setMockSpeechInputDumpRect", &TestRunner::setMockSpeechInputDump Rect);
286 bindMethod("addMockSpeechRecognitionResult", &TestRunner::addMockSpeechRecog nitionResult);
287 bindMethod("setMockSpeechRecognitionError", &TestRunner::setMockSpeechRecogn itionError);
288 bindMethod("wasMockSpeechRecognitionAborted", &TestRunner::wasMockSpeechReco gnitionAborted);
289 bindMethod("display", &TestRunner::display);
290 bindMethod("displayInvalidatedRegion", &TestRunner::displayInvalidatedRegion );
291 bindMethod("isChooserShown", &TestRunner::isChooserShown);
292
293 // The following modify WebPageOverlays.
294 bindMethod("addWebPageOverlay", &TestRunner::addWebPageOverlay);
295 bindMethod("removeWebPageOverlay", &TestRunner::removeWebPageOverlay);
296
297 // Properties.
298 bindProperty("globalFlag", &m_globalFlag);
299 bindProperty("platformName", &m_platformName);
300 bindProperty("tooltipText", &m_tooltipText);
301 bindProperty("disableNotifyDone", &m_disableNotifyDone);
302
303 // webHistoryItemCount is used by tests in LayoutTests\http\tests\history
304 bindProperty("webHistoryItemCount", &m_webHistoryItemCount);
305 bindProperty("interceptPostMessage", &m_interceptPostMessage);
306
307 // The following are stubs.
308 bindMethod("dumpDatabaseCallbacks", &TestRunner::notImplemented);
309 bindMethod("denyWebNotificationPermission", &TestRunner::notImplemented);
310 bindMethod("removeAllWebNotificationPermissions", &TestRunner::notImplemente d);
311 bindMethod("simulateWebNotificationClick", &TestRunner::notImplemented);
312 bindMethod("setIconDatabaseEnabled", &TestRunner::notImplemented);
313 bindMethod("setScrollbarPolicy", &TestRunner::notImplemented);
314 bindMethod("clearAllApplicationCaches", &TestRunner::notImplemented);
315 bindMethod("clearApplicationCacheForOrigin", &TestRunner::notImplemented);
316 bindMethod("clearBackForwardList", &TestRunner::notImplemented);
317 bindMethod("keepWebHistory", &TestRunner::notImplemented);
318 bindMethod("setApplicationCacheOriginQuota", &TestRunner::notImplemented);
319 bindMethod("setCallCloseOnWebViews", &TestRunner::notImplemented);
320 bindMethod("setMainFrameIsFirstResponder", &TestRunner::notImplemented);
321 bindMethod("setUseDashboardCompatibilityMode", &TestRunner::notImplemented);
322 bindMethod("deleteAllLocalStorage", &TestRunner::notImplemented);
323 bindMethod("localStorageDiskUsageForOrigin", &TestRunner::notImplemented);
324 bindMethod("originsWithLocalStorage", &TestRunner::notImplemented);
325 bindMethod("deleteLocalStorageForOrigin", &TestRunner::notImplemented);
326 bindMethod("observeStorageTrackerNotifications", &TestRunner::notImplemented );
327 bindMethod("syncLocalStorage", &TestRunner::notImplemented);
328 bindMethod("addDisallowedURL", &TestRunner::notImplemented);
329 bindMethod("applicationCacheDiskUsageForOrigin", &TestRunner::notImplemented );
330 bindMethod("abortModal", &TestRunner::notImplemented);
331
332 // The fallback method is called when an unknown method is invoked.
333 bindFallbackMethod(&TestRunner::fallbackMethod);
334 }
335
336 TestRunner::~TestRunner()
337 {
338 }
339
340 void TestRunner::setDelegate(WebTestDelegate* delegate)
341 {
342 m_delegate = delegate;
343 m_webPermissions->setDelegate(delegate);
344 m_notificationPresenter->setDelegate(delegate);
345 }
346
347 void TestRunner::setWebView(WebView* webView, WebTestProxyBase* proxy)
348 {
349 m_webView = webView;
350 m_proxy = proxy;
351 }
352
353 void TestRunner::reset()
354 {
355 if (m_webView) {
356 m_webView->setZoomLevel(0);
357 m_webView->setTextZoomFactor(1);
358 m_webView->setTabKeyCyclesThroughElements(true);
359 #if !defined(__APPLE__) && !defined(WIN32) // Actually, TOOLKIT_GTK
360 // (Constants copied because we can't depend on the header that defined
361 // them from this file.)
362 m_webView->setSelectionColors(0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff32 3232);
363 #endif
364 m_webView->removeInjectedStyleSheets();
365 m_webView->setVisibilityState(WebPageVisibilityStateVisible, true);
366 m_webView->mainFrame()->enableViewSourceMode(false);
367
368 if (m_pageOverlay) {
369 m_webView->removePageOverlay(m_pageOverlay);
370 delete m_pageOverlay;
371 m_pageOverlay = 0;
372 }
373 }
374
375 m_topLoadingFrame = 0;
376 m_waitUntilDone = false;
377 m_policyDelegateEnabled = false;
378 m_policyDelegateIsPermissive = false;
379 m_policyDelegateShouldNotifyDone = false;
380
381 WebSecurityPolicy::resetOriginAccessWhitelists();
382 #if defined(__linux__) || defined(ANDROID)
383 WebFontRendering::setSubpixelPositioning(false);
384 #endif
385
386 if (m_delegate) {
387 // Reset the default quota for each origin to 5MB
388 m_delegate->setDatabaseQuota(5 * 1024 * 1024);
389 m_delegate->setDeviceScaleFactor(1);
390 m_delegate->setAcceptAllCookies(false);
391 m_delegate->setLocale("");
392 m_delegate->useUnfortunateSynchronousResizeMode(false);
393 m_delegate->disableAutoResizeMode(WebSize());
394 m_delegate->deleteAllCookies();
395 }
396
397 m_dumpEditingCallbacks = false;
398 m_dumpAsText = false;
399 m_dumpAsMarkup = false;
400 m_generatePixelResults = true;
401 m_dumpChildFrameScrollPositions = false;
402 m_dumpChildFramesAsText = false;
403 m_dumpIconChanges = false;
404 m_dumpAsAudio = false;
405 m_dumpFrameLoadCallbacks = false;
406 m_dumpPingLoaderCallbacks = false;
407 m_dumpUserGestureInFrameLoadCallbacks = false;
408 m_dumpTitleChanges = false;
409 m_dumpCreateView = false;
410 m_canOpenWindows = false;
411 m_dumpResourceLoadCallbacks = false;
412 m_dumpResourceRequestCallbacks = false;
413 m_dumpResourceResponseMIMETypes = false;
414 m_dumpWindowStatusChanges = false;
415 m_dumpProgressFinishedCallback = false;
416 m_dumpSpellCheckCallbacks = false;
417 m_dumpBackForwardList = false;
418 m_dumpSelectionRect = false;
419 m_testRepaint = false;
420 m_sweepHorizontally = false;
421 m_isPrinting = false;
422 m_midiAccessorResult = true;
423 m_shouldStayOnPageAfterHandlingBeforeUnload = false;
424 m_shouldDumpResourcePriorities = false;
425
426 m_httpHeadersToClear.clear();
427
428 m_globalFlag.set(false);
429 m_webHistoryItemCount.set(0);
430 m_interceptPostMessage.set(false);
431 m_platformName.set("chromium");
432 m_tooltipText.set("");
433 m_disableNotifyDone.set(false);
434
435 m_webPermissions->reset();
436
437 m_notificationPresenter->reset();
438
439 m_pointerLocked = false;
440 m_pointerLockPlannedResult = PointerLockWillSucceed;
441
442 m_taskList.revokeAll();
443 m_workQueue.reset();
444
445 if (m_closeRemainingWindows && m_delegate)
446 m_delegate->closeRemainingWindows();
447 else
448 m_closeRemainingWindows = true;
449 }
450
451
452 void TestRunner::setTestIsRunning(bool running)
453 {
454 m_testIsRunning = running;
455 }
456
457 bool TestRunner::shouldDumpEditingCallbacks() const
458 {
459 return m_dumpEditingCallbacks;
460 }
461
462 void TestRunner::checkResponseMimeType()
463 {
464 // Text output: the test page can request different types of output
465 // which we handle here.
466 if (!m_dumpAsText) {
467 string mimeType = m_webView->mainFrame()->dataSource()->response().mimeT ype().utf8();
468 if (mimeType == "text/plain") {
469 m_dumpAsText = true;
470 m_generatePixelResults = false;
471 }
472 }
473 }
474
475 bool TestRunner::shouldDumpAsText()
476 {
477 checkResponseMimeType();
478 return m_dumpAsText;
479 }
480
481 void TestRunner::setShouldDumpAsText(bool value)
482 {
483 m_dumpAsText = value;
484 }
485
486 bool TestRunner::shouldDumpAsMarkup()
487 {
488 return m_dumpAsMarkup;
489 }
490
491 void TestRunner::setShouldDumpAsMarkup(bool value)
492 {
493 m_dumpAsMarkup = value;
494 }
495
496 bool TestRunner::shouldGeneratePixelResults()
497 {
498 checkResponseMimeType();
499 return m_generatePixelResults;
500 }
501
502 void TestRunner::setShouldGeneratePixelResults(bool value)
503 {
504 m_generatePixelResults = value;
505 }
506
507 bool TestRunner::shouldDumpChildFrameScrollPositions() const
508 {
509 return m_dumpChildFrameScrollPositions;
510 }
511
512 bool TestRunner::shouldDumpChildFramesAsText() const
513 {
514 return m_dumpChildFramesAsText;
515 }
516
517 bool TestRunner::shouldDumpAsAudio() const
518 {
519 return m_dumpAsAudio;
520 }
521
522 const WebArrayBufferView* TestRunner::audioData() const
523 {
524 return &m_audioData;
525 }
526
527 bool TestRunner::shouldDumpFrameLoadCallbacks() const
528 {
529 return m_testIsRunning && m_dumpFrameLoadCallbacks;
530 }
531
532 void TestRunner::setShouldDumpFrameLoadCallbacks(bool value)
533 {
534 m_dumpFrameLoadCallbacks = value;
535 }
536
537 bool TestRunner::shouldDumpPingLoaderCallbacks() const
538 {
539 return m_testIsRunning && m_dumpPingLoaderCallbacks;
540 }
541
542 void TestRunner::setShouldDumpPingLoaderCallbacks(bool value)
543 {
544 m_dumpPingLoaderCallbacks = value;
545 }
546
547 void TestRunner::setShouldEnableViewSource(bool value)
548 {
549 m_webView->mainFrame()->enableViewSourceMode(value);
550 }
551
552 bool TestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const
553 {
554 return m_testIsRunning && m_dumpUserGestureInFrameLoadCallbacks;
555 }
556
557 bool TestRunner::shouldDumpTitleChanges() const
558 {
559 return m_dumpTitleChanges;
560 }
561
562 bool TestRunner::shouldDumpIconChanges() const
563 {
564 return m_dumpIconChanges;
565 }
566
567 bool TestRunner::shouldDumpCreateView() const
568 {
569 return m_dumpCreateView;
570 }
571
572 bool TestRunner::canOpenWindows() const
573 {
574 return m_canOpenWindows;
575 }
576
577 bool TestRunner::shouldDumpResourceLoadCallbacks() const
578 {
579 return m_testIsRunning && m_dumpResourceLoadCallbacks;
580 }
581
582 bool TestRunner::shouldDumpResourceRequestCallbacks() const
583 {
584 return m_testIsRunning && m_dumpResourceRequestCallbacks;
585 }
586
587 bool TestRunner::shouldDumpResourceResponseMIMETypes() const
588 {
589 return m_testIsRunning && m_dumpResourceResponseMIMETypes;
590 }
591
592 WebPermissionClient* TestRunner::webPermissions() const
593 {
594 return m_webPermissions.get();
595 }
596
597 bool TestRunner::shouldDumpStatusCallbacks() const
598 {
599 return m_dumpWindowStatusChanges;
600 }
601
602 bool TestRunner::shouldDumpProgressFinishedCallback() const
603 {
604 return m_dumpProgressFinishedCallback;
605 }
606
607 bool TestRunner::shouldDumpSpellCheckCallbacks() const
608 {
609 return m_dumpSpellCheckCallbacks;
610 }
611
612 bool TestRunner::shouldDumpBackForwardList() const
613 {
614 return m_dumpBackForwardList;
615 }
616
617 bool TestRunner::shouldDumpSelectionRect() const
618 {
619 return m_dumpSelectionRect;
620 }
621
622 bool TestRunner::testRepaint() const
623 {
624 return m_testRepaint;
625 }
626
627 bool TestRunner::sweepHorizontally() const
628 {
629 return m_sweepHorizontally;
630 }
631
632 bool TestRunner::isPrinting() const
633 {
634 return m_isPrinting;
635 }
636
637 bool TestRunner::shouldStayOnPageAfterHandlingBeforeUnload() const
638 {
639 return m_shouldStayOnPageAfterHandlingBeforeUnload;
640 }
641
642 const std::set<std::string>* TestRunner::httpHeadersToClear() const
643 {
644 return &m_httpHeadersToClear;
645 }
646
647 void TestRunner::setTopLoadingFrame(WebFrame* frame, bool clear)
648 {
649 if (frame->top()->view() != m_webView)
650 return;
651 if (!m_testIsRunning)
652 return;
653 if (clear) {
654 m_topLoadingFrame = 0;
655 locationChangeDone();
656 } else if (!m_topLoadingFrame)
657 m_topLoadingFrame = frame;
658 }
659
660 WebFrame* TestRunner::topLoadingFrame() const
661 {
662 return m_topLoadingFrame;
663 }
664
665 void TestRunner::policyDelegateDone()
666 {
667 BLINK_ASSERT(m_waitUntilDone);
668 m_delegate->testFinished();
669 m_waitUntilDone = false;
670 }
671
672 bool TestRunner::policyDelegateEnabled() const
673 {
674 return m_policyDelegateEnabled;
675 }
676
677 bool TestRunner::policyDelegateIsPermissive() const
678 {
679 return m_policyDelegateIsPermissive;
680 }
681
682 bool TestRunner::policyDelegateShouldNotifyDone() const
683 {
684 return m_policyDelegateShouldNotifyDone;
685 }
686
687 bool TestRunner::shouldInterceptPostMessage() const
688 {
689 return m_interceptPostMessage.isBool() && m_interceptPostMessage.toBoolean() ;
690 }
691
692 bool TestRunner::shouldDumpResourcePriorities() const
693 {
694 return m_shouldDumpResourcePriorities;
695 }
696
697 WebNotificationPresenter* TestRunner::notificationPresenter() const
698 {
699 return m_notificationPresenter.get();
700 }
701
702 bool TestRunner::requestPointerLock()
703 {
704 switch (m_pointerLockPlannedResult) {
705 case PointerLockWillSucceed:
706 m_delegate->postDelayedTask(new HostMethodTask(this, &TestRunner::didAcq uirePointerLockInternal), 0);
707 return true;
708 case PointerLockWillRespondAsync:
709 BLINK_ASSERT(!m_pointerLocked);
710 return true;
711 case PointerLockWillFailSync:
712 BLINK_ASSERT(!m_pointerLocked);
713 return false;
714 default:
715 BLINK_ASSERT_NOT_REACHED();
716 return false;
717 }
718 }
719
720 void TestRunner::requestPointerUnlock()
721 {
722 m_delegate->postDelayedTask(new HostMethodTask(this, &TestRunner::didLosePoi nterLockInternal), 0);
723 }
724
725 bool TestRunner::isPointerLocked()
726 {
727 return m_pointerLocked;
728 }
729
730 void TestRunner::setToolTipText(const blink::WebString& text)
731 {
732 m_tooltipText.set(text.utf8());
733 }
734
735 bool TestRunner::midiAccessorResult()
736 {
737 return m_midiAccessorResult;
738 }
739
740 TestRunner::TestPageOverlay::TestPageOverlay(blink::WebView* webView) : m_webVie w(webView)
741 {
742 }
743
744 TestRunner::TestPageOverlay::~TestPageOverlay()
745 {
746 }
747
748 void TestRunner::TestPageOverlay::paintPageOverlay(blink::WebCanvas* canvas)
749 {
750 SkRect rect = SkRect::MakeWH(m_webView->size().width, m_webView->size().heig ht);
751 SkPaint paint;
752 paint.setColor(SK_ColorCYAN);
753 paint.setStyle(SkPaint::kFill_Style);
754 canvas->drawRect(rect, paint);
755 }
756
757 void TestRunner::didAcquirePointerLockInternal()
758 {
759 m_pointerLocked = true;
760 m_webView->didAcquirePointerLock();
761
762 // Reset planned result to default.
763 m_pointerLockPlannedResult = PointerLockWillSucceed;
764 }
765
766 void TestRunner::didNotAcquirePointerLockInternal()
767 {
768 BLINK_ASSERT(!m_pointerLocked);
769 m_pointerLocked = false;
770 m_webView->didNotAcquirePointerLock();
771
772 // Reset planned result to default.
773 m_pointerLockPlannedResult = PointerLockWillSucceed;
774 }
775
776 void TestRunner::didLosePointerLockInternal()
777 {
778 bool wasLocked = m_pointerLocked;
779 m_pointerLocked = false;
780 if (wasLocked)
781 m_webView->didLosePointerLock();
782 }
783
784 void TestRunner::showDevTools()
785 {
786 m_delegate->showDevTools();
787 }
788
789 void TestRunner::waitUntilDone(const CppArgumentList&, CppVariant* result)
790 {
791 m_waitUntilDone = true;
792 result->setNull();
793 }
794
795 void TestRunner::notifyDone(const CppArgumentList&, CppVariant* result)
796 {
797 if (m_disableNotifyDone.toBoolean())
798 return;
799
800 // Test didn't timeout. Kill the timeout timer.
801 taskList()->revokeAll();
802
803 completeNotifyDone();
804 result->setNull();
805 }
806
807 void TestRunner::completeNotifyDone()
808 {
809 if (m_waitUntilDone && !topLoadingFrame() && m_workQueue.isEmpty())
810 m_delegate->testFinished();
811 m_waitUntilDone = false;
812 }
813
814 class WorkItemBackForward : public TestRunner::WorkItem {
815 public:
816 WorkItemBackForward(int distance) : m_distance(distance) { }
817 bool run(WebTestDelegate* delegate, WebView*)
818 {
819 delegate->goToOffset(m_distance);
820 return true; // FIXME: Did it really start a navigation?
821 }
822
823 private:
824 int m_distance;
825 };
826
827 void TestRunner::queueBackNavigation(const CppArgumentList& arguments, CppVarian t* result)
828 {
829 if (arguments.size() > 0 && arguments[0].isNumber())
830 m_workQueue.addWork(new WorkItemBackForward(-arguments[0].toInt32()));
831 result->setNull();
832 }
833
834 void TestRunner::queueForwardNavigation(const CppArgumentList& arguments, CppVar iant* result)
835 {
836 if (arguments.size() > 0 && arguments[0].isNumber())
837 m_workQueue.addWork(new WorkItemBackForward(arguments[0].toInt32()));
838 result->setNull();
839 }
840
841 class WorkItemReload : public TestRunner::WorkItem {
842 public:
843 bool run(WebTestDelegate* delegate, WebView*)
844 {
845 delegate->reload();
846 return true;
847 }
848 };
849
850 void TestRunner::queueReload(const CppArgumentList&, CppVariant* result)
851 {
852 m_workQueue.addWork(new WorkItemReload);
853 result->setNull();
854 }
855
856 class WorkItemLoadingScript : public TestRunner::WorkItem {
857 public:
858 WorkItemLoadingScript(const string& script) : m_script(script) { }
859 bool run(WebTestDelegate*, WebView* webView)
860 {
861 webView->mainFrame()->executeScript(WebScriptSource(WebString::fromUTF8( m_script)));
862 return true; // FIXME: Did it really start a navigation?
863 }
864
865 private:
866 string m_script;
867 };
868
869 class WorkItemNonLoadingScript : public TestRunner::WorkItem {
870 public:
871 WorkItemNonLoadingScript(const string& script) : m_script(script) { }
872 bool run(WebTestDelegate*, WebView* webView)
873 {
874 webView->mainFrame()->executeScript(WebScriptSource(WebString::fromUTF8( m_script)));
875 return false;
876 }
877
878 private:
879 string m_script;
880 };
881
882 void TestRunner::queueLoadingScript(const CppArgumentList& arguments, CppVariant * result)
883 {
884 if (arguments.size() > 0 && arguments[0].isString())
885 m_workQueue.addWork(new WorkItemLoadingScript(arguments[0].toString()));
886 result->setNull();
887 }
888
889 void TestRunner::queueNonLoadingScript(const CppArgumentList& arguments, CppVari ant* result)
890 {
891 if (arguments.size() > 0 && arguments[0].isString())
892 m_workQueue.addWork(new WorkItemNonLoadingScript(arguments[0].toString() ));
893 result->setNull();
894 }
895
896 class WorkItemLoad : public TestRunner::WorkItem {
897 public:
898 WorkItemLoad(const WebURL& url, const string& target)
899 : m_url(url)
900 , m_target(target) { }
901 bool run(WebTestDelegate* delegate, WebView*)
902 {
903 delegate->loadURLForFrame(m_url, m_target);
904 return true; // FIXME: Did it really start a navigation?
905 }
906
907 private:
908 WebURL m_url;
909 string m_target;
910 };
911
912 void TestRunner::queueLoad(const CppArgumentList& arguments, CppVariant* result)
913 {
914 if (arguments.size() > 0 && arguments[0].isString()) {
915 // FIXME: Implement WebURL::resolve() and avoid GURL.
916 GURL currentURL = m_webView->mainFrame()->document().url();
917 GURL fullURL = currentURL.Resolve(arguments[0].toString());
918
919 string target = "";
920 if (arguments.size() > 1 && arguments[1].isString())
921 target = arguments[1].toString();
922
923 m_workQueue.addWork(new WorkItemLoad(fullURL, target));
924 }
925 result->setNull();
926 }
927
928 class WorkItemLoadHTMLString : public TestRunner::WorkItem {
929 public:
930 WorkItemLoadHTMLString(const std::string& html, const WebURL& baseURL)
931 : m_html(html)
932 , m_baseURL(baseURL) { }
933 WorkItemLoadHTMLString(const std::string& html, const WebURL& baseURL, const WebURL& unreachableURL)
934 : m_html(html)
935 , m_baseURL(baseURL)
936 , m_unreachableURL(unreachableURL) { }
937 bool run(WebTestDelegate*, WebView* webView)
938 {
939 webView->mainFrame()->loadHTMLString(
940 blink::WebData(m_html.data(), m_html.length()), m_baseURL, m_unreach ableURL);
941 return true;
942 }
943
944 private:
945 std::string m_html;
946 WebURL m_baseURL;
947 WebURL m_unreachableURL;
948 };
949
950 void TestRunner::queueLoadHTMLString(const CppArgumentList& arguments, CppVarian t* result)
951 {
952 if (arguments.size() > 0 && arguments[0].isString()) {
953 string html = arguments[0].toString();
954 WebURL baseURL(GURL(""));
955 if (arguments.size() > 1 && arguments[1].isString())
956 baseURL = WebURL(GURL(arguments[1].toString()));
957 if (arguments.size() > 2 && arguments[2].isString())
958 m_workQueue.addWork(new WorkItemLoadHTMLString(html, baseURL, WebURL (GURL(arguments[2].toString()))));
959 else
960 m_workQueue.addWork(new WorkItemLoadHTMLString(html, baseURL));
961 }
962 result->setNull();
963 }
964
965 void TestRunner::locationChangeDone()
966 {
967 m_webHistoryItemCount.set(m_delegate->navigationEntryCount());
968
969 // No more new work after the first complete load.
970 m_workQueue.setFrozen(true);
971
972 if (!m_waitUntilDone)
973 m_workQueue.processWorkSoon();
974 }
975
976 void TestRunner::windowCount(const CppArgumentList&, CppVariant* result)
977 {
978 result->set(static_cast<int>(m_testInterfaces->windowList().size()));
979 }
980
981 void TestRunner::setCloseRemainingWindowsWhenComplete(const CppArgumentList& arg uments, CppVariant* result)
982 {
983 if (arguments.size() > 0 && arguments[0].isBool())
984 m_closeRemainingWindows = arguments[0].value.boolValue;
985 result->setNull();
986 }
987
988 void TestRunner::resetTestHelperControllers(const CppArgumentList& arguments, Cp pVariant* result)
989 {
990 m_testInterfaces->resetTestHelperControllers();
991
992 result->setNull();
993 }
994
995 void TestRunner::setCustomPolicyDelegate(const CppArgumentList& arguments, CppVa riant* result)
996 {
997 if (arguments.size() > 0 && arguments[0].isBool()) {
998 m_policyDelegateEnabled = arguments[0].value.boolValue;
999 m_policyDelegateIsPermissive = false;
1000 if (arguments.size() > 1 && arguments[1].isBool())
1001 m_policyDelegateIsPermissive = arguments[1].value.boolValue;
1002 }
1003 result->setNull();
1004 }
1005
1006 void TestRunner::waitForPolicyDelegate(const CppArgumentList&, CppVariant* resul t)
1007 {
1008 m_policyDelegateEnabled = true;
1009 m_policyDelegateShouldNotifyDone = true;
1010 m_waitUntilDone = true;
1011 result->setNull();
1012 }
1013
1014 void TestRunner::dumpPermissionClientCallbacks(const CppArgumentList&, CppVarian t* result)
1015 {
1016 m_webPermissions->setDumpCallbacks(true);
1017 result->setNull();
1018 }
1019
1020 void TestRunner::setImagesAllowed(const CppArgumentList& arguments, CppVariant* result)
1021 {
1022 if (arguments.size() > 0 && arguments[0].isBool())
1023 m_webPermissions->setImagesAllowed(arguments[0].toBoolean());
1024 result->setNull();
1025 }
1026
1027 void TestRunner::setScriptsAllowed(const CppArgumentList& arguments, CppVariant* result)
1028 {
1029 if (arguments.size() > 0 && arguments[0].isBool())
1030 m_webPermissions->setScriptsAllowed(arguments[0].toBoolean());
1031 result->setNull();
1032 }
1033
1034 void TestRunner::setStorageAllowed(const CppArgumentList& arguments, CppVariant* result)
1035 {
1036 if (arguments.size() > 0 && arguments[0].isBool())
1037 m_webPermissions->setStorageAllowed(arguments[0].toBoolean());
1038 result->setNull();
1039 }
1040
1041 void TestRunner::setPluginsAllowed(const CppArgumentList& arguments, CppVariant* result)
1042 {
1043 if (arguments.size() > 0 && arguments[0].isBool())
1044 m_webPermissions->setPluginsAllowed(arguments[0].toBoolean());
1045 result->setNull();
1046 }
1047
1048 void TestRunner::setAllowDisplayOfInsecureContent(const CppArgumentList& argumen ts, CppVariant* result)
1049 {
1050 if (arguments.size() > 0 && arguments[0].isBool())
1051 m_webPermissions->setDisplayingInsecureContentAllowed(arguments[0].toBoo lean());
1052
1053 result->setNull();
1054 }
1055
1056 void TestRunner::setAllowRunningOfInsecureContent(const CppArgumentList& argumen ts, CppVariant* result)
1057 {
1058 if (arguments.size() > 0 && arguments[0].isBool())
1059 m_webPermissions->setRunningInsecureContentAllowed(arguments[0].value.bo olValue);
1060
1061 result->setNull();
1062 }
1063
1064 void TestRunner::dumpWindowStatusChanges(const CppArgumentList&, CppVariant* res ult)
1065 {
1066 m_dumpWindowStatusChanges = true;
1067 result->setNull();
1068 }
1069
1070 void TestRunner::dumpProgressFinishedCallback(const CppArgumentList&, CppVariant * result)
1071 {
1072 m_dumpProgressFinishedCallback = true;
1073 result->setNull();
1074 }
1075
1076 void TestRunner::dumpSpellCheckCallbacks(const CppArgumentList&, CppVariant* res ult)
1077 {
1078 m_dumpSpellCheckCallbacks = true;
1079 result->setNull();
1080 }
1081
1082 void TestRunner::dumpBackForwardList(const CppArgumentList&, CppVariant* result)
1083 {
1084 m_dumpBackForwardList = true;
1085 result->setNull();
1086 }
1087
1088 void TestRunner::dumpSelectionRect(const CppArgumentList& arguments, CppVariant* result)
1089 {
1090 m_dumpSelectionRect = true;
1091 result->setNull();
1092 }
1093
1094 void TestRunner::testRepaint(const CppArgumentList&, CppVariant* result)
1095 {
1096 m_testRepaint = true;
1097 result->setNull();
1098 }
1099
1100 void TestRunner::repaintSweepHorizontally(const CppArgumentList&, CppVariant* re sult)
1101 {
1102 m_sweepHorizontally = true;
1103 result->setNull();
1104 }
1105
1106 void TestRunner::setPrinting(const CppArgumentList& arguments, CppVariant* resul t)
1107 {
1108 m_isPrinting = true;
1109 result->setNull();
1110 }
1111
1112 void TestRunner::setShouldStayOnPageAfterHandlingBeforeUnload(const CppArgumentL ist& arguments, CppVariant* result)
1113 {
1114 if (arguments.size() == 1 && arguments[0].isBool())
1115 m_shouldStayOnPageAfterHandlingBeforeUnload = arguments[0].toBoolean();
1116
1117 result->setNull();
1118 }
1119
1120 void TestRunner::setWillSendRequestClearHeader(const CppArgumentList& arguments, CppVariant* result)
1121 {
1122 if (arguments.size() > 0 && arguments[0].isString()) {
1123 string header = arguments[0].toString();
1124 if (!header.empty())
1125 m_httpHeadersToClear.insert(header);
1126 }
1127 result->setNull();
1128 }
1129
1130 void TestRunner::setTabKeyCyclesThroughElements(const CppArgumentList& arguments , CppVariant* result)
1131 {
1132 if (arguments.size() > 0 && arguments[0].isBool())
1133 m_webView->setTabKeyCyclesThroughElements(arguments[0].toBoolean());
1134 result->setNull();
1135 }
1136
1137 void TestRunner::execCommand(const CppArgumentList& arguments, CppVariant* resul t)
1138 {
1139 result->setNull();
1140 if (arguments.size() <= 0 || !arguments[0].isString())
1141 return;
1142
1143 std::string command = arguments[0].toString();
1144 std::string value("");
1145 // Ignore the second parameter (which is userInterface)
1146 // since this command emulates a manual action.
1147 if (arguments.size() >= 3 && arguments[2].isString())
1148 value = arguments[2].toString();
1149
1150 // Note: webkit's version does not return the boolean, so neither do we.
1151 m_webView->focusedFrame()->executeCommand(WebString::fromUTF8(command), WebS tring::fromUTF8(value));
1152 }
1153
1154 void TestRunner::isCommandEnabled(const CppArgumentList& arguments, CppVariant* result)
1155 {
1156 if (arguments.size() <= 0 || !arguments[0].isString()) {
1157 result->setNull();
1158 return;
1159 }
1160
1161 std::string command = arguments[0].toString();
1162 bool rv = m_webView->focusedFrame()->isCommandEnabled(WebString::fromUTF8(co mmand));
1163 result->set(rv);
1164 }
1165
1166 void TestRunner::callShouldCloseOnWebView(const CppArgumentList&, CppVariant* re sult)
1167 {
1168 result->set(m_webView->dispatchBeforeUnloadEvent());
1169 }
1170
1171 void TestRunner::setDomainRelaxationForbiddenForURLScheme(const CppArgumentList& arguments, CppVariant* result)
1172 {
1173 if (arguments.size() != 2 || !arguments[0].isBool() || !arguments[1].isStrin g())
1174 return;
1175 m_webView->setDomainRelaxationForbidden(cppVariantToBool(arguments[0]), cppV ariantToWebString(arguments[1]));
1176 }
1177
1178 void TestRunner::evaluateScriptInIsolatedWorldAndReturnValue(const CppArgumentLi st& arguments, CppVariant* result)
1179 {
1180 v8::HandleScope scope(v8::Isolate::GetCurrent());
1181 WebVector<v8::Local<v8::Value> > values;
1182 if (arguments.size() >= 2 && arguments[0].isNumber() && arguments[1].isStrin g()) {
1183 WebScriptSource source(cppVariantToWebString(arguments[1]));
1184 // This relies on the iframe focusing itself when it loads. This is a bi t
1185 // sketchy, but it seems to be what other tests do.
1186 m_webView->focusedFrame()->executeScriptInIsolatedWorld(arguments[0].toI nt32(), &source, 1, 1, &values);
1187 }
1188 result->setNull();
1189 // Since only one script was added, only one result is expected
1190 if (values.size() == 1 && !values[0].IsEmpty()) {
1191 v8::Local<v8::Value> scriptValue = values[0];
1192 // FIXME: There are many more types that can be handled.
1193 if (scriptValue->IsString()) {
1194 v8::String::Utf8Value utf8V8(scriptValue);
1195 result->set(std::string(*utf8V8));
1196 } else if (scriptValue->IsBoolean())
1197 result->set(scriptValue->ToBoolean()->Value());
1198 else if (scriptValue->IsNumber()) {
1199 if (scriptValue->IsInt32())
1200 result->set(scriptValue->ToInt32()->Value());
1201 else
1202 result->set(scriptValue->ToNumber()->Value());
1203 } else if (scriptValue->IsNull())
1204 result->setNull();
1205 }
1206 }
1207
1208 void TestRunner::evaluateScriptInIsolatedWorld(const CppArgumentList& arguments, CppVariant* result)
1209 {
1210 if (arguments.size() >= 2 && arguments[0].isNumber() && arguments[1].isStrin g()) {
1211 WebScriptSource source(cppVariantToWebString(arguments[1]));
1212 // This relies on the iframe focusing itself when it loads. This is a bi t
1213 // sketchy, but it seems to be what other tests do.
1214 m_webView->focusedFrame()->executeScriptInIsolatedWorld(arguments[0].toI nt32(), &source, 1, 1);
1215 }
1216 result->setNull();
1217 }
1218
1219 void TestRunner::setIsolatedWorldSecurityOrigin(const CppArgumentList& arguments , CppVariant* result)
1220 {
1221 result->setNull();
1222
1223 if (arguments.size() != 2 || !arguments[0].isNumber() || !(arguments[1].isSt ring() || arguments[1].isNull()))
1224 return;
1225
1226 WebSecurityOrigin origin;
1227 if (arguments[1].isString())
1228 origin = WebSecurityOrigin::createFromString(cppVariantToWebString(argum ents[1]));
1229 m_webView->focusedFrame()->setIsolatedWorldSecurityOrigin(arguments[0].toInt 32(), origin);
1230 }
1231
1232 void TestRunner::setIsolatedWorldContentSecurityPolicy(const CppArgumentList& ar guments, CppVariant* result)
1233 {
1234 result->setNull();
1235
1236 if (arguments.size() != 2 || !arguments[0].isNumber() || !arguments[1].isStr ing())
1237 return;
1238
1239 m_webView->focusedFrame()->setIsolatedWorldContentSecurityPolicy(arguments[0 ].toInt32(), cppVariantToWebString(arguments[1]));
1240 }
1241
1242 void TestRunner::addOriginAccessWhitelistEntry(const CppArgumentList& arguments, CppVariant* result)
1243 {
1244 result->setNull();
1245
1246 if (arguments.size() != 4 || !arguments[0].isString() || !arguments[1].isStr ing()
1247 || !arguments[2].isString() || !arguments[3].isBool())
1248 return;
1249
1250 blink::WebURL url(GURL(arguments[0].toString()));
1251 if (!url.isValid())
1252 return;
1253
1254 WebSecurityPolicy::addOriginAccessWhitelistEntry(
1255 url,
1256 cppVariantToWebString(arguments[1]),
1257 cppVariantToWebString(arguments[2]),
1258 arguments[3].toBoolean());
1259 }
1260
1261 void TestRunner::removeOriginAccessWhitelistEntry(const CppArgumentList& argumen ts, CppVariant* result)
1262 {
1263 result->setNull();
1264
1265 if (arguments.size() != 4 || !arguments[0].isString() || !arguments[1].isStr ing()
1266 || !arguments[2].isString() || !arguments[3].isBool())
1267 return;
1268
1269 blink::WebURL url(GURL(arguments[0].toString()));
1270 if (!url.isValid())
1271 return;
1272
1273 WebSecurityPolicy::removeOriginAccessWhitelistEntry(
1274 url,
1275 cppVariantToWebString(arguments[1]),
1276 cppVariantToWebString(arguments[2]),
1277 arguments[3].toBoolean());
1278 }
1279
1280 void TestRunner::hasCustomPageSizeStyle(const CppArgumentList& arguments, CppVar iant* result)
1281 {
1282 result->set(false);
1283 int pageIndex = 0;
1284 if (arguments.size() > 1)
1285 return;
1286 if (arguments.size() == 1)
1287 pageIndex = cppVariantToInt32(arguments[0]);
1288 WebFrame* frame = m_webView->mainFrame();
1289 if (!frame)
1290 return;
1291 result->set(frame->hasCustomPageSizeStyle(pageIndex));
1292 }
1293
1294 void TestRunner::forceRedSelectionColors(const CppArgumentList& arguments, CppVa riant* result)
1295 {
1296 result->setNull();
1297 m_webView->setSelectionColors(0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0 );
1298 }
1299
1300 void TestRunner::injectStyleSheet(const CppArgumentList& arguments, CppVariant* result)
1301 {
1302 result->setNull();
1303 if (arguments.size() < 2 || !arguments[0].isString() || !arguments[1].isBool ())
1304 return;
1305 WebView::injectStyleSheet(
1306 cppVariantToWebString(arguments[0]), WebVector<WebString>(),
1307 arguments[1].toBoolean() ? WebView::InjectStyleInAllFrames : WebView::In jectStyleInTopFrameOnly);
1308 }
1309
1310 void TestRunner::startSpeechInput(const CppArgumentList& arguments, CppVariant* result)
1311 {
1312 result->setNull();
1313 if (arguments.size() != 1)
1314 return;
1315
1316 WebElement element;
1317 if (!WebBindings::getElement(arguments[0].value.objectValue, &element))
1318 return;
1319
1320 WebInputElement* input = toWebInputElement(&element);
1321 if (!input)
1322 return;
1323
1324 if (!input->isSpeechInputEnabled())
1325 return;
1326
1327 input->startSpeechInput();
1328 }
1329
1330 void TestRunner::findString(const CppArgumentList& arguments, CppVariant* result )
1331 {
1332 if (arguments.size() < 1 || !arguments[0].isString())
1333 return;
1334
1335 WebFindOptions findOptions;
1336 bool wrapAround = false;
1337 if (arguments.size() >= 2) {
1338 vector<string> optionsArray = arguments[1].toStringVector();
1339 findOptions.matchCase = true;
1340 findOptions.findNext = true;
1341
1342 for (size_t i = 0; i < optionsArray.size(); ++i) {
1343 const std::string& option = optionsArray[i];
1344 if (option == "CaseInsensitive")
1345 findOptions.matchCase = false;
1346 else if (option == "Backwards")
1347 findOptions.forward = false;
1348 else if (option == "StartInSelection")
1349 findOptions.findNext = false;
1350 else if (option == "AtWordStarts")
1351 findOptions.wordStart = true;
1352 else if (option == "TreatMedialCapitalAsWordStart")
1353 findOptions.medialCapitalAsWordStart = true;
1354 else if (option == "WrapAround")
1355 wrapAround = true;
1356 }
1357 }
1358
1359 WebFrame* frame = m_webView->mainFrame();
1360 const bool findResult = frame->find(0, cppVariantToWebString(arguments[0]), findOptions, wrapAround, 0);
1361 frame->stopFinding(false);
1362 result->set(findResult);
1363 }
1364
1365 void TestRunner::setValueForUser(const CppArgumentList& arguments, CppVariant* r esult)
1366 {
1367 result->setNull();
1368 if (arguments.size() != 2)
1369 return;
1370
1371 WebElement element;
1372 if (!WebBindings::getElement(arguments[0].value.objectValue, &element))
1373 return;
1374
1375 WebInputElement* input = toWebInputElement(&element);
1376 if (!input)
1377 return;
1378
1379 input->setValue(cppVariantToWebString(arguments[1]), true);
1380 }
1381
1382 void TestRunner::selectionAsMarkup(const CppArgumentList& arguments, CppVariant* result)
1383 {
1384 result->set(m_webView->mainFrame()->selectionAsMarkup().utf8());
1385 }
1386
1387 void TestRunner::setTextSubpixelPositioning(const CppArgumentList& arguments, Cp pVariant* result)
1388 {
1389 #if defined(__linux__) || defined(ANDROID)
1390 // Since FontConfig doesn't provide a variable to control subpixel positioni ng, we'll fall back
1391 // to setting it globally for all fonts.
1392 if (arguments.size() > 0 && arguments[0].isBool())
1393 WebFontRendering::setSubpixelPositioning(arguments[0].value.boolValue);
1394 #endif
1395 result->setNull();
1396 }
1397
1398 void TestRunner::setPageVisibility(const CppArgumentList& arguments, CppVariant* result)
1399 {
1400 if (arguments.size() > 0 && arguments[0].isString()) {
1401 string newVisibility = arguments[0].toString();
1402 if (newVisibility == "visible")
1403 m_webView->setVisibilityState(WebPageVisibilityStateVisible, false);
1404 else if (newVisibility == "hidden")
1405 m_webView->setVisibilityState(WebPageVisibilityStateHidden, false);
1406 else if (newVisibility == "prerender")
1407 m_webView->setVisibilityState(WebPageVisibilityStatePrerender, false );
1408 }
1409 }
1410
1411 void TestRunner::setTextDirection(const CppArgumentList& arguments, CppVariant* result)
1412 {
1413 result->setNull();
1414 if (arguments.size() != 1 || !arguments[0].isString())
1415 return;
1416
1417 // Map a direction name to a WebTextDirection value.
1418 std::string directionName = arguments[0].toString();
1419 blink::WebTextDirection direction;
1420 if (directionName == "auto")
1421 direction = blink::WebTextDirectionDefault;
1422 else if (directionName == "rtl")
1423 direction = blink::WebTextDirectionRightToLeft;
1424 else if (directionName == "ltr")
1425 direction = blink::WebTextDirectionLeftToRight;
1426 else
1427 return;
1428
1429 m_webView->setTextDirection(direction);
1430 }
1431
1432 void TestRunner::textSurroundingNode(const CppArgumentList& arguments, CppVarian t* result)
1433 {
1434 result->setNull();
1435 if (arguments.size() < 4 || !arguments[0].isObject() || !arguments[1].isNumb er() || !arguments[2].isNumber() || !arguments[3].isNumber())
1436 return;
1437
1438 WebNode node;
1439 if (!WebBindings::getNode(arguments[0].value.objectValue, &node))
1440 return;
1441
1442 if (node.isNull() || !node.isTextNode())
1443 return;
1444
1445 WebPoint point(arguments[1].toInt32(), arguments[2].toInt32());
1446 unsigned maxLength = arguments[3].toInt32();
1447
1448 WebSurroundingText surroundingText;
1449 surroundingText.initialize(node, point, maxLength);
1450 if (surroundingText.isNull())
1451 return;
1452
1453 result->set(surroundingText.textContent().utf8());
1454 }
1455
1456 void TestRunner::dumpResourceRequestPriorities(const CppArgumentList& arguments, CppVariant* result)
1457 {
1458 m_shouldDumpResourcePriorities = true;
1459 result->setNull();
1460 }
1461
1462 void TestRunner::useUnfortunateSynchronousResizeMode(const CppArgumentList& argu ments, CppVariant* result)
1463 {
1464 result->setNull();
1465 m_delegate->useUnfortunateSynchronousResizeMode(true);
1466 }
1467
1468 void TestRunner::enableAutoResizeMode(const CppArgumentList& arguments, CppVaria nt* result)
1469 {
1470 if (arguments.size() != 4) {
1471 result->set(false);
1472 return;
1473 }
1474 int minWidth = cppVariantToInt32(arguments[0]);
1475 int minHeight = cppVariantToInt32(arguments[1]);
1476 blink::WebSize minSize(minWidth, minHeight);
1477
1478 int maxWidth = cppVariantToInt32(arguments[2]);
1479 int maxHeight = cppVariantToInt32(arguments[3]);
1480 blink::WebSize maxSize(maxWidth, maxHeight);
1481
1482 m_delegate->enableAutoResizeMode(minSize, maxSize);
1483 result->set(true);
1484 }
1485
1486 void TestRunner::disableAutoResizeMode(const CppArgumentList& arguments, CppVari ant* result)
1487 {
1488 if (arguments.size() !=2) {
1489 result->set(false);
1490 return;
1491 }
1492 int newWidth = cppVariantToInt32(arguments[0]);
1493 int newHeight = cppVariantToInt32(arguments[1]);
1494 blink::WebSize newSize(newWidth, newHeight);
1495
1496 m_delegate->disableAutoResizeMode(newSize);
1497 result->set(true);
1498 }
1499
1500 void TestRunner::setMockDeviceMotion(const CppArgumentList& arguments, CppVarian t* result)
1501 {
1502 result->setNull();
1503 if (arguments.size() < 19
1504 || !arguments[0].isBool() || !arguments[1].isNumber() // acceleration.x
1505 || !arguments[2].isBool() || !arguments[3].isNumber() // acceleration.y
1506 || !arguments[4].isBool() || !arguments[5].isNumber() // acceleration.z
1507 || !arguments[6].isBool() || !arguments[7].isNumber() // accelerationInc ludingGravity.x
1508 || !arguments[8].isBool() || !arguments[9].isNumber() // accelerationInc ludingGravity.y
1509 || !arguments[10].isBool() || !arguments[11].isNumber() // accelerationI ncludingGravity.z
1510 || !arguments[12].isBool() || !arguments[13].isNumber() // rotationRate. alpha
1511 || !arguments[14].isBool() || !arguments[15].isNumber() // rotationRate. beta
1512 || !arguments[16].isBool() || !arguments[17].isNumber() // rotationRate. gamma
1513 || !arguments[18].isNumber()) // interval
1514 return;
1515
1516 WebDeviceMotionData motion;
1517
1518 // acceleration
1519 motion.hasAccelerationX = arguments[0].toBoolean();
1520 motion.accelerationX = arguments[1].toDouble();
1521 motion.hasAccelerationY = arguments[2].toBoolean();
1522 motion.accelerationY = arguments[3].toDouble();
1523 motion.hasAccelerationZ = arguments[4].toBoolean();
1524 motion.accelerationZ = arguments[5].toDouble();
1525
1526 // accelerationIncludingGravity
1527 motion.hasAccelerationIncludingGravityX = arguments[6].toBoolean();
1528 motion.accelerationIncludingGravityX = arguments[7].toDouble();
1529 motion.hasAccelerationIncludingGravityY = arguments[8].toBoolean();
1530 motion.accelerationIncludingGravityY = arguments[9].toDouble();
1531 motion.hasAccelerationIncludingGravityZ = arguments[10].toBoolean();
1532 motion.accelerationIncludingGravityZ = arguments[11].toDouble();
1533
1534 // rotationRate
1535 motion.hasRotationRateAlpha = arguments[12].toBoolean();
1536 motion.rotationRateAlpha = arguments[13].toDouble();
1537 motion.hasRotationRateBeta = arguments[14].toBoolean();
1538 motion.rotationRateBeta = arguments[15].toDouble();
1539 motion.hasRotationRateGamma = arguments[16].toBoolean();
1540 motion.rotationRateGamma = arguments[17].toDouble();
1541
1542 // interval
1543 motion.interval = arguments[18].toDouble();
1544
1545 m_delegate->setDeviceMotionData(motion);
1546 }
1547
1548 void TestRunner::setMockDeviceOrientation(const CppArgumentList& arguments, CppV ariant* result)
1549 {
1550 result->setNull();
1551 if (arguments.size() < 8
1552 || !arguments[0].isBool() || !arguments[1].isNumber() // alpha
1553 || !arguments[2].isBool() || !arguments[3].isNumber() // beta
1554 || !arguments[4].isBool() || !arguments[5].isNumber() // gamma
1555 || !arguments[6].isBool() || !arguments[7].isBool()) // absolute
1556 return;
1557
1558 WebDeviceOrientationData orientation;
1559
1560 // alpha
1561 orientation.hasAlpha = arguments[0].toBoolean();
1562 orientation.alpha = arguments[1].toDouble();
1563
1564 // beta
1565 orientation.hasBeta = arguments[2].toBoolean();
1566 orientation.beta = arguments[3].toDouble();
1567
1568 // gamma
1569 orientation.hasGamma = arguments[4].toBoolean();
1570 orientation.gamma = arguments[5].toDouble();
1571
1572 // absolute
1573 orientation.hasAbsolute = arguments[6].toBoolean();
1574 orientation.absolute = arguments[7].toBoolean();
1575
1576 m_delegate->setDeviceOrientationData(orientation);
1577 }
1578
1579 void TestRunner::setPopupBlockingEnabled(const CppArgumentList& arguments, CppVa riant* result)
1580 {
1581 if (arguments.size() > 0 && arguments[0].isBool()) {
1582 bool blockPopups = arguments[0].toBoolean();
1583 m_delegate->preferences()->javaScriptCanOpenWindowsAutomatically = !bloc kPopups;
1584 m_delegate->applyPreferences();
1585 }
1586 result->setNull();
1587 }
1588
1589 void TestRunner::setJavaScriptCanAccessClipboard(const CppArgumentList& argument s, CppVariant* result)
1590 {
1591 if (arguments.size() > 0 && arguments[0].isBool()) {
1592 m_delegate->preferences()->javaScriptCanAccessClipboard = arguments[0].v alue.boolValue;
1593 m_delegate->applyPreferences();
1594 }
1595 result->setNull();
1596 }
1597
1598 void TestRunner::setXSSAuditorEnabled(const CppArgumentList& arguments, CppVaria nt* result)
1599 {
1600 if (arguments.size() > 0 && arguments[0].isBool()) {
1601 m_delegate->preferences()->XSSAuditorEnabled = arguments[0].value.boolVa lue;
1602 m_delegate->applyPreferences();
1603 }
1604 result->setNull();
1605 }
1606
1607 void TestRunner::setAllowUniversalAccessFromFileURLs(const CppArgumentList& argu ments, CppVariant* result)
1608 {
1609 if (arguments.size() > 0 && arguments[0].isBool()) {
1610 m_delegate->preferences()->allowUniversalAccessFromFileURLs = arguments[ 0].value.boolValue;
1611 m_delegate->applyPreferences();
1612 }
1613 result->setNull();
1614 }
1615
1616 void TestRunner::setAllowFileAccessFromFileURLs(const CppArgumentList& arguments , CppVariant* result)
1617 {
1618 if (arguments.size() > 0 && arguments[0].isBool()) {
1619 m_delegate->preferences()->allowFileAccessFromFileURLs = arguments[0].va lue.boolValue;
1620 m_delegate->applyPreferences();
1621 }
1622 result->setNull();
1623 }
1624
1625 void TestRunner::overridePreference(const CppArgumentList& arguments, CppVariant * result)
1626 {
1627 result->setNull();
1628 if (arguments.size() != 2 || !arguments[0].isString())
1629 return;
1630
1631 string key = arguments[0].toString();
1632 CppVariant value = arguments[1];
1633 WebPreferences* prefs = m_delegate->preferences();
1634 if (key == "WebKitDefaultFontSize")
1635 prefs->defaultFontSize = cppVariantToInt32(value);
1636 else if (key == "WebKitMinimumFontSize")
1637 prefs->minimumFontSize = cppVariantToInt32(value);
1638 else if (key == "WebKitDefaultTextEncodingName")
1639 prefs->defaultTextEncodingName = cppVariantToWebString(value);
1640 else if (key == "WebKitJavaScriptEnabled")
1641 prefs->javaScriptEnabled = cppVariantToBool(value);
1642 else if (key == "WebKitSupportsMultipleWindows")
1643 prefs->supportsMultipleWindows = cppVariantToBool(value);
1644 else if (key == "WebKitDisplayImagesKey")
1645 prefs->loadsImagesAutomatically = cppVariantToBool(value);
1646 else if (key == "WebKitPluginsEnabled")
1647 prefs->pluginsEnabled = cppVariantToBool(value);
1648 else if (key == "WebKitJavaEnabled")
1649 prefs->javaEnabled = cppVariantToBool(value);
1650 else if (key == "WebKitOfflineWebApplicationCacheEnabled")
1651 prefs->offlineWebApplicationCacheEnabled = cppVariantToBool(value);
1652 else if (key == "WebKitTabToLinksPreferenceKey")
1653 prefs->tabsToLinks = cppVariantToBool(value);
1654 else if (key == "WebKitWebGLEnabled")
1655 prefs->experimentalWebGLEnabled = cppVariantToBool(value);
1656 else if (key == "WebKitCSSRegionsEnabled")
1657 prefs->experimentalCSSRegionsEnabled = cppVariantToBool(value);
1658 else if (key == "WebKitCSSGridLayoutEnabled")
1659 prefs->experimentalCSSGridLayoutEnabled = cppVariantToBool(value);
1660 else if (key == "WebKitHyperlinkAuditingEnabled")
1661 prefs->hyperlinkAuditingEnabled = cppVariantToBool(value);
1662 else if (key == "WebKitEnableCaretBrowsing")
1663 prefs->caretBrowsingEnabled = cppVariantToBool(value);
1664 else if (key == "WebKitAllowDisplayingInsecureContent")
1665 prefs->allowDisplayOfInsecureContent = cppVariantToBool(value);
1666 else if (key == "WebKitAllowRunningInsecureContent")
1667 prefs->allowRunningOfInsecureContent = cppVariantToBool(value);
1668 else if (key == "WebKitCSSCustomFilterEnabled")
1669 prefs->cssCustomFilterEnabled = cppVariantToBool(value);
1670 else if (key == "WebKitShouldRespectImageOrientation")
1671 prefs->shouldRespectImageOrientation = cppVariantToBool(value);
1672 else if (key == "WebKitWebAudioEnabled")
1673 BLINK_ASSERT(cppVariantToBool(value));
1674 else {
1675 string message("Invalid name for preference: ");
1676 message.append(key);
1677 printErrorMessage(message);
1678 }
1679 m_delegate->applyPreferences();
1680 }
1681
1682 void TestRunner::setPluginsEnabled(const CppArgumentList& arguments, CppVariant* result)
1683 {
1684 if (arguments.size() > 0 && arguments[0].isBool()) {
1685 m_delegate->preferences()->pluginsEnabled = arguments[0].toBoolean();
1686 m_delegate->applyPreferences();
1687 }
1688 result->setNull();
1689 }
1690
1691 void TestRunner::showWebInspector(const CppArgumentList&, CppVariant* result)
1692 {
1693 showDevTools();
1694 result->setNull();
1695 }
1696
1697 void TestRunner::closeWebInspector(const CppArgumentList& args, CppVariant* resu lt)
1698 {
1699 m_delegate->closeDevTools();
1700 result->setNull();
1701 }
1702
1703 void TestRunner::isChooserShown(const CppArgumentList&, CppVariant* result)
1704 {
1705 result->set(m_proxy->isChooserShown());
1706 }
1707
1708 void TestRunner::evaluateInWebInspector(const CppArgumentList& arguments, CppVar iant* result)
1709 {
1710 result->setNull();
1711 if (arguments.size() < 2 || !arguments[0].isNumber() || !arguments[1].isStri ng())
1712 return;
1713 m_delegate->evaluateInWebInspector(arguments[0].toInt32(), arguments[1].toSt ring());
1714 }
1715
1716 void TestRunner::clearAllDatabases(const CppArgumentList& arguments, CppVariant* result)
1717 {
1718 result->setNull();
1719 m_delegate->clearAllDatabases();
1720 }
1721
1722 void TestRunner::setDatabaseQuota(const CppArgumentList& arguments, CppVariant* result)
1723 {
1724 result->setNull();
1725 if ((arguments.size() >= 1) && arguments[0].isNumber())
1726 m_delegate->setDatabaseQuota(arguments[0].toInt32());
1727 }
1728
1729 void TestRunner::setAlwaysAcceptCookies(const CppArgumentList& arguments, CppVar iant* result)
1730 {
1731 if (arguments.size() > 0)
1732 m_delegate->setAcceptAllCookies(cppVariantToBool(arguments[0]));
1733 result->setNull();
1734 }
1735
1736 void TestRunner::setWindowIsKey(const CppArgumentList& arguments, CppVariant* re sult)
1737 {
1738 if (arguments.size() > 0 && arguments[0].isBool())
1739 m_delegate->setFocus(m_proxy, arguments[0].value.boolValue);
1740 result->setNull();
1741 }
1742
1743 void TestRunner::pathToLocalResource(const CppArgumentList& arguments, CppVarian t* result)
1744 {
1745 result->setNull();
1746 if (arguments.size() <= 0 || !arguments[0].isString())
1747 return;
1748
1749 result->set(m_delegate->pathToLocalResource(arguments[0].toString()));
1750 }
1751
1752 void TestRunner::setBackingScaleFactor(const CppArgumentList& arguments, CppVari ant* result)
1753 {
1754 if (arguments.size() < 2 || !arguments[0].isNumber() || !arguments[1].isObje ct())
1755 return;
1756
1757 float value = arguments[0].value.doubleValue;
1758 m_delegate->setDeviceScaleFactor(value);
1759 m_proxy->discardBackingStore();
1760
1761 WebScopedPtr<CppVariant> callbackArguments(new CppVariant());
1762 callbackArguments->set(arguments[1]);
1763 result->setNull();
1764 m_delegate->postTask(new InvokeCallbackTask(this, callbackArguments));
1765 }
1766
1767 void TestRunner::setPOSIXLocale(const CppArgumentList& arguments, CppVariant* re sult)
1768 {
1769 result->setNull();
1770 if (arguments.size() == 1 && arguments[0].isString())
1771 m_delegate->setLocale(arguments[0].toString());
1772 }
1773
1774 void TestRunner::numberOfPendingGeolocationPermissionRequests(const CppArgumentL ist& arguments, CppVariant* result)
1775 {
1776 result->set(m_proxy->geolocationClientMock()->numberOfPendingPermissionReque sts());
1777 }
1778
1779 // FIXME: For greater test flexibility, we should be able to set each page's geo location mock individually.
1780 // https://bugs.webkit.org/show_bug.cgi?id=52368
1781 void TestRunner::setGeolocationPermission(const CppArgumentList& arguments, CppV ariant* result)
1782 {
1783 result->setNull();
1784 if (arguments.size() < 1 || !arguments[0].isBool())
1785 return;
1786 const vector<WebTestProxyBase*>& windowList = m_testInterfaces->windowList() ;
1787 for (unsigned i = 0; i < windowList.size(); ++i)
1788 windowList.at(i)->geolocationClientMock()->setPermission(arguments[0].to Boolean());
1789 }
1790
1791 void TestRunner::setMockGeolocationPosition(const CppArgumentList& arguments, Cp pVariant* result)
1792 {
1793 result->setNull();
1794 if (arguments.size() < 3 || !arguments[0].isNumber() || !arguments[1].isNumb er() || !arguments[2].isNumber())
1795 return;
1796 const vector<WebTestProxyBase*>& windowList = m_testInterfaces->windowList() ;
1797 for (unsigned i = 0; i < windowList.size(); ++i)
1798 windowList.at(i)->geolocationClientMock()->setPosition(arguments[0].toDo uble(), arguments[1].toDouble(), arguments[2].toDouble());
1799 }
1800
1801 void TestRunner::setMockGeolocationPositionUnavailableError(const CppArgumentLis t& arguments, CppVariant* result)
1802 {
1803 result->setNull();
1804 if (arguments.size() != 1 || !arguments[0].isString())
1805 return;
1806 const vector<WebTestProxyBase*>& windowList = m_testInterfaces->windowList() ;
1807 for (unsigned i = 0; i < windowList.size(); ++i)
1808 windowList.at(i)->geolocationClientMock()->setPositionUnavailableError(W ebString::fromUTF8(arguments[0].toString()));
1809 }
1810
1811 void TestRunner::setMIDIAccessorResult(const CppArgumentList& arguments, CppVari ant* result)
1812 {
1813 result->setNull();
1814 if (arguments.size() < 1 || !arguments[0].isBool())
1815 return;
1816 m_midiAccessorResult = arguments[0].toBoolean();
1817 }
1818
1819 void TestRunner::setMIDISysExPermission(const CppArgumentList& arguments, CppVar iant* result)
1820 {
1821 result->setNull();
1822 if (arguments.size() < 1 || !arguments[0].isBool())
1823 return;
1824 const vector<WebTestProxyBase*>& windowList = m_testInterfaces->windowList() ;
1825 for (unsigned i = 0; i < windowList.size(); ++i)
1826 windowList.at(i)->midiClientMock()->setSysExPermission(arguments[0].toBo olean());
1827 }
1828
1829 void TestRunner::grantWebNotificationPermission(const CppArgumentList& arguments , CppVariant* result)
1830 {
1831 if (arguments.size() != 1 || !arguments[0].isString()) {
1832 result->set(false);
1833 return;
1834 }
1835 m_notificationPresenter->grantPermission(WebString::fromUTF8(arguments[0].to String()));
1836 result->set(true);
1837 }
1838
1839 void TestRunner::simulateLegacyWebNotificationClick(const CppArgumentList& argum ents, CppVariant* result)
1840 {
1841 if (arguments.size() != 1 || !arguments[0].isString()) {
1842 result->set(false);
1843 return;
1844 }
1845 result->set(m_notificationPresenter->simulateClick(WebString::fromUTF8(argum ents[0].toString())));
1846 }
1847
1848 void TestRunner::cancelAllActiveNotifications(const CppArgumentList& arguments, CppVariant* result)
1849 {
1850 m_notificationPresenter->cancelAllActiveNotifications();
1851 result->set(true);
1852 }
1853
1854 void TestRunner::addMockSpeechInputResult(const CppArgumentList& arguments, CppV ariant* result)
1855 {
1856 result->setNull();
1857 if (arguments.size() < 3 || !arguments[0].isString() || !arguments[1].isNumb er() || !arguments[2].isString())
1858 return;
1859
1860 #if ENABLE_INPUT_SPEECH
1861 m_proxy->speechInputControllerMock()->addMockRecognitionResult(WebString::fr omUTF8(arguments[0].toString()), arguments[1].toDouble(), WebString::fromUTF8(ar guments[2].toString()));
1862 #endif
1863 }
1864
1865 void TestRunner::setMockSpeechInputDumpRect(const CppArgumentList& arguments, Cp pVariant* result)
1866 {
1867 result->setNull();
1868 if (arguments.size() < 1 || !arguments[0].isBool())
1869 return;
1870
1871 #if ENABLE_INPUT_SPEECH
1872 m_proxy->speechInputControllerMock()->setDumpRect(arguments[0].toBoolean());
1873 #endif
1874 }
1875
1876 void TestRunner::addMockSpeechRecognitionResult(const CppArgumentList& arguments , CppVariant* result)
1877 {
1878 result->setNull();
1879 if (arguments.size() < 2 || !arguments[0].isString() || !arguments[1].isNumb er())
1880 return;
1881
1882 m_proxy->speechRecognizerMock()->addMockResult(WebString::fromUTF8(arguments [0].toString()), arguments[1].toDouble());
1883 }
1884
1885 void TestRunner::setMockSpeechRecognitionError(const CppArgumentList& arguments, CppVariant* result)
1886 {
1887 result->setNull();
1888 if (arguments.size() != 2 || !arguments[0].isString() || !arguments[1].isStr ing())
1889 return;
1890
1891 m_proxy->speechRecognizerMock()->setError(WebString::fromUTF8(arguments[0].t oString()), WebString::fromUTF8(arguments[1].toString()));
1892 }
1893
1894 void TestRunner::wasMockSpeechRecognitionAborted(const CppArgumentList&, CppVari ant* result)
1895 {
1896 result->set(m_proxy->speechRecognizerMock()->wasAborted());
1897 }
1898
1899 void TestRunner::addWebPageOverlay(const CppArgumentList&, CppVariant* result)
1900 {
1901 if (m_webView && !m_pageOverlay) {
1902 m_pageOverlay = new TestPageOverlay(m_webView);
1903 m_webView->addPageOverlay(m_pageOverlay, 0);
1904 }
1905 result->setNull();
1906 }
1907
1908 void TestRunner::removeWebPageOverlay(const CppArgumentList&, CppVariant* result )
1909 {
1910 if (m_webView && m_pageOverlay) {
1911 m_webView->removePageOverlay(m_pageOverlay);
1912 delete m_pageOverlay;
1913 m_pageOverlay = 0;
1914 }
1915
1916 result->setNull();
1917 }
1918
1919 void TestRunner::display(const CppArgumentList& arguments, CppVariant* result)
1920 {
1921 m_proxy->display();
1922 result->setNull();
1923 }
1924
1925 void TestRunner::displayInvalidatedRegion(const CppArgumentList& arguments, CppV ariant* result)
1926 {
1927 m_proxy->displayInvalidatedRegion();
1928 result->setNull();
1929 }
1930
1931 void TestRunner::dumpEditingCallbacks(const CppArgumentList&, CppVariant* result )
1932 {
1933 m_dumpEditingCallbacks = true;
1934 result->setNull();
1935 }
1936
1937 void TestRunner::dumpAsText(const CppArgumentList&, CppVariant* result)
1938 {
1939 m_dumpAsText = true;
1940 m_generatePixelResults = false;
1941
1942 result->setNull();
1943 }
1944
1945 void TestRunner::dumpAsTextWithPixelResults(const CppArgumentList&, CppVariant* result)
1946 {
1947 m_dumpAsText = true;
1948 m_generatePixelResults = true;
1949
1950 result->setNull();
1951 }
1952
1953 void TestRunner::dumpChildFrameScrollPositions(const CppArgumentList&, CppVarian t* result)
1954 {
1955 m_dumpChildFrameScrollPositions = true;
1956 result->setNull();
1957 }
1958
1959 void TestRunner::dumpChildFramesAsText(const CppArgumentList&, CppVariant* resul t)
1960 {
1961 m_dumpChildFramesAsText = true;
1962 result->setNull();
1963 }
1964
1965 void TestRunner::dumpIconChanges(const CppArgumentList&, CppVariant* result)
1966 {
1967 m_dumpIconChanges = true;
1968 result->setNull();
1969 }
1970
1971 void TestRunner::setAudioData(const CppArgumentList& arguments, CppVariant* resu lt)
1972 {
1973 result->setNull();
1974
1975 if (arguments.size() < 1 || !arguments[0].isObject())
1976 return;
1977
1978 // Check that passed-in object is, in fact, an ArrayBufferView.
1979 NPObject* npobject = NPVARIANT_TO_OBJECT(arguments[0]);
1980 if (!npobject)
1981 return;
1982 if (!WebBindings::getArrayBufferView(npobject, &m_audioData))
1983 return;
1984
1985 m_dumpAsAudio = true;
1986 }
1987
1988 void TestRunner::dumpFrameLoadCallbacks(const CppArgumentList&, CppVariant* resu lt)
1989 {
1990 m_dumpFrameLoadCallbacks = true;
1991 result->setNull();
1992 }
1993
1994 void TestRunner::dumpPingLoaderCallbacks(const CppArgumentList&, CppVariant* res ult)
1995 {
1996 m_dumpPingLoaderCallbacks = true;
1997 result->setNull();
1998 }
1999
2000 void TestRunner::dumpUserGestureInFrameLoadCallbacks(const CppArgumentList&, Cpp Variant* result)
2001 {
2002 m_dumpUserGestureInFrameLoadCallbacks = true;
2003 result->setNull();
2004 }
2005
2006 void TestRunner::dumpTitleChanges(const CppArgumentList&, CppVariant* result)
2007 {
2008 m_dumpTitleChanges = true;
2009 result->setNull();
2010 }
2011
2012 void TestRunner::dumpCreateView(const CppArgumentList&, CppVariant* result)
2013 {
2014 m_dumpCreateView = true;
2015 result->setNull();
2016 }
2017
2018 void TestRunner::setCanOpenWindows(const CppArgumentList&, CppVariant* result)
2019 {
2020 m_canOpenWindows = true;
2021 result->setNull();
2022 }
2023
2024 void TestRunner::dumpResourceLoadCallbacks(const CppArgumentList&, CppVariant* r esult)
2025 {
2026 m_dumpResourceLoadCallbacks = true;
2027 result->setNull();
2028 }
2029
2030 void TestRunner::dumpResourceRequestCallbacks(const CppArgumentList&, CppVariant * result)
2031 {
2032 m_dumpResourceRequestCallbacks = true;
2033 result->setNull();
2034 }
2035
2036 void TestRunner::dumpResourceResponseMIMETypes(const CppArgumentList&, CppVarian t* result)
2037 {
2038 m_dumpResourceResponseMIMETypes = true;
2039 result->setNull();
2040 }
2041
2042 // Need these conversions because the format of the value for booleans
2043 // may vary - for example, on mac "1" and "0" are used for boolean.
2044 bool TestRunner::cppVariantToBool(const CppVariant& value)
2045 {
2046 if (value.isBool())
2047 return value.toBoolean();
2048 if (value.isNumber())
2049 return value.toInt32() != 0;
2050 if (value.isString()) {
2051 string valueString = value.toString();
2052 if (valueString == "true" || valueString == "1")
2053 return true;
2054 if (valueString == "false" || valueString == "0")
2055 return false;
2056 }
2057 printErrorMessage("Invalid value. Expected boolean value.");
2058 return false;
2059 }
2060
2061 int32_t TestRunner::cppVariantToInt32(const CppVariant& value)
2062 {
2063 if (value.isNumber())
2064 return value.toInt32();
2065 if (value.isString()) {
2066 string stringSource = value.toString();
2067 const char* source = stringSource.data();
2068 char* end;
2069 long number = strtol(source, &end, 10);
2070 if (end == source + stringSource.length() && number >= numeric_limits<in t32_t>::min() && number <= numeric_limits<int32_t>::max())
2071 return static_cast<int32_t>(number);
2072 }
2073 printErrorMessage("Invalid value for preference. Expected integer value.");
2074 return 0;
2075 }
2076
2077 WebString TestRunner::cppVariantToWebString(const CppVariant& value)
2078 {
2079 if (!value.isString()) {
2080 printErrorMessage("Invalid value for preference. Expected string value." );
2081 return WebString();
2082 }
2083 return WebString::fromUTF8(value.toString());
2084 }
2085
2086 void TestRunner::printErrorMessage(const string& text)
2087 {
2088 m_delegate->printMessage(string("CONSOLE MESSAGE: ") + text + "\n");
2089 }
2090
2091 void TestRunner::fallbackMethod(const CppArgumentList&, CppVariant* result)
2092 {
2093 printErrorMessage("JavaScript ERROR: unknown method called on TestRunner");
2094 result->setNull();
2095 }
2096
2097 void TestRunner::notImplemented(const CppArgumentList&, CppVariant* result)
2098 {
2099 result->setNull();
2100 }
2101
2102 void TestRunner::didAcquirePointerLock(const CppArgumentList&, CppVariant* resul t)
2103 {
2104 didAcquirePointerLockInternal();
2105 result->setNull();
2106 }
2107
2108 void TestRunner::didNotAcquirePointerLock(const CppArgumentList&, CppVariant* re sult)
2109 {
2110 didNotAcquirePointerLockInternal();
2111 result->setNull();
2112 }
2113
2114 void TestRunner::didLosePointerLock(const CppArgumentList&, CppVariant* result)
2115 {
2116 didLosePointerLockInternal();
2117 result->setNull();
2118 }
2119
2120 void TestRunner::setPointerLockWillRespondAsynchronously(const CppArgumentList&, CppVariant* result)
2121 {
2122 m_pointerLockPlannedResult = PointerLockWillRespondAsync;
2123 result->setNull();
2124 }
2125
2126 void TestRunner::setPointerLockWillFailSynchronously(const CppArgumentList&, Cpp Variant* result)
2127 {
2128 m_pointerLockPlannedResult = PointerLockWillFailSync;
2129 result->setNull();
2130 }
2131
2132 }
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/TestRunner.h ('k') | content/shell/renderer/test_runner/TextInputController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698