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