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