Changeset 267761 in webkit
- Timestamp:
- Sep 29, 2020, 2:38:57 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 79 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/Source/JavaScriptCore/API/JSRetainPtr.h ¶
r236032 r267761 1 1 /* 2 * Copyright (C) 2005-20 18Apple Inc. All rights reserved.2 * Copyright (C) 2005-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 30 30 31 31 #include <JavaScriptCore/JSContextRef.h> 32 #include <JavaScriptCore/JSObjectRef.h> 32 33 #include <JavaScriptCore/JSStringRef.h> 33 34 #include <algorithm> 34 35 36 inline void JSRetain(JSClassRef context) { JSClassRetain(context); } 37 inline void JSRelease(JSClassRef context) { JSClassRelease(context); } 38 inline void JSRetain(JSGlobalContextRef context) { JSGlobalContextRetain(context); } 39 inline void JSRelease(JSGlobalContextRef context) { JSGlobalContextRelease(context); } 35 40 inline void JSRetain(JSStringRef string) { JSStringRetain(string); } 36 41 inline void JSRelease(JSStringRef string) { JSStringRelease(string); } 37 inline void JSRetain(JSGlobalContextRef context) { JSGlobalContextRetain(context); }38 inline void JSRelease(JSGlobalContextRef context) { JSGlobalContextRelease(context); }39 42 40 43 enum AdoptTag { Adopt }; … … 75 78 }; 76 79 80 JSRetainPtr<JSClassRef> adopt(JSClassRef); 77 81 JSRetainPtr<JSStringRef> adopt(JSStringRef); 78 82 JSRetainPtr<JSGlobalContextRef> adopt(JSGlobalContextRef); … … 81 85 : m_ptr(ptr) 82 86 { 87 } 88 89 inline JSRetainPtr<JSClassRef> adopt(JSClassRef o) 90 { 91 return JSRetainPtr<JSClassRef>(Adopt, o); 83 92 } 84 93 -
TabularUnified trunk/Source/JavaScriptCore/ChangeLog ¶
r267754 r267761 1 2020-09-26 Darin Adler <darin@apple.com> 2 3 Refactor test runner code to cut down on copy/paste code and long-winded repetitive idioms 4 https://bugs.webkit.org/show_bug.cgi?id=217028 5 6 Reviewed by Sam Weinig. 7 8 * API/JSRetainPtr.h: Added support for JSClassRef. 9 1 10 2020-09-29 Yusuke Suzuki <ysuzuki@apple.com> 2 11 -
TabularUnified trunk/Tools/ChangeLog ¶
r267757 r267761 1 2020-09-26 Darin Adler <darin@apple.com> 2 3 Refactor test runner code to cut down on copy/paste code and long-winded repetitive idioms 4 https://bugs.webkit.org/show_bug.cgi?id=217028 5 6 Reviewed by Sam Weinig. 7 8 I did a lot of simplifying, but even more is possible. For some reason, the test 9 code is a hotbed of repeated idioms, and copy and paste rather than helper functions. 10 Even after the refactoring, I have some doubts about the way this code is written with 11 so much repeated marshaling for each function. 12 13 * DumpRenderTree/AccessibilityController.cpp: 14 (AccessibilityController::makeWindowObject): Use setGlobalObjectProperty. 15 (AccessibilityController::createJSClass): Replaced getJSClass with this. Return a 16 JSRetainPtr to make it clear this passes ownership to the caller. 17 * DumpRenderTree/AccessibilityController.h: Updated for the above. 18 19 * DumpRenderTree/AccessibilityUIElement.cpp: 20 (uiElementCountForSearchPredicateCallback): Removed unneeded initialization of 21 JSRetainPtr, which starts out null. 22 23 * DumpRenderTree/Bindings/CodeGeneratorDumpRenderTree.pm: 24 (_platformTypeConstructor): Use toOptionalBool and createJSString. 25 (_returnExpression): Use makeValue. 26 27 * DumpRenderTree/GCController.cpp: 28 (GCController::GCController): Deleted. 29 (GCController::~GCController): Deleted. 30 (collectCallback): Use a reference and auto. 31 (collectOnAlternateThreadCallback): Ditto. 32 (getJSObjectCountCallback): Ditto. 33 (GCController::makeWindowObject): Use setGlobalObjectProperty. 34 (AccessibilityController::createJSClass): Replaced getJSClass with this. Return a 35 JSRetainPtr to make it clear this passes ownership to the caller. 36 * DumpRenderTree/GCController.h: Updated for the above. 37 38 * DumpRenderTree/TestRunner.cpp: 39 (encodeHostNameCallback): Use createJSString. 40 (execCommandCallback): Ditto. 41 (findStringCallback): Ditto. 42 (isCommandEnabledCallback): Ditto. 43 (overridePreferenceCallback): Ditto. 44 (queueLoadCallback): Ditto. 45 (queueLoadHTMLStringCallback): Ditto. 46 (TestRunner::makeWindowObject): Use setGlobalObjectProperty. 47 (TestRunner::createJSClass): Replaced getJSClass with this. Return a 48 JSRetainPtr to make it clear this passes ownership to the caller. 49 (TestRunner::staticValues): Made return value const*. 50 (TestRunner::staticFunctions): Ditto. 51 (TestRunner::waitToDumpWatchdogTimerFired): Simplified printing. 52 (TestRunner::cacheTestRunnerCallback): Updated to use object pointers as hash 53 table values instead of values, since callbacks need to be objects. 54 (TestRunner::callTestRunnerCallback): Ditto. 55 (TestRunner::clearTestRunnerCallbacks): Ditto. 56 (TestRunner::setOpenPanelFiles): Use arrayLength. 57 * DumpRenderTree/TestRunner.h: Updated for the above. 58 59 * DumpRenderTree/ios/AccessibilityControllerIOS.mm: 60 (AccessibilityController::platformName const): Use createJSString. 61 62 * DumpRenderTree/ios/AccessibilityUIElementIOS.mm: 63 (createEmptyJSString): Dleted. 64 (AccessibilityUIElement::stringForTextMarkerRange): Use createJSString. 65 (AccessibilityUIElement::attributesOfLinkedUIElements): Ditto. 66 (AccessibilityUIElement::attributesOfDocumentLinks): Ditto. 67 (AccessibilityUIElement::attributesOfChildren): Ditto. 68 (AccessibilityUIElement::allAttributes): Ditto. 69 (AccessibilityUIElement::stringAttributeValue): Ditto. 70 (AccessibilityUIElement::parameterizedAttributeNames): Ditto. 71 (AccessibilityUIElement::role): Ditto. 72 (AccessibilityUIElement::subrole): Ditto. 73 (AccessibilityUIElement::roleDescription): Ditto. 74 (AccessibilityUIElement::computedRoleString): Ditto. 75 (AccessibilityUIElement::title): Ditto. 76 (AccessibilityUIElement::orientation const): Ditto. 77 (AccessibilityUIElement::language): Ditto. 78 (AccessibilityUIElement::valueDescription): Ditto. 79 (AccessibilityUIElement::ariaDropEffects const): Ditto. 80 (AccessibilityUIElement::boundsForRange): Ditto. 81 (AccessibilityUIElement::attributesOfColumnHeaders): Ditto. 82 (AccessibilityUIElement::attributesOfRowHeaders): Ditto. 83 (AccessibilityUIElement::attributesOfColumns): Ditto. 84 (AccessibilityUIElement::attributesOfRows): Ditto. 85 (AccessibilityUIElement::attributesOfVisibleCells): Ditto. 86 (AccessibilityUIElement::attributesOfHeader): Ditto. 87 (AccessibilityUIElement::selectedTextRange): Ditto. 88 (AccessibilityUIElement::accessibilityValue const): Ditto. 89 (AccessibilityUIElement::documentEncoding): Ditto. 90 (AccessibilityUIElement::documentURI): Ditto. 91 92 * DumpRenderTree/mac/AccessibilityCommonMac.h: Removed unneeded "extern". 93 94 * DumpRenderTree/mac/AccessibilityCommonMac.mm: 95 (searchPredicateParameterizedAttributeForSearchCriteria): Use arrayLength. 96 Removed unneeded call to JSValueToObject after JSValueIsObject. 97 98 * DumpRenderTree/mac/AccessibilityControllerMac.mm: 99 (AccessibilityController::platformName const): Use createJSString. 100 101 * DumpRenderTree/mac/AccessibilityUIElementMac.mm: 102 (createEmptyJSString): Deleted. 103 (selectTextParameterizedAttributeForCriteria): Use arrayLength. 104 Removed unneeded call to JSValueToObject after JSValueIsObject. 105 (searchTextParameterizedAttributeForCriteria): Ditto. 106 (AccessibilityUIElement::accessibilityValue const): Use createJSString. 107 (AccessibilityUIElement::documentEncoding): Ditto. 108 (AccessibilityUIElement::documentURI): Ditto. 109 110 * DumpRenderTree/mac/FrameLoadDelegate.mm: 111 (-[FrameLoadDelegate didClearWindowObjectInStandardWorldForFrame:]): 112 Use auto. Pass fewer arguments to makeWindowObject. Simplified object 113 creation code by using adoptNS instead of release. 114 (-[FrameLoadDelegate didClearWindowObjectForFrame:inIsolatedWorld:]): 115 Use createJSString. 116 117 * DumpRenderTree/mac/TestRunnerMac.mm: 118 (TestRunner::findString): Use arrayLength. 119 120 * DumpRenderTree/win/FrameLoadDelegate.cpp: 121 (FrameLoadDelegate::didClearWindowObjectForFrameInStandardWorld): 122 Pass fewer arguments to makeWindowObject. 123 124 * DumpRenderTree/win/TextInputController.cpp: 125 (TextInputController::makeWindowObject): Use setGlobalObjectProperty. 126 (TextInputController::createJSClass): Replaced getJSClass with this. Return a 127 JSRetainPtr to make it clear this passes ownership to the caller. 128 (TextInputController::staticValues): Made return value const*. 129 (TextInputController::staticFunctions): Ditto. 130 * DumpRenderTree/win/TextInputController.h: Updated for above. 131 132 * TestRunnerShared/Bindings/JSBasics.cpp: 133 (WTR::toOptionalBool): Renamed from JSValueMakeBooleanOrNull. 134 (WTR::toOptionalDouble): Added. 135 (WTR::makeValue): Added with overloads for various types. 136 Replaced JSValueToNullableBoolean and JSValueMakeStringOrNull. 137 (WTR::createJSString): Added with overloads for various types. 138 (WTR::property): Added. 139 (WTR::stringProperty): Added. 140 (WTR::booleanProperty): Added. 141 (WTR::numericProperty): Added. 142 (WTR::objectProperty): Refactored to call property. 143 (WTR::arrayLength): Added. 144 (WTR::setGlobalObjectProperty): Added. 145 (WTR::call): Refactored to let objectProperty do more of the null checking. 146 (WTR::callConstructor): Ditto. 147 * TestRunnerShared/Bindings/JSBasics.h: Updated for the above. 148 149 * TestRunnerShared/Bindings/JSWrappable.h: Reduced includes a bit. 150 151 * TestRunnerShared/Bindings/JSWrapper.h: Added setGlobalObjectProperty. 152 153 * TestRunnerShared/UIScriptContext/UIScriptContext.cpp: 154 (UIScriptContext::UIScriptContext): Pass fewer arguments to makeWindowObject. 155 (UIScriptContext::runUIScript): Use createJSString. 156 (UIScriptContext::objectFromRect const): Use setProperty. 157 * TestRunnerShared/UIScriptContext/UIScriptController.h: Updated for the above. 158 159 * TestRunnerShared/UIScriptContext/UIScriptControllerShared.cpp: 160 (WTR::toDeviceOrientation): Use createJSString and JSStringIsEqualToUTF8CString. 161 (WTR::UIScriptController::makeWindowObject): Use setGlobalObjectProperty. 162 163 * TestRunnerShared/cocoa/LayoutTestSpellChecker.mm: 164 (-[LayoutTestSpellChecker setResultsFromJSValue:inContext:]): Use createJSString 165 and removed unneeded use of lroundl. 166 167 * WebKitTestRunner/DictionaryFunctions.h: Added. Contains convenience functions 168 for dealing with WKDictionaryRef. 169 170 * WebKitTestRunner/EventSenderProxy.h: Initialize data members. 171 172 * WebKitTestRunner/GeolocationProviderMock.cpp: 173 (GeolocationProviderMock::setPosition): Use Optional instead of separate bool. 174 * WebKitTestRunner/GeolocationProviderMock.h: Updated for the above. 175 176 * WebKitTestRunner/InjectedBundle/AccessibilityController.cpp: 177 (WTR::AccessibilityController::makeWindowObject): Use setGlobalObjectProperty. 178 * WebKitTestRunner/InjectedBundle/AccessibilityController.h: Updated for the above. 179 180 * WebKitTestRunner/InjectedBundle/Bindings/CodeGeneratorTestRunner.pm: 181 (_generateImplementationFile): Use static initialization and a lambda instead of 182 an if statement to initialize. 183 (_platformTypeConstructor): Use toOptionalBool and createJSString. Also added 184 support for nullable doubles and used auto a bit more. 185 (_returnExpression): Use makeValue. 186 187 * InjectedBundle/Bindings/TestRunner.idl: Made the optional arguments to the 188 setMockGeolocationPosition function "double?" instead of "object". 189 190 * WebKitTestRunner/InjectedBundle/EventSendingController.cpp: 191 (WTR::getMenuItemChildrenCallback): Use auto and not JSValueToObject. 192 (WTR::arrayLength): Moved to JSBasics.h/cpp. 193 (WTR::parseTouchModifier): Added. Factored out of the 194 EventSendingController::setTouchModifier function. 195 (WTR::parseModifierArray): Use createJSString and remove unneeded ignored 196 exception out argument, since that is optional. Also added overload that 197 gets the context. 198 (WTR::EventSendingController::EventSendingController): Deleted. 199 (WTR::EventSendingController::~EventSendingController): Deleted. 200 (WTR::createMouseMessageBody): Use adoptWK and setValue. Return a WKRetainPtr. 201 (WTR::EventSendingController::mouseDown): Use postSynchronousPageMessage. 202 (WTR::EventSendingController::mouseUp): Ditto. 203 (WTR::EventSendingController::mouseMoveTo): Use setValue and 204 postSynchronousPageMessages. 205 (WTR::EventSendingController::mouseForceClick): Ditto. 206 (WTR::EventSendingController::startAndCancelMouseForceClick): Ditto. 207 (WTR::EventSendingController::mouseForceDown): Ditto. 208 (WTR::EventSendingController::mouseForceUp): Ditto. 209 (WTR::EventSendingController::mouseForceChanged): Ditto. 210 (WTR::EventSendingController::leapForward): Ditto. 211 (WTR::EventSendingController::scheduleAsynchronousClick): Use postPageMessage. 212 (WTR::createKeyDownMessageBody): Use setValue. 213 (WTR::EventSendingController::keyDown): Use postSynchronousPageMessage. 214 (WTR::EventSendingController::scheduleAsynchronousKeyDown): Use postPageMessage. 215 (WTR::EventSendingController::mouseScrollBy): Use setValue and postPageMessage. 216 (WTR::EventSendingController::mouseScrollByWithWheelAndMomentumPhases): Use 217 setValue and postPageMessage. 218 (WTR::EventSendingController::continuousMouseScrollBy): Use setValue and 219 postSynchronousPageMessage. 220 (WTR::EventSendingController::contextClick): Use auto and not JSValueToObject. 221 (WTR::toMonitorWheelEventsOptions): Use booleanProperty. 222 (WTR::EventSendingController::addTouchPoint): Use setValue and postSynchronousPageMessage. 223 (WTR::EventSendingController::updateTouchPoint): Ditto. 224 (WTR::EventSendingController::setTouchModifier): Ditto. 225 (WTR::EventSendingController::setTouchPointRadius): Ditto. 226 (WTR::EventSendingController::touchStart): Ditto. 227 (WTR::EventSendingController::touchMove): Ditto. 228 (WTR::EventSendingController::touchEnd): Ditto. 229 (WTR::EventSendingController::touchCancel): Ditto. 230 (WTR::EventSendingController::clearTouchPoints): Ditto. 231 (WTR::EventSendingController::releaseTouchPoint): Ditto. 232 (WTR::EventSendingController::cancelTouchPoint): Ditto. 233 (WTR::EventSendingController::makeWindowObject): Use setGlobalObjectProperty. 234 * WebKitTestRunner/InjectedBundle/EventSendingController.h: Updated for the above. 235 Deleted various unneeded functions. 236 237 * WebKitTestRunner/InjectedBundle/GCController.cpp: 238 (WTR::GCController::GCController): Deleted. 239 (WTR::GCController::~GCController): Deleted. 240 (WTR::GCController::makeWindowObject): Use setGlobalObjectProperty. 241 242 * WebKitTestRunner/InjectedBundle/GCController.h: Updated for the above. 243 Also marked the class final. 244 245 * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp: 246 (WTR::InjectedBundle::didCreatePage): Use booleanValue. 247 (WTR::InjectedBundle::didReceiveMessage): Use toWK. 248 (WTR::InjectedBundle::postPageMessage): Added. 249 (WTR::InjectedBundle::reportLiveDocuments): Use postPageMessage. 250 (WTR::InjectedBundle::didReceiveMessageToPage): Use dictionaryValue, 251 booleanValue, postPageMessage, value, and more to streamline. 252 (WTR::InjectedBundle::booleanForKey): Deleted. 253 (WTR::InjectedBundle::stringForKey): Deleted. 254 (WTR::InjectedBundle::beginTesting): Use booleanValue. 255 (WTR::InjectedBundle::done): Use stringValue. 256 (WTR::InjectedBundle::closeOtherPages): Use setValue and toWK. 257 (WTR::InjectedBundle::dumpToStdErr): Use postPageMessage 258 (WTR::InjectedBundle::outputText): Use toWK. 259 (WTR::InjectedBundle::postNewBeforeUnloadReturnValue): Use postPageMessage. 260 (WTR::InjectedBundle::postAddChromeInputField): Ditto. 261 (WTR::InjectedBundle::postRemoveChromeInputField): Ditto. 262 (WTR::InjectedBundle::postFocusWebView): Ditto. 263 (WTR::InjectedBundle::postSetBackingScaleFactor): Ditto. 264 (WTR::InjectedBundle::postSetWindowIsKey): Use toWK. 265 (WTR::InjectedBundle::postSetViewSize): Use setValue and toWK. 266 (WTR::InjectedBundle::postSimulateWebNotificationClick): Use postPageMessage. 267 (WTR::InjectedBundle::postSetAddsVisitedLinks): Ditto. 268 (WTR::InjectedBundle::setGeolocationPermission): Ditto. 269 (WTR::InjectedBundle::setMockGeolocationPosition): Use setValue and postPageMessage, 270 and use Optional instead of bool/double pairs. 271 (WTR::InjectedBundle::setMockGeolocationPositionUnavailableError): Use postPageMessage. 272 (WTR::InjectedBundle::isGeolocationProviderActive const): Use toWK and booleanValue. 273 (WTR::InjectedBundle::imageCountInGeneralPasteboard const): Use toWK and uint64Value. 274 (WTR::InjectedBundle::setUserMediaPermission): Use postPageMessage. 275 (WTR::InjectedBundle::resetUserMediaPermission): Ditto. 276 (WTR::InjectedBundle::setUserMediaPersistentPermissionForOrigin): Use setValue 277 and postPageMessage. 278 (WTR::InjectedBundle::userMediaPermissionRequestCountForOrigin const): Ditto. 279 (WTR::InjectedBundle::resetUserMediaPermissionRequestCountForOrigin): Uset setValue 280 and uint64Value. 281 (WTR::InjectedBundle::setCustomPolicyDelegate): Use setValue and postPageMessage. 282 (WTR::InjectedBundle::setHidden): Ditto. 283 (WTR::InjectedBundle::setCacheModel): Ditto. 284 (WTR::InjectedBundle::shouldProcessWorkQueue const): Use toWK and booleanValue. 285 (WTR::InjectedBundle::processWorkQueue): Use postPageMessage. 286 (WTR::InjectedBundle::queueBackNavigation): Ditto. 287 (WTR::InjectedBundle::queueForwardNavigation): Ditto. 288 (WTR::InjectedBundle::queueLoad): Use setValue and postPageMessage. 289 (WTR::InjectedBundle::queueLoadHTMLString): Ditto. 290 (WTR::InjectedBundle::queueReload): Ditto. 291 (WTR::InjectedBundle::queueLoadingScript): Ditto. 292 (WTR::InjectedBundle::queueNonLoadingScript): Ditto. 293 (WTR::postMessage): Added. Overloads for many types to keep caller code streamlined. 294 (WTR::postSynchronousMessage): Ditto. 295 (WTR::postPageMessage): Ditto. 296 (WTR::postSynchronousPageMessage): Ditto. 297 * WebKitTestRunner/InjectedBundle/InjectedBundle.h: Updated for the above. 298 299 * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp: 300 (WTR::propertyValue): Deleted. Use functions from JSBasics.h instead. 301 (WTR::propertyValueDouble): Ditto. 302 (WTR::propertyValueInt): Ditto. 303 (WTR::numericWindowProperty): Renamed from numericWindowPropertyValue for brevity 304 and for consistency with JSBasics.h functions. 305 (WTR::dumpPath): Use stringProperty, objectProperty, and makeString. 306 (WTR::rangeToStr): Use auto, numericProperty, and makeString. 307 (WTR::NavigationTypeToString): Use toWK. 308 (WTR::string): Renamed from securityOriginToStr. Use makeString. 309 (WTR::frameToStr): Use auto. 310 (WTR::InjectedBundlePage::resetAfterTest): Removed unneeded local. 311 (WTR::dumpFrameDescriptionSuitableForTestResult): Use auto. 312 (WTR::dumpRequestDescriptionSuitableForTestResult): Ditto. 313 (WTR::dumpErrorDescriptionSuitableForTestResult): Use auto and toWK. 314 (WTR::dumpFrameScrollPosition): Update for name change. 315 (WTR::toJS): Deleted. Use functions from JSBasics.h instead. 316 (WTR::hasDocumentElement): Use objectProperty. 317 (WTR::InjectedBundlePage::didClearWindowForFrame): Use setGlobalObjectProperty, 318 and pass fewer arguments to makeWindowObject. 319 (WTR::InjectedBundlePage::decidePolicyForNavigationAction): Streamline code a bit. 320 (WTR::InjectedBundlePage::decidePolicyForResponse): Use makeString. 321 (WTR::lastFileURLPathComponent): Ditto. 322 (WTR::InjectedBundlePage::willSetStatusbarText): Ditto. 323 (WTR::InjectedBundlePage::didReachApplicationCacheOriginQuota): Ditto. 324 (WTR::InjectedBundlePage::didExceedDatabaseQuota): Ditto. 325 (WTR::InjectedBundlePage::shouldBeginEditing): Ditto. 326 (WTR::InjectedBundlePage::shouldEndEditing): Ditto. 327 328 * WebKitTestRunner/InjectedBundle/TestRunner.cpp: 329 (WTR::TestRunner::TestRunner): Use toWK. 330 (WTR::page): Added. 331 (WTR::mainFrame): Added. 332 (WTR::mainFrameJSContext): Added. 333 (WTR::TestRunner::display): Use page. 334 (WTR::TestRunner::displayAndTrackRepaints): Use page. 335 (WTR::toWK): Added overload for double. 336 (WTR::createWKDictionary): Added. 337 (WTR::postSynchronousMessageWithReturnValue): Added. 338 (WTR::postSynchronousMessageReturningBoolean): Added. 339 (WTR::postSynchronousPageMessageWithReturnValue): Added. 340 (WTR::postSynchronousPageMessageReturningBoolean): Added. 341 (WTR::postSynchronousPageMessageReturningUInt64): Added. 342 (WTR::postSynchronousMessageReturningUInt64): Added. 343 (WTR::overridePreference): Added. 344 (WTR::TestRunner::shouldDumpPixels const): Use postSynchronousMessageReturningBoolean. 345 (WTR::TestRunner::setDumpPixels): Use postSynchronousMessage. 346 (WTR::TestRunner::whatToDump const): Use postSynchronousMessageReturningUInt64. 347 (WTR::TestRunner::setWhatToDump): Use postSynchronousMessage. 348 (WTR::TestRunner::setWaitUntilDone): Use postSynchronousMessage. 349 (WTR::TestRunner::shouldWaitUntilDone const): Use postSynchronousMessageReturningBoolean. 350 (WTR::TestRunner::setShouldDumpFrameLoadCallbacks): Use postSynchronousMessage. 351 (WTR::TestRunner::shouldDumpFrameLoadCallbacks): Use postSynchronousMessageReturningBoolean. 352 (WTR::TestRunner::addUserScript): Use page. 353 (WTR::TestRunner::addUserStyleSheet): Ditto. 354 (WTR::TestRunner::execCommand): Ditto. 355 (WTR::findOptionsFromArray): Use mainFrameJSContext, arrayLength, and createJSString. 356 (WTR::TestRunner::findString): Use page. 357 (WTR::TestRunner::findStringMatchesInPage): Ditto. 358 (WTR::TestRunner::replaceFindMatchesAtIndices): Use mainFrameJSContext and arrayLength and 359 removed unneeded call to std::round. 360 (WTR::TestRunner::clearAllDatabases): Use postSynchronousMessage. 361 (WTR::TestRunner::syncLocalStorage): Ditto. 362 (WTR::TestRunner::clearAllApplicationCaches): Use page. 363 (WTR::TestRunner::clearApplicationCacheForOrigin): Ditto. 364 (WTR::TestRunner::setAppCacheMaximumSize): Ditto. 365 (WTR::TestRunner::applicationCacheDiskUsageForOrigin): Ditto. 366 (WTR::stringArrayToJS): Tweaked coding style a bit. 367 (WTR::TestRunner::originsWithApplicationCache): Use page. 368 (WTR::TestRunner::isCommandEnabled): Ditto. 369 (WTR::TestRunner::setCanOpenWindows): Use postSynchronousMessage. 370 (WTR::TestRunner::setXSSAuditorEnabled): Use overridePreference. 371 (WTR::TestRunner::setMediaDevicesEnabled): Ditto. 372 (WTR::TestRunner::setWebRTCMDNSICECandidatesEnabled): Ditto. 373 (WTR::TestRunner::setCustomUserAgent): Use postSynchronousMessage. 374 (WTR::TestRunner::setWebAPIStatisticsEnabled): Use overridePreference. 375 (WTR::TestRunner::setModernMediaControlsEnabled): Ditto. 376 (WTR::TestRunner::setWebGL2Enabled): Ditto. 377 (WTR::TestRunner::setWritableStreamAPIEnabled): Ditto. 378 (WTR::TestRunner::setTransformStreamAPIEnabled): Ditto. 379 (WTR::TestRunner::setReadableByteStreamAPIEnabled): Ditto. 380 (WTR::TestRunner::setEncryptedMediaAPIEnabled): Ditto. 381 (WTR::TestRunner::setPictureInPictureAPIEnabled): Ditto. 382 (WTR::TestRunner::setGenericCueAPIEnabled): Ditto. 383 (WTR::TestRunner::setAllowsAnySSLCertificate): Use postSynchronousPageMessage. 384 (WTR::TestRunner::setShouldSwapToEphemeralSessionOnNextNavigation): Ditto. 385 (WTR::TestRunner::setShouldSwapToDefaultSessionOnNextNavigation): Ditto. 386 (WTR::TestRunner::setPluginsEnabled): Use overridePreference. 387 (WTR::TestRunner::isPageBoxVisible): Use mainFrame. 388 (WTR::TestRunner::setValueForUser): Removed local. 389 (WTR::TestRunner::setAudioResult): Ditto. 390 (WTR::TestRunner::clearBackForwardList): Use page. 391 (WTR::TestRunner::makeWindowObject): Use setGlobalObjectProperty. 392 (WTR::TestRunner::showWebInspector): Use page. 393 (WTR::TestRunner::closeWebInspector): Ditto. 394 (WTR::TestRunner::evaluateInWebInspector): Ditto. 395 (WTR::TestRunner::worldIDForWorld): Use range-based for loop. 396 (WTR::TestRunner::evaluateScriptInIsolatedWorld): Use mainFrame. 397 (WTR::TestRunner::setTextDirection): Use mainFrame. 398 (WTR::TestRunner::didReceiveServerRedirectForProvisionalNavigation const): 399 Use postSynchronousPageMessageReturningBoolean. 400 (WTR::TestRunner::clearDidReceiveServerRedirectForProvisionalNavigation): 401 Use postSynchronousPageMessage. 402 (WTR::cacheTestRunnerCallback): Changed map to store objects instead of values. 403 (WTR::callTestRunnerCallback): Simplify since map has objects. Use mainFrameJSContext. 404 (WTR::TestRunner::clearTestRunnerCallbacks): Ditto. 405 (WTR::TestRunner::setAlwaysAcceptCookies): Use postSynchronousMessage. 406 (WTR::TestRunner::setOnlyAcceptFirstPartyCookies): Use auto and toWK. 407 (WTR::TestRunner::setUserStyleSheetEnabled): Use toWK. 408 (WTR::TestRunner::setUserStyleSheetLocation): Use page. 409 (WTR::TestRunner::setTabKeyCyclesThroughElements): Ditto. 410 (WTR::TestRunner::grantWebNotificationPermission): Ditto. 411 (WTR::TestRunner::denyWebNotificationPermission): Ditto. 412 (WTR::TestRunner::removeAllWebNotificationPermissions): Use mainFrameJSContext. 413 (WTR::TestRunner::simulateWebNotificationClick): Ditto. 414 (WTR::TestRunner::setMockGeolocationPosition): Use Optional<double> instead of bool/double 415 pairs, letting the IDL bindings do the work for us. 416 (WTR::TestRunner::setMockGeolocationPositionUnavailableError): Removed local. 417 (WTR::TestRunner::isDoingMediaCapture const): Use postSynchronousPageMessageReturningBoolean. 418 (WTR::TestRunner::setUserMediaPersistentPermissionForOrigin): Removed locals. 419 (WTR::TestRunner::userMediaPermissionRequestCountForOrigin const): Ditto. 420 (WTR::TestRunner::resetUserMediaPermissionRequestCountForOrigin): DItto. 421 (WTR::TestRunner::callShouldCloseOnWebView): Use mainFrame. 422 (WTR::TestRunner::queueLoad): Ditto. 423 (WTR::TestRunner::queueLoadHTMLString): Removed a local. 424 (WTR::TestRunner::queueLoadingScript): Ditto. 425 (WTR::TestRunner::queueNonLoadingScript): Ditto. 426 (WTR::TestRunner::setRejectsProtectionSpaceAndContinueForAuthenticationChallenges): 427 Use postPageMessage. 428 (WTR::TestRunner::setHandlesAuthenticationChallenges): Ditto. 429 (WTR::TestRunner::setShouldLogCanAuthenticateAgainstProtectionSpace): Ditto. 430 (WTR::TestRunner::setShouldLogDownloadCallbacks): Ditto. 431 (WTR::TestRunner::setAuthenticationUsername): Ditto. 432 (WTR::TestRunner::setAuthenticationPassword): Ditto. 433 (WTR::TestRunner::secureEventInputIsEnabled const): Use postSynchronousPageMessageReturningBoolean. 434 (WTR::TestRunner::setBlockAllPlugins): Use postPageMessage. 435 (WTR::TestRunner::setPluginSupportedMode): Ditto. 436 (WTR::TestRunner::failNextNewCodeBlock): Use mainFrameJSContext. 437 (WTR::TestRunner::numberOfDFGCompiles): Ditto. 438 (WTR::TestRunner::neverInlineFunction): Ditto. 439 (WTR::TestRunner::setShouldDecideNavigationPolicyAfterDelay): Use postPageMessage. 440 (WTR::TestRunner::setShouldDecideResponsePolicyAfterDelay): Ditto. 441 (WTR::TestRunner::setNavigationGesturesEnabled): Ditto. 442 (WTR::TestRunner::setIgnoresViewportScaleLimits): Ditto. 443 (WTR::TestRunner::setShouldDownloadUndisplayableMIMETypes): Ditto. 444 (WTR::TestRunner::setShouldAllowDeviceOrientationAndMotionAccess): Ditto. 445 (WTR::TestRunner::terminateNetworkProcess): Use postSynchronousPageMessage. 446 (WTR::TestRunner::terminateServiceWorkers): Ditto. 447 (WTR::TestRunner::setUseSeparateServiceWorkerProcess): Ditto. 448 (WTR::TestRunner::runUIScript): Use postPageMessage. 449 (WTR::TestRunner::runUIScriptImmediately): Ditto. 450 (WTR::TestRunner::runUIScriptCallback): Use mainFrameJSContext. 451 (WTR::TestRunner::setAllowedMenuActions): Use mainFrameJSContext, arrayLength, 452 and postPageMessage. 453 (WTR::TestRunner::installCustomMenuAction): Use postPageMessage. 454 (WTR::TestRunner::clearStatisticsDataForDomain): Use postSynchronousMessage. 455 (WTR::TestRunner::doesStatisticsDomainIDExistInDatabase): Use 456 postSynchronousPageMessageReturningBoolean. 457 (WTR::TestRunner::setStatisticsEnabled): Use postSynchronousMessage. 458 (WTR::TestRunner::isStatisticsEphemeral): Use postSynchronousPageMessageReturningBoolean. 459 (WTR::TestRunner::setStatisticsDebugMode): Use postMessage. 460 (WTR::TestRunner::setStatisticsPrevalentResourceForDebugMode): Ditto. 461 (WTR::TestRunner::setStatisticsLastSeen): Ditto. 462 (WTR::TestRunner::setStatisticsMergeStatistic): Ditto. 463 (WTR::TestRunner::setStatisticsExpiredStatistic): Ditto. 464 (WTR::TestRunner::setStatisticsPrevalentResource): Ditto. 465 (WTR::TestRunner::setStatisticsVeryPrevalentResource): Ditto. 466 (WTR::TestRunner::dumpResourceLoadStatistics): Use postSynchronousPageMessage. 467 (WTR::TestRunner::isStatisticsPrevalentResource): Use postSynchronousPageMessageReturningBoolean. 468 (WTR::TestRunner::isStatisticsVeryPrevalentResource): Ditto. 469 (WTR::TestRunner::isStatisticsRegisteredAsSubresourceUnder): Ditto. 470 (WTR::TestRunner::isStatisticsRegisteredAsSubFrameUnder): Ditto. 471 (WTR::TestRunner::isStatisticsRegisteredAsRedirectingTo): Ditto. 472 (WTR::TestRunner::setStatisticsHasHadUserInteraction): Use postMessage. 473 (WTR::TestRunner::isStatisticsHasHadUserInteraction): Use postSynchronousPageMessageReturningBoolean. 474 (WTR::TestRunner::isStatisticsOnlyInDatabaseOnce): Ditto. 475 (WTR::TestRunner::setStatisticsGrandfathered): Use postSynchronousMessage. 476 (WTR::TestRunner::setUseITPDatabase): Ditto. 477 (WTR::TestRunner::isStatisticsGrandfathered): Use postSynchronousPageMessageReturningBoolean. 478 (WTR::TestRunner::setStatisticsSubframeUnderTopFrameOrigin): Use postSynchronousMessage. 479 (WTR::TestRunner::setStatisticsSubresourceUnderTopFrameOrigin): Ditto. 480 (WTR::TestRunner::setStatisticsSubresourceUniqueRedirectTo): Ditto. 481 (WTR::TestRunner::setStatisticsSubresourceUniqueRedirectFrom): Ditto. 482 (WTR::TestRunner::setStatisticsTopFrameUniqueRedirectTo): Ditto. 483 (WTR::TestRunner::setStatisticsTopFrameUniqueRedirectFrom): Ditto. 484 (WTR::TestRunner::setStatisticsCrossSiteLoadWithLinkDecoration): Ditto. 485 (WTR::TestRunner::setStatisticsTimeToLiveUserInteraction): Ditto. 486 (WTR::TestRunner::statisticsDidRunTelemetryCallback): Use mainFrameJSContext. 487 (WTR::TestRunner::statisticsProcessStatisticsAndDataRecords): Use postSynchronousMessage. 488 (WTR::TestRunner::statisticsUpdateCookieBlocking): Use postMessage. 489 (WTR::TestRunner::statisticsSubmitTelemetry): Use postSynchronousMessage. 490 (WTR::TestRunner::setStatisticsNotifyPagesWhenDataRecordsWereScanned): Ditto. 491 (WTR::TestRunner::setStatisticsIsRunningTest): Ditto. 492 (WTR::TestRunner::setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval): Ditto. 493 (WTR::TestRunner::setStatisticsMinimumTimeBetweenDataRecordsRemoval): Ditto. 494 (WTR::TestRunner::setStatisticsGrandfatheringTime): Ditto. 495 (WTR::TestRunner::setStatisticsMaxStatisticsEntries): Ditto. 496 (WTR::TestRunner::setStatisticsPruneEntriesDownTo): Ditto. 497 (WTR::TestRunner::statisticsClearInMemoryAndPersistentStore): Use postMessage. 498 (WTR::TestRunner::statisticsClearInMemoryAndPersistentStoreModifiedSinceHours): Ditto. 499 (WTR::TestRunner::statisticsClearThroughWebsiteDataRemoval): Ditto. 500 (WTR::TestRunner::statisticsDeleteCookiesForHost): Use postSynchronousMessage. 501 (WTR::TestRunner::isStatisticsHasLocalStorage): Use postSynchronousPageMessageReturningBoolean. 502 (WTR::TestRunner::setStatisticsCacheMaxAgeCap): Use postSynchronousMessage. 503 (WTR::TestRunner::hasStatisticsIsolatedSession): Use postSynchronousPageMessageReturningBoolean. 504 (WTR::TestRunner::setStatisticsShouldDowngradeReferrer): Use postMessage. 505 (WTR::TestRunner::setStatisticsShouldBlockThirdPartyCookies): Ditto. 506 (WTR::TestRunner::setStatisticsFirstPartyWebsiteDataRemovalMode): Ditto. 507 (WTR::TestRunner::statisticsSetToSameSiteStrictCookies): Ditto. 508 (WTR::TestRunner::statisticsSetFirstPartyHostCNAMEDomain): Ditto. 509 (WTR::TestRunner::statisticsSetThirdPartyCNAMEDomain): Ditto. 510 (WTR::TestRunner::statisticsResetToConsistentState): Ditto. 511 (WTR::TestRunner::getAllStorageAccessEntries): Ditto. 512 (WTR::makeDomainsValue): Factored out. Use mainFrameJSContext. 513 (WTR::TestRunner::callDidReceiveAllStorageAccessEntriesCallback): Use makeDomainsValue. 514 (WTR::TestRunner::loadedSubresourceDomains): Use postMessage. 515 (WTR::TestRunner::callDidReceiveLoadedSubresourceDomainsCallback): Use makeDomainsValue. 516 (WTR::TestRunner::addMockMediaDevice): Use postSynchronousMessage. 517 (WTR::TestRunner::clearMockMediaDevices): Ditto. 518 (WTR::TestRunner::removeMockMediaDevice): Ditto. 519 (WTR::TestRunner::resetMockMediaDevices): Ditto. 520 (WTR::TestRunner::setMockCameraOrientation): Ditto. 521 (WTR::TestRunner::isMockRealtimeMediaSourceCenterEnabled): Use 522 postSynchronousMessageReturningBoolean. 523 (WTR::TestRunner::connectMockGamepad): Use postSynchronousMessage. 524 (WTR::TestRunner::disconnectMockGamepad): Ditto. 525 (WTR::TestRunner::setMockGamepadDetails): Ditto. 526 (WTR::TestRunner::setMockGamepadAxisValue): Ditto. 527 (WTR::TestRunner::setMockGamepadButtonValue): Ditto. 528 (WTR::TestRunner::setOpenPanelFiles): Use mainFrameJSContext, arrayLength, createJSString, 529 and postPageMessage. 530 (WTR::TestRunner::setOpenPanelFilesMediaIcon): Use mainFrameJSContext and postPageMessage. 531 (WTR::TestRunner::removeAllSessionCredentials): Use postMessage. 532 (WTR::TestRunner::clearDOMCache): Use postSynchronousMessage. 533 (WTR::TestRunner::clearDOMCaches): Ditto. 534 (WTR::TestRunner::hasDOMCache): Use postSynchronousPageMessageReturningBoolean. 535 (WTR::TestRunner::domCacheSize): Use postSynchronousPageMessageReturningUInt64. 536 (WTR::TestRunner::setAllowStorageQuotaIncrease): Use postSynchronousPageMessage. 537 (WTR::TestRunner::getApplicationManifestThen): Use postMessage. 538 (WTR::TestRunner::injectUserScript): Use postSynchronousMessage. 539 (WTR::TestRunner::sendDisplayConfigurationChangedMessageForTesting): Ditto. 540 (WTR::TestRunner::setServiceWorkerFetchTimeout): Ditto. 541 (WTR::TestRunner::addTestKeyToKeychain): Ditto. 542 (WTR::TestRunner::cleanUpKeychain): Ditto. 543 (WTR::TestRunner::keyExistsInKeychain): Use postSynchronousPageMessageReturningBoolean. 544 (WTR::TestRunner::serverTrustEvaluationCallbackCallsCount): Use 545 postSynchronousMessageReturningUInt64. 546 (WTR::TestRunner::setShouldDismissJavaScriptAlertsAsynchronously): Use 547 postSynchronousMessage. 548 (WTR::TestRunner::abortModal): Ditto. 549 (WTR::TestRunner::dumpAdClickAttribution): Use postSynchronousPageMessage. 550 (WTR::TestRunner::clearAdClickAttribution): Ditto. 551 (WTR::TestRunner::clearAdClickAttributionsThroughWebsiteDataRemoval): Ditto. 552 (WTR::TestRunner::setAdClickAttributionOverrideTimerForTesting): Ditto. 553 (WTR::TestRunner::setAdClickAttributionConversionURLForTesting): Ditto. 554 (WTR::TestRunner::markAdClickAttributionsAsExpiredForTesting): Ditto. 555 (WTR::TestRunner::setOffscreenCanvasEnabled): Use overridePreference. 556 (WTR::TestRunner::hasAppBoundSession): Use postSynchronousPageMessageReturningBoolean. 557 (WTR::TestRunner::clearAppBoundSession): Use postSynchronousMessage. 558 (WTR::TestRunner::setAppBoundDomains): Use mainFrameJSContext, arrayLength, createJSString, 559 and toWK. 560 (WTR::TestRunner::postMessage): Added. 561 562 * WebKitTestRunner/InjectedBundle/TestRunner.h: Updated for the above. Also changed 563 overridePreference ot a static member function. 564 565 * WebKitTestRunner/InjectedBundle/TextInputController.cpp: 566 (WTR::TextInputController::TextInputController): Deleted. 567 (WTR::TextInputController::~TextInputController): Deleted. 568 (WTR::TextInputController::makeWindowObject): Use setGlobalObjectProperty. 569 (WTR::arrayLength): Deleted. Use the one from JSBasics.h now. 570 (WTR::createCompositionHighlightData): Use setValue. 571 * WebKitTestRunner/InjectedBundle/TextInputController.h: Updated for the above. 572 573 * WebKitTestRunner/InjectedBundle/ios/AccessibilityControllerIOS.mm: 574 (WTR::AccessibilityController::platformName): Use createJSString. 575 576 * WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm: 577 (WTR::createEmptyJSString): Deleted. Use createJSString from JSBasics.h now. 578 (WTR::AccessibilityUIElement::attributesOfLinkedUIElements): Use createJSString. 579 (WTR::AccessibilityUIElement::attributesOfDocumentLinks): Ditto. 580 (WTR::AccessibilityUIElement::attributesOfChildren): Ditto. 581 (WTR::AccessibilityUIElement::allAttributes): Ditto. 582 (WTR::AccessibilityUIElement::stringDescriptionOfAttributeValue): Ditto. 583 (WTR::AccessibilityUIElement::stringAttributeValue): Ditto. 584 (WTR::AccessibilityUIElement::parameterizedAttributeNames): Ditto. 585 (WTR::AccessibilityUIElement::role): Ditto. 586 (WTR::AccessibilityUIElement::subrole): Ditto. 587 (WTR::AccessibilityUIElement::computedRoleString): Ditto. 588 (WTR::AccessibilityUIElement::title): Ditto. 589 (WTR::AccessibilityUIElement::orientation const): Ditto. 590 (WTR::AccessibilityUIElement::language): Ditto. 591 (WTR::AccessibilityUIElement::valueDescription): Ditto. 592 (WTR::AccessibilityUIElement::isFocused const): Ditto. 593 (WTR::AccessibilityUIElement::isSelectedOptionActive const): Ditto. 594 (WTR::AccessibilityUIElement::isIndeterminate const): Ditto. 595 (WTR::AccessibilityUIElement::ariaDropEffects const): Ditto. 596 (WTR::AccessibilityUIElement::boundsForRange): Ditto. 597 (WTR::AccessibilityUIElement::attributesOfColumnHeaders): Ditto. 598 (WTR::AccessibilityUIElement::attributesOfRowHeaders): Ditto. 599 (WTR::AccessibilityUIElement::attributesOfColumns): Ditto. 600 (WTR::AccessibilityUIElement::attributesOfRows): Ditto. 601 (WTR::AccessibilityUIElement::attributesOfVisibleCells): Ditto. 602 (WTR::AccessibilityUIElement::attributesOfHeader): Ditto. 603 (WTR::AccessibilityUIElement::clearSelectedChildren const): Ditto. 604 (WTR::AccessibilityUIElement::accessibilityValue const): Ditto. 605 (WTR::AccessibilityUIElement::documentEncoding): Ditto. 606 (WTR::AccessibilityUIElement::documentURI): Ditto. 607 (WTR::AccessibilityUIElement::isSelectable const): Ditto. 608 (WTR::AccessibilityUIElement::isMultiSelectable const): Ditto. 609 (WTR::AccessibilityUIElement::isVisible const): Ditto. 610 (WTR::AccessibilityUIElement::isOffScreen const): Ditto. 611 (WTR::AccessibilityUIElement::isCollapsed const): Ditto. 612 (WTR::AccessibilityUIElement::isSingleLine const): Ditto. 613 (WTR::AccessibilityUIElement::isMultiLine const): Ditto. 614 (WTR::AccessibilityUIElement::takeFocus): Ditto. 615 (WTR::AccessibilityUIElement::takeSelection): Ditto. 616 (WTR::AccessibilityUIElement::addSelection): Ditto. 617 (WTR::AccessibilityUIElement::removeSelection): Ditto. 618 (WTR::AccessibilityUIElement::stringForTextMarkerRange): Ditto. 619 620 * WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm: 621 (WTR::EventSenderProxy::EventSenderProxy): Initialize in the class definition. 622 (WTR::EventSenderProxy::~EventSenderProxy): Deleted. 623 624 * WebKitTestRunner/InjectedBundle/mac/AccessibilityCommonMac.mm: 625 (WTR::makeJSArray): Return a JSObjectRef. Renamed from makeArrayRefForArray. 626 (WTR::makeJSObject): Return a JSObjectRef. Renamed from makeObjectRefForDictionary. 627 (WTR::makeValueRefForValue): Updated for the above. 628 (WTR::searchPredicateParameterizedAttributeForSearchCriteria): Use toWTFString 629 and arrayLength. 630 631 * WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm: 632 (WTR::AccessibilityController::platformName): Use createJSString. 633 634 * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm: 635 (WTR::createEmptyJSString): Deleted. Use createJSString from JSBasics.h instead. 636 (WTR::convertVectorToObjectArray): Deleted. 637 (WTR::makeJSArray): Renamed from convertVectorToObjectArray. 638 (WTR::selectTextParameterizedAttributeForCriteria): Use toWTFString and arrayLength. 639 (WTR::searchTextParameterizedAttributeForCriteria): Ditto. 640 (WTR::AccessibilityUIElement::rowHeaders const): Use makeJSArray. 641 (WTR::AccessibilityUIElement::columnHeaders const): Ditto. 642 (WTR::AccessibilityUIElement::uiElementArrayAttributeValue const): Ditto. 643 (WTR::AccessibilityUIElement::searchTextWithCriteria): Ditto. 644 (WTR::AccessibilityUIElement::accessibilityValue const): Use createJSString. 645 (WTR::AccessibilityUIElement::documentEncoding): Ditto. 646 (WTR::AccessibilityUIElement::documentURI): Ditto. 647 648 * WebKitTestRunner/InjectedBundle/mac/TestRunnerMac.mm: 649 (WTR::TestRunner::inspectorTestStubURL): Remove locals. 650 651 * WebKitTestRunner/StringFunctions.h: Added toWKString overload that converts from 652 a JSValueRef, JSStringRef, or JSRetainPtr<JSStringRef> and toWK overload that converts 653 from a const char*. 654 655 * WebKitTestRunner/TestController.cpp: 656 (WTR::TestController::initialize): Use toWK. 657 (WTR::TestController::generateContextConfiguration const): Ditto. 658 (WTR::TestController::resetPreferencesToConsistentValues): Ditto. 659 (WTR::TestController::resetStateToConsistentValues): Use setValue. 660 (WTR::TestController::updateLiveDocumentsAfterTest): Ditto. 661 (WTR::TestController::checkForWorldLeaks): Use toWK. 662 (WTR::contentExtensionJSONPath): Use toSTD. 663 (WTR::TestController::configureContentExtensionForTest): Use toWK. 664 (WTR::TestController::didReceiveKeyDownMessageFromInjectedBundle): Use stringValue 665 and uint64Value. 666 (WTR::TestController::didReceiveLiveDocumentsList): Use dictionaryValue and 667 uint64Value. 668 (WTR::TestController::didReceiveMessageFromInjectedBundle): Use dictionaryValue, 669 stringValue, uint64Value, doubleValue, booleanValue. 670 (WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle): Ditto. 671 (WTR::TestController::setBlockAllPlugins): Use toWK. 672 (WTR::TestController::setPluginSupportedMode): Ditto. 673 (WTR::TestController::canAuthenticateAgainstProtectionSpace): Use auto. 674 (WTR::TestController::didFinishNavigation): Removed local. 675 (WTR::TestController::didReceiveAuthenticationChallenge): Use auto and toWTFString 676 instead of toSTD. 677 (WTR::TestController::setMockGeolocationPosition): Use Optional instead of pairs 678 of bool and double. 679 (WTR::TestController::handleCheckOfUserMediaPermissionForOrigin): Use toWK. 680 (WTR::TestController::decidePolicyForUserMediaPermissionRequestIfPossible): Ditto. 681 (WTR::TestController::updateBundleIdentifierInNetworkProcess): Use toWK. 682 * WebKitTestRunner/TestController.h: Updated for the above. 683 684 * WebKitTestRunner/TestInvocation.cpp: 685 (WTR::postPageMessage): Added. 686 (WTR::TestInvocation::TestIncovation): Use toWTFString. 687 (WTR::TestInvocation::createTestSettingsDictionary): Use auto and setValue. 688 (WTR::TestInvocation::invoke): Use postPageMessage and setValue. 689 (WTR::TestInvocation::didReceiveMessageFromInjectedBundle): Use postPageMessage 690 and stringValue. 691 (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle): Use 692 dictionaryValue, booleanValue, value, stringValue, doubleValue, and 693 optionalDoubleValue. 694 (WTR::TestInvocation::uiScriptDidComplete): Use postPageMessage and setValue. 695 (WTR::TestInvocation::didBeginSwipe): Use postPageMessage. 696 (WTR::TestInvocation::willEndSwipe): Ditto. 697 (WTR::TestInvocation::didEndSwipe): Ditto. 698 (WTR::TestInvocation::didRemoveSwipeSnapshot): Ditto. 699 (WTR::TestInvocation::notifyDownloadDone): Ditto. 700 (WTR::TestInvocation::didClearStatisticsInMemoryAndPersistentStore): Ditto. 701 (WTR::TestInvocation::didClearStatisticsThroughWebsiteDataRemoval): Ditto. 702 (WTR::TestInvocation::didSetShouldDowngradeReferrer): Ditto. 703 (WTR::TestInvocation::didSetShouldBlockThirdPartyCookies): Ditto. 704 (WTR::TestInvocation::didSetFirstPartyWebsiteDataRemovalMode): Ditto. 705 (WTR::TestInvocation::didSetToSameSiteStrictCookies): Ditto. 706 (WTR::TestInvocation::didSetFirstPartyHostCNAMEDomain): Ditto. 707 (WTR::TestInvocation::didSetThirdPartyCNAMEDomain): Ditto. 708 (WTR::TestInvocation::didResetStatisticsToConsistentState): Ditto. 709 (WTR::TestInvocation::didSetBlockCookiesForHost): Ditto. 710 (WTR::TestInvocation::didSetStatisticsDebugMode): Ditto. 711 (WTR::TestInvocation::didSetPrevalentResourceForDebugMode): Ditto. 712 (WTR::TestInvocation::didSetLastSeen): Ditto. 713 (WTR::TestInvocation::didMergeStatistic): Ditto. 714 (WTR::TestInvocation::didSetExpiredStatistic): Ditto. 715 (WTR::TestInvocation::didSetPrevalentResource): Ditto. 716 (WTR::TestInvocation::didSetVeryPrevalentResource): Ditto. 717 (WTR::TestInvocation::didSetHasHadUserInteraction): Ditto. 718 (WTR::TestInvocation::didReceiveAllStorageAccessEntries): Ditto. 719 (WTR::TestInvocation::didReceiveLoadedSubresourceDomains): Ditto. 720 (WTR::TestInvocation::didRemoveAllSessionCredentials): Ditto. 721 (WTR::TestInvocation::didSetAppBoundDomains): Ditto. 722 (WTR::TestInvocation::performCustomMenuAction): Ditto. 723 724 * WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj: 725 Added JSBasics.h to DictionaryFunctions.h to appropriate targets. 726 727 * WebKitTestRunner/WorkQueueManager.cpp: 728 (WTR::ScriptItem::ScriptItem): Use toWK. 729 (WTR::WorkQueueManager::queueLoadHTMLString): Ditto. 730 731 * WebKitTestRunner/cocoa/UIScriptControllerCocoa.h: Make most functions private. 732 733 * WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm: 734 (WTR::UIScriptControllerCocoa::overridePreference): Use toWTFString. 735 736 * WebKitTestRunner/ios/UIScriptControllerIOS.h: Marked the class final and made 737 most functions private. 738 739 * WebKitTestRunner/ios/UIScriptControllerIOS.mm: 740 (WTR::arrayLength): Deleted. Use the one in JSBasics.h. 741 (WTR::parseModifierArray): Use the new toWTFString overload. 742 (WTR::UIScriptControllerIOS::typeCharacterUsingHardwareKeyboard): Ditto. 743 744 * WebKitTestRunner/mac/EventSenderProxy.mm: 745 (WTR::EventSenderProxy::EventSenderProxy): Initialize in the class definition. 746 (WTR::EventSenderProxy::keyDown): Use toWTFString. 747 748 * WebKitTestRunner/mac/UIScriptControllerMac.h: Marked the class final and made 749 most functions private. 750 751 2020-09-27 Darin Adler <darin@apple.com> 752 753 Refactor test runner code to cut down on copy/paste code and long-winded repetitive idioms 754 https://bugs.webkit.org/show_bug.cgi?id=217028 755 756 Reviewed by Sam Weinig. 757 1 758 2020-09-29 Jonathan Bedard <jbedard@apple.com> 2 759 -
TabularUnified trunk/Tools/DumpRenderTree/AccessibilityController.cpp ¶
r236032 r267761 1 1 /* 2 * Copyright (C) 2008 , 2009, 2010 Apple Inc. All Rights Reserved.2 * Copyright (C) 2008-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 31 31 32 32 #include "AccessibilityUIElement.h" 33 #include "JSBasics.h" 33 34 34 35 // Static Value Getters … … 48 49 // Object Creation 49 50 50 void AccessibilityController::makeWindowObject(JSContextRef context , JSObjectRef windowObject, JSValueRef* exception)51 void AccessibilityController::makeWindowObject(JSContextRef context) 51 52 { 52 auto accessibilityControllerStr = adopt(JSStringCreateWithUTF8CString("accessibilityController")); 53 54 JSClassRef classRef = getJSClass(); 55 JSValueRef accessibilityControllerObject = JSObjectMake(context, classRef, this); 56 JSClassRelease(classRef); 57 58 JSObjectSetProperty(context, windowObject, accessibilityControllerStr.get(), accessibilityControllerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception); 53 WTR::setGlobalObjectProperty(context, "accessibilityController", JSObjectMake(context, createJSClass().get(), this)); 59 54 } 60 55 … … 153 148 } 154 149 155 JS ClassRef AccessibilityController::getJSClass()150 JSRetainPtr<JSClassRef> AccessibilityController::createJSClass() 156 151 { 157 static JSStaticFunction staticFunctions[] = {152 static constexpr JSStaticFunction functions[] = { 158 153 { "logFocusEvents", logFocusEventsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, 159 154 { "logValueChangeEvents", logValueChangeEventsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, … … 167 162 { 0, 0, 0 } 168 163 }; 169 170 static JSStaticValue staticValues[] = { 164 static constexpr JSStaticValue values[] = { 171 165 { "focusedElement", getFocusedElementCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, 172 166 { "rootElement", getRootElementCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, … … 175 169 { 0, 0, 0, 0 } 176 170 }; 177 178 static JSClassDefinition classDefinition = { 179 0, kJSClassAttributeNone, "AccessibilityController", 0, staticValues, staticFunctions, 171 static const JSClassDefinition definition = { 172 0, kJSClassAttributeNone, "AccessibilityController", 0, values, functions, 180 173 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 181 174 }; 182 183 return JSClassCreate(&classDefinition); 175 return adopt(JSClassCreate(&definition)); 184 176 } 185 177 -
TabularUnified trunk/Tools/DumpRenderTree/AccessibilityController.h ¶
r259843 r267761 1 1 /* 2 * Copyright (C) 2008 , 2009, 2010 Apple Inc. All Rights Reserved.2 * Copyright (C) 2008-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 48 48 ~AccessibilityController(); 49 49 50 void makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception);50 void makeWindowObject(JSContextRef); 51 51 52 52 // Controller Methods - platform-independent implementations … … 84 84 85 85 private: 86 static JS ClassRef getJSClass();86 static JSRetainPtr<JSClassRef> createJSClass(); 87 87 88 88 #if PLATFORM(WIN) -
TabularUnified trunk/Tools/DumpRenderTree/AccessibilityUIElement.cpp ¶
r264000 r267761 207 207 bool isDirectionNext = true; 208 208 JSValueRef searchKey = nullptr; 209 JSRetainPtr<JSStringRef> searchText = nullptr;209 JSRetainPtr<JSStringRef> searchText; 210 210 bool visibleOnly = false; 211 211 bool immediateDescendantsOnly = false; -
TabularUnified trunk/Tools/DumpRenderTree/Bindings/CodeGeneratorDumpRenderTree.pm ¶
r266311 r267761 1 # Copyright (C) 2016 Apple Inc. All rights reserved.1 # Copyright (C) 2016-2020 Apple Inc. All rights reserved. 2 2 # 3 3 # Redistribution and use in source and binary forms, with or without … … 432 432 my ($self, $type, $argumentName) = @_; 433 433 434 return " JSValueToNullableBoolean(context, $argumentName)" if $type->name eq "boolean" && $type->isNullable;434 return "toOptionalBool(context, $argumentName)" if $type->name eq "boolean" && $type->isNullable; 435 435 return "JSValueToBoolean(context, $argumentName)" if $type->name eq "boolean"; 436 436 return "$argumentName" if $type->name eq "object"; 437 return " adopt(JSValueToStringCopy(context, $argumentName, nullptr))" if $$self{codeGenerator}->IsStringType($type);437 return "createJSString(context, $argumentName)" if $$self{codeGenerator}->IsStringType($type); 438 438 return "JSValueToNumber(context, $argumentName, nullptr)" if $$self{codeGenerator}->IsPrimitiveType($type); 439 439 return "to" . _implementationClassName($type) . "(context, $argumentName)"; … … 473 473 474 474 return "JSValueMakeUndefined(context)" if $returnType->name eq "undefined"; 475 return " JSValueMakeBooleanOrNull(context, ${expression})" if $returnType->name eq "boolean" && $returnType->isNullable;475 return "makeValue(context, ${expression})" if $returnType->name eq "boolean" && $returnType->isNullable; 476 476 return "JSValueMakeBoolean(context, ${expression})" if $returnType->name eq "boolean"; 477 477 return "${expression}" if $returnType->name eq "object"; 478 478 return "JSValueMakeNumber(context, ${expression})" if $$self{codeGenerator}->IsPrimitiveType($returnType); 479 return " JSValueMakeStringOrNull(context, ${expression}.get())" if $$self{codeGenerator}->IsStringType($returnType);479 return "makeValue(context, ${expression}.get())" if $$self{codeGenerator}->IsStringType($returnType); 480 480 return "toJS(context, WTF::getPtr(${expression}))"; 481 481 } -
TabularUnified trunk/Tools/DumpRenderTree/GCController.cpp ¶
r236032 r267761 1 1 /* 2 * Copyright (C) 2007 Apple Inc. All rights reserved.2 * Copyright (C) 2007-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 30 30 #include "GCController.h" 31 31 32 #include <JavaScriptCore/JSObjectRef.h> 33 #include <JavaScriptCore/JSRetainPtr.h> 34 35 GCController::GCController() 36 { 37 } 38 39 GCController::~GCController() 40 { 41 } 32 #include "JSBasics.h" 42 33 43 34 // Static Functions … … 45 36 static JSValueRef collectCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 46 37 { 47 GCController* controller =static_cast<GCController*>(JSObjectGetPrivate(thisObject));48 controller ->collect();38 auto& controller = *static_cast<GCController*>(JSObjectGetPrivate(thisObject)); 39 controller.collect(); 49 40 return JSValueMakeUndefined(context); 50 41 } … … 52 43 static JSValueRef collectOnAlternateThreadCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 53 44 { 54 bool waitUntilDone = false; 55 if (argumentCount > 0) 56 waitUntilDone = JSValueToBoolean(context, arguments[0]); 57 58 GCController* controller = static_cast<GCController*>(JSObjectGetPrivate(thisObject)); 59 controller->collectOnAlternateThread(waitUntilDone); 60 45 auto& controller = *static_cast<GCController*>(JSObjectGetPrivate(thisObject)); 46 bool waitUntilDone = argumentCount > 0 && JSValueToBoolean(context, arguments[0]); 47 controller.collectOnAlternateThread(waitUntilDone); 61 48 return JSValueMakeUndefined(context); 62 49 } … … 64 51 static JSValueRef getJSObjectCountCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 65 52 { 66 GCController* controller = static_cast<GCController*>(JSObjectGetPrivate(thisObject)); 67 size_t jsObjectCount = controller->getJSObjectCount(); 68 69 return JSValueMakeNumber(context, jsObjectCount); 53 auto& controller = *static_cast<GCController*>(JSObjectGetPrivate(thisObject)); 54 return JSValueMakeNumber(context, controller.getJSObjectCount()); 70 55 } 71 56 72 57 // Object Creation 73 58 74 void GCController::makeWindowObject(JSContextRef context , JSObjectRef windowObject, JSValueRef* exception)59 void GCController::makeWindowObject(JSContextRef context) 75 60 { 76 auto gcControllerStr = adopt(JSStringCreateWithUTF8CString("GCController")); 77 78 JSClassRef classRef = getJSClass(); 79 JSValueRef gcControllerObject = JSObjectMake(context, classRef, this); 80 JSClassRelease(classRef); 81 82 JSObjectSetProperty(context, windowObject, gcControllerStr.get(), gcControllerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception); 61 WTR::setGlobalObjectProperty(context, "GCController", JSObjectMake(context, createJSClass().get(), this)); 83 62 } 84 63 85 JS ClassRef GCController::getJSClass()64 JSRetainPtr<JSClassRef> GCController::createJSClass() 86 65 { 87 static JSStaticFunction staticFunctions[] = {66 static constexpr JSStaticFunction functions[] = { 88 67 { "collect", collectCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, 89 68 { "collectOnAlternateThread", collectOnAlternateThreadCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, … … 91 70 { 0, 0, 0 } 92 71 }; 93 94 static JSClassDefinition classDefinition = { 95 0, kJSClassAttributeNone, "GCController", 0, 0, staticFunctions, 72 static const JSClassDefinition definition = { 73 0, kJSClassAttributeNone, "GCController", 0, 0, functions, 96 74 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 97 75 }; 98 99 return JSClassCreate(&classDefinition); 76 return adopt(JSClassCreate(&definition)); 100 77 } -
TabularUnified trunk/Tools/DumpRenderTree/GCController.h ¶
r248762 r267761 27 27 */ 28 28 29 #ifndef GCController_h 30 #define GCController_h 29 #pragma once 31 30 32 #include <JavaScriptCore/JS ObjectRef.h>31 #include <JavaScriptCore/JSRetainPtr.h> 33 32 #include <wtf/FastMalloc.h> 34 33 … … 36 35 WTF_MAKE_FAST_ALLOCATED; 37 36 public: 38 GCController(); 39 ~GCController(); 40 41 void makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception); 37 void makeWindowObject(JSContextRef); 42 38 43 39 // Controller Methods - platfrom independant implementations … … 47 43 48 44 private: 49 static JS ClassRef getJSClass();45 static JSRetainPtr<JSClassRef> createJSClass(); 50 46 }; 51 52 #endif // GCController_h -
TabularUnified trunk/Tools/DumpRenderTree/TestRunner.cpp ¶
r267030 r267761 31 31 #include "TestRunner.h" 32 32 33 #include "JSBasics.h" 33 34 #include "WebCoreTestSupport.h" 34 35 #include "WorkQueue.h" … … 39 40 #include <JavaScriptCore/JSArrayBufferView.h> 40 41 #include <JavaScriptCore/JSCTestRunnerUtils.h> 41 #include <JavaScriptCore/JSContextRef.h>42 42 #include <JavaScriptCore/JSGlobalObjectInlines.h> 43 #include <JavaScriptCore/JSObjectRef.h>44 #include <JavaScriptCore/JSRetainPtr.h>45 43 #include <JavaScriptCore/TypedArrayInlines.h> 46 44 #include <JavaScriptCore/VMInlines.h> … … 490 488 static JSValueRef displayAndTrackRepaintsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 491 489 { 492 // Has mac & windows implementation493 490 TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject)); 494 491 controller->displayAndTrackRepaints(); … … 499 496 static JSValueRef encodeHostNameCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 500 497 { 501 // Has mac implementation 502 if (argumentCount < 1) 503 return JSValueMakeUndefined(context); 504 505 auto name = adopt(JSValueToStringCopy(context, arguments[0], exception)); 506 ASSERT(!*exception); 498 if (argumentCount < 1) 499 return JSValueMakeUndefined(context); 500 501 auto name = WTR::createJSString(context, arguments[0]); 507 502 508 503 TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject)); … … 513 508 static JSValueRef execCommandCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 514 509 { 515 // Has Mac & Windows implementations. 516 if (argumentCount < 1) 517 return JSValueMakeUndefined(context); 518 519 auto name = adopt(JSValueToStringCopy(context, arguments[0], exception)); 520 ASSERT(!*exception); 521 510 if (argumentCount < 1) 511 return JSValueMakeUndefined(context); 512 513 auto name = WTR::createJSString(context, arguments[0]); 522 514 // Ignoring the second parameter (userInterface), as this command emulates a manual action. 523 524 JSRetainPtr<JSStringRef> value; 525 if (argumentCount >= 3) { 526 value = adopt(JSValueToStringCopy(context, arguments[2], exception)); 527 ASSERT(!*exception); 528 } else 529 value = adopt(JSStringCreateWithUTF8CString("")); 530 515 auto value = WTR::createJSString(context, argumentCount > 2 ? arguments[2] : nullptr); 531 516 532 517 TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject)); … … 542 527 return JSValueMakeUndefined(context); 543 528 544 auto target = adopt(JSValueToStringCopy(context, arguments[0], exception)); 545 ASSERT(!*exception); 546 547 JSObjectRef options = JSValueToObject(context, arguments[1], exception); 548 ASSERT(!*exception); 529 auto target = WTR::createJSString(context, arguments[0]); 530 auto options = JSValueToObject(context, arguments[1], nullptr); 549 531 550 532 TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject)); … … 567 549 return JSValueMakeUndefined(context); 568 550 569 auto name = adopt(JSValueToStringCopy(context, arguments[0], exception)); 570 ASSERT(!*exception); 551 auto name = WTR::createJSString(context, arguments[0]); 571 552 572 553 TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject)); … … 580 561 return JSValueMakeUndefined(context); 581 562 582 auto key = adopt(JSValueToStringCopy(context, arguments[0], exception)); 583 ASSERT(!*exception); 584 auto value = adopt(JSValueToStringCopy(context, arguments[1], exception)); 585 ASSERT(!*exception); 563 auto key = WTR::createJSString(context, arguments[0]); 564 auto value = WTR::createJSString(context, arguments[1]); 586 565 587 566 // Should use `<!-- webkit-test-runner [ enableBackForwardCache=true ] -->` instead. … … 663 642 return JSValueMakeUndefined(context); 664 643 665 auto url = adopt(JSValueToStringCopy(context, arguments[0], exception)); 666 ASSERT(!*exception); 667 668 JSRetainPtr<JSStringRef> target; 669 if (argumentCount >= 2) { 670 target = adopt(JSValueToStringCopy(context, arguments[1], exception)); 671 ASSERT(!*exception); 672 } else 673 target = adopt(JSStringCreateWithUTF8CString("")); 644 auto url = WTR::createJSString(context, arguments[0]); 645 ASSERT(!*exception); 646 647 auto target = WTR::createJSString(context, argumentCount > 1 ? arguments[1] : nullptr); 674 648 675 649 TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject)); … … 693 667 ASSERT(!*exception); 694 668 } else 695 baseURL = adopt(JSStringCreateWithUTF8CString(""));669 baseURL = WTR::createJSString(); 696 670 697 671 TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject)); … … 2046 2020 static void testRunnerObjectFinalize(JSObjectRef object) 2047 2021 { 2048 TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(object)); 2049 controller->deref(); 2022 static_cast<TestRunner*>(JSObjectGetPrivate(object))->deref(); 2050 2023 } 2051 2024 2052 2025 // Object Creation 2053 2026 2054 void TestRunner::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception) 2055 { 2056 auto testRunnerStr = adopt(JSStringCreateWithUTF8CString("testRunner")); 2027 void TestRunner::makeWindowObject(JSContextRef context) 2028 { 2057 2029 ref(); 2058 2059 JSClassRef classRef = getJSClass(); 2060 JSValueRef layoutTestContollerObject = JSObjectMake(context, classRef, this); 2061 JSClassRelease(classRef); 2062 2063 JSObjectSetProperty(context, windowObject, testRunnerStr.get(), layoutTestContollerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception); 2064 } 2065 2066 JSClassRef TestRunner::getJSClass() 2067 { 2068 static JSStaticValue* staticValues = TestRunner::staticValues(); 2069 static JSStaticFunction* staticFunctions = TestRunner::staticFunctions(); 2070 static JSClassDefinition classDefinition = { 2071 0, kJSClassAttributeNone, "TestRunner", 0, staticValues, staticFunctions, 2030 WTR::setGlobalObjectProperty(context, "testRunner", JSObjectMake(context, createJSClass().get(), this)); 2031 } 2032 2033 JSRetainPtr<JSClassRef> TestRunner::createJSClass() 2034 { 2035 static const JSClassDefinition definition = { 2036 0, kJSClassAttributeNone, "TestRunner", 0, staticValues(), staticFunctions(), 2072 2037 0, testRunnerObjectFinalize, 0, 0, 0, 0, 0, 0, 0, 0, 0 2073 2038 }; 2074 2075 return JSClassCreate(&classDefinition); 2039 return adopt(JSClassCreate(&definition)); 2076 2040 } 2077 2041 … … 2108 2072 } 2109 2073 2110 JSStaticValue* TestRunner::staticValues()2111 { 2112 static JSStaticValue staticValues[] = {2074 const JSStaticValue* TestRunner::staticValues() 2075 { 2076 static constexpr JSStaticValue values[] = { 2113 2077 { "didCancelClientRedirect", getDidCancelClientRedirect, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, 2114 2078 { "timeout", getTimeoutCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, … … 2128 2092 { 0, 0, 0, 0 } 2129 2093 }; 2130 return staticValues;2131 } 2132 2133 JSStaticFunction* TestRunner::staticFunctions()2134 { 2135 static JSStaticFunction staticFunctions[] = {2094 return values; 2095 } 2096 2097 const JSStaticFunction* TestRunner::staticFunctions() 2098 { 2099 static constexpr JSStaticFunction functions[] = { 2136 2100 { "abortModal", abortModalCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, 2137 2101 { "addDisallowedURL", addDisallowedURLCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, … … 2298 2262 }; 2299 2263 2300 return staticFunctions;2264 return functions; 2301 2265 } 2302 2266 … … 2343 2307 void TestRunner::waitToDumpWatchdogTimerFired() 2344 2308 { 2345 const char* message = "FAIL: Timed out waiting for notifyDone to be called\n"; 2346 fprintf(testResult, "%s", message); 2347 2348 auto accumulatedLogs = getAndResetAccumulatedLogs(); 2349 if (!accumulatedLogs.isEmpty()) { 2350 const char* message = "Logs accumulated during test run:\n"; 2351 fprintf(testResult, "%s%s\n", message, accumulatedLogs.utf8().data()); 2352 } 2309 fputs("FAIL: Timed out waiting for notifyDone to be called\n", testResult); 2310 2311 auto logs = getAndResetAccumulatedLogs(); 2312 if (!logs.isEmpty()) 2313 fprintf(testResult, "Logs accumulated during test run:\n%s\n", logs.utf8().data()); 2353 2314 2354 2315 notifyDone(); … … 2404 2365 } 2405 2366 2406 typedef WTF::HashMap<unsigned, JSValueRef> CallbackMap;2367 using CallbackMap = WTF::HashMap<unsigned, JSObjectRef>; 2407 2368 static CallbackMap& callbackMap() 2408 2369 { … … 2411 2372 } 2412 2373 2413 void TestRunner::cacheTestRunnerCallback(unsigned index, JSValueRef callback) 2414 { 2415 if (!callback) 2374 void TestRunner::cacheTestRunnerCallback(unsigned index, JSValueRef callbackValue) 2375 { 2376 auto context = mainFrameJSContext(); 2377 if (!callbackValue || !JSValueIsObject(context, callbackValue)) 2416 2378 return; 2379 auto callback = (JSObjectRef)callbackValue; 2417 2380 2418 2381 if (callbackMap().contains(index)) { 2419 fprintf(stderr, "FAIL: Tried to install a second TestRunner callback for the same event (id % d)\n", index);2382 fprintf(stderr, "FAIL: Tried to install a second TestRunner callback for the same event (id %u)\n", index); 2420 2383 return; 2421 2384 } 2422 2385 2423 JSContextRef context = mainFrameJSContext();2424 2386 JSValueProtect(context, callback); 2425 2387 callbackMap().add(index, callback); … … 2431 2393 return; 2432 2394 2433 JSContextRefcontext = mainFrameJSContext();2434 if ( JSObjectRef callback = JSValueToObject(context, callbackMap().take(index), 0)) {2435 JSObjectCallAsFunction(context, callback, JSContextGetGlobalObject(context), argumentCount, arguments, 0);2395 auto context = mainFrameJSContext(); 2396 if (auto callback = callbackMap().take(index)) { 2397 JSObjectCallAsFunction(context, callback, JSContextGetGlobalObject(context), argumentCount, arguments, nullptr); 2436 2398 JSValueUnprotect(context, callback); 2437 2399 } … … 2440 2402 void TestRunner::clearTestRunnerCallbacks() 2441 2403 { 2442 JSContextRef context = mainFrameJSContext(); 2443 2444 for (auto& iter : callbackMap()) { 2445 if (JSObjectRef callback = JSValueToObject(context, iter.value, 0)) 2446 JSValueUnprotect(context, callback); 2447 } 2448 2404 auto context = mainFrameJSContext(); 2405 for (auto& callback : callbackMap().values()) 2406 JSValueUnprotect(context, callback); 2449 2407 callbackMap().clear(); 2450 2408 } … … 2509 2467 if (!JSValueIsArray(context, filesValue)) 2510 2468 return; 2511 2512 JSObjectRef files = JSValueToObject(context, filesValue, nullptr); 2513 static auto lengthProperty = adopt(JSStringCreateWithUTF8CString("length")); 2514 JSValueRef filesLengthValue = JSObjectGetProperty(context, files, lengthProperty.get(), nullptr); 2515 if (!JSValueIsNumber(context, filesLengthValue)) 2516 return; 2469 auto files = (JSObjectRef)filesValue; 2470 auto filesLength = WTR::arrayLength(context, files); 2517 2471 2518 2472 m_openPanelFiles.clear(); 2519 auto filesLength = static_cast<size_t>(JSValueToNumber(context, filesLengthValue, nullptr)); 2520 for (size_t i = 0; i < filesLength; ++i) { 2473 for (unsigned i = 0; i < filesLength; ++i) { 2521 2474 JSValueRef fileValue = JSObjectGetPropertyAtIndex(context, files, i, nullptr); 2522 2475 if (!JSValueIsString(context, fileValue)) -
TabularUnified trunk/Tools/DumpRenderTree/TestRunner.h ¶
r267098 r267761 55 55 void cleanup(); 56 56 57 void makeWindowObject(JSContextRef , JSObjectRef windowObject, JSValueRef* exception);57 void makeWindowObject(JSContextRef); 58 58 59 59 void addDisallowedURL(JSStringRef url); … … 498 498 #endif 499 499 500 static JS ClassRef getJSClass();501 static JSStaticValue* staticValues();502 static JSStaticFunction* staticFunctions();500 static JSRetainPtr<JSClassRef> createJSClass(); 501 static const JSStaticValue* staticValues(); 502 static const JSStaticFunction* staticFunctions(); 503 503 }; -
TabularUnified trunk/Tools/DumpRenderTree/ios/AccessibilityControllerIOS.mm ¶
r236032 r267761 25 25 26 26 #import "config.h" 27 #import "DumpRenderTree.h"28 27 #import "AccessibilityController.h" 29 28 … … 31 30 #import "AccessibilityNotificationHandler.h" 32 31 #import "AccessibilityUIElement.h" 32 #import "DumpRenderTree.h" 33 #import "JSBasics.h" 33 34 #import <Foundation/Foundation.h> 34 35 #import <WebKit/WebFramePrivate.h> … … 156 157 JSRetainPtr<JSStringRef> AccessibilityController::platformName() const 157 158 { 158 return adopt(JSStringCreateWithUTF8CString("ios"));159 return WTR::createJSString("ios"); 159 160 } -
TabularUnified trunk/Tools/DumpRenderTree/ios/AccessibilityUIElementIOS.mm ¶
r264000 r267761 25 25 26 26 #import "config.h" 27 #import "DumpRenderTree.h"28 27 #import "AccessibilityUIElement.h" 29 28 30 29 #import "AccessibilityCommonMac.h" 31 30 #import "AccessibilityNotificationHandler.h" 31 #import "DumpRenderTree.h" 32 #import "JSBasics.h" 32 33 #import <Foundation/Foundation.h> 33 34 #import <JavaScriptCore/JSStringRefCF.h> … … 41 42 42 43 typedef void (*AXPostedNotificationCallback)(id element, NSString* notification, void* context); 43 44 AccessibilityUIElement::AccessibilityUIElement(id element)45 : m_element(element)46 {47 }48 44 49 45 @interface NSObject (UIAccessibilityHidden) … … 113 109 @end 114 110 115 static JSRetainPtr<JSStringRef> createEmptyJSString()116 { 117 return adopt(JSStringCreateWithCharacters(nullptr, 0)); 111 AccessibilityUIElement::AccessibilityUIElement(id element) 112 : m_element(element) 113 { 118 114 } 119 115 … … 180 176 return nullptr; 181 177 } 182 183 178 184 179 JSRetainPtr<JSStringRef> AccessibilityUIElement::url() … … 292 287 AccessibilityUIElement AccessibilityUIElement::linkedUIElementAtIndex(unsigned index) 293 288 { 294 // FIXME: implement295 289 return 0; 296 290 } … … 559 553 id textMarkers = markerRange->platformTextMarkerRange(); 560 554 if (!textMarkers || ![textMarkers isKindOfClass:[NSArray class]]) 561 return createEmptyJSString();555 return WTR::createJSString(); 562 556 return [[m_element stringForTextMarkers:textMarkers] createJSStringRef]; 563 557 } … … 682 676 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfLinkedUIElements() 683 677 { 684 return createEmptyJSString();678 return WTR::createJSString(); 685 679 } 686 680 687 681 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfDocumentLinks() 688 682 { 689 return createEmptyJSString();683 return WTR::createJSString(); 690 684 } 691 685 692 686 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfChildren() 693 687 { 694 return createEmptyJSString();688 return WTR::createJSString(); 695 689 } 696 690 697 691 JSRetainPtr<JSStringRef> AccessibilityUIElement::allAttributes() 698 692 { 699 return createEmptyJSString();693 return WTR::createJSString(); 700 694 } 701 695 … … 717 711 return [[m_element accessibilityTextualContext] createJSStringRef]; 718 712 719 return createEmptyJSString();713 return WTR::createJSString(); 720 714 } 721 715 … … 756 750 JSRetainPtr<JSStringRef> AccessibilityUIElement::parameterizedAttributeNames() 757 751 { 758 return createEmptyJSString();752 return WTR::createJSString(); 759 753 } 760 754 761 755 JSRetainPtr<JSStringRef> AccessibilityUIElement::role() 762 756 { 763 return createEmptyJSString();757 return WTR::createJSString(); 764 758 } 765 759 766 760 JSRetainPtr<JSStringRef> AccessibilityUIElement::subrole() 767 761 { 768 return createEmptyJSString();762 return WTR::createJSString(); 769 763 } 770 764 … … 790 784 JSRetainPtr<JSStringRef> AccessibilityUIElement::roleDescription() 791 785 { 792 return createEmptyJSString();786 return WTR::createJSString(); 793 787 } 794 788 795 789 JSRetainPtr<JSStringRef> AccessibilityUIElement::computedRoleString() 796 790 { 797 return createEmptyJSString();791 return WTR::createJSString(); 798 792 } 799 793 800 794 JSRetainPtr<JSStringRef> AccessibilityUIElement::title() 801 795 { 802 return createEmptyJSString();796 return WTR::createJSString(); 803 797 } 804 798 … … 810 804 JSRetainPtr<JSStringRef> AccessibilityUIElement::orientation() const 811 805 { 812 return createEmptyJSString();806 return WTR::createJSString(); 813 807 } 814 808 … … 820 814 JSRetainPtr<JSStringRef> AccessibilityUIElement::language() 821 815 { 822 return createEmptyJSString();816 return WTR::createJSString(); 823 817 } 824 818 … … 850 844 JSRetainPtr<JSStringRef> AccessibilityUIElement::valueDescription() 851 845 { 852 return createEmptyJSString();846 return WTR::createJSString(); 853 847 } 854 848 … … 870 864 bool AccessibilityUIElement::isFocused() const 871 865 { 872 // FIXME: implement873 866 return false; 874 867 } … … 893 886 bool AccessibilityUIElement::isIndeterminate() const 894 887 { 895 // FIXME: implement896 888 return false; 897 889 } … … 909 901 JSRetainPtr<JSStringRef> AccessibilityUIElement::ariaDropEffects() const 910 902 { 911 return createEmptyJSString();903 return WTR::createJSString(); 912 904 } 913 905 … … 919 911 JSRetainPtr<JSStringRef> AccessibilityUIElement::boundsForRange(unsigned location, unsigned length) 920 912 { 921 return createEmptyJSString();913 return WTR::createJSString(); 922 914 } 923 915 924 916 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfColumnHeaders() 925 917 { 926 return createEmptyJSString();918 return WTR::createJSString(); 927 919 } 928 920 929 921 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfRowHeaders() 930 922 { 931 return createEmptyJSString();923 return WTR::createJSString(); 932 924 } 933 925 934 926 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfColumns() 935 927 { 936 return createEmptyJSString();928 return WTR::createJSString(); 937 929 } 938 930 939 931 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfRows() 940 932 { 941 return createEmptyJSString();933 return WTR::createJSString(); 942 934 } 943 935 944 936 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfVisibleCells() 945 937 { 946 return createEmptyJSString();938 return WTR::createJSString(); 947 939 } 948 940 949 941 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfHeader() 950 942 { 951 return createEmptyJSString();943 return WTR::createJSString(); 952 944 } 953 945 … … 988 980 void AccessibilityUIElement::scrollToMakeVisible() 989 981 { 990 // FIXME: implement991 982 } 992 983 993 984 void AccessibilityUIElement::scrollToMakeVisibleWithSubFocus(int x, int y, int width, int height) 994 985 { 995 // FIXME: implement996 986 } 997 987 998 988 void AccessibilityUIElement::scrollToGlobalPoint(int x, int y) 999 989 { 1000 // FIXME: implement1001 990 } 1002 991 1003 992 JSRetainPtr<JSStringRef> AccessibilityUIElement::selectedTextRange() 1004 993 { 1005 return createEmptyJSString();994 return WTR::createJSString(); 1006 995 } 1007 996 … … 1036 1025 JSRetainPtr<JSStringRef> AccessibilityUIElement::accessibilityValue() const 1037 1026 { 1038 // FIXME: implement 1039 return createEmptyJSString(); 1027 return WTR::createJSString(); 1040 1028 } 1041 1029 1042 1030 void AccessibilityUIElement::clearSelectedChildren() const 1043 1031 { 1044 // FIXME: implement1045 1032 } 1046 1033 1047 1034 JSRetainPtr<JSStringRef> AccessibilityUIElement::documentEncoding() 1048 1035 { 1049 return createEmptyJSString();1036 return WTR::createJSString(); 1050 1037 } 1051 1038 1052 1039 JSRetainPtr<JSStringRef> AccessibilityUIElement::documentURI() 1053 1040 { 1054 return createEmptyJSString();1041 return WTR::createJSString(); 1055 1042 } 1056 1043 … … 1084 1071 bool AccessibilityUIElement::isFocusable() const 1085 1072 { 1086 // FIXME: implement1087 1073 return false; 1088 1074 } … … 1090 1076 bool AccessibilityUIElement::isSelectable() const 1091 1077 { 1092 // FIXME: implement1093 1078 return false; 1094 1079 } … … 1096 1081 bool AccessibilityUIElement::isMultiSelectable() const 1097 1082 { 1098 // FIXME: implement1099 1083 return false; 1100 1084 } … … 1102 1086 bool AccessibilityUIElement::isSelectedOptionActive() const 1103 1087 { 1104 // FIXME: implement1105 1088 return false; 1106 1089 } … … 1108 1091 bool AccessibilityUIElement::isVisible() const 1109 1092 { 1110 // FIXME: implement1111 1093 return false; 1112 1094 } … … 1114 1096 bool AccessibilityUIElement::isOffScreen() const 1115 1097 { 1116 // FIXME: implement1117 1098 return false; 1118 1099 } … … 1120 1101 bool AccessibilityUIElement::isCollapsed() const 1121 1102 { 1122 // FIXME: implement1123 1103 return false; 1124 1104 } … … 1131 1111 bool AccessibilityUIElement::isSingleLine() const 1132 1112 { 1133 // FIXME: implement1134 1113 return false; 1135 1114 } … … 1137 1116 bool AccessibilityUIElement::isMultiLine() const 1138 1117 { 1139 // FIXME: implement1140 1118 return false; 1141 1119 } … … 1153 1131 void AccessibilityUIElement::takeFocus() 1154 1132 { 1155 // FIXME: implement1156 1133 } 1157 1134 1158 1135 void AccessibilityUIElement::takeSelection() 1159 1136 { 1160 // FIXME: implement1161 1137 } 1162 1138 1163 1139 void AccessibilityUIElement::addSelection() 1164 1140 { 1165 // FIXME: implement1166 1141 } 1167 1142 1168 1143 void AccessibilityUIElement::removeSelection() 1169 1144 { 1170 // FIXME: implement1171 1145 } 1172 1146 1173 1147 unsigned AccessibilityUIElement::uiElementCountForSearchPredicate(JSContextRef context, AccessibilityUIElement* startElement, bool isDirectionNext, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly, bool immediateDescendantsOnly) 1174 1148 { 1175 // FIXME: implement1176 1149 return 0; 1177 1150 } … … 1215 1188 JSRetainPtr<JSStringRef> AccessibilityUIElement::classList() const 1216 1189 { 1217 // FIXME: implement1218 1190 return nullptr; 1219 1191 } … … 1221 1193 void AccessibilityUIElement::uiElementArrayAttributeValue(JSStringRef, Vector<AccessibilityUIElement>&) const 1222 1194 { 1223 // FIXME: implement1224 1195 } 1225 1196 1226 1197 void AccessibilityUIElement::columnHeaders(Vector<AccessibilityUIElement>&) const 1227 1198 { 1228 // FIXME: implement1229 1199 } 1230 1200 1231 1201 void AccessibilityUIElement::rowHeaders(Vector<AccessibilityUIElement>&) const 1232 1202 { 1233 // FIXME: implement1234 1203 } 1235 1204 -
TabularUnified trunk/Tools/DumpRenderTree/mac/AccessibilityCommonMac.h ¶
r260366 r267761 42 42 @end 43 43 44 externNSDictionary *searchPredicateParameterizedAttributeForSearchCriteria(JSContextRef, AccessibilityUIElement *startElement, bool isDirectionNext, unsigned resultsLimit, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly, bool immediateDescendantsOnly);44 NSDictionary *searchPredicateParameterizedAttributeForSearchCriteria(JSContextRef, AccessibilityUIElement *startElement, bool isDirectionNext, unsigned resultsLimit, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly, bool immediateDescendantsOnly); -
TabularUnified trunk/Tools/DumpRenderTree/mac/AccessibilityCommonMac.mm ¶
r259843 r267761 32 32 #import "AccessibilityCommonMac.h" 33 33 34 #import "JSBasics.h" 34 35 #import <JavaScriptCore/JSStringRefCF.h> 35 36 … … 57 58 58 59 [parameterizedAttribute setObject:(isDirectionNext) ? @"AXDirectionNext" : @"AXDirectionPrevious" forKey:@"AXDirection"]; 59 60 60 [parameterizedAttribute setObject:@(resultsLimit) forKey:@"AXResultsLimit"]; 61 61 … … 67 67 searchKeyParameter = [NSString stringWithJSStringRef:searchKeyString.get()]; 68 68 } else if (JSValueIsObject(context, searchKey)) { 69 JSObjectRef searchKeyArray = JSValueToObject(context, searchKey, nullptr); 70 unsigned searchKeyArrayLength = 0; 71 72 auto lengthPropertyString = adopt(JSStringCreateWithUTF8CString("length")); 73 JSValueRef searchKeyArrayLengthValue = JSObjectGetProperty(context, searchKeyArray, lengthPropertyString.get(), nullptr); 74 if (searchKeyArrayLengthValue && JSValueIsNumber(context, searchKeyArrayLengthValue)) 75 searchKeyArrayLength = static_cast<unsigned>(JSValueToNumber(context, searchKeyArrayLengthValue, nullptr)); 76 69 JSObjectRef searchKeyArray = (JSObjectRef)searchKey; 70 unsigned searchKeyArrayLength = WTR::arrayLength(context, searchKeyArray); 77 71 for (unsigned i = 0; i < searchKeyArrayLength; ++i) { 78 72 JSValueRef searchKeyValue = JSObjectGetPropertyAtIndex(context, searchKeyArray, i, nullptr); … … 89 83 [parameterizedAttribute setObject:searchKeyParameter forKey:@"AXSearchKey"]; 90 84 } 91 85 92 86 if (searchText && JSStringGetLength(searchText)) 93 87 [parameterizedAttribute setObject:[NSString stringWithJSStringRef:searchText] forKey:@"AXSearchText"]; 94 88 95 89 [parameterizedAttribute setObject:@(visibleOnly) forKey:@"AXVisibleOnly"]; 96 97 90 [parameterizedAttribute setObject:@(immediateDescendantsOnly) forKey:@"AXImmediateDescendantsOnly"]; 98 91 -
TabularUnified trunk/Tools/DumpRenderTree/mac/AccessibilityControllerMac.mm ¶
r236032 r267761 31 31 #import "AccessibilityNotificationHandler.h" 32 32 #import "AccessibilityUIElement.h" 33 #import "JSBasics.h" 33 34 #import <AppKit/NSColor.h> 34 35 #import <Foundation/Foundation.h> … … 159 160 JSRetainPtr<JSStringRef> AccessibilityController::platformName() const 160 161 { 161 return adopt(JSStringCreateWithUTF8CString("mac"));162 return WTR::createJSString("mac"); 162 163 } -
TabularUnified trunk/Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm ¶
r264000 r267761 30 30 #import "AccessibilityNotificationHandler.h" 31 31 #import "DumpRenderTree.h" 32 #import "JSBasics.h" 32 33 #import <Foundation/Foundation.h> 33 34 #import <JavaScriptCore/JSStringRefCF.h> … … 80 81 - (void)_accessibilitySetValue:(id)value forAttribute:(NSString*)attributeName; 81 82 @end 82 83 static JSRetainPtr<JSStringRef> createEmptyJSString()84 {85 return adopt(JSStringCreateWithCharacters(nullptr, 0));86 }87 83 88 84 static Optional<AccessibilityUIElement> makeVectorElement(const AccessibilityUIElement*, id element) … … 222 218 } 223 219 else if (JSValueIsObject(context, searchStrings)) { 224 JSObjectRef searchStringsArray = JSValueToObject(context, searchStrings, nullptr); 225 unsigned searchStringsArrayLength = 0; 226 227 auto lengthPropertyString = adopt(JSStringCreateWithUTF8CString("length")); 228 JSValueRef searchStringsArrayLengthValue = JSObjectGetProperty(context, searchStringsArray, lengthPropertyString.get(), nullptr); 229 if (searchStringsArrayLengthValue && JSValueIsNumber(context, searchStringsArrayLengthValue)) 230 searchStringsArrayLength = static_cast<unsigned>(JSValueToNumber(context, searchStringsArrayLengthValue, nullptr)); 231 220 auto searchStringsArray = (JSObjectRef)searchStrings; 221 auto searchStringsArrayLength = WTR::arrayLength(context, searchStringsArray); 232 222 for (unsigned i = 0; i < searchStringsArrayLength; ++i) { 233 223 auto searchStringsString = adopt(JSValueToStringCopy(context, JSObjectGetPropertyAtIndex(context, searchStringsArray, i, nullptr), nullptr)); … … 263 253 [searchStringsParameter addObject:[NSString stringWithJSStringRef:searchStringsString.get()]]; 264 254 } else if (JSValueIsObject(context, searchStrings)) { 265 JSObjectRef searchStringsArray = JSValueToObject(context, searchStrings, nullptr); 266 unsigned searchStringsArrayLength = 0; 267 268 auto lengthPropertyString = adopt(JSStringCreateWithUTF8CString("length")); 269 JSValueRef searchStringsArrayLengthValue = JSObjectGetProperty(context, searchStringsArray, lengthPropertyString.get(), nullptr); 270 if (searchStringsArrayLengthValue && JSValueIsNumber(context, searchStringsArrayLengthValue)) 271 searchStringsArrayLength = static_cast<unsigned>(JSValueToNumber(context, searchStringsArrayLengthValue, nullptr)); 272 255 auto searchStringsArray = (JSObjectRef)searchStrings; 256 auto searchStringsArrayLength = WTR::arrayLength(context, searchStringsArray); 273 257 for (unsigned i = 0; i < searchStringsArrayLength; ++i) { 274 258 auto searchStringsString = adopt(JSValueToStringCopy(context, JSObjectGetPropertyAtIndex(context, searchStringsArray, i, nullptr), nullptr)); … … 1447 1431 void AccessibilityUIElement::clearSelectedChildren() const 1448 1432 { 1449 // FIXME: implement1433 // FIXME: Implement this function. 1450 1434 } 1451 1435 1452 1436 JSRetainPtr<JSStringRef> AccessibilityUIElement::accessibilityValue() const 1453 1437 { 1454 // FIXME: implement1455 return createEmptyJSString();1438 // FIXME: Implement this function. 1439 return WTR::createJSString(); 1456 1440 } 1457 1441 … … 1464 1448 END_AX_OBJC_EXCEPTIONS 1465 1449 1466 return createEmptyJSString();1450 return WTR::createJSString(); 1467 1451 } 1468 1452 … … 1475 1459 END_AX_OBJC_EXCEPTIONS 1476 1460 1477 return createEmptyJSString();1461 return WTR::createJSString(); 1478 1462 } 1479 1463 -
TabularUnified trunk/Tools/DumpRenderTree/mac/FrameLoadDelegate.mm ¶
r267640 r267761 312 312 - (void)didClearWindowObjectInStandardWorldForFrame:(WebFrame *)frame 313 313 { 314 // Make New-Style TestRunner 315 JSContextRef context = [frame globalContext]; 316 JSObjectRef globalObject = JSContextGetGlobalObject(context); 317 JSValueRef exception = 0; 318 319 ASSERT(gTestRunner); 320 gTestRunner->makeWindowObject(context, globalObject, &exception); 321 ASSERT(!exception); 322 323 gcController->makeWindowObject(context, globalObject, &exception); 324 ASSERT(!exception); 325 326 accessibilityController->makeWindowObject(context, globalObject, &exception); 327 ASSERT(!exception); 314 auto context = [frame globalContext]; 315 auto webView = [frame webView]; 316 auto windowObject = [frame windowObject]; 317 318 gTestRunner->makeWindowObject(context); 319 gcController->makeWindowObject(context); 320 accessibilityController->makeWindowObject(context); 328 321 329 322 WebCoreTestSupport::injectInternalsObject(context); 330 323 331 // Make Old-Style controllers 332 333 WebView *webView = [frame webView]; 334 WebScriptObject *obj = [frame windowObject]; 335 #if !PLATFORM(IOS_FAMILY) 336 AppleScriptController *asc = [[AppleScriptController alloc] initWithWebView:webView]; 337 [obj setValue:asc forKey:@"appleScriptController"]; 338 [asc release]; 339 #endif 340 341 EventSendingController *esc = [[EventSendingController alloc] init]; 342 [obj setValue:esc forKey:@"eventSender"]; 343 [esc release]; 344 345 [obj setValue:gNavigationController forKey:@"navigationController"]; 346 347 ObjCController *occ = [[ObjCController alloc] init]; 348 [obj setValue:occ forKey:@"objCController"]; 349 [occ release]; 350 351 ObjCPlugin *plugin = [[ObjCPlugin alloc] init]; 352 [obj setValue:plugin forKey:@"objCPlugin"]; 353 [plugin release]; 354 355 ObjCPluginFunction *pluginFunction = [[ObjCPluginFunction alloc] init]; 356 [obj setValue:pluginFunction forKey:@"objCPluginFunction"]; 357 [pluginFunction release]; 358 359 TextInputController *tic = [[TextInputController alloc] initWithWebView:webView]; 360 [obj setValue:tic forKey:@"textInputController"]; 361 [tic release]; 324 #if PLATFORM(MAC) 325 [windowObject setValue:adoptNS([[AppleScriptController alloc] initWithWebView:webView]).get() forKey:@"appleScriptController"]; 326 #endif 327 328 [windowObject setValue:adoptNS([[EventSendingController alloc] init]).get() forKey:@"eventSender"]; 329 [windowObject setValue:gNavigationController forKey:@"navigationController"]; 330 [windowObject setValue:adoptNS([[ObjCController alloc] init]).get() forKey:@"objCController"]; 331 [windowObject setValue:adoptNS([[ObjCPlugin alloc] init]).get() forKey:@"objCPlugin"]; 332 [windowObject setValue:adoptNS([[ObjCPluginFunction alloc] init]).get() forKey:@"objCPluginFunction"]; 333 [windowObject setValue:adoptNS([[TextInputController alloc] initWithWebView:webView]).get() forKey:@"textInputController"]; 362 334 } 363 335 … … 372 344 return; 373 345 374 JSObjectSetProperty(ctx, globalObject, adopt(JSStringCreateWithUTF8CString("__worldID")).get(), JSValueMakeNumber(ctx, worldIDForWorld(world)), kJSPropertyAttributeReadOnly, 0);346 JSObjectSetProperty(ctx, globalObject, WTR::createJSString("__worldID").get(), JSValueMakeNumber(ctx, worldIDForWorld(world)), kJSPropertyAttributeReadOnly, 0); 375 347 } 376 348 -
TabularUnified trunk/Tools/DumpRenderTree/mac/TestRunnerMac.mm ¶
r265396 r267761 33 33 #import "DefaultPolicyDelegate.h" 34 34 #import "EditingDelegate.h" 35 #import "JSBasics.h" 35 36 #import "LayoutTestSpellChecker.h" 36 37 #import "MockGeolocationProvider.h" … … 671 672 WebFindOptions options = 0; 672 673 673 auto lengthPropertyName = adopt(JSStringCreateWithUTF8CString("length")); 674 JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0); 675 if (!JSValueIsNumber(context, lengthValue)) 676 return false; 677 678 RetainPtr<CFStringRef> targetCFString = adoptCF(JSStringCopyCFString(kCFAllocatorDefault, target)); 679 680 size_t length = static_cast<size_t>(JSValueToNumber(context, lengthValue, 0)); 681 for (size_t i = 0; i < length; ++i) { 674 auto length = WTR::arrayLength(context, optionsArray); 675 auto targetCFString = adoptCF(JSStringCopyCFString(kCFAllocatorDefault, target)); 676 677 for (unsigned i = 0; i < length; ++i) { 682 678 JSValueRef value = JSObjectGetPropertyAtIndex(context, optionsArray, i, 0); 683 679 if (!JSValueIsString(context, value)) -
TabularUnified trunk/Tools/DumpRenderTree/win/FrameLoadDelegate.cpp ¶
r267640 r267761 372 372 frame->parentFrame(&parentFrame); 373 373 374 JSValueRef exception = 0; 375 376 ::gTestRunner->makeWindowObject(context, windowObject, &exception); 377 ASSERT(!exception); 378 379 m_gcController->makeWindowObject(context, windowObject, &exception); 380 ASSERT(!exception); 381 382 m_accessibilityController->makeWindowObject(context, windowObject, &exception); 383 ASSERT(!exception); 384 385 m_textInputController->makeWindowObject(context, windowObject, &exception); 386 ASSERT(!exception); 374 ::gTestRunner->makeWindowObject(context); 375 m_gcController->makeWindowObject(context); 376 m_accessibilityController->makeWindowObject(context); 377 m_textInputController->makeWindowObject(context); 387 378 388 379 JSStringRef eventSenderStr = JSStringCreateWithUTF8CString("eventSender"); -
TabularUnified trunk/Tools/DumpRenderTree/win/TextInputController.cpp ¶
r231852 r267761 31 31 #include "TextInputController.h" 32 32 33 #include <JavaScriptCore/JSRetainPtr.h>33 #include "JSBasics.h" 34 34 #include <wtf/RefPtr.h> 35 35 … … 163 163 // Object Creation 164 164 165 void TextInputController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception) 166 { 167 JSRetainPtr<JSStringRef> textInputContollerStr(Adopt, JSStringCreateWithUTF8CString("textInputController")); 168 169 JSClassRef classRef = getJSClass(); 170 JSValueRef textInputContollerObject = JSObjectMake(context, classRef, this); 171 JSClassRelease(classRef); 172 173 JSObjectSetProperty(context, windowObject, textInputContollerStr.get(), textInputContollerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception); 174 } 175 176 JSClassRef TextInputController::getJSClass() 177 { 178 static JSStaticValue* staticValues = TextInputController::staticValues(); 179 static JSStaticFunction* staticFunctions = TextInputController::staticFunctions(); 180 static JSClassDefinition classDefinition = 181 { 182 0, kJSClassAttributeNone, "TextInputController", 0, staticValues, staticFunctions, 165 void TextInputController::makeWindowObject(JSContextRef context) 166 { 167 WTR::setGlobalObjectProperty(context, "textInputController", JSObjectMake(context, createJSClass().get(), this)); 168 } 169 170 JSRetainPtr<JSClassRef> TextInputController::createJSClass() 171 { 172 const JSClassDefinition classDefinition = { 173 0, kJSClassAttributeNone, "TextInputController", 0, staticValues(), staticFunctions(), 183 174 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 184 175 }; 185 186 return JSClassCreate(&classDefinition); 187 } 188 189 JSStaticValue* TextInputController::staticValues() 190 { 191 static JSStaticValue staticValues[] = 176 return adopt(JSClassCreate(&classDefinition)); 177 } 178 179 const JSStaticValue* TextInputController::staticValues() 180 { 181 static const JSStaticValue staticValues[] = 192 182 { 193 183 { 0, 0, 0, 0 } … … 196 186 } 197 187 198 JSStaticFunction* TextInputController::staticFunctions()199 { 200 static JSStaticFunction staticFunctions[] = {188 const JSStaticFunction* TextInputController::staticFunctions() 189 { 190 static const JSStaticFunction staticFunctions[] = { 201 191 { "setMarkedText", setMarkedTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, 202 192 { "hasMarkedText", hasMarkedTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, -
TabularUnified trunk/Tools/DumpRenderTree/win/TextInputController.h ¶
r248762 r267761 27 27 */ 28 28 29 #ifndef TextInputController_h 30 #define TextInputController_h 29 #pragma once 31 30 32 #include <JavaScriptCore/JSContextRef.h> 33 #include <JavaScriptCore/JSObjectRef.h> 34 #include <JavaScriptCore/JSStringRef.h> 35 #include <JavaScriptCore/JSValueRef.h> 31 #include <JavaScriptCore/JSRetainPtr.h> 36 32 #include <vector> 37 33 #include <wtf/FastMalloc.h> … … 40 36 WTF_MAKE_FAST_ALLOCATED; 41 37 public: 42 void makeWindowObject(JSContextRef , JSObjectRef windowObject, JSValueRef* exception);38 void makeWindowObject(JSContextRef); 43 39 44 40 void setMarkedText(JSStringRef text, unsigned int from, unsigned int length); … … 51 47 52 48 private: 53 static JS ClassRef getJSClass();54 static JSStaticValue* staticValues();55 static JSStaticFunction* staticFunctions();49 static JSRetainPtr<JSClassRef> createJSClass(); 50 static const JSStaticValue* staticValues(); 51 static const JSStaticFunction* staticFunctions(); 56 52 }; 57 58 #endif // TextInputController_h -
TabularUnified trunk/Tools/TestRunnerShared/Bindings/JSBasics.cpp ¶
r266988 r267761 29 29 namespace WTR { 30 30 31 JSValueRef JSValueMakeBooleanOrNull(JSContextRef context, Optional<bool> value) 31 Optional<bool> toOptionalBool(JSContextRef context, JSValueRef value) 32 { 33 return JSValueIsUndefined(context, value) || JSValueIsNull(context, value) ? WTF::nullopt : makeOptional(JSValueToBoolean(context, value)); 34 } 35 36 Optional<double> toOptionalDouble(JSContextRef context, JSValueRef value) 37 { 38 return JSValueIsUndefined(context, value) || JSValueIsNull(context, value) ? WTF::nullopt : makeOptional(JSValueToNumber(context, value, nullptr)); 39 } 40 41 JSValueRef makeValue(JSContextRef context, Optional<bool> value) 32 42 { 33 43 return value ? JSValueMakeBoolean(context, value.value()) : JSValueMakeNull(context); 34 44 } 35 45 36 Optional<bool> JSValueToNullableBoolean(JSContextRef context, JSValueRef value)46 JSValueRef makeValue(JSContextRef context, JSStringRef string) 37 47 { 38 return JSValueIsUndefined(context, value) || JSValueIsNull(context, value) ? WTF::nullopt : Optional<bool>(JSValueToBoolean(context, value)); 39 } 40 41 JSValueRef JSValueMakeStringOrNull(JSContextRef context, JSStringRef stringOrNull) 42 { 43 return stringOrNull ? JSValueMakeString(context, stringOrNull) : JSValueMakeNull(context); 48 return string ? JSValueMakeString(context, string) : JSValueMakeNull(context); 44 49 } 45 50 … … 49 54 } 50 55 56 JSRetainPtr<JSStringRef> createJSString(JSContextRef context, JSValueRef value) 57 { 58 auto string = adopt(value ? JSValueToStringCopy(context, value, nullptr) : nullptr); 59 return string ? string : createJSString(""); 60 } 61 51 62 JSValueRef makeValue(JSContextRef context, const char* string) 52 63 { … … 54 65 } 55 66 67 JSValueRef property(JSContextRef context, JSObjectRef object, const char* name) 68 { 69 return object ? JSObjectGetProperty(context, object, createJSString(name).get(), nullptr) : nullptr; 70 } 71 72 JSRetainPtr<JSStringRef> stringProperty(JSContextRef context, JSObjectRef object, const char* name) 73 { 74 return createJSString(context, property(context, object, name)); 75 } 76 77 bool booleanProperty(JSContextRef context, JSObjectRef object, const char* name, bool defaultValue) 78 { 79 auto value = property(context, object, name); 80 return value ? JSValueToBoolean(context, value) : defaultValue; 81 } 82 83 double numericProperty(JSContextRef context, JSObjectRef object, const char* name) 84 { 85 auto value = property(context, object, name); 86 return value ? JSValueToNumber(context, value, nullptr) : 0; 87 } 88 56 89 JSObjectRef objectProperty(JSContextRef context, JSObjectRef object, const char* name) 57 90 { 58 if (!object) 59 return nullptr; 60 auto value = JSObjectGetProperty(context, object, createJSString(name).get(), nullptr); 61 if (!JSValueIsObject(context, value)) 62 return nullptr; 63 return const_cast<JSObjectRef>(value); 91 auto value = property(context, object, name); 92 return value ? JSValueToObject(context, property(context, object, name), nullptr) : nullptr; 64 93 } 65 94 … … 71 100 } 72 101 102 unsigned arrayLength(JSContextRef context, JSObjectRef object) 103 { 104 return numericProperty(context, object, "length"); 105 } 106 73 107 void setProperty(JSContextRef context, JSObjectRef object, const char* name, bool value) 74 108 { … … 76 110 } 77 111 112 void setProperty(JSContextRef context, JSObjectRef object, const char* name, double value) 113 { 114 JSObjectSetProperty(context, object, createJSString(name).get(), JSValueMakeNumber(context, value), kJSPropertyAttributeNone, nullptr); 115 } 116 117 void setGlobalObjectProperty(JSContextRef context, const char* name, JSValueRef value) 118 { 119 JSObjectSetProperty(context, JSContextGetGlobalObject(context), createJSString(name).get(), value, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, nullptr); 120 } 121 122 void setGlobalObjectProperty(JSContextRef context, const char* name, double value) 123 { 124 setGlobalObjectProperty(context, name, JSValueMakeNumber(context, value)); 125 } 126 78 127 JSValueRef call(JSContextRef context, JSObjectRef object, const char* name, std::initializer_list<JSValueRef> arguments) 79 128 { 80 if (!object)81 return nullptr;82 129 auto function = objectProperty(context, object, name); 83 if (!function) 84 return nullptr; 85 return JSObjectCallAsFunction(context, function, object, arguments.size(), arguments.begin(), nullptr); 130 return function ? JSObjectCallAsFunction(context, function, object, arguments.size(), arguments.begin(), nullptr) : nullptr; 86 131 } 87 132 … … 89 134 { 90 135 auto constructor = objectProperty(context, JSContextGetGlobalObject(context), { name }); 91 if (!constructor) 92 return nullptr; 93 return JSObjectCallAsConstructor(context, constructor, arguments.size(), arguments.begin(), nullptr); 136 return constructor ? JSObjectCallAsConstructor(context, constructor, arguments.size(), arguments.begin(), nullptr) : nullptr; 94 137 } 95 138 -
TabularUnified trunk/Tools/TestRunnerShared/Bindings/JSBasics.h ¶
r266988 r267761 33 33 namespace WTR { 34 34 35 JSValueRef JSValueMakeBooleanOrNull(JSContextRef, Optional<bool>);36 Optional< bool> JSValueToNullableBoolean(JSContextRef, JSValueRef);35 Optional<bool> toOptionalBool(JSContextRef, JSValueRef); 36 Optional<double> toOptionalDouble(JSContextRef, JSValueRef); 37 37 38 JSValueRef JSValueMakeStringOrNull(JSContextRef, JSStringRef); 38 JSRetainPtr<JSStringRef> createJSString(const char* = ""); 39 JSRetainPtr<JSStringRef> createJSString(JSContextRef, JSValueRef); 39 40 40 JSRetainPtr<JSStringRef> createJSString(const char*);41 41 JSValueRef makeValue(JSContextRef, const char*); 42 JSValueRef makeValue(JSContextRef, Optional<bool>); 43 JSValueRef makeValue(JSContextRef, JSStringRef); 44 45 JSValueRef property(JSContextRef, JSObjectRef, const char* name); 46 bool booleanProperty(JSContextRef, JSObjectRef, const char* name, bool defaultValue = false); 47 double numericProperty(JSContextRef, JSObjectRef, const char* name); 48 JSRetainPtr<JSStringRef> stringProperty(JSContextRef, JSObjectRef, const char* name); 49 unsigned arrayLength(JSContextRef, JSObjectRef); 42 50 JSObjectRef objectProperty(JSContextRef, JSObjectRef, const char* name); 43 51 JSObjectRef objectProperty(JSContextRef, JSObjectRef, std::initializer_list<const char*> names); 52 44 53 void setProperty(JSContextRef, JSObjectRef, const char* name, bool value); 54 void setProperty(JSContextRef, JSObjectRef, const char* name, double value); 55 56 void setGlobalObjectProperty(JSContextRef, const char* name, JSValueRef); 57 void setGlobalObjectProperty(JSContextRef, const char* name, double value); 58 45 59 JSValueRef call(JSContextRef, JSObjectRef, const char* name, std::initializer_list<JSValueRef> arguments); 46 60 JSObjectRef callConstructor(JSGlobalContextRef, const char* name, std::initializer_list<JSValueRef> arguments); -
TabularUnified trunk/Tools/TestRunnerShared/Bindings/JSWrappable.h ¶
r266988 r267761 26 26 #pragma once 27 27 28 #include <JavaScriptCore/JavaScript.h>29 28 #include <wtf/RefCounted.h> 29 30 typedef struct OpaqueJSClass* JSClassRef; 30 31 31 32 namespace WTR { -
TabularUnified trunk/Tools/TestRunnerShared/Bindings/JSWrapper.h ¶
r266988 r267761 51 51 } 52 52 53 inline void setGlobalObjectProperty(JSContextRef context, const char* propertyName, JSWrappable* value) 54 { 55 setGlobalObjectProperty(context, propertyName, JSWrapper::wrap(context, value)); 56 } 57 53 58 } // namespace WTR -
TabularUnified trunk/Tools/TestRunnerShared/EventSerialization/mac/EventSerializerMac.mm ¶
r236303 r267761 196 196 + (NSDictionary *)dictionaryForEvent:(CGEventRef)rawEvent relativeToTime:(CGEventTimestamp)referenceTimestamp 197 197 { 198 RetainPtr<CGEventRef>plainEvent = adoptCF(CGEventCreate(NULL));198 auto plainEvent = adoptCF(CGEventCreate(NULL)); 199 199 CGEventRef rawPlainEvent = plainEvent.get(); 200 200 … … 227 227 + (RetainPtr<CGEventRef>)createEventForDictionary:(NSDictionary *)dict inWindow:(NSWindow *)window relativeToTime:(CGEventTimestamp)referenceTimestamp 228 228 { 229 RetainPtr<CGEventRef>event = adoptCF(CGEventCreate(NULL));229 auto event = adoptCF(CGEventCreate(NULL)); 230 230 CGEventRef rawEvent = event.get(); 231 231 … … 265 265 + (void)playStream:(NSArray<NSDictionary *> *)eventDicts window:(NSWindow *)window completionHandler:(void(^)())completionHandler 266 266 { 267 RetainPtr<EventStreamPlayer>player = adoptNS([[EventStreamPlayer alloc] init]);267 auto player = adoptNS([[EventStreamPlayer alloc] init]); 268 268 269 269 player->_remainingEventDictionaries = adoptNS([eventDicts mutableCopy]); … … 283 283 NSEvent *nsEvent = nil; 284 284 for (id eventDict in _remainingEventDictionaries.get()) { 285 RetainPtr<CGEventRef>event = [EventSerializer createEventForDictionary:eventDict inWindow:_window.get() relativeToTime:_startTime];285 auto event = [EventSerializer createEventForDictionary:eventDict inWindow:_window.get() relativeToTime:_startTime]; 286 286 if (CGEventGetTimestamp(event.get()) < mach_absolute_time()) { 287 287 nsEvent = [NSEvent eventWithCGEvent:event.get()]; -
TabularUnified trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptContext.cpp ¶
r267030 r267761 27 27 #include "UIScriptContext.h" 28 28 29 #include "JSBasics.h" 29 30 #include "UIScriptController.h" 30 #include <JavaScriptCore/JSContextRef.h>31 #include <JavaScriptCore/JSValueRef.h>32 31 #include <WebCore/FloatRect.h> 33 32 … … 44 43 { 45 44 m_controller = factory(*this); 46 47 JSObjectRef globalObject = JSContextGetGlobalObject(m_context.get()); 48 49 JSValueRef exception = nullptr; 50 m_controller->makeWindowObject(m_context.get(), globalObject, &exception); 45 m_controller->makeWindowObject(m_context.get()); 51 46 } 52 47 … … 67 62 68 63 if (!hasOutstandingAsyncTasks()) { 69 JSValueRef stringifyException = nullptr; 70 auto stringified = adopt(JSValueToStringCopy(m_context.get(), result, &stringifyException)); 71 requestUIScriptCompletion(stringified.get()); 64 requestUIScriptCompletion(createJSString(m_context.get(), result).get()); 72 65 tryToCompleteUIScriptForCurrentParentCallback(); 73 66 } … … 190 183 JSObjectRef object = JSObjectMake(m_context.get(), nullptr, nullptr); 191 184 192 JSObjectSetProperty(m_context.get(), object, adopt(JSStringCreateWithUTF8CString("left")).get(), JSValueMakeNumber(m_context.get(), rect.x()), kJSPropertyAttributeNone, nullptr);193 JSObjectSetProperty(m_context.get(), object, adopt(JSStringCreateWithUTF8CString("top")).get(), JSValueMakeNumber(m_context.get(), rect.y()), kJSPropertyAttributeNone, nullptr);194 JSObjectSetProperty(m_context.get(), object, adopt(JSStringCreateWithUTF8CString("width")).get(), JSValueMakeNumber(m_context.get(), rect.width()), kJSPropertyAttributeNone, nullptr);195 JSObjectSetProperty(m_context.get(), object, adopt(JSStringCreateWithUTF8CString("height")).get(), JSValueMakeNumber(m_context.get(), rect.height()), kJSPropertyAttributeNone, nullptr);185 setProperty(m_context.get(), object, "left", rect.x()); 186 setProperty(m_context.get(), object, "top", rect.y()); 187 setProperty(m_context.get(), object, "width", rect.width()); 188 setProperty(m_context.get(), object, "height", rect.height()); 196 189 197 190 return object; -
TabularUnified trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h ¶
r267120 r267761 64 64 virtual void waitForOutstandingCallbacks() { /* notImplemented(); */ } 65 65 66 void makeWindowObject(JSContextRef , JSObjectRef windowObject, JSValueRef* exception);66 void makeWindowObject(JSContextRef); 67 67 68 68 // Transaction helpers -
TabularUnified trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptControllerShared.cpp ¶
r267030 r267761 42 42 DeviceOrientation::LandscapeRight 43 43 }; 44 45 auto option = adopt(JSValueToStringCopy(context, value, nullptr)); 46 if (option->string() == "portrait") 44 auto option = createJSString(context, value); 45 if (JSStringIsEqualToUTF8CString(option.get(), "portrait")) 47 46 return &values[0]; 48 49 if (option->string() == "portrait-upsidedown") 47 if (JSStringIsEqualToUTF8CString(option.get(), "portrait-upsidedown")) 50 48 return &values[1]; 51 52 if (option->string() == "landscape-left") 49 if (JSStringIsEqualToUTF8CString(option.get(), "landscape-left")) 53 50 return &values[2]; 54 55 if (option->string() == "landscape-right") 51 if (JSStringIsEqualToUTF8CString(option.get(), "landscape-right")) 56 52 return &values[3]; 57 58 53 return nullptr; 59 54 } … … 69 64 } 70 65 71 void UIScriptController::makeWindowObject(JSContextRef context , JSObjectRef windowObject, JSValueRef* exception)72 { 73 set Property(context, windowObject, "uiController", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);66 void UIScriptController::makeWindowObject(JSContextRef context) 67 { 68 setGlobalObjectProperty(context, "uiController", this); 74 69 } 75 70 -
TabularUnified trunk/Tools/TestRunnerShared/cocoa/LayoutTestSpellChecker.mm ¶
r265396 r267761 27 27 #import "LayoutTestSpellChecker.h" 28 28 29 #import <JavaScriptCore/JSRetainPtr.h>29 #import "JSBasics.h" 30 30 #import <objc/runtime.h> 31 31 #import <wtf/Assertions.h> … … 213 213 { 214 214 auto resultsObject = JSValueToObject(context, resultsValue, nullptr); 215 auto fromPropertyName = adopt(JSStringCreateWithUTF8CString("from"));216 auto toPropertyName = adopt(JSStringCreateWithUTF8CString("to"));217 auto typePropertyName = adopt(JSStringCreateWithUTF8CString("type"));218 auto replacementPropertyName = adopt(JSStringCreateWithUTF8CString("replacement"));219 auto detailsPropertyName = adopt(JSStringCreateWithUTF8CString("details"));215 auto fromPropertyName = WTR::createJSString("from"); 216 auto toPropertyName = WTR::createJSString("to"); 217 auto typePropertyName = WTR::createJSString("type"); 218 auto replacementPropertyName = WTR::createJSString("replacement"); 219 auto detailsPropertyName = WTR::createJSString("details"); 220 220 auto results = adoptNS([[NSMutableDictionary alloc] init]); 221 221 … … 229 229 for (size_t resultIndex = 0; resultIndex < JSPropertyNameArrayGetCount(resultsArrayPropertyNames); ++resultIndex) { 230 230 auto resultsObject = JSValueToObject(context, JSObjectGetPropertyAtIndex(context, resultsArray, resultIndex, nullptr), nullptr); 231 long fromValue = lroundl(JSValueToNumber(context, JSObjectGetProperty(context, resultsObject, fromPropertyName.get(), nullptr), nullptr));232 long toValue = lroundl(JSValueToNumber(context, JSObjectGetProperty(context, resultsObject, toPropertyName.get(), nullptr), nullptr));233 auto typeValue = adopt(JSValueToStringCopy(context, JSObjectGetProperty(context, resultsObject, typePropertyName.get(), nullptr), nullptr));231 long fromValue = JSValueToNumber(context, JSObjectGetProperty(context, resultsObject, fromPropertyName.get(), nullptr), nullptr); 232 long toValue = JSValueToNumber(context, JSObjectGetProperty(context, resultsObject, toPropertyName.get(), nullptr), nullptr); 233 auto typeValue = WTR::createJSString(context, JSObjectGetProperty(context, resultsObject, typePropertyName.get(), nullptr)); 234 234 auto replacementValue = JSObjectGetProperty(context, resultsObject, replacementPropertyName.get(), nullptr); 235 235 RetainPtr<CFStringRef> replacementText; 236 if (!JSValueIsUndefined(context, replacementValue)) { 237 auto replacementJSString = adopt(JSValueToStringCopy(context, replacementValue, nullptr)); 238 replacementText = adoptCF(JSStringCopyCFString(kCFAllocatorDefault, replacementJSString.get())); 239 } 236 if (!JSValueIsUndefined(context, replacementValue)) 237 replacementText = adoptCF(JSStringCopyCFString(kCFAllocatorDefault, WTR::createJSString(context, replacementValue).get())); 240 238 auto details = adoptNS([[NSMutableArray alloc] init]); 241 239 auto detailsValue = JSObjectGetProperty(context, resultsObject, detailsPropertyName.get(), nullptr); -
TabularUnified trunk/Tools/WebKitTestRunner/EventSenderProxy.h ¶
r264488 r267761 113 113 #endif 114 114 115 double m_time ;116 WKPoint m_position ;117 bool m_leftMouseButtonDown ;118 int m_clickCount ;119 double m_clickTime ;120 WKPoint m_clickPosition ;121 WKEventMouseButton m_clickButton ;115 double m_time { 0 }; 116 WKPoint m_position { }; 117 bool m_leftMouseButtonDown { false }; 118 int m_clickCount { 0 }; 119 double m_clickTime { 0 }; 120 WKPoint m_clickPosition { }; 121 WKEventMouseButton m_clickButton { kWKEventMouseButtonNoButton }; 122 122 unsigned m_mouseButtonsCurrentlyDown { 0 }; 123 123 #if PLATFORM(COCOA) 124 int eventNumber; 125 #elif PLATFORM(WPE) 126 uint32_t m_buttonState; 124 int eventNumber { 0 }; 125 #endif 126 #if PLATFORM(WPE) 127 uint32_t m_buttonState { 0 }; 127 128 Vector<struct wpe_input_touch_event_raw> m_touchEvents; 128 129 HashSet<unsigned, DefaultHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<unsigned>> m_updatedTouchEvents; -
TabularUnified trunk/Tools/WebKitTestRunner/GeolocationProviderMock.cpp ¶
r228942 r267761 64 64 } 65 65 66 void GeolocationProviderMock::setPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed, bool providesFloorLevel, doublefloorLevel)66 void GeolocationProviderMock::setPosition(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitudeAccuracy, Optional<double> heading, Optional<double> speed, Optional<double> floorLevel) 67 67 { 68 m_position.adopt(WKGeolocationPositionCreate_c(WallTime::now().secondsSinceEpoch().seconds(), latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed, providesFloorLevel, floorLevel));68 m_position.adopt(WKGeolocationPositionCreate_c(WallTime::now().secondsSinceEpoch().seconds(), latitude, longitude, accuracy, altitude.hasValue(), altitude.valueOr(0), altitudeAccuracy.hasValue(), altitudeAccuracy.valueOr(0), heading.hasValue(), heading.valueOr(0), speed.hasValue(), speed.valueOr(0), floorLevel.hasValue(), floorLevel.valueOr(0))); 69 69 70 70 m_hasError = false; -
TabularUnified trunk/Tools/WebKitTestRunner/GeolocationProviderMock.h ¶
r248762 r267761 38 38 ~GeolocationProviderMock(); 39 39 40 void setPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed, bool providesFloorLevel, doublefloorLevel);40 void setPosition(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitudeAccuracy, Optional<double> heading, Optional<double> speed, Optional<double> floorLevel); 41 41 void setPositionUnavailableError(WKStringRef errorMessage); 42 42 -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityController.cpp ¶
r265248 r267761 76 76 #endif 77 77 78 void AccessibilityController::makeWindowObject(JSContextRef context , JSObjectRef windowObject, JSValueRef* exception)79 { 80 set Property(context, windowObject, "accessibilityController", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);78 void AccessibilityController::makeWindowObject(JSContextRef context) 79 { 80 setGlobalObjectProperty(context, "accessibilityController", this); 81 81 } 82 82 … … 97 97 98 98 #if PLATFORM(COCOA) 99 99 100 Ref<AccessibilityUIElement> AccessibilityController::rootElement() 100 101 { 101 WKBundlePageRefpage = InjectedBundle::singleton().page()->page();102 auto page = InjectedBundle::singleton().page()->page(); 102 103 PlatformUIElement root = static_cast<PlatformUIElement>(WKAccessibilityRootObject(page)); 103 104 104 return AccessibilityUIElement::create(root); 105 105 } … … 107 107 Ref<AccessibilityUIElement> AccessibilityController::focusedElement() 108 108 { 109 WKBundlePageRefpage = InjectedBundle::singleton().page()->page();109 auto page = InjectedBundle::singleton().page()->page(); 110 110 PlatformUIElement focusedElement = static_cast<PlatformUIElement>(WKAccessibilityFocusedObject(page)); 111 111 return AccessibilityUIElement::create(focusedElement); -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityController.h ¶
r265248 r267761 46 46 ~AccessibilityController(); 47 47 48 void makeWindowObject(JSContextRef , JSObjectRef windowObject, JSValueRef* exception);48 void makeWindowObject(JSContextRef); 49 49 virtual JSClassRef wrapperClass(); 50 50 -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/CodeGeneratorTestRunner.pm ¶
r266311 r267761 262 262 JSClassRef ${className}::${classRefGetter}() 263 263 { 264 static JSClassRef jsClass; 265 if (!jsClass) { 264 static const JSClassRef jsClass = [] { 266 265 JSClassDefinition definition = kJSClassDefinitionEmpty; 267 266 definition.className = "@{[$type->name]}"; … … 275 274 276 275 push(@contents, <<EOF); 277 jsClass =JSClassCreate(&definition);278 } 276 return JSClassCreate(&definition); 277 }(); 279 278 return jsClass; 280 279 } … … 478 477 my ($self, $type, $argumentName) = @_; 479 478 480 return " JSValueToNullableBoolean(context, $argumentName)" if $type->name eq "boolean" && $type->isNullable;479 return "toOptionalBool(context, $argumentName)" if $type->name eq "boolean" && $type->isNullable; 481 480 return "JSValueToBoolean(context, $argumentName)" if $type->name eq "boolean"; 482 481 return "$argumentName" if $type->name eq "object"; 483 return "adopt(JSValueToStringCopy(context, $argumentName, nullptr))" if $$self{codeGenerator}->IsStringType($type); 482 return "createJSString(context, $argumentName)" if $$self{codeGenerator}->IsStringType($type); 483 return "toOptionalDouble(context, $argumentName)" if $$self{codeGenerator}->IsPrimitiveType($type) && $type->isNullable; 484 484 return "JSValueToNumber(context, $argumentName, nullptr)" if $$self{codeGenerator}->IsPrimitiveType($type); 485 485 return "to" . _implementationClassName($type) . "(context, $argumentName)"; … … 500 500 ); 501 501 502 my $nullValue = " 0";502 my $nullValue = "nullptr"; 503 503 if ($platformType eq "JSValueRef") { 504 504 $nullValue = "JSValueMakeUndefined(context)"; 505 } elsif (defined $nonPointerTypes{$platformType} && $platformType ne "double") { 506 $nullValue = "$platformType()"; 507 } 508 509 $platformType .= "*" unless defined $nonPointerTypes{$platformType}; 510 511 return "$platformType $variableName = $condition && $constructor;" if $condition && $platformType eq "bool"; 512 return "$platformType $variableName = $condition ? $constructor : $nullValue;" if $condition; 513 return "$platformType $variableName = $constructor;"; 505 } elsif (defined $nonPointerTypes{$platformType}) { 506 $nullValue = $type->isNullable ? "WTF::nullopt" : "$platformType()"; 507 } 508 509 return "bool $variableName = $condition && $constructor;" if $condition && $platformType eq "bool"; 510 return "auto $variableName = $condition ? $constructor : $nullValue;" if $condition; 511 return "auto $variableName = $constructor;"; 514 512 } 515 513 … … 519 517 520 518 return "JSValueMakeUndefined(context)" if $returnType->name eq "undefined"; 521 return " JSValueMakeBooleanOrNull(context, ${expression})" if $returnType->name eq "boolean" && $returnType->isNullable;519 return "makeValue(context, ${expression})" if $returnType->name eq "boolean" && $returnType->isNullable; 522 520 return "JSValueMakeBoolean(context, ${expression})" if $returnType->name eq "boolean"; 523 521 return "${expression}" if $returnType->name eq "object"; 524 522 return "JSValueMakeNumber(context, ${expression})" if $$self{codeGenerator}->IsPrimitiveType($returnType); 525 return " JSValueMakeStringOrNull(context, ${expression}.get())" if $$self{codeGenerator}->IsStringType($returnType);523 return "makeValue(context, ${expression}.get())" if $$self{codeGenerator}->IsStringType($returnType); 526 524 return "toJS(context, WTF::getPtr(${expression}))"; 527 525 } -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl ¶
r267750 r267761 216 216 // Geolocation 217 217 undefined setGeolocationPermission(boolean value); 218 undefined setMockGeolocationPosition(double latitude, double longitude, double accuracy, optional object altitude, optional object altitudeAccuracy, optional object heading, optional object speed, optional objectfloorLevel);218 undefined setMockGeolocationPosition(double latitude, double longitude, double accuracy, optional double? altitude, optional double? altitudeAccuracy, optional double? heading, optional double? speed, optional double? floorLevel); 219 219 undefined setMockGeolocationPositionUnavailableError(DOMString errorMessage); 220 220 boolean isGeolocationProviderActive(); -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp ¶
r261539 r267761 27 27 #include "EventSendingController.h" 28 28 29 #include "DictionaryFunctions.h" 29 30 #include "InjectedBundle.h" 30 31 #include "InjectedBundlePage.h" 31 32 #include "JSEventSendingController.h" 32 #include "StringFunctions.h"33 33 #include <WebKit/WKBundle.h> 34 34 #include <WebKit/WKBundleFrame.h> … … 53 53 54 54 #if ENABLE(CONTEXT_MENUS) 55 55 56 static JSValueRef menuItemClickCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t, const JSValueRef[], JSValueRef*) 56 57 { … … 63 64 { 64 65 MenuItemPrivateData* privateData = static_cast<MenuItemPrivateData*>(JSObjectGetPrivate(object)); 65 WKRetainPtr<WKStringRef>wkTitle = adoptWK(WKContextMenuItemCopyTitle(privateData->m_item.get()));66 auto wkTitle = adoptWK(WKContextMenuItemCopyTitle(privateData->m_item.get())); 66 67 return JSValueMakeString(context, toJS(wkTitle).get()); 67 68 } … … 73 74 MenuItemPrivateData* privateData = static_cast<MenuItemPrivateData*>(JSObjectGetPrivate(object)); 74 75 auto children = adoptWK(WKContextMenuCopySubmenuItems(privateData->m_item.get())); 75 76 JSValueRef arrayResult = JSObjectMakeArray(context, 0, 0, 0); 77 if (!WKArrayGetSize(children.get())) 78 return arrayResult; 79 80 JSObjectRef arrayObject = JSValueToObject(context, arrayResult, 0); 76 auto array = JSObjectMakeArray(context, 0, 0, 0); 81 77 for (size_t i = 0; i < WKArrayGetSize(children.get()); ++i) { 82 78 auto item = static_cast<WKContextMenuItemRef>(WKArrayGetItemAtIndex(children.get(), i)); 83 79 auto* privateData = new MenuItemPrivateData(InjectedBundle::singleton().page()->page(), item); 84 JSObjectSetPropertyAtIndex(context, array Object, i, JSObjectMake(context, getMenuItemClass(), privateData), 0);80 JSObjectSetPropertyAtIndex(context, array, i, JSObjectMake(context, getMenuItemClass(), privateData), 0); 85 81 } 86 87 return arrayResult; 82 return array; 88 83 } 89 84 … … 127 122 return menuItemClass; 128 123 } 124 129 125 #endif 130 126 131 static WKEventModifiers parseModifier( JSStringRefmodifier)132 { 133 if (JSStringIsEqualToUTF8CString(modifier , "ctrlKey"))127 static WKEventModifiers parseModifier(const JSRetainPtr<JSStringRef>& modifier) 128 { 129 if (JSStringIsEqualToUTF8CString(modifier.get(), "ctrlKey")) 134 130 return kWKEventModifiersControlKey; 135 if (JSStringIsEqualToUTF8CString(modifier , "shiftKey") || JSStringIsEqualToUTF8CString(modifier, "rangeSelectionKey"))131 if (JSStringIsEqualToUTF8CString(modifier.get(), "shiftKey") || JSStringIsEqualToUTF8CString(modifier.get(), "rangeSelectionKey")) 136 132 return kWKEventModifiersShiftKey; 137 if (JSStringIsEqualToUTF8CString(modifier , "altKey"))133 if (JSStringIsEqualToUTF8CString(modifier.get(), "altKey")) 138 134 return kWKEventModifiersAltKey; 139 if (JSStringIsEqualToUTF8CString(modifier , "metaKey"))135 if (JSStringIsEqualToUTF8CString(modifier.get(), "metaKey")) 140 136 return kWKEventModifiersMetaKey; 141 if (JSStringIsEqualToUTF8CString(modifier , "capsLockKey"))137 if (JSStringIsEqualToUTF8CString(modifier.get(), "capsLockKey")) 142 138 return kWKEventModifiersCapsLockKey; 143 if (JSStringIsEqualToUTF8CString(modifier , "addSelectionKey")) {139 if (JSStringIsEqualToUTF8CString(modifier.get(), "addSelectionKey")) { 144 140 #if OS(MAC_OS_X) 145 141 return kWKEventModifiersMetaKey; … … 151 147 } 152 148 153 static unsigned arrayLength(JSContextRef context, JSObjectRef array) 154 { 155 auto lengthString = adopt(JSStringCreateWithUTF8CString("length")); 156 JSValueRef lengthValue = JSObjectGetProperty(context, array, lengthString.get(), 0); 157 if (!lengthValue) 158 return 0; 159 return static_cast<unsigned>(JSValueToNumber(context, lengthValue, 0)); 160 } 149 #if ENABLE(TOUCH_EVENTS) 150 151 static uint64_t parseTouchModifier(JSStringRef modifier) 152 { 153 if (JSStringIsEqualToUTF8CString(modifier, "ctrl")) 154 return kWKEventModifiersControlKey; 155 if (JSStringIsEqualToUTF8CString(modifier, "shift")) 156 return kWKEventModifiersShiftKey; 157 if (JSStringIsEqualToUTF8CString(modifier, "alt")) 158 return kWKEventModifiersAltKey; 159 if (JSStringIsEqualToUTF8CString(modifier, "metaKey")) 160 return kWKEventModifiersMetaKey; 161 return 0; 162 } 163 164 #endif 161 165 162 166 static WKEventModifiers parseModifierArray(JSContextRef context, JSValueRef arrayValue) … … 166 170 167 171 // The value may either be a string with a single modifier or an array of modifiers. 168 if (JSValueIsString(context, arrayValue)) { 169 auto string = adopt(JSValueToStringCopy(context, arrayValue, 0)); 170 return parseModifier(string.get()); 171 } 172 if (JSValueIsString(context, arrayValue)) 173 return parseModifier(createJSString(context, arrayValue)); 172 174 173 175 if (!JSValueIsObject(context, arrayValue)) … … 177 179 WKEventModifiers modifiers = 0; 178 180 for (unsigned i = 0; i < length; i++) { 179 JSValueRef exception = 0; 180 JSValueRef value = JSObjectGetPropertyAtIndex(context, array, i, &exception); 181 if (exception) 182 continue; 183 auto string = adopt(JSValueToStringCopy(context, value, &exception)); 184 if (exception) 185 continue; 186 modifiers |= parseModifier(string.get()); 181 if (auto value = JSObjectGetPropertyAtIndex(context, array, i, nullptr)) 182 modifiers |= parseModifier(createJSString(context, value)); 187 183 } 188 184 return modifiers; 189 185 } 190 186 187 static WKEventModifiers parseModifierArray(JSValueRef arrayValue) 188 { 189 return parseModifierArray(WKBundleFrameGetJavaScriptContext(WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page())), arrayValue); 190 } 191 191 192 Ref<EventSendingController> EventSendingController::create() 192 193 { … … 194 195 } 195 196 196 EventSendingController::EventSendingController()197 {198 }199 200 EventSendingController::~EventSendingController()201 {202 }203 204 197 JSClassRef EventSendingController::wrapperClass() 205 198 { … … 207 200 } 208 201 209 enum MouseState { 210 MouseUp, 211 MouseDown 212 }; 213 214 static WKMutableDictionaryRef createMouseMessageBody(MouseState state, int button, WKEventModifiers modifiers) 215 { 216 WKMutableDictionaryRef EventSenderMessageBody = WKMutableDictionaryCreate(); 217 218 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 219 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString(state == MouseUp ? "MouseUp" : "MouseDown")); 220 WKDictionarySetItem(EventSenderMessageBody, subMessageKey.get(), subMessageName.get()); 221 222 WKRetainPtr<WKStringRef> buttonKey = adoptWK(WKStringCreateWithUTF8CString("Button")); 223 WKRetainPtr<WKUInt64Ref> buttonRef = adoptWK(WKUInt64Create(button)); 224 WKDictionarySetItem(EventSenderMessageBody, buttonKey.get(), buttonRef.get()); 225 226 WKRetainPtr<WKStringRef> modifiersKey = adoptWK(WKStringCreateWithUTF8CString("Modifiers")); 227 WKRetainPtr<WKUInt64Ref> modifiersRef = adoptWK(WKUInt64Create(modifiers)); 228 WKDictionarySetItem(EventSenderMessageBody, modifiersKey.get(), modifiersRef.get()); 229 230 return EventSenderMessageBody; 202 enum MouseState { MouseUp, MouseDown }; 203 204 static WKRetainPtr<WKDictionaryRef> createMouseMessageBody(MouseState state, int button, WKEventModifiers modifiers) 205 { 206 auto body = adoptWK(WKMutableDictionaryCreate()); 207 setValue(body, "SubMessage", state == MouseUp ? "MouseUp" : "MouseDown"); 208 setValue(body, "Button", adoptWK(WKUInt64Create(button))); 209 setValue(body, "Modifiers", adoptWK(WKUInt64Create(modifiers))); 210 return body; 231 211 } 232 212 233 213 void EventSendingController::mouseDown(int button, JSValueRef modifierArray) 234 214 { 235 auto& injectedBundle = InjectedBundle::singleton(); 236 WKBundlePageRef page = injectedBundle.page()->page(); 237 WKBundleFrameRef frame = WKBundlePageGetMainFrame(page); 238 JSContextRef context = WKBundleFrameGetJavaScriptContext(frame); 239 WKEventModifiers modifiers = parseModifierArray(context, modifierArray); 240 241 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 242 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(createMouseMessageBody(MouseDown, button, modifiers)); 243 244 WKBundlePagePostSynchronousMessageForTesting(page, EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 215 postSynchronousPageMessage("EventSender", createMouseMessageBody(MouseDown, button, parseModifierArray(modifierArray))); 245 216 } 246 217 247 218 void EventSendingController::mouseUp(int button, JSValueRef modifierArray) 248 219 { 249 WKBundlePageRef page = InjectedBundle::singleton().page()->page(); 250 WKBundleFrameRef frame = WKBundlePageGetMainFrame(page); 251 JSContextRef context = WKBundleFrameGetJavaScriptContext(frame); 252 WKEventModifiers modifiers = parseModifierArray(context, modifierArray); 253 254 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 255 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(createMouseMessageBody(MouseUp, button, modifiers)); 256 257 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 220 postSynchronousPageMessage("EventSender", createMouseMessageBody(MouseUp, button, parseModifierArray(modifierArray))); 258 221 } 259 222 260 223 void EventSendingController::mouseMoveTo(int x, int y) 261 224 { 262 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 263 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 264 265 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 266 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("MouseMoveTo")); 267 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 268 269 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X")); 270 WKRetainPtr<WKDoubleRef> xRef = adoptWK(WKDoubleCreate(x)); 271 WKDictionarySetItem(EventSenderMessageBody.get(), xKey.get(), xRef.get()); 272 273 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); 274 WKRetainPtr<WKDoubleRef> yRef = adoptWK(WKDoubleCreate(y)); 275 WKDictionarySetItem(EventSenderMessageBody.get(), yKey.get(), yRef.get()); 276 225 auto body = adoptWK(WKMutableDictionaryCreate()); 226 setValue(body, "SubMessage", "MouseMoveTo"); 227 setValue(body, "X", adoptWK(WKDoubleCreate(x))); 228 setValue(body, "Y", adoptWK(WKDoubleCreate(y))); 277 229 m_position = WKPointMake(x, y); 278 279 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 230 postSynchronousPageMessage("EventSender", body); 280 231 } 281 232 282 233 void EventSendingController::mouseForceClick() 283 234 { 284 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 285 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 286 287 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 288 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("MouseForceClick")); 289 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 290 291 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 235 auto body = adoptWK(WKMutableDictionaryCreate()); 236 setValue(body, "SubMessage", "MouseForceClick"); 237 postSynchronousPageMessage("EventSender", body); 292 238 } 293 239 294 240 void EventSendingController::startAndCancelMouseForceClick() 295 241 { 296 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 297 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 298 299 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 300 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("StartAndCancelMouseForceClick")); 301 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 302 303 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 242 auto body = adoptWK(WKMutableDictionaryCreate()); 243 setValue(body, "SubMessage", "StartAndCancelMouseForceClick"); 244 postSynchronousPageMessage("EventSender", body); 304 245 } 305 246 306 247 void EventSendingController::mouseForceDown() 307 248 { 308 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 309 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 310 311 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 312 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("MouseForceDown")); 313 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 314 315 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 249 auto body = adoptWK(WKMutableDictionaryCreate()); 250 setValue(body, "SubMessage", "MouseForceDown"); 251 postSynchronousPageMessage("EventSender", body); 316 252 } 317 253 318 254 void EventSendingController::mouseForceUp() 319 255 { 320 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 321 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 322 323 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 324 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("MouseForceUp")); 325 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 326 327 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 256 auto body = adoptWK(WKMutableDictionaryCreate()); 257 setValue(body, "SubMessage", "MouseForceUp"); 258 postSynchronousPageMessage("EventSender", body); 328 259 } 329 260 330 261 void EventSendingController::mouseForceChanged(double force) 331 262 { 332 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 333 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 334 335 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 336 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("MouseForceChanged")); 337 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 338 339 WKRetainPtr<WKStringRef> forceKey = adoptWK(WKStringCreateWithUTF8CString("Force")); 340 WKRetainPtr<WKDoubleRef> forceRef = adoptWK(WKDoubleCreate(force)); 341 WKDictionarySetItem(EventSenderMessageBody.get(), forceKey.get(), forceRef.get()); 342 343 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 263 auto body = adoptWK(WKMutableDictionaryCreate()); 264 setValue(body, "SubMessage", "MouseForceChanged"); 265 setValue(body, "Force", force); 266 postSynchronousPageMessage("EventSender", body); 344 267 } 345 268 346 269 void EventSendingController::leapForward(int milliseconds) 347 270 { 348 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 349 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 350 351 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 352 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("LeapForward")); 353 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 354 355 WKRetainPtr<WKStringRef> timeKey = adoptWK(WKStringCreateWithUTF8CString("TimeInMilliseconds")); 356 WKRetainPtr<WKUInt64Ref> timeRef = adoptWK(WKUInt64Create(milliseconds)); 357 WKDictionarySetItem(EventSenderMessageBody.get(), timeKey.get(), timeRef.get()); 358 359 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 271 auto body = adoptWK(WKMutableDictionaryCreate()); 272 setValue(body, "SubMessage", "LeapForward"); 273 setValue(body, "TimeInMilliseconds", adoptWK(WKUInt64Create(milliseconds))); 274 postSynchronousPageMessage("EventSender", body); 360 275 } 361 276 362 277 void EventSendingController::scheduleAsynchronousClick() 363 278 { 364 WKEventModifiers modifiers = 0; 365 int button = 0; 366 367 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 368 369 // Asynchronous mouse down. 370 WKRetainPtr<WKMutableDictionaryRef> mouseDownMessageBody = adoptWK(createMouseMessageBody(MouseDown, button, modifiers)); 371 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), mouseDownMessageBody.get()); 372 373 // Asynchronous mouse up. 374 WKRetainPtr<WKMutableDictionaryRef> mouseUpMessageBody = adoptWK(createMouseMessageBody(MouseUp, button, modifiers)); 375 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), mouseUpMessageBody.get()); 279 postPageMessage("EventSender", createMouseMessageBody(MouseDown, 0, 0)); 280 postPageMessage("EventSender", createMouseMessageBody(MouseUp, 0, 0)); 376 281 } 377 282 378 283 static WKRetainPtr<WKMutableDictionaryRef> createKeyDownMessageBody(JSStringRef key, WKEventModifiers modifiers, int location) 379 284 { 380 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 381 382 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 383 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("KeyDown")); 384 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 385 386 WKRetainPtr<WKStringRef> keyKey = adoptWK(WKStringCreateWithUTF8CString("Key")); 387 WKDictionarySetItem(EventSenderMessageBody.get(), keyKey.get(), toWK(key).get()); 388 389 WKRetainPtr<WKStringRef> modifiersKey = adoptWK(WKStringCreateWithUTF8CString("Modifiers")); 390 WKRetainPtr<WKUInt64Ref> modifiersRef = adoptWK(WKUInt64Create(modifiers)); 391 WKDictionarySetItem(EventSenderMessageBody.get(), modifiersKey.get(), modifiersRef.get()); 392 393 WKRetainPtr<WKStringRef> locationKey = adoptWK(WKStringCreateWithUTF8CString("Location")); 394 WKRetainPtr<WKUInt64Ref> locationRef = adoptWK(WKUInt64Create(location)); 395 WKDictionarySetItem(EventSenderMessageBody.get(), locationKey.get(), locationRef.get()); 396 397 return EventSenderMessageBody; 285 auto body = adoptWK(WKMutableDictionaryCreate()); 286 setValue(body, "SubMessage", "KeyDown"); 287 setValue(body, "Key", key); 288 setValue(body, "Modifiers", adoptWK(WKUInt64Create(modifiers))); 289 setValue(body, "Location", adoptWK(WKUInt64Create(location))); 290 return body; 398 291 } 399 292 400 293 void EventSendingController::keyDown(JSStringRef key, JSValueRef modifierArray, int location) 401 294 { 402 WKBundlePageRef page = InjectedBundle::singleton().page()->page(); 403 WKBundleFrameRef frame = WKBundlePageGetMainFrame(page); 404 JSContextRef context = WKBundleFrameGetJavaScriptContext(frame); 405 WKEventModifiers modifiers = parseModifierArray(context, modifierArray); 406 407 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 408 WKRetainPtr<WKMutableDictionaryRef> keyDownMessageBody = createKeyDownMessageBody(key, modifiers, location); 409 410 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), keyDownMessageBody.get(), 0); 295 postSynchronousPageMessage("EventSender", createKeyDownMessageBody(key, parseModifierArray(modifierArray), location)); 411 296 } 412 297 413 298 void EventSendingController::scheduleAsynchronousKeyDown(JSStringRef key) 414 299 { 415 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 416 WKRetainPtr<WKMutableDictionaryRef> keyDownMessageBody = createKeyDownMessageBody(key, 0 /* modifiers */, 0 /* location */); 417 418 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), keyDownMessageBody.get()); 300 postPageMessage("EventSender", createKeyDownMessageBody(key, 0, 0)); 419 301 } 420 302 421 303 void EventSendingController::mouseScrollBy(int x, int y) 422 304 { 423 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender"));424 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate());425 426 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage"));427 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("MouseScrollBy"));428 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());429 430 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X"));431 WKRetainPtr<WKDoubleRef> xRef = adoptWK(WKDoubleCreate(x));432 WKDictionarySetItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());433 434 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y"));435 WKRetainPtr<WKDoubleRef> yRef = adoptWK(WKDoubleCreate(y));436 WKDictionarySetItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());437 438 305 WKBundlePageForceRepaint(InjectedBundle::singleton().page()->page()); // Triggers a scrolling tree commit. 439 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get()); 306 307 auto body = adoptWK(WKMutableDictionaryCreate()); 308 setValue(body, "SubMessage", "MouseScrollBy"); 309 setValue(body, "X", adoptWK(WKDoubleCreate(x))); 310 setValue(body, "Y", adoptWK(WKDoubleCreate(y))); 311 postPageMessage("EventSender", body); 440 312 } 441 313 … … 476 348 void EventSendingController::mouseScrollByWithWheelAndMomentumPhases(int x, int y, JSStringRef phaseStr, JSStringRef momentumStr) 477 349 { 478 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender"));479 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate());480 481 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage"));482 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("MouseScrollByWithWheelAndMomentumPhases"));483 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());484 485 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X"));486 WKRetainPtr<WKDoubleRef> xRef = adoptWK(WKDoubleCreate(x));487 WKDictionarySetItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());488 489 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y"));490 WKRetainPtr<WKDoubleRef> yRef = adoptWK(WKDoubleCreate(y));491 WKDictionarySetItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());492 493 350 uint64_t phase = cgEventPhaseFromString(phaseStr); 494 351 uint64_t momentum = cgEventMomentumPhaseFromString(momentumStr); 495 352 496 353 if (phase == 4 /* kCGScrollPhaseEnded */ || phase == 8 /* kCGScrollPhaseCancelled */) 497 354 m_sentWheelPhaseEndOrCancel = true; 498 499 355 if (momentum == 3 /* kCGMomentumScrollPhaseEnd */) 500 356 m_sentWheelMomentumPhaseEnd = true; 501 357 502 WKRetainPtr<WKStringRef> phaseKey = adoptWK(WKStringCreateWithUTF8CString("Phase"));503 WKRetainPtr<WKUInt64Ref> phaseRef = adoptWK(WKUInt64Create(phase));504 WKDictionarySetItem(EventSenderMessageBody.get(), phaseKey.get(), phaseRef.get());505 506 WKRetainPtr<WKStringRef> momentumKey = adoptWK(WKStringCreateWithUTF8CString("Momentum"));507 WKRetainPtr<WKUInt64Ref> momentumRef = adoptWK(WKUInt64Create(momentum));508 WKDictionarySetItem(EventSenderMessageBody.get(), momentumKey.get(), momentumRef.get());509 510 358 WKBundlePageForceRepaint(InjectedBundle::singleton().page()->page()); // Triggers a scrolling tree commit. 511 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get()); 359 360 auto body = adoptWK(WKMutableDictionaryCreate()); 361 setValue(body, "SubMessage", "MouseScrollByWithWheelAndMomentumPhases"); 362 setValue(body, "X", adoptWK(WKDoubleCreate(x))); 363 setValue(body, "Y", adoptWK(WKDoubleCreate(y))); 364 setValue(body, "Phase", phase); 365 setValue(body, "Momentum", momentum); 366 postPageMessage("EventSender", body); 512 367 } 513 368 514 369 void EventSendingController::continuousMouseScrollBy(int x, int y, bool paged) 515 370 { 516 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 517 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 518 519 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 520 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("ContinuousMouseScrollBy")); 521 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 522 523 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X")); 524 WKRetainPtr<WKDoubleRef> xRef = adoptWK(WKDoubleCreate(x)); 525 WKDictionarySetItem(EventSenderMessageBody.get(), xKey.get(), xRef.get()); 526 527 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); 528 WKRetainPtr<WKDoubleRef> yRef = adoptWK(WKDoubleCreate(y)); 529 WKDictionarySetItem(EventSenderMessageBody.get(), yKey.get(), yRef.get()); 530 531 WKRetainPtr<WKStringRef> pagedKey = adoptWK(WKStringCreateWithUTF8CString("Paged")); 532 WKRetainPtr<WKUInt64Ref> pagedRef = adoptWK(WKUInt64Create(paged)); 533 WKDictionarySetItem(EventSenderMessageBody.get(), pagedKey.get(), pagedRef.get()); 534 371 auto body = adoptWK(WKMutableDictionaryCreate()); 372 setValue(body, "SubMessage", "ContinuousMouseScrollBy"); 373 setValue(body, "X", adoptWK(WKDoubleCreate(x))); 374 setValue(body, "Y", adoptWK(WKDoubleCreate(y))); 375 setValue(body, "Paged", paged); 535 376 // FIXME: This message should be asynchronous, as scrolling is intrinsically asynchronous. 536 377 // See also: <https://bugs.webkit.org/show_bug.cgi?id=148256>. 537 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);378 postSynchronousPageMessage("EventSender", body); 538 379 } 539 380 540 381 JSValueRef EventSendingController::contextClick() 541 382 { 542 WKBundlePageRefpage = InjectedBundle::singleton().page()->page();383 auto page = InjectedBundle::singleton().page()->page(); 543 384 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(page); 544 385 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); 545 386 #if ENABLE(CONTEXT_MENUS) 546 WKRetainPtr<WKArrayRef>menuEntries = adoptWK(WKBundlePageCopyContextMenuAtPointInWindow(page, m_position));547 JSValueRef arrayResult= JSObjectMakeArray(context, 0, 0, 0);387 auto menuEntries = adoptWK(WKBundlePageCopyContextMenuAtPointInWindow(page, m_position)); 388 auto array = JSObjectMakeArray(context, 0, 0, 0); 548 389 if (!menuEntries) 549 return arrayResult; 550 551 JSObjectRef arrayObj = JSValueToObject(context, arrayResult, 0); 390 return array; 391 552 392 size_t entriesSize = WKArrayGetSize(menuEntries.get()); 553 393 for (size_t i = 0; i < entriesSize; ++i) { … … 556 396 WKContextMenuItemRef item = static_cast<WKContextMenuItemRef>(WKArrayGetItemAtIndex(menuEntries.get(), i)); 557 397 MenuItemPrivateData* privateData = new MenuItemPrivateData(page, item); 558 JSObjectSetPropertyAtIndex(context, array Obj, i, JSObjectMake(context, getMenuItemClass(), privateData), 0);398 JSObjectSetPropertyAtIndex(context, array, i, JSObjectMake(context, getMenuItemClass(), privateData), 0); 559 399 } 560 400 561 return array Result;401 return array; 562 402 #else 563 403 return JSValueMakeUndefined(context); … … 616 456 return nullptr; 617 457 618 auto resetLatchingString = adopt(JSStringCreateWithUTF8CString("resetLatching"));619 auto resetLatchingValue = JSObjectGetProperty(context, JSValueToObject(context, argument, nullptr), resetLatchingString.get(), nullptr);620 621 bool resetLatching = true;622 if (resetLatchingValue && JSValueIsBoolean(context, resetLatchingValue))623 resetLatching = JSValueToBoolean(context, resetLatchingValue);624 625 458 static MonitorWheelEventsOptions options; 626 options.resetLatching = resetLatching;459 options.resetLatching = booleanProperty(context, (JSObjectRef)argument, "resetLatching", true); 627 460 return &options; 628 461 } … … 630 463 void EventSendingController::monitorWheelEvents(MonitorWheelEventsOptions* options) 631 464 { 632 WKBundlePageRefpage = InjectedBundle::singleton().page()->page();465 auto page = InjectedBundle::singleton().page()->page(); 633 466 634 467 m_sentWheelPhaseEndOrCancel = false; … … 664 497 return; 665 498 666 WKBundlePageRefpage = InjectedBundle::singleton().page()->page();499 auto page = InjectedBundle::singleton().page()->page(); 667 500 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(page); 668 501 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); … … 684 517 685 518 #if ENABLE(TOUCH_EVENTS) 519 686 520 void EventSendingController::addTouchPoint(int x, int y) 687 521 { 688 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 689 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 690 691 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 692 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("AddTouchPoint")); 693 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 694 695 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X")); 696 WKRetainPtr<WKUInt64Ref> xRef = adoptWK(WKUInt64Create(x)); 697 WKDictionarySetItem(EventSenderMessageBody.get(), xKey.get(), xRef.get()); 698 699 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); 700 WKRetainPtr<WKUInt64Ref> yRef = adoptWK(WKUInt64Create(y)); 701 WKDictionarySetItem(EventSenderMessageBody.get(), yKey.get(), yRef.get()); 702 703 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 522 auto body = adoptWK(WKMutableDictionaryCreate()); 523 setValue(body, "SubMessage", "AddTouchPoint"); 524 setValue(body, "X", static_cast<uint64_t>(x)); 525 setValue(body, "Y", static_cast<uint64_t>(y)); 526 postSynchronousPageMessage("EventSender", body); 704 527 } 705 528 706 529 void EventSendingController::updateTouchPoint(int index, int x, int y) 707 530 { 708 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 709 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 710 711 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 712 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("UpdateTouchPoint")); 713 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 714 715 WKRetainPtr<WKStringRef> indexKey = adoptWK(WKStringCreateWithUTF8CString("Index")); 716 WKRetainPtr<WKUInt64Ref> indexRef = adoptWK(WKUInt64Create(index)); 717 WKDictionarySetItem(EventSenderMessageBody.get(), indexKey.get(), indexRef.get()); 718 719 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X")); 720 WKRetainPtr<WKUInt64Ref> xRef = adoptWK(WKUInt64Create(x)); 721 WKDictionarySetItem(EventSenderMessageBody.get(), xKey.get(), xRef.get()); 722 723 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); 724 WKRetainPtr<WKUInt64Ref> yRef = adoptWK(WKUInt64Create(y)); 725 WKDictionarySetItem(EventSenderMessageBody.get(), yKey.get(), yRef.get()); 726 727 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 728 } 729 730 void EventSendingController::setTouchModifier(const JSStringRef &modifier, bool enable) 731 { 732 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 733 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 734 735 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 736 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("SetTouchModifier")); 737 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 738 739 WKEventModifiers mod = 0; 740 if (JSStringIsEqualToUTF8CString(modifier, "ctrl")) 741 mod = kWKEventModifiersControlKey; 742 if (JSStringIsEqualToUTF8CString(modifier, "shift")) 743 mod = kWKEventModifiersShiftKey; 744 if (JSStringIsEqualToUTF8CString(modifier, "alt")) 745 mod = kWKEventModifiersAltKey; 746 if (JSStringIsEqualToUTF8CString(modifier, "meta")) 747 mod = kWKEventModifiersMetaKey; 748 749 WKRetainPtr<WKStringRef> modifierKey = adoptWK(WKStringCreateWithUTF8CString("Modifier")); 750 WKRetainPtr<WKUInt64Ref> modifierRef = adoptWK(WKUInt64Create(mod)); 751 WKDictionarySetItem(EventSenderMessageBody.get(), modifierKey.get(), modifierRef.get()); 752 753 WKRetainPtr<WKStringRef> enableKey = adoptWK(WKStringCreateWithUTF8CString("Enable")); 754 WKRetainPtr<WKUInt64Ref> enableRef = adoptWK(WKUInt64Create(enable)); 755 WKDictionarySetItem(EventSenderMessageBody.get(), enableKey.get(), enableRef.get()); 756 757 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 758 } 759 531 auto body = adoptWK(WKMutableDictionaryCreate()); 532 setValue(body, "SubMessage", "UpdateTouchPoint"); 533 setValue(body, "Index", static_cast<uint64_t>(index)); 534 setValue(body, "X", static_cast<uint64_t>(x)); 535 setValue(body, "Y", static_cast<uint64_t>(y)); 536 postSynchronousPageMessage("EventSender", body); 537 } 538 539 void EventSendingController::setTouchModifier(JSStringRef modifier, bool enable) 540 { 541 auto body = adoptWK(WKMutableDictionaryCreate()); 542 setValue(body, "SubMessage", "SetTouchModifier"); 543 setValue(body, "Modifier", parseTouchModifier(modifier)); 544 setValue(body, "Enable", enable); 545 postSynchronousPageMessage("EventSender", body); 546 } 760 547 761 548 void EventSendingController::setTouchPointRadius(int radiusX, int radiusY) 762 549 { 763 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 764 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 765 766 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 767 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("SetTouchPointRadius")); 768 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 769 770 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("RadiusX")); 771 WKRetainPtr<WKUInt64Ref> xRef = adoptWK(WKUInt64Create(radiusX)); 772 WKDictionarySetItem(EventSenderMessageBody.get(), xKey.get(), xRef.get()); 773 774 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("RadiusY")); 775 WKRetainPtr<WKUInt64Ref> yRef = adoptWK(WKUInt64Create(radiusY)); 776 WKDictionarySetItem(EventSenderMessageBody.get(), yKey.get(), yRef.get()); 777 778 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 550 auto body = adoptWK(WKMutableDictionaryCreate()); 551 setValue(body, "SubMessage", "SetTouchPointRadius"); 552 setValue(body, "RadiusX", static_cast<uint64_t>(radiusX)); 553 setValue(body, "RadiusY", static_cast<uint64_t>(radiusY)); 554 postSynchronousPageMessage("EventSender", body); 779 555 } 780 556 781 557 void EventSendingController::touchStart() 782 558 { 783 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 784 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 785 786 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 787 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("TouchStart")); 788 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 789 790 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 559 auto body = adoptWK(WKMutableDictionaryCreate()); 560 setValue(body, "SubMessage", "TouchStart"); 561 postSynchronousPageMessage("EventSender", body); 791 562 } 792 563 793 564 void EventSendingController::touchMove() 794 565 { 795 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 796 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 797 798 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 799 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("TouchMove")); 800 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 801 802 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 566 auto body = adoptWK(WKMutableDictionaryCreate()); 567 setValue(body, "SubMessage", "TouchMove"); 568 postSynchronousPageMessage("EventSender", body); 803 569 } 804 570 805 571 void EventSendingController::touchEnd() 806 572 { 807 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 808 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 809 810 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 811 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("TouchEnd")); 812 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 813 814 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 573 auto body = adoptWK(WKMutableDictionaryCreate()); 574 setValue(body, "SubMessage", "TouchEnd"); 575 postSynchronousPageMessage("EventSender", body); 815 576 } 816 577 817 578 void EventSendingController::touchCancel() 818 579 { 819 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 820 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 821 822 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 823 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("TouchCancel")); 824 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 825 826 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 580 auto body = adoptWK(WKMutableDictionaryCreate()); 581 setValue(body, "SubMessage", "TouchCancel"); 582 postSynchronousPageMessage("EventSender", body); 827 583 } 828 584 829 585 void EventSendingController::clearTouchPoints() 830 586 { 831 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 832 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 833 834 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 835 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("ClearTouchPoints")); 836 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 837 838 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 587 auto body = adoptWK(WKMutableDictionaryCreate()); 588 setValue(body, "SubMessage", "ClearTouchPoints"); 589 postSynchronousPageMessage("EventSender", body); 839 590 } 840 591 841 592 void EventSendingController::releaseTouchPoint(int index) 842 593 { 843 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 844 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 845 846 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 847 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("ReleaseTouchPoint")); 848 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 849 850 WKRetainPtr<WKStringRef> indexKey = adoptWK(WKStringCreateWithUTF8CString("Index")); 851 WKRetainPtr<WKUInt64Ref> indexRef = adoptWK(WKUInt64Create(index)); 852 WKDictionarySetItem(EventSenderMessageBody.get(), indexKey.get(), indexRef.get()); 853 854 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 594 auto body = adoptWK(WKMutableDictionaryCreate()); 595 setValue(body, "SubMessage", "ReleaseTouchPoint"); 596 setValue(body, "Index", static_cast<uint64_t>(index)); 597 postSynchronousPageMessage("EventSender", body); 855 598 } 856 599 857 600 void EventSendingController::cancelTouchPoint(int index) 858 601 { 859 WKRetainPtr<WKStringRef> EventSenderMessageName = adoptWK(WKStringCreateWithUTF8CString("EventSender")); 860 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody = adoptWK(WKMutableDictionaryCreate()); 861 862 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 863 WKRetainPtr<WKStringRef> subMessageName = adoptWK(WKStringCreateWithUTF8CString("CancelTouchPoint")); 864 WKDictionarySetItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get()); 865 866 WKRetainPtr<WKStringRef> indexKey = adoptWK(WKStringCreateWithUTF8CString("Index")); 867 WKRetainPtr<WKUInt64Ref> indexRef = adoptWK(WKUInt64Create(index)); 868 WKDictionarySetItem(EventSenderMessageBody.get(), indexKey.get(), indexRef.get()); 869 870 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0); 871 } 602 auto body = adoptWK(WKMutableDictionaryCreate()); 603 setValue(body, "SubMessage", "CancelTouchPoint"); 604 setValue(body, "Index", static_cast<uint64_t>(index)); 605 postSynchronousPageMessage("EventSender", body); 606 } 607 872 608 #endif 873 609 874 610 // Object Creation 875 611 876 void EventSendingController::makeWindowObject(JSContextRef context , JSObjectRef windowObject, JSValueRef* exception)877 { 878 set Property(context, windowObject, "eventSender", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);612 void EventSendingController::makeWindowObject(JSContextRef context) 613 { 614 setGlobalObjectProperty(context, "eventSender", this); 879 615 } 880 616 -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.h ¶
r261539 r267761 31 31 #include <wtf/Ref.h> 32 32 33 typedef const struct OpaqueJSContext* JSContextRef; 34 typedef struct OpaqueJSString* JSStringRef; 35 typedef const struct OpaqueJSValue* JSValueRef; 36 33 37 namespace WTR { 34 38 35 39 struct MonitorWheelEventsOptions { 36 MonitorWheelEventsOptions(bool resetLatching = true)37 : resetLatching(resetLatching)38 { }39 40 40 bool resetLatching { true }; 41 41 }; … … 43 43 MonitorWheelEventsOptions* toMonitorWheelEventsOptions(JSContextRef, JSValueRef); 44 44 45 class EventSendingController : public JSWrappable {45 class EventSendingController final : public JSWrappable { 46 46 public: 47 47 static Ref<EventSendingController> create(); 48 virtual ~EventSendingController();49 48 50 void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception); 51 52 // JSWrappable 53 virtual JSClassRef wrapperClass(); 49 void makeWindowObject(JSContextRef); 54 50 55 51 void mouseDown(int button, JSValueRef modifierArray); … … 74 70 void scheduleAsynchronousKeyDown(JSStringRef key); 75 71 76 // Zoom functions.77 72 void textZoomIn(); 78 73 void textZoomOut(); … … 82 77 83 78 #if ENABLE(TOUCH_EVENTS) 84 // Touch events.85 79 void addTouchPoint(int x, int y); 86 80 void updateTouchPoint(int index, int x, int y); 87 void setTouchModifier( const JSStringRef &modifier, bool enable);81 void setTouchModifier(JSStringRef modifier, bool enable); 88 82 void setTouchPointRadius(int radiusX, int radiusY); 89 83 void touchStart(); … … 97 91 98 92 private: 99 EventSendingController(); 93 EventSendingController() = default; 94 95 JSClassRef wrapperClass() final; 96 100 97 WKPoint m_position; 101 98 bool m_sentWheelPhaseEndOrCancel { false }; -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/GCController.cpp ¶
r208338 r267761 38 38 } 39 39 40 GCController::GCController()41 {42 }43 44 GCController::~GCController()45 {46 }47 48 40 JSClassRef GCController::wrapperClass() 49 41 { … … 66 58 } 67 59 68 // Object Creation 69 70 void GCController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception) 60 void GCController::makeWindowObject(JSContextRef context) 71 61 { 72 set Property(context, windowObject, "GCController", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);62 setGlobalObjectProperty(context, "GCController", this); 73 63 } 74 64 -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/GCController.h ¶
r208338 r267761 27 27 28 28 #include "JSWrappable.h" 29 #include <wtf/Ref.h> 29 #include <wtf/Forward.h> 30 31 typedef const struct OpaqueJSContext* JSContextRef; 30 32 31 33 namespace WTR { 32 34 33 class GCController : public JSWrappable {35 class GCController final : public JSWrappable { 34 36 public: 35 37 static Ref<GCController> create(); 36 virtual ~GCController();37 38 38 void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception); 39 40 // JSWrappable 41 virtual JSClassRef wrapperClass(); 39 void makeWindowObject(JSContextRef); 42 40 43 41 void collect(); … … 46 44 47 45 private: 48 GCController(); 46 GCController() = default; 47 48 JSClassRef wrapperClass() final; 49 49 }; 50 50 -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp ¶
r266895 r267761 1 1 /* 2 * Copyright (C) 2010-20 18Apple Inc. All rights reserved.2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 28 28 29 29 #include "ActivateFonts.h" 30 #include "DictionaryFunctions.h" 30 31 #include "InjectedBundlePage.h" 31 #include "StringFunctions.h"32 32 #include "WebCoreTestSupport.h" 33 33 #include <JavaScriptCore/Options.h> … … 119 119 return; 120 120 121 WKRetainPtr<WKStringRef> messsageName = adoptWK(WKStringCreateWithUTF8CString("Initialization"));122 121 WKTypeRef result = nullptr; 123 122 ALLOW_DEPRECATED_DECLARATIONS_BEGIN 124 WKBundlePostSynchronousMessage(m_bundle, messsageName.get(), nullptr, &result);123 WKBundlePostSynchronousMessage(m_bundle, toWK("Initialization").get(), nullptr, &result); 125 124 ALLOW_DEPRECATED_DECLARATIONS_END 126 ASSERT(WKGetTypeID(result) == WKDictionaryGetTypeID()); 127 WKRetainPtr<WKDictionaryRef> initializationDictionary = adoptWK(static_cast<WKDictionaryRef>(result)); 128 129 WKRetainPtr<WKStringRef> resumeTestingKey = adoptWK(WKStringCreateWithUTF8CString("ResumeTesting")); 130 WKTypeRef resumeTestingValue = WKDictionaryGetItemForKey(initializationDictionary.get(), resumeTestingKey.get()); 131 ASSERT(WKGetTypeID(resumeTestingValue) == WKBooleanGetTypeID()); 132 if (WKBooleanGetValue(static_cast<WKBooleanRef>(resumeTestingValue))) 125 auto initializationDictionary = adoptWK(dictionaryValue(result)); 126 127 if (booleanValue(initializationDictionary.get(), "ResumeTesting")) 133 128 beginTesting(initializationDictionary.get(), BegingTestingMode::Resume); 134 129 } … … 175 170 } 176 171 177 void InjectedBundle::resetLocalSettings() 178 { 179 setlocale(LC_ALL, ""); 180 } 181 182 void InjectedBundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody) 183 { 184 WKRetainPtr<WKStringRef> errorMessageName = adoptWK(WKStringCreateWithUTF8CString("Error")); 185 WKRetainPtr<WKStringRef> errorMessageBody = adoptWK(WKStringCreateWithUTF8CString("Unknown")); 186 WKBundlePostMessage(m_bundle, errorMessageName.get(), errorMessageBody.get()); 172 WKBundlePageRef InjectedBundle::pageRef() const 173 { 174 auto page = this->page(); 175 return page ? page->page() : nullptr; 176 } 177 178 void InjectedBundle::didReceiveMessage(WKStringRef, WKTypeRef) 179 { 180 WKBundlePostMessage(m_bundle, toWK("Error").get(), toWK("Unknown").get()); 187 181 } 188 182 189 183 static void postGCTask(void* context) 190 184 { 191 WKBundlePageRefpage = reinterpret_cast<WKBundlePageRef>(context);185 auto page = reinterpret_cast<WKBundlePageRef>(context); 192 186 InjectedBundle::singleton().reportLiveDocuments(page); 193 187 WKRelease(page); … … 200 194 201 195 const bool excludeDocumentsInPageGroup = true; 202 auto documentURLs = adoptWK(WKBundleGetLiveDocumentURLs(m_bundle, m_pageGroup, excludeDocumentsInPageGroup)); 203 auto ackMessageName = adoptWK(WKStringCreateWithUTF8CString("LiveDocuments")); 204 WKBundlePagePostMessage(page, ackMessageName.get(), documentURLs.get()); 196 WKBundlePagePostMessage(page, toWK("LiveDocuments").get(), adoptWK(WKBundleGetLiveDocumentURLs(m_bundle, m_pageGroup, excludeDocumentsInPageGroup)).get()); 205 197 } 206 198 … … 209 201 if (WKStringIsEqualToUTF8CString(messageName, "BeginTest")) { 210 202 ASSERT(messageBody); 211 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 212 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 213 214 WKRetainPtr<WKStringRef> dumpPixelsKey = adoptWK(WKStringCreateWithUTF8CString("DumpPixels")); 215 m_dumpPixels = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, dumpPixelsKey.get()))); 216 217 WKRetainPtr<WKStringRef> timeoutKey = adoptWK(WKStringCreateWithUTF8CString("Timeout")); 218 m_timeout = Seconds::fromMilliseconds(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, timeoutKey.get())))); 219 220 WKRetainPtr<WKStringRef> dumpJSConsoleLogInStdErrKey = adoptWK(WKStringCreateWithUTF8CString("DumpJSConsoleLogInStdErr")); 221 m_dumpJSConsoleLogInStdErr = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, dumpJSConsoleLogInStdErrKey.get()))); 222 223 WKRetainPtr<WKStringRef> ackMessageName = adoptWK(WKStringCreateWithUTF8CString("Ack")); 224 WKRetainPtr<WKStringRef> ackMessageBody = adoptWK(WKStringCreateWithUTF8CString("BeginTest")); 225 WKBundlePagePostMessage(page, ackMessageName.get(), ackMessageBody.get()); 226 203 auto messageBodyDictionary = dictionaryValue(messageBody); 204 m_dumpPixels = booleanValue(messageBodyDictionary, "DumpPixels"); 205 m_timeout = Seconds::fromMilliseconds(WKUInt64GetValue(static_cast<WKUInt64Ref>(value(messageBodyDictionary, "Timeout")))); 206 m_dumpJSConsoleLogInStdErr = booleanValue(messageBodyDictionary, "DumpJSConsoleLogInStdErr"); 207 WKBundlePagePostMessage(page, toWK("Ack").get(), toWK("BeginTest").get()); 227 208 beginTesting(messageBodyDictionary, BegingTestingMode::New); 228 209 return; … … 231 212 if (WKStringIsEqualToUTF8CString(messageName, "Reset")) { 232 213 ASSERT(messageBody); 233 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 234 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 235 WKRetainPtr<WKStringRef> jscOptionsKey = adoptWK(WKStringCreateWithUTF8CString("JSCOptions")); 236 WKRetainPtr<WKStringRef> jscOptionsString = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, jscOptionsKey.get())); 237 if (jscOptionsString) { 238 String options = toWTFString(jscOptionsString); 239 JSC::Options::setOptions(options.utf8().data()); 240 } 241 242 WKRetainPtr<WKStringRef> shouldGCKey = adoptWK(WKStringCreateWithUTF8CString("ShouldGC")); 243 bool shouldGC = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, shouldGCKey.get()))); 244 if (shouldGC) 214 auto messageBodyDictionary = dictionaryValue(messageBody); 215 if (auto options = stringValue(messageBodyDictionary, "JSCOptions")) 216 JSC::Options::setOptions(toWTFString(options).utf8().data()); 217 if (booleanValue(messageBodyDictionary, "ShouldGC")) 245 218 WKBundleGarbageCollectJavaScriptObjects(m_bundle); 246 219 247 220 #if ENABLE(ACCESSIBILITY_ISOLATED_TREE) 248 WKRetainPtr<WKStringRef> axIsolatedModeKey = adoptWK(WKStringCreateWithUTF8CString("AccessibilityIsolatedTree")); 249 m_accessibilityIsolatedTreeMode = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, axIsolatedModeKey.get()))); 221 m_accessibilityIsolatedTreeMode = booleanValue(messageBodyDictionary, "AccessibilityIsolatedTree"); 250 222 #endif 251 223 252 WKRetainPtr<WKStringRef> allowedHostsKey = adoptWK(WKStringCreateWithUTF8CString("AllowedHosts")); 253 WKTypeRef allowedHostsValue = WKDictionaryGetItemForKey(messageBodyDictionary, allowedHostsKey.get()); 224 auto allowedHostsValue = value(messageBodyDictionary, "AllowedHosts"); 254 225 if (allowedHostsValue && WKGetTypeID(allowedHostsValue) == WKArrayGetTypeID()) { 255 226 m_allowedHosts.clear(); 256 257 WKArrayRef allowedHostsArray = static_cast<WKArrayRef>(allowedHostsValue); 258 for (size_t i = 0, size = WKArrayGetSize(allowedHostsArray); i < size; ++i) { 259 WKTypeRef item = WKArrayGetItemAtIndex(allowedHostsArray, i); 260 if (item && WKGetTypeID(item) == WKStringGetTypeID()) 261 m_allowedHosts.append(toWTFString(static_cast<WKStringRef>(item))); 262 } 227 auto array = static_cast<WKArrayRef>(allowedHostsValue); 228 for (size_t i = 0, size = WKArrayGetSize(array); i < size; ++i) 229 m_allowedHosts.append(toWTFString(WKArrayGetItemAtIndex(array, i))); 263 230 } 264 231 … … 267 234 m_pixelResultIsPending = false; 268 235 269 resetLocalSettings();236 setlocale(LC_ALL, ""); 270 237 TestRunner::removeAllWebNotificationPermissions(); 271 238 … … 276 243 if (WKStringIsEqualToUTF8CString(messageName, "GetLiveDocuments")) { 277 244 const bool excludeDocumentsInPageGroup = false; 278 auto documentURLs = adoptWK(WKBundleGetLiveDocumentURLs(m_bundle, m_pageGroup, excludeDocumentsInPageGroup)); 279 auto ackMessageName = adoptWK(WKStringCreateWithUTF8CString("LiveDocuments")); 280 WKBundlePagePostMessage(page, ackMessageName.get(), documentURLs.get()); 245 postPageMessage("LiveDocuments", adoptWK(WKBundleGetLiveDocumentURLs(m_bundle, m_pageGroup, excludeDocumentsInPageGroup))); 281 246 return; 282 247 } … … 429 394 domains.reserveInitialCapacity(size); 430 395 for (size_t i = 0; i < size; ++i) { 431 WKTypeRefitem = WKArrayGetItemAtIndex(domainsArray, i);396 auto item = WKArrayGetItemAtIndex(domainsArray, i); 432 397 if (item && WKGetTypeID(item) == WKStringGetTypeID()) 433 398 domains.append(toWTFString(static_cast<WKStringRef>(item))); … … 447 412 domains.reserveInitialCapacity(size); 448 413 for (size_t i = 0; i < size; ++i) { 449 WKTypeRefitem = WKArrayGetItemAtIndex(domainsArray, i);414 auto item = WKArrayGetItemAtIndex(domainsArray, i); 450 415 if (item && WKGetTypeID(item) == WKStringGetTypeID()) 451 416 domains.uncheckedAppend(toWTFString(static_cast<WKStringRef>(item))); … … 468 433 469 434 if (WKStringIsEqualToUTF8CString(messageName, "CallUISideScriptCallback")) { 470 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 471 472 WKRetainPtr<WKStringRef> resultKey = adoptWK(WKStringCreateWithUTF8CString("Result")); 473 WKRetainPtr<WKStringRef> callbackIDKey = adoptWK(WKStringCreateWithUTF8CString("CallbackID")); 474 475 unsigned callbackID = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, callbackIDKey.get()))); 476 477 WKStringRef resultString = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, resultKey.get())); 478 auto resultJSString = toJS(resultString); 479 480 m_testRunner->runUIScriptCallback(callbackID, resultJSString.get()); 435 auto messageBodyDictionary = dictionaryValue(messageBody); 436 auto callbackID = uint64Value(messageBodyDictionary, "CallbackID"); 437 auto resultString = stringValue(messageBodyDictionary, "Result"); 438 m_testRunner->runUIScriptCallback(callbackID, toJS(resultString).get()); 481 439 return; 482 440 } … … 499 457 500 458 if (WKStringIsEqualToUTF8CString(messageName, "ResourceLoadStatisticsTelemetryFinished")) { 501 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 502 503 WKRetainPtr<WKStringRef> numberOfPrevalentResourcesKey = adoptWK(WKStringCreateWithUTF8CString("NumberOfPrevalentResources")); 504 WKRetainPtr<WKStringRef> numberOfPrevalentResourcesWithUserInteractionKey = adoptWK(WKStringCreateWithUTF8CString("NumberOfPrevalentResourcesWithUserInteraction")); 505 WKRetainPtr<WKStringRef> numberOfPrevalentResourcesWithoutUserInteractionKey = adoptWK(WKStringCreateWithUTF8CString("NumberOfPrevalentResourcesWithoutUserInteraction")); 506 WKRetainPtr<WKStringRef> topPrevalentResourceWithUserInteractionDaysSinceUserInteractionKey = adoptWK(WKStringCreateWithUTF8CString("TopPrevalentResourceWithUserInteractionDaysSinceUserInteraction")); 507 WKRetainPtr<WKStringRef> medianDaysSinceUserInteractionPrevalentResourceWithUserInteractionKey = adoptWK(WKStringCreateWithUTF8CString("MedianDaysSinceUserInteractionPrevalentResourceWithUserInteraction")); 508 WKRetainPtr<WKStringRef> top3NumberOfPrevalentResourcesWithUIKey = adoptWK(WKStringCreateWithUTF8CString("Top3NumberOfPrevalentResourcesWithUI")); 509 WKRetainPtr<WKStringRef> top3MedianSubFrameWithoutUIKey = adoptWK(WKStringCreateWithUTF8CString("Top3MedianSubFrameWithoutUI")); 510 WKRetainPtr<WKStringRef> top3MedianSubResourceWithoutUIKey = adoptWK(WKStringCreateWithUTF8CString("Top3MedianSubResourceWithoutUI")); 511 WKRetainPtr<WKStringRef> top3MedianUniqueRedirectsWithoutUIKey = adoptWK(WKStringCreateWithUTF8CString("Top3MedianUniqueRedirectsWithoutUI")); 512 WKRetainPtr<WKStringRef> top3MedianDataRecordsRemovedWithoutUIKey = adoptWK(WKStringCreateWithUTF8CString("Top3MedianDataRecordsRemovedWithoutUI")); 513 514 unsigned numberOfPrevalentResources = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, numberOfPrevalentResourcesKey.get()))); 515 unsigned numberOfPrevalentResourcesWithUserInteraction = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, numberOfPrevalentResourcesWithUserInteractionKey.get()))); 516 unsigned numberOfPrevalentResourcesWithoutUserInteraction = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, numberOfPrevalentResourcesWithoutUserInteractionKey.get()))); 517 unsigned topPrevalentResourceWithUserInteractionDaysSinceUserInteraction = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, topPrevalentResourceWithUserInteractionDaysSinceUserInteractionKey.get()))); 518 unsigned medianDaysSinceUserInteractionPrevalentResourceWithUserInteraction = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, medianDaysSinceUserInteractionPrevalentResourceWithUserInteractionKey.get()))); 519 unsigned top3NumberOfPrevalentResourcesWithUI = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, top3NumberOfPrevalentResourcesWithUIKey.get()))); 520 unsigned top3MedianSubFrameWithoutUI = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, top3MedianSubFrameWithoutUIKey.get()))); 521 unsigned top3MedianSubResourceWithoutUI = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, top3MedianSubResourceWithoutUIKey.get()))); 522 unsigned top3MedianUniqueRedirectsWithoutUI = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, top3MedianUniqueRedirectsWithoutUIKey.get()))); 523 unsigned top3MedianDataRecordsRemovedWithoutUI = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, top3MedianDataRecordsRemovedWithoutUIKey.get()))); 459 auto messageBodyDictionary = dictionaryValue(messageBody); 460 auto numberOfPrevalentResources = uint64Value(messageBodyDictionary, "NumberOfPrevalentResources"); 461 auto numberOfPrevalentResourcesWithUserInteraction = uint64Value(messageBodyDictionary, "NumberOfPrevalentResourcesWithUserInteraction"); 462 auto numberOfPrevalentResourcesWithoutUserInteraction = uint64Value(messageBodyDictionary, "NumberOfPrevalentResourcesWithoutUserInteraction"); 463 auto topPrevalentResourceWithUserInteractionDaysSinceUserInteraction = uint64Value(messageBodyDictionary, "TopPrevalentResourceWithUserInteractionDaysSinceUserInteraction"); 464 auto medianDaysSinceUserInteractionPrevalentResourceWithUserInteraction = uint64Value(messageBodyDictionary, "MedianDaysSinceUserInteractionPrevalentResourceWithUserInteraction"); 465 auto top3NumberOfPrevalentResourcesWithUI = uint64Value(messageBodyDictionary, "Top3NumberOfPrevalentResourcesWithUI"); 466 auto top3MedianSubFrameWithoutUI = uint64Value(messageBodyDictionary, "Top3MedianSubFrameWithoutUI"); 467 auto top3MedianSubResourceWithoutUI = uint64Value(messageBodyDictionary, "Top3MedianSubResourceWithoutUI"); 468 auto top3MedianUniqueRedirectsWithoutUI = uint64Value(messageBodyDictionary, "Top3MedianUniqueRedirectsWithoutUI"); 469 auto top3MedianDataRecordsRemovedWithoutUI = uint64Value(messageBodyDictionary, "Top3MedianDataRecordsRemovedWithoutUI"); 524 470 525 471 m_testRunner->statisticsDidRunTelemetryCallback(numberOfPrevalentResources, numberOfPrevalentResourcesWithUserInteraction, numberOfPrevalentResourcesWithoutUserInteraction, topPrevalentResourceWithUserInteractionDaysSinceUserInteraction, medianDaysSinceUserInteractionPrevalentResourceWithUserInteraction, top3NumberOfPrevalentResourcesWithUI, top3MedianSubFrameWithoutUI, top3MedianSubResourceWithoutUI, top3MedianUniqueRedirectsWithoutUI, top3MedianDataRecordsRemovedWithoutUI); … … 542 488 } 543 489 544 WKRetainPtr<WKStringRef> errorMessageName = adoptWK(WKStringCreateWithUTF8CString("Error")); 545 WKRetainPtr<WKStringRef> errorMessageBody = adoptWK(WKStringCreateWithUTF8CString("Unknown")); 546 WKBundlePagePostMessage(page, errorMessageName.get(), errorMessageBody.get()); 547 } 548 549 bool InjectedBundle::booleanForKey(WKDictionaryRef dictionary, const char* key) 550 { 551 WKRetainPtr<WKStringRef> wkKey = adoptWK(WKStringCreateWithUTF8CString(key)); 552 WKTypeRef value = WKDictionaryGetItemForKey(dictionary, wkKey.get()); 553 if (WKGetTypeID(value) != WKBooleanGetTypeID()) { 554 outputText(makeString("Boolean value for key", key, " not found in dictionary\n")); 555 return false; 556 } 557 return WKBooleanGetValue(static_cast<WKBooleanRef>(value)); 558 } 559 560 String InjectedBundle::stringForKey(WKDictionaryRef dictionary, const char* key) 561 { 562 WKRetainPtr<WKStringRef> wkKey = adoptWK(WKStringCreateWithUTF8CString(key)); 563 WKStringRef value = static_cast<WKStringRef>(WKDictionaryGetItemForKey(dictionary, wkKey.get())); 564 if (!value) { 565 outputText(makeString("String value for key", key, " not found in dictionary\n")); 566 return emptyString(); 567 } 568 return toWTFString(value); 490 postPageMessage("Error", "Unknown"); 569 491 } 570 492 … … 599 521 600 522 #if PLATFORM(IOS_FAMILY) 601 WKBundlePageSetUseTestingViewportConfiguration(page()->page(), !boolean ForKey(settings, "UseFlexibleViewport"));523 WKBundlePageSetUseTestingViewportConfiguration(page()->page(), !booleanValue(settings, "UseFlexibleViewport")); 602 524 #endif 603 525 604 526 #if PLATFORM(COCOA) 605 WebCoreTestSupport::setAdditionalSupportedImageTypesForTesting( stringForKey(settings, "additionalSupportedImageTypes"));527 WebCoreTestSupport::setAdditionalSupportedImageTypesForTesting(toWTFString(stringValue(settings, "additionalSupportedImageTypes"))); 606 528 #endif 607 529 … … 661 583 #endif 662 584 663 WKRetainPtr<WKStringRef> doneMessageName = adoptWK(WKStringCreateWithUTF8CString("Done")); 664 WKRetainPtr<WKMutableDictionaryRef> doneMessageBody = adoptWK(WKMutableDictionaryCreate()); 665 666 WKRetainPtr<WKStringRef> pixelResultIsPendingKey = adoptWK(WKStringCreateWithUTF8CString("PixelResultIsPending")); 667 WKRetainPtr<WKBooleanRef> pixelResultIsPending = adoptWK(WKBooleanCreate(m_pixelResultIsPending)); 668 WKDictionarySetItem(doneMessageBody.get(), pixelResultIsPendingKey.get(), pixelResultIsPending.get()); 669 670 if (!m_pixelResultIsPending) { 671 WKRetainPtr<WKStringRef> pixelResultKey = adoptWK(WKStringCreateWithUTF8CString("PixelResult")); 672 WKDictionarySetItem(doneMessageBody.get(), pixelResultKey.get(), m_pixelResult.get()); 673 } 674 675 WKRetainPtr<WKStringRef> repaintRectsKey = adoptWK(WKStringCreateWithUTF8CString("RepaintRects")); 676 WKDictionarySetItem(doneMessageBody.get(), repaintRectsKey.get(), m_repaintRects.get()); 677 678 WKRetainPtr<WKStringRef> audioResultKey = adoptWK(WKStringCreateWithUTF8CString("AudioResult")); 679 WKDictionarySetItem(doneMessageBody.get(), audioResultKey.get(), m_audioResult.get()); 680 681 WKBundlePagePostMessageIgnoringFullySynchronousMode(page()->page(), doneMessageName.get(), doneMessageBody.get()); 585 auto body = adoptWK(WKMutableDictionaryCreate()); 586 587 setValue(body, "PixelResultIsPending", m_pixelResultIsPending); 588 if (!m_pixelResultIsPending) 589 setValue(body, "PixelResult", m_pixelResult); 590 setValue(body, "RepaintRects", m_repaintRects); 591 setValue(body, "AudioResult", m_audioResult); 592 593 WKBundlePagePostMessageIgnoringFullySynchronousMode(page()->page(), toWK("Done").get(), body.get()); 682 594 683 595 closeOtherPages(); … … 692 604 for (size_t i = 1; i < size; ++i) 693 605 pagesToClose.append(m_pages[i]->page()); 694 size = pagesToClose.size(); 695 for (size_t i = 0; i < size; ++i) 696 WKBundlePageClose(pagesToClose[i]); 606 for (auto& page : pagesToClose) 607 WKBundlePageClose(page); 697 608 } 698 609 … … 710 621 if (output.isEmpty()) 711 622 return; 712 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("DumpToStdErr")); 713 WKRetainPtr<WKStringRef> messageBody; 714 if (auto utf8 = output.tryGetUtf8()) 715 messageBody = adoptWK(WKStringCreateWithUTF8CString(utf8->data())); 716 else 717 messageBody = adoptWK(WKStringCreateWithUTF8CString("Out of memory\n")); 718 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); 623 // FIXME: Do we really have to convert to UTF-8 instead of using toWK? 624 auto string = output.tryGetUtf8(); 625 postPageMessage("DumpToStdErr", string ? string->data() : "Out of memory\n"); 719 626 } 720 627 … … 725 632 if (output.isEmpty()) 726 633 return; 727 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("TextOutput")); 728 WKRetainPtr<WKStringRef> messageBody; 729 if (auto utf8 = output.tryGetUtf8()) 730 messageBody = adoptWK(WKStringCreateWithUTF8CString(utf8->data())); 731 else 732 messageBody = adoptWK(WKStringCreateWithUTF8CString("Out of memory\n")); 634 // FIXME: Do we really have to convert to UTF-8 instead of using toWK? 635 auto string = output.tryGetUtf8(); 733 636 // We use WKBundlePagePostMessageIgnoringFullySynchronousMode() instead of WKBundlePagePostMessage() to make sure that all text output 734 637 // is done via asynchronous IPC, even if the connection is in fully synchronous mode due to a WKBundlePagePostSynchronousMessageForTesting() 735 638 // call. Otherwise, messages logged via sync and async IPC may end up out of order and cause flakiness. 736 WKBundlePagePostMessageIgnoringFullySynchronousMode(page()->page(), messageName.get(), messageBody.get());639 WKBundlePagePostMessageIgnoringFullySynchronousMode(page()->page(), toWK("TextOutput").get(), toWK(string ? string->data() : "Out of memory\n").get()); 737 640 } 738 641 739 642 void InjectedBundle::postNewBeforeUnloadReturnValue(bool value) 740 643 { 741 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("BeforeUnloadReturnValue")); 742 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 743 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); 644 postPageMessage("BeforeUnloadReturnValue", value); 744 645 } 745 646 746 647 void InjectedBundle::postAddChromeInputField() 747 648 { 748 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("AddChromeInputField")); 749 WKBundlePagePostMessage(page()->page(), messageName.get(), 0); 649 postPageMessage("AddChromeInputField"); 750 650 } 751 651 752 652 void InjectedBundle::postRemoveChromeInputField() 753 653 { 754 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("RemoveChromeInputField")); 755 WKBundlePagePostMessage(page()->page(), messageName.get(), 0); 654 postPageMessage("RemoveChromeInputField"); 756 655 } 757 656 758 657 void InjectedBundle::postFocusWebView() 759 658 { 760 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("FocusWebView")); 761 WKBundlePagePostMessage(page()->page(), messageName.get(), 0); 659 postPageMessage("FocusWebView"); 762 660 } 763 661 764 662 void InjectedBundle::postSetBackingScaleFactor(double backingScaleFactor) 765 663 { 766 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetBackingScaleFactor")); 767 WKRetainPtr<WKDoubleRef> messageBody = adoptWK(WKDoubleCreate(backingScaleFactor)); 768 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); 664 postPageMessage("SetBackingScaleFactor", adoptWK(WKDoubleCreate(backingScaleFactor))); 769 665 } 770 666 771 667 void InjectedBundle::postSetWindowIsKey(bool isKey) 772 668 { 773 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetWindowIsKey")); 774 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(isKey)); 775 WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), messageBody.get(), 0); 669 WKBundlePagePostSynchronousMessageForTesting(page()->page(), toWK("SetWindowIsKey").get(), adoptWK(WKBooleanCreate(isKey)).get(), 0); 776 670 } 777 671 778 672 void InjectedBundle::postSetViewSize(double width, double height) 779 673 { 780 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetViewSize")); 781 782 WKRetainPtr<WKStringRef> widthKey = adoptWK(WKStringCreateWithUTF8CString("width")); 783 WKRetainPtr<WKStringRef> heightKey = adoptWK(WKStringCreateWithUTF8CString("height")); 784 785 WKRetainPtr<WKMutableDictionaryRef> messageBody = adoptWK(WKMutableDictionaryCreate()); 786 787 WKRetainPtr<WKDoubleRef> widthWK = adoptWK(WKDoubleCreate(width)); 788 WKDictionarySetItem(messageBody.get(), widthKey.get(), widthWK.get()); 789 790 WKRetainPtr<WKDoubleRef> heightWK = adoptWK(WKDoubleCreate(height)); 791 WKDictionarySetItem(messageBody.get(), heightKey.get(), heightWK.get()); 792 793 WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), messageBody.get(), 0); 674 auto body = adoptWK(WKMutableDictionaryCreate()); 675 setValue(body, "width", width); 676 setValue(body, "height", height); 677 WKBundlePagePostSynchronousMessageForTesting(page()->page(), toWK("SetViewSize").get(), body.get(), 0); 794 678 } 795 679 796 680 void InjectedBundle::postSimulateWebNotificationClick(uint64_t notificationID) 797 681 { 798 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SimulateWebNotificationClick")); 799 WKRetainPtr<WKUInt64Ref> messageBody = adoptWK(WKUInt64Create(notificationID)); 800 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); 682 postPageMessage("SimulateWebNotificationClick", adoptWK(WKUInt64Create(notificationID))); 801 683 } 802 684 803 685 void InjectedBundle::postSetAddsVisitedLinks(bool addsVisitedLinks) 804 686 { 805 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetAddsVisitedLinks")); 806 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(addsVisitedLinks)); 807 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); 687 postPageMessage("SetAddsVisitedLinks", adoptWK(WKBooleanCreate(addsVisitedLinks))); 808 688 } 809 689 810 690 void InjectedBundle::setGeolocationPermission(bool enabled) 811 691 { 812 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetGeolocationPermission")); 813 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(enabled)); 814 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); 815 } 816 817 void InjectedBundle::setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed, bool providesFloorLevel, double floorLevel) 818 { 819 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetMockGeolocationPosition")); 820 821 WKRetainPtr<WKMutableDictionaryRef> messageBody = adoptWK(WKMutableDictionaryCreate()); 822 823 WKRetainPtr<WKStringRef> latitudeKeyWK = adoptWK(WKStringCreateWithUTF8CString("latitude")); 824 WKRetainPtr<WKDoubleRef> latitudeWK = adoptWK(WKDoubleCreate(latitude)); 825 WKDictionarySetItem(messageBody.get(), latitudeKeyWK.get(), latitudeWK.get()); 826 827 WKRetainPtr<WKStringRef> longitudeKeyWK = adoptWK(WKStringCreateWithUTF8CString("longitude")); 828 WKRetainPtr<WKDoubleRef> longitudeWK = adoptWK(WKDoubleCreate(longitude)); 829 WKDictionarySetItem(messageBody.get(), longitudeKeyWK.get(), longitudeWK.get()); 830 831 WKRetainPtr<WKStringRef> accuracyKeyWK = adoptWK(WKStringCreateWithUTF8CString("accuracy")); 832 WKRetainPtr<WKDoubleRef> accuracyWK = adoptWK(WKDoubleCreate(accuracy)); 833 WKDictionarySetItem(messageBody.get(), accuracyKeyWK.get(), accuracyWK.get()); 834 835 WKRetainPtr<WKStringRef> providesAltitudeKeyWK = adoptWK(WKStringCreateWithUTF8CString("providesAltitude")); 836 WKRetainPtr<WKBooleanRef> providesAltitudeWK = adoptWK(WKBooleanCreate(providesAltitude)); 837 WKDictionarySetItem(messageBody.get(), providesAltitudeKeyWK.get(), providesAltitudeWK.get()); 838 839 WKRetainPtr<WKStringRef> altitudeKeyWK = adoptWK(WKStringCreateWithUTF8CString("altitude")); 840 WKRetainPtr<WKDoubleRef> altitudeWK = adoptWK(WKDoubleCreate(altitude)); 841 WKDictionarySetItem(messageBody.get(), altitudeKeyWK.get(), altitudeWK.get()); 842 843 WKRetainPtr<WKStringRef> providesAltitudeAccuracyKeyWK = adoptWK(WKStringCreateWithUTF8CString("providesAltitudeAccuracy")); 844 WKRetainPtr<WKBooleanRef> providesAltitudeAccuracyWK = adoptWK(WKBooleanCreate(providesAltitudeAccuracy)); 845 WKDictionarySetItem(messageBody.get(), providesAltitudeAccuracyKeyWK.get(), providesAltitudeAccuracyWK.get()); 846 847 WKRetainPtr<WKStringRef> altitudeAccuracyKeyWK = adoptWK(WKStringCreateWithUTF8CString("altitudeAccuracy")); 848 WKRetainPtr<WKDoubleRef> altitudeAccuracyWK = adoptWK(WKDoubleCreate(altitudeAccuracy)); 849 WKDictionarySetItem(messageBody.get(), altitudeAccuracyKeyWK.get(), altitudeAccuracyWK.get()); 850 851 WKRetainPtr<WKStringRef> providesHeadingKeyWK = adoptWK(WKStringCreateWithUTF8CString("providesHeading")); 852 WKRetainPtr<WKBooleanRef> providesHeadingWK = adoptWK(WKBooleanCreate(providesHeading)); 853 WKDictionarySetItem(messageBody.get(), providesHeadingKeyWK.get(), providesHeadingWK.get()); 854 855 WKRetainPtr<WKStringRef> headingKeyWK = adoptWK(WKStringCreateWithUTF8CString("heading")); 856 WKRetainPtr<WKDoubleRef> headingWK = adoptWK(WKDoubleCreate(heading)); 857 WKDictionarySetItem(messageBody.get(), headingKeyWK.get(), headingWK.get()); 858 859 WKRetainPtr<WKStringRef> providesSpeedKeyWK = adoptWK(WKStringCreateWithUTF8CString("providesSpeed")); 860 WKRetainPtr<WKBooleanRef> providesSpeedWK = adoptWK(WKBooleanCreate(providesSpeed)); 861 WKDictionarySetItem(messageBody.get(), providesSpeedKeyWK.get(), providesSpeedWK.get()); 862 863 WKRetainPtr<WKStringRef> speedKeyWK = adoptWK(WKStringCreateWithUTF8CString("speed")); 864 WKRetainPtr<WKDoubleRef> speedWK = adoptWK(WKDoubleCreate(speed)); 865 WKDictionarySetItem(messageBody.get(), speedKeyWK.get(), speedWK.get()); 866 867 WKRetainPtr<WKStringRef> providesFloorLevelKeyWK = adoptWK(WKStringCreateWithUTF8CString("providesFloorLevel")); 868 WKRetainPtr<WKBooleanRef> providesFloorLevelWK = adoptWK(WKBooleanCreate(providesFloorLevel)); 869 WKDictionarySetItem(messageBody.get(), providesFloorLevelKeyWK.get(), providesFloorLevelWK.get()); 870 871 WKRetainPtr<WKStringRef> floorLevelKeyWK = adoptWK(WKStringCreateWithUTF8CString("floorLevel")); 872 WKRetainPtr<WKDoubleRef> floorLevelWK = adoptWK(WKDoubleCreate(floorLevel)); 873 WKDictionarySetItem(messageBody.get(), floorLevelKeyWK.get(), floorLevelWK.get()); 874 875 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); 692 postPageMessage("SetGeolocationPermission", adoptWK(WKBooleanCreate(enabled))); 693 } 694 695 void InjectedBundle::setMockGeolocationPosition(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitudeAccuracy, Optional<double> heading, Optional<double> speed, Optional<double> floorLevel) 696 { 697 auto body = adoptWK(WKMutableDictionaryCreate()); 698 setValue(body, "latitude", latitude); 699 setValue(body, "longitude", longitude); 700 setValue(body, "accuracy", accuracy); 701 setValue(body, "altitude", altitude); 702 setValue(body, "altitudeAccuracy", altitudeAccuracy); 703 setValue(body, "heading", heading); 704 setValue(body, "speed", speed); 705 setValue(body, "floorLevel", floorLevel); 706 postPageMessage("SetMockGeolocationPosition", body); 876 707 } 877 708 878 709 void InjectedBundle::setMockGeolocationPositionUnavailableError(WKStringRef errorMessage) 879 710 { 880 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetMockGeolocationPositionUnavailableError")); 881 WKBundlePagePostMessage(page()->page(), messageName.get(), errorMessage); 711 postPageMessage("SetMockGeolocationPositionUnavailableError", errorMessage); 882 712 } 883 713 884 714 bool InjectedBundle::isGeolocationProviderActive() const 885 715 { 886 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("IsGeolocationClientActive")); 887 WKTypeRef resultToPass = 0; 888 WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), 0, &resultToPass); 889 WKRetainPtr<WKBooleanRef> isActive = adoptWK(static_cast<WKBooleanRef>(resultToPass)); 890 891 return WKBooleanGetValue(isActive.get()); 716 WKTypeRef result = nullptr; 717 WKBundlePagePostSynchronousMessageForTesting(page()->page(), toWK("IsGeolocationClientActive").get(), 0, &result); 718 return booleanValue(adoptWK(result).get()); 892 719 } 893 720 894 721 unsigned InjectedBundle::imageCountInGeneralPasteboard() const 895 722 { 896 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ImageCountInGeneralPasteboard")); 897 WKTypeRef resultToPass = 0; 898 WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), 0, &resultToPass); 899 WKRetainPtr<WKUInt64Ref> imageCount = adoptWK(static_cast<WKUInt64Ref>(resultToPass)); 900 901 return static_cast<unsigned>(WKUInt64GetValue(imageCount.get())); 723 WKTypeRef result = nullptr; 724 WKBundlePagePostSynchronousMessageForTesting(page()->page(), toWK("ImageCountInGeneralPasteboard").get(), 0, &result); 725 return uint64Value(adoptWK(result).get()); 902 726 } 903 727 904 728 void InjectedBundle::setUserMediaPermission(bool enabled) 905 729 { 906 auto messageName = adoptWK(WKStringCreateWithUTF8CString("SetUserMediaPermission")); 907 auto messageBody = adoptWK(WKBooleanCreate(enabled)); 908 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); 730 postPageMessage("SetUserMediaPermission", adoptWK(WKBooleanCreate(enabled))); 909 731 } 910 732 911 733 void InjectedBundle::resetUserMediaPermission() 912 734 { 913 auto messageName = adoptWK(WKStringCreateWithUTF8CString("ResetUserMediaPermission")); 914 WKBundlePagePostMessage(page()->page(), messageName.get(), 0); 735 postPageMessage("ResetUserMediaPermission"); 915 736 } 916 737 917 738 void InjectedBundle::setUserMediaPersistentPermissionForOrigin(bool permission, WKStringRef origin, WKStringRef parentOrigin) 918 739 { 919 auto messageName = adoptWK(WKStringCreateWithUTF8CString("SetUserMediaPersistentPermissionForOrigin")); 920 WKRetainPtr<WKMutableDictionaryRef> messageBody = adoptWK(WKMutableDictionaryCreate()); 921 922 WKRetainPtr<WKStringRef> permissionKeyWK = adoptWK(WKStringCreateWithUTF8CString("permission")); 923 WKRetainPtr<WKBooleanRef> permissionWK = adoptWK(WKBooleanCreate(permission)); 924 WKDictionarySetItem(messageBody.get(), permissionKeyWK.get(), permissionWK.get()); 925 926 WKRetainPtr<WKStringRef> originKeyWK = adoptWK(WKStringCreateWithUTF8CString("origin")); 927 WKDictionarySetItem(messageBody.get(), originKeyWK.get(), origin); 928 929 WKRetainPtr<WKStringRef> parentOriginKeyWK = adoptWK(WKStringCreateWithUTF8CString("parentOrigin")); 930 WKDictionarySetItem(messageBody.get(), parentOriginKeyWK.get(), parentOrigin); 931 932 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); 740 auto body = adoptWK(WKMutableDictionaryCreate()); 741 setValue(body, "permission", permission); 742 setValue(body, "origin", origin); 743 setValue(body, "parentOrigin", parentOrigin); 744 postPageMessage("SetUserMediaPersistentPermissionForOrigin", body); 933 745 } 934 746 935 747 unsigned InjectedBundle::userMediaPermissionRequestCountForOrigin(WKStringRef origin, WKStringRef parentOrigin) const 936 748 { 937 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("UserMediaPermissionRequestCountForOrigin")); 938 WKRetainPtr<WKMutableDictionaryRef> messageBody = adoptWK(WKMutableDictionaryCreate()); 939 940 WKRetainPtr<WKStringRef> originKeyWK = adoptWK(WKStringCreateWithUTF8CString("origin")); 941 WKDictionarySetItem(messageBody.get(), originKeyWK.get(), origin); 942 943 WKRetainPtr<WKStringRef> parentOriginKeyWK = adoptWK(WKStringCreateWithUTF8CString("parentOrigin")); 944 WKDictionarySetItem(messageBody.get(), parentOriginKeyWK.get(), parentOrigin); 945 946 WKTypeRef resultToPass = 0; 947 WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), messageBody.get(), &resultToPass); 948 WKRetainPtr<WKUInt64Ref> count = adoptWK(static_cast<WKUInt64Ref>(resultToPass)); 949 950 return static_cast<unsigned>(WKUInt64GetValue(count.get())); 749 auto body = adoptWK(WKMutableDictionaryCreate()); 750 setValue(body, "origin", origin); 751 setValue(body, "parentOrigin", parentOrigin); 752 WKTypeRef result = nullptr; 753 WKBundlePagePostSynchronousMessageForTesting(page()->page(), toWK("UserMediaPermissionRequestCountForOrigin").get(), body.get(), &result); 754 return uint64Value(adoptWK(result).get()); 951 755 } 952 756 953 757 void InjectedBundle::resetUserMediaPermissionRequestCountForOrigin(WKStringRef origin, WKStringRef parentOrigin) 954 758 { 955 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ResetUserMediaPermissionRequestCountForOrigin")); 956 WKRetainPtr<WKMutableDictionaryRef> messageBody = adoptWK(WKMutableDictionaryCreate()); 957 958 WKRetainPtr<WKStringRef> originKeyWK = adoptWK(WKStringCreateWithUTF8CString("origin")); 959 WKDictionarySetItem(messageBody.get(), originKeyWK.get(), origin); 960 961 WKRetainPtr<WKStringRef> parentOriginKeyWK = adoptWK(WKStringCreateWithUTF8CString("parentOrigin")); 962 WKDictionarySetItem(messageBody.get(), parentOriginKeyWK.get(), parentOrigin); 963 964 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); 759 auto body = adoptWK(WKMutableDictionaryCreate()); 760 setValue(body, "origin", origin); 761 setValue(body, "parentOrigin", parentOrigin); 762 postPageMessage("ResetUserMediaPermissionRequestCountForOrigin", body); 965 763 } 966 764 967 765 void InjectedBundle::setCustomPolicyDelegate(bool enabled, bool permissive) 968 766 { 969 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetCustomPolicyDelegate")); 970 971 WKRetainPtr<WKMutableDictionaryRef> messageBody = adoptWK(WKMutableDictionaryCreate()); 972 973 WKRetainPtr<WKStringRef> enabledKeyWK = adoptWK(WKStringCreateWithUTF8CString("enabled")); 974 WKRetainPtr<WKBooleanRef> enabledWK = adoptWK(WKBooleanCreate(enabled)); 975 WKDictionarySetItem(messageBody.get(), enabledKeyWK.get(), enabledWK.get()); 976 977 WKRetainPtr<WKStringRef> permissiveKeyWK = adoptWK(WKStringCreateWithUTF8CString("permissive")); 978 WKRetainPtr<WKBooleanRef> permissiveWK = adoptWK(WKBooleanCreate(permissive)); 979 WKDictionarySetItem(messageBody.get(), permissiveKeyWK.get(), permissiveWK.get()); 980 981 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); 767 auto body = adoptWK(WKMutableDictionaryCreate()); 768 setValue(body, "enabled", enabled); 769 setValue(body, "permissive", permissive); 770 postPageMessage("SetCustomPolicyDelegate", body); 982 771 } 983 772 984 773 void InjectedBundle::setHidden(bool hidden) 985 774 { 986 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetHidden")); 987 WKRetainPtr<WKMutableDictionaryRef> messageBody = adoptWK(WKMutableDictionaryCreate()); 988 989 WKRetainPtr<WKStringRef> isInitialKeyWK = adoptWK(WKStringCreateWithUTF8CString("hidden")); 990 WKRetainPtr<WKBooleanRef> isInitialWK = adoptWK(WKBooleanCreate(hidden)); 991 WKDictionarySetItem(messageBody.get(), isInitialKeyWK.get(), isInitialWK.get()); 992 993 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); 775 auto body = adoptWK(WKMutableDictionaryCreate()); 776 setValue(body, "hidden", hidden); 777 postPageMessage("SetHidden", body); 994 778 } 995 779 996 780 void InjectedBundle::setCacheModel(int model) 997 781 { 998 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetCacheModel")); 999 WKRetainPtr<WKUInt64Ref> messageBody = adoptWK(WKUInt64Create(model)); 1000 WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), messageBody.get(), nullptr); 782 WKBundlePagePostSynchronousMessageForTesting(page()->page(), toWK("SetCacheModel").get(), adoptWK(WKUInt64Create(model)).get(), nullptr); 1001 783 } 1002 784 … … 1006 788 return false; 1007 789 1008 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("IsWorkQueueEmpty")); 1009 WKTypeRef resultToPass = 0; 1010 WKBundlePagePostSynchronousMessageForTesting(page()->page(), messageName.get(), 0, &resultToPass); 1011 WKRetainPtr<WKBooleanRef> isEmpty = adoptWK(static_cast<WKBooleanRef>(resultToPass)); 790 WKTypeRef result = nullptr; 791 WKBundlePagePostSynchronousMessageForTesting(page()->page(), toWK("IsWorkQueueEmpty").get(), 0, &result); 1012 792 1013 793 // The IPC failed. This happens when swapping processes on navigation because the WebPageProxy unregisters itself 1014 794 // as a MessageReceiver from the old WebProcessProxy and register itself with the new WebProcessProxy instead. 1015 if (! isEmpty)795 if (!result) 1016 796 return false; 1017 797 1018 return !WKBooleanGetValue(isEmpty.get()); 798 auto isEmpty = booleanValue(adoptWK(result).get()); 799 return !isEmpty; 1019 800 } 1020 801 1021 802 void InjectedBundle::processWorkQueue() 1022 803 { 1023 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ProcessWorkQueue")); 1024 WKBundlePagePostMessage(page()->page(), messageName.get(), 0); 804 postPageMessage("ProcessWorkQueue"); 1025 805 } 1026 806 … … 1028 808 { 1029 809 m_useWorkQueue = true; 1030 1031 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("QueueBackNavigation")); 1032 WKRetainPtr<WKUInt64Ref> messageBody = adoptWK(WKUInt64Create(howFarBackward)); 1033 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); 810 postPageMessage("QueueBackNavigation", adoptWK(WKUInt64Create(howFarBackward))); 1034 811 } 1035 812 … … 1037 814 { 1038 815 m_useWorkQueue = true; 1039 1040 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("QueueForwardNavigation")); 1041 WKRetainPtr<WKUInt64Ref> messageBody = adoptWK(WKUInt64Create(howFarForward)); 1042 WKBundlePagePostMessage(page()->page(), messageName.get(), messageBody.get()); 816 postPageMessage("QueueForwardNavigation", adoptWK(WKUInt64Create(howFarForward))); 1043 817 } 1044 818 … … 1046 820 { 1047 821 m_useWorkQueue = true; 1048 1049 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("QueueLoad")); 1050 1051 WKRetainPtr<WKMutableDictionaryRef> loadData = adoptWK(WKMutableDictionaryCreate()); 1052 1053 WKRetainPtr<WKStringRef> urlKey = adoptWK(WKStringCreateWithUTF8CString("url")); 1054 WKDictionarySetItem(loadData.get(), urlKey.get(), url); 1055 1056 WKRetainPtr<WKStringRef> targetKey = adoptWK(WKStringCreateWithUTF8CString("target")); 1057 WKDictionarySetItem(loadData.get(), targetKey.get(), target); 1058 1059 WKRetainPtr<WKStringRef> shouldOpenExternalURLsKey = adoptWK(WKStringCreateWithUTF8CString("shouldOpenExternalURLs")); 1060 WKRetainPtr<WKBooleanRef> shouldOpenExternalURLsValue = adoptWK(WKBooleanCreate(shouldOpenExternalURLs)); 1061 WKDictionarySetItem(loadData.get(), shouldOpenExternalURLsKey.get(), shouldOpenExternalURLsValue.get()); 1062 1063 WKBundlePagePostMessage(page()->page(), messageName.get(), loadData.get()); 822 auto body = adoptWK(WKMutableDictionaryCreate()); 823 setValue(body, "url", url); 824 setValue(body, "target", target); 825 setValue(body, "shouldOpenExternalURLs", shouldOpenExternalURLs); 826 postPageMessage("QueueLoad", body); 1064 827 } 1065 828 … … 1067 830 { 1068 831 m_useWorkQueue = true; 1069 1070 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("QueueLoadHTMLString")); 1071 1072 WKRetainPtr<WKMutableDictionaryRef> loadData = adoptWK(WKMutableDictionaryCreate()); 1073 1074 WKRetainPtr<WKStringRef> contentKey = adoptWK(WKStringCreateWithUTF8CString("content")); 1075 WKDictionarySetItem(loadData.get(), contentKey.get(), content); 1076 1077 if (baseURL) { 1078 WKRetainPtr<WKStringRef> baseURLKey = adoptWK(WKStringCreateWithUTF8CString("baseURL")); 1079 WKDictionarySetItem(loadData.get(), baseURLKey.get(), baseURL); 1080 } 1081 1082 if (unreachableURL) { 1083 WKRetainPtr<WKStringRef> unreachableURLKey = adoptWK(WKStringCreateWithUTF8CString("unreachableURL")); 1084 WKDictionarySetItem(loadData.get(), unreachableURLKey.get(), unreachableURL); 1085 } 1086 1087 WKBundlePagePostMessage(page()->page(), messageName.get(), loadData.get()); 832 auto body = adoptWK(WKMutableDictionaryCreate()); 833 setValue(body, "content", content); 834 if (baseURL) 835 setValue(body, "baseURL", baseURL); 836 if (unreachableURL) 837 setValue(body, "unreachableURL", unreachableURL); 838 postPageMessage("QueueLoadHTMLString", body); 1088 839 } 1089 840 … … 1091 842 { 1092 843 m_useWorkQueue = true; 1093 1094 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("QueueReload")); 1095 WKBundlePagePostMessage(page()->page(), messageName.get(), 0); 844 postPageMessage("QueueReload"); 1096 845 } 1097 846 … … 1099 848 { 1100 849 m_useWorkQueue = true; 1101 1102 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("QueueLoadingScript")); 1103 WKBundlePagePostMessage(page()->page(), messageName.get(), script); 850 postPageMessage("QueueLoadingScript", script); 1104 851 } 1105 852 … … 1107 854 { 1108 855 m_useWorkQueue = true; 1109 1110 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("QueueNonLoadingScript")); 1111 WKBundlePagePostMessage(page()->page(), messageName.get(), script); 856 postPageMessage("QueueNonLoadingScript", script); 1112 857 } 1113 858 … … 1144 889 } 1145 890 891 void postMessage(const char* name) 892 { 893 postMessage(name, WKRetainPtr<WKTypeRef> { }); 894 } 895 896 void postMessage(const char* name, bool value) 897 { 898 postMessage(name, adoptWK(WKBooleanCreate(value))); 899 } 900 901 void postMessage(const char* name, unsigned value) 902 { 903 postMessage(name, adoptWK(WKUInt64Create(value))); 904 } 905 906 void postMessage(const char* name, JSStringRef value) 907 { 908 postMessage(name, toWK(value)); 909 } 910 911 void postSynchronousMessage(const char* name) 912 { 913 postSynchronousMessage(name, WKRetainPtr<WKTypeRef> { }); 914 } 915 916 void postSynchronousMessage(const char* name, bool value) 917 { 918 postSynchronousMessage(name, adoptWK(WKBooleanCreate(value))); 919 } 920 921 void postSynchronousMessage(const char* name, uint64_t value) 922 { 923 postSynchronousMessage(name, adoptWK(WKUInt64Create(value))); 924 } 925 926 void postSynchronousMessage(const char* name, unsigned value) 927 { 928 uint64_t promotedValue = value; 929 postSynchronousMessage(name, promotedValue); 930 } 931 932 void postSynchronousMessage(const char* name, double value) 933 { 934 postSynchronousMessage(name, adoptWK(WKDoubleCreate(value))); 935 } 936 937 void postPageMessage(const char* name) 938 { 939 postPageMessage(name, WKRetainPtr<WKTypeRef> { }); 940 } 941 942 void postPageMessage(const char* name, bool value) 943 { 944 postPageMessage(name, adoptWK(WKBooleanCreate(value))); 945 } 946 947 void postPageMessage(const char* name, const char* value) 948 { 949 postPageMessage(name, toWK(value)); 950 } 951 952 void postPageMessage(const char* name, WKStringRef value) 953 { 954 if (auto page = InjectedBundle::singleton().pageRef()) 955 WKBundlePagePostMessage(page, toWK(name).get(), value); 956 } 957 958 void postSynchronousPageMessage(const char* name) 959 { 960 postSynchronousPageMessage(name, WKRetainPtr<WKTypeRef> { }); 961 } 962 963 void postSynchronousPageMessage(const char* name, bool value) 964 { 965 postSynchronousPageMessage(name, adoptWK(WKBooleanCreate(value))); 966 } 967 1146 968 } // namespace WTR -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h ¶
r258075 r267761 1 1 /* 2 * Copyright (C) 2010-20 16Apple Inc. All rights reserved.2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 64 64 65 65 InjectedBundlePage* page() const; 66 WKBundlePageRef pageRef() const; 66 67 size_t pageCount() const { return m_pages.size(); } 67 68 void closeOtherPages(); … … 97 98 // Geolocation. 98 99 void setGeolocationPermission(bool); 99 void setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed, bool providesFloorLevel, doublefloorLevel);100 void setMockGeolocationPosition(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitudeAccuracy, Optional<double> heading, Optional<double> speed, Optional<double> floorLevel); 100 101 void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage); 101 102 bool isGeolocationProviderActive() const; … … 165 166 166 167 void platformInitialize(WKTypeRef initializationUserData); 167 void resetLocalSettings();168 168 169 169 enum class BegingTestingMode { New, Resume }; 170 170 void beginTesting(WKDictionaryRef initialSettings, BegingTestingMode); 171 172 bool booleanForKey(WKDictionaryRef, const char* key);173 String stringForKey(WKDictionaryRef, const char* key);174 171 175 172 WKBundleRef m_bundle { nullptr }; … … 211 208 }; 212 209 210 void postMessage(const char* name); 211 void postMessage(const char* name, bool value); 212 void postMessage(const char* name, int value); 213 void postMessage(const char* name, unsigned value); 214 void postMessage(const char* name, uint64_t value); 215 void postMessage(const char* name, const char* value); 216 void postMessage(const char* name, JSStringRef value); 217 void postMessage(const char* name, const void* value) = delete; 218 219 void postSynchronousMessage(const char* name); 220 void postSynchronousMessage(const char* name, bool value); 221 void postSynchronousMessage(const char* name, int value); 222 void postSynchronousMessage(const char* name, unsigned value); 223 void postSynchronousMessage(const char* name, uint64_t value); 224 void postSynchronousMessage(const char* name, double value); 225 void postSynchronousMessage(const char* name, const char* value); 226 void postSynchronousMessage(const char* name, const void* value) = delete; 227 228 void postPageMessage(const char* name); 229 void postPageMessage(const char* name, bool value); 230 void postPageMessage(const char* name, const char* value); 231 void postPageMessage(const char* name, WKStringRef value); 232 void postPageMessage(const char* name, const void* value) = delete; 233 234 void postSynchronousPageMessage(const char* name); 235 void postSynchronousPageMessage(const char* name, bool value); 236 void postSynchronousPageMessage(const char* name, const char* value); 237 void postSynchronousPageMessage(const char* name, const void* value) = delete; 238 239 template<typename T> void postMessage(const char* name, const WKRetainPtr<T>& value) 240 { 241 WKBundlePostMessage(InjectedBundle::singleton().bundle(), toWK(name).get(), value.get()); 242 } 243 244 template<typename T> void postSynchronousMessage(const char* name, const WKRetainPtr<T>& value) 245 { 246 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), toWK(name).get(), value.get(), nullptr); 247 } 248 249 template<typename T> void postPageMessage(const char* name, const WKRetainPtr<T>& value) 250 { 251 if (auto page = InjectedBundle::singleton().pageRef()) 252 WKBundlePagePostMessage(page, toWK(name).get(), value.get()); 253 } 254 255 template<typename T> void postSynchronousPageMessage(const char* name, const WKRetainPtr<T>& value) 256 { 257 if (auto page = InjectedBundle::singleton().pageRef()) 258 WKBundlePagePostSynchronousMessageForTesting(page, toWK(name).get(), value.get(), nullptr); 259 } 260 213 261 } // namespace WTR -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp ¶
r267640 r267761 61 61 namespace WTR { 62 62 63 static JSValueRef propertyValue(JSContextRef context, JSObjectRef object, const char* propertyName) 64 { 65 if (!object) 66 return 0; 67 auto propertyNameString = adopt(JSStringCreateWithUTF8CString(propertyName)); 68 return JSObjectGetProperty(context, object, propertyNameString.get(), 0); 69 } 70 71 static double propertyValueDouble(JSContextRef context, JSObjectRef object, const char* propertyName) 72 { 73 JSValueRef value = propertyValue(context, object, propertyName); 74 if (!value) 75 return 0; 76 return JSValueToNumber(context, value, 0); 77 } 78 79 static int propertyValueInt(JSContextRef context, JSObjectRef object, const char* propertyName) 80 { 81 return static_cast<int>(propertyValueDouble(context, object, propertyName)); 82 } 83 84 static double numericWindowPropertyValue(WKBundleFrameRef frame, const char* propertyName) 85 { 86 JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame); 87 return propertyValueDouble(context, JSContextGetGlobalObject(context), propertyName); 63 static double numericWindowProperty(WKBundleFrameRef frame, const char* name) 64 { 65 auto context = WKBundleFrameGetJavaScriptContext(frame); 66 return numericProperty(context, JSContextGetGlobalObject(context), name); 88 67 } 89 68 90 69 static WTF::String dumpPath(JSGlobalContextRef context, JSObjectRef nodeValue) 91 70 { 92 JSValueRef nodeNameValue = propertyValue(context, nodeValue, "nodeName"); 93 auto jsStringNodeName = adopt(JSValueToStringCopy(context, nodeNameValue, 0)); 94 WKRetainPtr<WKStringRef> nodeName = toWK(jsStringNodeName); 95 96 JSValueRef parentNode = propertyValue(context, nodeValue, "parentNode"); 97 98 StringBuilder stringBuilder; 99 stringBuilder.append(toWTFString(nodeName)); 100 101 if (parentNode && JSValueIsObject(context, parentNode)) { 102 stringBuilder.appendLiteral(" > "); 103 stringBuilder.append(dumpPath(context, (JSObjectRef)parentNode)); 104 } 105 106 return stringBuilder.toString(); 71 auto name = toWTFString(stringProperty(context, nodeValue, "nodeName")); 72 if (auto parentNode = objectProperty(context, nodeValue, "parentNode")) 73 return makeString(name, " > ", dumpPath(context, parentNode)); 74 return name; 107 75 } 108 76 … … 127 95 return "(null)"; 128 96 129 WKBundleFrameRef frame = WKBundlePageGetMainFrame(page); 130 131 JSGlobalContextRef context = WKBundleFrameGetJavaScriptContextForWorld(frame, world); 132 JSValueRef rangeValue = WKBundleFrameGetJavaScriptWrapperForRangeForWorld(frame, rangeRef, world); 97 auto frame = WKBundlePageGetMainFrame(page); 98 auto context = WKBundleFrameGetJavaScriptContextForWorld(frame, world); 99 auto rangeValue = WKBundleFrameGetJavaScriptWrapperForRangeForWorld(frame, rangeRef, world); 133 100 ASSERT(JSValueIsObject(context, rangeValue)); 134 JSObjectRef rangeObject = (JSObjectRef)rangeValue; 135 136 JSValueRef startNodeValue = propertyValue(context, rangeObject, "startContainer"); 137 ASSERT(JSValueIsObject(context, startNodeValue)); 138 JSObjectRef startNodeObject = (JSObjectRef)startNodeValue; 139 140 JSValueRef endNodeValue = propertyValue(context, rangeObject, "endContainer"); 141 ASSERT(JSValueIsObject(context, endNodeValue)); 142 JSObjectRef endNodeObject = (JSObjectRef)endNodeValue; 143 144 int startOffset = propertyValueInt(context, rangeObject, "startOffset"); 145 int endOffset = propertyValueInt(context, rangeObject, "endOffset"); 146 147 StringBuilder stringBuilder; 148 stringBuilder.appendLiteral("range from "); 149 stringBuilder.appendNumber(startOffset); 150 stringBuilder.appendLiteral(" of "); 151 stringBuilder.append(dumpPath(context, startNodeObject)); 152 stringBuilder.appendLiteral(" to "); 153 stringBuilder.appendNumber(endOffset); 154 stringBuilder.appendLiteral(" of "); 155 stringBuilder.append(dumpPath(context, endNodeObject)); 156 return stringBuilder.toString(); 101 auto rangeObject = (JSObjectRef)rangeValue; 102 103 return makeString("range from ", 104 numericProperty(context, rangeObject, "startOffset"), 105 " of ", 106 dumpPath(context, objectProperty(context, rangeObject, "startContainer")), 107 " to ", 108 numericProperty(context, rangeObject, "endOffset"), 109 " of ", 110 dumpPath(context, objectProperty(context, rangeObject, "endContainer")) 111 ); 157 112 } 158 113 … … 161 116 switch (type) { 162 117 case kWKFrameNavigationTypeLinkClicked: 163 return adoptWK(WKStringCreateWithUTF8CString("link clicked"));118 return toWK("link clicked"); 164 119 case kWKFrameNavigationTypeFormSubmitted: 165 return adoptWK(WKStringCreateWithUTF8CString("form submitted"));120 return toWK("form submitted"); 166 121 case kWKFrameNavigationTypeBackForward: 167 return adoptWK(WKStringCreateWithUTF8CString("back/forward"));122 return toWK("back/forward"); 168 123 case kWKFrameNavigationTypeReload: 169 return adoptWK(WKStringCreateWithUTF8CString("reload"));124 return toWK("reload"); 170 125 case kWKFrameNavigationTypeFormResubmitted: 171 return adoptWK(WKStringCreateWithUTF8CString("form resubmitted"));126 return toWK("form resubmitted"); 172 127 case kWKFrameNavigationTypeOther: 173 return adoptWK(WKStringCreateWithUTF8CString("other"));174 } 175 return adoptWK(WKStringCreateWithUTF8CString("illegal value"));128 return toWK("other"); 129 } 130 return toWK("illegal value"); 176 131 } 177 132 … … 186 141 } 187 142 188 static WTF::String securityOriginToStr(WKSecurityOriginRef origin) 189 { 190 StringBuilder stringBuilder; 191 stringBuilder.append('{'); 192 stringBuilder.append(toWTFString(adoptWK(WKSecurityOriginCopyProtocol(origin)))); 193 stringBuilder.appendLiteral(", "); 194 stringBuilder.append(toWTFString(adoptWK(WKSecurityOriginCopyHost(origin)))); 195 stringBuilder.appendLiteral(", "); 196 stringBuilder.appendNumber(WKSecurityOriginGetPort(origin)); 197 stringBuilder.append('}'); 198 199 return stringBuilder.toString(); 143 static WTF::String string(WKSecurityOriginRef origin) 144 { 145 return makeString('{', toWTFString(adoptWK(WKSecurityOriginCopyProtocol(origin))), ", ", toWTFString(adoptWK(WKSecurityOriginCopyHost(origin))), ", ", WKSecurityOriginGetPort(origin), '}'); 200 146 } 201 147 202 148 static WTF::String frameToStr(WKBundleFrameRef frame) 203 149 { 204 WKRetainPtr<WKStringRef>name = adoptWK(WKBundleFrameCopyName(frame));150 auto name = adoptWK(WKBundleFrameCopyName(frame)); 205 151 StringBuilder stringBuilder; 206 152 if (WKBundleFrameIsMainFrame(frame)) { … … 236 182 return "(null)"; 237 183 238 WKRetainPtr<WKStringRef>schemeString = adoptWK(WKURLCopyScheme(fileUrl));184 auto schemeString = adoptWK(WKURLCopyScheme(fileUrl)); 239 185 if (!isLocalFileScheme(schemeString.get())) 240 186 return toWTFString(adoptWK(WKURLCopyString(fileUrl))); 241 187 242 188 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page()); 243 WKRetainPtr<WKURLRef>mainFrameURL = adoptWK(WKBundleFrameCopyURL(mainFrame));189 auto mainFrameURL = adoptWK(WKBundleFrameCopyURL(mainFrame)); 244 190 if (!mainFrameURL) 245 191 mainFrameURL = adoptWK(WKBundleFrameCopyProvisionalURL(mainFrame)); … … 435 381 WKBundleFrameFocus(frame); 436 382 437 JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame); 438 WebCoreTestSupport::resetInternalsObject(context); 383 WebCoreTestSupport::resetInternalsObject(WKBundleFrameGetJavaScriptContext(frame)); 439 384 assignedUrlsCache().clear(); 440 385 … … 452 397 static void dumpFrameDescriptionSuitableForTestResult(WKBundleFrameRef frame, StringBuilder& stringBuilder) 453 398 { 454 WKRetainPtr<WKStringRef>name = adoptWK(WKBundleFrameCopyName(frame));399 auto name = adoptWK(WKBundleFrameCopyName(frame)); 455 400 if (WKBundleFrameIsMainFrame(frame)) { 456 401 if (WKStringIsEmpty(name.get())) { … … 487 432 static inline void dumpRequestDescriptionSuitableForTestResult(WKURLRequestRef request, StringBuilder& stringBuilder) 488 433 { 489 WKRetainPtr<WKURLRef> url = adoptWK(WKURLRequestCopyURL(request)); 490 WKRetainPtr<WKURLRef> firstParty = adoptWK(WKURLRequestCopyFirstPartyForCookies(request)); 491 WKRetainPtr<WKStringRef> httpMethod = adoptWK(WKURLRequestCopyHTTPMethod(request)); 492 493 stringBuilder.appendLiteral("<NSURLRequest URL "); 494 stringBuilder.append(pathSuitableForTestResult(url.get())); 495 stringBuilder.appendLiteral(", main document URL "); 496 stringBuilder.append(pathSuitableForTestResult(firstParty.get())); 497 stringBuilder.appendLiteral(", http method "); 498 434 auto url = adoptWK(WKURLRequestCopyURL(request)); 435 auto firstParty = adoptWK(WKURLRequestCopyFirstPartyForCookies(request)); 436 auto httpMethod = adoptWK(WKURLRequestCopyHTTPMethod(request)); 437 438 stringBuilder.append("<NSURLRequest URL ", pathSuitableForTestResult(url.get()), ", main document URL ", pathSuitableForTestResult(firstParty.get()), ", http method "); 499 439 if (WKStringIsEmpty(httpMethod.get())) 500 440 stringBuilder.appendLiteral("(none)"); 501 441 else 502 442 stringBuilder.append(toWTFString(httpMethod)); 503 504 443 stringBuilder.append('>'); 505 444 } … … 507 446 static inline void dumpResponseDescriptionSuitableForTestResult(WKURLResponseRef response, StringBuilder& stringBuilder, bool shouldDumpResponseHeaders = false) 508 447 { 509 WKRetainPtr<WKURLRef>url = adoptWK(WKURLResponseCopyURL(response));448 auto url = adoptWK(WKURLResponseCopyURL(response)); 510 449 if (!url) { 511 450 stringBuilder.appendLiteral("(null)"); … … 536 475 static inline void dumpErrorDescriptionSuitableForTestResult(WKErrorRef error, StringBuilder& stringBuilder) 537 476 { 538 WKRetainPtr<WKStringRef> errorDomain = adoptWK(WKErrorCopyDomain(error));539 interrorCode = WKErrorGetErrorCode(error);477 auto errorDomain = toWTFString(adoptWK(WKErrorCopyDomain(error))); 478 auto errorCode = WKErrorGetErrorCode(error); 540 479 541 480 // We need to do some error mapping here to match the test expectations (Mac error names are expected). 542 if ( WKStringIsEqualToUTF8CString(errorDomain.get(), "WebKitNetworkError")) {543 errorDomain = adoptWK(WKStringCreateWithUTF8CString("NSURLErrorDomain"));481 if (errorDomain == "WebKitNetworkError") { 482 errorDomain = "NSURLErrorDomain"; 544 483 errorCode = -999; 545 484 } 546 547 if (WKStringIsEqualToUTF8CString(errorDomain.get(), "WebKitPolicyError")) 548 errorDomain = adoptWK(WKStringCreateWithUTF8CString("WebKitErrorDomain")); 549 550 stringBuilder.appendLiteral("<NSError domain "); 551 stringBuilder.append(toWTFString(errorDomain)); 552 stringBuilder.appendLiteral(", code "); 553 stringBuilder.appendNumber(errorCode); 554 555 WKRetainPtr<WKURLRef> url = adoptWK(WKErrorCopyFailingURL(error)); 556 if (url.get()) { 557 WKRetainPtr<WKStringRef> urlString = adoptWK(WKURLCopyString(url.get())); 558 stringBuilder.appendLiteral(", failing URL \""); 559 stringBuilder.append(toWTFString(urlString)); 560 stringBuilder.append('"'); 561 } 562 485 if (errorDomain == "WebKitPolicyError") 486 errorDomain = "WebKitErrorDomain"; 487 488 stringBuilder.append("<NSError domain ", errorDomain, ", code ", errorCode); 489 if (auto url = adoptWK(WKErrorCopyFailingURL(error))) 490 stringBuilder.append(", failing URL \"", toWTFString(adoptWK(WKURLCopyString(url.get()))), '"'); 563 491 stringBuilder.append('>'); 564 492 } … … 696 624 697 625 if (!injectedBundle.testRunner()->testURL()) { 698 WKRetainPtr<WKURLRef>testURL = adoptWK(WKBundleFrameCopyProvisionalURL(frame));626 auto testURL = adoptWK(WKBundleFrameCopyProvisionalURL(frame)); 699 627 injectedBundle.testRunner()->setTestURL(testURL.get()); 700 628 } … … 775 703 static void dumpFrameScrollPosition(WKBundleFrameRef frame, StringBuilder& stringBuilder, FrameNamePolicy shouldIncludeFrameName = ShouldNotIncludeFrameName) 776 704 { 777 double x = numericWindowProperty Value(frame, "pageXOffset");778 double y = numericWindowProperty Value(frame, "pageYOffset");705 double x = numericWindowProperty(frame, "pageXOffset"); 706 double y = numericWindowProperty(frame, "pageYOffset"); 779 707 if (fabs(x) <= 0.00000001 && fabs(y) <= 0.00000001) 780 708 return; 781 709 782 710 if (shouldIncludeFrameName) { 783 WKRetainPtr<WKStringRef>name = adoptWK(WKBundleFrameCopyName(frame));711 auto name = adoptWK(WKBundleFrameCopyName(frame)); 784 712 stringBuilder.appendLiteral("frame '"); 785 713 stringBuilder.append(toWTFString(name)); … … 795 723 static void dumpDescendantFrameScrollPositions(WKBundleFrameRef frame, StringBuilder& stringBuilder) 796 724 { 797 WKRetainPtr<WKArrayRef>childFrames = adoptWK(WKBundleFrameCopyChildFrames(frame));725 auto childFrames = adoptWK(WKBundleFrameCopyChildFrames(frame)); 798 726 size_t size = WKArrayGetSize(childFrames.get()); 799 727 for (size_t i = 0; i < size; ++i) { … … 811 739 } 812 740 813 static JSRetainPtr<JSStringRef> toJS(const char* string)814 {815 return adopt(JSStringCreateWithUTF8CString(string));816 }817 818 741 static bool hasDocumentElement(WKBundleFrameRef frame) 819 742 { 820 JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame); 821 JSObjectRef globalObject = JSContextGetGlobalObject(context); 822 823 JSValueRef documentValue = JSObjectGetProperty(context, globalObject, toJS("document").get(), 0); 824 if (!documentValue) 825 return false; 826 827 ASSERT(JSValueIsObject(context, documentValue)); 828 JSObjectRef document = JSValueToObject(context, documentValue, 0); 829 830 JSValueRef documentElementValue = JSObjectGetProperty(context, document, toJS("documentElement").get(), 0); 831 if (!documentElementValue) 832 return false; 833 834 return JSValueToBoolean(context, documentElementValue); 743 auto context = WKBundleFrameGetJavaScriptContext(frame); 744 return objectProperty(context, JSContextGetGlobalObject(context), { "document", "documentElement" }); 835 745 } 836 746 … … 855 765 static void dumpDescendantFramesText(WKBundleFrameRef frame, StringBuilder& stringBuilder) 856 766 { 857 WKRetainPtr<WKArrayRef>childFrames = adoptWK(WKBundleFrameCopyChildFrames(frame));767 auto childFrames = adoptWK(WKBundleFrameCopyChildFrames(frame)); 858 768 size_t size = WKArrayGetSize(childFrames.get()); 859 769 for (size_t i = 0; i < size; ++i) { 860 770 WKBundleFrameRef subframe = static_cast<WKBundleFrameRef>(WKArrayGetItemAtIndex(childFrames.get(), i)); 861 WKRetainPtr<WKStringRef>subframeName = adoptWK(WKBundleFrameCopyName(subframe));771 auto subframeName = adoptWK(WKBundleFrameCopyName(subframe)); 862 772 863 773 // DumpRenderTree ignores empty frames, so do the same thing here. … … 885 795 { 886 796 #if USE(CF) && !PLATFORM(WIN_CAIRO) && !USE(DIRECT2D) 887 WKRetainPtr<WKDataRef>wkData = adoptWK(WKBundleFrameCopyWebArchive(frame));888 RetainPtr<CFDataRef>cfData = adoptCF(CFDataCreate(0, WKDataGetBytes(wkData.get()), WKDataGetSize(wkData.get())));889 RetainPtr<CFStringRef>cfString = adoptCF(WebCoreTestSupport::createXMLStringFromWebArchiveData(cfData.get()));797 auto wkData = adoptWK(WKBundleFrameCopyWebArchive(frame)); 798 auto cfData = adoptCF(CFDataCreate(0, WKDataGetBytes(wkData.get()), WKDataGetSize(wkData.get()))); 799 auto cfString = adoptCF(WebCoreTestSupport::createXMLStringFromWebArchiveData(cfData.get())); 890 800 stringBuilder.append(cfString.get()); 891 801 #endif … … 903 813 904 814 WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page); 905 WKRetainPtr<WKURLRef>urlRef = adoptWK(WKBundleFrameCopyURL(frame));815 auto urlRef = adoptWK(WKBundleFrameCopyURL(frame)); 906 816 String url = toWTFString(adoptWK(WKURLCopyString(urlRef.get()))); 907 WKRetainPtr<WKStringRef>mimeType = adoptWK(WKBundleFrameCopyMIMETypeForResourceWithURL(frame, urlRef.get()));817 auto mimeType = adoptWK(WKBundleFrameCopyMIMETypeForResourceWithURL(frame, urlRef.get())); 908 818 if (url.find("dumpAsText/") != notFound || WKStringIsEqualToUTF8CString(mimeType.get(), "text/plain")) 909 819 injectedBundle.testRunner()->dumpAsText(false); … … 1019 929 return; 1020 930 1021 JSGlobalContextRef context = WKBundleFrameGetJavaScriptContextForWorld(frame, world); 1022 JSObjectRef window = JSContextGetGlobalObject(context); 931 auto context = WKBundleFrameGetJavaScriptContextForWorld(frame, world); 1023 932 1024 933 if (WKBundleScriptWorldNormalWorld() != world) { 1025 JSObjectSetProperty(context, window, toJS("__worldID").get(), JSValueMakeNumber(context, TestRunner::worldIDForWorld(world)), kJSPropertyAttributeReadOnly, 0); 1026 return; 1027 } 1028 1029 JSValueRef exception = nullptr; 1030 injectedBundle.testRunner()->makeWindowObject(context, window, &exception); 1031 injectedBundle.gcController()->makeWindowObject(context, window, &exception); 1032 injectedBundle.eventSendingController()->makeWindowObject(context, window, &exception); 1033 injectedBundle.textInputController()->makeWindowObject(context, window, &exception); 934 setGlobalObjectProperty(context, "__worldID", TestRunner::worldIDForWorld(world)); 935 return; 936 } 937 938 injectedBundle.testRunner()->makeWindowObject(context); 939 injectedBundle.gcController()->makeWindowObject(context); 940 injectedBundle.eventSendingController()->makeWindowObject(context); 941 injectedBundle.textInputController()->makeWindowObject(context); 1034 942 #if HAVE(ACCESSIBILITY) 1035 injectedBundle.accessibilityController()->makeWindowObject(context , window, &exception);943 injectedBundle.accessibilityController()->makeWindowObject(context); 1036 944 #endif 1037 945 … … 1137 1045 return; 1138 1046 1139 WKRetainPtr<WKURLRef>url = adoptWK(WKURLRequestCopyURL(request));1047 auto url = adoptWK(WKURLRequestCopyURL(request)); 1140 1048 assignedUrlsCache().add(identifier, pathSuitableForTestResult(url.get())); 1141 1049 } … … 1176 1084 return nullptr; 1177 1085 1178 WKRetainPtr<WKURLRef>redirectURL = adoptWK(WKURLResponseCopyURL(response));1086 auto redirectURL = adoptWK(WKURLResponseCopyURL(response)); 1179 1087 if (injectedBundle.isTestRunning() && injectedBundle.testRunner()->willSendRequestReturnsNullOnRedirect() && redirectURL) { 1180 1088 injectedBundle.outputText("Returning null for this redirect\n"); … … 1182 1090 } 1183 1091 1184 WKRetainPtr<WKURLRef>url = adoptWK(WKURLRequestCopyURL(request));1185 WKRetainPtr<WKStringRef>host = adoptWK(WKURLCopyHostName(url.get()));1186 WKRetainPtr<WKStringRef>scheme = adoptWK(WKURLCopyScheme(url.get()));1187 WKRetainPtr<WKStringRef>urlString = adoptWK(WKURLCopyString(url.get()));1092 auto url = adoptWK(WKURLRequestCopyURL(request)); 1093 auto host = adoptWK(WKURLCopyHostName(url.get())); 1094 auto scheme = adoptWK(WKURLCopyScheme(url.get())); 1095 auto urlString = adoptWK(WKURLCopyString(url.get())); 1188 1096 if (host && !WKStringIsEmpty(host.get()) 1189 1097 && isHTTPOrHTTPSScheme(scheme.get()) … … 1193 1101 if (injectedBundle.isTestRunning()) { 1194 1102 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(m_page); 1195 WKRetainPtr<WKURLRef>mainFrameURL = adoptWK(WKBundleFrameCopyURL(mainFrame));1103 auto mainFrameURL = adoptWK(WKBundleFrameCopyURL(mainFrame)); 1196 1104 if (!mainFrameURL || WKStringIsEqualToUTF8CString(adoptWK(WKURLCopyString(mainFrameURL.get())).get(), "about:blank")) 1197 1105 mainFrameURL = adoptWK(WKBundleFrameCopyProvisionalURL(mainFrame)); 1198 1106 1199 WKRetainPtr<WKStringRef>mainFrameHost = adoptWK(WKURLCopyHostName(mainFrameURL.get()));1200 WKRetainPtr<WKStringRef>mainFrameScheme = adoptWK(WKURLCopyScheme(mainFrameURL.get()));1107 auto mainFrameHost = adoptWK(WKURLCopyHostName(mainFrameURL.get())); 1108 auto mainFrameScheme = adoptWK(WKURLCopyScheme(mainFrameURL.get())); 1201 1109 mainFrameIsExternal = isHTTPOrHTTPSScheme(mainFrameScheme.get()) && !isLocalHost(mainFrameHost.get()); 1202 1110 } … … 1215 1123 if (!body.isEmpty()) { 1216 1124 CString cBody = body.utf8(); 1217 WKRetainPtr<WKDataRef>body = adoptWK(WKDataCreate(reinterpret_cast<const unsigned char*>(cBody.data()), cBody.length()));1125 auto body = adoptWK(WKDataCreate(reinterpret_cast<const unsigned char*>(cBody.data()), cBody.length())); 1218 1126 return WKURLRequestCopySettingHTTPBody(request, body.get()); 1219 1127 } … … 1243 1151 return; 1244 1152 1245 WKRetainPtr<WKURLRef>url = adoptWK(WKURLResponseCopyURL(response));1246 WKRetainPtr<WKStringRef>urlString = adoptWK(WKURLCopyLastPathComponent(url.get()));1247 WKRetainPtr<WKStringRef>mimeTypeString = adoptWK(WKURLResponseCopyMIMEType(response));1153 auto url = adoptWK(WKURLResponseCopyURL(response)); 1154 auto urlString = adoptWK(WKURLCopyLastPathComponent(url.get())); 1155 auto mimeTypeString = adoptWK(WKURLResponseCopyMIMEType(response)); 1248 1156 1249 1157 StringBuilder stringBuilder; … … 1351 1259 stringBuilder.appendLiteral(" - decidePolicyForNavigationAction\n"); 1352 1260 dumpRequestDescriptionSuitableForTestResult(request, stringBuilder); 1353 stringBuilder.appendLiteral(" is main frame - "); 1354 stringBuilder.append(WKBundleFrameIsMainFrame(frame) ? "yes" : "no"); 1355 stringBuilder.appendLiteral(" should open URLs externally - "); 1356 stringBuilder.append(WKBundleNavigationActionGetShouldOpenExternalURLs(navigationAction) ? "yes" : "no"); 1261 stringBuilder.append(" is main frame - ", WKBundleFrameIsMainFrame(frame) ? "yes" : "no"); 1262 stringBuilder.append(" should open URLs externally - ", WKBundleNavigationActionGetShouldOpenExternalURLs(navigationAction) ? "yes" : "no"); 1357 1263 stringBuilder.append('\n'); 1358 1264 injectedBundle.outputText(stringBuilder.toString()); … … 1362 1268 return WKBundlePagePolicyActionPassThrough; 1363 1269 1364 WKRetainPtr<WKURLRef>url = adoptWK(WKURLRequestCopyURL(request));1365 WKRetainPtr<WKStringRef>urlScheme = adoptWK(WKURLCopyScheme(url.get()));1270 auto url = adoptWK(WKURLRequestCopyURL(request)); 1271 auto urlScheme = adoptWK(WKURLCopyScheme(url.get())); 1366 1272 1367 1273 StringBuilder stringBuilder; 1368 1274 stringBuilder.appendLiteral("Policy delegate: attempt to load "); 1369 if (isLocalFileScheme(urlScheme.get())) { 1370 WKRetainPtr<WKStringRef> filename = adoptWK(WKURLCopyLastPathComponent(url.get())); 1371 stringBuilder.append(toWTFString(filename)); 1372 } else { 1373 WKRetainPtr<WKStringRef> urlString = adoptWK(WKURLCopyString(url.get())); 1374 stringBuilder.append(toWTFString(urlString)); 1375 } 1275 if (isLocalFileScheme(urlScheme.get())) 1276 stringBuilder.append(toWTFString(adoptWK(WKURLCopyLastPathComponent(url.get())))); 1277 else 1278 stringBuilder.append(toWTFString(adoptWK(WKURLCopyString(url.get())))); 1376 1279 stringBuilder.appendLiteral(" with navigation type \'"); 1377 1280 stringBuilder.append(toWTFString(NavigationTypeToString(WKBundleNavigationActionGetNavigationType(navigationAction)))); 1378 1281 stringBuilder.appendLiteral("\'"); 1379 WKRetainPtr<WKBundleHitTestResultRef>hitTestResultRef = adoptWK(WKBundleNavigationActionCopyHitTestResult(navigationAction));1282 auto hitTestResultRef = adoptWK(WKBundleNavigationActionCopyHitTestResult(navigationAction)); 1380 1283 if (hitTestResultRef) { 1381 WKRetainPtr<WKBundleNodeHandleRef>nodeHandleRef = adoptWK(WKBundleHitTestResultCopyNodeHandle(hitTestResultRef.get()));1284 auto nodeHandleRef = adoptWK(WKBundleHitTestResultCopyNodeHandle(hitTestResultRef.get())); 1382 1285 stringBuilder.appendLiteral(" originating from "); 1383 1286 stringBuilder.append(dumpPath(m_page, m_world.get(), nodeHandleRef.get())); … … 1401 1304 auto& injectedBundle = InjectedBundle::singleton(); 1402 1305 if (injectedBundle.testRunner() && injectedBundle.testRunner()->isPolicyDelegateEnabled() && WKURLResponseIsAttachment(response)) { 1403 StringBuilder stringBuilder; 1404 WKRetainPtr<WKStringRef> filename = adoptWK(WKURLResponseCopySuggestedFilename(response)); 1405 stringBuilder.appendLiteral("Policy delegate: resource is an attachment, suggested file name \'"); 1406 stringBuilder.append(toWTFString(filename)); 1407 stringBuilder.appendLiteral("\'\n"); 1408 InjectedBundle::singleton().outputText(stringBuilder.toString()); 1306 InjectedBundle::singleton().outputText(makeString("Policy delegate: resource is an attachment, suggested file name \'", toWTFString(adoptWK(WKURLResponseCopySuggestedFilename(response))), "\'\n")); 1409 1307 } 1410 1308 … … 1472 1370 static WTF::String lastFileURLPathComponent(const WTF::String& path) 1473 1371 { 1474 size_tpos = path.find("file://");1372 auto pos = path.find("file://"); 1475 1373 ASSERT(WTF::notFound != pos); 1476 1374 1477 WTF::StringtmpPath = path.substring(pos + 7);1375 auto tmpPath = path.substring(pos + 7); 1478 1376 if (tmpPath.length() < 2) // Keep the lone slash to avoid empty output. 1479 1377 return tmpPath; … … 1522 1420 return; 1523 1421 1524 StringBuilder stringBuilder; 1525 stringBuilder.appendLiteral("UI DELEGATE STATUS CALLBACK: setStatusText:"); 1526 stringBuilder.append(toWTFString(statusbarText)); 1527 stringBuilder.append('\n'); 1528 injectedBundle.outputText(stringBuilder.toString()); 1422 injectedBundle.outputText(makeString("UI DELEGATE STATUS CALLBACK: setStatusText:", toWTFString(statusbarText), '\n')); 1529 1423 } 1530 1424 … … 1560 1454 // sufficient to just get a range of 10000 to determine if we were 1561 1455 // above or below a threshold. 1562 int64_t truncatedSpaceNeeded = (totalBytesNeeded / 10000) * 10000; 1563 1564 StringBuilder stringBuilder; 1565 stringBuilder.appendLiteral("UI DELEGATE APPLICATION CACHE CALLBACK: exceededApplicationCacheOriginQuotaForSecurityOrigin:"); 1566 stringBuilder.append(securityOriginToStr(origin)); 1567 stringBuilder.appendLiteral(" totalSpaceNeeded:~"); 1568 stringBuilder.appendNumber(truncatedSpaceNeeded); 1569 stringBuilder.append('\n'); 1570 injectedBundle.outputText(stringBuilder.toString()); 1456 auto truncatedSpaceNeeded = (totalBytesNeeded / 10000) * 10000; 1457 injectedBundle.outputText(makeString("UI DELEGATE APPLICATION CACHE CALLBACK: exceededApplicationCacheOriginQuotaForSecurityOrigin:", string(origin), " totalSpaceNeeded:~", truncatedSpaceNeeded, '\n')); 1571 1458 } 1572 1459 … … 1581 1468 { 1582 1469 auto& injectedBundle = InjectedBundle::singleton(); 1583 if (injectedBundle.testRunner()->shouldDumpDatabaseCallbacks()) { 1584 StringBuilder stringBuilder; 1585 stringBuilder.appendLiteral("UI DELEGATE DATABASE CALLBACK: exceededDatabaseQuotaForSecurityOrigin:"); 1586 stringBuilder.append(securityOriginToStr(origin)); 1587 stringBuilder.appendLiteral(" database:"); 1588 stringBuilder.append(toWTFString(databaseName)); 1589 stringBuilder.append('\n'); 1590 injectedBundle.outputText(stringBuilder.toString()); 1591 } 1470 if (injectedBundle.testRunner()->shouldDumpDatabaseCallbacks()) 1471 injectedBundle.outputText(makeString("UI DELEGATE DATABASE CALLBACK: exceededDatabaseQuotaForSecurityOrigin:", string(origin), " database:", toWTFString(databaseName), '\n')); 1592 1472 1593 1473 uint64_t defaultQuota = 5 * 1024 * 1024; … … 1602 1482 if (defaultQuota < expectedUsageBytes && expectedUsageBytes <= maxQuota) { 1603 1483 newQuota = expectedUsageBytes; 1604 1605 StringBuilder stringBuilder; 1606 stringBuilder.appendLiteral("UI DELEGATE DATABASE CALLBACK: increased quota to "); 1607 stringBuilder.appendNumber(newQuota); 1608 stringBuilder.append('\n'); 1609 injectedBundle.outputText(stringBuilder.toString()); 1484 injectedBundle.outputText(makeString("UI DELEGATE DATABASE CALLBACK: increased quota to ", newQuota, '\n')); 1610 1485 } 1611 1486 } … … 1676 1551 return true; 1677 1552 1678 if (injectedBundle.testRunner()->shouldDumpEditingCallbacks()) { 1679 StringBuilder stringBuilder; 1680 stringBuilder.appendLiteral("EDITING DELEGATE: shouldBeginEditingInDOMRange:"); 1681 stringBuilder.append(rangeToStr(m_page, m_world.get(), range)); 1682 stringBuilder.append('\n'); 1683 injectedBundle.outputText(stringBuilder.toString()); 1684 } 1553 if (injectedBundle.testRunner()->shouldDumpEditingCallbacks()) 1554 injectedBundle.outputText(makeString("EDITING DELEGATE: shouldBeginEditingInDOMRange:", rangeToStr(m_page, m_world.get(), range), '\n')); 1685 1555 return injectedBundle.testRunner()->shouldAllowEditing(); 1686 1556 } … … 1692 1562 return true; 1693 1563 1694 if (injectedBundle.testRunner()->shouldDumpEditingCallbacks()) { 1695 StringBuilder stringBuilder; 1696 stringBuilder.appendLiteral("EDITING DELEGATE: shouldEndEditingInDOMRange:"); 1697 stringBuilder.append(rangeToStr(m_page, m_world.get(), range)); 1698 stringBuilder.append('\n'); 1699 injectedBundle.outputText(stringBuilder.toString()); 1700 } 1564 if (injectedBundle.testRunner()->shouldDumpEditingCallbacks()) 1565 injectedBundle.outputText(makeString("EDITING DELEGATE: shouldEndEditingInDOMRange:", rangeToStr(m_page, m_world.get(), range), '\n')); 1701 1566 return injectedBundle.testRunner()->shouldAllowEditing(); 1702 1567 } -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp ¶
r267750 r267761 1 1 /* 2 * Copyright (C) 2010-20 17Apple Inc. All rights reserved.2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 27 27 #include "TestRunner.h" 28 28 29 #include "DictionaryFunctions.h" 29 30 #include "InjectedBundle.h" 30 31 #include "InjectedBundlePage.h" 31 32 #include "JSTestRunner.h" 32 33 #include "PlatformWebView.h" 33 #include "StringFunctions.h"34 34 #include "TestController.h" 35 35 #include <JavaScriptCore/JSCTestRunnerUtils.h> … … 70 70 71 71 TestRunner::TestRunner() 72 : m_userStyleSheetLocation( adoptWK(WKStringCreateWithUTF8CString("")))72 : m_userStyleSheetLocation(toWK("")) 73 73 { 74 74 platformInitialize(); … … 84 84 } 85 85 86 static WKBundlePageRef page() 87 { 88 return InjectedBundle::singleton().page()->page(); 89 } 90 91 static WKBundleFrameRef mainFrame() 92 { 93 return WKBundlePageGetMainFrame(page()); 94 } 95 96 static JSContextRef mainFrameJSContext() 97 { 98 return WKBundleFrameGetJavaScriptContext(mainFrame()); 99 } 100 86 101 void TestRunner::display() 87 102 { 88 WKBundlePageRef page = InjectedBundle::singleton().page()->page(); 89 WKBundlePageForceRepaint(page); 103 WKBundlePageForceRepaint(page()); 90 104 } 91 105 92 106 void TestRunner::displayAndTrackRepaints() 93 107 { 94 WKBundlePageRef page = InjectedBundle::singleton().page()->page();108 auto page = WTR::page(); 95 109 WKBundlePageForceRepaint(page); 96 110 WKBundlePageSetTracksRepaints(page, true); … … 98 112 } 99 113 114 static WKRetainPtr<WKDoubleRef> toWK(double value) 115 { 116 return adoptWK(WKDoubleCreate(value)); 117 } 118 119 static WKRetainPtr<WKDictionaryRef> createWKDictionary(std::initializer_list<std::pair<const char*, WKRetainPtr<WKTypeRef>>> pairs) 120 { 121 Vector<WKStringRef> keys; 122 Vector<WKTypeRef> values; 123 Vector<WKRetainPtr<WKStringRef>> strings; 124 for (auto& pair : pairs) { 125 auto key = toWK(pair.first); 126 keys.append(key.get()); 127 values.append(pair.second.get()); 128 strings.append(WTFMove(key)); 129 } 130 return adoptWK(WKDictionaryCreate(keys.data(), values.data(), keys.size())); 131 } 132 133 template<typename T> static WKRetainPtr<WKTypeRef> postSynchronousMessageWithReturnValue(const char* name, const WKRetainPtr<T>& value) 134 { 135 WKTypeRef rawReturnValue = nullptr; 136 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), toWK(name).get(), value.get(), &rawReturnValue); 137 return adoptWK(rawReturnValue); 138 } 139 140 template<typename T> static bool postSynchronousMessageReturningBoolean(const char* name, const WKRetainPtr<T>& value) 141 { 142 return booleanValue(postSynchronousMessageWithReturnValue(name, value)); 143 } 144 145 static bool postSynchronousMessageReturningBoolean(const char* name) 146 { 147 return postSynchronousMessageReturningBoolean(name, WKRetainPtr<WKTypeRef> { }); 148 } 149 150 template<typename T> static WKRetainPtr<WKTypeRef> postSynchronousPageMessageWithReturnValue(const char* name, const WKRetainPtr<T>& value) 151 { 152 WKTypeRef rawReturnValue = nullptr; 153 WKBundlePagePostSynchronousMessageForTesting(page(), toWK(name).get(), value.get(), &rawReturnValue); 154 return adoptWK(rawReturnValue); 155 } 156 157 template<typename T> static bool postSynchronousPageMessageReturningBoolean(const char* name, const WKRetainPtr<T>& value) 158 { 159 return booleanValue(postSynchronousPageMessageWithReturnValue(name, value)); 160 } 161 162 static bool postSynchronousPageMessageReturningBoolean(const char* name) 163 { 164 return postSynchronousPageMessageReturningBoolean(name, WKRetainPtr<WKTypeRef> { }); 165 } 166 167 static bool postSynchronousPageMessageReturningBoolean(const char* name, JSStringRef string) 168 { 169 return postSynchronousPageMessageReturningBoolean(name, toWK(string)); 170 } 171 172 template<typename T> static uint64_t postSynchronousPageMessageReturningUInt64(const char* name, const WKRetainPtr<T>& value) 173 { 174 return uint64Value(postSynchronousPageMessageWithReturnValue(name, value)); 175 } 176 177 static uint64_t postSynchronousMessageReturningUInt64(const char* name) 178 { 179 return uint64Value(postSynchronousMessageWithReturnValue(name, WKRetainPtr<WKTypeRef> { })); 180 } 181 182 static bool postSynchronousPageMessageReturningUInt64(const char* name, JSStringRef string) 183 { 184 return postSynchronousPageMessageReturningUInt64(name, toWK(string)); 185 } 186 187 static void overridePreference(const char* name, bool value) 188 { 189 auto& bundle = InjectedBundle::singleton(); 190 WKBundleOverrideBoolPreferenceForTestRunner(bundle.bundle(), bundle.pageGroup(), toWK(name).get(), value); 191 } 192 100 193 bool TestRunner::shouldDumpPixels() const 101 194 { 102 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("GetDumpPixels")); 103 WKTypeRef returnData = nullptr; 104 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, &returnData); 105 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 106 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 195 return postSynchronousMessageReturningBoolean("GetDumpPixels"); 107 196 } 108 197 109 198 void TestRunner::setDumpPixels(bool dumpPixels) 110 199 { 111 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetDumpPixels")); 112 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(dumpPixels)); 113 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 200 postSynchronousMessage("SetDumpPixels", dumpPixels); 114 201 } 115 202 … … 123 210 WhatToDump TestRunner::whatToDump() const 124 211 { 125 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("GetWhatToDump")); 126 WKTypeRef returnData = nullptr; 127 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, &returnData); 128 ASSERT(WKGetTypeID(returnData) == WKUInt64GetTypeID()); 129 return static_cast<WhatToDump>(WKUInt64GetValue(adoptWK(static_cast<WKUInt64Ref>(returnData)).get())); 212 return static_cast<WhatToDump>(postSynchronousMessageReturningUInt64("GetWhatToDump")); 130 213 } 131 214 132 215 void TestRunner::setWhatToDump(WhatToDump whatToDump) 133 216 { 134 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetWhatToDump")); 135 WKRetainPtr<WKUInt64Ref> messageBody = adoptWK(WKUInt64Create(static_cast<uint64_t>(whatToDump))); 136 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 217 postSynchronousMessage("SetWhatToDump", static_cast<uint64_t>(whatToDump)); 137 218 } 138 219 … … 159 240 void TestRunner::waitUntilDone() 160 241 { 161 auto& injectedBundle = InjectedBundle::singleton(); 162 RELEASE_ASSERT(injectedBundle.isTestRunning()); 242 RELEASE_ASSERT(InjectedBundle::singleton().isTestRunning()); 163 243 164 244 setWaitUntilDone(true); … … 167 247 void TestRunner::setWaitUntilDone(bool value) 168 248 { 169 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetWaitUntilDone")); 170 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 171 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 249 postSynchronousMessage("SetWaitUntilDone", value); 172 250 } 173 251 174 252 bool TestRunner::shouldWaitUntilDone() const 175 253 { 176 WKRetainPtr<WKStringRef> messsageName = adoptWK(WKStringCreateWithUTF8CString("GetWaitUntilDone")); 177 WKTypeRef returnData = nullptr; 178 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messsageName.get(), nullptr, &returnData); 179 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 180 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 254 return postSynchronousMessageReturningBoolean("GetWaitUntilDone"); 181 255 } 182 256 … … 211 285 void TestRunner::setShouldDumpFrameLoadCallbacks(bool value) 212 286 { 213 WKRetainPtr<WKStringRef> messsageName = adoptWK(WKStringCreateWithUTF8CString("SetDumpFrameLoadCallbacks")); 214 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 215 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messsageName.get(), messageBody.get(), nullptr); 287 postSynchronousMessage("SetDumpFrameLoadCallbacks", value); 216 288 } 217 289 218 290 bool TestRunner::shouldDumpFrameLoadCallbacks() 219 291 { 220 WKRetainPtr<WKStringRef> messsageName = adoptWK(WKStringCreateWithUTF8CString("GetDumpFrameLoadCallbacks")); 221 WKTypeRef returnData = nullptr; 222 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messsageName.get(), nullptr, &returnData); 223 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 224 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 292 return postSynchronousMessageReturningBoolean("GetDumpFrameLoadCallbacks"); 225 293 } 226 294 … … 232 300 void TestRunner::addUserScript(JSStringRef source, bool runAtStart, bool allFrames) 233 301 { 234 WKRetainPtr<WKStringRef> sourceWK = toWK(source); 235 236 WKBundlePageAddUserScript(InjectedBundle::singleton().page()->page(), sourceWK.get(), 302 WKBundlePageAddUserScript(page(), toWK(source).get(), 237 303 (runAtStart ? kWKInjectAtDocumentStart : kWKInjectAtDocumentEnd), 238 304 (allFrames ? kWKInjectInAllFrames : kWKInjectInTopFrameOnly)); … … 241 307 void TestRunner::addUserStyleSheet(JSStringRef source, bool allFrames) 242 308 { 243 WKRetainPtr<WKStringRef> sourceWK = toWK(source); 244 245 WKBundlePageAddUserStyleSheet(InjectedBundle::singleton().page()->page(), sourceWK.get(), 309 WKBundlePageAddUserStyleSheet(page(), toWK(source).get(), 246 310 (allFrames ? kWKInjectInAllFrames : kWKInjectInTopFrameOnly)); 247 311 } … … 254 318 void TestRunner::execCommand(JSStringRef name, JSStringRef showUI, JSStringRef value) 255 319 { 256 WKBundlePageExecuteEditingCommand( InjectedBundle::singleton().page()->page(), toWK(name).get(), toWK(value).get());320 WKBundlePageExecuteEditingCommand(page(), toWK(name).get(), toWK(value).get()); 257 321 } 258 322 259 323 static Optional<WKFindOptions> findOptionsFromArray(JSValueRef optionsArrayAsValue) 260 324 { 261 auto& injectedBundle = InjectedBundle::singleton(); 262 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(injectedBundle.page()->page()); 263 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); 264 auto lengthPropertyName = adopt(JSStringCreateWithUTF8CString("length")); 265 JSObjectRef optionsArray = JSValueToObject(context, optionsArrayAsValue, 0); 266 JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0); 267 if (!JSValueIsNumber(context, lengthValue)) 268 return WTF::nullopt; 269 325 auto context = mainFrameJSContext(); 326 auto optionsArray = JSValueToObject(context, optionsArrayAsValue, nullptr); 327 auto length = arrayLength(context, optionsArray); 270 328 WKFindOptions options = 0; 271 size_t length = static_cast<size_t>(JSValueToNumber(context, lengthValue, 0)); 272 for (size_t i = 0; i < length; ++i) { 273 JSValueRef value = JSObjectGetPropertyAtIndex(context, optionsArray, i, 0); 274 if (!JSValueIsString(context, value)) 275 continue; 276 277 auto optionName = adopt(JSValueToStringCopy(context, value, 0)); 278 329 for (unsigned i = 0; i < length; ++i) { 330 auto optionName = createJSString(context, JSObjectGetPropertyAtIndex(context, optionsArray, i, 0)); 279 331 if (JSStringIsEqualToUTF8CString(optionName.get(), "CaseInsensitive")) 280 332 options |= kWKFindOptionsCaseInsensitive; … … 297 349 { 298 350 if (auto options = findOptionsFromArray(optionsArrayAsValue)) 299 return WKBundlePageFindString( InjectedBundle::singleton().page()->page(), toWK(target).get(), *options);351 return WKBundlePageFindString(page(), toWK(target).get(), *options); 300 352 301 353 return false; … … 305 357 { 306 358 if (auto options = findOptionsFromArray(optionsArrayAsValue)) 307 return WKBundlePageFindStringMatches(InjectedBundle::singleton().page()->page(), toWK(target).get(), *options);359 WKBundlePageFindStringMatches(page(), toWK(target).get(), *options); 308 360 } 309 361 … … 311 363 { 312 364 auto& bundle = InjectedBundle::singleton(); 313 auto mainFrame = WKBundlePageGetMainFrame(bundle.page()->page()); 314 auto context = WKBundleFrameGetJavaScriptContext(mainFrame); 315 auto lengthPropertyName = adopt(JSStringCreateWithUTF8CString("length")); 365 auto context = mainFrameJSContext(); 316 366 auto matchIndicesObject = JSValueToObject(context, matchIndicesAsValue, 0); 317 auto lengthValue = JSObjectGetProperty(context, matchIndicesObject, lengthPropertyName.get(), 0); 318 if (!JSValueIsNumber(context, lengthValue)) 319 return; 367 auto length = arrayLength(context, matchIndicesObject); 320 368 321 369 auto indices = adoptWK(WKMutableArrayCreate()); 322 auto length = static_cast<size_t>(JSValueToNumber(context, lengthValue, 0)); 323 for (size_t i = 0; i < length; ++i) { 324 auto value = JSObjectGetPropertyAtIndex(context, matchIndicesObject, i, 0); 370 for (unsigned i = 0; i < length; ++i) { 371 auto value = JSObjectGetPropertyAtIndex(context, matchIndicesObject, i, nullptr); 325 372 if (!JSValueIsNumber(context, value)) 326 373 continue; 327 374 328 auto index = adoptWK(WKUInt64Create( std::round(JSValueToNumber(context, value, nullptr))));375 auto index = adoptWK(WKUInt64Create(JSValueToNumber(context, value, nullptr))); 329 376 WKArrayAppendItem(indices.get(), index.get()); 330 377 } … … 335 382 { 336 383 WKBundleClearAllDatabases(InjectedBundle::singleton().bundle()); 337 338 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("DeleteAllIndexedDatabases")); 339 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(true)); 340 341 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 384 postSynchronousMessage("DeleteAllIndexedDatabases", true); 342 385 } 343 386 … … 349 392 void TestRunner::syncLocalStorage() 350 393 { 351 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SyncLocalStorage")); 352 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(true)); 353 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 394 postSynchronousMessage("SyncLocalStorage", true); 354 395 } 355 396 356 397 void TestRunner::clearAllApplicationCaches() 357 398 { 358 WKBundlePageClearApplicationCache( InjectedBundle::singleton().page()->page());399 WKBundlePageClearApplicationCache(page()); 359 400 } 360 401 361 402 void TestRunner::clearApplicationCacheForOrigin(JSStringRef origin) 362 403 { 363 WKBundlePageClearApplicationCacheForOrigin( InjectedBundle::singleton().page()->page(), toWK(origin).get());404 WKBundlePageClearApplicationCacheForOrigin(page(), toWK(origin).get()); 364 405 } 365 406 366 407 void TestRunner::setAppCacheMaximumSize(uint64_t size) 367 408 { 368 WKBundlePageSetAppCacheMaximumSize( InjectedBundle::singleton().page()->page(), size);409 WKBundlePageSetAppCacheMaximumSize(page(), size); 369 410 } 370 411 371 412 long long TestRunner::applicationCacheDiskUsageForOrigin(JSStringRef origin) 372 413 { 373 return WKBundlePageGetAppCacheUsageForOrigin( InjectedBundle::singleton().page()->page(), toWK(origin).get());414 return WKBundlePageGetAppCacheUsageForOrigin(page(), toWK(origin).get()); 374 415 } 375 416 … … 382 423 { 383 424 const size_t count = WKArrayGetSize(strings); 384 385 JSValueRef arrayResult = JSObjectMakeArray(context, 0, 0, 0); 386 JSObjectRef arrayObj = JSValueToObject(context, arrayResult, 0); 425 auto array = JSObjectMakeArray(context, 0, 0, nullptr); 387 426 for (size_t i = 0; i < count; ++i) { 388 WKStringRef stringRef = static_cast<WKStringRef>(WKArrayGetItemAtIndex(strings, i)); 389 JSRetainPtr<JSStringRef> stringJS = toJS(stringRef); 390 JSObjectSetPropertyAtIndex(context, arrayObj, i, JSValueMakeString(context, stringJS.get()), 0); 427 auto stringRef = static_cast<WKStringRef>(WKArrayGetItemAtIndex(strings, i)); 428 JSObjectSetPropertyAtIndex(context, array, i, JSValueMakeString(context, toJS(stringRef).get()), nullptr); 391 429 } 392 393 return arrayResult; 430 return array; 394 431 } 395 432 396 433 JSValueRef TestRunner::originsWithApplicationCache() 397 434 { 398 WKBundlePageRef page = InjectedBundle::singleton().page()->page(); 399 400 WKRetainPtr<WKArrayRef> origins = adoptWK(WKBundlePageCopyOriginsWithApplicationCache(page)); 401 402 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(page); 403 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); 404 405 return stringArrayToJS(context, origins.get()); 435 return stringArrayToJS(mainFrameJSContext(), adoptWK(WKBundlePageCopyOriginsWithApplicationCache(page())).get()); 406 436 } 407 437 408 438 bool TestRunner::isCommandEnabled(JSStringRef name) 409 439 { 410 return WKBundlePageIsEditingCommandEnabled( InjectedBundle::singleton().page()->page(), toWK(name).get());440 return WKBundlePageIsEditingCommandEnabled(page(), toWK(name).get()); 411 441 } 412 442 413 443 void TestRunner::setCanOpenWindows() 414 444 { 415 WKRetainPtr<WKStringRef> messsageName = adoptWK(WKStringCreateWithUTF8CString("SetCanOpenWindows")); 416 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(true)); 417 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messsageName.get(), messageBody.get(), nullptr); 445 postSynchronousMessage("SetCanOpenWindows", true); 418 446 } 419 447 420 448 void TestRunner::setXSSAuditorEnabled(bool enabled) 421 449 { 422 WKRetainPtr<WKStringRef> key = adoptWK(WKStringCreateWithUTF8CString("WebKitXSSAuditorEnabled")); 423 auto& injectedBundle = InjectedBundle::singleton(); 424 WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled); 450 WTR::overridePreference("WebKitXSSAuditorEnabled", enabled); 425 451 } 426 452 427 453 void TestRunner::setMediaDevicesEnabled(bool enabled) 428 454 { 429 WKRetainPtr<WKStringRef> key = adoptWK(WKStringCreateWithUTF8CString("WebKitMediaDevicesEnabled")); 430 auto& injectedBundle = InjectedBundle::singleton(); 431 WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled); 455 WTR::overridePreference("WebKitMediaDevicesEnabled", enabled); 432 456 } 433 457 434 458 void TestRunner::setWebRTCMDNSICECandidatesEnabled(bool enabled) 435 459 { 436 WKRetainPtr<WKStringRef> key = adoptWK(WKStringCreateWithUTF8CString("WebKitWebRTCMDNSICECandidatesEnabled")); 437 auto& injectedBundle = InjectedBundle::singleton(); 438 WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled); 460 WTR::overridePreference("WebKitWebRTCMDNSICECandidatesEnabled", enabled); 439 461 } 440 462 441 463 void TestRunner::setCustomUserAgent(JSStringRef userAgent) 442 464 { 443 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetCustomUserAgent")); 444 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), toWK(userAgent).get(), nullptr); 465 postSynchronousMessage("SetCustomUserAgent", toWK(userAgent)); 445 466 } 446 467 447 468 void TestRunner::setWebAPIStatisticsEnabled(bool enabled) 448 469 { 449 WKRetainPtr<WKStringRef> key = adoptWK(WKStringCreateWithUTF8CString("WebKitWebAPIStatisticsEnabled")); 450 auto& injectedBundle = InjectedBundle::singleton(); 451 WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled); 470 WTR::overridePreference("WebKitWebAPIStatisticsEnabled", enabled); 452 471 } 453 472 454 473 void TestRunner::setModernMediaControlsEnabled(bool enabled) 455 474 { 456 WKRetainPtr<WKStringRef> key = adoptWK(WKStringCreateWithUTF8CString("WebKitModernMediaControlsEnabled")); 457 auto& injectedBundle = InjectedBundle::singleton(); 458 WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled); 475 WTR::overridePreference("WebKitModernMediaControlsEnabled", enabled); 459 476 } 460 477 461 478 void TestRunner::setWebGL2Enabled(bool enabled) 462 479 { 463 WKRetainPtr<WKStringRef> key = adoptWK(WKStringCreateWithUTF8CString("WebKitWebGL2Enabled")); 464 auto& injectedBundle = InjectedBundle::singleton(); 465 WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled); 480 WTR::overridePreference("WebKitWebGL2Enabled", enabled); 466 481 } 467 482 468 483 void TestRunner::setWritableStreamAPIEnabled(bool enabled) 469 484 { 470 WKRetainPtr<WKStringRef> key = adoptWK(WKStringCreateWithUTF8CString("WebKitWritableStreamAPIEnabled")); 471 auto& injectedBundle = InjectedBundle::singleton(); 472 WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled); 485 WTR::overridePreference("WebKitWritableStreamAPIEnabled", enabled); 473 486 } 474 487 475 488 void TestRunner::setTransformStreamAPIEnabled(bool enabled) 476 489 { 477 WKRetainPtr<WKStringRef> key = adoptWK(WKStringCreateWithUTF8CString("WebKitTransformStreamAPIEnabled")); 478 auto& injectedBundle = InjectedBundle::singleton(); 479 WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled); 490 WTR::overridePreference("WebKitTransformStreamAPIEnabled", enabled); 480 491 } 481 492 482 493 void TestRunner::setReadableByteStreamAPIEnabled(bool enabled) 483 494 { 484 WKRetainPtr<WKStringRef> key = adoptWK(WKStringCreateWithUTF8CString("WebKitReadableByteStreamAPIEnabled")); 485 auto& injectedBundle = InjectedBundle::singleton(); 486 WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled); 495 WTR::overridePreference("WebKitReadableByteStreamAPIEnabled", enabled); 487 496 } 488 497 489 498 void TestRunner::setEncryptedMediaAPIEnabled(bool enabled) 490 499 { 491 WKRetainPtr<WKStringRef> key = adoptWK(WKStringCreateWithUTF8CString("WebKitEncryptedMediaAPIEnabled")); 492 auto& injectedBundle = InjectedBundle::singleton(); 493 WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled); 500 WTR::overridePreference("WebKitEncryptedMediaAPIEnabled", enabled); 494 501 } 495 502 496 503 void TestRunner::setPictureInPictureAPIEnabled(bool enabled) 497 504 { 498 WKRetainPtr<WKStringRef> key = adoptWK(WKStringCreateWithUTF8CString("WebKitPictureInPictureAPIEnabled")); 499 auto& injectedBundle = InjectedBundle::singleton(); 500 WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled); 505 WTR::overridePreference("WebKitPictureInPictureAPIEnabled", enabled); 501 506 } 502 507 503 508 void TestRunner::setGenericCueAPIEnabled(bool enabled) 504 509 { 505 WKRetainPtr<WKStringRef> key = adoptWK(WKStringCreateWithUTF8CString("WebKitGenericCueAPIEnabled")); 506 auto& injectedBundle = InjectedBundle::singleton(); 507 WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled); 510 WTR::overridePreference("WebKitGenericCueAPIEnabled", enabled); 508 511 } 509 512 510 513 void TestRunner::setAllowsAnySSLCertificate(bool enabled) 511 514 { 512 auto& injectedBundle = InjectedBundle::singleton(); 513 injectedBundle.setAllowsAnySSLCertificate(enabled); 514 515 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetAllowsAnySSLCertificate")); 516 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(enabled)); 517 WKBundlePagePostSynchronousMessageForTesting(injectedBundle.page()->page(), messageName.get(), messageBody.get(), nullptr); 515 InjectedBundle::singleton().setAllowsAnySSLCertificate(enabled); 516 postSynchronousPageMessage("SetAllowsAnySSLCertificate", enabled); 518 517 } 519 518 520 519 void TestRunner::setShouldSwapToEphemeralSessionOnNextNavigation(bool shouldSwap) 521 520 { 522 auto& injectedBundle = InjectedBundle::singleton(); 523 524 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetShouldSwapToEphemeralSessionOnNextNavigation")); 525 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(shouldSwap)); 526 WKBundlePagePostSynchronousMessageForTesting(injectedBundle.page()->page(), messageName.get(), messageBody.get(), nullptr); 521 postSynchronousPageMessage("SetShouldSwapToEphemeralSessionOnNextNavigation", shouldSwap); 527 522 } 528 523 529 524 void TestRunner::setShouldSwapToDefaultSessionOnNextNavigation(bool shouldSwap) 530 525 { 531 auto& injectedBundle = InjectedBundle::singleton(); 532 533 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetShouldSwapToDefaultSessionOnNextNavigation")); 534 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(shouldSwap)); 535 WKBundlePagePostSynchronousMessageForTesting(injectedBundle.page()->page(), messageName.get(), messageBody.get(), nullptr); 526 postSynchronousPageMessage("SetShouldSwapToDefaultSessionOnNextNavigation", shouldSwap); 536 527 } 537 528 … … 556 547 void TestRunner::setPluginsEnabled(bool enabled) 557 548 { 558 WKRetainPtr<WKStringRef> key = adoptWK(WKStringCreateWithUTF8CString("WebKitPluginsEnabled")); 559 auto& injectedBundle = InjectedBundle::singleton(); 560 WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled); 549 WTR::overridePreference("WebKitPluginsEnabled", enabled); 561 550 } 562 551 … … 592 581 { 593 582 auto& injectedBundle = InjectedBundle::singleton(); 594 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(injectedBundle.page()->page()); 595 return WKBundleIsPageBoxVisible(injectedBundle.bundle(), mainFrame, pageIndex); 583 return WKBundleIsPageBoxVisible(injectedBundle.bundle(), mainFrame(), pageIndex); 596 584 } 597 585 … … 601 589 return; 602 590 603 WKRetainPtr<WKBundleNodeHandleRef> nodeHandle = adoptWK(WKBundleNodeHandleCreate(context, const_cast<JSObjectRef>(element))); 604 WKBundleNodeHandleSetHTMLInputElementValueForUser(nodeHandle.get(), toWK(value).get()); 591 WKBundleNodeHandleSetHTMLInputElementValueForUser(adoptWK(WKBundleNodeHandleCreate(context, const_cast<JSObjectRef>(element))).get(), toWK(value).get()); 605 592 } 606 593 … … 609 596 auto& injectedBundle = InjectedBundle::singleton(); 610 597 // FIXME (123058): Use a JSC API to get buffer contents once such is exposed. 611 WKRetainPtr<WKDataRef> audioData = adoptWK(WKBundleCreateWKDataFromUInt8Array(injectedBundle.bundle(), context, data)); 612 injectedBundle.setAudioResult(audioData.get()); 598 injectedBundle.setAudioResult(adoptWK(WKBundleCreateWKDataFromUInt8Array(injectedBundle.bundle(), context, data)).get()); 613 599 setWhatToDump(WhatToDump::Audio); 614 600 setDumpPixels(false); … … 622 608 void TestRunner::clearBackForwardList() 623 609 { 624 WKBundleClearHistoryForTesting(InjectedBundle::singleton().page()->page()); 625 } 626 627 // Object Creation 628 629 void TestRunner::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception) 630 { 631 setProperty(context, windowObject, "testRunner", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception); 610 WKBundleClearHistoryForTesting(page()); 611 } 612 613 void TestRunner::makeWindowObject(JSContextRef context) 614 { 615 setGlobalObjectProperty(context, "testRunner", this); 632 616 } 633 617 634 618 void TestRunner::showWebInspector() 635 619 { 636 WKBundleInspectorShow(WKBundlePageGetInspector( InjectedBundle::singleton().page()->page()));620 WKBundleInspectorShow(WKBundlePageGetInspector(page())); 637 621 } 638 622 639 623 void TestRunner::closeWebInspector() 640 624 { 641 WKBundleInspectorClose(WKBundlePageGetInspector( InjectedBundle::singleton().page()->page()));625 WKBundleInspectorClose(WKBundlePageGetInspector(page())); 642 626 } 643 627 644 628 void TestRunner::evaluateInWebInspector(JSStringRef script) 645 629 { 646 WKRetainPtr<WKStringRef> scriptWK = toWK(script); 647 WKBundleInspectorEvaluateScriptForTest(WKBundlePageGetInspector(InjectedBundle::singleton().page()->page()), scriptWK.get()); 648 } 649 650 typedef WTF::HashMap<unsigned, WKRetainPtr<WKBundleScriptWorldRef> > WorldMap; 630 WKBundleInspectorEvaluateScriptForTest(WKBundlePageGetInspector(page()), toWK(script).get()); 631 } 632 633 using WorldMap = WTF::HashMap<unsigned, WKRetainPtr<WKBundleScriptWorldRef>>; 651 634 static WorldMap& worldMap() 652 635 { … … 657 640 unsigned TestRunner::worldIDForWorld(WKBundleScriptWorldRef world) 658 641 { 659 WorldMap::const_iterator end = worldMap().end();660 for ( WorldMap::const_iterator it = worldMap().begin(); it != end; ++it) {661 if ( it->value == world)662 return it->key;642 // FIXME: This is the anti-pattern of iterating an entire map. Typically we use a pair of maps or just a vector in a case like this. 643 for (auto& mapEntry : worldMap()) { 644 if (mapEntry.value == world) 645 return mapEntry.key; 663 646 } 664 665 647 return 0; 666 648 } … … 682 664 WKBundleFrameRef frame = WKBundleFrameForJavaScriptContext(context); 683 665 if (!frame) 684 frame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());666 frame = mainFrame(); 685 667 686 668 JSGlobalContextRef jsContext = WKBundleFrameGetJavaScriptContextForWorld(frame, world.get()); … … 697 679 void TestRunner::setTextDirection(JSStringRef direction) 698 680 { 699 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page()); 700 return WKBundleFrameSetTextDirection(mainFrame, toWK(direction).get()); 681 return WKBundleFrameSetTextDirection(mainFrame(), toWK(direction).get()); 701 682 } 702 683 … … 708 689 bool TestRunner::didReceiveServerRedirectForProvisionalNavigation() const 709 690 { 710 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("DidReceiveServerRedirectForProvisionalNavigation")); 711 WKTypeRef returnData = nullptr; 712 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, &returnData); 713 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 714 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 691 return postSynchronousPageMessageReturningBoolean("DidReceiveServerRedirectForProvisionalNavigation"); 715 692 } 716 693 717 694 void TestRunner::clearDidReceiveServerRedirectForProvisionalNavigation() 718 695 { 719 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ClearDidReceiveServerRedirectForProvisionalNavigation")); 720 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, nullptr); 696 postSynchronousPageMessage("ClearDidReceiveServerRedirectForProvisionalNavigation"); 721 697 } 722 698 … … 731 707 } 732 708 733 typedef WTF::HashMap<unsigned, JSValueRef> CallbackMap;709 using CallbackMap = WTF::HashMap<unsigned, JSObjectRef>; 734 710 static CallbackMap& callbackMap() 735 711 { … … 784 760 if (!callback) 785 761 return; 786 762 auto context = mainFrameJSContext(); 763 if (!JSValueIsObject(context, callback)) 764 return; 787 765 if (callbackMap().contains(index)) { 788 766 InjectedBundle::singleton().outputText(makeString("FAIL: Tried to install a second TestRunner callback for the same event (id ", index, ")\n\n")); 789 767 return; 790 768 } 791 792 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());793 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);794 769 JSValueProtect(context, callback); 795 callbackMap().add(index, c allback);770 callbackMap().add(index, const_cast<JSObjectRef>(callback)); 796 771 } 797 772 798 773 static void callTestRunnerCallback(unsigned index, size_t argumentCount = 0, const JSValueRef arguments[] = nullptr) 799 774 { 800 if (!callbackMap().contains(index)) 775 auto callback = callbackMap().take(index); 776 if (!callback) 801 777 return; 802 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page()); 803 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); 804 JSObjectRef callback = JSValueToObject(context, callbackMap().take(index), 0); 778 auto context = mainFrameJSContext(); 805 779 JSObjectCallAsFunction(context, callback, JSContextGetGlobalObject(context), argumentCount, arguments, 0); 806 780 JSValueUnprotect(context, callback); … … 809 783 void TestRunner::clearTestRunnerCallbacks() 810 784 { 811 for (auto& iter : callbackMap()) { 812 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page()); 813 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); 814 JSObjectRef callback = JSValueToObject(context, iter.value, 0); 815 JSValueUnprotect(context, callback); 816 } 817 785 auto context = mainFrameJSContext(); 786 for (auto& value : callbackMap().values()) 787 JSValueUnprotect(context, JSValueToObject(context, value, nullptr)); 818 788 callbackMap().clear(); 819 789 } … … 895 865 void TestRunner::setAlwaysAcceptCookies(bool accept) 896 866 { 897 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetAlwaysAcceptCookies")); 898 899 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(accept)); 900 901 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 867 postSynchronousMessage("SetAlwaysAcceptCookies", accept); 902 868 } 903 869 904 870 void TestRunner::setOnlyAcceptFirstPartyCookies(bool accept) 905 871 { 906 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetOnlyAcceptFirstPartyCookies")); 907 908 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(accept)); 909 910 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 872 postSynchronousMessage("SetOnlyAcceptFirstPartyCookies", accept); 911 873 } 912 874 … … 925 887 m_userStyleSheetEnabled = enabled; 926 888 927 WKRetainPtr<WKStringRef> emptyUrl = adoptWK(WKStringCreateWithUTF8CString(""));928 WKStringRef location = enabled ? m_userStyleSheetLocation.get() : emptyUrl.get();889 auto emptyString = toWK(""); 890 auto location = enabled ? m_userStyleSheetLocation.get() : emptyString.get(); 929 891 auto& injectedBundle = InjectedBundle::singleton(); 930 892 WKBundleSetUserStyleSheetLocation(injectedBundle.bundle(), injectedBundle.pageGroup(), location); … … 933 895 void TestRunner::setUserStyleSheetLocation(JSStringRef location) 934 896 { 935 m_userStyleSheetLocation = adoptWK(WKStringCreateWithJSString(location));897 m_userStyleSheetLocation = toWK(location); 936 898 937 899 if (m_userStyleSheetEnabled) … … 947 909 void TestRunner::setTabKeyCyclesThroughElements(bool enabled) 948 910 { 949 auto& injectedBundle = InjectedBundle::singleton(); 950 WKBundleSetTabKeyCyclesThroughElements(injectedBundle.bundle(), injectedBundle.page()->page(), enabled); 911 WKBundleSetTabKeyCyclesThroughElements(InjectedBundle::singleton().bundle(), page(), enabled); 951 912 } 952 913 … … 974 935 void TestRunner::grantWebNotificationPermission(JSStringRef origin) 975 936 { 976 WKRetainPtr<WKStringRef> originWK = toWK(origin); 937 WKBundleSetWebNotificationPermission(InjectedBundle::singleton().bundle(), page(), toWK(origin).get(), true); 938 } 939 940 void TestRunner::denyWebNotificationPermission(JSStringRef origin) 941 { 942 WKBundleSetWebNotificationPermission(InjectedBundle::singleton().bundle(), page(), toWK(origin).get(), false); 943 } 944 945 void TestRunner::removeAllWebNotificationPermissions() 946 { 947 WKBundleRemoveAllWebNotificationPermissions(InjectedBundle::singleton().bundle(), page()); 948 } 949 950 void TestRunner::simulateWebNotificationClick(JSValueRef notification) 951 { 977 952 auto& injectedBundle = InjectedBundle::singleton(); 978 WKBundleSetWebNotificationPermission(injectedBundle.bundle(), injectedBundle.page()->page(), originWK.get(), true); 979 } 980 981 void TestRunner::denyWebNotificationPermission(JSStringRef origin) 982 { 983 WKRetainPtr<WKStringRef> originWK = toWK(origin); 953 injectedBundle.postSimulateWebNotificationClick(WKBundleGetWebNotificationID(injectedBundle.bundle(), mainFrameJSContext(), notification)); 954 } 955 956 void TestRunner::setGeolocationPermission(bool enabled) 957 { 958 // FIXME: This should be done by frame. 959 InjectedBundle::singleton().setGeolocationPermission(enabled); 960 } 961 962 bool TestRunner::isGeolocationProviderActive() 963 { 964 return InjectedBundle::singleton().isGeolocationProviderActive(); 965 } 966 967 void TestRunner::setMockGeolocationPosition(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitudeAccuracy, Optional<double> heading, Optional<double> speed, Optional<double> floorLevel) 968 { 969 InjectedBundle::singleton().setMockGeolocationPosition(latitude, longitude, accuracy, altitude, altitudeAccuracy, heading, speed, floorLevel); 970 } 971 972 void TestRunner::setMockGeolocationPositionUnavailableError(JSStringRef message) 973 { 974 InjectedBundle::singleton().setMockGeolocationPositionUnavailableError(toWK(message).get()); 975 } 976 977 void TestRunner::setUserMediaPermission(bool enabled) 978 { 979 // FIXME: This should be done by frame. 980 InjectedBundle::singleton().setUserMediaPermission(enabled); 981 } 982 983 void TestRunner::resetUserMediaPermission() 984 { 985 // FIXME: This should be done by frame. 986 InjectedBundle::singleton().resetUserMediaPermission(); 987 } 988 989 bool TestRunner::isDoingMediaCapture() const 990 { 991 return postSynchronousPageMessageReturningBoolean("IsDoingMediaCapture"); 992 } 993 994 void TestRunner::setUserMediaPersistentPermissionForOrigin(bool permission, JSStringRef origin, JSStringRef parentOrigin) 995 { 996 InjectedBundle::singleton().setUserMediaPersistentPermissionForOrigin(permission, toWK(origin).get(), toWK(parentOrigin).get()); 997 } 998 999 unsigned TestRunner::userMediaPermissionRequestCountForOrigin(JSStringRef origin, JSStringRef parentOrigin) const 1000 { 1001 return InjectedBundle::singleton().userMediaPermissionRequestCountForOrigin(toWK(origin).get(), toWK(parentOrigin).get()); 1002 } 1003 1004 void TestRunner::resetUserMediaPermissionRequestCountForOrigin(JSStringRef origin, JSStringRef parentOrigin) 1005 { 1006 InjectedBundle::singleton().resetUserMediaPermissionRequestCountForOrigin(toWK(origin).get(), toWK(parentOrigin).get()); 1007 } 1008 1009 bool TestRunner::callShouldCloseOnWebView() 1010 { 1011 return WKBundleFrameCallShouldCloseOnWebView(mainFrame()); 1012 } 1013 1014 void TestRunner::queueBackNavigation(unsigned howFarBackward) 1015 { 1016 InjectedBundle::singleton().queueBackNavigation(howFarBackward); 1017 } 1018 1019 void TestRunner::queueForwardNavigation(unsigned howFarForward) 1020 { 1021 InjectedBundle::singleton().queueForwardNavigation(howFarForward); 1022 } 1023 1024 void TestRunner::queueLoad(JSStringRef url, JSStringRef target, bool shouldOpenExternalURLs) 1025 { 984 1026 auto& injectedBundle = InjectedBundle::singleton(); 985 WKBundleSetWebNotificationPermission(injectedBundle.bundle(), injectedBundle.page()->page(), originWK.get(), false); 986 } 987 988 void TestRunner::removeAllWebNotificationPermissions() 989 { 990 auto& injectedBundle = InjectedBundle::singleton(); 991 WKBundleRemoveAllWebNotificationPermissions(injectedBundle.bundle(), injectedBundle.page()->page()); 992 } 993 994 void TestRunner::simulateWebNotificationClick(JSValueRef notification) 995 { 996 auto& injectedBundle = InjectedBundle::singleton(); 997 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(injectedBundle.page()->page()); 998 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); 999 uint64_t notificationID = WKBundleGetWebNotificationID(injectedBundle.bundle(), context, notification); 1000 injectedBundle.postSimulateWebNotificationClick(notificationID); 1001 } 1002 1003 void TestRunner::setGeolocationPermission(bool enabled) 1004 { 1005 // FIXME: this should be done by frame. 1006 InjectedBundle::singleton().setGeolocationPermission(enabled); 1007 } 1008 1009 bool TestRunner::isGeolocationProviderActive() 1010 { 1011 return InjectedBundle::singleton().isGeolocationProviderActive(); 1012 } 1013 1014 void TestRunner::setMockGeolocationPosition(double latitude, double longitude, double accuracy, JSValueRef jsAltitude, JSValueRef jsAltitudeAccuracy, JSValueRef jsHeading, JSValueRef jsSpeed, JSValueRef jsFloorLevel) 1015 { 1016 auto& injectedBundle = InjectedBundle::singleton(); 1017 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(injectedBundle.page()->page()); 1018 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); 1019 1020 bool providesAltitude = false; 1021 double altitude = 0.; 1022 if (!JSValueIsUndefined(context, jsAltitude)) { 1023 providesAltitude = true; 1024 altitude = JSValueToNumber(context, jsAltitude, 0); 1025 } 1026 1027 bool providesAltitudeAccuracy = false; 1028 double altitudeAccuracy = 0.; 1029 if (!JSValueIsUndefined(context, jsAltitudeAccuracy)) { 1030 providesAltitudeAccuracy = true; 1031 altitudeAccuracy = JSValueToNumber(context, jsAltitudeAccuracy, 0); 1032 } 1033 1034 bool providesHeading = false; 1035 double heading = 0.; 1036 if (!JSValueIsUndefined(context, jsHeading)) { 1037 providesHeading = true; 1038 heading = JSValueToNumber(context, jsHeading, 0); 1039 } 1040 1041 bool providesSpeed = false; 1042 double speed = 0.; 1043 if (!JSValueIsUndefined(context, jsSpeed)) { 1044 providesSpeed = true; 1045 speed = JSValueToNumber(context, jsSpeed, 0); 1046 } 1047 1048 bool providesFloorLevel = false; 1049 double floorLevel = 0.; 1050 if (!JSValueIsUndefined(context, jsFloorLevel)) { 1051 providesFloorLevel = true; 1052 floorLevel = JSValueToNumber(context, jsFloorLevel, 0); 1053 } 1054 1055 injectedBundle.setMockGeolocationPosition(latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed, providesFloorLevel, floorLevel); 1056 } 1057 1058 void TestRunner::setMockGeolocationPositionUnavailableError(JSStringRef message) 1059 { 1060 WKRetainPtr<WKStringRef> messageWK = toWK(message); 1061 InjectedBundle::singleton().setMockGeolocationPositionUnavailableError(messageWK.get()); 1062 } 1063 1064 void TestRunner::setUserMediaPermission(bool enabled) 1065 { 1066 // FIXME: this should be done by frame. 1067 InjectedBundle::singleton().setUserMediaPermission(enabled); 1068 } 1069 1070 void TestRunner::resetUserMediaPermission() 1071 { 1072 // FIXME: this should be done by frame. 1073 InjectedBundle::singleton().resetUserMediaPermission(); 1074 } 1075 1076 bool TestRunner::isDoingMediaCapture() const 1077 { 1078 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("IsDoingMediaCapture")); 1079 WKTypeRef returnData = nullptr; 1080 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, &returnData); 1081 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 1082 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 1083 } 1084 1085 void TestRunner::setUserMediaPersistentPermissionForOrigin(bool permission, JSStringRef origin, JSStringRef parentOrigin) 1086 { 1087 WKRetainPtr<WKStringRef> originWK = toWK(origin); 1088 WKRetainPtr<WKStringRef> parentOriginWK = toWK(parentOrigin); 1089 InjectedBundle::singleton().setUserMediaPersistentPermissionForOrigin(permission, originWK.get(), parentOriginWK.get()); 1090 } 1091 1092 unsigned TestRunner::userMediaPermissionRequestCountForOrigin(JSStringRef origin, JSStringRef parentOrigin) const 1093 { 1094 WKRetainPtr<WKStringRef> originWK = toWK(origin); 1095 WKRetainPtr<WKStringRef> parentOriginWK = toWK(parentOrigin); 1096 return InjectedBundle::singleton().userMediaPermissionRequestCountForOrigin(originWK.get(), parentOriginWK.get()); 1097 } 1098 1099 void TestRunner::resetUserMediaPermissionRequestCountForOrigin(JSStringRef origin, JSStringRef parentOrigin) 1100 { 1101 WKRetainPtr<WKStringRef> originWK = toWK(origin); 1102 WKRetainPtr<WKStringRef> parentOriginWK = toWK(parentOrigin); 1103 InjectedBundle::singleton().resetUserMediaPermissionRequestCountForOrigin(originWK.get(), parentOriginWK.get()); 1104 } 1105 1106 bool TestRunner::callShouldCloseOnWebView() 1107 { 1108 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page()); 1109 return WKBundleFrameCallShouldCloseOnWebView(mainFrame); 1110 } 1111 1112 void TestRunner::queueBackNavigation(unsigned howFarBackward) 1113 { 1114 InjectedBundle::singleton().queueBackNavigation(howFarBackward); 1115 } 1116 1117 void TestRunner::queueForwardNavigation(unsigned howFarForward) 1118 { 1119 InjectedBundle::singleton().queueForwardNavigation(howFarForward); 1120 } 1121 1122 void TestRunner::queueLoad(JSStringRef url, JSStringRef target, bool shouldOpenExternalURLs) 1123 { 1124 auto& injectedBundle = InjectedBundle::singleton(); 1125 WKRetainPtr<WKURLRef> baseURLWK = adoptWK(WKBundleFrameCopyURL(WKBundlePageGetMainFrame(injectedBundle.page()->page()))); 1126 WKRetainPtr<WKURLRef> urlWK = adoptWK(WKURLCreateWithBaseURL(baseURLWK.get(), toWTFString(toWK(url)).utf8().data())); 1127 WKRetainPtr<WKStringRef> urlStringWK = adoptWK(WKURLCopyString(urlWK.get())); 1128 1027 auto baseURLWK = adoptWK(WKBundleFrameCopyURL(mainFrame())); 1028 auto urlWK = adoptWK(WKURLCreateWithBaseURL(baseURLWK.get(), toWTFString(url).utf8().data())); 1029 auto urlStringWK = adoptWK(WKURLCopyString(urlWK.get())); 1129 1030 injectedBundle.queueLoad(urlStringWK.get(), toWK(target).get(), shouldOpenExternalURLs); 1130 1031 } … … 1132 1033 void TestRunner::queueLoadHTMLString(JSStringRef content, JSStringRef baseURL, JSStringRef unreachableURL) 1133 1034 { 1134 WKRetainPtr<WKStringRef> contentWK = toWK(content); 1135 WKRetainPtr<WKStringRef> baseURLWK = baseURL ? toWK(baseURL) : WKRetainPtr<WKStringRef>(); 1136 WKRetainPtr<WKStringRef> unreachableURLWK = unreachableURL ? toWK(unreachableURL) : WKRetainPtr<WKStringRef>(); 1137 1138 InjectedBundle::singleton().queueLoadHTMLString(contentWK.get(), baseURLWK.get(), unreachableURLWK.get()); 1035 auto baseURLWK = baseURL ? toWK(baseURL) : WKRetainPtr<WKStringRef>(); 1036 auto unreachableURLWK = unreachableURL ? toWK(unreachableURL) : WKRetainPtr<WKStringRef>(); 1037 InjectedBundle::singleton().queueLoadHTMLString(toWK(content).get(), baseURLWK.get(), unreachableURLWK.get()); 1139 1038 } 1140 1039 … … 1146 1045 void TestRunner::queueLoadingScript(JSStringRef script) 1147 1046 { 1148 WKRetainPtr<WKStringRef> scriptWK = toWK(script); 1149 InjectedBundle::singleton().queueLoadingScript(scriptWK.get()); 1047 InjectedBundle::singleton().queueLoadingScript(toWK(script).get()); 1150 1048 } 1151 1049 1152 1050 void TestRunner::queueNonLoadingScript(JSStringRef script) 1153 1051 { 1154 WKRetainPtr<WKStringRef> scriptWK = toWK(script); 1155 InjectedBundle::singleton().queueNonLoadingScript(scriptWK.get()); 1052 InjectedBundle::singleton().queueNonLoadingScript(toWK(script).get()); 1156 1053 } 1157 1054 1158 1055 void TestRunner::setRejectsProtectionSpaceAndContinueForAuthenticationChallenges(bool value) 1159 1056 { 1160 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetRejectsProtectionSpaceAndContinueForAuthenticationChallenges")); 1161 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 1162 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get()); 1057 postPageMessage("SetRejectsProtectionSpaceAndContinueForAuthenticationChallenges", value); 1163 1058 } 1164 1059 1165 1060 void TestRunner::setHandlesAuthenticationChallenges(bool handlesAuthenticationChallenges) 1166 1061 { 1167 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetHandlesAuthenticationChallenges")); 1168 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(handlesAuthenticationChallenges)); 1169 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get()); 1062 postPageMessage("SetHandlesAuthenticationChallenges", handlesAuthenticationChallenges); 1170 1063 } 1171 1064 1172 1065 void TestRunner::setShouldLogCanAuthenticateAgainstProtectionSpace(bool value) 1173 1066 { 1174 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetShouldLogCanAuthenticateAgainstProtectionSpace")); 1175 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 1176 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get()); 1067 postPageMessage("SetShouldLogCanAuthenticateAgainstProtectionSpace", value); 1177 1068 } 1178 1069 1179 1070 void TestRunner::setShouldLogDownloadCallbacks(bool value) 1180 1071 { 1181 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetShouldLogDownloadCallbacks")); 1182 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 1183 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get()); 1072 postPageMessage("SetShouldLogDownloadCallbacks", value); 1184 1073 } 1185 1074 1186 1075 void TestRunner::setAuthenticationUsername(JSStringRef username) 1187 1076 { 1188 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetAuthenticationUsername")); 1189 WKRetainPtr<WKStringRef> messageBody = adoptWK(WKStringCreateWithJSString(username)); 1190 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get()); 1077 postPageMessage("SetAuthenticationUsername", toWK(username)); 1191 1078 } 1192 1079 1193 1080 void TestRunner::setAuthenticationPassword(JSStringRef password) 1194 1081 { 1195 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetAuthenticationPassword")); 1196 WKRetainPtr<WKStringRef> messageBody = adoptWK(WKStringCreateWithJSString(password)); 1197 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get()); 1082 postPageMessage("SetAuthenticationPassword", toWK(password)); 1198 1083 } 1199 1084 1200 1085 bool TestRunner::secureEventInputIsEnabled() const 1201 1086 { 1202 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SecureEventInputIsEnabled")); 1203 WKTypeRef returnData = nullptr; 1204 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, &returnData); 1205 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 1206 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 1087 return postSynchronousPageMessageReturningBoolean("SecureEventInputIsEnabled"); 1207 1088 } 1208 1089 1209 1090 void TestRunner::setBlockAllPlugins(bool shouldBlock) 1210 1091 { 1211 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetBlockAllPlugins")); 1212 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(shouldBlock)); 1213 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get()); 1092 postPageMessage("SetBlockAllPlugins", shouldBlock); 1214 1093 } 1215 1094 1216 1095 void TestRunner::setPluginSupportedMode(JSStringRef mode) 1217 1096 { 1218 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetPluginSupportedMode")); 1219 WKRetainPtr<WKStringRef> messageBody = adoptWK(WKStringCreateWithJSString(mode)); 1220 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get()); 1097 postPageMessage("SetPluginSupportedMode", toWK(mode)); 1221 1098 } 1222 1099 1223 1100 JSValueRef TestRunner::failNextNewCodeBlock() 1224 1101 { 1225 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page()); 1226 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); 1227 return JSC::failNextNewCodeBlock(context); 1228 } 1229 1230 JSValueRef TestRunner::numberOfDFGCompiles(JSValueRef theFunction) 1231 { 1232 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page()); 1233 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); 1234 return JSC::numberOfDFGCompiles(context, theFunction); 1235 } 1236 1237 JSValueRef TestRunner::neverInlineFunction(JSValueRef theFunction) 1238 { 1239 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page()); 1240 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); 1241 return JSC::setNeverInline(context, theFunction); 1102 return JSC::failNextNewCodeBlock(mainFrameJSContext()); 1103 } 1104 1105 JSValueRef TestRunner::numberOfDFGCompiles(JSValueRef function) 1106 { 1107 return JSC::numberOfDFGCompiles(mainFrameJSContext(), function); 1108 } 1109 1110 JSValueRef TestRunner::neverInlineFunction(JSValueRef function) 1111 { 1112 return JSC::setNeverInline(mainFrameJSContext(), function); 1242 1113 } 1243 1114 … … 1245 1116 { 1246 1117 m_shouldDecideNavigationPolicyAfterDelay = value; 1247 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetShouldDecideNavigationPolicyAfterDelay")); 1248 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 1249 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get()); 1118 postPageMessage("SetShouldDecideNavigationPolicyAfterDelay", value); 1250 1119 } 1251 1120 … … 1253 1122 { 1254 1123 m_shouldDecideResponsePolicyAfterDelay = value; 1255 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetShouldDecideResponsePolicyAfterDelay")); 1256 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 1257 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get()); 1124 postPageMessage("SetShouldDecideResponsePolicyAfterDelay", value); 1258 1125 } 1259 1126 1260 1127 void TestRunner::setNavigationGesturesEnabled(bool value) 1261 1128 { 1262 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetNavigationGesturesEnabled")); 1263 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 1264 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get()); 1129 postPageMessage("SetNavigationGesturesEnabled", value); 1265 1130 } 1266 1131 1267 1132 void TestRunner::setIgnoresViewportScaleLimits(bool value) 1268 1133 { 1269 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetIgnoresViewportScaleLimits")); 1270 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 1271 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get()); 1134 postPageMessage("SetIgnoresViewportScaleLimits", value); 1272 1135 } 1273 1136 1274 1137 void TestRunner::setShouldDownloadUndisplayableMIMETypes(bool value) 1275 1138 { 1276 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetShouldDownloadUndisplayableMIMETypes")); 1277 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 1278 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get()); 1139 postPageMessage("SetShouldDownloadUndisplayableMIMETypes", value); 1279 1140 } 1280 1141 1281 1142 void TestRunner::setShouldAllowDeviceOrientationAndMotionAccess(bool value) 1282 1143 { 1283 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetShouldAllowDeviceOrientationAndMotionAccess")); 1284 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 1285 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get()); 1144 postPageMessage("SetShouldAllowDeviceOrientationAndMotionAccess", value); 1286 1145 } 1287 1146 1288 1147 void TestRunner::terminateNetworkProcess() 1289 1148 { 1290 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("TerminateNetworkProcess")); 1291 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, nullptr); 1149 postSynchronousPageMessage("TerminateNetworkProcess"); 1292 1150 } 1293 1151 1294 1152 void TestRunner::terminateServiceWorkers() 1295 1153 { 1296 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("TerminateServiceWorkers")); 1297 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, nullptr); 1154 postSynchronousPageMessage("TerminateServiceWorkers"); 1298 1155 } 1299 1156 1300 1157 void TestRunner::setUseSeparateServiceWorkerProcess(bool value) 1301 1158 { 1302 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetUseSeparateServiceWorkerProcess")); 1303 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 1304 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), nullptr); 1159 postSynchronousPageMessage("SetUseSeparateServiceWorkerProcess", value); 1305 1160 } 1306 1161 … … 1315 1170 unsigned callbackID = nextUIScriptCallbackID(); 1316 1171 cacheTestRunnerCallback(callbackID, callback); 1317 1318 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("RunUIProcessScript")); 1319 1320 WKRetainPtr<WKMutableDictionaryRef> testDictionary = adoptWK(WKMutableDictionaryCreate()); 1321 1322 WKRetainPtr<WKStringRef> scriptKey = adoptWK(WKStringCreateWithUTF8CString("Script")); 1323 WKRetainPtr<WKStringRef> scriptValue = adoptWK(WKStringCreateWithJSString(script)); 1324 1325 WKRetainPtr<WKStringRef> callbackIDKey = adoptWK(WKStringCreateWithUTF8CString("CallbackID")); 1326 WKRetainPtr<WKUInt64Ref> callbackIDValue = adoptWK(WKUInt64Create(callbackID)); 1327 1328 WKDictionarySetItem(testDictionary.get(), scriptKey.get(), scriptValue.get()); 1329 WKDictionarySetItem(testDictionary.get(), callbackIDKey.get(), callbackIDValue.get()); 1330 1331 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), testDictionary.get()); 1172 postPageMessage("RunUIProcessScript", createWKDictionary({ 1173 { "Script", toWK(script) }, 1174 { "CallbackID", adoptWK(WKUInt64Create(callbackID)).get() }, 1175 })); 1332 1176 } 1333 1177 … … 1336 1180 unsigned callbackID = nextUIScriptCallbackID(); 1337 1181 cacheTestRunnerCallback(callbackID, callback); 1338 1339 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("RunUIProcessScriptImmediately")); 1340 1341 WKRetainPtr<WKMutableDictionaryRef> testDictionary = adoptWK(WKMutableDictionaryCreate()); 1342 1343 WKRetainPtr<WKStringRef> scriptKey = adoptWK(WKStringCreateWithUTF8CString("Script")); 1344 WKRetainPtr<WKStringRef> scriptValue = adoptWK(WKStringCreateWithJSString(script)); 1345 1346 WKRetainPtr<WKStringRef> callbackIDKey = adoptWK(WKStringCreateWithUTF8CString("CallbackID")); 1347 WKRetainPtr<WKUInt64Ref> callbackIDValue = adoptWK(WKUInt64Create(callbackID)); 1348 1349 WKDictionarySetItem(testDictionary.get(), scriptKey.get(), scriptValue.get()); 1350 WKDictionarySetItem(testDictionary.get(), callbackIDKey.get(), callbackIDValue.get()); 1351 1352 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), testDictionary.get()); 1182 postPageMessage("RunUIProcessScriptImmediately", createWKDictionary({ 1183 { "Script", toWK(script) }, 1184 { "CallbackID", adoptWK(WKUInt64Create(callbackID)).get() }, 1185 })); 1353 1186 } 1354 1187 1355 1188 void TestRunner::runUIScriptCallback(unsigned callbackID, JSStringRef result) 1356 1189 { 1357 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page()); 1358 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); 1359 1360 JSValueRef resultValue = JSValueMakeString(context, result); 1190 JSValueRef resultValue = JSValueMakeString(mainFrameJSContext(), result); 1361 1191 callTestRunnerCallback(callbackID, 1, &resultValue); 1362 1192 } … … 1364 1194 void TestRunner::setAllowedMenuActions(JSValueRef actions) 1365 1195 { 1366 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetAllowedMenuActions")); 1367 WKRetainPtr<WKMutableArrayRef> messageBody = adoptWK(WKMutableArrayCreate()); 1368 1369 auto page = InjectedBundle::singleton().page()->page(); 1370 auto mainFrame = WKBundlePageGetMainFrame(page); 1371 auto context = WKBundleFrameGetJavaScriptContext(mainFrame); 1372 auto lengthPropertyName = adopt(JSStringCreateWithUTF8CString("length")); 1196 auto messageBody = adoptWK(WKMutableArrayCreate()); 1197 auto context = mainFrameJSContext(); 1373 1198 auto actionsArray = JSValueToObject(context, actions, nullptr); 1374 auto lengthValue = JSObjectGetProperty(context, actionsArray, lengthPropertyName.get(), nullptr); 1375 if (!JSValueIsNumber(context, lengthValue)) 1376 return; 1377 1378 auto length = static_cast<size_t>(JSValueToNumber(context, lengthValue, 0)); 1379 for (size_t i = 0; i < length; ++i) { 1380 auto value = JSObjectGetPropertyAtIndex(context, actionsArray, i, 0); 1381 if (!JSValueIsString(context, value)) 1382 continue; 1383 1384 auto actionName = adopt(JSValueToStringCopy(context, value, 0)); 1385 WKRetainPtr<WKStringRef> action = adoptWK(WKStringCreateWithJSString(actionName.get())); 1386 WKArrayAppendItem(messageBody.get(), action.get()); 1199 auto length = arrayLength(context, actionsArray); 1200 for (unsigned i = 0; i < length; ++i) { 1201 auto value = JSObjectGetPropertyAtIndex(context, actionsArray, i, nullptr); 1202 WKArrayAppendItem(messageBody.get(), toWKString(context, value).get()); 1387 1203 } 1388 1389 WKBundlePagePostMessage(page, messageName.get(), messageBody.get()); 1204 postPageMessage("SetAllowedMenuActions", messageBody); 1390 1205 } 1391 1206 … … 1393 1208 { 1394 1209 cacheTestRunnerCallback(CustomMenuActionCallbackID, callback); 1395 1396 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("InstallCustomMenuAction")); 1397 WKRetainPtr<WKMutableDictionaryRef> messageBody = adoptWK(WKMutableDictionaryCreate()); 1398 1399 WKRetainPtr<WKStringRef> nameKey = adoptWK(WKStringCreateWithUTF8CString("name")); 1400 WKRetainPtr<WKStringRef> nameValue = adoptWK(WKStringCreateWithJSString(name)); 1401 WKDictionarySetItem(messageBody.get(), nameKey.get(), nameValue.get()); 1402 1403 WKRetainPtr<WKStringRef> dismissesAutomaticallyKey = adoptWK(WKStringCreateWithUTF8CString("dismissesAutomatically")); 1404 WKRetainPtr<WKBooleanRef> dismissesAutomaticallyValue = adoptWK(WKBooleanCreate(dismissesAutomatically)); 1405 WKDictionarySetItem(messageBody.get(), dismissesAutomaticallyKey.get(), dismissesAutomaticallyValue.get()); 1406 1407 WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get()); 1210 postPageMessage("InstallCustomMenuAction", createWKDictionary({ 1211 { "name", toWK(name) }, 1212 { "dismissesAutomatically", adoptWK(WKBooleanCreate(dismissesAutomatically)).get() }, 1213 })); 1408 1214 } 1409 1215 … … 1450 1256 void TestRunner::clearStatisticsDataForDomain(JSStringRef domain) 1451 1257 { 1452 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ClearStatisticsDataForDomain")); 1453 WKRetainPtr<WKStringRef> messageBody = adoptWK(WKStringCreateWithJSString(domain)); 1454 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1258 postSynchronousMessage("ClearStatisticsDataForDomain", toWK(domain)); 1455 1259 } 1456 1260 1457 1261 bool TestRunner::doesStatisticsDomainIDExistInDatabase(unsigned domainID) 1458 1262 { 1459 Vector<WKRetainPtr<WKStringRef>> keys; 1460 Vector<WKRetainPtr<WKTypeRef>> values; 1461 1462 keys.append(adoptWK(WKStringCreateWithUTF8CString("DomainID"))); 1463 values.append(adoptWK(WKUInt64Create(domainID))); 1464 1465 Vector<WKStringRef> rawKeys(keys.size()); 1466 Vector<WKTypeRef> rawValues(values.size()); 1467 1468 for (size_t i = 0; i < keys.size(); ++i) { 1469 rawKeys[i] = keys[i].get(); 1470 rawValues[i] = values[i].get(); 1471 } 1472 1473 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("DoesStatisticsDomainIDExistInDatabase")); 1474 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 1475 WKTypeRef returnData = nullptr; 1476 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData); 1477 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 1478 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 1263 return postSynchronousPageMessageReturningBoolean("DoesStatisticsDomainIDExistInDatabase", createWKDictionary({ 1264 { "DomainID", adoptWK(WKUInt64Create(domainID)) } 1265 })); 1479 1266 } 1480 1267 1481 1268 void TestRunner::setStatisticsEnabled(bool value) 1482 1269 { 1483 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsEnabled")); 1484 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 1485 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1270 postSynchronousMessage("SetStatisticsEnabled", value); 1486 1271 } 1487 1272 1488 1273 bool TestRunner::isStatisticsEphemeral() 1489 1274 { 1490 auto messageName = adoptWK(WKStringCreateWithUTF8CString("IsStatisticsEphemeral")); 1491 WKTypeRef returnData = nullptr; 1492 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, &returnData); 1493 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 1494 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 1275 return postSynchronousPageMessageReturningBoolean("IsStatisticsEphemeral"); 1495 1276 } 1496 1277 … … 1498 1279 { 1499 1280 cacheTestRunnerCallback(SetStatisticsDebugModeCallbackID, completionHandler); 1500 1501 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsDebugMode")); 1502 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 1503 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 1281 postMessage("SetStatisticsDebugMode", value); 1504 1282 } 1505 1283 … … 1512 1290 { 1513 1291 cacheTestRunnerCallback(SetStatisticsPrevalentResourceForDebugModeCallbackID, completionHandler); 1514 1515 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsPrevalentResourceForDebugMode")); 1516 WKRetainPtr<WKStringRef> messageBody = adoptWK(WKStringCreateWithJSString(hostName)); 1517 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 1292 postMessage("SetStatisticsPrevalentResourceForDebugMode", hostName); 1518 1293 } 1519 1294 … … 1527 1302 cacheTestRunnerCallback(SetStatisticsLastSeenCallbackID, completionHandler); 1528 1303 1529 Vector<WKRetainPtr<WKStringRef>> keys; 1530 Vector<WKRetainPtr<WKTypeRef>> values; 1531 1532 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostName"))); 1533 values.append(adoptWK(WKStringCreateWithJSString(hostName))); 1534 1535 keys.append(adoptWK(WKStringCreateWithUTF8CString("Value"))); 1536 values.append(adoptWK(WKDoubleCreate(seconds))); 1537 1538 Vector<WKStringRef> rawKeys(keys.size()); 1539 Vector<WKTypeRef> rawValues(values.size()); 1540 1541 for (size_t i = 0; i < keys.size(); ++i) { 1542 rawKeys[i] = keys[i].get(); 1543 rawValues[i] = values[i].get(); 1544 } 1545 1546 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsLastSeen")); 1547 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 1548 1549 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 1304 postMessage("SetStatisticsLastSeen", createWKDictionary({ 1305 { "HostName", toWK(hostName) }, 1306 { "Value", toWK(seconds) }, 1307 })); 1550 1308 } 1551 1309 … … 1559 1317 cacheTestRunnerCallback(SetStatisticsMergeStatisticCallbackID, completionHandler); 1560 1318 1561 Vector<WKRetainPtr<WKStringRef>> keys; 1562 Vector<WKRetainPtr<WKTypeRef>> values; 1563 1564 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostName"))); 1565 values.append(adoptWK(WKStringCreateWithJSString(hostName))); 1566 1567 keys.append(adoptWK(WKStringCreateWithUTF8CString("TopFrameDomain1"))); 1568 values.append(adoptWK(WKStringCreateWithJSString(topFrameDomain1))); 1569 1570 keys.append(adoptWK(WKStringCreateWithUTF8CString("TopFrameDomain2"))); 1571 values.append(adoptWK(WKStringCreateWithJSString(topFrameDomain2))); 1572 1573 keys.append(adoptWK(WKStringCreateWithUTF8CString("LastSeen"))); 1574 values.append(adoptWK(WKDoubleCreate(lastSeen))); 1575 1576 keys.append(adoptWK(WKStringCreateWithUTF8CString("HadUserInteraction"))); 1577 values.append(adoptWK(WKBooleanCreate(hadUserInteraction))); 1578 1579 keys.append(adoptWK(WKStringCreateWithUTF8CString("MostRecentUserInteraction"))); 1580 values.append(adoptWK(WKDoubleCreate(mostRecentUserInteraction))); 1581 1582 keys.append(adoptWK(WKStringCreateWithUTF8CString("IsGrandfathered"))); 1583 values.append(adoptWK(WKBooleanCreate(isGrandfathered))); 1584 1585 keys.append(adoptWK(WKStringCreateWithUTF8CString("IsPrevalent"))); 1586 values.append(adoptWK(WKBooleanCreate(isPrevalent))); 1587 1588 keys.append(adoptWK(WKStringCreateWithUTF8CString("IsVeryPrevalent"))); 1589 values.append(adoptWK(WKBooleanCreate(isVeryPrevalent))); 1590 1591 keys.append(adoptWK(WKStringCreateWithUTF8CString("DataRecordsRemoved"))); 1592 values.append(adoptWK(WKUInt64Create(dataRecordsRemoved))); 1593 1594 Vector<WKStringRef> rawKeys(keys.size()); 1595 Vector<WKTypeRef> rawValues(values.size()); 1596 1597 for (size_t i = 0; i < keys.size(); ++i) { 1598 rawKeys[i] = keys[i].get(); 1599 rawValues[i] = values[i].get(); 1600 } 1601 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsMergeStatistic")); 1602 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 1603 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 1319 postMessage("SetStatisticsMergeStatistic", createWKDictionary({ 1320 { "HostName", toWK(hostName) }, 1321 { "TopFrameDomain1", toWK(topFrameDomain1) }, 1322 { "TopFrameDomain2", toWK(topFrameDomain2) }, 1323 { "LastSeen", adoptWK(WKDoubleCreate(lastSeen)) }, 1324 { "HadUserInteraction", adoptWK(WKBooleanCreate(hadUserInteraction)) }, 1325 { "MostRecentUserInteraction", adoptWK(WKDoubleCreate(mostRecentUserInteraction)) }, 1326 { "IsGrandfathered", adoptWK(WKBooleanCreate(isGrandfathered)) }, 1327 { "IsPrevalent", adoptWK(WKBooleanCreate(isPrevalent)) }, 1328 { "IsVeryPrevalent", adoptWK(WKBooleanCreate(isVeryPrevalent)) }, 1329 { "DataRecordsRemoved", adoptWK(WKUInt64Create(dataRecordsRemoved)) }, 1330 })); 1604 1331 } 1605 1332 … … 1613 1340 cacheTestRunnerCallback(SetStatisticsExpiredStatisticCallbackID, completionHandler); 1614 1341 1615 Vector<WKRetainPtr<WKStringRef>> keys; 1616 Vector<WKRetainPtr<WKTypeRef>> values; 1617 1618 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostName"))); 1619 values.append(adoptWK(WKStringCreateWithJSString(hostName))); 1620 1621 keys.append(adoptWK(WKStringCreateWithUTF8CString("HadUserInteraction"))); 1622 values.append(adoptWK(WKBooleanCreate(hadUserInteraction))); 1623 1624 keys.append(adoptWK(WKStringCreateWithUTF8CString("IsScheduledForAllButCookieDataRemoval"))); 1625 values.append(adoptWK(WKBooleanCreate(isScheduledForAllButCookieDataRemoval))); 1626 1627 keys.append(adoptWK(WKStringCreateWithUTF8CString("IsPrevalent"))); 1628 values.append(adoptWK(WKBooleanCreate(isPrevalent))); 1629 1630 Vector<WKStringRef> rawKeys(keys.size()); 1631 Vector<WKTypeRef> rawValues(values.size()); 1632 1633 for (size_t i = 0; i < keys.size(); ++i) { 1634 rawKeys[i] = keys[i].get(); 1635 rawValues[i] = values[i].get(); 1636 } 1637 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsExpiredStatistic")); 1638 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 1639 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 1342 postMessage("SetStatisticsExpiredStatistic", createWKDictionary({ 1343 { "HostName", toWK(hostName) }, 1344 { "HadUserInteraction", adoptWK(WKBooleanCreate(hadUserInteraction)) }, 1345 { "IsScheduledForAllButCookieDataRemoval", adoptWK(WKBooleanCreate(isScheduledForAllButCookieDataRemoval)) }, 1346 { "IsPrevalent", adoptWK(WKBooleanCreate(isPrevalent)) } 1347 })); 1640 1348 } 1641 1349 … … 1649 1357 cacheTestRunnerCallback(SetStatisticsPrevalentResourceCallbackID, completionHandler); 1650 1358 1651 Vector<WKRetainPtr<WKStringRef>> keys; 1652 Vector<WKRetainPtr<WKTypeRef>> values; 1653 1654 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostName"))); 1655 values.append(adoptWK(WKStringCreateWithJSString(hostName))); 1656 1657 keys.append(adoptWK(WKStringCreateWithUTF8CString("Value"))); 1658 values.append(adoptWK(WKBooleanCreate(value))); 1659 1660 Vector<WKStringRef> rawKeys; 1661 Vector<WKTypeRef> rawValues; 1662 rawKeys.resize(keys.size()); 1663 rawValues.resize(values.size()); 1664 1665 for (size_t i = 0; i < keys.size(); ++i) { 1666 rawKeys[i] = keys[i].get(); 1667 rawValues[i] = values[i].get(); 1668 } 1669 1670 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsPrevalentResource")); 1671 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 1672 1673 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 1359 postMessage("SetStatisticsPrevalentResource", createWKDictionary({ 1360 { "HostName", toWK(hostName) }, 1361 { "Value", adoptWK(WKBooleanCreate(value)) }, 1362 })); 1674 1363 } 1675 1364 … … 1683 1372 cacheTestRunnerCallback(SetStatisticsVeryPrevalentResourceCallbackID, completionHandler); 1684 1373 1685 Vector<WKRetainPtr<WKStringRef>> keys; 1686 Vector<WKRetainPtr<WKTypeRef>> values; 1687 1688 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostName"))); 1689 values.append(adoptWK(WKStringCreateWithJSString(hostName))); 1690 1691 keys.append(adoptWK(WKStringCreateWithUTF8CString("Value"))); 1692 values.append(adoptWK(WKBooleanCreate(value))); 1693 1694 Vector<WKStringRef> rawKeys; 1695 Vector<WKTypeRef> rawValues; 1696 rawKeys.resize(keys.size()); 1697 rawValues.resize(values.size()); 1698 1699 for (size_t i = 0; i < keys.size(); ++i) { 1700 rawKeys[i] = keys[i].get(); 1701 rawValues[i] = values[i].get(); 1702 } 1703 1704 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsVeryPrevalentResource")); 1705 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 1706 1707 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 1374 postMessage("SetStatisticsVeryPrevalentResource", createWKDictionary({ 1375 { "HostName", toWK(hostName) }, 1376 { "Value", adoptWK(WKBooleanCreate(value)) }, 1377 })); 1708 1378 } 1709 1379 … … 1715 1385 void TestRunner::dumpResourceLoadStatistics() 1716 1386 { 1717 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("dumpResourceLoadStatistics")); 1718 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, nullptr); 1387 postSynchronousPageMessage("dumpResourceLoadStatistics"); 1719 1388 } 1720 1389 1721 1390 bool TestRunner::isStatisticsPrevalentResource(JSStringRef hostName) 1722 1391 { 1723 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("IsStatisticsPrevalentResource")); 1724 WKRetainPtr<WKStringRef> messageBody = adoptWK(WKStringCreateWithJSString(hostName)); 1725 WKTypeRef returnData = nullptr; 1726 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData); 1727 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 1728 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 1392 return postSynchronousPageMessageReturningBoolean("IsStatisticsPrevalentResource", hostName); 1729 1393 } 1730 1394 1731 1395 bool TestRunner::isStatisticsVeryPrevalentResource(JSStringRef hostName) 1732 1396 { 1733 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("IsStatisticsVeryPrevalentResource")); 1734 WKRetainPtr<WKStringRef> messageBody = adoptWK(WKStringCreateWithJSString(hostName)); 1735 WKTypeRef returnData = nullptr; 1736 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData); 1737 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 1738 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 1397 return postSynchronousPageMessageReturningBoolean("IsStatisticsVeryPrevalentResource", hostName); 1739 1398 } 1740 1399 1741 1400 bool TestRunner::isStatisticsRegisteredAsSubresourceUnder(JSStringRef subresourceHost, JSStringRef topFrameHost) 1742 1401 { 1743 Vector<WKRetainPtr<WKStringRef>> keys; 1744 Vector<WKRetainPtr<WKTypeRef>> values; 1745 1746 keys.append(adoptWK(WKStringCreateWithUTF8CString("SubresourceHost"))); 1747 values.append(adoptWK(WKStringCreateWithJSString(subresourceHost))); 1748 1749 keys.append(adoptWK(WKStringCreateWithUTF8CString("TopFrameHost"))); 1750 values.append(adoptWK(WKStringCreateWithJSString(topFrameHost))); 1751 1752 Vector<WKStringRef> rawKeys(keys.size()); 1753 Vector<WKTypeRef> rawValues(values.size()); 1754 1755 for (size_t i = 0; i < keys.size(); ++i) { 1756 rawKeys[i] = keys[i].get(); 1757 rawValues[i] = values[i].get(); 1758 } 1759 1760 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("IsStatisticsRegisteredAsSubresourceUnder")); 1761 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 1762 WKTypeRef returnData = nullptr; 1763 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData); 1764 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 1765 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 1402 return postSynchronousPageMessageReturningBoolean("IsStatisticsRegisteredAsSubresourceUnder", createWKDictionary({ 1403 { "SubresourceHost", toWK(subresourceHost) }, 1404 { "TopFrameHost", toWK(topFrameHost) }, 1405 })); 1766 1406 } 1767 1407 1768 1408 bool TestRunner::isStatisticsRegisteredAsSubFrameUnder(JSStringRef subFrameHost, JSStringRef topFrameHost) 1769 1409 { 1770 Vector<WKRetainPtr<WKStringRef>> keys; 1771 Vector<WKRetainPtr<WKTypeRef>> values; 1772 1773 keys.append(adoptWK(WKStringCreateWithUTF8CString("SubFrameHost"))); 1774 values.append(adoptWK(WKStringCreateWithJSString(subFrameHost))); 1775 1776 keys.append(adoptWK(WKStringCreateWithUTF8CString("TopFrameHost"))); 1777 values.append(adoptWK(WKStringCreateWithJSString(topFrameHost))); 1778 1779 Vector<WKStringRef> rawKeys(keys.size()); 1780 Vector<WKTypeRef> rawValues(values.size()); 1781 1782 for (size_t i = 0; i < keys.size(); ++i) { 1783 rawKeys[i] = keys[i].get(); 1784 rawValues[i] = values[i].get(); 1785 } 1786 1787 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("IsStatisticsRegisteredAsSubFrameUnder")); 1788 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 1789 WKTypeRef returnData = nullptr; 1790 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData); 1791 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 1792 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 1410 return postSynchronousPageMessageReturningBoolean("IsStatisticsRegisteredAsSubFrameUnder", createWKDictionary({ 1411 { "SubFrameHost", toWK(subFrameHost) }, 1412 { "TopFrameHost", toWK(topFrameHost) }, 1413 })); 1793 1414 } 1794 1415 1795 1416 bool TestRunner::isStatisticsRegisteredAsRedirectingTo(JSStringRef hostRedirectedFrom, JSStringRef hostRedirectedTo) 1796 1417 { 1797 Vector<WKRetainPtr<WKStringRef>> keys; 1798 Vector<WKRetainPtr<WKTypeRef>> values; 1799 1800 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostRedirectedFrom"))); 1801 values.append(adoptWK(WKStringCreateWithJSString(hostRedirectedFrom))); 1802 1803 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostRedirectedTo"))); 1804 values.append(adoptWK(WKStringCreateWithJSString(hostRedirectedTo))); 1805 1806 Vector<WKStringRef> rawKeys(keys.size()); 1807 Vector<WKTypeRef> rawValues(values.size()); 1808 1809 for (size_t i = 0; i < keys.size(); ++i) { 1810 rawKeys[i] = keys[i].get(); 1811 rawValues[i] = values[i].get(); 1812 } 1813 1814 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("IsStatisticsRegisteredAsRedirectingTo")); 1815 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 1816 WKTypeRef returnData = nullptr; 1817 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData); 1818 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 1819 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 1418 return postSynchronousPageMessageReturningBoolean("IsStatisticsRegisteredAsRedirectingTo", createWKDictionary({ 1419 { "HostRedirectedFrom", toWK(hostRedirectedFrom) }, 1420 { "HostRedirectedTo", toWK(hostRedirectedTo) }, 1421 })); 1820 1422 } 1821 1423 … … 1824 1426 cacheTestRunnerCallback(SetStatisticsHasHadUserInteractionCallbackID, completionHandler); 1825 1427 1826 Vector<WKRetainPtr<WKStringRef>> keys; 1827 Vector<WKRetainPtr<WKTypeRef>> values; 1828 1829 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostName"))); 1830 values.append(adoptWK(WKStringCreateWithJSString(hostName))); 1831 1832 keys.append(adoptWK(WKStringCreateWithUTF8CString("Value"))); 1833 values.append(adoptWK(WKBooleanCreate(value))); 1834 1835 Vector<WKStringRef> rawKeys; 1836 Vector<WKTypeRef> rawValues; 1837 rawKeys.resize(keys.size()); 1838 rawValues.resize(values.size()); 1839 1840 for (size_t i = 0; i < keys.size(); ++i) { 1841 rawKeys[i] = keys[i].get(); 1842 rawValues[i] = values[i].get(); 1843 } 1844 1845 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsHasHadUserInteraction")); 1846 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 1847 1848 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 1428 postMessage("SetStatisticsHasHadUserInteraction", createWKDictionary({ 1429 { "HostName", toWK(hostName) }, 1430 { "Value", adoptWK(WKBooleanCreate(value)) }, 1431 })); 1849 1432 } 1850 1433 … … 1856 1439 bool TestRunner::isStatisticsHasHadUserInteraction(JSStringRef hostName) 1857 1440 { 1858 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("IsStatisticsHasHadUserInteraction")); 1859 WKRetainPtr<WKStringRef> messageBody = adoptWK(WKStringCreateWithJSString(hostName)); 1860 WKTypeRef returnData = nullptr; 1861 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData); 1862 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 1863 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 1441 return postSynchronousPageMessageReturningBoolean("IsStatisticsHasHadUserInteraction", hostName); 1864 1442 } 1865 1443 1866 1444 bool TestRunner::isStatisticsOnlyInDatabaseOnce(JSStringRef subHost, JSStringRef topHost) 1867 1445 { 1868 1869 Vector<WKRetainPtr<WKStringRef>> keys; 1870 Vector<WKRetainPtr<WKTypeRef>> values; 1871 1872 keys.append(adoptWK(WKStringCreateWithUTF8CString("SubHost"))); 1873 values.append(adoptWK(WKStringCreateWithJSString(subHost))); 1874 1875 keys.append(adoptWK(WKStringCreateWithUTF8CString("TopHost"))); 1876 values.append(adoptWK(WKStringCreateWithJSString(topHost))); 1877 1878 Vector<WKStringRef> rawKeys(keys.size()); 1879 Vector<WKTypeRef> rawValues(values.size()); 1880 1881 for (size_t i = 0; i < keys.size(); ++i) { 1882 rawKeys[i] = keys[i].get(); 1883 rawValues[i] = values[i].get(); 1884 } 1885 1886 auto messageName = adoptWK(WKStringCreateWithUTF8CString("IsStatisticsOnlyInDatabaseOnce")); 1887 auto messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 1888 WKTypeRef returnData = nullptr; 1889 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData); 1890 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 1891 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 1446 return postSynchronousPageMessageReturningBoolean("IsStatisticsOnlyInDatabaseOnce", createWKDictionary({ 1447 { "SubHost", toWK(subHost) }, 1448 { "TopHost", toWK(topHost) }, 1449 })); 1892 1450 } 1893 1451 1894 1452 void TestRunner::setStatisticsGrandfathered(JSStringRef hostName, bool value) 1895 1453 { 1896 Vector<WKRetainPtr<WKStringRef>> keys; 1897 Vector<WKRetainPtr<WKTypeRef>> values; 1898 1899 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostName"))); 1900 values.append(adoptWK(WKStringCreateWithJSString(hostName))); 1901 1902 keys.append(adoptWK(WKStringCreateWithUTF8CString("Value"))); 1903 values.append(adoptWK(WKBooleanCreate(value))); 1904 1905 Vector<WKStringRef> rawKeys; 1906 Vector<WKTypeRef> rawValues; 1907 rawKeys.resize(keys.size()); 1908 rawValues.resize(values.size()); 1909 1910 for (size_t i = 0; i < keys.size(); ++i) { 1911 rawKeys[i] = keys[i].get(); 1912 rawValues[i] = values[i].get(); 1913 } 1914 1915 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsGrandfathered")); 1916 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 1917 1918 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1454 postSynchronousMessage("SetStatisticsGrandfathered", createWKDictionary({ 1455 { "HostName", toWK(hostName) }, 1456 { "Value", adoptWK(WKBooleanCreate(value)) }, 1457 })); 1919 1458 } 1920 1459 1921 1460 bool TestRunner::isStatisticsGrandfathered(JSStringRef hostName) 1922 1461 { 1923 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("IsStatisticsGrandfathered")); 1924 WKRetainPtr<WKStringRef> messageBody = adoptWK(WKStringCreateWithJSString(hostName)); 1925 WKTypeRef returnData = nullptr; 1926 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData); 1927 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 1928 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 1462 return postSynchronousPageMessageReturningBoolean("IsStatisticsGrandfathered", hostName); 1929 1463 } 1930 1464 1931 1465 void TestRunner::setStatisticsSubframeUnderTopFrameOrigin(JSStringRef hostName, JSStringRef topFrameHostName) 1932 1466 { 1933 Vector<WKRetainPtr<WKStringRef>> keys; 1934 Vector<WKRetainPtr<WKTypeRef>> values; 1935 1936 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostName"))); 1937 values.append(adoptWK(WKStringCreateWithJSString(hostName))); 1938 1939 keys.append(adoptWK(WKStringCreateWithUTF8CString("TopFrameHostName"))); 1940 values.append(adoptWK(WKStringCreateWithJSString(topFrameHostName))); 1941 1942 Vector<WKStringRef> rawKeys(keys.size()); 1943 Vector<WKTypeRef> rawValues(values.size()); 1944 1945 for (size_t i = 0; i < keys.size(); ++i) { 1946 rawKeys[i] = keys[i].get(); 1947 rawValues[i] = values[i].get(); 1948 } 1949 1950 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsSubframeUnderTopFrameOrigin")); 1951 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 1952 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1467 postSynchronousMessage("SetStatisticsSubframeUnderTopFrameOrigin", createWKDictionary({ 1468 { "HostName", toWK(hostName) }, 1469 { "TopFrameHostName", toWK(topFrameHostName) }, 1470 })); 1953 1471 } 1954 1472 1955 1473 void TestRunner::setStatisticsSubresourceUnderTopFrameOrigin(JSStringRef hostName, JSStringRef topFrameHostName) 1956 1474 { 1957 Vector<WKRetainPtr<WKStringRef>> keys; 1958 Vector<WKRetainPtr<WKTypeRef>> values; 1959 1960 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostName"))); 1961 values.append(adoptWK(WKStringCreateWithJSString(hostName))); 1962 1963 keys.append(adoptWK(WKStringCreateWithUTF8CString("TopFrameHostName"))); 1964 values.append(adoptWK(WKStringCreateWithJSString(topFrameHostName))); 1965 1966 Vector<WKStringRef> rawKeys(keys.size()); 1967 Vector<WKTypeRef> rawValues(values.size()); 1968 1969 for (size_t i = 0; i < keys.size(); ++i) { 1970 rawKeys[i] = keys[i].get(); 1971 rawValues[i] = values[i].get(); 1972 } 1973 1974 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsSubresourceUnderTopFrameOrigin")); 1975 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 1976 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1475 postSynchronousMessage("SetStatisticsSubresourceUnderTopFrameOrigin", createWKDictionary({ 1476 { "HostName", toWK(hostName) }, 1477 { "TopFrameHostName", toWK(topFrameHostName) }, 1478 })); 1977 1479 } 1978 1480 1979 1481 void TestRunner::setStatisticsSubresourceUniqueRedirectTo(JSStringRef hostName, JSStringRef hostNameRedirectedTo) 1980 1482 { 1981 Vector<WKRetainPtr<WKStringRef>> keys; 1982 Vector<WKRetainPtr<WKTypeRef>> values; 1983 1984 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostName"))); 1985 values.append(adoptWK(WKStringCreateWithJSString(hostName))); 1986 1987 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostNameRedirectedTo"))); 1988 values.append(adoptWK(WKStringCreateWithJSString(hostNameRedirectedTo))); 1989 1990 Vector<WKStringRef> rawKeys(keys.size()); 1991 Vector<WKTypeRef> rawValues(values.size()); 1992 1993 for (size_t i = 0; i < keys.size(); ++i) { 1994 rawKeys[i] = keys[i].get(); 1995 rawValues[i] = values[i].get(); 1996 } 1997 1998 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsSubresourceUniqueRedirectTo")); 1999 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 2000 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1483 postSynchronousMessage("SetStatisticsSubresourceUniqueRedirectTo", createWKDictionary({ 1484 { "HostName", toWK(hostName) }, 1485 { "HostNameRedirectedTo", toWK(hostNameRedirectedTo) }, 1486 })); 2001 1487 } 2002 1488 … … 2004 1490 void TestRunner::setStatisticsSubresourceUniqueRedirectFrom(JSStringRef hostName, JSStringRef hostNameRedirectedFrom) 2005 1491 { 2006 Vector<WKRetainPtr<WKStringRef>> keys; 2007 Vector<WKRetainPtr<WKTypeRef>> values; 2008 2009 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostName"))); 2010 values.append(adoptWK(WKStringCreateWithJSString(hostName))); 2011 2012 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostNameRedirectedFrom"))); 2013 values.append(adoptWK(WKStringCreateWithJSString(hostNameRedirectedFrom))); 2014 2015 Vector<WKStringRef> rawKeys(keys.size()); 2016 Vector<WKTypeRef> rawValues(values.size()); 2017 2018 for (size_t i = 0; i < keys.size(); ++i) { 2019 rawKeys[i] = keys[i].get(); 2020 rawValues[i] = values[i].get(); 2021 } 2022 2023 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsSubresourceUniqueRedirectFrom")); 2024 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 2025 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1492 postSynchronousMessage("SetStatisticsSubresourceUniqueRedirectFrom", createWKDictionary({ 1493 { "HostName", toWK(hostName) }, 1494 { "HostNameRedirectedFrom", toWK(hostNameRedirectedFrom) }, 1495 })); 2026 1496 } 2027 1497 2028 1498 void TestRunner::setStatisticsTopFrameUniqueRedirectTo(JSStringRef hostName, JSStringRef hostNameRedirectedTo) 2029 1499 { 2030 Vector<WKRetainPtr<WKStringRef>> keys; 2031 Vector<WKRetainPtr<WKTypeRef>> values; 2032 2033 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostName"))); 2034 values.append(adoptWK(WKStringCreateWithJSString(hostName))); 2035 2036 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostNameRedirectedTo"))); 2037 values.append(adoptWK(WKStringCreateWithJSString(hostNameRedirectedTo))); 2038 2039 Vector<WKStringRef> rawKeys(keys.size()); 2040 Vector<WKTypeRef> rawValues(values.size()); 2041 2042 for (size_t i = 0; i < keys.size(); ++i) { 2043 rawKeys[i] = keys[i].get(); 2044 rawValues[i] = values[i].get(); 2045 } 2046 2047 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsTopFrameUniqueRedirectTo")); 2048 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 2049 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1500 postSynchronousMessage("SetStatisticsTopFrameUniqueRedirectTo", createWKDictionary({ 1501 { "HostName", toWK(hostName) }, 1502 { "HostNameRedirectedTo", toWK(hostNameRedirectedTo) }, 1503 })); 2050 1504 } 2051 1505 2052 1506 void TestRunner::setStatisticsTopFrameUniqueRedirectFrom(JSStringRef hostName, JSStringRef hostNameRedirectedFrom) 2053 1507 { 2054 Vector<WKRetainPtr<WKStringRef>> keys; 2055 Vector<WKRetainPtr<WKTypeRef>> values; 2056 2057 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostName"))); 2058 values.append(adoptWK(WKStringCreateWithJSString(hostName))); 2059 2060 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostNameRedirectedFrom"))); 2061 values.append(adoptWK(WKStringCreateWithJSString(hostNameRedirectedFrom))); 2062 2063 Vector<WKStringRef> rawKeys(keys.size()); 2064 Vector<WKTypeRef> rawValues(values.size()); 2065 2066 for (size_t i = 0; i < keys.size(); ++i) { 2067 rawKeys[i] = keys[i].get(); 2068 rawValues[i] = values[i].get(); 2069 } 2070 2071 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsTopFrameUniqueRedirectFrom")); 2072 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 2073 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1508 postSynchronousMessage("SetStatisticsTopFrameUniqueRedirectFrom", createWKDictionary({ 1509 { "HostName", toWK(hostName) }, 1510 { "HostNameRedirectedFrom", toWK(hostNameRedirectedFrom) }, 1511 })); 2074 1512 } 2075 1513 2076 1514 void TestRunner::setStatisticsCrossSiteLoadWithLinkDecoration(JSStringRef fromHost, JSStringRef toHost) 2077 1515 { 2078 Vector<WKRetainPtr<WKStringRef>> keys; 2079 Vector<WKRetainPtr<WKTypeRef>> values; 2080 2081 keys.append(adoptWK(WKStringCreateWithUTF8CString("FromHost"))); 2082 values.append(adoptWK(WKStringCreateWithJSString(fromHost))); 2083 2084 keys.append(adoptWK(WKStringCreateWithUTF8CString("ToHost"))); 2085 values.append(adoptWK(WKStringCreateWithJSString(toHost))); 2086 2087 Vector<WKStringRef> rawKeys(keys.size()); 2088 Vector<WKTypeRef> rawValues(values.size()); 2089 2090 for (size_t i = 0; i < keys.size(); ++i) { 2091 rawKeys[i] = keys[i].get(); 2092 rawValues[i] = values[i].get(); 2093 } 2094 2095 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsCrossSiteLoadWithLinkDecoration")); 2096 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 2097 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1516 postSynchronousMessage("SetStatisticsCrossSiteLoadWithLinkDecoration", createWKDictionary({ 1517 { "FromHost", toWK(fromHost) }, 1518 { "ToHost", toWK(toHost) }, 1519 })); 2098 1520 } 2099 1521 2100 1522 void TestRunner::setStatisticsTimeToLiveUserInteraction(double seconds) 2101 1523 { 2102 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsTimeToLiveUserInteraction")); 2103 WKRetainPtr<WKDoubleRef> messageBody = adoptWK(WKDoubleCreate(seconds)); 2104 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1524 postSynchronousMessage("SetStatisticsTimeToLiveUserInteraction", seconds); 2105 1525 } 2106 1526 … … 2140 1560 void TestRunner::statisticsDidRunTelemetryCallback(unsigned numberOfPrevalentResources, unsigned numberOfPrevalentResourcesWithUserInteraction, unsigned numberOfPrevalentResourcesWithoutUserInteraction, unsigned topPrevalentResourceWithUserInteractionDaysSinceUserInteraction, unsigned medianDaysSinceUserInteractionPrevalentResourceWithUserInteraction, unsigned top3NumberOfPrevalentResourcesWithUI, unsigned top3MedianSubFrameWithoutUI, unsigned top3MedianSubResourceWithoutUI, unsigned top3MedianUniqueRedirectsWithoutUI, unsigned top3MedianDataRecordsRemovedWithoutUI) 2141 1561 { 2142 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());2143 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);2144 2145 1562 String string = makeString("{ \"numberOfPrevalentResources\" : ", numberOfPrevalentResources, ", \"numberOfPrevalentResourcesWithUserInteraction\" : ", numberOfPrevalentResourcesWithUserInteraction, ", \"numberOfPrevalentResourcesWithoutUserInteraction\" : ", numberOfPrevalentResourcesWithoutUserInteraction, ", \"topPrevalentResourceWithUserInteractionDaysSinceUserInteraction\" : ", topPrevalentResourceWithUserInteractionDaysSinceUserInteraction, ", \"medianDaysSinceUserInteractionPrevalentResourceWithUserInteraction\" : ", medianDaysSinceUserInteractionPrevalentResourceWithUserInteraction, ", \"top3NumberOfPrevalentResourcesWithUI\" : ", top3NumberOfPrevalentResourcesWithUI, ", \"top3MedianSubFrameWithoutUI\" : ", top3MedianSubFrameWithoutUI, ", \"top3MedianSubResourceWithoutUI\" : ", top3MedianSubResourceWithoutUI, ", \"top3MedianUniqueRedirectsWithoutUI\" : ", top3MedianUniqueRedirectsWithoutUI, ", \"top3MedianDataRecordsRemovedWithoutUI\" : ", top3MedianDataRecordsRemovedWithoutUI, " }"); 2146 1563 2147 JSValueRef result = JSValueMakeFromJSONString( context, adopt(JSStringCreateWithUTF8CString(string.utf8().data())).get());1564 JSValueRef result = JSValueMakeFromJSONString(mainFrameJSContext(), createJSString(string.utf8().data()).get()); 2148 1565 2149 1566 callTestRunnerCallback(StatisticsDidRunTelemetryCallbackID, 1, &result); … … 2157 1574 void TestRunner::statisticsProcessStatisticsAndDataRecords() 2158 1575 { 2159 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsProcessStatisticsAndDataRecords")); 2160 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr); 1576 postSynchronousMessage("StatisticsProcessStatisticsAndDataRecords"); 2161 1577 } 2162 1578 … … 2165 1581 cacheTestRunnerCallback(StatisticsDidSetBlockCookiesForHostCallbackID, completionHandler); 2166 1582 2167 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsUpdateCookieBlocking")); 2168 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr); 1583 postMessage("StatisticsUpdateCookieBlocking"); 2169 1584 } 2170 1585 … … 2176 1591 void TestRunner::statisticsSubmitTelemetry() 2177 1592 { 2178 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsSubmitTelemetry")); 2179 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr); 1593 postSynchronousMessage("StatisticsSubmitTelemetry"); 2180 1594 } 2181 1595 2182 1596 void TestRunner::setStatisticsNotifyPagesWhenDataRecordsWereScanned(bool value) 2183 1597 { 2184 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsNotifyPagesWhenDataRecordsWereScanned")); 2185 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 2186 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1598 postSynchronousMessage("StatisticsNotifyPagesWhenDataRecordsWereScanned", value); 2187 1599 } 2188 1600 2189 1601 void TestRunner::setStatisticsIsRunningTest(bool value) 2190 1602 { 2191 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsSetIsRunningTest")); 2192 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 2193 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1603 postSynchronousMessage("StatisticsSetIsRunningTest", value); 2194 1604 } 2195 1605 2196 1606 void TestRunner::setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool value) 2197 1607 { 2198 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsShouldClassifyResourcesBeforeDataRecordsRemoval")); 2199 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 2200 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1608 postSynchronousMessage("StatisticsShouldClassifyResourcesBeforeDataRecordsRemoval", value); 2201 1609 } 2202 1610 2203 1611 void TestRunner::setStatisticsMinimumTimeBetweenDataRecordsRemoval(double seconds) 2204 1612 { 2205 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsMinimumTimeBetweenDataRecordsRemoval")); 2206 WKRetainPtr<WKDoubleRef> messageBody = adoptWK(WKDoubleCreate(seconds)); 2207 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1613 postSynchronousMessage("SetStatisticsMinimumTimeBetweenDataRecordsRemoval", seconds); 2208 1614 } 2209 1615 2210 1616 void TestRunner::setStatisticsGrandfatheringTime(double seconds) 2211 1617 { 2212 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsGrandfatheringTime")); 2213 WKRetainPtr<WKDoubleRef> messageBody = adoptWK(WKDoubleCreate(seconds)); 2214 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1618 postSynchronousMessage("SetStatisticsGrandfatheringTime", seconds); 2215 1619 } 2216 1620 2217 1621 void TestRunner::setStatisticsMaxStatisticsEntries(unsigned entries) 2218 1622 { 2219 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetMaxStatisticsEntries")); 2220 WKRetainPtr<WKTypeRef> messageBody = adoptWK(WKUInt64Create(entries)); 2221 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1623 postSynchronousMessage("SetMaxStatisticsEntries", entries); 2222 1624 } 2223 1625 2224 1626 void TestRunner::setStatisticsPruneEntriesDownTo(unsigned entries) 2225 1627 { 2226 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetPruneEntriesDownTo")); 2227 WKRetainPtr<WKTypeRef> messageBody = adoptWK(WKUInt64Create(entries)); 2228 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1628 postSynchronousMessage("SetPruneEntriesDownTo", entries); 2229 1629 } 2230 1630 … … 2232 1632 { 2233 1633 cacheTestRunnerCallback(StatisticsDidClearInMemoryAndPersistentStoreCallbackID, callback); 2234 2235 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsClearInMemoryAndPersistentStore")); 2236 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr); 1634 postMessage("StatisticsClearInMemoryAndPersistentStore"); 2237 1635 } 2238 1636 … … 2240 1638 { 2241 1639 cacheTestRunnerCallback(StatisticsDidClearInMemoryAndPersistentStoreCallbackID, callback); 2242 2243 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsClearInMemoryAndPersistentStoreModifiedSinceHours")); 2244 WKRetainPtr<WKTypeRef> messageBody = adoptWK(WKUInt64Create(hours)); 2245 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 1640 postMessage("StatisticsClearInMemoryAndPersistentStoreModifiedSinceHours", hours); 2246 1641 } 2247 1642 … … 2249 1644 { 2250 1645 cacheTestRunnerCallback(StatisticsDidClearThroughWebsiteDataRemovalCallbackID, callback); 2251 2252 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsClearThroughWebsiteDataRemoval")); 2253 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr); 1646 postMessage("StatisticsClearThroughWebsiteDataRemoval"); 2254 1647 } 2255 1648 2256 1649 void TestRunner::statisticsDeleteCookiesForHost(JSStringRef hostName, bool includeHttpOnlyCookies) 2257 1650 { 2258 Vector<WKRetainPtr<WKStringRef>> keys; 2259 Vector<WKRetainPtr<WKTypeRef>> values; 2260 2261 keys.append(adoptWK(WKStringCreateWithUTF8CString("HostName"))); 2262 values.append(adoptWK(WKStringCreateWithJSString(hostName))); 2263 2264 keys.append(adoptWK(WKStringCreateWithUTF8CString("IncludeHttpOnlyCookies"))); 2265 values.append(adoptWK(WKBooleanCreate(includeHttpOnlyCookies))); 2266 2267 Vector<WKStringRef> rawKeys; 2268 Vector<WKTypeRef> rawValues; 2269 rawKeys.resize(keys.size()); 2270 rawValues.resize(values.size()); 2271 2272 for (size_t i = 0; i < keys.size(); ++i) { 2273 rawKeys[i] = keys[i].get(); 2274 rawValues[i] = values[i].get(); 2275 } 2276 2277 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsDeleteCookiesForHost")); 2278 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 2279 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1651 postSynchronousMessage("StatisticsDeleteCookiesForHost", createWKDictionary({ 1652 { "HostName", toWK(hostName) }, 1653 { "IncludeHttpOnlyCookies", adoptWK(WKBooleanCreate(includeHttpOnlyCookies)) }, 1654 })); 2280 1655 } 2281 1656 2282 1657 bool TestRunner::isStatisticsHasLocalStorage(JSStringRef hostName) 2283 1658 { 2284 auto messageName = adoptWK(WKStringCreateWithUTF8CString("IsStatisticsHasLocalStorage")); 2285 auto messageBody = adoptWK(WKStringCreateWithJSString(hostName)); 2286 WKTypeRef returnData = nullptr; 2287 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData); 2288 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 2289 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 1659 return postSynchronousPageMessageReturningBoolean("IsStatisticsHasLocalStorage", hostName); 2290 1660 } 2291 1661 2292 1662 void TestRunner::setStatisticsCacheMaxAgeCap(double seconds) 2293 1663 { 2294 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsCacheMaxAgeCap")); 2295 WKRetainPtr<WKDoubleRef> messageBody = adoptWK(WKDoubleCreate(seconds)); 2296 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1664 postSynchronousMessage("SetStatisticsCacheMaxAgeCap", seconds); 2297 1665 } 2298 1666 2299 1667 bool TestRunner::hasStatisticsIsolatedSession(JSStringRef hostName) 2300 1668 { 2301 auto messageName = adoptWK(WKStringCreateWithUTF8CString("HasStatisticsIsolatedSession")); 2302 auto messageBody = adoptWK(WKStringCreateWithJSString(hostName)); 2303 WKTypeRef returnData = nullptr; 2304 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData); 2305 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 2306 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 1669 return postSynchronousPageMessageReturningBoolean("HasStatisticsIsolatedSession", hostName); 2307 1670 } 2308 1671 … … 2313 1676 2314 1677 cacheTestRunnerCallback(StatisticsDidSetShouldDowngradeReferrerCallbackID, completionHandler); 2315 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsShouldDowngradeReferrer")); 2316 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 2317 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 1678 postMessage("SetStatisticsShouldDowngradeReferrer", value); 2318 1679 m_hasSetDowngradeReferrerCallback = true; 2319 1680 } … … 2331 1692 2332 1693 cacheTestRunnerCallback(StatisticsDidSetShouldBlockThirdPartyCookiesCallbackID, completionHandler); 2333 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsShouldBlockThirdPartyCookies"));1694 auto messageName = "SetStatisticsShouldBlockThirdPartyCookies"; 2334 1695 if (onlyOnSitesWithoutUserInteraction) 2335 messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsShouldBlockThirdPartyCookiesOnSitesWithoutUserInteraction")); 2336 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 2337 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 1696 messageName = "SetStatisticsShouldBlockThirdPartyCookiesOnSitesWithoutUserInteraction"; 1697 postMessage(messageName, value); 2338 1698 m_hasSetBlockThirdPartyCookiesCallback = true; 2339 1699 } … … 2351 1711 2352 1712 cacheTestRunnerCallback(StatisticsDidSetFirstPartyWebsiteDataRemovalModeCallbackID, completionHandler); 2353 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsFirstPartyWebsiteDataRemovalMode")); 2354 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 2355 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 1713 postMessage("SetStatisticsFirstPartyWebsiteDataRemovalMode", value); 2356 1714 m_hasSetFirstPartyWebsiteDataRemovalModeCallback = true; 2357 1715 } … … 2376 1734 { 2377 1735 cacheTestRunnerCallback(StatisticsDidSetToSameSiteStrictCookiesCallbackID, completionHandler); 2378 2379 auto messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsSetToSameSiteStrictCookies")); 2380 auto messageBody = adoptWK(WKStringCreateWithJSString(hostName)); 2381 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 1736 postMessage("StatisticsSetToSameSiteStrictCookies", hostName); 2382 1737 } 2383 1738 … … 2391 1746 { 2392 1747 cacheTestRunnerCallback(StatisticsDidSetFirstPartyHostCNAMEDomainCallbackID, completionHandler); 2393 2394 Vector<WKRetainPtr<WKStringRef>> keys; 2395 Vector<WKRetainPtr<WKTypeRef>> values; 2396 2397 keys.append(adoptWK(WKStringCreateWithUTF8CString("FirstPartyURL"))); 2398 values.append(adoptWK(WKStringCreateWithJSString(firstPartyURLString))); 2399 2400 keys.append(adoptWK(WKStringCreateWithUTF8CString("CNAME"))); 2401 values.append(adoptWK(WKStringCreateWithJSString(cnameURLString))); 2402 2403 Vector<WKStringRef> rawKeys(keys.size()); 2404 Vector<WKTypeRef> rawValues(values.size()); 2405 2406 for (size_t i = 0; i < keys.size(); ++i) { 2407 rawKeys[i] = keys[i].get(); 2408 rawValues[i] = values[i].get(); 2409 } 2410 2411 auto messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsSetFirstPartyHostCNAMEDomain")); 2412 auto messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 2413 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 1748 postMessage("StatisticsSetFirstPartyHostCNAMEDomain", createWKDictionary({ 1749 { "FirstPartyURL", toWK(firstPartyURLString) }, 1750 { "CNAME", toWK(cnameURLString) }, 1751 })); 2414 1752 } 2415 1753 … … 2422 1760 { 2423 1761 cacheTestRunnerCallback(StatisticsDidSetThirdPartyCNAMEDomainCallbackID, completionHandler); 2424 2425 auto messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsSetThirdPartyCNAMEDomain")); 2426 auto messageBody = adoptWK(WKStringCreateWithJSString(cnameURLString)); 2427 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 1762 postMessage("StatisticsSetThirdPartyCNAMEDomain", toWK(cnameURLString)); 2428 1763 } 2429 1764 … … 2436 1771 { 2437 1772 cacheTestRunnerCallback(StatisticsDidResetToConsistentStateCallbackID, completionHandler); 2438 2439 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsResetToConsistentState")); 2440 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr); 1773 1774 postMessage("StatisticsResetToConsistentState"); 2441 1775 } 2442 1776 … … 2479 1813 { 2480 1814 cacheTestRunnerCallback(AllStorageAccessEntriesCallbackID, callback); 2481 2482 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("GetAllStorageAccessEntries")); 2483 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr); 2484 } 2485 2486 void TestRunner::callDidReceiveAllStorageAccessEntriesCallback(Vector<String>& domains) 2487 { 2488 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page()); 2489 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); 2490 2491 StringBuilder stringBuilder; 2492 stringBuilder.appendLiteral("["); 1815 postMessage("GetAllStorageAccessEntries"); 1816 } 1817 1818 static JSValueRef makeDomainsValue(const Vector<String>& domains) 1819 { 1820 StringBuilder builder; 1821 builder.append('['); 2493 1822 bool firstDomain = true; 2494 1823 for (auto& domain : domains) { 2495 if (firstDomain) 2496 firstDomain = false; 2497 else 2498 stringBuilder.appendLiteral(", "); 2499 stringBuilder.appendLiteral("\""); 2500 stringBuilder.append(domain); 2501 stringBuilder.appendLiteral("\""); 1824 builder.append(firstDomain ? "\"" : ", \"", domain, '"'); 1825 firstDomain = false; 2502 1826 } 2503 stringBuilder.appendLiteral("]"); 2504 2505 JSValueRef result = JSValueMakeFromJSONString(context, adopt(JSStringCreateWithUTF8CString(stringBuilder.toString().utf8().data())).get()); 2506 1827 builder.append(']'); 1828 return JSValueMakeFromJSONString(mainFrameJSContext(), createJSString(builder.toString().utf8().data()).get()); 1829 } 1830 void TestRunner::callDidReceiveAllStorageAccessEntriesCallback(Vector<String>& domains) 1831 { 1832 auto result = makeDomainsValue(domains); 2507 1833 callTestRunnerCallback(AllStorageAccessEntriesCallbackID, 1, &result); 2508 1834 } … … 2511 1837 { 2512 1838 cacheTestRunnerCallback(LoadedSubresourceDomainsCallbackID, callback); 2513 2514 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("LoadedSubresourceDomains")); 2515 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr); 1839 postMessage("LoadedSubresourceDomains"); 2516 1840 } 2517 1841 2518 1842 void TestRunner::callDidReceiveLoadedSubresourceDomainsCallback(Vector<String>&& domains) 2519 1843 { 2520 WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page()); 2521 JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame); 2522 2523 StringBuilder stringBuilder; 2524 stringBuilder.append('['); 2525 bool isFirstDomain = true; 2526 for (auto& domain : domains) { 2527 if (isFirstDomain) 2528 isFirstDomain = false; 2529 else 2530 stringBuilder.appendLiteral(", "); 2531 stringBuilder.appendLiteral("\""); 2532 stringBuilder.append(domain); 2533 stringBuilder.appendLiteral("\""); 2534 } 2535 stringBuilder.append(']'); 2536 2537 JSValueRef result = JSValueMakeFromJSONString(context, adopt(JSStringCreateWithUTF8CString(stringBuilder.toString().utf8().data())).get()); 2538 1844 auto result = makeDomainsValue(domains); 2539 1845 callTestRunnerCallback(LoadedSubresourceDomainsCallbackID, 1, &result); 2540 1846 } … … 2542 1848 void TestRunner::addMockMediaDevice(JSStringRef persistentId, JSStringRef label, const char* type) 2543 1849 { 2544 Vector<WKRetainPtr<WKStringRef>> keys; 2545 Vector<WKRetainPtr<WKTypeRef>> values; 2546 2547 keys.append(adoptWK(WKStringCreateWithUTF8CString("PersistentID"))); 2548 values.append(toWK(persistentId)); 2549 2550 keys.append(adoptWK(WKStringCreateWithUTF8CString("Label"))); 2551 values.append(toWK(label)); 2552 2553 keys.append(adoptWK(WKStringCreateWithUTF8CString("Type"))); 2554 values.append(adoptWK(WKStringCreateWithUTF8CString(type))); 2555 2556 Vector<WKStringRef> rawKeys; 2557 Vector<WKTypeRef> rawValues; 2558 rawKeys.resize(keys.size()); 2559 rawValues.resize(values.size()); 2560 2561 for (size_t i = 0; i < keys.size(); ++i) { 2562 rawKeys[i] = keys[i].get(); 2563 rawValues[i] = values[i].get(); 2564 } 2565 2566 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("AddMockMediaDevice")); 2567 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 2568 2569 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1850 postSynchronousMessage("AddMockMediaDevice", createWKDictionary({ 1851 { "PersistentID", toWK(persistentId) }, 1852 { "Label", toWK(label) }, 1853 { "Type", toWK(type) }, 1854 })); 2570 1855 } 2571 1856 … … 2587 1872 void TestRunner::clearMockMediaDevices() 2588 1873 { 2589 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ClearMockMediaDevices")); 2590 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr); 1874 postSynchronousMessage("ClearMockMediaDevices"); 2591 1875 } 2592 1876 2593 1877 void TestRunner::removeMockMediaDevice(JSStringRef persistentId) 2594 1878 { 2595 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("RemoveMockMediaDevice")); 2596 WKRetainPtr<WKTypeRef> messageBody(toWK(persistentId)); 2597 2598 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1879 postSynchronousMessage("RemoveMockMediaDevice", toWK(persistentId)); 2599 1880 } 2600 1881 2601 1882 void TestRunner::resetMockMediaDevices() 2602 1883 { 2603 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ResetMockMediaDevices")); 2604 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr); 1884 postSynchronousMessage("ResetMockMediaDevices"); 2605 1885 } 2606 1886 2607 1887 void TestRunner::setMockCameraOrientation(unsigned orientation) 2608 1888 { 2609 auto messageName = adoptWK(WKStringCreateWithUTF8CString("SetMockCameraOrientation")); 2610 auto messageBody = adoptWK(WKUInt64Create(orientation)); 2611 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1889 postSynchronousMessage("SetMockCameraOrientation", orientation); 2612 1890 } 2613 1891 2614 1892 bool TestRunner::isMockRealtimeMediaSourceCenterEnabled() 2615 1893 { 2616 auto messageName = adoptWK(WKStringCreateWithUTF8CString("IsMockRealtimeMediaSourceCenterEnabled")); 2617 WKTypeRef returnData = nullptr; 2618 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, &returnData); 2619 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 2620 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 1894 return postSynchronousMessageReturningBoolean("IsMockRealtimeMediaSourceCenterEnabled"); 2621 1895 } 2622 1896 2623 1897 #if PLATFORM(MAC) 1898 2624 1899 void TestRunner::connectMockGamepad(unsigned index) 2625 1900 { 2626 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ConnectMockGamepad")); 2627 WKRetainPtr<WKTypeRef> messageBody = adoptWK(WKUInt64Create(index)); 2628 2629 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1901 postSynchronousMessage("ConnectMockGamepad", index); 2630 1902 } 2631 1903 2632 1904 void TestRunner::disconnectMockGamepad(unsigned index) 2633 1905 { 2634 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("DisconnectMockGamepad")); 2635 WKRetainPtr<WKTypeRef> messageBody = adoptWK(WKUInt64Create(index)); 2636 2637 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1906 postSynchronousMessage("DisconnectMockGamepad", index); 2638 1907 } 2639 1908 2640 1909 void TestRunner::setMockGamepadDetails(unsigned index, JSStringRef gamepadID, JSStringRef mapping, unsigned axisCount, unsigned buttonCount) 2641 1910 { 2642 Vector<WKRetainPtr<WKStringRef>> keys; 2643 Vector<WKRetainPtr<WKTypeRef>> values; 2644 2645 keys.append(adoptWK(WKStringCreateWithUTF8CString("GamepadID"))); 2646 values.append(toWK(gamepadID)); 2647 2648 keys.append(adoptWK(WKStringCreateWithUTF8CString("Mapping"))); 2649 values.append(toWK(mapping)); 2650 2651 keys.append(adoptWK(WKStringCreateWithUTF8CString("GamepadIndex"))); 2652 values.append(adoptWK(WKUInt64Create(index))); 2653 2654 keys.append(adoptWK(WKStringCreateWithUTF8CString("AxisCount"))); 2655 values.append(adoptWK(WKUInt64Create(axisCount))); 2656 2657 keys.append(adoptWK(WKStringCreateWithUTF8CString("ButtonCount"))); 2658 values.append(adoptWK(WKUInt64Create(buttonCount))); 2659 2660 Vector<WKStringRef> rawKeys; 2661 Vector<WKTypeRef> rawValues; 2662 rawKeys.resize(keys.size()); 2663 rawValues.resize(values.size()); 2664 2665 for (size_t i = 0; i < keys.size(); ++i) { 2666 rawKeys[i] = keys[i].get(); 2667 rawValues[i] = values[i].get(); 2668 } 2669 2670 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetMockGamepadDetails")); 2671 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 2672 2673 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1911 postSynchronousMessage("SetMockGamepadDetails", createWKDictionary({ 1912 { "GamepadID", toWK(gamepadID) }, 1913 { "Mapping", toWK(mapping) }, 1914 { "GamepadIndex", adoptWK(WKUInt64Create(index)) }, 1915 { "AxisCount", adoptWK(WKUInt64Create(axisCount)) }, 1916 { "ButtonCount", adoptWK(WKUInt64Create(buttonCount)) }, 1917 })); 2674 1918 } 2675 1919 2676 1920 void TestRunner::setMockGamepadAxisValue(unsigned index, unsigned axisIndex, double value) 2677 1921 { 2678 Vector<WKRetainPtr<WKStringRef>> keys; 2679 Vector<WKRetainPtr<WKTypeRef>> values; 2680 2681 keys.append(adoptWK(WKStringCreateWithUTF8CString("GamepadIndex"))); 2682 values.append(adoptWK(WKUInt64Create(index))); 2683 2684 keys.append(adoptWK(WKStringCreateWithUTF8CString("AxisIndex"))); 2685 values.append(adoptWK(WKUInt64Create(axisIndex))); 2686 2687 keys.append(adoptWK(WKStringCreateWithUTF8CString("Value"))); 2688 values.append(adoptWK(WKDoubleCreate(value))); 2689 2690 Vector<WKStringRef> rawKeys; 2691 Vector<WKTypeRef> rawValues; 2692 rawKeys.resize(keys.size()); 2693 rawValues.resize(values.size()); 2694 2695 for (size_t i = 0; i < keys.size(); ++i) { 2696 rawKeys[i] = keys[i].get(); 2697 rawValues[i] = values[i].get(); 2698 } 2699 2700 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetMockGamepadAxisValue")); 2701 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 2702 2703 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 1922 postSynchronousMessage("SetMockGamepadAxisValue", createWKDictionary({ 1923 { "GamepadIndex", adoptWK(WKUInt64Create(index)) }, 1924 { "AxisIndex", adoptWK(WKUInt64Create(axisIndex)) }, 1925 { "Value", adoptWK(WKDoubleCreate(value)) }, 1926 })); 2704 1927 } 2705 1928 2706 1929 void TestRunner::setMockGamepadButtonValue(unsigned index, unsigned buttonIndex, double value) 2707 1930 { 2708 Vector<WKRetainPtr<WKStringRef>> keys; 2709 Vector<WKRetainPtr<WKTypeRef>> values; 2710 2711 keys.append(adoptWK(WKStringCreateWithUTF8CString("GamepadIndex"))); 2712 values.append(adoptWK(WKUInt64Create(index))); 2713 2714 keys.append(adoptWK(WKStringCreateWithUTF8CString("ButtonIndex"))); 2715 values.append(adoptWK(WKUInt64Create(buttonIndex))); 2716 2717 keys.append(adoptWK(WKStringCreateWithUTF8CString("Value"))); 2718 values.append(adoptWK(WKDoubleCreate(value))); 2719 2720 Vector<WKStringRef> rawKeys; 2721 Vector<WKTypeRef> rawValues; 2722 rawKeys.resize(keys.size()); 2723 rawValues.resize(values.size()); 2724 2725 for (size_t i = 0; i < keys.size(); ++i) { 2726 rawKeys[i] = keys[i].get(); 2727 rawValues[i] = values[i].get(); 2728 } 2729 2730 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetMockGamepadButtonValue")); 2731 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 2732 2733 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 2734 } 1931 postSynchronousMessage("SetMockGamepadButtonValue", createWKDictionary({ 1932 { "GamepadIndex", adoptWK(WKUInt64Create(index)) }, 1933 { "ButtonIndex", adoptWK(WKUInt64Create(buttonIndex)) }, 1934 { "Value", adoptWK(WKDoubleCreate(value)) }, 1935 })); 1936 } 1937 2735 1938 #else 1939 2736 1940 void TestRunner::connectMockGamepad(unsigned) 2737 1941 { … … 2753 1957 { 2754 1958 } 1959 2755 1960 #endif // PLATFORM(MAC) 2756 1961 2757 1962 void TestRunner::setOpenPanelFiles(JSValueRef filesValue) 2758 1963 { 2759 WKBundlePageRef page = InjectedBundle::singleton().page()->page(); 2760 JSContextRef context = WKBundleFrameGetJavaScriptContext(WKBundlePageGetMainFrame(page)); 1964 JSContextRef context = mainFrameJSContext(); 2761 1965 2762 1966 if (!JSValueIsArray(context, filesValue)) 2763 1967 return; 2764 1968 2765 JSObjectRef files = JSValueToObject(context, filesValue, nullptr); 2766 static auto lengthProperty = adopt(JSStringCreateWithUTF8CString("length")); 2767 JSValueRef filesLengthValue = JSObjectGetProperty(context, files, lengthProperty.get(), nullptr); 2768 if (!JSValueIsNumber(context, filesLengthValue)) 2769 return; 2770 1969 auto files = (JSObjectRef)filesValue; 2771 1970 auto fileURLs = adoptWK(WKMutableArrayCreate()); 2772 auto filesLength = static_cast<size_t>(JSValueToNumber(context, filesLengthValue, nullptr));1971 auto filesLength = arrayLength(context, files); 2773 1972 for (size_t i = 0; i < filesLength; ++i) { 2774 1973 JSValueRef fileValue = JSObjectGetPropertyAtIndex(context, files, i, nullptr); … … 2776 1975 continue; 2777 1976 2778 auto file = adopt(JSValueToStringCopy(context, fileValue, nullptr));1977 auto file = createJSString(context, fileValue); 2779 1978 size_t fileBufferSize = JSStringGetMaximumUTF8CStringSize(file.get()) + 1; 2780 1979 auto fileBuffer = makeUniqueArray<char>(fileBufferSize); … … 2790 1989 } 2791 1990 2792 static auto messageName = adoptWK(WKStringCreateWithUTF8CString("SetOpenPanelFileURLs")); 2793 WKBundlePagePostMessage(page, messageName.get(), fileURLs.get()); 1991 postPageMessage("SetOpenPanelFileURLs", fileURLs); 2794 1992 } 2795 1993 … … 2797 1995 { 2798 1996 #if PLATFORM(IOS_FAMILY) 2799 WKBundlePageRef page = InjectedBundle::singleton().page()->page();2800 JSContextRef context = WKBundleFrameGetJavaScriptContext(WKBundlePageGetMainFrame(page));2801 2802 auto& injectedBundle = InjectedBundle::singleton();2803 1997 // FIXME (123058): Use a JSC API to get buffer contents once such is exposed. 2804 WKRetainPtr<WKDataRef> iconData = adoptWK(WKBundleCreateWKDataFromUInt8Array(injectedBundle.bundle(), context, data)); 2805 2806 static auto messageName = adoptWK(WKStringCreateWithUTF8CString("SetOpenPanelFileURLsMediaIcon")); 2807 WKBundlePagePostMessage(page, messageName.get(), iconData.get()); 1998 auto iconData = adoptWK(WKBundleCreateWKDataFromUInt8Array(InjectedBundle::singleton().bundle(), mainFrameJSContext(), data)); 1999 postPageMessage("SetOpenPanelFileURLsMediaIcon", iconData); 2808 2000 #else 2809 2001 UNUSED_PARAM(data); … … 2814 2006 { 2815 2007 cacheTestRunnerCallback(DidRemoveAllSessionCredentialsCallbackID, callback); 2816 2817 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("RemoveAllSessionCredentials")); 2818 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(true)); 2819 2820 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get()); 2008 postMessage("RemoveAllSessionCredentials", true); 2821 2009 } 2822 2010 … … 2828 2016 void TestRunner::clearDOMCache(JSStringRef origin) 2829 2017 { 2830 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ClearDOMCache")); 2831 WKRetainPtr<WKStringRef> messageBody = adoptWK(WKStringCreateWithJSString(origin)); 2832 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 2018 postSynchronousMessage("ClearDOMCache", toWK(origin)); 2833 2019 } 2834 2020 2835 2021 void TestRunner::clearDOMCaches() 2836 2022 { 2837 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ClearDOMCaches")); 2838 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr); 2023 postSynchronousMessage("ClearDOMCaches"); 2839 2024 } 2840 2025 2841 2026 bool TestRunner::hasDOMCache(JSStringRef origin) 2842 2027 { 2843 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("HasDOMCache")); 2844 WKRetainPtr<WKStringRef> messageBody = adoptWK(WKStringCreateWithJSString(origin)); 2845 WKTypeRef returnData = nullptr; 2846 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData); 2847 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 2848 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 2028 return postSynchronousPageMessageReturningBoolean("HasDOMCache", origin); 2849 2029 } 2850 2030 2851 2031 uint64_t TestRunner::domCacheSize(JSStringRef origin) 2852 2032 { 2853 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("DOMCacheSize")); 2854 WKRetainPtr<WKStringRef> messageBody = adoptWK(WKStringCreateWithJSString(origin)); 2855 WKTypeRef returnData = nullptr; 2856 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData); 2857 return WKUInt64GetValue(static_cast<WKUInt64Ref>(returnData)); 2033 return postSynchronousPageMessageReturningUInt64("DOMCacheSize", origin); 2858 2034 } 2859 2035 2860 2036 void TestRunner::setAllowStorageQuotaIncrease(bool willIncrease) 2861 2037 { 2862 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetAllowStorageQuotaIncrease")); 2863 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(willIncrease)); 2864 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 2038 postSynchronousPageMessage("SetAllowStorageQuotaIncrease", willIncrease); 2865 2039 } 2866 2040 … … 2868 2042 { 2869 2043 cacheTestRunnerCallback(GetApplicationManifestCallbackID, callback); 2870 2871 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("GetApplicationManifest")); 2872 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr); 2044 postMessage("GetApplicationManifest"); 2873 2045 } 2874 2046 … … 2890 2062 void TestRunner::injectUserScript(JSStringRef script) 2891 2063 { 2892 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("InjectUserScript")); 2893 WKRetainPtr<WKStringRef> messageBody = adoptWK(WKStringCreateWithJSString(script)); 2894 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), nullptr); 2064 postSynchronousMessage("InjectUserScript", toWK(script)); 2895 2065 } 2896 2066 2897 2067 void TestRunner::sendDisplayConfigurationChangedMessageForTesting() 2898 2068 { 2899 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SendDisplayConfigurationChangedMessageForTesting")); 2900 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr); 2069 postSynchronousMessage("SendDisplayConfigurationChangedMessageForTesting"); 2901 2070 } 2902 2071 2903 2072 void TestRunner::setServiceWorkerFetchTimeout(double seconds) 2904 2073 { 2905 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetServiceWorkerFetchTimeout")); 2906 WKRetainPtr<WKDoubleRef> messageBody = adoptWK(WKDoubleCreate(seconds)); 2907 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 2074 postSynchronousMessage("SetServiceWorkerFetchTimeout", seconds); 2908 2075 } 2909 2076 … … 2911 2078 void TestRunner::addTestKeyToKeychain(JSStringRef privateKeyBase64, JSStringRef attrLabel, JSStringRef applicationTagBase64) 2912 2079 { 2913 Vector<WKRetainPtr<WKStringRef>> keys; 2914 Vector<WKRetainPtr<WKTypeRef>> values; 2915 2916 keys.append(adoptWK(WKStringCreateWithUTF8CString("PrivateKey"))); 2917 values.append(toWK(privateKeyBase64)); 2918 2919 keys.append(adoptWK(WKStringCreateWithUTF8CString("AttrLabel"))); 2920 values.append(toWK(attrLabel)); 2921 2922 keys.append(adoptWK(WKStringCreateWithUTF8CString("ApplicationTag"))); 2923 values.append(toWK(applicationTagBase64)); 2924 2925 Vector<WKStringRef> rawKeys; 2926 Vector<WKTypeRef> rawValues; 2927 rawKeys.resize(keys.size()); 2928 rawValues.resize(values.size()); 2929 2930 for (size_t i = 0; i < keys.size(); ++i) { 2931 rawKeys[i] = keys[i].get(); 2932 rawValues[i] = values[i].get(); 2080 postSynchronousMessage("AddTestKeyToKeychain", createWKDictionary({ 2081 { "PrivateKey", toWK(privateKeyBase64) }, 2082 { "AttrLabel", toWK(attrLabel) }, 2083 { "ApplicationTag", toWK(applicationTagBase64) }, 2084 })); 2085 } 2086 2087 void TestRunner::cleanUpKeychain(JSStringRef attrLabel, JSStringRef applicationLabelBase64) 2088 { 2089 if (!applicationLabelBase64) { 2090 postSynchronousMessage("CleanUpKeychain", createWKDictionary({ 2091 { "AttrLabel", toWK(attrLabel) }, 2092 })); 2093 return; 2933 2094 } 2934 2935 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("AddTestKeyToKeychain")); 2936 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 2937 2938 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 2939 } 2940 2941 void TestRunner::cleanUpKeychain(JSStringRef attrLabel, JSStringRef applicationLabelBase64) 2942 { 2943 Vector<WKRetainPtr<WKStringRef>> keys; 2944 Vector<WKRetainPtr<WKTypeRef>> values; 2945 2946 keys.append(adoptWK(WKStringCreateWithUTF8CString("AttrLabel"))); 2947 values.append(toWK(attrLabel)); 2948 2949 if (applicationLabelBase64) { 2950 keys.append(adoptWK(WKStringCreateWithUTF8CString("ApplicationLabel"))); 2951 values.append(toWK(applicationLabelBase64)); 2952 } 2953 2954 Vector<WKStringRef> rawKeys; 2955 Vector<WKTypeRef> rawValues; 2956 rawKeys.resize(keys.size()); 2957 rawValues.resize(values.size()); 2958 2959 for (size_t i = 0; i < keys.size(); ++i) { 2960 rawKeys[i] = keys[i].get(); 2961 rawValues[i] = values[i].get(); 2962 } 2963 2964 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CleanUpKeychain")); 2965 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 2966 2967 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 2095 postSynchronousMessage("CleanUpKeychain", createWKDictionary({ 2096 { "AttrLabel", toWK(attrLabel) }, 2097 { "ApplicationLabel", toWK(applicationLabelBase64) }, 2098 })); 2968 2099 } 2969 2100 2970 2101 bool TestRunner::keyExistsInKeychain(JSStringRef attrLabel, JSStringRef applicationLabelBase64) 2971 2102 { 2972 Vector<WKRetainPtr<WKStringRef>> keys; 2973 Vector<WKRetainPtr<WKTypeRef>> values; 2974 2975 keys.append(adoptWK(WKStringCreateWithUTF8CString("AttrLabel"))); 2976 values.append(toWK(attrLabel)); 2977 2978 keys.append(adoptWK(WKStringCreateWithUTF8CString("ApplicationLabel"))); 2979 values.append(toWK(applicationLabelBase64)); 2980 2981 Vector<WKStringRef> rawKeys; 2982 Vector<WKTypeRef> rawValues; 2983 rawKeys.resize(keys.size()); 2984 rawValues.resize(values.size()); 2985 2986 for (size_t i = 0; i < keys.size(); ++i) { 2987 rawKeys[i] = keys[i].get(); 2988 rawValues[i] = values[i].get(); 2989 } 2990 2991 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("KeyExistsInKeychain")); 2992 WKRetainPtr<WKDictionaryRef> messageBody = adoptWK(WKDictionaryCreate(rawKeys.data(), rawValues.data(), rawKeys.size())); 2993 2994 WKTypeRef returnData = nullptr; 2995 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), &returnData); 2996 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 2997 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 2103 return postSynchronousMessageReturningBoolean("KeyExistsInKeychain", createWKDictionary({ 2104 { "AttrLabel", toWK(attrLabel) }, 2105 { "ApplicationLabel", toWK(applicationLabelBase64) }, 2106 })); 2998 2107 } 2999 2108 3000 2109 unsigned long TestRunner::serverTrustEvaluationCallbackCallsCount() 3001 2110 { 3002 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ServerTrustEvaluationCallbackCallsCount")); 3003 WKTypeRef returnData = nullptr; 3004 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, &returnData); 3005 ASSERT(WKGetTypeID(returnData) == WKUInt64GetTypeID()); 3006 return WKUInt64GetValue(adoptWK(static_cast<WKUInt64Ref>(returnData)).get()); 2111 return postSynchronousMessageReturningUInt64("ServerTrustEvaluationCallbackCallsCount"); 3007 2112 } 3008 2113 3009 2114 void TestRunner::setShouldDismissJavaScriptAlertsAsynchronously(bool shouldDismissAsynchronously) 3010 2115 { 3011 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ShouldDismissJavaScriptAlertsAsynchronously")); 3012 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(shouldDismissAsynchronously)); 3013 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr); 2116 postSynchronousMessage("ShouldDismissJavaScriptAlertsAsynchronously", shouldDismissAsynchronously); 3014 2117 } 3015 2118 3016 2119 void TestRunner::abortModal() 3017 2120 { 3018 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("AbortModal")); 3019 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr); 2121 postSynchronousMessage("AbortModal"); 3020 2122 } 3021 2123 3022 2124 void TestRunner::dumpAdClickAttribution() 3023 2125 { 3024 auto messageName = adoptWK(WKStringCreateWithUTF8CString("DumpAdClickAttribution")); 3025 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, nullptr); 2126 postSynchronousPageMessage("DumpAdClickAttribution"); 3026 2127 } 3027 2128 3028 2129 void TestRunner::clearAdClickAttribution() 3029 2130 { 3030 auto messageName = adoptWK(WKStringCreateWithUTF8CString("ClearAdClickAttribution")); 3031 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, nullptr); 2131 postSynchronousPageMessage("ClearAdClickAttribution"); 3032 2132 } 3033 2133 3034 2134 void TestRunner::clearAdClickAttributionsThroughWebsiteDataRemoval() 3035 2135 { 3036 auto messageName = adoptWK(WKStringCreateWithUTF8CString("ClearAdClickAttributionsThroughWebsiteDataRemoval")); 3037 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr); 2136 postSynchronousMessage("ClearAdClickAttributionsThroughWebsiteDataRemoval"); 3038 2137 } 3039 2138 3040 2139 void TestRunner::setAdClickAttributionOverrideTimerForTesting(bool value) 3041 2140 { 3042 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetAdClickAttributionOverrideTimerForTesting")); 3043 WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value)); 3044 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), nullptr); 2141 postSynchronousPageMessage("SetAdClickAttributionOverrideTimerForTesting", value); 3045 2142 } 3046 2143 3047 2144 void TestRunner::setAdClickAttributionConversionURLForTesting(JSStringRef urlString) 3048 2145 { 3049 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetAdClickAttributionConversionURLForTesting")); 3050 auto wtfURLString = toWTFString(WKStringCreateWithJSString(urlString)); 3051 WKRetainPtr<WKURLRef> messageBody = adoptWK(WKURLCreateWithUTF8CString(wtfURLString.utf8().data())); 3052 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), nullptr); 2146 postSynchronousPageMessage("SetAdClickAttributionConversionURLForTesting", 2147 adoptWK(WKURLCreateWithUTF8CString(toWTFString(urlString).utf8().data()))); 3053 2148 } 3054 2149 3055 2150 void TestRunner::markAdClickAttributionsAsExpiredForTesting() 3056 2151 { 3057 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("MarkAdClickAttributionsAsExpiredForTesting")); 3058 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, nullptr); 2152 postSynchronousPageMessage("MarkAdClickAttributionsAsExpiredForTesting"); 3059 2153 } 3060 2154 3061 2155 void TestRunner::setOffscreenCanvasEnabled(bool enabled) 3062 2156 { 3063 WKRetainPtr<WKStringRef> key = adoptWK(WKStringCreateWithUTF8CString("OffscreenCanvasEnabled")); 3064 auto& injectedBundle = InjectedBundle::singleton(); 3065 WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled); 2157 WTR::overridePreference("OffscreenCanvasEnabled", enabled); 3066 2158 } 3067 2159 3068 2160 bool TestRunner::hasAppBoundSession() 3069 2161 { 3070 auto messageName = adoptWK(WKStringCreateWithUTF8CString("HasAppBoundSession")); 3071 WKTypeRef returnData = nullptr; 3072 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, &returnData); 3073 ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID()); 3074 3075 return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get()); 2162 return postSynchronousPageMessageReturningBoolean("HasAppBoundSession"); 3076 2163 } 3077 2164 3078 2165 void TestRunner::clearAppBoundSession() 3079 2166 { 3080 auto messageName = adoptWK(WKStringCreateWithUTF8CString("ClearAppBoundSession")); 3081 WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr); 2167 postSynchronousMessage("ClearAppBoundSession"); 3082 2168 } 3083 2169 … … 3086 2172 cacheTestRunnerCallback(DidSetAppBoundDomainsCallbackID, completionHandler); 3087 2173 3088 JSContextRef context = WKBundleFrameGetJavaScriptContext(WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page())); 3089 2174 auto context = mainFrameJSContext(); 3090 2175 if (!JSValueIsArray(context, originArray)) 3091 2176 return; 3092 2177 3093 JSObjectRef origins = JSValueToObject(context, originArray, nullptr); 3094 static auto lengthProperty = adopt(JSStringCreateWithUTF8CString("length")); 3095 JSValueRef originsLengthValue = JSObjectGetProperty(context, origins, lengthProperty.get(), nullptr); 3096 if (!JSValueIsNumber(context, originsLengthValue)) 3097 return; 3098 2178 auto origins = JSValueToObject(context, originArray, nullptr); 3099 2179 auto originURLs = adoptWK(WKMutableArrayCreate()); 3100 auto originsLength = static_cast<size_t>(JSValueToNumber(context, originsLengthValue, nullptr));3101 for ( size_ti = 0; i < originsLength; ++i) {2180 auto originsLength = arrayLength(context, origins); 2181 for (unsigned i = 0; i < originsLength; ++i) { 3102 2182 JSValueRef originValue = JSObjectGetPropertyAtIndex(context, origins, i, nullptr); 3103 2183 if (!JSValueIsString(context, originValue)) 3104 2184 continue; 3105 2185 3106 auto origin = adopt(JSValueToStringCopy(context, originValue, nullptr));2186 auto origin = createJSString(context, originValue); 3107 2187 size_t originBufferSize = JSStringGetMaximumUTF8CStringSize(origin.get()) + 1; 3108 2188 auto originBuffer = makeUniqueArray<char>(originBufferSize); … … 3112 2192 } 3113 2193 3114 auto messageName = adoptWK(WKStringCreateWithUTF8CString("SetAppBoundDomains"));2194 auto messageName = toWK("SetAppBoundDomains"); 3115 2195 WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), originURLs.get()); 3116 2196 } -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h ¶
r267750 r267761 47 47 virtual JSClassRef wrapperClass(); 48 48 49 void makeWindowObject(JSContextRef , JSObjectRef windowObject, JSValueRef* exception);49 void makeWindowObject(JSContextRef); 50 50 51 51 bool isIOSFamily() const … … 254 254 bool willSendRequestReturnsNullOnRedirect() const { return m_willSendRequestReturnsNullOnRedirect; } 255 255 void setWillSendRequestReturnsNullOnRedirect(bool f) { m_willSendRequestReturnsNullOnRedirect = f; } 256 void setWillSendRequestAddsHTTPBody(JSStringRef body) { m_willSendRequestHTTPBody = toWTFString( toWK(body)); }256 void setWillSendRequestAddsHTTPBody(JSStringRef body) { m_willSendRequestHTTPBody = toWTFString(body); } 257 257 String willSendRequestHTTPBody() const { return m_willSendRequestHTTPBody; } 258 258 … … 287 287 void callSetBackingScaleFactorCallback(); 288 288 289 void overridePreference(JSStringRef preference, JSStringRef value);289 static void overridePreference(JSStringRef preference, JSStringRef value); 290 290 291 291 // Cookies testing … … 305 305 // Geolocation. 306 306 void setGeolocationPermission(bool); 307 void setMockGeolocationPosition(double latitude, double longitude, double accuracy, JSValueRef altitude, JSValueRef altitudeAccuracy, JSValueRef heading, JSValueRef speed, JSValueReffloorLevel);307 void setMockGeolocationPosition(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitudeAccuracy, Optional<double> heading, Optional<double> speed, Optional<double> floorLevel); 308 308 void setMockGeolocationPositionUnavailableError(JSStringRef message); 309 309 bool isGeolocationProviderActive(); … … 336 336 337 337 JSValueRef failNextNewCodeBlock(); 338 JSValueRef numberOfDFGCompiles(JSValueRef theFunction);339 JSValueRef neverInlineFunction(JSValueRef theFunction);338 JSValueRef numberOfDFGCompiles(JSValueRef function); 339 JSValueRef neverInlineFunction(JSValueRef function); 340 340 341 341 bool shouldDecideNavigationPolicyAfterDelay() const { return m_shouldDecideNavigationPolicyAfterDelay; } -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/TextInputController.cpp ¶
r255532 r267761 27 27 #include "TextInputController.h" 28 28 29 #include "DictionaryFunctions.h" 29 30 #include "InjectedBundle.h" 30 31 #include "InjectedBundlePage.h" … … 41 42 } 42 43 43 TextInputController::TextInputController()44 {45 }46 47 TextInputController::~TextInputController()48 {49 }50 51 44 JSClassRef TextInputController::wrapperClass() 52 45 { … … 54 47 } 55 48 56 void TextInputController::makeWindowObject(JSContextRef context , JSObjectRef windowObject, JSValueRef* exception)49 void TextInputController::makeWindowObject(JSContextRef context) 57 50 { 58 setProperty(context, windowObject, "textInputController", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception); 59 } 60 61 static unsigned arrayLength(JSContextRef context, JSObjectRef array) 62 { 63 auto lengthString = adopt(JSStringCreateWithUTF8CString("length")); 64 if (auto lengthValue = JSObjectGetProperty(context, array, lengthString.get(), nullptr)) 65 return static_cast<unsigned>(JSValueToNumber(context, lengthValue, nullptr)); 66 return 0; 51 setGlobalObjectProperty(context, "textInputController", this); 67 52 } 68 53 … … 73 58 74 59 auto result = WKMutableArrayCreate(); 75 auto jsHighlightsArray = const_cast<JSObjectRef>(jsHighlightsValue); 76 unsigned length = arrayLength(context, jsHighlightsArray); 77 if (!length) 78 return result; 79 80 auto jsFromKey = adopt(JSStringCreateWithUTF8CString("from")); 81 auto jsLengthKey = adopt(JSStringCreateWithUTF8CString("length")); 82 auto jsColorKey = adopt(JSStringCreateWithUTF8CString("color")); 83 84 auto wkFromKey = adoptWK(WKStringCreateWithUTF8CString("from")); 85 auto wkLengthKey = adoptWK(WKStringCreateWithUTF8CString("length")); 86 auto wkColorKey = adoptWK(WKStringCreateWithUTF8CString("color")); 87 88 for (size_t i = 0; i < length; ++i) { 89 JSValueRef exception = nullptr; 90 auto jsObjectValue = JSObjectGetPropertyAtIndex(context, jsHighlightsArray, i, &exception); 91 if (exception || !JSValueIsObject(context, jsObjectValue)) 60 auto array = const_cast<JSObjectRef>(jsHighlightsValue); 61 unsigned length = arrayLength(context, array); 62 for (unsigned i = 0; i < length; ++i) { 63 auto value = JSObjectGetPropertyAtIndex(context, array, i, nullptr); 64 if (!value || !JSValueIsObject(context, value)) 92 65 continue; 93 94 auto jsObject = const_cast<JSObjectRef>(jsObjectValue); 95 auto jsFromValue = JSObjectGetProperty(context, jsObject, jsFromKey.get(), nullptr); 96 if (!jsFromValue || !JSValueIsNumber(context, jsFromValue)) 97 continue; 98 99 auto jsLengthValue = JSObjectGetProperty(context, jsObject, jsLengthKey.get(), nullptr); 100 if (!jsLengthValue || !JSValueIsNumber(context, jsLengthValue)) 101 continue; 102 103 auto jsColorValue = JSObjectGetProperty(context, jsObject, jsColorKey.get(), nullptr); 104 if (!jsColorValue || !JSValueIsString(context, jsColorValue)) 105 continue; 106 107 auto color = adopt(JSValueToStringCopy(context, jsColorValue, nullptr)); 108 auto wkColor = adoptWK(WKStringCreateWithJSString(color.get())); 109 auto wkFrom = adoptWK(WKUInt64Create(lround(JSValueToNumber(context, jsFromValue, nullptr)))); 110 auto wkLength = adoptWK(WKUInt64Create(lround(JSValueToNumber(context, jsLengthValue, nullptr)))); 111 66 auto object = const_cast<JSObjectRef>(value); 112 67 auto dictionary = adoptWK(WKMutableDictionaryCreate()); 113 WKDictionarySetItem(dictionary.get(), wkFromKey.get(), wkFrom.get());114 WKDictionarySetItem(dictionary.get(), wkLengthKey.get(), wkLength.get());115 WKDictionarySetItem(dictionary.get(), wkColorKey.get(), wkColor.get());68 setValue(dictionary, "from", static_cast<uint64_t>(numericProperty(context, object, "from"))); 69 setValue(dictionary, "length", static_cast<uint64_t>(numericProperty(context, object, "length"))); 70 setValue(dictionary, "color", toWK(stringProperty(context, object, "color"))); 116 71 WKArrayAppendItem(result, dictionary.get()); 117 72 } 118 119 73 return result; 120 74 } -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/TextInputController.h ¶
r255532 r267761 29 29 #include <wtf/Ref.h> 30 30 31 typedef const struct OpaqueJSContext* JSContextRef; 32 typedef struct OpaqueJSString* JSStringRef; 33 typedef const struct OpaqueJSValue* JSValueRef; 34 31 35 namespace WTR { 32 36 33 class TextInputController : public JSWrappable {37 class TextInputController final : public JSWrappable { 34 38 public: 35 39 static Ref<TextInputController> create(); 36 virtual ~TextInputController();37 40 38 // JSWrappable 39 virtual JSClassRef wrapperClass(); 40 41 void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception); 41 void makeWindowObject(JSContextRef); 42 42 43 43 void setMarkedText(JSStringRef text, int from, int length, bool suppressUnderline, JSValueRef highlights); … … 47 47 48 48 private: 49 TextInputController(); 49 TextInputController() = default; 50 51 JSClassRef wrapperClass() final; 50 52 }; 51 53 -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/cocoa/ActivateFontsCocoa.mm ¶
r261153 r267761 137 137 void installFakeHelvetica(WKStringRef configuration) 138 138 { 139 RetainPtr<CFStringRef>configurationString = adoptCF(WKStringCopyCFString(kCFAllocatorDefault, configuration));139 auto configurationString = adoptCF(WKStringCopyCFString(kCFAllocatorDefault, configuration)); 140 140 NSURL *resourceURL = [resourcesDirectoryURL() URLByAppendingPathComponent:[NSString stringWithFormat:@"FakeHelvetica-%@.ttf", configurationString.get()] isDirectory:NO]; 141 141 CFErrorRef error = nullptr; -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/cocoa/InjectedBundlePageCocoa.mm ¶
r240641 r267761 48 48 String InjectedBundlePage::platformResponseMimeType(WKURLResponseRef response) 49 49 { 50 RetainPtr<NSURLResponse>nsURLResponse = adoptNS(WKURLResponseCopyNSURLResponse(response));50 auto nsURLResponse = adoptNS(WKURLResponseCopyNSURLResponse(response)); 51 51 return [nsURLResponse.get() MIMEType]; 52 52 } … … 54 54 uint64_t InjectedBundlePage::responseHeaderCount(WKURLResponseRef response) 55 55 { 56 RetainPtr<NSURLResponse>nsURLResponse = adoptNS(WKURLResponseCopyNSURLResponse(response));56 auto nsURLResponse = adoptNS(WKURLResponseCopyNSURLResponse(response)); 57 57 if (![nsURLResponse isKindOfClass:[NSHTTPURLResponse class]]) 58 58 return { }; -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityControllerIOS.mm ¶
r236032 r267761 63 63 JSRetainPtr<JSStringRef> AccessibilityController::platformName() 64 64 { 65 return adopt(JSStringCreateWithUTF8CString("ios"));65 return WTR::createJSString("ios"); 66 66 } 67 67 … … 90 90 RefPtr<AccessibilityUIElement> AccessibilityController::accessibleElementById(JSStringRef idAttribute) 91 91 { 92 WKBundlePageRefpage = InjectedBundle::singleton().page()->page();92 auto page = InjectedBundle::singleton().page()->page(); 93 93 id root = static_cast<PlatformUIElement>(WKAccessibilityRootObject(page)); 94 94 -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm ¶
r264235 r267761 137 137 namespace WTR { 138 138 139 static JSRetainPtr<JSStringRef> createEmptyJSString()140 {141 return adopt(JSStringCreateWithCharacters(nullptr, 0));142 }143 144 139 static JSRetainPtr<JSStringRef> concatenateAttributeAndValue(NSString *attribute, NSString *value) 145 140 { … … 331 326 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfLinkedUIElements() 332 327 { 333 return create EmptyJSString();328 return createJSString(); 334 329 } 335 330 336 331 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfDocumentLinks() 337 332 { 338 return create EmptyJSString();333 return createJSString(); 339 334 } 340 335 341 336 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfChildren() 342 337 { 343 return create EmptyJSString();338 return createJSString(); 344 339 } 345 340 346 341 JSRetainPtr<JSStringRef> AccessibilityUIElement::allAttributes() 347 342 { 348 return create EmptyJSString();343 return createJSString(); 349 344 } 350 345 351 346 JSRetainPtr<JSStringRef> AccessibilityUIElement::stringDescriptionOfAttributeValue(JSStringRef attribute) 352 347 { 353 return create EmptyJSString();348 return createJSString(); 354 349 } 355 350 … … 383 378 return [[m_element accessibilityTextualContext] createJSStringRef]; 384 379 385 return create EmptyJSString();380 return createJSString(); 386 381 } 387 382 … … 444 439 JSRetainPtr<JSStringRef> AccessibilityUIElement::parameterizedAttributeNames() 445 440 { 446 return create EmptyJSString();441 return createJSString(); 447 442 } 448 443 449 444 JSRetainPtr<JSStringRef> AccessibilityUIElement::role() 450 445 { 451 return create EmptyJSString();446 return createJSString(); 452 447 } 453 448 454 449 JSRetainPtr<JSStringRef> AccessibilityUIElement::subrole() 455 450 { 456 return create EmptyJSString();451 return createJSString(); 457 452 } 458 453 … … 464 459 JSRetainPtr<JSStringRef> AccessibilityUIElement::computedRoleString() 465 460 { 466 // FIXME: implement 467 return createEmptyJSString(); 461 return createJSString(); 468 462 } 469 463 470 464 JSRetainPtr<JSStringRef> AccessibilityUIElement::title() 471 465 { 472 return create EmptyJSString();466 return createJSString(); 473 467 } 474 468 … … 480 474 JSRetainPtr<JSStringRef> AccessibilityUIElement::orientation() const 481 475 { 482 return create EmptyJSString();476 return createJSString(); 483 477 } 484 478 … … 490 484 JSRetainPtr<JSStringRef> AccessibilityUIElement::language() 491 485 { 492 return create EmptyJSString();486 return createJSString(); 493 487 } 494 488 … … 550 544 JSRetainPtr<JSStringRef> AccessibilityUIElement::valueDescription() 551 545 { 552 return create EmptyJSString();546 return createJSString(); 553 547 } 554 548 … … 585 579 bool AccessibilityUIElement::isFocused() const 586 580 { 587 // FIXME: implement588 581 return false; 589 582 } … … 597 590 bool AccessibilityUIElement::isSelectedOptionActive() const 598 591 { 599 // FIXME: implement600 592 return false; 601 593 } … … 603 595 bool AccessibilityUIElement::isIndeterminate() const 604 596 { 605 // FIXME: implement606 597 return false; 607 598 } … … 639 630 JSRetainPtr<JSStringRef> AccessibilityUIElement::ariaDropEffects() const 640 631 { 641 return create EmptyJSString();632 return createJSString(); 642 633 } 643 634 … … 660 651 JSRetainPtr<JSStringRef> AccessibilityUIElement::boundsForRange(unsigned location, unsigned length) 661 652 { 662 return create EmptyJSString();653 return createJSString(); 663 654 } 664 655 … … 714 705 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfColumnHeaders() 715 706 { 716 return create EmptyJSString();707 return createJSString(); 717 708 } 718 709 719 710 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfRowHeaders() 720 711 { 721 return create EmptyJSString();712 return createJSString(); 722 713 } 723 714 724 715 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfColumns() 725 716 { 726 return create EmptyJSString();717 return createJSString(); 727 718 } 728 719 729 720 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfRows() 730 721 { 731 return create EmptyJSString();722 return createJSString(); 732 723 } 733 724 734 725 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfVisibleCells() 735 726 { 736 return create EmptyJSString();727 return createJSString(); 737 728 } 738 729 739 730 JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfHeader() 740 731 { 741 return create EmptyJSString();732 return createJSString(); 742 733 } 743 734 … … 904 895 void AccessibilityUIElement::clearSelectedChildren() const 905 896 { 906 // FIXME: implement907 897 } 908 898 909 899 JSRetainPtr<JSStringRef> AccessibilityUIElement::accessibilityValue() const 910 900 { 911 // FIXME: implement 912 return createEmptyJSString(); 901 return createJSString(); 913 902 } 914 903 915 904 JSRetainPtr<JSStringRef> AccessibilityUIElement::documentEncoding() 916 905 { 917 return create EmptyJSString();906 return createJSString(); 918 907 } 919 908 920 909 JSRetainPtr<JSStringRef> AccessibilityUIElement::documentURI() 921 910 { 922 return create EmptyJSString();911 return createJSString(); 923 912 } 924 913 … … 1017 1006 bool AccessibilityUIElement::isSelectable() const 1018 1007 { 1019 // FIXME: implement1020 1008 return false; 1021 1009 } … … 1023 1011 bool AccessibilityUIElement::isMultiSelectable() const 1024 1012 { 1025 // FIXME: implement1026 1013 return false; 1027 1014 } … … 1029 1016 bool AccessibilityUIElement::isVisible() const 1030 1017 { 1031 // FIXME: implement1032 1018 return false; 1033 1019 } … … 1035 1021 bool AccessibilityUIElement::isOffScreen() const 1036 1022 { 1037 // FIXME: implement1038 1023 return false; 1039 1024 } … … 1041 1026 bool AccessibilityUIElement::isCollapsed() const 1042 1027 { 1043 // FIXME: implement1044 1028 return false; 1045 1029 } … … 1053 1037 bool AccessibilityUIElement::isSingleLine() const 1054 1038 { 1055 // FIXME: implement1056 1039 return false; 1057 1040 } … … 1059 1042 bool AccessibilityUIElement::isMultiLine() const 1060 1043 { 1061 // FIXME: implement1062 1044 return false; 1063 1045 } … … 1075 1057 void AccessibilityUIElement::takeFocus() 1076 1058 { 1077 // FIXME: implement1078 1059 } 1079 1060 1080 1061 void AccessibilityUIElement::takeSelection() 1081 1062 { 1082 // FIXME: implement1083 1063 } 1084 1064 1085 1065 void AccessibilityUIElement::addSelection() 1086 1066 { 1087 // FIXME: implement1088 1067 } 1089 1068 1090 1069 void AccessibilityUIElement::removeSelection() 1091 1070 { 1092 // FIXME: implement1093 1071 } 1094 1072 … … 1137 1115 id textMarkers = markerRange->platformTextMarkerRange(); 1138 1116 if (![textMarkers isKindOfClass:[NSArray class]]) 1139 return create EmptyJSString();1117 return createJSString(); 1140 1118 return [[m_element stringForTextMarkers:textMarkers] createJSStringRef]; 1141 1119 } -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm ¶
r214586 r267761 37 37 EventSenderProxy::EventSenderProxy(TestController* testController) 38 38 : m_testController(testController) 39 , m_time(0)40 , m_position()41 , m_leftMouseButtonDown(false)42 , m_clickCount(0)43 , m_clickTime(0)44 , m_clickPosition()45 , m_clickButton(kWKEventMouseButtonNoButton)46 , eventNumber(0)47 39 { 48 40 UNUSED_PARAM(m_testController); … … 51 43 } 52 44 53 EventSenderProxy::~EventSenderProxy() 54 { 55 } 45 EventSenderProxy::~EventSenderProxy() = default; 56 46 57 47 void EventSenderProxy::updateClickCountForButton(int button) … … 71 61 void EventSenderProxy::mouseDown(unsigned buttonNumber, WKEventModifiers modifiers) 72 62 { 73 // Write me.74 63 } 75 64 76 65 void EventSenderProxy::mouseUp(unsigned buttonNumber, WKEventModifiers modifiers) 77 66 { 78 // Write me.79 67 } 80 68 81 69 void EventSenderProxy::mouseMoveTo(double x, double y) 82 70 { 83 // Write me.84 71 } 85 72 … … 91 78 void EventSenderProxy::keyDown(WKStringRef key, WKEventModifiers modifiers, unsigned keyLocation) 92 79 { 93 // Write me.94 80 } 95 81 96 82 void EventSenderProxy::mouseScrollBy(int x, int y) 97 83 { 98 // Write me.99 84 } 100 85 101 86 void EventSenderProxy::mouseScrollByWithWheelAndMomentumPhases(int x, int y, int phase, int momentum) 102 87 { 103 // Write me.104 88 } 105 89 106 90 void EventSenderProxy::continuousMouseScrollBy(int x, int y, bool paged) 107 91 { 108 // Write me.109 92 } 110 93 111 94 #if ENABLE(TOUCH_EVENTS) 95 112 96 void EventSenderProxy::addTouchPoint(int x, int y) 113 97 { 114 // Write me.115 98 } 116 99 117 100 void EventSenderProxy::updateTouchPoint(int index, int x, int y) 118 101 { 119 // Write me.120 102 } 121 103 122 104 void EventSenderProxy::setTouchModifier(WKEventModifiers, bool enable) 123 105 { 124 // Write me.125 106 } 126 107 127 108 void EventSenderProxy::setTouchPointRadius(int radiusX, int radiusY) 128 109 { 129 // Write me.130 110 } 131 111 132 112 void EventSenderProxy::touchStart() 133 113 { 134 // Write me.135 114 } 136 115 137 116 void EventSenderProxy::touchMove() 138 117 { 139 // Write me.140 118 } 141 119 142 120 void EventSenderProxy::touchEnd() 143 121 { 144 // Write me.145 122 } 146 123 147 124 void EventSenderProxy::touchCancel() 148 125 { 149 // Write me.150 126 } 151 127 152 128 void EventSenderProxy::clearTouchPoints() 153 129 { 154 // Write me.155 130 } 156 131 157 132 void EventSenderProxy::releaseTouchPoint(int index) 158 133 { 159 // Write me.160 134 } 161 135 162 136 void EventSenderProxy::cancelTouchPoint(int index) 163 137 { 164 // Write me.165 138 } 139 166 140 #endif 167 141 -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityCommonMac.mm ¶
r262244 r267761 33 33 34 34 #import "JSWrapper.h" 35 #import "StringFunctions.h" 35 36 #import <JavaScriptCore/JSStringRefCF.h> 36 37 #import <objc/runtime.h> … … 62 63 } 63 64 64 static JS ValueRef makeArrayRefForArray(JSContextRef context, NSArray *array)65 static JSObjectRef makeJSArray(JSContextRef context, NSArray *array) 65 66 { 66 67 NSUInteger count = array.count; 67 68 JSValueRef arguments[count]; 68 69 69 for (NSUInteger i = 0; i < count; i++) 70 70 arguments[i] = makeValueRefForValue(context, [array objectAtIndex:i]); 71 72 71 return JSObjectMakeArray(context, count, arguments, nullptr); 73 72 } 74 73 75 static JS ValueRef makeObjectRefForDictionary(JSContextRef context, NSDictionary *dictionary)74 static JSObjectRef makeJSObject(JSContextRef context, NSDictionary *dictionary) 76 75 { 77 JSObjectRef object = JSObjectMake(context, nullptr, nullptr); 78 76 auto object = JSObjectMake(context, nullptr, nullptr); 79 77 [dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *) { 80 78 if (JSValueRef propertyValue = makeValueRefForValue(context, obj)) 81 79 JSObjectSetProperty(context, object, [key createJSStringRef].get(), propertyValue, kJSPropertyAttributeNone, nullptr); 82 80 }]; 83 84 81 return object; 85 82 } … … 97 94 return toJS(context, WTR::AccessibilityUIElement::create(static_cast<PlatformUIElement>(value)).ptr()); 98 95 if ([value isKindOfClass:[NSDictionary class]]) 99 return make ObjectRefForDictionary(context, value);96 return makeJSObject(context, value); 100 97 if ([value isKindOfClass:[NSArray class]]) 101 return make ArrayRefForArray(context, value);98 return makeJSArray(context, value); 102 99 return nullptr; 103 100 } … … 116 113 if (searchKey) { 117 114 id searchKeyParameter = nil; 118 if (JSValueIsString(context, searchKey)) { 119 auto searchKeyString = adopt(JSValueToStringCopy(context, searchKey, nullptr)); 120 if (searchKeyString) 121 searchKeyParameter = [NSString stringWithJSStringRef:searchKeyString.get()]; 122 } else if (JSValueIsObject(context, searchKey)) { 115 if (JSValueIsString(context, searchKey)) 116 searchKeyParameter = toWTFString(context, searchKey); 117 else if (JSValueIsObject(context, searchKey)) { 123 118 JSObjectRef searchKeyArray = JSValueToObject(context, searchKey, nullptr); 124 unsigned searchKeyArrayLength = 0; 125 126 auto lengthPropertyString = adopt(JSStringCreateWithUTF8CString("length")); 127 JSValueRef searchKeyArrayLengthValue = JSObjectGetProperty(context, searchKeyArray, lengthPropertyString.get(), nullptr); 128 if (searchKeyArrayLengthValue && JSValueIsNumber(context, searchKeyArrayLengthValue)) 129 searchKeyArrayLength = static_cast<unsigned>(JSValueToNumber(context, searchKeyArrayLengthValue, nullptr)); 130 119 unsigned searchKeyArrayLength = arrayLength(context, searchKeyArray); 131 120 for (unsigned i = 0; i < searchKeyArrayLength; ++i) { 132 JSValueRef searchKeyValue = JSObjectGetPropertyAtIndex(context, searchKeyArray, i, nullptr); 133 JSStringRef searchKeyString = JSValueToStringCopy(context, searchKeyValue, nullptr); 134 if (searchKeyString) { 135 if (!searchKeyParameter) 136 searchKeyParameter = [NSMutableArray array]; 137 [searchKeyParameter addObject:[NSString stringWithJSStringRef:searchKeyString]]; 138 JSStringRelease(searchKeyString); 139 } 121 auto searchKey = toWTFString(context, JSObjectGetPropertyAtIndex(context, searchKeyArray, i, nullptr)); 122 if (!searchKeyParameter) 123 searchKeyParameter = [NSMutableArray array]; 124 [searchKeyParameter addObject:searchKey]; 140 125 } 141 126 } … … 145 130 146 131 if (searchText && JSStringGetLength(searchText)) 147 [parameterizedAttribute setObject: [NSString stringWithJSStringRef:searchText]forKey:@"AXSearchText"];132 [parameterizedAttribute setObject:toWTFString(searchText) forKey:@"AXSearchText"]; 148 133 149 134 [parameterizedAttribute setObject:@(visibleOnly) forKey:@"AXVisibleOnly"]; 150 151 135 [parameterizedAttribute setObject:@(immediateDescendantsOnly) forKey:@"AXImmediateDescendantsOnly"]; 152 136 -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm ¶
r261081 r267761 36 36 #import "InjectedBundle.h" 37 37 #import "InjectedBundlePage.h" 38 #import "JSBasics.h" 38 39 #import <JavaScriptCore/JSStringRefCF.h> 39 40 #import <WebKit/WKBundle.h> … … 97 98 RefPtr<AccessibilityUIElement> AccessibilityController::accessibleElementById(JSStringRef idAttribute) 98 99 { 99 WKBundlePageRefpage = InjectedBundle::singleton().page()->page();100 auto page = InjectedBundle::singleton().page()->page(); 100 101 PlatformUIElement root = static_cast<PlatformUIElement>(WKAccessibilityRootObject(page)); 101 102 … … 112 113 JSRetainPtr<JSStringRef> AccessibilityController::platformName() 113 114 { 114 return adopt(JSStringCreateWithUTF8CString("mac"));115 return WTR::createJSString("mac"); 115 116 } 116 117 -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm ¶
r265259 r267761 33 33 #import "InjectedBundle.h" 34 34 #import "InjectedBundlePage.h" 35 35 #import "JSBasics.h" 36 36 #import <AppKit/NSAccessibility.h> 37 37 #import <Foundation/Foundation.h> … … 87 87 88 88 namespace WTR { 89 90 static JSRetainPtr<JSStringRef> createEmptyJSString()91 {92 return adopt(JSStringCreateWithCharacters(nullptr, 0));93 }94 89 95 90 RefPtr<AccessibilityController> AccessibilityUIElement::s_controller; … … 207 202 static NSString *attributesOfElement(id accessibilityObject) 208 203 { 209 RetainPtr<NSArray>attributes = supportedAttributes(accessibilityObject);204 auto attributes = supportedAttributes(accessibilityObject); 210 205 211 206 NSMutableString* attributesString = [NSMutableString string]; … … 228 223 } 229 224 230 template<typename T> 231 static JSValueRef convertVectorToObjectArray(JSContextRef context, Vector<T> const& elements) 232 { 233 JSValueRef arrayResult = JSObjectMakeArray(context, 0, 0, 0); 234 JSObjectRef arrayObj = JSValueToObject(context, arrayResult, 0); 225 template<typename T> static JSObjectRef makeJSArray(JSContextRef context, const Vector<T>& elements) 226 { 227 auto array = JSObjectMakeArray(context, 0, 0, 0); 235 228 size_t elementCount = elements.size(); 236 229 for (size_t i = 0; i < elementCount; ++i) 237 JSObjectSetPropertyAtIndex(context, arrayObj, i, JSObjectMake(context, elements[i]->wrapperClass(), elements[i].get()), 0); 238 239 return arrayResult; 230 JSObjectSetPropertyAtIndex(context, array, i, JSObjectMake(context, elements[i]->wrapperClass(), elements[i].get()), 0); 231 return array; 240 232 } 241 233 … … 274 266 if (searchStrings) { 275 267 NSMutableArray *searchStringsParameter = [NSMutableArray array]; 276 if (JSValueIsString(context, searchStrings)) { 277 auto searchStringsString = adopt(JSValueToStringCopy(context, searchStrings, nullptr)); 278 if (searchStringsString) 279 [searchStringsParameter addObject:[NSString stringWithJSStringRef:searchStringsString.get()]]; 280 } 281 else if (JSValueIsObject(context, searchStrings)) { 268 if (JSValueIsString(context, searchStrings)) 269 [searchStringsParameter addObject:toWTFString(context, searchStrings)]; 270 else { 282 271 JSObjectRef searchStringsArray = JSValueToObject(context, searchStrings, nullptr); 283 unsigned searchStringsArrayLength = 0; 284 285 auto lengthPropertyString = adopt(JSStringCreateWithUTF8CString("length")); 286 JSValueRef searchStringsArrayLengthValue = JSObjectGetProperty(context, searchStringsArray, lengthPropertyString.get(), nullptr); 287 if (searchStringsArrayLengthValue && JSValueIsNumber(context, searchStringsArrayLengthValue)) 288 searchStringsArrayLength = static_cast<unsigned>(JSValueToNumber(context, searchStringsArrayLengthValue, nullptr)); 289 290 for (unsigned i = 0; i < searchStringsArrayLength; ++i) { 291 auto searchStringsString = adopt(JSValueToStringCopy(context, JSObjectGetPropertyAtIndex(context, searchStringsArray, i, nullptr), nullptr)); 292 if (searchStringsString) 293 [searchStringsParameter addObject:[NSString stringWithJSStringRef:searchStringsString.get()]]; 294 } 272 unsigned searchStringsArrayLength = arrayLength(context, searchStringsArray); 273 for (unsigned i = 0; i < searchStringsArrayLength; ++i) 274 [searchStringsParameter addObject:toWTFString(context, JSObjectGetPropertyAtIndex(context, searchStringsArray, i, nullptr))]; 295 275 } 296 276 [parameterizedAttribute setObject:searchStringsParameter forKey:@"AXSelectTextSearchStrings"]; … … 315 295 if (searchStrings) { 316 296 NSMutableArray *searchStringsParameter = [NSMutableArray array]; 317 if (JSValueIsString(context, searchStrings)) { 318 auto searchStringsString = adopt(JSValueToStringCopy(context, searchStrings, nullptr)); 319 if (searchStringsString) 320 [searchStringsParameter addObject:[NSString stringWithJSStringRef:searchStringsString.get()]]; 321 } else if (JSValueIsObject(context, searchStrings)) { 297 if (JSValueIsString(context, searchStrings)) 298 [searchStringsParameter addObject:toWTFString(context, searchStrings)]; 299 else { 322 300 JSObjectRef searchStringsArray = JSValueToObject(context, searchStrings, nullptr); 323 unsigned searchStringsArrayLength = 0; 324 325 auto lengthPropertyString = adopt(JSStringCreateWithUTF8CString("length")); 326 JSValueRef searchStringsArrayLengthValue = JSObjectGetProperty(context, searchStringsArray, lengthPropertyString.get(), nullptr); 327 if (searchStringsArrayLengthValue && JSValueIsNumber(context, searchStringsArrayLengthValue)) 328 searchStringsArrayLength = static_cast<unsigned>(JSValueToNumber(context, searchStringsArrayLengthValue, nullptr)); 329 330 for (unsigned i = 0; i < searchStringsArrayLength; ++i) { 331 auto searchStringsString = adopt(JSValueToStringCopy(context, JSObjectGetPropertyAtIndex(context, searchStringsArray, i, nullptr), nullptr)); 332 if (searchStringsString) 333 [searchStringsParameter addObject:[NSString stringWithJSStringRef:searchStringsString.get()]]; 334 } 301 unsigned searchStringsArrayLength = arrayLength(context, searchStringsArray); 302 for (unsigned i = 0; i < searchStringsArrayLength; ++i) 303 [searchStringsParameter addObject:toWTFString(context, JSObjectGetPropertyAtIndex(context, searchStringsArray, i, nullptr))]; 335 304 } 336 305 [parameterizedAttribute setObject:searchStringsParameter forKey:@"AXSearchTextSearchStrings"]; … … 402 371 if ([value isKindOfClass:[NSArray class]]) 403 372 elements = makeVector<RefPtr<AccessibilityUIElement>>(value); 404 return convertVectorToObjectArray<RefPtr<AccessibilityUIElement>>(context, elements);373 return makeJSArray(context, elements); 405 374 END_AX_OBJC_EXCEPTIONS 406 375 } … … 416 385 if ([value isKindOfClass:[NSArray class]]) 417 386 elements = makeVector<RefPtr<AccessibilityUIElement>>(value); 418 return convertVectorToObjectArray<RefPtr<AccessibilityUIElement>>(context, elements);387 return makeJSArray(context, elements); 419 388 END_AX_OBJC_EXCEPTIONS 420 389 } … … 608 577 Vector<RefPtr<AccessibilityUIElement>> elements; 609 578 getUIElementsWithAttribute(attribute, elements); 610 return convertVectorToObjectArray<RefPtr<AccessibilityUIElement>>(context, elements);579 return makeJSArray(context, elements); 611 580 } 612 581 … … 977 946 bool AccessibilityUIElement::isSelectedOptionActive() const 978 947 { 979 // FIXME: implement980 948 return false; 981 949 } … … 1230 1198 id result = [m_element accessibilityAttributeValue:@"AXSearchTextWithCriteria" forParameter:parameterizedAttribute]; 1231 1199 if ([result isKindOfClass:[NSArray class]]) 1232 return convertVectorToObjectArray<RefPtr<AccessibilityTextMarkerRange>>(context, makeVector<RefPtr<AccessibilityTextMarkerRange>>(result));1200 return makeJSArray(context, makeVector<RefPtr<AccessibilityTextMarkerRange>>(result)); 1233 1201 END_AX_OBJC_EXCEPTIONS 1234 1202 … … 1547 1515 void AccessibilityUIElement::clearSelectedChildren() const 1548 1516 { 1549 // FIXME: implement1550 1517 } 1551 1518 1552 1519 JSRetainPtr<JSStringRef> AccessibilityUIElement::accessibilityValue() const 1553 1520 { 1554 // FIXME: implement 1555 return createEmptyJSString(); 1521 return createJSString(); 1556 1522 } 1557 1523 … … 1563 1529 return [value createJSStringRef]; 1564 1530 END_AX_OBJC_EXCEPTIONS 1565 1566 return createEmptyJSString(); 1531 return createJSString(); 1567 1532 } 1568 1533 … … 1574 1539 return [value createJSStringRef]; 1575 1540 END_AX_OBJC_EXCEPTIONS 1576 1577 return createEmptyJSString(); 1541 return createJSString(); 1578 1542 } 1579 1543 … … 1584 1548 return [[url absoluteString] createJSStringRef]; 1585 1549 END_AX_OBJC_EXCEPTIONS 1586 1587 1550 return nullptr; 1588 1551 } … … 1623 1586 result = [m_element accessibilityIsAttributeSettable:NSAccessibilityFocusedAttribute]; 1624 1587 END_AX_OBJC_EXCEPTIONS 1625 1626 1588 return result; 1627 1589 } … … 1649 1611 bool AccessibilityUIElement::isVisible() const 1650 1612 { 1651 // FIXME: implement1652 1613 return false; 1653 1614 } … … 1655 1616 bool AccessibilityUIElement::isOffScreen() const 1656 1617 { 1657 // FIXME: implement1658 1618 return false; 1659 1619 } … … 1661 1621 bool AccessibilityUIElement::isCollapsed() const 1662 1622 { 1663 // FIXME: implement1664 1623 return false; 1665 1624 } … … 1676 1635 bool AccessibilityUIElement::isSingleLine() const 1677 1636 { 1678 // FIXME: implement1679 1637 return false; 1680 1638 } … … 1682 1640 bool AccessibilityUIElement::isMultiLine() const 1683 1641 { 1684 // FIXME: implement1685 1642 return false; 1686 1643 } … … 1715 1672 void AccessibilityUIElement::takeSelection() 1716 1673 { 1717 // FIXME: implement1718 1674 } 1719 1675 1720 1676 void AccessibilityUIElement::addSelection() 1721 1677 { 1722 // FIXME: implement1723 1678 } 1724 1679 1725 1680 void AccessibilityUIElement::removeSelection() 1726 1681 { 1727 // FIXME: implement1728 1682 } 1729 1683 -
TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/mac/TestRunnerMac.mm ¶
r245419 r267761 47 47 return nullptr; 48 48 #else 49 CFBundleRefinspectorBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.WebInspectorUI"));49 auto inspectorBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.WebInspectorUI")); 50 50 if (!inspectorBundle) 51 51 return nullptr; 52 53 RetainPtr<CFURLRef> url = adoptCF(CFBundleCopyResourceURL(inspectorBundle, CFSTR("TestStub"), CFSTR("html"), NULL)); 54 if (!url) 55 return nullptr; 56 57 CFStringRef urlString = CFURLGetString(url.get()); 58 return adopt(JSStringCreateWithCFString(urlString)); 52 auto resourceURL = adoptCF(CFBundleCopyResourceURL(inspectorBundle, CFSTR("TestStub"), CFSTR("html"), NULL)); 53 return resourceURL ? adopt(JSStringCreateWithCFString(CFURLGetString(resourceURL.get()))) : nullptr; 59 54 #endif 60 55 } -
TabularUnified trunk/Tools/WebKitTestRunner/StringFunctions.h ¶
r263164 r267761 1 1 /* 2 * Copyright (C) 2010 Apple Inc. All rights reserved.2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved. 3 3 * Copyright (C) 2010 University of Szeged. All rights reserved. 4 4 * … … 25 25 */ 26 26 27 #ifndef StringFunctions_h 28 #define StringFunctions_h 27 #pragma once 29 28 30 #include <JavaScriptCore/JSRetainPtr.h> 31 #include <JavaScriptCore/JavaScript.h> 29 #include "JSBasics.h" 32 30 #include <WebKit/WKRetainPtr.h> 33 31 #include <WebKit/WKString.h> 34 32 #include <WebKit/WKStringPrivate.h> 35 #include <WebKit/WKURL.h>36 33 #include <sstream> 37 34 #include <string> … … 45 42 namespace WTR { 46 43 47 // Conversion functions 44 WKRetainPtr<WKStringRef> toWKString(JSContextRef, JSValueRef); 45 WTF::String toWTFString(JSContextRef, JSValueRef); 48 46 49 47 inline WKRetainPtr<WKStringRef> toWK(JSStringRef string) … … 57 55 } 58 56 57 inline WKRetainPtr<WKStringRef> toWK(const char* string) 58 { 59 return adoptWK(WKStringCreateWithUTF8CString(string)); 60 } 61 59 62 inline WKRetainPtr<WKStringRef> toWK(const WTF::String& string) 60 63 { 61 return adoptWK(WKStringCreateWithUTF8CString(string.utf8().data()));64 return toWK(string.utf8().data()); 62 65 } 63 66 … … 87 90 inline WTF::String toWTFString(WKStringRef string) 88 91 { 92 if (!string) 93 return nullString(); 89 94 size_t bufferSize = WKStringGetMaximumUTF8CStringSize(string); 90 95 auto buffer = makeUniqueWithoutFastMallocCheck<char[]>(bufferSize); … … 100 105 } 101 106 107 inline WTF::String toWTFString(JSStringRef string) 108 { 109 return toWTFString(toWK(string)); 110 } 111 112 inline WTF::String toWTFString(const JSRetainPtr<JSStringRef>& string) 113 { 114 return toWTFString(string.get()); 115 } 116 117 inline WKRetainPtr<WKStringRef> toWKString(JSContextRef context, JSValueRef value) 118 { 119 return toWK(createJSString(context, value).get()); 120 } 121 122 inline WTF::String toWTFString(JSContextRef context, JSValueRef value) 123 { 124 // FIXME: Could make this efficient by using the WTFString inside OpaqueJSString if we wanted to. 125 return toWTFString(createJSString(context, value)); 126 } 127 102 128 } // namespace WTR 103 104 #endif // StringFunctions_h -
TabularUnified trunk/Tools/WebKitTestRunner/TestController.cpp ¶
r267750 r267761 27 27 #include "TestController.h" 28 28 29 #include "DictionaryFunctions.h" 29 30 #include "EventSenderProxy.h" 30 31 #include "Options.h" 31 32 #include "PlatformWebView.h" 32 #include "StringFunctions.h"33 33 #include "TestInvocation.h" 34 34 #include "WebCoreTestSupport.h" … … 495 495 #endif 496 496 497 WKRetainPtr<WKStringRef> pageGroupIdentifier = adoptWK(WKStringCreateWithUTF8CString("WebKitTestRunnerPageGroup")); 498 m_pageGroup.adopt(WKPageGroupCreateWithIdentifier(pageGroupIdentifier.get())); 497 m_pageGroup.adopt(WKPageGroupCreateWithIdentifier(toWK("WebKitTestRunnerPageGroup").get())); 499 498 500 499 m_eventSenderProxy = makeUnique<EventSenderProxy>(this); … … 508 507 WKContextConfigurationSetIgnoreSynchronousMessagingTimeoutsForTesting(configuration.get(), options.ignoreSynchronousMessagingTimeouts); 509 508 510 WKRetainPtr<WKMutableArrayRef>overrideLanguages = adoptWK(WKMutableArrayCreate());509 auto overrideLanguages = adoptWK(WKMutableArrayCreate()); 511 510 for (auto& language : options.overrideLanguages) 512 WKArrayAppendItem(overrideLanguages.get(), adoptWK(WKStringCreateWithUTF8CString(language.utf8().data())).get());511 WKArrayAppendItem(overrideLanguages.get(), toWK(language).get()); 513 512 WKContextConfigurationSetOverrideLanguages(configuration.get(), overrideLanguages.get()); 514 513 … … 844 843 845 844 // Set internal features that have different default values for testing. 846 static WKStringRef asyncOverflowScrollingFeature = WKStringCreateWithUTF8CString("AsyncOverflowScrollingEnabled"); 847 WKPreferencesSetInternalDebugFeatureForKey(preferences, false, asyncOverflowScrollingFeature); 848 849 static WKStringRef asyncFrameScrollingFeature = WKStringCreateWithUTF8CString("AsyncFrameScrollingEnabled"); 850 WKPreferencesSetInternalDebugFeatureForKey(preferences, false, asyncFrameScrollingFeature); 845 846 WKPreferencesSetInternalDebugFeatureForKey(preferences, false, toWK("AsyncOverflowScrollingEnabled").get()); 847 WKPreferencesSetInternalDebugFeatureForKey(preferences, false, toWK("AsyncFrameScrollingEnabled").get()); 851 848 852 849 #if ENABLE(INPUT_TYPE_DATE) 853 static WKStringRef inputTypeDateFeature = WKStringCreateWithUTF8CString("InputTypeDateEnabled"); 854 WKPreferencesSetInternalDebugFeatureForKey(preferences, true, inputTypeDateFeature); 850 WKPreferencesSetInternalDebugFeatureForKey(preferences, true, toWK("InputTypeDateEnabled").get()); 855 851 #endif 856 852 #if ENABLE(INPUT_TYPE_DATETIMELOCAL) 857 static WKStringRef inputTypeDateTimeLocalFeature = WKStringCreateWithUTF8CString("InputTypeDateTimeLocalEnabled"); 858 WKPreferencesSetInternalDebugFeatureForKey(preferences, true, inputTypeDateTimeLocalFeature); 853 WKPreferencesSetInternalDebugFeatureForKey(preferences, true, toWK("InputTypeDateTimeLocalEnabled").get()); 859 854 #endif 860 855 #if ENABLE(INPUT_TYPE_MONTH) 861 static WKStringRef inputTypeMonthFeature = WKStringCreateWithUTF8CString("InputTypeMonthEnabled"); 862 WKPreferencesSetInternalDebugFeatureForKey(preferences, true, inputTypeMonthFeature); 856 WKPreferencesSetInternalDebugFeatureForKey(preferences, true, toWK("InputTypeMonthEnabled").get()); 863 857 #endif 864 858 #if ENABLE(INPUT_TYPE_TIME) 865 static WKStringRef inputTypeTimeFeature = WKStringCreateWithUTF8CString("InputTypeTimeEnabled"); 866 WKPreferencesSetInternalDebugFeatureForKey(preferences, true, inputTypeTimeFeature); 859 WKPreferencesSetInternalDebugFeatureForKey(preferences, true, toWK("InputTypeTimeEnabled").get()); 867 860 #endif 868 861 #if ENABLE(INPUT_TYPE_WEEK) 869 static WKStringRef inputTypeWeekFeature = WKStringCreateWithUTF8CString("InputTypeWeekEnabled"); 870 WKPreferencesSetInternalDebugFeatureForKey(preferences, true, inputTypeWeekFeature); 862 WKPreferencesSetInternalDebugFeatureForKey(preferences, true, toWK("InputTypeWeekEnabled").get()); 871 863 #endif 872 864 … … 921 913 WKPreferencesSetPageCacheEnabled(preferences, options.enableBackForwardCache); 922 914 923 static WKStringRef defaultTextEncoding = WKStringCreateWithUTF8CString("ISO-8859-1"); 924 WKPreferencesSetDefaultTextEncodingName(preferences, defaultTextEncoding); 925 926 static WKStringRef standardFontFamily = WKStringCreateWithUTF8CString("Times"); 927 static WKStringRef cursiveFontFamily = WKStringCreateWithUTF8CString("Apple Chancery"); 928 static WKStringRef fantasyFontFamily = WKStringCreateWithUTF8CString("Papyrus"); 929 static WKStringRef fixedFontFamily = WKStringCreateWithUTF8CString("Courier"); 930 static WKStringRef pictographFontFamily = WKStringCreateWithUTF8CString("Apple Color Emoji"); 931 static WKStringRef sansSerifFontFamily = WKStringCreateWithUTF8CString("Helvetica"); 932 static WKStringRef serifFontFamily = WKStringCreateWithUTF8CString("Times"); 915 WKPreferencesSetDefaultTextEncodingName(preferences, toWK("ISO-8859-1").get()); 933 916 934 917 WKPreferencesSetMinimumFontSize(preferences, 0); 935 WKPreferencesSetStandardFontFamily(preferences, standardFontFamily);936 WKPreferencesSetCursiveFontFamily(preferences, cursiveFontFamily);937 WKPreferencesSetFantasyFontFamily(preferences, fantasyFontFamily);938 WKPreferencesSetFixedFontFamily(preferences, fixedFontFamily);939 WKPreferencesSetPictographFontFamily(preferences, pictographFontFamily);940 WKPreferencesSetSansSerifFontFamily(preferences, sansSerifFontFamily);941 WKPreferencesSetSerifFontFamily(preferences, serifFontFamily);918 WKPreferencesSetStandardFontFamily(preferences, toWK("Times").get()); 919 WKPreferencesSetCursiveFontFamily(preferences, toWK("Apple Chancery").get()); 920 WKPreferencesSetFantasyFontFamily(preferences, toWK("Papyrus").get()); 921 WKPreferencesSetFixedFontFamily(preferences, toWK("Courier").get()); 922 WKPreferencesSetPictographFontFamily(preferences, toWK("Apple Color Emoji").get()); 923 WKPreferencesSetSansSerifFontFamily(preferences, toWK("Helvetica").get()); 924 WKPreferencesSetSerifFontFamily(preferences, toWK("Times").get()); 942 925 WKPreferencesSetAsynchronousSpellCheckingEnabled(preferences, false); 943 926 #if ENABLE(MEDIA_SOURCE) … … 1011 994 WKPageSetCustomUserAgent(m_mainWebView->page(), nullptr); 1012 995 1013 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("Reset")); 1014 WKRetainPtr<WKMutableDictionaryRef> resetMessageBody = adoptWK(WKMutableDictionaryCreate()); 1015 1016 WKRetainPtr<WKStringRef> shouldGCKey = adoptWK(WKStringCreateWithUTF8CString("ShouldGC")); 1017 WKRetainPtr<WKBooleanRef> shouldGCValue = adoptWK(WKBooleanCreate(m_gcBetweenTests)); 1018 WKDictionarySetItem(resetMessageBody.get(), shouldGCKey.get(), shouldGCValue.get()); 1019 1020 WKRetainPtr<WKStringRef> allowedHostsKey = adoptWK(WKStringCreateWithUTF8CString("AllowedHosts")); 1021 WKRetainPtr<WKMutableArrayRef> allowedHostsValue = adoptWK(WKMutableArrayCreate()); 1022 for (auto& host : m_allowedHosts) { 1023 WKRetainPtr<WKStringRef> wkHost = adoptWK(WKStringCreateWithUTF8CString(host.c_str())); 1024 WKArrayAppendItem(allowedHostsValue.get(), wkHost.get()); 1025 } 1026 WKDictionarySetItem(resetMessageBody.get(), allowedHostsKey.get(), allowedHostsValue.get()); 996 auto resetMessageBody = adoptWK(WKMutableDictionaryCreate()); 997 998 setValue(resetMessageBody, "ShouldGC", m_gcBetweenTests); 999 1000 auto allowedHostsValue = adoptWK(WKMutableArrayCreate()); 1001 for (auto& host : m_allowedHosts) 1002 WKArrayAppendItem(allowedHostsValue.get(), toWK(host.c_str()).get()); 1003 setValue(resetMessageBody, "AllowedHosts", allowedHostsValue); 1027 1004 1028 1005 #if ENABLE(ACCESSIBILITY_ISOLATED_TREE) 1029 WKRetainPtr<WKStringRef> axIsolatedModeKey = adoptWK(WKStringCreateWithUTF8CString("AccessibilityIsolatedTree")); 1030 WKRetainPtr<WKBooleanRef> axIsolatedModeValue = adoptWK(WKBooleanCreate(m_accessibilityIsolatedTreeMode)); 1031 WKDictionarySetItem(resetMessageBody.get(), axIsolatedModeKey.get(), axIsolatedModeValue.get()); 1006 setValue(resetMessageBody, "AccessibilityIsolatedTree", m_accessibilityIsolatedTreeMode); 1032 1007 #endif 1033 1034 if (options.jscOptions.length()) { 1035 WKRetainPtr<WKStringRef> jscOptionsKey = adoptWK(WKStringCreateWithUTF8CString("JSCOptions")); 1036 WKRetainPtr<WKStringRef> jscOptionsValue = adoptWK(WKStringCreateWithUTF8CString(options.jscOptions.c_str())); 1037 WKDictionarySetItem(resetMessageBody.get(), jscOptionsKey.get(), jscOptionsValue.get()); 1038 } 1008 1009 if (options.jscOptions.length()) 1010 setValue(resetMessageBody, "JSCOptions", options.jscOptions.c_str()); 1039 1011 1040 1012 #if PLATFORM(COCOA) … … 1042 1014 #endif 1043 1015 1044 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), resetMessageBody.get());1016 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), toWK("Reset").get(), resetMessageBody.get()); 1045 1017 1046 1018 WKContextSetShouldUseFontSmoothing(TestController::singleton().context(), false); … … 1204 1176 AsyncTask([]() { 1205 1177 // After each test, we update the list of live documents so that we can detect when an abandoned document first showed up. 1206 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("GetLiveDocuments")); 1207 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), nullptr); 1178 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), toWK("GetLiveDocuments").get(), nullptr); 1208 1179 }, 5_s).run(); 1209 1180 } … … 1216 1187 AsyncTask([]() { 1217 1188 // This runs at the end of a series of tests. It clears caches, runs a GC and then fetches the list of documents. 1218 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CheckForWorldLeaks")); 1219 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), nullptr); 1189 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), toWK("CheckForWorldLeaks").get(), nullptr); 1220 1190 }, 20_s).run(); 1221 1191 } … … 1325 1295 1326 1296 #if !PLATFORM(COCOA) 1297 1327 1298 void TestController::setAllowsAnySSLCertificate(bool allows) 1328 1299 { … … 1401 1372 static std::string parseStringTestHeaderValueAsRelativePath(const std::string& value, const std::string& pathOrURL) 1402 1373 { 1403 WKRetainPtr<WKURLRef>baseURL = adoptWK(createTestURL(pathOrURL.c_str()));1404 WKRetainPtr<WKURLRef>relativeURL = adoptWK(WKURLCreateWithBaseURL(baseURL.get(), value.c_str()));1374 auto baseURL = adoptWK(createTestURL(pathOrURL.c_str())); 1375 auto relativeURL = adoptWK(WKURLCreateWithBaseURL(baseURL.get(), value.c_str())); 1405 1376 return toSTD(adoptWK(WKURLCopyPath(relativeURL.get()))); 1406 1377 } … … 1416 1387 if (filename.empty()) { 1417 1388 // Gross. Need to reduce conversions between all the string types and URLs. 1418 WKRetainPtr<WKURLRef> wkURL = adoptWK(createTestURL(pathOrURL.c_str())); 1419 filename = testPath(wkURL.get()); 1389 filename = testPath(adoptWK(createTestURL(pathOrURL.c_str())).get()); 1420 1390 } 1421 1391 … … 1616 1586 1617 1587 #if ENABLE(CONTENT_EXTENSIONS) && !PLATFORM(COCOA) 1588 1618 1589 struct ContentExtensionStoreCallbackContext { 1619 1590 explicit ContentExtensionStoreCallbackContext(TestController& controller) … … 1643 1614 return path + ".json"; 1644 1615 1645 auto p = adoptWK(WKURLCopyPath(url)); 1646 auto buffer = std::vector<char>(WKStringGetMaximumUTF8CStringSize(p.get())); 1647 const auto length = WKStringGetUTF8CString(p.get(), buffer.data(), buffer.size()); 1648 return std::string("LayoutTests/http/tests") + std::string(buffer.data(), length - 1) + ".json"; 1649 } 1650 #endif 1651 1652 #if !PLATFORM(COCOA) 1653 #if ENABLE(CONTENT_EXTENSIONS) 1616 return "LayoutTests/http/tests" + toSTD(adoptWK(WKURLCopyPath(url)).get()) + ".json"; 1617 } 1618 1654 1619 void TestController::configureContentExtensionForTest(const TestInvocation& test) 1655 1620 { … … 1671 1636 1672 1637 std::string jsonFileContents {std::istreambuf_iterator<char>(jsonFile), std::istreambuf_iterator<char>()}; 1673 auto jsonSource = adoptWK(WKStringCreateWithUTF8CString(jsonFileContents.c_str()));1674 1675 auto storePath = adoptWK(WKStringCreateWithUTF8CString(contentExtensionsPath));1638 auto jsonSource = toWK(jsonFileContents.c_str()); 1639 1640 auto storePath = toWK(contentExtensionsPath); 1676 1641 auto extensionStore = adoptWK(WKUserContentExtensionStoreCreate(storePath.get())); 1677 1642 ASSERT(extensionStore); 1678 1643 1679 auto filterIdentifier = adoptWK(WKStringCreateWithUTF8CString("TestContentExtension"));1644 auto filterIdentifier = toWK("TestContentExtension"); 1680 1645 1681 1646 ContentExtensionStoreCallbackContext context(*this); … … 1702 1667 WKUserContentControllerRemoveAllUserContentFilters(userContentController()); 1703 1668 1704 auto storePath = adoptWK(WKStringCreateWithUTF8CString(contentExtensionsPath));1669 auto storePath = toWK(contentExtensionsPath); 1705 1670 auto extensionStore = adoptWK(WKUserContentExtensionStoreCreate(storePath.get())); 1706 1671 ASSERT(extensionStore); 1707 1672 1708 auto filterIdentifier = adoptWK(WKStringCreateWithUTF8CString("TestContentExtension"));1673 auto filterIdentifier = toWK("TestContentExtension"); 1709 1674 1710 1675 ContentExtensionStoreCallbackContext context(*this); … … 1713 1678 ASSERT(!context.filter); 1714 1679 } 1715 #else // ENABLE(CONTENT_EXTENSIONS) 1680 1681 #endif // ENABLE(CONTENT_EXTENSIONS) && !PLATFORM(COCOA) 1682 1683 #if !ENABLE(CONTENT_EXTENSIONS) 1684 1716 1685 void TestController::configureContentExtensionForTest(const TestInvocation&) 1717 1686 { … … 1721 1690 { 1722 1691 } 1723 #endif // ENABLE(CONTENT_EXTENSIONS) 1724 #endif // ! PLATFORM(COCOA)1692 1693 #endif // !ENABLE(CONTENT_EXTENSIONS) 1725 1694 1726 1695 class CommandTokenizer { … … 1728 1697 explicit CommandTokenizer(const std::string& input) 1729 1698 : m_input(input) 1730 , m_posNextSeparator(0)1731 1699 { 1732 1700 pump(); … … 1741 1709 const std::string& m_input; 1742 1710 std::string m_next; 1743 size_t m_posNextSeparator ;1711 size_t m_posNextSeparator { 0 }; 1744 1712 }; 1745 1713 … … 1815 1783 TestOptions options = testOptionsForTest(command); 1816 1784 1817 WKRetainPtr<WKURLRef> wkURL = adoptWK(createTestURL(command.pathOrURL.c_str())); 1818 m_currentInvocation = makeUnique<TestInvocation>(wkURL.get(), options); 1785 m_currentInvocation = makeUnique<TestInvocation>(adoptWK(createTestURL(command.pathOrURL.c_str())).get(), options); 1819 1786 1820 1787 if (command.shouldDumpPixels || m_shouldDumpPixelsForAllTests) … … 1945 1912 } 1946 1913 1947 void TestController::didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef messageBodyDictionary, bool synchronous) 1948 { 1949 WKRetainPtr<WKStringRef> keyKey = adoptWK(WKStringCreateWithUTF8CString("Key")); 1950 WKStringRef key = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, keyKey.get())); 1951 1952 WKRetainPtr<WKStringRef> modifiersKey = adoptWK(WKStringCreateWithUTF8CString("Modifiers")); 1953 WKEventModifiers modifiers = static_cast<WKEventModifiers>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, modifiersKey.get())))); 1954 1955 WKRetainPtr<WKStringRef> locationKey = adoptWK(WKStringCreateWithUTF8CString("Location")); 1956 unsigned location = static_cast<unsigned>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, locationKey.get())))); 1957 1958 m_eventSenderProxy->keyDown(key, modifiers, location); 1914 void TestController::didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef dictionary, bool synchronous) 1915 { 1916 m_eventSenderProxy->keyDown(stringValue(dictionary, "Key"), uint64Value(dictionary, "Modifiers"), uint64Value(dictionary, "Location")); 1959 1917 } 1960 1918 … … 1965 1923 HashMap<uint64_t, String> documentInfo; 1966 1924 for (size_t i = 0; i < numDocuments; ++i) { 1967 WKTypeRef item = WKArrayGetItemAtIndex(liveDocumentList, i); 1968 if (item && WKGetTypeID(item) == WKDictionaryGetTypeID()) { 1969 WKDictionaryRef liveDocumentItem = static_cast<WKDictionaryRef>(item); 1970 1971 WKRetainPtr<WKStringRef> idKey = adoptWK(WKStringCreateWithUTF8CString("id")); 1972 WKUInt64Ref documentID = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(liveDocumentItem, idKey.get())); 1973 1974 WKRetainPtr<WKStringRef> urlKey = adoptWK(WKStringCreateWithUTF8CString("url")); 1975 WKStringRef documentURL = static_cast<WKStringRef>(WKDictionaryGetItemForKey(liveDocumentItem, urlKey.get())); 1976 1977 documentInfo.add(WKUInt64GetValue(documentID), toWTFString(documentURL)); 1978 } 1925 if (auto dictionary = dictionaryValue(WKArrayGetItemAtIndex(liveDocumentList, i))) 1926 documentInfo.add(uint64Value(dictionary, "id"), toWTFString(stringValue(dictionary, "url"))); 1979 1927 } 1980 1928 … … 2008 1956 return; 2009 1957 2010 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 2011 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 2012 2013 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 2014 WKStringRef subMessageName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, subMessageKey.get())); 2015 2016 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseDown") || WKStringIsEqualToUTF8CString(subMessageName, "MouseUp")) { 2017 WKRetainPtr<WKStringRef> buttonKey = adoptWK(WKStringCreateWithUTF8CString("Button")); 2018 unsigned button = static_cast<unsigned>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, buttonKey.get())))); 2019 2020 WKRetainPtr<WKStringRef> modifiersKey = adoptWK(WKStringCreateWithUTF8CString("Modifiers")); 2021 WKEventModifiers modifiers = static_cast<WKEventModifiers>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, modifiersKey.get())))); 2022 2023 // Forward to WebProcess 2024 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseDown")) 2025 m_eventSenderProxy->mouseDown(button, modifiers); 2026 else 2027 m_eventSenderProxy->mouseUp(button, modifiers); 2028 1958 auto dictionary = dictionaryValue(messageBody); 1959 auto subMessageName = stringValue(dictionary, "SubMessage"); 1960 1961 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseDown")) { 1962 m_eventSenderProxy->mouseDown(uint64Value(dictionary, "Button"), uint64Value(dictionary, "Modifiers")); 2029 1963 return; 2030 1964 } 2031 1965 2032 if (WKStringIsEqualToUTF8CString(subMessageName, " KeyDown")) {2033 didReceiveKeyDownMessageFromInjectedBundle(messageBodyDictionary, false);1966 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseUp")) { 1967 m_eventSenderProxy->mouseUp(uint64Value(dictionary, "Button"), uint64Value(dictionary, "Modifiers")); 2034 1968 return; 2035 1969 } 2036 1970 2037 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseScrollBy")) { 2038 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X")); 2039 double x = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))); 2040 2041 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); 2042 double y = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))); 2043 2044 // Forward to WebProcess 2045 m_eventSenderProxy->mouseScrollBy(x, y); 1971 if (WKStringIsEqualToUTF8CString(subMessageName, "KeyDown")) { 1972 didReceiveKeyDownMessageFromInjectedBundle(dictionary, false); 2046 1973 return; 2047 1974 } 2048 1975 1976 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseScrollBy")) { 1977 m_eventSenderProxy->mouseScrollBy(doubleValue(dictionary, "X"), doubleValue(dictionary, "Y")); 1978 return; 1979 } 1980 2049 1981 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseScrollByWithWheelAndMomentumPhases")) { 2050 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X")); 2051 double x = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))); 2052 2053 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); 2054 double y = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))); 2055 2056 WKRetainPtr<WKStringRef> phaseKey = adoptWK(WKStringCreateWithUTF8CString("Phase")); 2057 int phase = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, phaseKey.get())))); 2058 WKRetainPtr<WKStringRef> momentumKey = adoptWK(WKStringCreateWithUTF8CString("Momentum")); 2059 int momentum = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, momentumKey.get())))); 2060 2061 // Forward to WebProcess 1982 auto x = doubleValue(dictionary, "X"); 1983 auto y = doubleValue(dictionary, "Y"); 1984 auto phase = uint64Value(dictionary, "Phase"); 1985 auto momentum = uint64Value(dictionary, "Momentum"); 2062 1986 m_eventSenderProxy->mouseScrollByWithWheelAndMomentumPhases(x, y, phase, momentum); 2063 2064 1987 return; 2065 1988 } … … 2084 2007 return completionHandler(nullptr); 2085 2008 2086 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 2087 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 2088 2089 WKRetainPtr<WKStringRef> subMessageKey = adoptWK(WKStringCreateWithUTF8CString("SubMessage")); 2090 WKStringRef subMessageName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, subMessageKey.get())); 2009 auto dictionary = dictionaryValue(messageBody); 2010 auto subMessageName = stringValue(dictionary, "SubMessage"); 2091 2011 2092 2012 if (WKStringIsEqualToUTF8CString(subMessageName, "KeyDown")) { 2093 didReceiveKeyDownMessageFromInjectedBundle(messageBodyDictionary, true); 2094 2013 didReceiveKeyDownMessageFromInjectedBundle(dictionary, true); 2095 2014 return completionHandler(nullptr); 2096 2015 } 2097 2016 2098 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseDown") || WKStringIsEqualToUTF8CString(subMessageName, "MouseUp")) { 2099 WKRetainPtr<WKStringRef> buttonKey = adoptWK(WKStringCreateWithUTF8CString("Button")); 2100 unsigned button = static_cast<unsigned>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, buttonKey.get())))); 2101 2102 WKRetainPtr<WKStringRef> modifiersKey = adoptWK(WKStringCreateWithUTF8CString("Modifiers")); 2103 WKEventModifiers modifiers = static_cast<WKEventModifiers>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, modifiersKey.get())))); 2104 2105 // Forward to WebProcess 2106 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseDown")) 2107 m_eventSenderProxy->mouseDown(button, modifiers); 2108 else 2109 m_eventSenderProxy->mouseUp(button, modifiers); 2017 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseDown")) { 2018 m_eventSenderProxy->mouseDown(uint64Value(dictionary, "Button"), uint64Value(dictionary, "Modifiers")); 2110 2019 return completionHandler(nullptr); 2111 2020 } 2112 2021 2022 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseUp")) { 2023 m_eventSenderProxy->mouseUp(uint64Value(dictionary, "Button"), uint64Value(dictionary, "Modifiers")); 2024 return completionHandler(nullptr); 2025 } 2026 2113 2027 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseMoveTo")) { 2114 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X")); 2115 double x = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))); 2116 2117 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); 2118 double y = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))); 2119 2120 // Forward to WebProcess 2121 m_eventSenderProxy->mouseMoveTo(x, y); 2028 m_eventSenderProxy->mouseMoveTo(doubleValue(dictionary, "X"), doubleValue(dictionary, "Y")); 2122 2029 return completionHandler(nullptr); 2123 2030 } … … 2145 2052 2146 2053 if (WKStringIsEqualToUTF8CString(subMessageName, "MouseForceChanged")) { 2147 WKRetainPtr<WKStringRef> forceKey = adoptWK(WKStringCreateWithUTF8CString("Force")); 2148 double force = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, forceKey.get()))); 2149 2150 m_eventSenderProxy->mouseForceChanged(force); 2054 m_eventSenderProxy->mouseForceChanged(doubleValue(dictionary, "Force")); 2151 2055 return completionHandler(nullptr); 2152 2056 } … … 2154 2058 2155 2059 if (WKStringIsEqualToUTF8CString(subMessageName, "ContinuousMouseScrollBy")) { 2156 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X")); 2157 double x = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))); 2158 2159 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); 2160 double y = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))); 2161 2162 WKRetainPtr<WKStringRef> pagedKey = adoptWK(WKStringCreateWithUTF8CString("Paged")); 2163 bool paged = static_cast<bool>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, pagedKey.get())))); 2164 2165 // Forward to WebProcess 2060 auto x = doubleValue(dictionary, "X"); 2061 auto y = doubleValue(dictionary, "Y"); 2062 auto paged = booleanValue(dictionary, "Paged"); 2166 2063 m_eventSenderProxy->continuousMouseScrollBy(x, y, paged); 2167 2064 return completionHandler(nullptr); … … 2169 2066 2170 2067 if (WKStringIsEqualToUTF8CString(subMessageName, "LeapForward")) { 2171 WKRetainPtr<WKStringRef> timeKey = adoptWK(WKStringCreateWithUTF8CString("TimeInMilliseconds")); 2172 unsigned time = static_cast<unsigned>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, timeKey.get())))); 2173 2174 m_eventSenderProxy->leapForward(time); 2068 m_eventSenderProxy->leapForward(uint64Value(dictionary, "TimeInMilliseconds")); 2175 2069 return completionHandler(nullptr); 2176 2070 } … … 2178 2072 #if ENABLE(TOUCH_EVENTS) 2179 2073 if (WKStringIsEqualToUTF8CString(subMessageName, "AddTouchPoint")) { 2180 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X")); 2181 int x = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get())))); 2182 2183 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); 2184 int y = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get())))); 2185 2186 m_eventSenderProxy->addTouchPoint(x, y); 2074 m_eventSenderProxy->addTouchPoint(uint64Value(dictionary, "X"), uint64Value(dictionary, "Y")); 2187 2075 return completionHandler(nullptr); 2188 2076 } 2189 2077 2190 2078 if (WKStringIsEqualToUTF8CString(subMessageName, "UpdateTouchPoint")) { 2191 WKRetainPtr<WKStringRef> indexKey = adoptWK(WKStringCreateWithUTF8CString("Index")); 2192 int index = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, indexKey.get())))); 2193 2194 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X")); 2195 int x = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get())))); 2196 2197 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); 2198 int y = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get())))); 2199 2079 auto index = uint64Value(dictionary, "Index"); 2080 auto x = uint64Value(dictionary, "X"); 2081 auto y = uint64Value(dictionary, "Y"); 2200 2082 m_eventSenderProxy->updateTouchPoint(index, x, y); 2201 2083 return completionHandler(nullptr); … … 2203 2085 2204 2086 if (WKStringIsEqualToUTF8CString(subMessageName, "SetTouchModifier")) { 2205 WKRetainPtr<WKStringRef> modifierKey = adoptWK(WKStringCreateWithUTF8CString("Modifier")); 2206 WKEventModifiers modifier = static_cast<WKEventModifiers>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, modifierKey.get())))); 2207 2208 WKRetainPtr<WKStringRef> enableKey = adoptWK(WKStringCreateWithUTF8CString("Enable")); 2209 bool enable = static_cast<bool>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, enableKey.get())))); 2210 2087 auto modifier = uint64Value(dictionary, "Modifier"); 2088 auto enable = booleanValue(dictionary, "Enable"); 2211 2089 m_eventSenderProxy->setTouchModifier(modifier, enable); 2212 2090 return completionHandler(nullptr); … … 2214 2092 2215 2093 if (WKStringIsEqualToUTF8CString(subMessageName, "SetTouchPointRadius")) { 2216 WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("RadiusX")); 2217 int x = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get())))); 2218 2219 WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("RadiusY")); 2220 int y = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get())))); 2221 2094 auto x = uint64Value(dictionary, "RadiusX"); 2095 auto y = uint64Value(dictionary, "RadiusY"); 2222 2096 m_eventSenderProxy->setTouchPointRadius(x, y); 2223 2097 return completionHandler(nullptr); … … 2250 2124 2251 2125 if (WKStringIsEqualToUTF8CString(subMessageName, "ReleaseTouchPoint")) { 2252 WKRetainPtr<WKStringRef> indexKey = adoptWK(WKStringCreateWithUTF8CString("Index")); 2253 int index = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, indexKey.get())))); 2254 m_eventSenderProxy->releaseTouchPoint(index); 2126 m_eventSenderProxy->releaseTouchPoint(uint64Value(dictionary, "Index")); 2255 2127 return completionHandler(nullptr); 2256 2128 } 2257 2129 2258 2130 if (WKStringIsEqualToUTF8CString(subMessageName, "CancelTouchPoint")) { 2259 WKRetainPtr<WKStringRef> indexKey = adoptWK(WKStringCreateWithUTF8CString("Index")); 2260 int index = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, indexKey.get())))); 2261 m_eventSenderProxy->cancelTouchPoint(index); 2131 m_eventSenderProxy->cancelTouchPoint(uint64Value(dictionary, "Index")); 2262 2132 return completionHandler(nullptr); 2263 2133 } … … 2276 2146 2277 2147 if (WKStringIsEqualToUTF8CString(messageName, "SetAlwaysAcceptCookies")) { 2278 WKBooleanRef accept = static_cast<WKBooleanRef>(messageBody); 2279 WKHTTPCookieAcceptPolicy policy = WKBooleanGetValue(accept) ? kWKHTTPCookieAcceptPolicyAlways : kWKHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain; 2148 auto policy = WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody)) 2149 ? kWKHTTPCookieAcceptPolicyAlways 2150 : kWKHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain; 2280 2151 return setHTTPCookieAcceptPolicy(policy, WTFMove(completionHandler)); 2281 2152 } 2282 2153 2283 2154 if (WKStringIsEqualToUTF8CString(messageName, "SetOnlyAcceptFirstPartyCookies")) { 2284 WKBooleanRef accept = static_cast<WKBooleanRef>(messageBody); 2285 WKHTTPCookieAcceptPolicy policy = WKBooleanGetValue(accept) ? kWKHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain : kWKHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain; 2155 auto policy = WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody)) 2156 ? kWKHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain 2157 : kWKHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain; 2286 2158 return setHTTPCookieAcceptPolicy(policy, WTFMove(completionHandler)); 2287 2159 } … … 2404 2276 #if PLATFORM(MAC) 2405 2277 auto policy = shouldBlock ? kWKPluginLoadClientPolicyBlock : kWKPluginLoadClientPolicyAllow; 2406 2407 WKRetainPtr<WKStringRef> nameNetscape = adoptWK(WKStringCreateWithUTF8CString("com.apple.testnetscapeplugin")); 2408 WKRetainPtr<WKStringRef> nameFlash = adoptWK(WKStringCreateWithUTF8CString("com.macromedia.Flash Player.plugin")); 2409 WKRetainPtr<WKStringRef> emptyString = adoptWK(WKStringCreateWithUTF8CString("")); 2410 WKContextSetPluginLoadClientPolicy(m_context.get(), policy, emptyString.get(), nameNetscape.get(), emptyString.get()); 2411 WKContextSetPluginLoadClientPolicy(m_context.get(), policy, emptyString.get(), nameFlash.get(), emptyString.get()); 2278 WKContextSetPluginLoadClientPolicy(m_context.get(), policy, toWK("").get(), toWK("com.apple.testnetscapeplugin").get(), toWK("").get()); 2279 WKContextSetPluginLoadClientPolicy(m_context.get(), policy, toWK("").get(), toWK("com.macromedia.Flash Player.plugin").get(), toWK("").get()); 2412 2280 #endif 2413 2281 } … … 2424 2292 } 2425 2293 2426 WKRetainPtr<WKMutableArrayRef> emptyArray = adoptWK(WKMutableArrayCreate()); 2427 WKRetainPtr<WKStringRef> allOrigins = adoptWK(WKStringCreateWithUTF8CString("")); 2428 WKRetainPtr<WKStringRef> specificOrigin = adoptWK(WKStringCreateWithUTF8CString("localhost")); 2429 2430 WKRetainPtr<WKStringRef> pdfName = adoptWK(WKStringCreateWithUTF8CString("My personal PDF")); 2431 WKContextAddSupportedPlugin(m_context.get(), allOrigins.get(), pdfName.get(), emptyArray.get(), emptyArray.get()); 2432 2433 WKRetainPtr<WKStringRef> nameNetscape = adoptWK(WKStringCreateWithUTF8CString("com.apple.testnetscapeplugin")); 2434 WKRetainPtr<WKStringRef> mimeTypeNetscape = adoptWK(WKStringCreateWithUTF8CString("application/x-webkit-test-netscape")); 2435 WKRetainPtr<WKMutableArrayRef> mimeTypesNetscape = adoptWK(WKMutableArrayCreate()); 2436 WKArrayAppendItem(mimeTypesNetscape.get(), mimeTypeNetscape.get()); 2437 2438 WKRetainPtr<WKStringRef> namePdf = adoptWK(WKStringCreateWithUTF8CString("WebKit built-in PDF")); 2294 auto emptyArray = adoptWK(WKMutableArrayCreate()); 2295 2296 WKContextAddSupportedPlugin(m_context.get(), toWK("").get(), toWK("My personal PDF").get(), emptyArray.get(), emptyArray.get()); 2297 2298 auto nameNetscape = toWK("com.apple.testnetscapeplugin"); 2299 auto mimeTypesNetscape = adoptWK(WKMutableArrayCreate()); 2300 WKArrayAppendItem(mimeTypesNetscape.get(), toWK("application/x-webkit-test-netscape").get()); 2301 auto namePdf = toWK("WebKit built-in PDF"); 2439 2302 2440 2303 if (m_unsupportedPluginMode == "allOrigins") { 2441 WKContextAddSupportedPlugin(m_context.get(), allOrigins.get(), nameNetscape.get(), mimeTypesNetscape.get(), emptyArray.get());2442 WKContextAddSupportedPlugin(m_context.get(), allOrigins.get(), namePdf.get(), emptyArray.get(), emptyArray.get());2304 WKContextAddSupportedPlugin(m_context.get(), toWK("").get(), nameNetscape.get(), mimeTypesNetscape.get(), emptyArray.get()); 2305 WKContextAddSupportedPlugin(m_context.get(), toWK("").get(), namePdf.get(), emptyArray.get(), emptyArray.get()); 2443 2306 return; 2444 2307 } 2445 2308 2446 2309 if (m_unsupportedPluginMode == "specificOrigin") { 2447 WKContextAddSupportedPlugin(m_context.get(), specificOrigin.get(), nameNetscape.get(), mimeTypesNetscape.get(), emptyArray.get());2448 WKContextAddSupportedPlugin(m_context.get(), specificOrigin.get(), namePdf.get(), emptyArray.get(), emptyArray.get());2310 WKContextAddSupportedPlugin(m_context.get(), toWK("localhost").get(), nameNetscape.get(), mimeTypesNetscape.get(), emptyArray.get()); 2311 WKContextAddSupportedPlugin(m_context.get(), toWK("localhost").get(), namePdf.get(), emptyArray.get(), emptyArray.get()); 2449 2312 return; 2450 2313 } … … 2492 2355 if (m_shouldLogCanAuthenticateAgainstProtectionSpace) 2493 2356 m_currentInvocation->outputText("canAuthenticateAgainstProtectionSpace\n"); 2494 WKProtectionSpaceAuthenticationScheme authenticationScheme = WKProtectionSpaceGetAuthenticationScheme(protectionSpace); 2495 2496 if (authenticationScheme == kWKProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested) { 2497 std::string host = toSTD(adoptWK(WKProtectionSpaceCopyHost(protectionSpace)).get()); 2357 auto scheme = WKProtectionSpaceGetAuthenticationScheme(protectionSpace); 2358 if (scheme == kWKProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested) { 2359 auto host = toSTD(adoptWK(WKProtectionSpaceCopyHost(protectionSpace))); 2498 2360 return host == "localhost" || host == "127.0.0.1" || (m_allowAnyHTTPSCertificateForAllowedHosts && m_allowedHosts.find(host) != m_allowedHosts.end()); 2499 2361 } 2500 2501 return authenticationScheme <= kWKProtectionSpaceAuthenticationSchemeHTTPDigest || authenticationScheme == kWKProtectionSpaceAuthenticationSchemeOAuth; 2362 return scheme <= kWKProtectionSpaceAuthenticationSchemeHTTPDigest || scheme == kWKProtectionSpaceAuthenticationSchemeOAuth; 2502 2363 } 2503 2364 … … 2507 2368 return; 2508 2369 2509 WKRetainPtr<WKURLRef> wkURL = adoptWK(WKFrameCopyURL(WKPageGetMainFrame(page))); 2510 if (!WKURLIsEqual(wkURL.get(), blankURL())) 2370 if (!WKURLIsEqual(adoptWK(WKFrameCopyURL(WKPageGetMainFrame(page))).get(), blankURL())) 2511 2371 return; 2512 2372 … … 2528 2388 2529 2389 if (m_allowsAnySSLCertificate) { 2530 WKRetainPtr<WKCredentialRef>credential = adoptWK(WKCredentialCreate(toWK("accept server trust").get(), toWK("").get(), kWKCredentialPersistenceNone));2390 auto credential = adoptWK(WKCredentialCreate(toWK("accept server trust").get(), toWK("").get(), kWKCredentialPersistenceNone)); 2531 2391 WKAuthenticationDecisionListenerUseCredential(decisionListener, credential.get()); 2532 2392 return; … … 2542 2402 } 2543 2403 2544 std::string host = toSTD(adoptWK(WKProtectionSpaceCopyHost(protectionSpace)).get());2404 auto host = toWTFString(adoptWK(WKProtectionSpaceCopyHost(protectionSpace)).get()); 2545 2405 int port = WKProtectionSpaceGetPort(protectionSpace); 2546 String message = makeString(host .c_str(), ':', port, " - didReceiveAuthenticationChallenge - ", toString(authenticationScheme), " - ");2406 String message = makeString(host, ':', port, " - didReceiveAuthenticationChallenge - ", toString(authenticationScheme), " - "); 2547 2407 if (!m_handlesAuthenticationChallenges) 2548 2408 message.append("Simulating cancelled authentication sheet\n"); … … 2555 2415 return; 2556 2416 } 2557 WKRetainPtr<WKStringRef> username = adoptWK(WKStringCreateWithUTF8CString(m_authenticationUsername.utf8().data())); 2558 WKRetainPtr<WKStringRef> password = adoptWK(WKStringCreateWithUTF8CString(m_authenticationPassword.utf8().data())); 2559 WKRetainPtr<WKCredentialRef> credential = adoptWK(WKCredentialCreate(username.get(), password.get(), kWKCredentialPersistenceForSession)); 2417 auto credential = adoptWK(WKCredentialCreate(toWK(m_authenticationUsername).get(), toWK(m_authenticationPassword).get(), kWKCredentialPersistenceForSession)); 2560 2418 WKAuthenticationDecisionListenerUseCredential(decisionListener, credential.get()); 2561 2419 } 2562 2420 2563 2421 2564 2422 // WKContextDownloadClient 2565 2423 … … 2705 2563 } 2706 2564 2707 void TestController::setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed, bool providesFloorLevel, doublefloorLevel)2708 { 2709 m_geolocationProvider->setPosition(latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed, providesFloorLevel, floorLevel);2565 void TestController::setMockGeolocationPosition(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitudeAccuracy, Optional<double> heading, Optional<double> speed, Optional<double> floorLevel) 2566 { 2567 m_geolocationProvider->setPosition(latitude, longitude, accuracy, altitude, altitudeAccuracy, heading, speed, floorLevel); 2710 2568 } 2711 2569 … … 2857 2715 auto originHash = userMediaOriginHash(userMediaDocumentOrigin, topLevelDocumentOrigin); 2858 2716 auto salt = saltForOrigin(frame, originHash); 2859 WKRetainPtr<WKStringRef> saltString = adoptWK(WKStringCreateWithUTF8CString(salt.utf8().data())); 2860 2861 WKUserMediaPermissionCheckSetUserMediaAccessInfo(checkRequest, saltString.get(), settingsForOrigin(originHash).persistentPermission()); 2717 WKUserMediaPermissionCheckSetUserMediaAccessInfo(checkRequest, toWK(salt).get(), settingsForOrigin(originHash).persistentPermission()); 2862 2718 } 2863 2719 … … 2915 2771 } 2916 2772 2917 WKRetainPtr<WKArrayRef>audioDeviceUIDs = adoptWK(WKUserMediaPermissionRequestAudioDeviceUIDs(request));2918 WKRetainPtr<WKArrayRef>videoDeviceUIDs = adoptWK(WKUserMediaPermissionRequestVideoDeviceUIDs(request));2773 auto audioDeviceUIDs = adoptWK(WKUserMediaPermissionRequestAudioDeviceUIDs(request)); 2774 auto videoDeviceUIDs = adoptWK(WKUserMediaPermissionRequestVideoDeviceUIDs(request)); 2919 2775 2920 2776 if (!WKArrayGetSize(videoDeviceUIDs.get()) && !WKArrayGetSize(audioDeviceUIDs.get())) { … … 2927 2783 videoDeviceUID = reinterpret_cast<WKStringRef>(WKArrayGetItemAtIndex(videoDeviceUIDs.get(), 0)); 2928 2784 else 2929 videoDeviceUID = adoptWK(WKStringCreateWithUTF8CString(""));2785 videoDeviceUID = toWK(""); 2930 2786 2931 2787 WKRetainPtr<WKStringRef> audioDeviceUID; … … 2933 2789 audioDeviceUID = reinterpret_cast<WKStringRef>(WKArrayGetItemAtIndex(audioDeviceUIDs.get(), 0)); 2934 2790 else 2935 audioDeviceUID = adoptWK(WKStringCreateWithUTF8CString(""));2791 audioDeviceUID = toWK(""); 2936 2792 2937 2793 WKUserMediaPermissionRequestAllow(request, audioDeviceUID.get(), videoDeviceUID.get()); … … 3057 2913 return; 3058 2914 3059 // URL3060 2915 auto url = adoptWK(WKNavigationDataCopyURL(navigationData)); 3061 2916 auto urlString = toWTFString(adoptWK(WKURLCopyString(url.get()))); 3062 // Title3063 2917 auto title = toWTFString(adoptWK(WKNavigationDataCopyTitle(navigationData))); 3064 // HTTP method3065 2918 auto request = adoptWK(WKNavigationDataCopyOriginalRequest(navigationData)); 3066 2919 auto method = toWTFString(adoptWK(WKURLRequestCopyHTTPMethod(request.get()))); … … 3207 3060 Vector<String> resultDomains; 3208 3061 for (unsigned i = 0; i < WKArrayGetSize(domainList); i++) { 3209 auto domain = 3062 auto domain = reinterpret_cast<WKStringRef>(WKArrayGetItemAtIndex(domainList, i)); 3210 3063 auto buffer = std::vector<char>(WKStringGetMaximumUTF8CStringSize(domain)); 3211 3064 auto stringLength = WKStringGetUTF8CString(domain, buffer.data(), buffer.size()); … … 3972 3825 { 3973 3826 InAppBrowserPrivacyCallbackContext context(*this); 3974 WKWebsiteDataStoreUpdateBundleIdentifierInNetworkProcess(TestController::websiteDataStore(), adoptWK(WKStringCreateWithUTF8CString(bundleIdentifier.utf8().data())).get(), &context, inAppBrowserPrivacyVoidResultCallback);3827 WKWebsiteDataStoreUpdateBundleIdentifierInNetworkProcess(TestController::websiteDataStore(), toWK(bundleIdentifier).get(), &context, inAppBrowserPrivacyVoidResultCallback); 3975 3828 runUntil(context.done, noTimeout); 3976 3829 } -
TabularUnified trunk/Tools/WebKitTestRunner/TestController.h ¶
r267750 r267761 141 141 // Geolocation. 142 142 void setGeolocationPermission(bool); 143 void setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed, bool providesFloorLevel, doublefloorLevel);143 void setMockGeolocationPosition(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitudeAccuracy, Optional<double> heading, Optional<double> speed, Optional<double> floorLevel); 144 144 void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage); 145 145 void handleGeolocationPermissionRequest(WKGeolocationPermissionRequestRef); -
TabularUnified trunk/Tools/WebKitTestRunner/TestInvocation.cpp ¶
r267750 r267761 28 28 #include "TestInvocation.h" 29 29 30 #include "DictionaryFunctions.h" 30 31 #include "PlatformWebView.h" 31 #include "StringFunctions.h"32 32 #include "TestController.h" 33 33 #include "UIScriptController.h" … … 67 67 namespace WTR { 68 68 69 static void postPageMessage(const char* name, const WKRetainPtr<WKTypeRef>& body) 70 { 71 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), toWK(name).get(), body.get()); 72 } 73 74 static void postPageMessage(const char* name) 75 { 76 postPageMessage(name, WKRetainPtr<WKTypeRef> { }); 77 } 78 69 79 TestInvocation::TestInvocation(WKURLRef url, const TestOptions& options) 70 80 : m_options(options) … … 72 82 , m_waitToDumpWatchdogTimer(RunLoop::main(), this, &TestInvocation::waitToDumpWatchdogTimerFired) 73 83 { 74 WKRetainPtr<WKStringRef> urlString = adoptWK(WKURLCopyString(m_url.get())); 75 76 size_t stringLength = WKStringGetLength(urlString.get()); 77 78 Vector<char> urlVector; 79 urlVector.resize(stringLength + 1); 80 81 WKStringGetUTF8CString(urlString.get(), urlVector.data(), stringLength + 1); 82 83 m_urlString = String(urlVector.data(), stringLength); 84 m_urlString = toWTFString(adoptWK(WKURLCopyString(m_url.get())).get()); 84 85 85 86 // FIXME: Avoid mutating the setting via a test directory like this. … … 130 131 WKRetainPtr<WKMutableDictionaryRef> TestInvocation::createTestSettingsDictionary() 131 132 { 132 WKRetainPtr<WKMutableDictionaryRef> beginTestMessageBody = adoptWK(WKMutableDictionaryCreate()); 133 134 WKRetainPtr<WKStringRef> useFlexibleViewportKey = adoptWK(WKStringCreateWithUTF8CString("UseFlexibleViewport")); 135 WKRetainPtr<WKBooleanRef> useFlexibleViewportValue = adoptWK(WKBooleanCreate(options().useFlexibleViewport)); 136 WKDictionarySetItem(beginTestMessageBody.get(), useFlexibleViewportKey.get(), useFlexibleViewportValue.get()); 137 138 WKRetainPtr<WKStringRef> dumpPixelsKey = adoptWK(WKStringCreateWithUTF8CString("DumpPixels")); 139 WKRetainPtr<WKBooleanRef> dumpPixelsValue = adoptWK(WKBooleanCreate(m_dumpPixels)); 140 WKDictionarySetItem(beginTestMessageBody.get(), dumpPixelsKey.get(), dumpPixelsValue.get()); 141 142 WKRetainPtr<WKStringRef> timeoutKey = adoptWK(WKStringCreateWithUTF8CString("Timeout")); 143 WKRetainPtr<WKUInt64Ref> timeoutValue = adoptWK(WKUInt64Create(m_timeout.milliseconds())); 144 WKDictionarySetItem(beginTestMessageBody.get(), timeoutKey.get(), timeoutValue.get()); 145 146 WKRetainPtr<WKStringRef> dumpJSConsoleLogInStdErrKey = adoptWK(WKStringCreateWithUTF8CString("DumpJSConsoleLogInStdErr")); 147 WKRetainPtr<WKBooleanRef> dumpJSConsoleLogInStdErrValue = adoptWK(WKBooleanCreate(m_dumpJSConsoleLogInStdErr)); 148 WKDictionarySetItem(beginTestMessageBody.get(), dumpJSConsoleLogInStdErrKey.get(), dumpJSConsoleLogInStdErrValue.get()); 149 150 WKRetainPtr<WKStringRef> additionalSupportedImageTypesKey = adoptWK(WKStringCreateWithUTF8CString("additionalSupportedImageTypes")); 151 WKRetainPtr<WKStringRef> additionalSupportedImageTypesValue = adoptWK(WKStringCreateWithUTF8CString(options().additionalSupportedImageTypes.c_str())); 152 WKDictionarySetItem(beginTestMessageBody.get(), additionalSupportedImageTypesKey.get(), additionalSupportedImageTypesValue.get()); 153 133 auto beginTestMessageBody = adoptWK(WKMutableDictionaryCreate()); 134 setValue(beginTestMessageBody, "UseFlexibleViewport", options().useFlexibleViewport); 135 setValue(beginTestMessageBody, "DumpPixels", m_dumpPixels); 136 setValue(beginTestMessageBody, "Timeout", static_cast<uint64_t>(m_timeout.milliseconds())); 137 setValue(beginTestMessageBody, "DumpJSConsoleLogInStdErr", m_dumpJSConsoleLogInStdErr); 138 setValue(beginTestMessageBody, "additionalSupportedImageTypes", options().additionalSupportedImageTypes.c_str()); 154 139 return beginTestMessageBody; 155 140 } … … 169 154 // FIXME: We should clear out visited links here. 170 155 171 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("BeginTest")); 172 auto beginTestMessageBody = createTestSettingsDictionary(); 173 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), beginTestMessageBody.get()); 156 postPageMessage("BeginTest", createTestSettingsDictionary()); 174 157 175 158 m_startedTesting = true; … … 328 311 329 312 if (WKStringIsEqualToUTF8CString(messageName, "Ack")) { 330 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 331 WKStringRef messageBodyString = static_cast<WKStringRef>(messageBody); 332 if (WKStringIsEqualToUTF8CString(messageBodyString, "BeginTest")) { 313 if (WKStringIsEqualToUTF8CString(stringValue(messageBody), "BeginTest")) { 333 314 m_gotInitialResponse = true; 334 315 TestController::singleton().notifyDone(); 335 316 return; 336 317 } 337 338 318 ASSERT_NOT_REACHED(); 339 319 } 340 320 341 321 if (WKStringIsEqualToUTF8CString(messageName, "Done")) { 342 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 343 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 344 345 WKRetainPtr<WKStringRef> pixelResultIsPendingKey = adoptWK(WKStringCreateWithUTF8CString("PixelResultIsPending")); 346 WKBooleanRef pixelResultIsPending = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, pixelResultIsPendingKey.get())); 347 m_pixelResultIsPending = WKBooleanGetValue(pixelResultIsPending); 348 322 auto messageBodyDictionary = dictionaryValue(messageBody); 323 m_pixelResultIsPending = booleanValue(messageBodyDictionary, "PixelResultIsPending"); 349 324 if (!m_pixelResultIsPending) { 350 WKRetainPtr<WKStringRef> pixelResultKey = adoptWK(WKStringCreateWithUTF8CString("PixelResult")); 351 m_pixelResult = static_cast<WKImageRef>(WKDictionaryGetItemForKey(messageBodyDictionary, pixelResultKey.get())); 325 m_pixelResult = static_cast<WKImageRef>(value(messageBodyDictionary, "PixelResult")); 352 326 ASSERT(!m_pixelResult || m_dumpPixels); 353 327 } 354 355 WKRetainPtr<WKStringRef> repaintRectsKey = adoptWK(WKStringCreateWithUTF8CString("RepaintRects")); 356 m_repaintRects = static_cast<WKArrayRef>(WKDictionaryGetItemForKey(messageBodyDictionary, repaintRectsKey.get())); 357 358 WKRetainPtr<WKStringRef> audioResultKey = adoptWK(WKStringCreateWithUTF8CString("AudioResult")); 359 m_audioResult = static_cast<WKDataRef>(WKDictionaryGetItemForKey(messageBodyDictionary, audioResultKey.get())); 360 328 m_repaintRects = static_cast<WKArrayRef>(value(messageBodyDictionary, "RepaintRects")); 329 m_audioResult = static_cast<WKDataRef>(value(messageBodyDictionary, "AudioResult")); 361 330 done(); 362 331 return; … … 364 333 365 334 if (WKStringIsEqualToUTF8CString(messageName, "TextOutput")) { 366 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 367 WKStringRef textOutput = static_cast<WKStringRef>(messageBody); 368 m_textOutput.append(toWTFString(textOutput)); 335 m_textOutput.append(toWTFString(stringValue(messageBody))); 369 336 return; 370 337 } 371 338 372 339 if (WKStringIsEqualToUTF8CString(messageName, "DumpToStdErr")) { 373 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 374 WKStringRef textOutput = static_cast<WKStringRef>(messageBody); 375 fprintf(stderr, "%s", toWTFString(textOutput).utf8().data()); 340 fprintf(stderr, "%s", toWTFString(stringValue(messageBody)).utf8().data()); 376 341 return; 377 342 } 378 343 379 344 if (WKStringIsEqualToUTF8CString(messageName, "BeforeUnloadReturnValue")) { 380 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 381 WKBooleanRef beforeUnloadReturnValue = static_cast<WKBooleanRef>(messageBody); 382 TestController::singleton().setBeforeUnloadReturnValue(WKBooleanGetValue(beforeUnloadReturnValue)); 345 TestController::singleton().setBeforeUnloadReturnValue(booleanValue(messageBody)); 383 346 return; 384 347 } … … 386 349 if (WKStringIsEqualToUTF8CString(messageName, "AddChromeInputField")) { 387 350 TestController::singleton().mainWebView()->addChromeInputField(); 388 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallAddChromeInputFieldCallback")); 389 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 351 postPageMessage("CallAddChromeInputFieldCallback"); 390 352 return; 391 353 } … … 393 355 if (WKStringIsEqualToUTF8CString(messageName, "RemoveChromeInputField")) { 394 356 TestController::singleton().mainWebView()->removeChromeInputField(); 395 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallRemoveChromeInputFieldCallback")); 396 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 357 postPageMessage("CallRemoveChromeInputFieldCallback"); 397 358 return; 398 359 } … … 400 361 if (WKStringIsEqualToUTF8CString(messageName, "FocusWebView")) { 401 362 TestController::singleton().mainWebView()->makeWebViewFirstResponder(); 402 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallFocusWebViewCallback")); 403 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 363 postPageMessage("CallFocusWebViewCallback"); 404 364 return; 405 365 } 406 366 407 367 if (WKStringIsEqualToUTF8CString(messageName, "SetBackingScaleFactor")) { 408 ASSERT(WKGetTypeID(messageBody) == WKDoubleGetTypeID()); 409 double backingScaleFactor = WKDoubleGetValue(static_cast<WKDoubleRef>(messageBody)); 410 WKPageSetCustomBackingScaleFactor(TestController::singleton().mainWebView()->page(), backingScaleFactor); 411 412 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallSetBackingScaleFactorCallback")); 413 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 368 WKPageSetCustomBackingScaleFactor(TestController::singleton().mainWebView()->page(), doubleValue(messageBody)); 369 postPageMessage("CallSetBackingScaleFactorCallback"); 414 370 return; 415 371 } 416 372 417 373 if (WKStringIsEqualToUTF8CString(messageName, "SimulateWebNotificationClick")) { 418 ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID()); 419 uint64_t notificationID = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody)); 374 uint64_t notificationID = uint64Value(messageBody); 420 375 TestController::singleton().simulateWebNotificationClick(notificationID); 421 376 return; … … 423 378 424 379 if (WKStringIsEqualToUTF8CString(messageName, "SetAddsVisitedLinks")) { 425 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 426 WKBooleanRef enabledWK = static_cast<WKBooleanRef>(messageBody); 427 WKPageSetAddsVisitedLinks(TestController::singleton().mainWebView()->page(), WKBooleanGetValue(enabledWK)); 380 WKPageSetAddsVisitedLinks(TestController::singleton().mainWebView()->page(), booleanValue(messageBody)); 428 381 return; 429 382 } 430 383 431 384 if (WKStringIsEqualToUTF8CString(messageName, "SetGeolocationPermission")) { 432 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 433 WKBooleanRef enabledWK = static_cast<WKBooleanRef>(messageBody); 434 TestController::singleton().setGeolocationPermission(WKBooleanGetValue(enabledWK)); 385 TestController::singleton().setGeolocationPermission(booleanValue(messageBody)); 435 386 return; 436 387 } 437 388 438 389 if (WKStringIsEqualToUTF8CString(messageName, "SetMockGeolocationPosition")) { 439 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 440 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 441 442 WKRetainPtr<WKStringRef> latitudeKeyWK = adoptWK(WKStringCreateWithUTF8CString("latitude")); 443 WKDoubleRef latitudeWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, latitudeKeyWK.get())); 444 double latitude = WKDoubleGetValue(latitudeWK); 445 446 WKRetainPtr<WKStringRef> longitudeKeyWK = adoptWK(WKStringCreateWithUTF8CString("longitude")); 447 WKDoubleRef longitudeWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, longitudeKeyWK.get())); 448 double longitude = WKDoubleGetValue(longitudeWK); 449 450 WKRetainPtr<WKStringRef> accuracyKeyWK = adoptWK(WKStringCreateWithUTF8CString("accuracy")); 451 WKDoubleRef accuracyWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, accuracyKeyWK.get())); 452 double accuracy = WKDoubleGetValue(accuracyWK); 453 454 WKRetainPtr<WKStringRef> providesAltitudeKeyWK = adoptWK(WKStringCreateWithUTF8CString("providesAltitude")); 455 WKBooleanRef providesAltitudeWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesAltitudeKeyWK.get())); 456 bool providesAltitude = WKBooleanGetValue(providesAltitudeWK); 457 458 WKRetainPtr<WKStringRef> altitudeKeyWK = adoptWK(WKStringCreateWithUTF8CString("altitude")); 459 WKDoubleRef altitudeWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, altitudeKeyWK.get())); 460 double altitude = WKDoubleGetValue(altitudeWK); 461 462 WKRetainPtr<WKStringRef> providesAltitudeAccuracyKeyWK = adoptWK(WKStringCreateWithUTF8CString("providesAltitudeAccuracy")); 463 WKBooleanRef providesAltitudeAccuracyWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesAltitudeAccuracyKeyWK.get())); 464 bool providesAltitudeAccuracy = WKBooleanGetValue(providesAltitudeAccuracyWK); 465 466 WKRetainPtr<WKStringRef> altitudeAccuracyKeyWK = adoptWK(WKStringCreateWithUTF8CString("altitudeAccuracy")); 467 WKDoubleRef altitudeAccuracyWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, altitudeAccuracyKeyWK.get())); 468 double altitudeAccuracy = WKDoubleGetValue(altitudeAccuracyWK); 469 470 WKRetainPtr<WKStringRef> providesHeadingKeyWK = adoptWK(WKStringCreateWithUTF8CString("providesHeading")); 471 WKBooleanRef providesHeadingWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesHeadingKeyWK.get())); 472 bool providesHeading = WKBooleanGetValue(providesHeadingWK); 473 474 WKRetainPtr<WKStringRef> headingKeyWK = adoptWK(WKStringCreateWithUTF8CString("heading")); 475 WKDoubleRef headingWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, headingKeyWK.get())); 476 double heading = WKDoubleGetValue(headingWK); 477 478 WKRetainPtr<WKStringRef> providesSpeedKeyWK = adoptWK(WKStringCreateWithUTF8CString("providesSpeed")); 479 WKBooleanRef providesSpeedWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesSpeedKeyWK.get())); 480 bool providesSpeed = WKBooleanGetValue(providesSpeedWK); 481 482 WKRetainPtr<WKStringRef> speedKeyWK = adoptWK(WKStringCreateWithUTF8CString("speed")); 483 WKDoubleRef speedWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, speedKeyWK.get())); 484 double speed = WKDoubleGetValue(speedWK); 485 486 WKRetainPtr<WKStringRef> providesFloorLevelKeyWK = adoptWK(WKStringCreateWithUTF8CString("providesFloorLevel")); 487 WKBooleanRef providesFloorLevelWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, providesFloorLevelKeyWK.get())); 488 bool providesFloorLevel = WKBooleanGetValue(providesFloorLevelWK); 489 490 WKRetainPtr<WKStringRef> floorLevelKeyWK = adoptWK(WKStringCreateWithUTF8CString("floorLevel")); 491 WKDoubleRef floorLevelWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, floorLevelKeyWK.get())); 492 double floorLevel = WKDoubleGetValue(floorLevelWK); 493 494 TestController::singleton().setMockGeolocationPosition(latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed, providesFloorLevel, floorLevel); 390 auto messageBodyDictionary = dictionaryValue(messageBody); 391 auto latitude = doubleValue(messageBodyDictionary, "latitude"); 392 auto longitude = doubleValue(messageBodyDictionary, "longitude"); 393 auto accuracy = doubleValue(messageBodyDictionary, "accuracy"); 394 auto altitude = optionalDoubleValue(messageBodyDictionary, "altitude"); 395 auto altitudeAccuracy = optionalDoubleValue(messageBodyDictionary, "altitudeAccuracy"); 396 auto heading = optionalDoubleValue(messageBodyDictionary, "heading"); 397 auto speed = optionalDoubleValue(messageBodyDictionary, "speed"); 398 auto floorLevel = optionalDoubleValue(messageBodyDictionary, "floorLevel"); 399 TestController::singleton().setMockGeolocationPosition(latitude, longitude, accuracy, altitude, altitudeAccuracy, heading, speed, floorLevel); 495 400 return; 496 401 } 497 402 498 403 if (WKStringIsEqualToUTF8CString(messageName, "SetMockGeolocationPositionUnavailableError")) { 499 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 500 WKStringRef errorMessage = static_cast<WKStringRef>(messageBody); 404 WKStringRef errorMessage = stringValue(messageBody); 501 405 TestController::singleton().setMockGeolocationPositionUnavailableError(errorMessage); 502 406 return; … … 504 408 505 409 if (WKStringIsEqualToUTF8CString(messageName, "SetUserMediaPermission")) { 506 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 507 WKBooleanRef enabledWK = static_cast<WKBooleanRef>(messageBody); 508 TestController::singleton().setUserMediaPermission(WKBooleanGetValue(enabledWK)); 410 TestController::singleton().setUserMediaPermission(booleanValue(messageBody)); 509 411 return; 510 412 } … … 516 418 517 419 if (WKStringIsEqualToUTF8CString(messageName, "SetUserMediaPersistentPermissionForOrigin")) { 518 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 519 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 520 521 WKRetainPtr<WKStringRef> permissionKeyWK = adoptWK(WKStringCreateWithUTF8CString("permission")); 522 WKBooleanRef permissionWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, permissionKeyWK.get())); 523 bool permission = WKBooleanGetValue(permissionWK); 524 525 WKRetainPtr<WKStringRef> originKey = adoptWK(WKStringCreateWithUTF8CString("origin")); 526 WKStringRef originWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, originKey.get())); 527 528 WKRetainPtr<WKStringRef> parentOriginKey = adoptWK(WKStringCreateWithUTF8CString("parentOrigin")); 529 WKStringRef parentOriginWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, parentOriginKey.get())); 530 420 auto messageBodyDictionary = dictionaryValue(messageBody); 421 auto permission = booleanValue(messageBodyDictionary, "permission"); 422 auto originWK = stringValue(messageBodyDictionary, "origin"); 423 auto parentOriginWK = stringValue(messageBodyDictionary, "parentOrigin"); 531 424 TestController::singleton().setUserMediaPersistentPermissionForOrigin(permission, originWK, parentOriginWK); 532 425 return; … … 534 427 535 428 if (WKStringIsEqualToUTF8CString(messageName, "ResetUserMediaPermissionRequestCountForOrigin")) { 536 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 537 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 538 539 WKRetainPtr<WKStringRef> originKey = adoptWK(WKStringCreateWithUTF8CString("origin")); 540 WKStringRef originWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, originKey.get())); 541 542 WKRetainPtr<WKStringRef> parentOriginKey = adoptWK(WKStringCreateWithUTF8CString("parentOrigin")); 543 WKStringRef parentOriginWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, parentOriginKey.get())); 544 429 auto messageBodyDictionary = dictionaryValue(messageBody); 430 auto originWK = stringValue(messageBodyDictionary, "origin"); 431 auto parentOriginWK = stringValue(messageBodyDictionary, "parentOrigin"); 545 432 TestController::singleton().resetUserMediaPermissionRequestCountForOrigin(originWK, parentOriginWK); 546 433 return; … … 548 435 549 436 if (WKStringIsEqualToUTF8CString(messageName, "SetCustomPolicyDelegate")) { 550 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 551 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 552 553 WKRetainPtr<WKStringRef> enabledKeyWK = adoptWK(WKStringCreateWithUTF8CString("enabled")); 554 WKBooleanRef enabledWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, enabledKeyWK.get())); 555 bool enabled = WKBooleanGetValue(enabledWK); 556 557 WKRetainPtr<WKStringRef> permissiveKeyWK = adoptWK(WKStringCreateWithUTF8CString("permissive")); 558 WKBooleanRef permissiveWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, permissiveKeyWK.get())); 559 bool permissive = WKBooleanGetValue(permissiveWK); 560 437 auto messageBodyDictionary = dictionaryValue(messageBody); 438 auto enabled = booleanValue(messageBodyDictionary, "enabled"); 439 auto permissive = booleanValue(messageBodyDictionary, "permissive"); 561 440 TestController::singleton().setCustomPolicyDelegate(enabled, permissive); 562 441 return; … … 564 443 565 444 if (WKStringIsEqualToUTF8CString(messageName, "SetHidden")) { 566 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 567 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 568 569 WKRetainPtr<WKStringRef> isInitialKeyWK = adoptWK(WKStringCreateWithUTF8CString("hidden")); 570 WKBooleanRef hiddenWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, isInitialKeyWK.get())); 571 bool hidden = WKBooleanGetValue(hiddenWK); 572 573 TestController::singleton().setHidden(hidden); 445 auto messageBodyDictionary = dictionaryValue(messageBody); 446 TestController::singleton().setHidden(booleanValue(messageBodyDictionary, "hidden")); 574 447 return; 575 448 } 576 449 577 450 if (WKStringIsEqualToUTF8CString(messageName, "ProcessWorkQueue")) { 578 if (TestController::singleton().workQueueManager().processWorkQueue()) { 579 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("WorkQueueProcessedCallback")); 580 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 581 } 451 if (TestController::singleton().workQueueManager().processWorkQueue()) 452 postPageMessage("WorkQueueProcessedCallback"); 582 453 return; 583 454 } 584 455 585 456 if (WKStringIsEqualToUTF8CString(messageName, "QueueBackNavigation")) { 586 ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID()); 587 uint64_t stepCount = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody)); 588 TestController::singleton().workQueueManager().queueBackNavigation(stepCount); 457 TestController::singleton().workQueueManager().queueBackNavigation(uint64Value(messageBody)); 589 458 return; 590 459 } 591 460 592 461 if (WKStringIsEqualToUTF8CString(messageName, "QueueForwardNavigation")) { 593 ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID()); 594 uint64_t stepCount = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody)); 595 TestController::singleton().workQueueManager().queueForwardNavigation(stepCount); 462 TestController::singleton().workQueueManager().queueForwardNavigation(uint64Value(messageBody)); 596 463 return; 597 464 } 598 465 599 466 if (WKStringIsEqualToUTF8CString(messageName, "QueueLoad")) { 600 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 601 WKDictionaryRef loadDataDictionary = static_cast<WKDictionaryRef>(messageBody); 602 603 WKRetainPtr<WKStringRef> urlKey = adoptWK(WKStringCreateWithUTF8CString("url")); 604 WKStringRef urlWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, urlKey.get())); 605 606 WKRetainPtr<WKStringRef> targetKey = adoptWK(WKStringCreateWithUTF8CString("target")); 607 WKStringRef targetWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, targetKey.get())); 608 609 WKRetainPtr<WKStringRef> shouldOpenExternalURLsKey = adoptWK(WKStringCreateWithUTF8CString("shouldOpenExternalURLs")); 610 WKBooleanRef shouldOpenExternalURLsValueWK = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(loadDataDictionary, shouldOpenExternalURLsKey.get())); 611 612 TestController::singleton().workQueueManager().queueLoad(toWTFString(urlWK), toWTFString(targetWK), WKBooleanGetValue(shouldOpenExternalURLsValueWK)); 467 auto loadDataDictionary = dictionaryValue(messageBody); 468 auto url = toWTFString(stringValue(loadDataDictionary, "url")); 469 auto target = toWTFString(stringValue(loadDataDictionary, "target")); 470 auto shouldOpenExternalURLs = booleanValue(loadDataDictionary, "shouldOpenExternalURLs"); 471 TestController::singleton().workQueueManager().queueLoad(url, target, shouldOpenExternalURLs); 613 472 return; 614 473 } 615 474 616 475 if (WKStringIsEqualToUTF8CString(messageName, "QueueLoadHTMLString")) { 617 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 618 WKDictionaryRef loadDataDictionary = static_cast<WKDictionaryRef>(messageBody); 619 620 WKRetainPtr<WKStringRef> contentKey = adoptWK(WKStringCreateWithUTF8CString("content")); 621 WKStringRef contentWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, contentKey.get())); 622 623 WKRetainPtr<WKStringRef> baseURLKey = adoptWK(WKStringCreateWithUTF8CString("baseURL")); 624 WKStringRef baseURLWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, baseURLKey.get())); 625 626 WKRetainPtr<WKStringRef> unreachableURLKey = adoptWK(WKStringCreateWithUTF8CString("unreachableURL")); 627 WKStringRef unreachableURLWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(loadDataDictionary, unreachableURLKey.get())); 628 476 auto loadDataDictionary = dictionaryValue(messageBody); 477 auto contentWK = stringValue(loadDataDictionary, "content"); 478 auto baseURLWK = stringValue(loadDataDictionary, "baseURL"); 479 auto unreachableURLWK = stringValue(loadDataDictionary, "unreachableURL"); 629 480 TestController::singleton().workQueueManager().queueLoadHTMLString(toWTFString(contentWK), baseURLWK ? toWTFString(baseURLWK) : String(), unreachableURLWK ? toWTFString(unreachableURLWK) : String()); 630 481 return; … … 637 488 638 489 if (WKStringIsEqualToUTF8CString(messageName, "QueueLoadingScript")) { 639 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 640 WKStringRef script = static_cast<WKStringRef>(messageBody); 490 WKStringRef script = stringValue(messageBody); 641 491 TestController::singleton().workQueueManager().queueLoadingScript(toWTFString(script)); 642 492 return; … … 644 494 645 495 if (WKStringIsEqualToUTF8CString(messageName, "QueueNonLoadingScript")) { 646 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 647 WKStringRef script = static_cast<WKStringRef>(messageBody); 496 WKStringRef script = stringValue(messageBody); 648 497 TestController::singleton().workQueueManager().queueNonLoadingScript(toWTFString(script)); 649 498 return; … … 651 500 652 501 if (WKStringIsEqualToUTF8CString(messageName, "SetRejectsProtectionSpaceAndContinueForAuthenticationChallenges")) { 653 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 654 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 655 TestController::singleton().setRejectsProtectionSpaceAndContinueForAuthenticationChallenges(WKBooleanGetValue(value)); 502 TestController::singleton().setRejectsProtectionSpaceAndContinueForAuthenticationChallenges(booleanValue(messageBody)); 656 503 return; 657 504 } 658 505 659 506 if (WKStringIsEqualToUTF8CString(messageName, "SetHandlesAuthenticationChallenges")) { 660 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 661 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 662 TestController::singleton().setHandlesAuthenticationChallenges(WKBooleanGetValue(value)); 507 TestController::singleton().setHandlesAuthenticationChallenges(booleanValue(messageBody)); 663 508 return; 664 509 } 665 510 666 511 if (WKStringIsEqualToUTF8CString(messageName, "SetShouldLogCanAuthenticateAgainstProtectionSpace")) { 667 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 668 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 669 TestController::singleton().setShouldLogCanAuthenticateAgainstProtectionSpace(WKBooleanGetValue(value)); 512 TestController::singleton().setShouldLogCanAuthenticateAgainstProtectionSpace(booleanValue(messageBody)); 670 513 return; 671 514 } 672 515 673 516 if (WKStringIsEqualToUTF8CString(messageName, "SetShouldLogDownloadCallbacks")) { 674 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 675 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 676 TestController::singleton().setShouldLogDownloadCallbacks(WKBooleanGetValue(value)); 517 TestController::singleton().setShouldLogDownloadCallbacks(booleanValue(messageBody)); 677 518 return; 678 519 } 679 520 680 521 if (WKStringIsEqualToUTF8CString(messageName, "SetAuthenticationUsername")) { 681 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 682 WKStringRef username = static_cast<WKStringRef>(messageBody); 522 WKStringRef username = stringValue(messageBody); 683 523 TestController::singleton().setAuthenticationUsername(toWTFString(username)); 684 524 return; … … 686 526 687 527 if (WKStringIsEqualToUTF8CString(messageName, "SetAuthenticationPassword")) { 688 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 689 WKStringRef password = static_cast<WKStringRef>(messageBody); 528 WKStringRef password = stringValue(messageBody); 690 529 TestController::singleton().setAuthenticationPassword(toWTFString(password)); 691 530 return; … … 693 532 694 533 if (WKStringIsEqualToUTF8CString(messageName, "SetBlockAllPlugins")) { 695 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 696 WKBooleanRef shouldBlock = static_cast<WKBooleanRef>(messageBody); 697 TestController::singleton().setBlockAllPlugins(WKBooleanGetValue(shouldBlock)); 534 TestController::singleton().setBlockAllPlugins(booleanValue(messageBody)); 698 535 return; 699 536 } 700 537 701 538 if (WKStringIsEqualToUTF8CString(messageName, "SetPluginSupportedMode")) { 702 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 703 WKStringRef mode = static_cast<WKStringRef>(messageBody); 539 WKStringRef mode = stringValue(messageBody); 704 540 TestController::singleton().setPluginSupportedMode(toWTFString(mode)); 705 541 return; … … 707 543 708 544 if (WKStringIsEqualToUTF8CString(messageName, "SetShouldDecideNavigationPolicyAfterDelay")) { 709 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 710 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 711 TestController::singleton().setShouldDecideNavigationPolicyAfterDelay(WKBooleanGetValue(value)); 545 TestController::singleton().setShouldDecideNavigationPolicyAfterDelay(booleanValue(messageBody)); 712 546 return; 713 547 } 714 548 715 549 if (WKStringIsEqualToUTF8CString(messageName, "SetShouldDecideResponsePolicyAfterDelay")) { 716 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 717 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 718 TestController::singleton().setShouldDecideResponsePolicyAfterDelay(WKBooleanGetValue(value)); 550 TestController::singleton().setShouldDecideResponsePolicyAfterDelay(booleanValue(messageBody)); 719 551 return; 720 552 } 721 553 722 554 if (WKStringIsEqualToUTF8CString(messageName, "SetNavigationGesturesEnabled")) { 723 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 724 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 725 TestController::singleton().setNavigationGesturesEnabled(WKBooleanGetValue(value)); 555 TestController::singleton().setNavigationGesturesEnabled(booleanValue(messageBody)); 726 556 return; 727 557 } 728 558 729 559 if (WKStringIsEqualToUTF8CString(messageName, "SetIgnoresViewportScaleLimits")) { 730 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 731 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 732 TestController::singleton().setIgnoresViewportScaleLimits(WKBooleanGetValue(value)); 560 TestController::singleton().setIgnoresViewportScaleLimits(booleanValue(messageBody)); 733 561 return; 734 562 } 735 563 736 564 if (WKStringIsEqualToUTF8CString(messageName, "SetShouldDownloadUndisplayableMIMETypes")) { 737 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 738 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 739 TestController::singleton().setShouldDownloadUndisplayableMIMETypes(WKBooleanGetValue(value)); 565 TestController::singleton().setShouldDownloadUndisplayableMIMETypes(booleanValue(messageBody)); 740 566 return; 741 567 } 742 568 743 569 if (WKStringIsEqualToUTF8CString(messageName, "SetShouldAllowDeviceOrientationAndMotionAccess")) { 744 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 745 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 746 TestController::singleton().setShouldAllowDeviceOrientationAndMotionAccess(WKBooleanGetValue(value)); 570 TestController::singleton().setShouldAllowDeviceOrientationAndMotionAccess(booleanValue(messageBody)); 747 571 return; 748 572 } 749 573 750 574 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsShouldBlockThirdPartyCookiesOnSitesWithoutUserInteraction")) { 751 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 752 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 753 TestController::singleton().setStatisticsShouldBlockThirdPartyCookies(WKBooleanGetValue(value), true); 575 TestController::singleton().setStatisticsShouldBlockThirdPartyCookies(booleanValue(messageBody), true); 754 576 return; 755 577 } 756 578 757 579 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsShouldBlockThirdPartyCookies")) { 758 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 759 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 760 TestController::singleton().setStatisticsShouldBlockThirdPartyCookies(WKBooleanGetValue(value), false); 580 TestController::singleton().setStatisticsShouldBlockThirdPartyCookies(booleanValue(messageBody), false); 761 581 return; 762 582 } 763 583 764 584 if (WKStringIsEqualToUTF8CString(messageName, "RunUIProcessScript")) { 765 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 766 WKRetainPtr<WKStringRef> scriptKey = adoptWK(WKStringCreateWithUTF8CString("Script")); 767 WKRetainPtr<WKStringRef> callbackIDKey = adoptWK(WKStringCreateWithUTF8CString("CallbackID")); 768 769 UIScriptInvocationData* invocationData = new UIScriptInvocationData(); 585 auto messageBodyDictionary = dictionaryValue(messageBody); 586 auto invocationData = new UIScriptInvocationData; 770 587 invocationData->testInvocation = this; 771 invocationData->callbackID = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, callbackIDKey.get())));772 invocationData->scriptString = st atic_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, scriptKey.get()));588 invocationData->callbackID = uint64Value(messageBodyDictionary, "CallbackID"); 589 invocationData->scriptString = stringValue(messageBodyDictionary, "Script"); 773 590 m_pendingUIScriptInvocationData = invocationData; 774 591 WKPageCallAfterNextPresentationUpdate(TestController::singleton().mainWebView()->page(), invocationData, runUISideScriptAfterUpdateCallback); … … 777 594 778 595 if (WKStringIsEqualToUTF8CString(messageName, "RunUIProcessScriptImmediately")) { 779 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 780 WKRetainPtr<WKStringRef> scriptKey = adoptWK(WKStringCreateWithUTF8CString("Script")); 781 WKRetainPtr<WKStringRef> callbackIDKey = adoptWK(WKStringCreateWithUTF8CString("CallbackID")); 782 783 UIScriptInvocationData* invocationData = new UIScriptInvocationData(); 596 auto messageBodyDictionary = dictionaryValue(messageBody); 597 auto invocationData = new UIScriptInvocationData; 784 598 invocationData->testInvocation = this; 785 invocationData->callbackID = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, callbackIDKey.get())));786 invocationData->scriptString = st atic_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, scriptKey.get()));599 invocationData->callbackID = uint64Value(messageBodyDictionary, "CallbackID"); 600 invocationData->scriptString = stringValue(messageBodyDictionary, "Script"); 787 601 m_pendingUIScriptInvocationData = invocationData; 788 602 runUISideScriptImmediately(nullptr, invocationData); … … 792 606 if (WKStringIsEqualToUTF8CString(messageName, "InstallCustomMenuAction")) { 793 607 auto messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 794 WKRetainPtr<WKStringRef> nameKey = adoptWK(WKStringCreateWithUTF8CString("name")); 795 WKRetainPtr<WKStringRef> name = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, nameKey.get())); 796 WKRetainPtr<WKStringRef> dismissesAutomaticallyKey = adoptWK(WKStringCreateWithUTF8CString("dismissesAutomatically")); 797 auto dismissesAutomatically = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, dismissesAutomaticallyKey.get())); 798 TestController::singleton().installCustomMenuAction(toWTFString(name.get()), WKBooleanGetValue(dismissesAutomatically)); 608 auto name = stringValue(messageBodyDictionary, "name"); 609 auto dismissesAutomatically = booleanValue(messageBodyDictionary, "dismissesAutomatically"); 610 TestController::singleton().installCustomMenuAction(toWTFString(name), dismissesAutomatically); 799 611 return; 800 612 } … … 806 618 actions.reserveInitialCapacity(size); 807 619 for (size_t index = 0; index < size; ++index) 808 actions.append(toWTFString(st atic_cast<WKStringRef>(WKArrayGetItemAtIndex(messageBodyArray, index))));620 actions.append(toWTFString(stringValue(WKArrayGetItemAtIndex(messageBodyArray, index)))); 809 621 TestController::singleton().setAllowedMenuActions(actions); 810 622 return; … … 829 641 830 642 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsDebugMode")) { 831 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 832 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 833 TestController::singleton().setStatisticsDebugMode(WKBooleanGetValue(value)); 643 TestController::singleton().setStatisticsDebugMode(booleanValue(messageBody)); 834 644 return; 835 645 } 836 646 837 647 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsPrevalentResourceForDebugMode")) { 838 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 839 WKStringRef hostName = static_cast<WKStringRef>(messageBody); 648 WKStringRef hostName = stringValue(messageBody); 840 649 TestController::singleton().setStatisticsPrevalentResourceForDebugMode(hostName); 841 650 return; … … 843 652 844 653 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsLastSeen")) { 845 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 846 847 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 848 WKRetainPtr<WKStringRef> hostNameKey = adoptWK(WKStringCreateWithUTF8CString("HostName")); 849 WKRetainPtr<WKStringRef> valueKey = adoptWK(WKStringCreateWithUTF8CString("Value")); 850 851 WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get())); 852 WKDoubleRef value = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get())); 853 854 TestController::singleton().setStatisticsLastSeen(hostName, WKDoubleGetValue(value)); 654 auto messageBodyDictionary = dictionaryValue(messageBody); 655 auto hostName = stringValue(messageBodyDictionary, "HostName"); 656 auto value = doubleValue(messageBodyDictionary, "Value"); 657 TestController::singleton().setStatisticsLastSeen(hostName, value); 855 658 return; 856 659 } 857 660 858 661 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsMergeStatistic")) { 859 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 860 861 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 862 WKRetainPtr<WKStringRef> hostNameKey = adoptWK(WKStringCreateWithUTF8CString("HostName")); 863 WKRetainPtr<WKStringRef> topFrameDomain1Key = adoptWK(WKStringCreateWithUTF8CString("TopFrameDomain1")); 864 WKRetainPtr<WKStringRef> topFrameDomain2Key = adoptWK(WKStringCreateWithUTF8CString("TopFrameDomain2")); 865 WKRetainPtr<WKStringRef> lastSeenKey = adoptWK(WKStringCreateWithUTF8CString("LastSeen")); 866 WKRetainPtr<WKStringRef> hadUserInteractionKey = adoptWK(WKStringCreateWithUTF8CString("HadUserInteraction")); 867 WKRetainPtr<WKStringRef> mostRecentUserInteractionKey = adoptWK(WKStringCreateWithUTF8CString("MostRecentUserInteraction")); 868 WKRetainPtr<WKStringRef> isGrandfatheredKey = adoptWK(WKStringCreateWithUTF8CString("IsGrandfathered")); 869 WKRetainPtr<WKStringRef> isPrevalentKey = adoptWK(WKStringCreateWithUTF8CString("IsPrevalent")); 870 WKRetainPtr<WKStringRef> isVeryPrevalentKey = adoptWK(WKStringCreateWithUTF8CString("IsVeryPrevalent")); 871 WKRetainPtr<WKStringRef> dataRecordsRemovedKey = adoptWK(WKStringCreateWithUTF8CString("DataRecordsRemoved")); 872 WKRetainPtr<WKStringRef> timesAccessedFirstPartyInteractionKey = adoptWK(WKStringCreateWithUTF8CString("TimesAccessedFirstPartyInteraction")); 873 874 WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get())); 875 WKStringRef topFrameDomain1 = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, topFrameDomain1Key.get())); 876 WKStringRef topFrameDomain2 = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, topFrameDomain2Key.get())); 877 WKDoubleRef lastSeen = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, lastSeenKey.get())); 878 WKBooleanRef hadUserInteraction = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hadUserInteractionKey.get())); 879 WKDoubleRef mostRecentUserInteraction = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, mostRecentUserInteractionKey.get())); 880 WKBooleanRef isGrandfathered = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, isGrandfatheredKey.get())); 881 WKBooleanRef isPrevalent = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, isPrevalentKey.get())); 882 WKBooleanRef isVeryPrevalent = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, isVeryPrevalentKey.get())); 883 WKUInt64Ref dataRecordsRemoved = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, dataRecordsRemovedKey.get())); 884 885 TestController::singleton().setStatisticsMergeStatistic(hostName, topFrameDomain1, topFrameDomain2, WKDoubleGetValue(lastSeen), WKBooleanGetValue(hadUserInteraction), WKDoubleGetValue(mostRecentUserInteraction), WKBooleanGetValue(isGrandfathered), WKBooleanGetValue(isPrevalent), WKBooleanGetValue(isVeryPrevalent), WKUInt64GetValue(dataRecordsRemoved)); 662 auto messageBodyDictionary = dictionaryValue(messageBody); 663 auto hostName = stringValue(messageBodyDictionary, "HostName"); 664 auto topFrameDomain1 = stringValue(messageBodyDictionary, "TopFrameDomain1"); 665 auto topFrameDomain2 = stringValue(messageBodyDictionary, "TopFrameDomain2"); 666 auto lastSeen = doubleValue(messageBodyDictionary, "LastSeen"); 667 auto hadUserInteraction = booleanValue(messageBodyDictionary, "HadUserInteraction"); 668 auto mostRecentUserInteraction = doubleValue(messageBodyDictionary, "MostRecentUserInteraction"); 669 auto isGrandfathered = booleanValue(messageBodyDictionary, "IsGrandfathered"); 670 auto isPrevalent = booleanValue(messageBodyDictionary, "IsPrevalent"); 671 auto isVeryPrevalent = booleanValue(messageBodyDictionary, "IsVeryPrevalent"); 672 auto dataRecordsRemoved = uint64Value(messageBodyDictionary, "DataRecordsRemoved"); 673 TestController::singleton().setStatisticsMergeStatistic(hostName, topFrameDomain1, topFrameDomain2, lastSeen, hadUserInteraction, mostRecentUserInteraction, isGrandfathered, isPrevalent, isVeryPrevalent, dataRecordsRemoved); 886 674 return; 887 675 } 888 676 889 677 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsExpiredStatistic")) { 890 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 891 892 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 893 WKRetainPtr<WKStringRef> hostNameKey = adoptWK(WKStringCreateWithUTF8CString("HostName")); 894 WKRetainPtr<WKStringRef> hadUserInteractionKey = adoptWK(WKStringCreateWithUTF8CString("HadUserInteraction")); 895 WKRetainPtr<WKStringRef> mostRecentUserInteractionKey = adoptWK(WKStringCreateWithUTF8CString("MostRecentUserInteraction")); 896 WKRetainPtr<WKStringRef> isScheduledForAllButCookieDataRemovalKey = adoptWK(WKStringCreateWithUTF8CString("IsScheduledForAllButCookieDataRemoval")); 897 WKRetainPtr<WKStringRef> isPrevalentKey = adoptWK(WKStringCreateWithUTF8CString("IsPrevalent")); 898 899 WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get())); 900 WKBooleanRef hadUserInteraction = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hadUserInteractionKey.get())); 901 WKBooleanRef isScheduledForAllButCookieDataRemoval = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, isScheduledForAllButCookieDataRemovalKey.get())); 902 WKBooleanRef isPrevalent = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, isPrevalentKey.get())); 903 904 TestController::singleton().setStatisticsExpiredStatistic(hostName, WKBooleanGetValue(hadUserInteraction), WKBooleanGetValue(isScheduledForAllButCookieDataRemoval), WKBooleanGetValue(isPrevalent)); 678 auto messageBodyDictionary = dictionaryValue(messageBody); 679 auto hostName = stringValue(messageBodyDictionary, "HostName"); 680 auto hadUserInteraction = booleanValue(messageBodyDictionary, "HadUserInteraction"); 681 auto isScheduledForAllButCookieDataRemoval = booleanValue(messageBodyDictionary, "IsScheduledForAllButCookieDataRemoval"); 682 auto isPrevalent = booleanValue(messageBodyDictionary, "IsPrevalent"); 683 TestController::singleton().setStatisticsExpiredStatistic(hostName, hadUserInteraction, isScheduledForAllButCookieDataRemoval, isPrevalent); 905 684 return; 906 685 } 907 686 908 687 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsPrevalentResource")) { 909 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 910 911 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 912 WKRetainPtr<WKStringRef> hostNameKey = adoptWK(WKStringCreateWithUTF8CString("HostName")); 913 WKRetainPtr<WKStringRef> valueKey = adoptWK(WKStringCreateWithUTF8CString("Value")); 914 915 WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get())); 916 WKBooleanRef value = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get())); 917 918 TestController::singleton().setStatisticsPrevalentResource(hostName, WKBooleanGetValue(value)); 688 auto messageBodyDictionary = dictionaryValue(messageBody); 689 auto hostName = stringValue(messageBodyDictionary, "HostName"); 690 auto value = booleanValue(messageBodyDictionary, "Value"); 691 TestController::singleton().setStatisticsPrevalentResource(hostName, value); 919 692 return; 920 693 } 921 694 922 695 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsVeryPrevalentResource")) { 923 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 924 925 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 926 WKRetainPtr<WKStringRef> hostNameKey = adoptWK(WKStringCreateWithUTF8CString("HostName")); 927 WKRetainPtr<WKStringRef> valueKey = adoptWK(WKStringCreateWithUTF8CString("Value")); 928 929 WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get())); 930 WKBooleanRef value = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get())); 931 932 TestController::singleton().setStatisticsVeryPrevalentResource(hostName, WKBooleanGetValue(value)); 696 auto messageBodyDictionary = dictionaryValue(messageBody); 697 auto hostName = stringValue(messageBodyDictionary, "HostName"); 698 auto value = booleanValue(messageBodyDictionary, "Value"); 699 TestController::singleton().setStatisticsVeryPrevalentResource(hostName, value); 933 700 return; 934 701 } … … 945 712 946 713 if (WKStringIsEqualToUTF8CString(messageName, "StatisticsClearInMemoryAndPersistentStoreModifiedSinceHours")) { 947 ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID()); 948 WKUInt64Ref hours = static_cast<WKUInt64Ref>(messageBody); 949 TestController::singleton().statisticsClearInMemoryAndPersistentStoreModifiedSinceHours(WKUInt64GetValue(hours)); 714 TestController::singleton().statisticsClearInMemoryAndPersistentStoreModifiedSinceHours(uint64Value(messageBody)); 950 715 return; 951 716 } 952 717 953 718 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsShouldDowngradeReferrer")) { 954 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 955 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 956 TestController::singleton().setStatisticsShouldDowngradeReferrer(WKBooleanGetValue(value)); 719 TestController::singleton().setStatisticsShouldDowngradeReferrer(booleanValue(messageBody)); 957 720 return; 958 721 } 959 722 960 723 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsFirstPartyWebsiteDataRemovalMode")) { 961 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 962 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 963 TestController::singleton().setStatisticsFirstPartyWebsiteDataRemovalMode(WKBooleanGetValue(value)); 724 TestController::singleton().setStatisticsFirstPartyWebsiteDataRemovalMode(booleanValue(messageBody)); 964 725 return; 965 726 } 966 727 967 728 if (WKStringIsEqualToUTF8CString(messageName, "StatisticsSetToSameSiteStrictCookies")) { 968 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 969 WKStringRef hostName = static_cast<WKStringRef>(messageBody); 970 TestController::singleton().setStatisticsToSameSiteStrictCookies(hostName); 729 TestController::singleton().setStatisticsToSameSiteStrictCookies(stringValue(messageBody)); 971 730 return; 972 731 } 973 732 974 733 if (WKStringIsEqualToUTF8CString(messageName, "StatisticsSetFirstPartyHostCNAMEDomain")) { 975 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 976 977 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 978 WKRetainPtr<WKStringRef> firstPartyURLStringKey = adoptWK(WKStringCreateWithUTF8CString("FirstPartyURL")); 979 WKRetainPtr<WKStringRef> cnameURLStringKey = adoptWK(WKStringCreateWithUTF8CString("CNAME")); 980 981 WKStringRef firstPartyURLString = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, firstPartyURLStringKey.get())); 982 WKStringRef cnameURLString = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, cnameURLStringKey.get())); 983 734 auto messageBodyDictionary = dictionaryValue(messageBody); 735 auto firstPartyURLString = stringValue(messageBodyDictionary, "FirstPartyURL"); 736 auto cnameURLString = stringValue(messageBodyDictionary, "CNAME"); 984 737 TestController::singleton().setStatisticsFirstPartyHostCNAMEDomain(firstPartyURLString, cnameURLString); 985 738 return; … … 987 740 988 741 if (WKStringIsEqualToUTF8CString(messageName, "StatisticsSetThirdPartyCNAMEDomain")) { 989 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 990 WKStringRef cnameURLString = static_cast<WKStringRef>(messageBody); 991 TestController::singleton().setStatisticsThirdPartyCNAMEDomain(cnameURLString); 742 TestController::singleton().setStatisticsThirdPartyCNAMEDomain(stringValue(messageBody)); 992 743 return; 993 744 } … … 1013 764 #ifdef __BLOCKS__ 1014 765 WKPageGetApplicationManifest_b(TestController::singleton().mainWebView()->page(), ^{ 1015 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("DidGetApplicationManifest")); 1016 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 766 postPageMessage("DidGetApplicationManifest"); 1017 767 }); 1018 768 #else … … 1024 774 1025 775 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsHasHadUserInteraction")) { 1026 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1027 1028 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1029 WKRetainPtr<WKStringRef> hostNameKey = adoptWK(WKStringCreateWithUTF8CString("HostName")); 1030 WKRetainPtr<WKStringRef> valueKey = adoptWK(WKStringCreateWithUTF8CString("Value")); 1031 1032 WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get())); 1033 WKBooleanRef value = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get())); 1034 1035 TestController::singleton().setStatisticsHasHadUserInteraction(hostName, WKBooleanGetValue(value)); 776 auto messageBodyDictionary = dictionaryValue(messageBody); 777 auto hostName = stringValue(messageBodyDictionary, "HostName"); 778 auto value = booleanValue(messageBodyDictionary, "Value"); 779 TestController::singleton().setStatisticsHasHadUserInteraction(hostName, value); 1036 780 return; 1037 781 } … … 1044 788 if (WKStringIsEqualToUTF8CString(messageName, "SetAppBoundDomains")) { 1045 789 ASSERT(WKGetTypeID(messageBody) == WKArrayGetTypeID()); 1046 WKArrayRef originURLs = static_cast<WKArrayRef>(messageBody); 1047 TestController::singleton().setAppBoundDomains(originURLs); 790 TestController::singleton().setAppBoundDomains(static_cast<WKArrayRef>(messageBody)); 1048 791 return; 1049 792 } … … 1056 799 if (WKStringIsEqualToUTF8CString(messageName, "Initialization")) { 1057 800 auto settings = createTestSettingsDictionary(); 1058 WKRetainPtr<WKStringRef> resumeTestingKey = adoptWK(WKStringCreateWithUTF8CString("ResumeTesting")); 1059 WKRetainPtr<WKBooleanRef> resumeTestingValue = adoptWK(WKBooleanCreate(m_startedTesting)); 1060 WKDictionarySetItem(settings.get(), resumeTestingKey.get(), resumeTestingValue.get()); 801 setValue(settings, "ResumeTesting", m_startedTesting); 1061 802 return settings; 1062 803 } 1063 804 1064 805 if (WKStringIsEqualToUTF8CString(messageName, "SetDumpPixels")) { 1065 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 1066 m_dumpPixels = WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody)); 806 m_dumpPixels = booleanValue(messageBody); 1067 807 return nullptr; 1068 808 } … … 1071 811 1072 812 if (WKStringIsEqualToUTF8CString(messageName, "SetWhatToDump")) { 1073 ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID()); 1074 m_whatToDump = static_cast<WhatToDump>(WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody))); 813 m_whatToDump = static_cast<WhatToDump>(uint64Value(messageBody)); 1075 814 return nullptr; 1076 815 } … … 1079 818 1080 819 if (WKStringIsEqualToUTF8CString(messageName, "SetWaitUntilDone")) { 1081 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 1082 setWaitUntilDone(static_cast<unsigned char>(WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody)))); 820 setWaitUntilDone(booleanValue(messageBody)); 1083 821 return nullptr; 1084 822 } … … 1087 825 1088 826 if (WKStringIsEqualToUTF8CString(messageName, "SetDumpFrameLoadCallbacks")) { 1089 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 1090 m_dumpFrameLoadCallbacks = static_cast<unsigned char>(WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody))); 827 m_dumpFrameLoadCallbacks = booleanValue(messageBody); 1091 828 return nullptr; 1092 829 } … … 1095 832 1096 833 if (WKStringIsEqualToUTF8CString(messageName, "SetCanOpenWindows")) { 1097 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 1098 m_canOpenWindows = static_cast<unsigned char>(WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody))); 834 m_canOpenWindows = booleanValue(messageBody); 1099 835 return nullptr; 1100 836 } 1101 837 1102 838 if (WKStringIsEqualToUTF8CString(messageName, "SetWindowIsKey")) { 1103 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 1104 WKBooleanRef isKeyValue = static_cast<WKBooleanRef>(messageBody); 1105 TestController::singleton().mainWebView()->setWindowIsKey(WKBooleanGetValue(isKeyValue)); 839 TestController::singleton().mainWebView()->setWindowIsKey(booleanValue(messageBody)); 1106 840 return nullptr; 1107 841 } 1108 842 1109 843 if (WKStringIsEqualToUTF8CString(messageName, "SetViewSize")) { 1110 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1111 1112 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1113 WKRetainPtr<WKStringRef> widthKey = adoptWK(WKStringCreateWithUTF8CString("width")); 1114 WKRetainPtr<WKStringRef> heightKey = adoptWK(WKStringCreateWithUTF8CString("height")); 1115 1116 WKDoubleRef widthWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, widthKey.get())); 1117 WKDoubleRef heightWK = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, heightKey.get())); 1118 1119 TestController::singleton().mainWebView()->resizeTo(WKDoubleGetValue(widthWK), WKDoubleGetValue(heightWK)); 1120 return nullptr; 1121 } 1122 1123 if (WKStringIsEqualToUTF8CString(messageName, "IsGeolocationClientActive")) { 1124 bool isActive = TestController::singleton().isGeolocationProviderActive(); 1125 WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(isActive)); 1126 return result; 1127 } 844 auto messageBodyDictionary = dictionaryValue(messageBody); 845 auto width = doubleValue(messageBodyDictionary, "width"); 846 auto height = doubleValue(messageBodyDictionary, "height"); 847 TestController::singleton().mainWebView()->resizeTo(width, height); 848 return nullptr; 849 } 850 851 if (WKStringIsEqualToUTF8CString(messageName, "IsGeolocationClientActive")) 852 return adoptWK(WKBooleanCreate(TestController::singleton().isGeolocationProviderActive())); 1128 853 1129 854 if (WKStringIsEqualToUTF8CString(messageName, "SetCacheModel")) { 1130 ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID()); 1131 uint64_t model = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody)); 855 uint64_t model = uint64Value(messageBody); 1132 856 WKWebsiteDataStoreSetCacheModelSynchronouslyForTesting(TestController::singleton().websiteDataStore(), model); 1133 857 return nullptr; 1134 858 } 1135 859 1136 if (WKStringIsEqualToUTF8CString(messageName, "IsWorkQueueEmpty")) { 1137 bool isEmpty = TestController::singleton().workQueueManager().isWorkQueueEmpty(); 1138 WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(isEmpty)); 1139 return result; 1140 } 1141 1142 if (WKStringIsEqualToUTF8CString(messageName, "DidReceiveServerRedirectForProvisionalNavigation")) { 1143 WKRetainPtr<WKBooleanRef> result = adoptWK(WKBooleanCreate(TestController::singleton().didReceiveServerRedirectForProvisionalNavigation())); 1144 return result; 1145 } 860 if (WKStringIsEqualToUTF8CString(messageName, "IsWorkQueueEmpty")) 861 return adoptWK(WKBooleanCreate(TestController::singleton().workQueueManager().isWorkQueueEmpty())); 862 863 if (WKStringIsEqualToUTF8CString(messageName, "DidReceiveServerRedirectForProvisionalNavigation")) 864 return adoptWK(WKBooleanCreate(TestController::singleton().didReceiveServerRedirectForProvisionalNavigation())); 1146 865 1147 866 if (WKStringIsEqualToUTF8CString(messageName, "ClearDidReceiveServerRedirectForProvisionalNavigation")) { … … 1151 870 1152 871 if (WKStringIsEqualToUTF8CString(messageName, "SecureEventInputIsEnabled")) { 1153 #if PLATFORM(MAC) && !PLATFORM(IOS_FAMILY)1154 WKRetainPtr<WKBooleanRef> result =adoptWK(WKBooleanCreate(IsSecureEventInputEnabled()));872 #if PLATFORM(MAC) 873 return adoptWK(WKBooleanCreate(IsSecureEventInputEnabled())); 1155 874 #else 1156 WKRetainPtr<WKBooleanRef> result =adoptWK(WKBooleanCreate(false));875 return adoptWK(WKBooleanCreate(false)); 1157 876 #endif 1158 return result;1159 877 } 1160 878 1161 879 if (WKStringIsEqualToUTF8CString(messageName, "SetCustomUserAgent")) { 1162 WKStringRef userAgent = static_cast<WKStringRef>(messageBody); 1163 WKPageSetCustomUserAgent(TestController::singleton().mainWebView()->page(), userAgent); 880 WKPageSetCustomUserAgent(TestController::singleton().mainWebView()->page(), stringValue(messageBody)); 1164 881 return nullptr; 1165 882 } 1166 883 1167 884 if (WKStringIsEqualToUTF8CString(messageName, "SetAllowsAnySSLCertificate")) { 1168 TestController::singleton().setAllowsAnySSLCertificate( WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody)));885 TestController::singleton().setAllowsAnySSLCertificate(booleanValue(messageBody)); 1169 886 return nullptr; 1170 887 } 1171 888 1172 889 if (WKStringIsEqualToUTF8CString(messageName, "SetShouldSwapToEphemeralSessionOnNextNavigation")) { 1173 TestController::singleton().setShouldSwapToEphemeralSessionOnNextNavigation( WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody)));890 TestController::singleton().setShouldSwapToEphemeralSessionOnNextNavigation(booleanValue(messageBody)); 1174 891 return nullptr; 1175 892 } 1176 893 1177 894 if (WKStringIsEqualToUTF8CString(messageName, "SetShouldSwapToDefaultSessionOnNextNavigation")) { 1178 TestController::singleton().setShouldSwapToDefaultSessionOnNextNavigation(WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody))); 1179 return nullptr; 1180 } 1181 1182 if (WKStringIsEqualToUTF8CString(messageName, "ImageCountInGeneralPasteboard")) { 1183 unsigned count = TestController::singleton().imageCountInGeneralPasteboard(); 1184 WKRetainPtr<WKUInt64Ref> result = adoptWK(WKUInt64Create(count)); 1185 return result; 1186 } 895 TestController::singleton().setShouldSwapToDefaultSessionOnNextNavigation(booleanValue(messageBody)); 896 return nullptr; 897 } 898 899 if (WKStringIsEqualToUTF8CString(messageName, "ImageCountInGeneralPasteboard")) 900 return adoptWK(WKUInt64Create(TestController::singleton().imageCountInGeneralPasteboard())); 1187 901 1188 902 if (WKStringIsEqualToUTF8CString(messageName, "DeleteAllIndexedDatabases")) { … … 1192 906 1193 907 if (WKStringIsEqualToUTF8CString(messageName, "AddMockMediaDevice")) { 1194 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1195 1196 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1197 WKRetainPtr<WKStringRef> persistentIDKey = adoptWK(WKStringCreateWithUTF8CString("PersistentID")); 1198 WKRetainPtr<WKStringRef> labelKey = adoptWK(WKStringCreateWithUTF8CString("Label")); 1199 WKRetainPtr<WKStringRef> typeKey = adoptWK(WKStringCreateWithUTF8CString("Type")); 1200 1201 auto persistentID = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, persistentIDKey.get())); 1202 auto label = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, labelKey.get())); 1203 auto type = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, typeKey.get())); 1204 908 auto messageBodyDictionary = dictionaryValue(messageBody); 909 auto persistentID = stringValue(messageBodyDictionary, "PersistentID"); 910 auto label = stringValue(messageBodyDictionary, "Label"); 911 auto type = stringValue(messageBodyDictionary, "Type"); 1205 912 TestController::singleton().addMockMediaDevice(persistentID, label, type); 1206 913 return nullptr; … … 1213 920 1214 921 if (WKStringIsEqualToUTF8CString(messageName, "RemoveMockMediaDevice")) { 1215 WKStringRef persistentId = static_cast<WKStringRef>(messageBody); 1216 1217 TestController::singleton().removeMockMediaDevice(persistentId); 922 TestController::singleton().removeMockMediaDevice(stringValue(messageBody)); 1218 923 return nullptr; 1219 924 } … … 1225 930 1226 931 if (WKStringIsEqualToUTF8CString(messageName, "SetMockCameraOrientation")) { 1227 TestController::singleton().setMockCameraOrientation(WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody))); 1228 return nullptr; 1229 } 1230 1231 if (WKStringIsEqualToUTF8CString(messageName, "IsMockRealtimeMediaSourceCenterEnabled")) { 1232 bool isMockRealtimeMediaSourceCenterEnabled = TestController::singleton().isMockRealtimeMediaSourceCenterEnabled(); 1233 return adoptWK(WKBooleanCreate(isMockRealtimeMediaSourceCenterEnabled)); 1234 } 1235 1236 if (WKStringIsEqualToUTF8CString(messageName, "HasAppBoundSession")) { 1237 bool hasAppBoundSession = TestController::singleton().hasAppBoundSession(); 1238 return adoptWK(WKBooleanCreate(hasAppBoundSession)); 1239 } 932 TestController::singleton().setMockCameraOrientation(uint64Value(messageBody)); 933 return nullptr; 934 } 935 936 if (WKStringIsEqualToUTF8CString(messageName, "IsMockRealtimeMediaSourceCenterEnabled")) 937 return adoptWK(WKBooleanCreate(TestController::singleton().isMockRealtimeMediaSourceCenterEnabled())); 938 939 if (WKStringIsEqualToUTF8CString(messageName, "HasAppBoundSession")) 940 return adoptWK(WKBooleanCreate(TestController::singleton().hasAppBoundSession())); 1240 941 1241 942 #if PLATFORM(MAC) 1242 943 if (WKStringIsEqualToUTF8CString(messageName, "ConnectMockGamepad")) { 1243 ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID()); 1244 1245 uint64_t index = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody)); 1246 WebCoreTestSupport::connectMockGamepad(index); 1247 944 WebCoreTestSupport::connectMockGamepad(uint64Value(messageBody)); 1248 945 return nullptr; 1249 946 } 1250 947 1251 948 if (WKStringIsEqualToUTF8CString(messageName, "DisconnectMockGamepad")) { 1252 ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID()); 1253 1254 uint64_t index = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody)); 1255 WebCoreTestSupport::disconnectMockGamepad(index); 1256 949 WebCoreTestSupport::disconnectMockGamepad(uint64Value(messageBody)); 1257 950 return nullptr; 1258 951 } 1259 952 1260 953 if (WKStringIsEqualToUTF8CString(messageName, "SetMockGamepadDetails")) { 1261 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1262 1263 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1264 WKRetainPtr<WKStringRef> gamepadIndexKey = adoptWK(WKStringCreateWithUTF8CString("GamepadIndex")); 1265 WKRetainPtr<WKStringRef> gamepadIDKey = adoptWK(WKStringCreateWithUTF8CString("GamepadID")); 1266 WKRetainPtr<WKStringRef> mappingKey = adoptWK(WKStringCreateWithUTF8CString("Mapping")); 1267 WKRetainPtr<WKStringRef> axisCountKey = adoptWK(WKStringCreateWithUTF8CString("AxisCount")); 1268 WKRetainPtr<WKStringRef> buttonCountKey = adoptWK(WKStringCreateWithUTF8CString("ButtonCount")); 1269 1270 WKUInt64Ref gamepadIndex = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, gamepadIndexKey.get())); 1271 WKStringRef gamepadID = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, gamepadIDKey.get())); 1272 WKStringRef mapping = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, mappingKey.get())); 1273 WKUInt64Ref axisCount = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, axisCountKey.get())); 1274 WKUInt64Ref buttonCount = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, buttonCountKey.get())); 1275 1276 WebCoreTestSupport::setMockGamepadDetails(WKUInt64GetValue(gamepadIndex), toWTFString(gamepadID), toWTFString(mapping), WKUInt64GetValue(axisCount), WKUInt64GetValue(buttonCount)); 954 auto messageBodyDictionary = dictionaryValue(messageBody); 955 auto gamepadIndex = uint64Value(messageBodyDictionary, "GamepadIndex"); 956 auto gamepadID = stringValue(messageBodyDictionary, "GamepadID"); 957 auto mapping = stringValue(messageBodyDictionary, "Mapping"); 958 auto axisCount = uint64Value(messageBodyDictionary, "AxisCount"); 959 auto buttonCount = uint64Value(messageBodyDictionary, "ButtonCount"); 960 WebCoreTestSupport::setMockGamepadDetails(gamepadIndex, toWTFString(gamepadID), toWTFString(mapping), axisCount, buttonCount); 1277 961 return nullptr; 1278 962 } 1279 963 1280 964 if (WKStringIsEqualToUTF8CString(messageName, "SetMockGamepadAxisValue")) { 1281 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1282 1283 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1284 WKRetainPtr<WKStringRef> gamepadIndexKey = adoptWK(WKStringCreateWithUTF8CString("GamepadIndex")); 1285 WKRetainPtr<WKStringRef> axisIndexKey = adoptWK(WKStringCreateWithUTF8CString("AxisIndex")); 1286 WKRetainPtr<WKStringRef> valueKey = adoptWK(WKStringCreateWithUTF8CString("Value")); 1287 1288 WKUInt64Ref gamepadIndex = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, gamepadIndexKey.get())); 1289 WKUInt64Ref axisIndex = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, axisIndexKey.get())); 1290 WKDoubleRef value = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get())); 1291 1292 WebCoreTestSupport::setMockGamepadAxisValue(WKUInt64GetValue(gamepadIndex), WKUInt64GetValue(axisIndex), WKDoubleGetValue(value)); 1293 965 auto messageBodyDictionary = dictionaryValue(messageBody); 966 auto gamepadIndex = uint64Value(messageBodyDictionary, "GamepadIndex"); 967 auto axisIndex = uint64Value(messageBodyDictionary, "AxisIndex"); 968 auto value = doubleValue(messageBodyDictionary, "Value"); 969 WebCoreTestSupport::setMockGamepadAxisValue(gamepadIndex, axisIndex, value); 1294 970 return nullptr; 1295 971 } 1296 972 1297 973 if (WKStringIsEqualToUTF8CString(messageName, "SetMockGamepadButtonValue")) { 1298 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1299 1300 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1301 WKRetainPtr<WKStringRef> gamepadIndexKey = adoptWK(WKStringCreateWithUTF8CString("GamepadIndex")); 1302 WKRetainPtr<WKStringRef> buttonIndexKey = adoptWK(WKStringCreateWithUTF8CString("ButtonIndex")); 1303 WKRetainPtr<WKStringRef> valueKey = adoptWK(WKStringCreateWithUTF8CString("Value")); 1304 1305 WKUInt64Ref gamepadIndex = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, gamepadIndexKey.get())); 1306 WKUInt64Ref buttonIndex = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, buttonIndexKey.get())); 1307 WKDoubleRef value = static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get())); 1308 1309 WebCoreTestSupport::setMockGamepadButtonValue(WKUInt64GetValue(gamepadIndex), WKUInt64GetValue(buttonIndex), WKDoubleGetValue(value)); 1310 974 auto messageBodyDictionary = dictionaryValue(messageBody); 975 auto gamepadIndex = uint64Value(messageBodyDictionary, "GamepadIndex"); 976 auto buttonIndex = uint64Value(messageBodyDictionary, "ButtonIndex"); 977 auto value = doubleValue(messageBodyDictionary, "Value"); 978 WebCoreTestSupport::setMockGamepadButtonValue(gamepadIndex, buttonIndex, value); 1311 979 return nullptr; 1312 980 } … … 1314 982 1315 983 if (WKStringIsEqualToUTF8CString(messageName, "UserMediaPermissionRequestCountForOrigin")) { 1316 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1317 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1318 1319 WKRetainPtr<WKStringRef> originKey = adoptWK(WKStringCreateWithUTF8CString("origin")); 1320 WKStringRef originWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, originKey.get())); 1321 1322 WKRetainPtr<WKStringRef> parentOriginKey = adoptWK(WKStringCreateWithUTF8CString("parentOrigin")); 1323 WKStringRef parentOriginWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, parentOriginKey.get())); 1324 984 auto messageBodyDictionary = dictionaryValue(messageBody); 985 auto originWK = stringValue(messageBodyDictionary, "origin"); 986 auto parentOriginWK = stringValue(messageBodyDictionary, "parentOrigin"); 1325 987 unsigned count = TestController::singleton().userMediaPermissionRequestCountForOrigin(originWK, parentOriginWK); 1326 WKRetainPtr<WKUInt64Ref> result = adoptWK(WKUInt64Create(count)); 1327 return result; 1328 } 1329 if (WKStringIsEqualToUTF8CString(messageName, "IsDoingMediaCapture")) { 1330 WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(TestController::singleton().isDoingMediaCapture())); 1331 return result; 1332 } 988 return adoptWK(WKUInt64Create(count)); 989 } 990 991 if (WKStringIsEqualToUTF8CString(messageName, "IsDoingMediaCapture")) 992 return adoptWK(WKBooleanCreate(TestController::singleton().isDoingMediaCapture())); 1333 993 1334 994 if (WKStringIsEqualToUTF8CString(messageName, "ClearStatisticsDataForDomain")) { 1335 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 1336 WKStringRef domain = static_cast<WKStringRef>(messageBody); 1337 1338 TestController::singleton().clearStatisticsDataForDomain(domain); 995 TestController::singleton().clearStatisticsDataForDomain(stringValue(messageBody)); 1339 996 return nullptr; 1340 997 } 1341 998 1342 999 if (WKStringIsEqualToUTF8CString(messageName, "DoesStatisticsDomainIDExistInDatabase")) { 1343 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1344 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1345 WKRetainPtr<WKStringRef> domainIDKey = adoptWK(WKStringCreateWithUTF8CString("DomainID")); 1346 WKUInt64Ref domainID = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, domainIDKey.get())); 1347 bool domainIDExists = TestController::singleton().doesStatisticsDomainIDExistInDatabase(WKUInt64GetValue(domainID)); 1348 WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(domainIDExists)); 1349 return result; 1000 auto messageBodyDictionary = dictionaryValue(messageBody); 1001 auto domainID = uint64Value(messageBodyDictionary, "DomainID"); 1002 bool domainIDExists = TestController::singleton().doesStatisticsDomainIDExistInDatabase(domainID); 1003 return adoptWK(WKBooleanCreate(domainIDExists)); 1350 1004 } 1351 1005 1352 1006 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsEnabled")) { 1353 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 1354 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 1355 TestController::singleton().setStatisticsEnabled(WKBooleanGetValue(value)); 1007 TestController::singleton().setStatisticsEnabled(booleanValue(messageBody)); 1356 1008 return nullptr; 1357 1009 } 1358 1010 1359 1011 if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsEphemeral")) { 1360 bool isEphemeral = TestController::singleton().isStatisticsEphemeral(); 1361 WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(isEphemeral)); 1362 return result; 1012 return adoptWK(WKBooleanCreate(TestController::singleton().isStatisticsEphemeral())); 1363 1013 } 1364 1014 … … 1369 1019 1370 1020 if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsPrevalentResource")) { 1371 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 1372 1373 WKStringRef hostName = static_cast<WKStringRef>(messageBody); 1374 bool isPrevalent = TestController::singleton().isStatisticsPrevalentResource(hostName); 1375 WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(isPrevalent)); 1376 return result; 1021 bool isPrevalent = TestController::singleton().isStatisticsPrevalentResource(stringValue(messageBody)); 1022 return adoptWK(WKBooleanCreate(isPrevalent)); 1377 1023 } 1378 1024 1379 1025 if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsVeryPrevalentResource")) { 1380 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 1381 1382 WKStringRef hostName = static_cast<WKStringRef>(messageBody); 1383 bool isPrevalent = TestController::singleton().isStatisticsVeryPrevalentResource(hostName); 1384 WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(isPrevalent)); 1385 return result; 1026 bool isPrevalent = TestController::singleton().isStatisticsVeryPrevalentResource(stringValue(messageBody)); 1027 return adoptWK(WKBooleanCreate(isPrevalent)); 1386 1028 } 1387 1029 1388 1030 if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsRegisteredAsSubresourceUnder")) { 1389 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1390 1391 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1392 WKRetainPtr<WKStringRef> subresourceHostKey = adoptWK(WKStringCreateWithUTF8CString("SubresourceHost")); 1393 WKRetainPtr<WKStringRef> topFrameHostKey = adoptWK(WKStringCreateWithUTF8CString("TopFrameHost")); 1394 1395 WKStringRef subresourceHost = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, subresourceHostKey.get())); 1396 WKStringRef topFrameHost = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, topFrameHostKey.get())); 1397 1031 auto messageBodyDictionary = dictionaryValue(messageBody); 1032 auto subresourceHost = stringValue(messageBodyDictionary, "SubresourceHost"); 1033 auto topFrameHost = stringValue(messageBodyDictionary, "TopFrameHost"); 1398 1034 bool isRegisteredAsSubresourceUnder = TestController::singleton().isStatisticsRegisteredAsSubresourceUnder(subresourceHost, topFrameHost); 1399 WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(isRegisteredAsSubresourceUnder)); 1400 return result; 1035 return adoptWK(WKBooleanCreate(isRegisteredAsSubresourceUnder)); 1401 1036 } 1402 1037 1403 1038 if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsRegisteredAsSubFrameUnder")) { 1404 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1405 1406 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1407 WKRetainPtr<WKStringRef> subFrameHostKey = adoptWK(WKStringCreateWithUTF8CString("SubFrameHost")); 1408 WKRetainPtr<WKStringRef> topFrameHostKey = adoptWK(WKStringCreateWithUTF8CString("TopFrameHost")); 1409 1410 WKStringRef subFrameHost = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, subFrameHostKey.get())); 1411 WKStringRef topFrameHost = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, topFrameHostKey.get())); 1412 1039 auto messageBodyDictionary = dictionaryValue(messageBody); 1040 auto subFrameHost = stringValue(messageBodyDictionary, "SubFrameHost"); 1041 auto topFrameHost = stringValue(messageBodyDictionary, "TopFrameHost"); 1413 1042 bool isRegisteredAsSubFrameUnder = TestController::singleton().isStatisticsRegisteredAsSubFrameUnder(subFrameHost, topFrameHost); 1414 WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(isRegisteredAsSubFrameUnder)); 1415 return result; 1043 return adoptWK(WKBooleanCreate(isRegisteredAsSubFrameUnder)); 1416 1044 } 1417 1045 1418 1046 if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsRegisteredAsRedirectingTo")) { 1419 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1420 1421 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1422 WKRetainPtr<WKStringRef> hostRedirectedFromKey = adoptWK(WKStringCreateWithUTF8CString("HostRedirectedFrom")); 1423 WKRetainPtr<WKStringRef> hostRedirectedToKey = adoptWK(WKStringCreateWithUTF8CString("HostRedirectedTo")); 1424 1425 WKStringRef hostRedirectedFrom = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostRedirectedFromKey.get())); 1426 WKStringRef hostRedirectedTo = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostRedirectedToKey.get())); 1427 1047 auto messageBodyDictionary = dictionaryValue(messageBody); 1048 auto hostRedirectedFrom = stringValue(messageBodyDictionary, "HostRedirectedFrom"); 1049 auto hostRedirectedTo = stringValue(messageBodyDictionary, "HostRedirectedTo"); 1428 1050 bool isRegisteredAsRedirectingTo = TestController::singleton().isStatisticsRegisteredAsRedirectingTo(hostRedirectedFrom, hostRedirectedTo); 1429 WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(isRegisteredAsRedirectingTo)); 1430 return result; 1051 return adoptWK(WKBooleanCreate(isRegisteredAsRedirectingTo)); 1431 1052 } 1432 1053 1433 1054 if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsHasHadUserInteraction")) { 1434 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 1435 1436 WKStringRef hostName = static_cast<WKStringRef>(messageBody); 1437 bool hasHadUserInteraction = TestController::singleton().isStatisticsHasHadUserInteraction(hostName); 1438 WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(hasHadUserInteraction)); 1439 return result; 1055 bool hasHadUserInteraction = TestController::singleton().isStatisticsHasHadUserInteraction(stringValue(messageBody)); 1056 return adoptWK(WKBooleanCreate(hasHadUserInteraction)); 1440 1057 } 1441 1058 1442 1059 if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsOnlyInDatabaseOnce")) { 1443 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1444 1445 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1446 auto subHostKey = adoptWK(WKStringCreateWithUTF8CString("SubHost")); 1447 auto topHostKey = adoptWK(WKStringCreateWithUTF8CString("TopHost")); 1448 1449 WKStringRef subHost = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, subHostKey.get())); 1450 WKStringRef topHost = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, topHostKey.get())); 1451 1060 auto messageBodyDictionary = dictionaryValue(messageBody); 1061 auto subHost = stringValue(messageBodyDictionary, "SubHost"); 1062 auto topHost = stringValue(messageBodyDictionary, "TopHost"); 1452 1063 bool statisticInDatabaseOnce = TestController::singleton().isStatisticsOnlyInDatabaseOnce(subHost, topHost); 1453 1064 return adoptWK(WKBooleanCreate(statisticInDatabaseOnce)); … … 1455 1066 1456 1067 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsGrandfathered")) { 1457 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1458 1459 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1460 WKRetainPtr<WKStringRef> hostNameKey = adoptWK(WKStringCreateWithUTF8CString("HostName")); 1461 WKRetainPtr<WKStringRef> valueKey = adoptWK(WKStringCreateWithUTF8CString("Value")); 1462 1463 WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get())); 1464 WKBooleanRef value = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get())); 1465 1466 TestController::singleton().setStatisticsGrandfathered(hostName, WKBooleanGetValue(value)); 1068 auto messageBodyDictionary = dictionaryValue(messageBody); 1069 auto hostName = stringValue(messageBodyDictionary, "HostName"); 1070 auto value = booleanValue(messageBodyDictionary, "Value"); 1071 TestController::singleton().setStatisticsGrandfathered(hostName, value); 1467 1072 return nullptr; 1468 1073 } 1469 1074 1470 1075 if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsGrandfathered")) { 1471 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 1472 1473 WKStringRef hostName = static_cast<WKStringRef>(messageBody); 1474 bool isGrandfathered = TestController::singleton().isStatisticsGrandfathered(hostName); 1475 WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(isGrandfathered)); 1476 return result; 1076 bool isGrandfathered = TestController::singleton().isStatisticsGrandfathered(stringValue(messageBody)); 1077 return adoptWK(WKBooleanCreate(isGrandfathered)); 1477 1078 } 1478 1079 1479 1080 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsSubframeUnderTopFrameOrigin")) { 1480 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1481 1482 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1483 WKRetainPtr<WKStringRef> hostNameKey = adoptWK(WKStringCreateWithUTF8CString("HostName")); 1484 WKRetainPtr<WKStringRef> topFrameHostNameKey = adoptWK(WKStringCreateWithUTF8CString("TopFrameHostName")); 1485 1486 WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get())); 1487 WKStringRef topFrameHostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, topFrameHostNameKey.get())); 1488 1081 auto messageBodyDictionary = dictionaryValue(messageBody); 1082 auto hostName = stringValue(messageBodyDictionary, "HostName"); 1083 auto topFrameHostName = stringValue(messageBodyDictionary, "TopFrameHostName"); 1489 1084 TestController::singleton().setStatisticsSubframeUnderTopFrameOrigin(hostName, topFrameHostName); 1490 1085 return nullptr; … … 1492 1087 1493 1088 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsSubresourceUnderTopFrameOrigin")) { 1494 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1495 1496 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1497 WKRetainPtr<WKStringRef> hostNameKey = adoptWK(WKStringCreateWithUTF8CString("HostName")); 1498 WKRetainPtr<WKStringRef> topFrameHostNameKey = adoptWK(WKStringCreateWithUTF8CString("TopFrameHostName")); 1499 1500 WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get())); 1501 WKStringRef topFrameHostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, topFrameHostNameKey.get())); 1502 1089 auto messageBodyDictionary = dictionaryValue(messageBody); 1090 auto hostName = stringValue(messageBodyDictionary, "HostName"); 1091 auto topFrameHostName = stringValue(messageBodyDictionary, "TopFrameHostName"); 1503 1092 TestController::singleton().setStatisticsSubresourceUnderTopFrameOrigin(hostName, topFrameHostName); 1504 1093 return nullptr; … … 1506 1095 1507 1096 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsSubresourceUniqueRedirectTo")) { 1508 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1509 1510 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1511 WKRetainPtr<WKStringRef> hostNameKey = adoptWK(WKStringCreateWithUTF8CString("HostName")); 1512 WKRetainPtr<WKStringRef> hostNameRedirectedToKey = adoptWK(WKStringCreateWithUTF8CString("HostNameRedirectedTo")); 1513 1514 WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get())); 1515 WKStringRef hostNameRedirectedTo = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameRedirectedToKey.get())); 1516 1097 auto messageBodyDictionary = dictionaryValue(messageBody); 1098 auto hostName = stringValue(messageBodyDictionary, "HostName"); 1099 auto hostNameRedirectedTo = stringValue(messageBodyDictionary, "HostNameRedirectedTo"); 1517 1100 TestController::singleton().setStatisticsSubresourceUniqueRedirectTo(hostName, hostNameRedirectedTo); 1518 1101 return nullptr; … … 1520 1103 1521 1104 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsSubresourceUniqueRedirectFrom")) { 1522 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1523 1524 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1525 WKRetainPtr<WKStringRef> hostNameKey = adoptWK(WKStringCreateWithUTF8CString("HostName")); 1526 WKRetainPtr<WKStringRef> hostNameRedirectedFromKey = adoptWK(WKStringCreateWithUTF8CString("HostNameRedirectedFrom")); 1527 1528 WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get())); 1529 WKStringRef hostNameRedirectedFrom = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameRedirectedFromKey.get())); 1530 1105 auto messageBodyDictionary = dictionaryValue(messageBody); 1106 auto hostName = stringValue(messageBodyDictionary, "HostName"); 1107 auto hostNameRedirectedFrom = stringValue(messageBodyDictionary, "HostNameRedirectedFrom"); 1531 1108 TestController::singleton().setStatisticsSubresourceUniqueRedirectFrom(hostName, hostNameRedirectedFrom); 1532 1109 return nullptr; … … 1534 1111 1535 1112 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsTopFrameUniqueRedirectTo")) { 1536 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1537 1538 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1539 WKRetainPtr<WKStringRef> hostNameKey = adoptWK(WKStringCreateWithUTF8CString("HostName")); 1540 WKRetainPtr<WKStringRef> hostNameRedirectedToKey = adoptWK(WKStringCreateWithUTF8CString("HostNameRedirectedTo")); 1541 1542 WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get())); 1543 WKStringRef hostNameRedirectedTo = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameRedirectedToKey.get())); 1544 1113 auto messageBodyDictionary = dictionaryValue(messageBody); 1114 auto hostName = stringValue(messageBodyDictionary, "HostName"); 1115 auto hostNameRedirectedTo = stringValue(messageBodyDictionary, "HostNameRedirectedTo"); 1545 1116 TestController::singleton().setStatisticsTopFrameUniqueRedirectTo(hostName, hostNameRedirectedTo); 1546 1117 return nullptr; … … 1548 1119 1549 1120 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsTopFrameUniqueRedirectFrom")) { 1550 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1551 1552 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1553 WKRetainPtr<WKStringRef> hostNameKey = adoptWK(WKStringCreateWithUTF8CString("HostName")); 1554 WKRetainPtr<WKStringRef> hostNameRedirectedFromKey = adoptWK(WKStringCreateWithUTF8CString("HostNameRedirectedFrom")); 1555 1556 WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get())); 1557 WKStringRef hostNameRedirectedFrom = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameRedirectedFromKey.get())); 1558 1121 auto messageBodyDictionary = dictionaryValue(messageBody); 1122 auto hostName = stringValue(messageBodyDictionary, "HostName"); 1123 auto hostNameRedirectedFrom = stringValue(messageBodyDictionary, "HostNameRedirectedFrom"); 1559 1124 TestController::singleton().setStatisticsTopFrameUniqueRedirectFrom(hostName, hostNameRedirectedFrom); 1560 1125 return nullptr; … … 1562 1127 1563 1128 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsCrossSiteLoadWithLinkDecoration")) { 1564 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1565 1566 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1567 auto fromHostKey = adoptWK(WKStringCreateWithUTF8CString("FromHost")); 1568 auto toHostKey = adoptWK(WKStringCreateWithUTF8CString("ToHost")); 1569 1570 WKStringRef fromHost = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, fromHostKey.get())); 1571 WKStringRef toHost = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, toHostKey.get())); 1572 1129 auto messageBodyDictionary = dictionaryValue(messageBody); 1130 auto fromHost = stringValue(messageBodyDictionary, "FromHost"); 1131 auto toHost = stringValue(messageBodyDictionary, "ToHost"); 1573 1132 TestController::singleton().setStatisticsCrossSiteLoadWithLinkDecoration(fromHost, toHost); 1574 1133 return nullptr; … … 1576 1135 1577 1136 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsTimeToLiveUserInteraction")) { 1578 ASSERT(WKGetTypeID(messageBody) == WKDoubleGetTypeID()); 1579 WKDoubleRef seconds = static_cast<WKDoubleRef>(messageBody); 1580 TestController::singleton().setStatisticsTimeToLiveUserInteraction(WKDoubleGetValue(seconds)); 1137 TestController::singleton().setStatisticsTimeToLiveUserInteraction(doubleValue(messageBody)); 1581 1138 return nullptr; 1582 1139 } … … 1593 1150 1594 1151 if (WKStringIsEqualToUTF8CString(messageName, "StatisticsNotifyPagesWhenDataRecordsWereScanned")) { 1595 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 1596 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 1597 TestController::singleton().setStatisticsNotifyPagesWhenDataRecordsWereScanned(WKBooleanGetValue(value)); 1152 TestController::singleton().setStatisticsNotifyPagesWhenDataRecordsWereScanned(booleanValue(messageBody)); 1598 1153 return nullptr; 1599 1154 } 1600 1155 1601 1156 if (WKStringIsEqualToUTF8CString(messageName, "StatisticsSetIsRunningTest")) { 1602 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 1603 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 1604 TestController::singleton().setStatisticsIsRunningTest(WKBooleanGetValue(value)); 1157 TestController::singleton().setStatisticsIsRunningTest(booleanValue(messageBody)); 1605 1158 return nullptr; 1606 1159 } 1607 1160 1608 1161 if (WKStringIsEqualToUTF8CString(messageName, "StatisticsShouldClassifyResourcesBeforeDataRecordsRemoval")) { 1609 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 1610 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 1611 TestController::singleton().setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(WKBooleanGetValue(value)); 1162 TestController::singleton().setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(booleanValue(messageBody)); 1612 1163 return nullptr; 1613 1164 } 1614 1165 1615 1166 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsMinimumTimeBetweenDataRecordsRemoval")) { 1616 ASSERT(WKGetTypeID(messageBody) == WKDoubleGetTypeID()); 1617 WKDoubleRef seconds = static_cast<WKDoubleRef>(messageBody); 1618 TestController::singleton().setStatisticsMinimumTimeBetweenDataRecordsRemoval(WKDoubleGetValue(seconds)); 1167 TestController::singleton().setStatisticsMinimumTimeBetweenDataRecordsRemoval(doubleValue(messageBody)); 1619 1168 return nullptr; 1620 1169 } 1621 1170 1622 1171 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsGrandfatheringTime")) { 1623 ASSERT(WKGetTypeID(messageBody) == WKDoubleGetTypeID()); 1624 WKDoubleRef seconds = static_cast<WKDoubleRef>(messageBody); 1625 TestController::singleton().setStatisticsGrandfatheringTime(WKDoubleGetValue(seconds)); 1172 TestController::singleton().setStatisticsGrandfatheringTime(doubleValue(messageBody)); 1626 1173 return nullptr; 1627 1174 } 1628 1175 1629 1176 if (WKStringIsEqualToUTF8CString(messageName, "SetMaxStatisticsEntries")) { 1630 ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID()); 1631 WKUInt64Ref entries = static_cast<WKUInt64Ref>(messageBody); 1632 TestController::singleton().setStatisticsMaxStatisticsEntries(WKUInt64GetValue(entries)); 1177 TestController::singleton().setStatisticsMaxStatisticsEntries(uint64Value(messageBody)); 1633 1178 return nullptr; 1634 1179 } 1635 1180 1636 1181 if (WKStringIsEqualToUTF8CString(messageName, "SetPruneEntriesDownTo")) { 1637 ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID()); 1638 WKUInt64Ref entries = static_cast<WKUInt64Ref>(messageBody); 1639 TestController::singleton().setStatisticsPruneEntriesDownTo(WKUInt64GetValue(entries)); 1182 TestController::singleton().setStatisticsPruneEntriesDownTo(uint64Value(messageBody)); 1640 1183 return nullptr; 1641 1184 } 1642 1185 1643 1186 if (WKStringIsEqualToUTF8CString(messageName, "StatisticsDeleteCookiesForHost")) { 1644 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1645 1646 WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); 1647 WKRetainPtr<WKStringRef> hostNameKey = adoptWK(WKStringCreateWithUTF8CString("HostName")); 1648 WKRetainPtr<WKStringRef> valueKey = adoptWK(WKStringCreateWithUTF8CString("IncludeHttpOnlyCookies")); 1649 1650 WKStringRef hostName = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, hostNameKey.get())); 1651 WKBooleanRef includeHttpOnlyCookies = static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, valueKey.get())); 1652 1653 TestController::singleton().statisticsDeleteCookiesForHost(hostName, WKBooleanGetValue(includeHttpOnlyCookies)); 1187 auto messageBodyDictionary = dictionaryValue(messageBody); 1188 auto hostName = stringValue(messageBodyDictionary, "HostName"); 1189 auto includeHttpOnlyCookies = booleanValue(messageBodyDictionary, "IncludeHttpOnlyCookies"); 1190 TestController::singleton().statisticsDeleteCookiesForHost(hostName, includeHttpOnlyCookies); 1654 1191 return nullptr; 1655 1192 } 1656 1193 1657 1194 if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsHasLocalStorage")) { 1658 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 1659 1660 WKStringRef hostName = static_cast<WKStringRef>(messageBody); 1195 auto hostName = stringValue(messageBody); 1661 1196 bool hasLocalStorage = TestController::singleton().isStatisticsHasLocalStorage(hostName); 1662 1197 auto result = adoptWK(WKBooleanCreate(hasLocalStorage)); … … 1665 1200 1666 1201 if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsCacheMaxAgeCap")) { 1667 ASSERT(WKGetTypeID(messageBody) == WKDoubleGetTypeID()); 1668 WKDoubleRef seconds = static_cast<WKDoubleRef>(messageBody); 1669 TestController::singleton().setStatisticsCacheMaxAgeCap(WKDoubleGetValue(seconds)); 1202 TestController::singleton().setStatisticsCacheMaxAgeCap(doubleValue(messageBody)); 1670 1203 return nullptr; 1671 1204 } 1672 1205 1673 1206 if (WKStringIsEqualToUTF8CString(messageName, "HasStatisticsIsolatedSession")) { 1674 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 1675 1676 WKStringRef hostName = static_cast<WKStringRef>(messageBody); 1207 auto hostName = stringValue(messageBody); 1677 1208 bool hasIsolatedSession = TestController::singleton().hasStatisticsIsolatedSession(hostName); 1678 1209 auto result = adoptWK(WKBooleanCreate(hasIsolatedSession)); … … 1681 1212 1682 1213 if (WKStringIsEqualToUTF8CString(messageName, "ClearDOMCache")) { 1683 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 1684 WKStringRef origin = static_cast<WKStringRef>(messageBody); 1685 1214 auto origin = stringValue(messageBody); 1686 1215 TestController::singleton().clearDOMCache(origin); 1687 1216 return nullptr; … … 1694 1223 1695 1224 if (WKStringIsEqualToUTF8CString(messageName, "HasDOMCache")) { 1696 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 1697 WKStringRef origin = static_cast<WKStringRef>(messageBody); 1698 1225 auto origin = stringValue(messageBody); 1699 1226 bool hasDOMCache = TestController::singleton().hasDOMCache(origin); 1700 WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(hasDOMCache)); 1701 return result; 1227 return adoptWK(WKBooleanCreate(hasDOMCache)); 1702 1228 } 1703 1229 1704 1230 if (WKStringIsEqualToUTF8CString(messageName, "DOMCacheSize")) { 1705 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 1706 WKStringRef origin = static_cast<WKStringRef>(messageBody); 1707 1231 auto origin = stringValue(messageBody); 1708 1232 auto domCacheSize = TestController::singleton().domCacheSize(origin); 1709 WKRetainPtr<WKTypeRef> result = adoptWK(WKUInt64Create(domCacheSize)); 1710 return result; 1233 return adoptWK(WKUInt64Create(domCacheSize)); 1711 1234 } 1712 1235 1713 1236 if (WKStringIsEqualToUTF8CString(messageName, "SetAllowStorageQuotaIncrease")) { 1714 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 1715 auto canIncrease = WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody)); 1716 TestController::singleton().setAllowStorageQuotaIncrease(canIncrease); 1237 TestController::singleton().setAllowStorageQuotaIncrease(booleanValue(messageBody)); 1717 1238 return nullptr; 1718 1239 } 1719 1240 1720 1241 if (WKStringIsEqualToUTF8CString(messageName, "InjectUserScript")) { 1721 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 1722 WKStringRef script = static_cast<WKStringRef>(messageBody); 1723 1724 TestController::singleton().injectUserScript(script); 1242 TestController::singleton().injectUserScript(stringValue(messageBody)); 1725 1243 return nullptr; 1726 1244 } … … 1732 1250 1733 1251 if (WKStringIsEqualToUTF8CString(messageName, "SetServiceWorkerFetchTimeout")) { 1734 ASSERT(WKGetTypeID(messageBody) == WKDoubleGetTypeID()); 1735 WKDoubleRef seconds = static_cast<WKDoubleRef>(messageBody); 1736 TestController::singleton().setServiceWorkerFetchTimeoutForTesting(WKDoubleGetValue(seconds)); 1252 TestController::singleton().setServiceWorkerFetchTimeoutForTesting(doubleValue(messageBody)); 1737 1253 return nullptr; 1738 1254 } 1739 1255 1740 1256 if (WKStringIsEqualToUTF8CString(messageName, "SetUseSeparateServiceWorkerProcess")) { 1741 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 1742 auto useSeparateServiceWorkerProcess = WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody)); 1257 auto useSeparateServiceWorkerProcess = booleanValue(messageBody); 1743 1258 WKContextSetUseSeparateServiceWorkerProcess(TestController::singleton().context(), useSeparateServiceWorkerProcess); 1744 1259 return nullptr; … … 1758 1273 1759 1274 if (WKStringIsEqualToUTF8CString(messageName, "AddTestKeyToKeychain")) { 1760 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1761 WKDictionaryRef testKeyDictionary = static_cast<WKDictionaryRef>(messageBody); 1762 1763 WKRetainPtr<WKStringRef> privateKeyKey = adoptWK(WKStringCreateWithUTF8CString("PrivateKey")); 1764 WKStringRef privateKeyWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(testKeyDictionary, privateKeyKey.get())); 1765 1766 WKRetainPtr<WKStringRef> attrLabelKey = adoptWK(WKStringCreateWithUTF8CString("AttrLabel")); 1767 WKStringRef attrLabelWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(testKeyDictionary, attrLabelKey.get())); 1768 1769 WKRetainPtr<WKStringRef> applicationTagKey = adoptWK(WKStringCreateWithUTF8CString("ApplicationTag")); 1770 WKStringRef applicationTagWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(testKeyDictionary, applicationTagKey.get())); 1771 1275 auto testKeyDictionary = dictionaryValue(messageBody); 1276 auto privateKeyWK = stringValue(testKeyDictionary, "PrivateKey"); 1277 auto attrLabelWK = stringValue(testKeyDictionary, "AttrLabel"); 1278 auto applicationTagWK = stringValue(testKeyDictionary, "ApplicationTag"); 1772 1279 TestController::singleton().addTestKeyToKeychain(toWTFString(privateKeyWK), toWTFString(attrLabelWK), toWTFString(applicationTagWK)); 1773 1280 return nullptr; … … 1775 1282 1776 1283 if (WKStringIsEqualToUTF8CString(messageName, "CleanUpKeychain")) { 1777 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1778 WKDictionaryRef testDictionary = static_cast<WKDictionaryRef>(messageBody); 1779 1780 WKRetainPtr<WKStringRef> attrLabelKey = adoptWK(WKStringCreateWithUTF8CString("AttrLabel")); 1781 WKStringRef attrLabelWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(testDictionary, attrLabelKey.get())); 1782 1783 WKRetainPtr<WKStringRef> applicationLabelKey = adoptWK(WKStringCreateWithUTF8CString("ApplicationLabel")); 1784 WKStringRef applicationLabelWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(testDictionary, applicationLabelKey.get())); 1785 1284 auto testDictionary = dictionaryValue(messageBody); 1285 auto attrLabelWK = stringValue(testDictionary, "AttrLabel"); 1286 auto applicationLabelWK = stringValue(testDictionary, "ApplicationLabel"); 1786 1287 TestController::singleton().cleanUpKeychain(toWTFString(attrLabelWK), applicationLabelWK ? toWTFString(applicationLabelWK) : String()); 1787 1288 return nullptr; … … 1789 1290 1790 1291 if (WKStringIsEqualToUTF8CString(messageName, "KeyExistsInKeychain")) { 1791 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 1792 WKDictionaryRef testDictionary = static_cast<WKDictionaryRef>(messageBody); 1793 1794 WKRetainPtr<WKStringRef> attrLabelKey = adoptWK(WKStringCreateWithUTF8CString("AttrLabel")); 1795 WKStringRef attrLabelWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(testDictionary, attrLabelKey.get())); 1796 1797 WKRetainPtr<WKStringRef> applicationLabelKey = adoptWK(WKStringCreateWithUTF8CString("ApplicationLabel")); 1798 WKStringRef applicationLabelWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(testDictionary, applicationLabelKey.get())); 1799 1292 auto testDictionary = dictionaryValue(messageBody); 1293 auto attrLabelWK = stringValue(testDictionary, "AttrLabel"); 1294 auto applicationLabelWK = stringValue(testDictionary, "ApplicationLabel"); 1800 1295 bool keyExistsInKeychain = TestController::singleton().keyExistsInKeychain(toWTFString(attrLabelWK), toWTFString(applicationLabelWK)); 1801 WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(keyExistsInKeychain)); 1802 return result; 1803 } 1804 1805 if (WKStringIsEqualToUTF8CString(messageName, "ServerTrustEvaluationCallbackCallsCount")) { 1806 WKRetainPtr<WKTypeRef> result = adoptWK(WKUInt64Create(TestController::singleton().serverTrustEvaluationCallbackCallsCount())); 1807 return result; 1808 } 1296 return adoptWK(WKBooleanCreate(keyExistsInKeychain)); 1297 } 1298 1299 if (WKStringIsEqualToUTF8CString(messageName, "ServerTrustEvaluationCallbackCallsCount")) 1300 return adoptWK(WKUInt64Create(TestController::singleton().serverTrustEvaluationCallbackCallsCount())); 1809 1301 1810 1302 if (WKStringIsEqualToUTF8CString(messageName, "ShouldDismissJavaScriptAlertsAsynchronously")) { 1811 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 1812 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 1813 TestController::singleton().setShouldDismissJavaScriptAlertsAsynchronously(WKBooleanGetValue(value)); 1303 TestController::singleton().setShouldDismissJavaScriptAlertsAsynchronously(booleanValue(messageBody)); 1814 1304 return nullptr; 1815 1305 } … … 1841 1331 1842 1332 if (WKStringIsEqualToUTF8CString(messageName, "SetAdClickAttributionOverrideTimerForTesting")) { 1843 ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID()); 1844 WKBooleanRef value = static_cast<WKBooleanRef>(messageBody); 1845 TestController::singleton().setAdClickAttributionOverrideTimerForTesting(WKBooleanGetValue(value)); 1333 TestController::singleton().setAdClickAttributionOverrideTimerForTesting(booleanValue(messageBody)); 1846 1334 return nullptr; 1847 1335 } … … 1849 1337 if (WKStringIsEqualToUTF8CString(messageName, "SetAdClickAttributionConversionURLForTesting")) { 1850 1338 ASSERT(WKGetTypeID(messageBody) == WKURLGetTypeID()); 1851 WKURLRef url = static_cast<WKURLRef>(messageBody); 1852 TestController::singleton().setAdClickAttributionConversionURLForTesting(url); 1339 TestController::singleton().setAdClickAttributionConversionURLForTesting(static_cast<WKURLRef>(messageBody)); 1853 1340 return nullptr; 1854 1341 } … … 1895 1382 void TestInvocation::uiScriptDidComplete(const String& result, unsigned scriptCallbackID) 1896 1383 { 1897 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallUISideScriptCallback")); 1898 1899 WKRetainPtr<WKMutableDictionaryRef> messageBody = adoptWK(WKMutableDictionaryCreate()); 1900 WKRetainPtr<WKStringRef> resultKey = adoptWK(WKStringCreateWithUTF8CString("Result")); 1901 WKRetainPtr<WKStringRef> callbackIDKey = adoptWK(WKStringCreateWithUTF8CString("CallbackID")); 1902 WKRetainPtr<WKUInt64Ref> callbackIDValue = adoptWK(WKUInt64Create(scriptCallbackID)); 1903 1904 WKDictionarySetItem(messageBody.get(), resultKey.get(), toWK(result).get()); 1905 WKDictionarySetItem(messageBody.get(), callbackIDKey.get(), callbackIDValue.get()); 1906 1907 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), messageBody.get()); 1384 auto messageBody = adoptWK(WKMutableDictionaryCreate()); 1385 setValue(messageBody, "Result", result); 1386 setValue(messageBody, "CallbackID", static_cast<uint64_t>(scriptCallbackID)); 1387 postPageMessage("CallUISideScriptCallback", messageBody); 1908 1388 } 1909 1389 … … 1915 1395 void TestInvocation::didBeginSwipe() 1916 1396 { 1917 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidBeginSwipeCallback")); 1918 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1397 postPageMessage("CallDidBeginSwipeCallback"); 1919 1398 } 1920 1399 1921 1400 void TestInvocation::willEndSwipe() 1922 1401 { 1923 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallWillEndSwipeCallback")); 1924 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1402 postPageMessage("CallWillEndSwipeCallback"); 1925 1403 } 1926 1404 1927 1405 void TestInvocation::didEndSwipe() 1928 1406 { 1929 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidEndSwipeCallback")); 1930 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1407 postPageMessage("CallDidEndSwipeCallback"); 1931 1408 } 1932 1409 1933 1410 void TestInvocation::didRemoveSwipeSnapshot() 1934 1411 { 1935 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidRemoveSwipeSnapshotCallback")); 1936 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1412 postPageMessage("CallDidRemoveSwipeSnapshotCallback"); 1937 1413 } 1938 1414 1939 1415 void TestInvocation::notifyDownloadDone() 1940 1416 { 1941 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("NotifyDownloadDone")); 1942 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1417 postPageMessage("NotifyDownloadDone"); 1943 1418 } 1944 1419 1945 1420 void TestInvocation::didClearStatisticsInMemoryAndPersistentStore() 1946 1421 { 1947 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidClearStatisticsInMemoryAndPersistentStore")); 1948 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1422 postPageMessage("CallDidClearStatisticsInMemoryAndPersistentStore"); 1949 1423 } 1950 1424 1951 1425 void TestInvocation::didClearStatisticsThroughWebsiteDataRemoval() 1952 1426 { 1953 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidClearStatisticsThroughWebsiteDataRemoval")); 1954 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1427 postPageMessage("CallDidClearStatisticsThroughWebsiteDataRemoval"); 1955 1428 } 1956 1429 1957 1430 void TestInvocation::didSetShouldDowngradeReferrer() 1958 1431 { 1959 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetShouldDowngradeReferrer")); 1960 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1432 postPageMessage("CallDidSetShouldDowngradeReferrer"); 1961 1433 } 1962 1434 1963 1435 void TestInvocation::didSetShouldBlockThirdPartyCookies() 1964 1436 { 1965 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetShouldBlockThirdPartyCookies")); 1966 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), nullptr); 1437 postPageMessage("CallDidSetShouldBlockThirdPartyCookies"); 1967 1438 } 1968 1439 1969 1440 void TestInvocation::didSetFirstPartyWebsiteDataRemovalMode() 1970 1441 { 1971 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetFirstPartyWebsiteDataRemovalMode")); 1972 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), nullptr); 1442 postPageMessage("CallDidSetFirstPartyWebsiteDataRemovalMode"); 1973 1443 } 1974 1444 1975 1445 void TestInvocation::didSetToSameSiteStrictCookies() 1976 1446 { 1977 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetToSameSiteStrictCookies")); 1978 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), nullptr); 1447 postPageMessage("CallDidSetToSameSiteStrictCookies"); 1979 1448 } 1980 1449 1981 1450 void TestInvocation::didSetFirstPartyHostCNAMEDomain() 1982 1451 { 1983 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetFirstPartyHostCNAMEDomain")); 1984 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), nullptr); 1452 postPageMessage("CallDidSetFirstPartyHostCNAMEDomain"); 1985 1453 } 1986 1454 1987 1455 void TestInvocation::didSetThirdPartyCNAMEDomain() 1988 1456 { 1989 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetThirdPartyCNAMEDomain")); 1990 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), nullptr); 1457 postPageMessage("CallDidSetThirdPartyCNAMEDomain"); 1991 1458 } 1992 1459 1993 1460 void TestInvocation::didResetStatisticsToConsistentState() 1994 1461 { 1995 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidResetStatisticsToConsistentState")); 1996 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1462 postPageMessage("CallDidResetStatisticsToConsistentState"); 1997 1463 } 1998 1464 1999 1465 void TestInvocation::didSetBlockCookiesForHost() 2000 1466 { 2001 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetBlockCookiesForHost")); 2002 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1467 postPageMessage("CallDidSetBlockCookiesForHost"); 2003 1468 } 2004 1469 2005 1470 void TestInvocation::didSetStatisticsDebugMode() 2006 1471 { 2007 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetStatisticsDebugMode")); 2008 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1472 postPageMessage("CallDidSetStatisticsDebugMode"); 2009 1473 } 2010 1474 2011 1475 void TestInvocation::didSetPrevalentResourceForDebugMode() 2012 1476 { 2013 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetPrevalentResourceForDebugMode")); 2014 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1477 postPageMessage("CallDidSetPrevalentResourceForDebugMode"); 2015 1478 } 2016 1479 2017 1480 void TestInvocation::didSetLastSeen() 2018 1481 { 2019 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetLastSeen")); 2020 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1482 postPageMessage("CallDidSetLastSeen"); 2021 1483 } 2022 1484 2023 1485 void TestInvocation::didMergeStatistic() 2024 1486 { 2025 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidMergeStatistic")); 2026 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1487 postPageMessage("CallDidMergeStatistic"); 2027 1488 } 2028 1489 2029 1490 void TestInvocation::didSetExpiredStatistic() 2030 1491 { 2031 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetExpiredStatistic")); 2032 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1492 postPageMessage("CallDidSetExpiredStatistic"); 2033 1493 } 2034 1494 2035 1495 void TestInvocation::didSetPrevalentResource() 2036 1496 { 2037 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetPrevalentResource")); 2038 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1497 postPageMessage("CallDidSetPrevalentResource"); 2039 1498 } 2040 1499 2041 1500 void TestInvocation::didSetVeryPrevalentResource() 2042 1501 { 2043 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetVeryPrevalentResource")); 2044 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1502 postPageMessage("CallDidSetVeryPrevalentResource"); 2045 1503 } 2046 1504 2047 1505 void TestInvocation::didSetHasHadUserInteraction() 2048 1506 { 2049 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetHasHadUserInteraction")); 2050 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1507 postPageMessage("CallDidSetHasHadUserInteraction"); 2051 1508 } 2052 1509 2053 1510 void TestInvocation::didReceiveAllStorageAccessEntries(Vector<String>&& domains) 2054 1511 { 2055 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidReceiveAllStorageAccessEntries")); 2056 2057 WKRetainPtr<WKMutableArrayRef> messageBody = adoptWK(WKMutableArrayCreate()); 1512 auto messageBody = adoptWK(WKMutableArrayCreate()); 2058 1513 for (auto& domain : domains) 2059 WKArrayAppendItem(messageBody.get(), adoptWK(WKStringCreateWithUTF8CString(domain.utf8().data())).get()); 2060 2061 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), messageBody.get()); 1514 WKArrayAppendItem(messageBody.get(), toWK(domain).get()); 1515 postPageMessage("CallDidReceiveAllStorageAccessEntries", messageBody); 2062 1516 } 2063 1517 2064 1518 void TestInvocation::didReceiveLoadedSubresourceDomains(Vector<String>&& domains) 2065 1519 { 2066 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidReceiveLoadedSubresourceDomains")); 2067 2068 WKRetainPtr<WKMutableArrayRef> messageBody = adoptWK(WKMutableArrayCreate()); 1520 auto messageBody = adoptWK(WKMutableArrayCreate()); 2069 1521 for (auto& domain : domains) 2070 WKArrayAppendItem(messageBody.get(), adoptWK(WKStringCreateWithUTF8CString(domain.utf8().data())).get()); 2071 2072 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), messageBody.get()); 1522 WKArrayAppendItem(messageBody.get(), toWK(domain).get()); 1523 postPageMessage("CallDidReceiveLoadedSubresourceDomains", messageBody); 2073 1524 } 2074 1525 2075 1526 void TestInvocation::didRemoveAllSessionCredentials() 2076 1527 { 2077 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidRemoveAllSessionCredentialsCallback")); 2078 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1528 postPageMessage("CallDidRemoveAllSessionCredentialsCallback"); 2079 1529 } 2080 1530 2081 1531 void TestInvocation::didSetAppBoundDomains() 2082 1532 { 2083 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetAppBoundDomains")); 2084 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), nullptr); 1533 postPageMessage("CallDidSetAppBoundDomains"); 2085 1534 } 2086 1535 … … 2097 1546 void TestInvocation::performCustomMenuAction() 2098 1547 { 2099 WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("PerformCustomMenuAction")); 2100 WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0); 1548 postPageMessage("PerformCustomMenuAction"); 2101 1549 } 2102 1550 -
TabularUnified trunk/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj ¶
r267120 r267761 356 356 841CC00E181185BF0042E9B6 /* Options.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Options.h; sourceTree = "<group>"; }; 357 357 8DD76FA10486AA7600D96B5E /* WebKitTestRunner */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = WebKitTestRunner; sourceTree = BUILT_PRODUCTS_DIR; }; 358 9338D1BA250A79EB00E827F6 /* JSBasics.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = JSBasics.h; path = ../TestRunnerShared/Bindings/JSBasics.h; sourceTree = "<group>"; }; 359 9338D1BE250BD9DD00E827F6 /* DictionaryFunctions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DictionaryFunctions.h; sourceTree = "<group>"; }; 358 360 93764176210D736000A3DAAE /* WebKitTestRunnerWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebKitTestRunnerWindow.mm; sourceTree = "<group>"; }; 359 361 93764177210D736100A3DAAE /* WebKitTestRunnerWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitTestRunnerWindow.h; sourceTree = "<group>"; }; … … 893 895 children = ( 894 896 378D442213346D00006A777B /* config.h */, 897 9338D1BE250BD9DD00E827F6 /* DictionaryFunctions.h */, 895 898 BC99A4841208901A007E9F08 /* StringFunctions.h */, 896 899 9B36A270209453A0003E0651 /* WhatToDump.h */, -
TabularUnified trunk/Tools/WebKitTestRunner/WebNotificationProvider.cpp ¶
r244390 r267761 127 127 removeGlobalIDFromIDMap(m_localToGlobalNotificationIDMap, id); 128 128 129 WKRetainPtr<WKUInt64Ref>wkID = adoptWK(WKUInt64Create(id));130 WKRetainPtr<WKMutableArrayRef>array = adoptWK(WKMutableArrayCreate());129 auto wkID = adoptWK(WKUInt64Create(id)); 130 auto array = adoptWK(WKMutableArrayCreate()); 131 131 WKArrayAppendItem(array.get(), wkID.get()); 132 132 WKNotificationManagerProviderDidCloseNotifications(notificationManager, array.get()); … … 145 145 WKRetainPtr<WKNotificationManagerRef> guard(manager); 146 146 m_ownedNotifications.remove(iterator); 147 WKRetainPtr<WKMutableArrayRef>array = adoptWK(WKMutableArrayCreate());147 auto array = adoptWK(WKMutableArrayCreate()); 148 148 for (uint64_t notificationID : toRemove) { 149 149 bool success = m_owningManager.remove(notificationID); … … 174 174 if (notificationPair.value.isEmpty()) 175 175 continue; 176 WKRetainPtr<WKMutableArrayRef>array = adoptWK(WKMutableArrayCreate());176 auto array = adoptWK(WKMutableArrayCreate()); 177 177 for (uint64_t notificationID : notificationPair.value) 178 178 WKArrayAppendItem(array.get(), adoptWK(WKUInt64Create(notificationID)).get()); -
TabularUnified trunk/Tools/WebKitTestRunner/WorkQueueManager.cpp ¶
r244390 r267761 28 28 29 29 #include "PlatformWebView.h" 30 #include "StringFunctions.h" 30 31 #include "TestController.h" 31 32 #include <WebKit/WKPage.h> … … 76 77 public: 77 78 explicit ScriptItem(const String& script) 78 : m_script( adoptWK(WKStringCreateWithUTF8CString(script.utf8().data())))79 : m_script(toWK(script)) 79 80 { 80 81 } … … 162 163 public: 163 164 LoadHTMLStringItem(const String& content, const String& baseURL, const String& unreachableURL) 164 : m_content( adoptWK(WKStringCreateWithUTF8CString(content.utf8().data())))165 : m_content(toWK(content)) 165 166 , m_baseURL(adoptWK(WKURLCreateWithUTF8CString(baseURL.utf8().data()))) 166 167 , m_unreachableURL(adoptWK(WKURLCreateWithUTF8CString(unreachableURL.utf8().data()))) -
TabularUnified trunk/Tools/WebKitTestRunner/cg/TestInvocationCG.cpp ¶
r263759 r267761 53 53 54 54 // Creating this bitmap in the device color space should prevent any color conversion when the image of the web view is drawn into it. 55 RetainPtr<CGColorSpaceRef>colorSpace = adoptCF(CGColorSpaceCreateDeviceRGB());55 auto colorSpace = adoptCF(CGColorSpaceCreateDeviceRGB()); 56 56 CGContextRef context = CGBitmapContextCreate(0, pixelsWide, pixelsHigh, 8, rowBytes, colorSpace.get(), kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host); 57 57 if (!context) … … 64 64 static CGContextRef createCGContextFromImage(WKImageRef wkImage) 65 65 { 66 RetainPtr<CGImageRef>image = adoptCF(WKImageCreateCGImage(wkImage));66 auto image = adoptCF(WKImageCreateCGImage(wkImage)); 67 67 return createCGContextFromCGImage(image.get()); 68 68 } … … 110 110 static void dumpBitmap(CGContextRef bitmapContext, const char* checksum) 111 111 { 112 RetainPtr<CGImageRef>image = adoptCF(CGBitmapContextCreateImage(bitmapContext));113 RetainPtr<CFMutableDataRef>imageData = adoptCF(CFDataCreateMutable(0, 0));114 RetainPtr<CGImageDestinationRef>imageDest = adoptCF(CGImageDestinationCreateWithData(imageData.get(), kUTTypePNG, 1, 0));112 auto image = adoptCF(CGBitmapContextCreateImage(bitmapContext)); 113 auto imageData = adoptCF(CFDataCreateMutable(0, 0)); 114 auto imageDest = adoptCF(CGImageDestinationCreateWithData(imageData.get(), kUTTypePNG, 1, 0)); 115 115 CGImageDestinationAddImage(imageDest.get(), image.get(), 0); 116 116 CGImageDestinationFinalize(imageDest.get()); -
TabularUnified trunk/Tools/WebKitTestRunner/cocoa/CrashReporterInfo.mm ¶
r264957 r267761 36 36 static String testPathFromURL(WKURLRef url) 37 37 { 38 RetainPtr<CFURLRef>cfURL = adoptCF(WKURLCopyCFURL(kCFAllocatorDefault, url));38 auto cfURL = adoptCF(WKURLCopyCFURL(kCFAllocatorDefault, url)); 39 39 if (!cfURL) 40 40 return String(); 41 41 42 RetainPtr<CFStringRef>schemeCFString = adoptCF(CFURLCopyScheme(cfURL.get()));43 RetainPtr<CFStringRef>pathCFString = adoptCF(CFURLCopyPath(cfURL.get()));42 auto schemeCFString = adoptCF(CFURLCopyScheme(cfURL.get())); 43 auto pathCFString = adoptCF(CFURLCopyPath(cfURL.get())); 44 44 45 45 String schemeString(schemeCFString.get()); … … 58 58 return String(); 59 59 60 RetainPtr<CFStringRef>hostCFString = adoptCF(CFURLCopyHostName(cfURL.get()));60 auto hostCFString = adoptCF(CFURLCopyHostName(cfURL.get())); 61 61 String hostString(hostCFString.get()); 62 62 if (hostString == "127.0.0.1") -
TabularUnified trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm ¶
r267088 r267761 143 143 void TestController::platformCreateWebView(WKPageConfigurationRef, const TestOptions& options) 144 144 { 145 RetainPtr<WKWebViewConfiguration>copiedConfiguration = adoptNS([globalWebViewConfiguration copy]);145 auto copiedConfiguration = adoptNS([globalWebViewConfiguration copy]); 146 146 147 147 #if PLATFORM(IOS_FAMILY) -
TabularUnified trunk/Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.mm ¶
r265211 r267761 91 91 IGNORE_WARNINGS_END 92 92 { 93 RetainPtr<WebKitTestRunnerDraggingInfo>draggingInfo = adoptNS([[WebKitTestRunnerDraggingInfo alloc] initWithImage:anImage offset:initialOffset pasteboard:pboard source:sourceObj]);93 auto draggingInfo = adoptNS([[WebKitTestRunnerDraggingInfo alloc] initWithImage:anImage offset:initialOffset pasteboard:pboard source:sourceObj]); 94 94 [self draggingUpdated:draggingInfo.get()]; 95 95 } -
TabularUnified trunk/Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.h ¶
r267120 r267761 33 33 34 34 class UIScriptControllerCocoa : public UIScriptControllerCommon { 35 public: 35 protected: 36 explicit UIScriptControllerCocoa(UIScriptContext&); 37 TestRunnerWKWebView *webView() const; 38 39 void doAsyncTask(JSValueRef) override; 40 41 private: 36 42 void setViewScale(double) override; 37 43 void setMinimumEffectiveWidth(double) override; 38 44 void becomeFirstResponder() override; 39 45 void resignFirstResponder() override; 40 void doAsyncTask(JSValueRef) override;41 46 void removeViewFromWindow(JSValueRef) override; 42 47 void addViewToWindow(JSValueRef) override; … … 60 65 void insertAttachmentForFilePath(JSStringRef filePath, JSStringRef contentType, JSValueRef callback) override; 61 66 62 protected:63 explicit UIScriptControllerCocoa(UIScriptContext&);64 TestRunnerWKWebView *webView() const;65 66 private:67 67 void completeTaskAsynchronouslyAfterActivityStateUpdate(unsigned callbackID); 68 68 }; -
TabularUnified trunk/Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm ¶
r267120 r267761 136 136 void UIScriptControllerCocoa::overridePreference(JSStringRef preferenceRef, JSStringRef valueRef) 137 137 { 138 WKPreferences *preferences = webView().configuration.preferences; 139 140 String preference = toWTFString(toWK(preferenceRef)); 141 String value = toWTFString(toWK(valueRef)); 142 if (preference == "WebKitMinimumFontSize") 143 preferences.minimumFontSize = value.toDouble(); 138 if (toWTFString(preferenceRef) == "WebKitMinimumFontSize") 139 webView().configuration.preferences.minimumFontSize = toWTFString(valueRef).toDouble(); 144 140 } 145 141 146 142 void UIScriptControllerCocoa::findString(JSStringRef string, unsigned long options, unsigned long maxCount) 147 143 { 148 [webView() _findString:toWTFString( toWK(string)) options:options maxCount:maxCount];144 [webView() _findString:toWTFString(string) options:options maxCount:maxCount]; 149 145 } 150 146 151 147 JSObjectRef UIScriptControllerCocoa::contentsOfUserInterfaceItem(JSStringRef interfaceItem) const 152 148 { 153 NSDictionary *contentDictionary = [webView() _contentsOfUserInterfaceItem:toWTFString( toWK(interfaceItem))];149 NSDictionary *contentDictionary = [webView() _contentsOfUserInterfaceItem:toWTFString(interfaceItem)]; 154 150 return JSValueToObject(m_context->jsContext(), [JSValue valueWithObject:contentDictionary inContext:[JSContext contextWithJSGlobalContextRef:m_context->jsContext()]].JSValueRef, nullptr); 155 151 } … … 220 216 { 221 217 unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent); 222 223 RetainPtr<CFURLRef> testURL = adoptCF(WKURLCopyCFURL(kCFAllocatorDefault, TestController::singleton().currentTestURL())); 224 RetainPtr<NSURL> attachmentURL = [NSURL fileURLWithPath:toWTFString(toWK(filePath)) relativeToURL:(__bridge NSURL *)testURL.get()]; 225 226 auto fileWrapper = adoptNS([[NSFileWrapper alloc] initWithURL:attachmentURL.get() options:0 error:nil]); 227 [webView() _insertAttachmentWithFileWrapper:fileWrapper.get() contentType:toWTFString(toWK(contentType)) completion:^(BOOL success) { 218 auto testURL = adoptCF(WKURLCopyCFURL(kCFAllocatorDefault, TestController::singleton().currentTestURL())); 219 auto attachmentURL = [NSURL fileURLWithPath:toWTFString(filePath) relativeToURL:(__bridge NSURL *)testURL.get()]; 220 auto fileWrapper = adoptNS([[NSFileWrapper alloc] initWithURL:attachmentURL options:0 error:nil]); 221 [webView() _insertAttachmentWithFileWrapper:fileWrapper.get() contentType:toWTFString(contentType) completion:^(BOOL success) { 228 222 if (!m_context) 229 223 return; -
TabularUnified trunk/Tools/WebKitTestRunner/ios/HIDEventGenerator.mm ¶
r259843 r267761 190 190 - (void)_sendIOHIDKeyboardEvent:(uint64_t)timestamp usage:(uint32_t)usage isKeyDown:(bool)isKeyDown 191 191 { 192 RetainPtr<IOHIDEventRef>eventRef = adoptCF(IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault,192 auto eventRef = adoptCF(IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault, 193 193 timestamp, 194 194 kHIDPage_KeyboardOrKeypad, … … 362 362 363 363 uint64_t machTime = mach_absolute_time(); 364 RetainPtr<IOHIDEventRef>eventRef = adoptCF(IOHIDEventCreateDigitizerEvent(kCFAllocatorDefault, machTime,364 auto eventRef = adoptCF(IOHIDEventCreateDigitizerEvent(kCFAllocatorDefault, machTime, 365 365 kIOHIDDigitizerTransducerTypeHand, 366 366 0, … … 454 454 455 455 if (eventRef) { 456 RetainPtr<IOHIDEventRef> strongEvent = eventRef;456 auto strongEvent = retainPtr(eventRef); 457 457 dispatch_async(dispatch_get_main_queue(), ^{ 458 458 uint32_t contextID = [UIApplication sharedApplication].keyWindow._contextId; … … 513 513 } 514 514 515 RetainPtr<IOHIDEventRef>eventRef = adoptCF([self _createIOHIDEventType:handEventType]);515 auto eventRef = adoptCF([self _createIOHIDEventType:handEventType]); 516 516 [self _sendHIDEvent:eventRef.get()]; 517 517 } … … 530 530 } 531 531 532 RetainPtr<IOHIDEventRef>eventRef = adoptCF([self _createIOHIDEventType:HandEventTouched]);532 auto eventRef = adoptCF([self _createIOHIDEventType:HandEventTouched]); 533 533 [self _sendHIDEvent:eventRef.get()]; 534 534 } … … 564 564 } 565 565 566 RetainPtr<IOHIDEventRef>eventRef = adoptCF([self _createIOHIDEventType:HandEventLifted]);566 auto eventRef = adoptCF([self _createIOHIDEventType:HandEventLifted]); 567 567 [self _sendHIDEvent:eventRef.get()]; 568 568 … … 642 642 _activePoints[0].altitudeAngle = M_PI_2 - altitudeAngle; 643 643 644 RetainPtr<IOHIDEventRef>eventRef = adoptCF([self _createIOHIDEventType:StylusEventTouched]);644 auto eventRef = adoptCF([self _createIOHIDEventType:StylusEventTouched]); 645 645 [self _sendHIDEvent:eventRef.get()]; 646 646 } … … 656 656 _activePoints[0].altitudeAngle = M_PI_2 - altitudeAngle; 657 657 658 RetainPtr<IOHIDEventRef>eventRef = adoptCF([self _createIOHIDEventType:StylusEventMoved]);658 auto eventRef = adoptCF([self _createIOHIDEventType:StylusEventMoved]); 659 659 [self _sendHIDEvent:eventRef.get()]; 660 660 } … … 669 669 _activePoints[0].altitudeAngle = 0; 670 670 671 RetainPtr<IOHIDEventRef>eventRef = adoptCF([self _createIOHIDEventType:StylusEventLifted]);671 auto eventRef = adoptCF([self _createIOHIDEventType:StylusEventLifted]); 672 672 [self _sendHIDEvent:eventRef.get()]; 673 673 } … … 1022 1022 ASSERT([NSThread isMainThread]); 1023 1023 1024 RetainPtr<IOHIDEventRef>eventRef = adoptCF([self _createIOHIDEventWithInfo:eventInfo]);1024 auto eventRef = adoptCF([self _createIOHIDEventWithInfo:eventInfo]); 1025 1025 [self _sendHIDEvent:eventRef.get()]; 1026 1026 } -
TabularUnified trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.h ¶
r266342 r267761 26 26 #pragma once 27 27 28 #if PLATFORM(IOS_FAMILY) 29 28 30 #import "UIScriptControllerCocoa.h" 29 31 #import <wtf/BlockPtr.h> 30 31 #if PLATFORM(IOS_FAMILY)32 32 33 33 namespace WebCore { … … 38 38 namespace WTR { 39 39 40 class UIScriptControllerIOS : public UIScriptControllerCocoa {40 class UIScriptControllerIOS final : public UIScriptControllerCocoa { 41 41 public: 42 42 explicit UIScriptControllerIOS(UIScriptContext& context) … … 45 45 } 46 46 47 private: 47 48 void waitForOutstandingCallbacks() override; 48 49 void doAfterPresentationUpdate(JSValueRef) override; … … 157 158 void clearAllCallbacks() override; 158 159 159 private:160 160 void waitForModalTransitionToFinish() const; 161 161 void waitForSingleTapToReset() const; -
TabularUnified trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm ¶
r266342 r267761 69 69 } 70 70 71 static unsigned arrayLength(JSContextRef context, JSObjectRef array)72 {73 auto lengthString = adopt(JSStringCreateWithUTF8CString("length"));74 if (auto lengthValue = JSObjectGetProperty(context, array, lengthString.get(), nullptr))75 return static_cast<unsigned>(JSValueToNumber(context, lengthValue, nullptr));76 return 0;77 }78 79 71 static Vector<String> parseModifierArray(JSContextRef context, JSValueRef arrayValue) 80 72 { … … 83 75 84 76 // The value may either be a string with a single modifier or an array of modifiers. 85 if (JSValueIsString(context, arrayValue)) { 86 auto string = toWTFString(toWK(adopt(JSValueToStringCopy(context, arrayValue, nullptr)))); 87 return { string }; 88 } 77 if (JSValueIsString(context, arrayValue)) 78 return { toWTFString(context, arrayValue) }; 89 79 90 80 if (!JSValueIsObject(context, arrayValue)) … … 94 84 Vector<String> modifiers; 95 85 modifiers.reserveInitialCapacity(length); 96 for (unsigned i = 0; i < length; ++i) { 97 JSValueRef exception = nullptr; 98 JSValueRef value = JSObjectGetPropertyAtIndex(context, array, i, &exception); 99 if (exception) 100 continue; 101 auto string = adopt(JSValueToStringCopy(context, value, &exception)); 102 if (exception) 103 continue; 104 modifiers.append(toWTFString(toWK(string.get()))); 105 } 86 for (unsigned i = 0; i < length; ++i) 87 modifiers.append(toWTFString(context, JSObjectGetPropertyAtIndex(context, array, i, nullptr))); 106 88 return modifiers; 107 89 } … … 515 497 516 498 // Assumes that the keyboard is already shown. 517 [[HIDEventGenerator sharedHIDEventGenerator] keyPress:toWTFString(toWK(character)) completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] { 518 if (!m_context) 519 return; 520 m_context->asyncTaskComplete(callbackID); 499 [[HIDEventGenerator sharedHIDEventGenerator] keyPress:toWTFString(character) completionBlock:makeBlockPtr([strongThis = makeRef(*this), callbackID] { 500 if (strongThis->m_context) 501 strongThis->m_context->asyncTaskComplete(callbackID); 521 502 }).get()]; 522 503 } … … 535 516 // Key can be either a single Unicode code point or the name of a special key (e.g. "downArrow"). 536 517 // HIDEventGenerator knows how to map these special keys to the appropriate keycode. 537 [[HIDEventGenerator sharedHIDEventGenerator] keyDown:toWTFString( toWK(key))];518 [[HIDEventGenerator sharedHIDEventGenerator] keyDown:toWTFString(key)]; 538 519 [[HIDEventGenerator sharedHIDEventGenerator] sendMarkerHIDEventWithCompletionBlock:^{ /* Do nothing */ }]; 539 520 } … … 543 524 // Key can be either a single Unicode code point or the name of a special key (e.g. "downArrow"). 544 525 // HIDEventGenerator knows how to map these special keys to the appropriate keycode. 545 [[HIDEventGenerator sharedHIDEventGenerator] keyUp:toWTFString( toWK(key))];526 [[HIDEventGenerator sharedHIDEventGenerator] keyUp:toWTFString(key)]; 546 527 [[HIDEventGenerator sharedHIDEventGenerator] sendMarkerHIDEventWithCompletionBlock:^{ /* Do nothing */ }]; 547 528 } … … 551 532 // Character can be either a single Unicode code point or the name of a special key (e.g. "downArrow"). 552 533 // HIDEventGenerator knows how to map these special keys to the appropriate keycode. 553 String inputString = toWTFString(toWK(character));534 auto inputString = toWTFString(character); 554 535 auto modifierFlags = parseModifierArray(m_context->jsContext(), modifierArray); 555 536 … … 728 709 729 710 TestRunnerWKWebView *webView = this->webView(); 730 [webView applyAutocorrection:toWTFString( toWK(newString)) toString:toWTFString(toWK(oldString)) withCompletionHandler:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {711 [webView applyAutocorrection:toWTFString(newString) toString:toWTFString(oldString) withCompletionHandler:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] { 731 712 dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] { 732 713 // applyAutocorrection can call its completion handler synchronously, … … 1158 1139 void UIScriptControllerIOS::setKeyboardInputModeIdentifier(JSStringRef identifier) 1159 1140 { 1160 TestController::singleton().setKeyboardInputModeIdentifier(toWTFString( toWK(identifier)));1141 TestController::singleton().setKeyboardInputModeIdentifier(toWTFString(identifier)); 1161 1142 } 1162 1143 … … 1179 1160 JSObjectRef UIScriptControllerIOS::attachmentInfo(JSStringRef jsAttachmentIdentifier) 1180 1161 { 1181 auto attachmentIdentifier = toWTFString( toWK(jsAttachmentIdentifier));1162 auto attachmentIdentifier = toWTFString(jsAttachmentIdentifier); 1182 1163 _WKAttachment *attachment = [webView() _attachmentForIdentifier:attachmentIdentifier]; 1183 1164 _WKAttachmentInfo *attachmentInfo = attachment.info; -
TabularUnified trunk/Tools/WebKitTestRunner/mac/EventSenderProxy.mm ¶
r267281 r267761 273 273 EventSenderProxy::EventSenderProxy(TestController* testController) 274 274 : m_testController(testController) 275 , m_time(0) 276 , m_position() 277 , m_leftMouseButtonDown(false) 278 , m_clickCount(0) 279 , m_clickTime(0) 280 , m_clickPosition() 281 , m_clickButton(kWKEventMouseButtonNoButton) 282 , eventNumber(0) 283 { 284 } 285 286 EventSenderProxy::~EventSenderProxy() 287 { 288 } 275 { 276 } 277 278 EventSenderProxy::~EventSenderProxy() = default; 289 279 290 280 void EventSenderProxy::updateClickCountForButton(int button) … … 395 385 RetainPtr<NSEvent> EventSenderProxy::beginPressureEvent(int stage) 396 386 { 397 RetainPtr<EventSenderSyntheticEvent>event = adoptNS([[EventSenderSyntheticEvent alloc] initPressureEventAtLocation:NSMakePoint(m_position.x, m_position.y)387 auto event = adoptNS([[EventSenderSyntheticEvent alloc] initPressureEventAtLocation:NSMakePoint(m_position.x, m_position.y) 398 388 globalLocation:([m_testController->mainWebView()->platformWindow() convertRectToScreen:NSMakeRect(m_position.x, m_position.y, 1, 1)].origin) 399 389 stage:stage … … 410 400 RetainPtr<NSEvent> EventSenderProxy::pressureChangeEvent(int stage, float pressure, EventSenderProxy::PressureChangeDirection direction) 411 401 { 412 RetainPtr<EventSenderSyntheticEvent>event = adoptNS([[EventSenderSyntheticEvent alloc] initPressureEventAtLocation:NSMakePoint(m_position.x, m_position.y)402 auto event = adoptNS([[EventSenderSyntheticEvent alloc] initPressureEventAtLocation:NSMakePoint(m_position.x, m_position.y) 413 403 globalLocation:([m_testController->mainWebView()->platformWindow() convertRectToScreen:NSMakeRect(m_position.x, m_position.y, 1, 1)].origin) 414 404 stage:stage … … 432 422 sendMouseDownToStartPressureEvents(); 433 423 434 RetainPtr<NSEvent>beginPressure = beginPressureEvent(1);435 RetainPtr<NSEvent>preForceClick = pressureChangeEvent(1, PressureChangeDirection::Increasing);436 RetainPtr<NSEvent>forceClick = pressureChangeEvent(2, PressureChangeDirection::Increasing);437 RetainPtr<NSEvent>releasingPressure = pressureChangeEvent(1, PressureChangeDirection::Decreasing);424 auto beginPressure = beginPressureEvent(1); 425 auto preForceClick = pressureChangeEvent(1, PressureChangeDirection::Increasing); 426 auto forceClick = pressureChangeEvent(2, PressureChangeDirection::Increasing); 427 auto releasingPressure = pressureChangeEvent(1, PressureChangeDirection::Decreasing); 438 428 NSEvent *mouseUp = [NSEvent mouseEventWithType:NSEventTypeLeftMouseUp 439 429 location:NSMakePoint(m_position.x, m_position.y) … … 469 459 sendMouseDownToStartPressureEvents(); 470 460 471 RetainPtr<NSEvent>beginPressure = beginPressureEvent(1);472 RetainPtr<NSEvent>increasingPressure = pressureChangeEvent(1, PressureChangeDirection::Increasing);473 RetainPtr<NSEvent>releasingPressure = pressureChangeEvent(1, PressureChangeDirection::Decreasing);461 auto beginPressure = beginPressureEvent(1); 462 auto increasingPressure = pressureChangeEvent(1, PressureChangeDirection::Increasing); 463 auto releasingPressure = pressureChangeEvent(1, PressureChangeDirection::Decreasing); 474 464 NSEvent *mouseUp = [NSEvent mouseEventWithType:NSEventTypeLeftMouseUp 475 465 location:NSMakePoint(m_position.x, m_position.y) … … 504 494 sendMouseDownToStartPressureEvents(); 505 495 506 RetainPtr<NSEvent>beginPressure = beginPressureEvent(1);507 RetainPtr<NSEvent>preForceClick = pressureChangeEvent(1, PressureChangeDirection::Increasing);508 RetainPtr<NSEvent>forceMouseDown = pressureChangeEvent(2, PressureChangeDirection::Increasing);496 auto beginPressure = beginPressureEvent(1); 497 auto preForceClick = pressureChangeEvent(1, PressureChangeDirection::Increasing); 498 auto forceMouseDown = pressureChangeEvent(2, PressureChangeDirection::Increasing); 509 499 510 500 NSView *targetView = [m_testController->mainWebView()->platformView() hitTest:[beginPressure locationInWindow]]; … … 527 517 void EventSenderProxy::mouseForceUp() 528 518 { 529 RetainPtr<NSEvent>beginPressure = beginPressureEvent(2);530 RetainPtr<NSEvent>stageTwoEvent = pressureChangeEvent(2, PressureChangeDirection::Decreasing);531 RetainPtr<NSEvent>stageOneEvent = pressureChangeEvent(1, PressureChangeDirection::Decreasing);519 auto beginPressure = beginPressureEvent(2); 520 auto stageTwoEvent = pressureChangeEvent(2, PressureChangeDirection::Decreasing); 521 auto stageOneEvent = pressureChangeEvent(1, PressureChangeDirection::Decreasing); 532 522 533 523 // Since AppKit does not implement forceup/down as mouse events, we need to send two pressure events to detect … … 552 542 int stage = force < 1 ? 1 : 2; 553 543 float pressure = force < 1 ? force : force - 1; 554 RetainPtr<NSEvent>beginPressure = beginPressureEvent(stage);555 RetainPtr<NSEvent>pressureChangedEvent = pressureChangeEvent(stage, pressure, PressureChangeDirection::Increasing);544 auto beginPressure = beginPressureEvent(stage); 545 auto pressureChangedEvent = pressureChangeEvent(stage, pressure, PressureChangeDirection::Increasing); 556 546 557 547 NSView *targetView = [m_testController->mainWebView()->platformView() hitTest:[beginPressure locationInWindow]]; … … 612 602 void EventSenderProxy::keyDown(WKStringRef key, WKEventModifiers modifiers, unsigned keyLocation) 613 603 { 614 NSString* character = [NSString stringWithCString:toSTD(key).c_str() 615 encoding:[NSString defaultCStringEncoding]]; 604 NSString* character = toWTFString(key); 616 605 617 606 NSString *eventCharacter = character; … … 833 822 void EventSenderProxy::mouseScrollBy(int x, int y) 834 823 { 835 RetainPtr<CGEventRef>cgScrollEvent = adoptCF(CGEventCreateScrollWheelEvent2(0, kCGScrollEventUnitLine, 2, y, x, 0));824 auto cgScrollEvent = adoptCF(CGEventCreateScrollWheelEvent2(0, kCGScrollEventUnitLine, 2, y, x, 0)); 836 825 837 826 // Set the CGEvent location in flipped coords relative to the first screen, which … … 860 849 void EventSenderProxy::mouseScrollByWithWheelAndMomentumPhases(int x, int y, int phase, int momentum) 861 850 { 862 RetainPtr<CGEventRef>cgScrollEvent = adoptCF(CGEventCreateScrollWheelEvent2(0, kCGScrollEventUnitLine, 2, y, x, 0));851 auto cgScrollEvent = adoptCF(CGEventCreateScrollWheelEvent2(0, kCGScrollEventUnitLine, 2, y, x, 0)); 863 852 864 853 // Set the CGEvent location in flipped coords relative to the first screen, which -
TabularUnified trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm ¶
r259843 r267761 65 65 [[NSUserDefaults standardUserDefaults] setValue:@YES forKey:@"WebKit2UseRemoteLayerTreeDrawingArea"]; 66 66 67 RetainPtr<WKWebViewConfiguration>copiedConfiguration = adoptNS([configuration copy]);67 auto copiedConfiguration = adoptNS([configuration copy]); 68 68 WKPreferencesSetThreadedScrollingEnabled((__bridge WKPreferencesRef)[copiedConfiguration preferences], m_options.useThreadedScrolling); 69 69 -
TabularUnified trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm ¶
r265396 r267761 185 185 return; 186 186 187 RetainPtr<CFURLRef>testURL = adoptCF(WKURLCopyCFURL(kCFAllocatorDefault, test.url()));187 auto testURL = adoptCF(WKURLCopyCFURL(kCFAllocatorDefault, test.url())); 188 188 NSURL *filterURL = [(__bridge NSURL *)testURL.get() URLByAppendingPathExtension:@"json"]; 189 189 … … 372 372 static WKRetainPtr<WKArrayRef> generateFontAllowList() 373 373 { 374 WKRetainPtr<WKMutableArrayRef>result = adoptWK(WKMutableArrayCreate());374 auto result = adoptWK(WKMutableArrayCreate()); 375 375 for (NSString *fontFamily in allowedFontFamilySet()) { 376 376 NSArray *fontsForFamily = [[NSFontManager sharedFontManager] availableMembersOfFontFamily:fontFamily]; 377 WKRetainPtr<WKStringRef>familyInFont = adoptWK(WKStringCreateWithUTF8CString([fontFamily UTF8String]));377 auto familyInFont = adoptWK(WKStringCreateWithUTF8CString([fontFamily UTF8String])); 378 378 WKArrayAppendItem(result.get(), familyInFont.get()); 379 379 for (NSArray *fontInfo in fontsForFamily) { 380 380 // Font name is the first entry in the array. 381 WKRetainPtr<WKStringRef>fontName = adoptWK(WKStringCreateWithUTF8CString([[fontInfo objectAtIndex:0] UTF8String]));381 auto fontName = adoptWK(WKStringCreateWithUTF8CString([[fontInfo objectAtIndex:0] UTF8String])); 382 382 WKArrayAppendItem(result.get(), fontName.get()); 383 383 } … … 395 395 // and if we haven't created one yet, the default one will be created on disk. 396 396 // Making the shared cache memory-only avoids touching the file system. 397 RetainPtr<NSURLCache>sharedCache =397 auto sharedCache = 398 398 adoptNS([[NSURLCache alloc] initWithMemoryCapacity:1024 * 1024 399 399 diskCapacity:0 -
TabularUnified trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.h ¶
r266461 r267761 32 32 namespace WTR { 33 33 34 class UIScriptControllerMac : public UIScriptControllerCocoa {34 class UIScriptControllerMac final : public UIScriptControllerCocoa { 35 35 public: 36 36 explicit UIScriptControllerMac(UIScriptContext& context) … … 39 39 } 40 40 41 private: 41 42 void replaceTextAtRange(JSStringRef, int, int) override; 42 43 void zoomToScale(double, JSValueRef) override; … … 63 64 void activateAtPoint(long x, long y, JSValueRef callback) override; 64 65 65 private:66 66 NSTableView *dataListSuggestionsTableView() const; 67 67 }; -
TabularUnified trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm ¶
r266461 r267761 215 215 void UIScriptControllerMac::playBackEventStream(JSStringRef eventStream, JSValueRef callback) 216 216 { 217 RetainPtr<CFStringRef>stream = adoptCF(JSStringCopyCFString(kCFAllocatorDefault, eventStream));217 auto stream = adoptCF(JSStringCopyCFString(kCFAllocatorDefault, eventStream)); 218 218 playBackEvents(webView(), m_context, (__bridge NSString *)stream.get(), callback); 219 219 }
Note:
See TracChangeset
for help on using the changeset viewer.