Changeset 267761 in webkit


Ignore:
Timestamp:
Sep 29, 2020, 2:38:57 PM (5 years ago)
Author:
Darin Adler
Message:

Refactor test runner code to cut down on copy/paste code and long-winded repetitive idioms
https://bugs.webkit.org/show_bug.cgi?id=217028

Reviewed by Sam Weinig.

Source/JavaScriptCore:

  • API/JSRetainPtr.h: Added support for JSClassRef.

Tools:

I did a lot of simplifying, but even more is possible. For some reason, the test
code is a hotbed of repeated idioms, and copy and paste rather than helper functions.
Even after the refactoring, I have some doubts about the way this code is written with
so much repeated marshaling for each function.

  • DumpRenderTree/AccessibilityController.cpp:

(AccessibilityController::makeWindowObject): Use setGlobalObjectProperty.
(AccessibilityController::createJSClass): Replaced getJSClass with this. Return a
JSRetainPtr to make it clear this passes ownership to the caller.

  • DumpRenderTree/AccessibilityController.h: Updated for the above.
  • DumpRenderTree/AccessibilityUIElement.cpp:

(uiElementCountForSearchPredicateCallback): Removed unneeded initialization of
JSRetainPtr, which starts out null.

  • DumpRenderTree/Bindings/CodeGeneratorDumpRenderTree.pm:

(_platformTypeConstructor): Use toOptionalBool and createJSString.
(_returnExpression): Use makeValue.

  • DumpRenderTree/GCController.cpp:

(GCController::GCController): Deleted.
(GCController::~GCController): Deleted.
(collectCallback): Use a reference and auto.
(collectOnAlternateThreadCallback): Ditto.
(getJSObjectCountCallback): Ditto.
(GCController::makeWindowObject): Use setGlobalObjectProperty.
(AccessibilityController::createJSClass): Replaced getJSClass with this. Return a
JSRetainPtr to make it clear this passes ownership to the caller.

  • DumpRenderTree/GCController.h: Updated for the above.
  • DumpRenderTree/TestRunner.cpp:

(encodeHostNameCallback): Use createJSString.
(execCommandCallback): Ditto.
(findStringCallback): Ditto.
(isCommandEnabledCallback): Ditto.
(overridePreferenceCallback): Ditto.
(queueLoadCallback): Ditto.
(queueLoadHTMLStringCallback): Ditto.
(TestRunner::makeWindowObject): Use setGlobalObjectProperty.
(TestRunner::createJSClass): Replaced getJSClass with this. Return a
JSRetainPtr to make it clear this passes ownership to the caller.
(TestRunner::staticValues): Made return value const*.
(TestRunner::staticFunctions): Ditto.
(TestRunner::waitToDumpWatchdogTimerFired): Simplified printing.
(TestRunner::cacheTestRunnerCallback): Updated to use object pointers as hash
table values instead of values, since callbacks need to be objects.
(TestRunner::callTestRunnerCallback): Ditto.
(TestRunner::clearTestRunnerCallbacks): Ditto.
(TestRunner::setOpenPanelFiles): Use arrayLength.

  • DumpRenderTree/TestRunner.h: Updated for the above.
  • DumpRenderTree/ios/AccessibilityControllerIOS.mm:

(AccessibilityController::platformName const): Use createJSString.

  • DumpRenderTree/ios/AccessibilityUIElementIOS.mm:

(createEmptyJSString): Dleted.
(AccessibilityUIElement::stringForTextMarkerRange): Use createJSString.
(AccessibilityUIElement::attributesOfLinkedUIElements): Ditto.
(AccessibilityUIElement::attributesOfDocumentLinks): Ditto.
(AccessibilityUIElement::attributesOfChildren): Ditto.
(AccessibilityUIElement::allAttributes): Ditto.
(AccessibilityUIElement::stringAttributeValue): Ditto.
(AccessibilityUIElement::parameterizedAttributeNames): Ditto.
(AccessibilityUIElement::role): Ditto.
(AccessibilityUIElement::subrole): Ditto.
(AccessibilityUIElement::roleDescription): Ditto.
(AccessibilityUIElement::computedRoleString): Ditto.
(AccessibilityUIElement::title): Ditto.
(AccessibilityUIElement::orientation const): Ditto.
(AccessibilityUIElement::language): Ditto.
(AccessibilityUIElement::valueDescription): Ditto.
(AccessibilityUIElement::ariaDropEffects const): Ditto.
(AccessibilityUIElement::boundsForRange): Ditto.
(AccessibilityUIElement::attributesOfColumnHeaders): Ditto.
(AccessibilityUIElement::attributesOfRowHeaders): Ditto.
(AccessibilityUIElement::attributesOfColumns): Ditto.
(AccessibilityUIElement::attributesOfRows): Ditto.
(AccessibilityUIElement::attributesOfVisibleCells): Ditto.
(AccessibilityUIElement::attributesOfHeader): Ditto.
(AccessibilityUIElement::selectedTextRange): Ditto.
(AccessibilityUIElement::accessibilityValue const): Ditto.
(AccessibilityUIElement::documentEncoding): Ditto.
(AccessibilityUIElement::documentURI): Ditto.

  • DumpRenderTree/mac/AccessibilityCommonMac.h: Removed unneeded "extern".
  • DumpRenderTree/mac/AccessibilityCommonMac.mm:

(searchPredicateParameterizedAttributeForSearchCriteria): Use arrayLength.
Removed unneeded call to JSValueToObject after JSValueIsObject.

  • DumpRenderTree/mac/AccessibilityControllerMac.mm:

(AccessibilityController::platformName const): Use createJSString.

  • DumpRenderTree/mac/AccessibilityUIElementMac.mm:

(createEmptyJSString): Deleted.
(selectTextParameterizedAttributeForCriteria): Use arrayLength.
Removed unneeded call to JSValueToObject after JSValueIsObject.
(searchTextParameterizedAttributeForCriteria): Ditto.
(AccessibilityUIElement::accessibilityValue const): Use createJSString.
(AccessibilityUIElement::documentEncoding): Ditto.
(AccessibilityUIElement::documentURI): Ditto.

  • DumpRenderTree/mac/FrameLoadDelegate.mm:

(-[FrameLoadDelegate didClearWindowObjectInStandardWorldForFrame:]):
Use auto. Pass fewer arguments to makeWindowObject. Simplified object
creation code by using adoptNS instead of release.
(-[FrameLoadDelegate didClearWindowObjectForFrame:inIsolatedWorld:]):
Use createJSString.

  • DumpRenderTree/mac/TestRunnerMac.mm:

(TestRunner::findString): Use arrayLength.

  • DumpRenderTree/win/FrameLoadDelegate.cpp:

(FrameLoadDelegate::didClearWindowObjectForFrameInStandardWorld):
Pass fewer arguments to makeWindowObject.

  • DumpRenderTree/win/TextInputController.cpp:

(TextInputController::makeWindowObject): Use setGlobalObjectProperty.
(TextInputController::createJSClass): Replaced getJSClass with this. Return a
JSRetainPtr to make it clear this passes ownership to the caller.
(TextInputController::staticValues): Made return value const*.
(TextInputController::staticFunctions): Ditto.

  • DumpRenderTree/win/TextInputController.h: Updated for above.
  • TestRunnerShared/Bindings/JSBasics.cpp:

(WTR::toOptionalBool): Renamed from JSValueMakeBooleanOrNull.
(WTR::toOptionalDouble): Added.
(WTR::makeValue): Added with overloads for various types.
Replaced JSValueToNullableBoolean and JSValueMakeStringOrNull.
(WTR::createJSString): Added with overloads for various types.
(WTR::property): Added.
(WTR::stringProperty): Added.
(WTR::booleanProperty): Added.
(WTR::numericProperty): Added.
(WTR::objectProperty): Refactored to call property.
(WTR::arrayLength): Added.
(WTR::setGlobalObjectProperty): Added.
(WTR::call): Refactored to let objectProperty do more of the null checking.
(WTR::callConstructor): Ditto.

  • TestRunnerShared/Bindings/JSBasics.h: Updated for the above.
  • TestRunnerShared/Bindings/JSWrappable.h: Reduced includes a bit.
  • TestRunnerShared/Bindings/JSWrapper.h: Added setGlobalObjectProperty.
  • TestRunnerShared/UIScriptContext/UIScriptContext.cpp:

(UIScriptContext::UIScriptContext): Pass fewer arguments to makeWindowObject.
(UIScriptContext::runUIScript): Use createJSString.
(UIScriptContext::objectFromRect const): Use setProperty.

  • TestRunnerShared/UIScriptContext/UIScriptController.h: Updated for the above.
  • TestRunnerShared/UIScriptContext/UIScriptControllerShared.cpp:

(WTR::toDeviceOrientation): Use createJSString and JSStringIsEqualToUTF8CString.
(WTR::UIScriptController::makeWindowObject): Use setGlobalObjectProperty.

  • TestRunnerShared/cocoa/LayoutTestSpellChecker.mm:

(-[LayoutTestSpellChecker setResultsFromJSValue:inContext:]): Use createJSString
and removed unneeded use of lroundl.

  • WebKitTestRunner/DictionaryFunctions.h: Added. Contains convenience functions

for dealing with WKDictionaryRef.

  • WebKitTestRunner/EventSenderProxy.h: Initialize data members.
  • WebKitTestRunner/GeolocationProviderMock.cpp:

(GeolocationProviderMock::setPosition): Use Optional instead of separate bool.

  • WebKitTestRunner/GeolocationProviderMock.h: Updated for the above.
  • WebKitTestRunner/InjectedBundle/AccessibilityController.cpp:

(WTR::AccessibilityController::makeWindowObject): Use setGlobalObjectProperty.

  • WebKitTestRunner/InjectedBundle/AccessibilityController.h: Updated for the above.
  • WebKitTestRunner/InjectedBundle/Bindings/CodeGeneratorTestRunner.pm:

(_generateImplementationFile): Use static initialization and a lambda instead of
an if statement to initialize.
(_platformTypeConstructor): Use toOptionalBool and createJSString. Also added
support for nullable doubles and used auto a bit more.
(_returnExpression): Use makeValue.

  • InjectedBundle/Bindings/TestRunner.idl: Made the optional arguments to the

setMockGeolocationPosition function "double?" instead of "object".

  • WebKitTestRunner/InjectedBundle/EventSendingController.cpp:

(WTR::getMenuItemChildrenCallback): Use auto and not JSValueToObject.
(WTR::arrayLength): Moved to JSBasics.h/cpp.
(WTR::parseTouchModifier): Added. Factored out of the
EventSendingController::setTouchModifier function.
(WTR::parseModifierArray): Use createJSString and remove unneeded ignored
exception out argument, since that is optional. Also added overload that
gets the context.
(WTR::EventSendingController::EventSendingController): Deleted.
(WTR::EventSendingController::~EventSendingController): Deleted.
(WTR::createMouseMessageBody): Use adoptWK and setValue. Return a WKRetainPtr.
(WTR::EventSendingController::mouseDown): Use postSynchronousPageMessage.
(WTR::EventSendingController::mouseUp): Ditto.
(WTR::EventSendingController::mouseMoveTo): Use setValue and
postSynchronousPageMessages.
(WTR::EventSendingController::mouseForceClick): Ditto.
(WTR::EventSendingController::startAndCancelMouseForceClick): Ditto.
(WTR::EventSendingController::mouseForceDown): Ditto.
(WTR::EventSendingController::mouseForceUp): Ditto.
(WTR::EventSendingController::mouseForceChanged): Ditto.
(WTR::EventSendingController::leapForward): Ditto.
(WTR::EventSendingController::scheduleAsynchronousClick): Use postPageMessage.
(WTR::createKeyDownMessageBody): Use setValue.
(WTR::EventSendingController::keyDown): Use postSynchronousPageMessage.
(WTR::EventSendingController::scheduleAsynchronousKeyDown): Use postPageMessage.
(WTR::EventSendingController::mouseScrollBy): Use setValue and postPageMessage.
(WTR::EventSendingController::mouseScrollByWithWheelAndMomentumPhases): Use
setValue and postPageMessage.
(WTR::EventSendingController::continuousMouseScrollBy): Use setValue and
postSynchronousPageMessage.
(WTR::EventSendingController::contextClick): Use auto and not JSValueToObject.
(WTR::toMonitorWheelEventsOptions): Use booleanProperty.
(WTR::EventSendingController::addTouchPoint): Use setValue and postSynchronousPageMessage.
(WTR::EventSendingController::updateTouchPoint): Ditto.
(WTR::EventSendingController::setTouchModifier): Ditto.
(WTR::EventSendingController::setTouchPointRadius): Ditto.
(WTR::EventSendingController::touchStart): Ditto.
(WTR::EventSendingController::touchMove): Ditto.
(WTR::EventSendingController::touchEnd): Ditto.
(WTR::EventSendingController::touchCancel): Ditto.
(WTR::EventSendingController::clearTouchPoints): Ditto.
(WTR::EventSendingController::releaseTouchPoint): Ditto.
(WTR::EventSendingController::cancelTouchPoint): Ditto.
(WTR::EventSendingController::makeWindowObject): Use setGlobalObjectProperty.

  • WebKitTestRunner/InjectedBundle/EventSendingController.h: Updated for the above.

Deleted various unneeded functions.

  • WebKitTestRunner/InjectedBundle/GCController.cpp:

(WTR::GCController::GCController): Deleted.
(WTR::GCController::~GCController): Deleted.
(WTR::GCController::makeWindowObject): Use setGlobalObjectProperty.

  • WebKitTestRunner/InjectedBundle/GCController.h: Updated for the above.

Also marked the class final.

  • WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:

(WTR::InjectedBundle::didCreatePage): Use booleanValue.
(WTR::InjectedBundle::didReceiveMessage): Use toWK.
(WTR::InjectedBundle::postPageMessage): Added.
(WTR::InjectedBundle::reportLiveDocuments): Use postPageMessage.
(WTR::InjectedBundle::didReceiveMessageToPage): Use dictionaryValue,
booleanValue, postPageMessage, value, and more to streamline.
(WTR::InjectedBundle::booleanForKey): Deleted.
(WTR::InjectedBundle::stringForKey): Deleted.
(WTR::InjectedBundle::beginTesting): Use booleanValue.
(WTR::InjectedBundle::done): Use stringValue.
(WTR::InjectedBundle::closeOtherPages): Use setValue and toWK.
(WTR::InjectedBundle::dumpToStdErr): Use postPageMessage
(WTR::InjectedBundle::outputText): Use toWK.
(WTR::InjectedBundle::postNewBeforeUnloadReturnValue): Use postPageMessage.
(WTR::InjectedBundle::postAddChromeInputField): Ditto.
(WTR::InjectedBundle::postRemoveChromeInputField): Ditto.
(WTR::InjectedBundle::postFocusWebView): Ditto.
(WTR::InjectedBundle::postSetBackingScaleFactor): Ditto.
(WTR::InjectedBundle::postSetWindowIsKey): Use toWK.
(WTR::InjectedBundle::postSetViewSize): Use setValue and toWK.
(WTR::InjectedBundle::postSimulateWebNotificationClick): Use postPageMessage.
(WTR::InjectedBundle::postSetAddsVisitedLinks): Ditto.
(WTR::InjectedBundle::setGeolocationPermission): Ditto.
(WTR::InjectedBundle::setMockGeolocationPosition): Use setValue and postPageMessage,
and use Optional instead of bool/double pairs.
(WTR::InjectedBundle::setMockGeolocationPositionUnavailableError): Use postPageMessage.
(WTR::InjectedBundle::isGeolocationProviderActive const): Use toWK and booleanValue.
(WTR::InjectedBundle::imageCountInGeneralPasteboard const): Use toWK and uint64Value.
(WTR::InjectedBundle::setUserMediaPermission): Use postPageMessage.
(WTR::InjectedBundle::resetUserMediaPermission): Ditto.
(WTR::InjectedBundle::setUserMediaPersistentPermissionForOrigin): Use setValue
and postPageMessage.
(WTR::InjectedBundle::userMediaPermissionRequestCountForOrigin const): Ditto.
(WTR::InjectedBundle::resetUserMediaPermissionRequestCountForOrigin): Uset setValue
and uint64Value.
(WTR::InjectedBundle::setCustomPolicyDelegate): Use setValue and postPageMessage.
(WTR::InjectedBundle::setHidden): Ditto.
(WTR::InjectedBundle::setCacheModel): Ditto.
(WTR::InjectedBundle::shouldProcessWorkQueue const): Use toWK and booleanValue.
(WTR::InjectedBundle::processWorkQueue): Use postPageMessage.
(WTR::InjectedBundle::queueBackNavigation): Ditto.
(WTR::InjectedBundle::queueForwardNavigation): Ditto.
(WTR::InjectedBundle::queueLoad): Use setValue and postPageMessage.
(WTR::InjectedBundle::queueLoadHTMLString): Ditto.
(WTR::InjectedBundle::queueReload): Ditto.
(WTR::InjectedBundle::queueLoadingScript): Ditto.
(WTR::InjectedBundle::queueNonLoadingScript): Ditto.
(WTR::postMessage): Added. Overloads for many types to keep caller code streamlined.
(WTR::postSynchronousMessage): Ditto.
(WTR::postPageMessage): Ditto.
(WTR::postSynchronousPageMessage): Ditto.

  • WebKitTestRunner/InjectedBundle/InjectedBundle.h: Updated for the above.
  • WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:

(WTR::propertyValue): Deleted. Use functions from JSBasics.h instead.
(WTR::propertyValueDouble): Ditto.
(WTR::propertyValueInt): Ditto.
(WTR::numericWindowProperty): Renamed from numericWindowPropertyValue for brevity
and for consistency with JSBasics.h functions.
(WTR::dumpPath): Use stringProperty, objectProperty, and makeString.
(WTR::rangeToStr): Use auto, numericProperty, and makeString.
(WTR::NavigationTypeToString): Use toWK.
(WTR::string): Renamed from securityOriginToStr. Use makeString.
(WTR::frameToStr): Use auto.
(WTR::InjectedBundlePage::resetAfterTest): Removed unneeded local.
(WTR::dumpFrameDescriptionSuitableForTestResult): Use auto.
(WTR::dumpRequestDescriptionSuitableForTestResult): Ditto.
(WTR::dumpErrorDescriptionSuitableForTestResult): Use auto and toWK.
(WTR::dumpFrameScrollPosition): Update for name change.
(WTR::toJS): Deleted. Use functions from JSBasics.h instead.
(WTR::hasDocumentElement): Use objectProperty.
(WTR::InjectedBundlePage::didClearWindowForFrame): Use setGlobalObjectProperty,
and pass fewer arguments to makeWindowObject.
(WTR::InjectedBundlePage::decidePolicyForNavigationAction): Streamline code a bit.
(WTR::InjectedBundlePage::decidePolicyForResponse): Use makeString.
(WTR::lastFileURLPathComponent): Ditto.
(WTR::InjectedBundlePage::willSetStatusbarText): Ditto.
(WTR::InjectedBundlePage::didReachApplicationCacheOriginQuota): Ditto.
(WTR::InjectedBundlePage::didExceedDatabaseQuota): Ditto.
(WTR::InjectedBundlePage::shouldBeginEditing): Ditto.
(WTR::InjectedBundlePage::shouldEndEditing): Ditto.

  • WebKitTestRunner/InjectedBundle/TestRunner.cpp:

(WTR::TestRunner::TestRunner): Use toWK.
(WTR::page): Added.
(WTR::mainFrame): Added.
(WTR::mainFrameJSContext): Added.
(WTR::TestRunner::display): Use page.
(WTR::TestRunner::displayAndTrackRepaints): Use page.
(WTR::toWK): Added overload for double.
(WTR::createWKDictionary): Added.
(WTR::postSynchronousMessageWithReturnValue): Added.
(WTR::postSynchronousMessageReturningBoolean): Added.
(WTR::postSynchronousPageMessageWithReturnValue): Added.
(WTR::postSynchronousPageMessageReturningBoolean): Added.
(WTR::postSynchronousPageMessageReturningUInt64): Added.
(WTR::postSynchronousMessageReturningUInt64): Added.
(WTR::overridePreference): Added.
(WTR::TestRunner::shouldDumpPixels const): Use postSynchronousMessageReturningBoolean.
(WTR::TestRunner::setDumpPixels): Use postSynchronousMessage.
(WTR::TestRunner::whatToDump const): Use postSynchronousMessageReturningUInt64.
(WTR::TestRunner::setWhatToDump): Use postSynchronousMessage.
(WTR::TestRunner::setWaitUntilDone): Use postSynchronousMessage.
(WTR::TestRunner::shouldWaitUntilDone const): Use postSynchronousMessageReturningBoolean.
(WTR::TestRunner::setShouldDumpFrameLoadCallbacks): Use postSynchronousMessage.
(WTR::TestRunner::shouldDumpFrameLoadCallbacks): Use postSynchronousMessageReturningBoolean.
(WTR::TestRunner::addUserScript): Use page.
(WTR::TestRunner::addUserStyleSheet): Ditto.
(WTR::TestRunner::execCommand): Ditto.
(WTR::findOptionsFromArray): Use mainFrameJSContext, arrayLength, and createJSString.
(WTR::TestRunner::findString): Use page.
(WTR::TestRunner::findStringMatchesInPage): Ditto.
(WTR::TestRunner::replaceFindMatchesAtIndices): Use mainFrameJSContext and arrayLength and
removed unneeded call to std::round.
(WTR::TestRunner::clearAllDatabases): Use postSynchronousMessage.
(WTR::TestRunner::syncLocalStorage): Ditto.
(WTR::TestRunner::clearAllApplicationCaches): Use page.
(WTR::TestRunner::clearApplicationCacheForOrigin): Ditto.
(WTR::TestRunner::setAppCacheMaximumSize): Ditto.
(WTR::TestRunner::applicationCacheDiskUsageForOrigin): Ditto.
(WTR::stringArrayToJS): Tweaked coding style a bit.
(WTR::TestRunner::originsWithApplicationCache): Use page.
(WTR::TestRunner::isCommandEnabled): Ditto.
(WTR::TestRunner::setCanOpenWindows): Use postSynchronousMessage.
(WTR::TestRunner::setXSSAuditorEnabled): Use overridePreference.
(WTR::TestRunner::setMediaDevicesEnabled): Ditto.
(WTR::TestRunner::setWebRTCMDNSICECandidatesEnabled): Ditto.
(WTR::TestRunner::setCustomUserAgent): Use postSynchronousMessage.
(WTR::TestRunner::setWebAPIStatisticsEnabled): Use overridePreference.
(WTR::TestRunner::setModernMediaControlsEnabled): Ditto.
(WTR::TestRunner::setWebGL2Enabled): Ditto.
(WTR::TestRunner::setWritableStreamAPIEnabled): Ditto.
(WTR::TestRunner::setTransformStreamAPIEnabled): Ditto.
(WTR::TestRunner::setReadableByteStreamAPIEnabled): Ditto.
(WTR::TestRunner::setEncryptedMediaAPIEnabled): Ditto.
(WTR::TestRunner::setPictureInPictureAPIEnabled): Ditto.
(WTR::TestRunner::setGenericCueAPIEnabled): Ditto.
(WTR::TestRunner::setAllowsAnySSLCertificate): Use postSynchronousPageMessage.
(WTR::TestRunner::setShouldSwapToEphemeralSessionOnNextNavigation): Ditto.
(WTR::TestRunner::setShouldSwapToDefaultSessionOnNextNavigation): Ditto.
(WTR::TestRunner::setPluginsEnabled): Use overridePreference.
(WTR::TestRunner::isPageBoxVisible): Use mainFrame.
(WTR::TestRunner::setValueForUser): Removed local.
(WTR::TestRunner::setAudioResult): Ditto.
(WTR::TestRunner::clearBackForwardList): Use page.
(WTR::TestRunner::makeWindowObject): Use setGlobalObjectProperty.
(WTR::TestRunner::showWebInspector): Use page.
(WTR::TestRunner::closeWebInspector): Ditto.
(WTR::TestRunner::evaluateInWebInspector): Ditto.
(WTR::TestRunner::worldIDForWorld): Use range-based for loop.
(WTR::TestRunner::evaluateScriptInIsolatedWorld): Use mainFrame.
(WTR::TestRunner::setTextDirection): Use mainFrame.
(WTR::TestRunner::didReceiveServerRedirectForProvisionalNavigation const):
Use postSynchronousPageMessageReturningBoolean.
(WTR::TestRunner::clearDidReceiveServerRedirectForProvisionalNavigation):
Use postSynchronousPageMessage.
(WTR::cacheTestRunnerCallback): Changed map to store objects instead of values.
(WTR::callTestRunnerCallback): Simplify since map has objects. Use mainFrameJSContext.
(WTR::TestRunner::clearTestRunnerCallbacks): Ditto.
(WTR::TestRunner::setAlwaysAcceptCookies): Use postSynchronousMessage.
(WTR::TestRunner::setOnlyAcceptFirstPartyCookies): Use auto and toWK.
(WTR::TestRunner::setUserStyleSheetEnabled): Use toWK.
(WTR::TestRunner::setUserStyleSheetLocation): Use page.
(WTR::TestRunner::setTabKeyCyclesThroughElements): Ditto.
(WTR::TestRunner::grantWebNotificationPermission): Ditto.
(WTR::TestRunner::denyWebNotificationPermission): Ditto.
(WTR::TestRunner::removeAllWebNotificationPermissions): Use mainFrameJSContext.
(WTR::TestRunner::simulateWebNotificationClick): Ditto.
(WTR::TestRunner::setMockGeolocationPosition): Use Optional<double> instead of bool/double
pairs, letting the IDL bindings do the work for us.
(WTR::TestRunner::setMockGeolocationPositionUnavailableError): Removed local.
(WTR::TestRunner::isDoingMediaCapture const): Use postSynchronousPageMessageReturningBoolean.
(WTR::TestRunner::setUserMediaPersistentPermissionForOrigin): Removed locals.
(WTR::TestRunner::userMediaPermissionRequestCountForOrigin const): Ditto.
(WTR::TestRunner::resetUserMediaPermissionRequestCountForOrigin): DItto.
(WTR::TestRunner::callShouldCloseOnWebView): Use mainFrame.
(WTR::TestRunner::queueLoad): Ditto.
(WTR::TestRunner::queueLoadHTMLString): Removed a local.
(WTR::TestRunner::queueLoadingScript): Ditto.
(WTR::TestRunner::queueNonLoadingScript): Ditto.
(WTR::TestRunner::setRejectsProtectionSpaceAndContinueForAuthenticationChallenges):
Use postPageMessage.
(WTR::TestRunner::setHandlesAuthenticationChallenges): Ditto.
(WTR::TestRunner::setShouldLogCanAuthenticateAgainstProtectionSpace): Ditto.
(WTR::TestRunner::setShouldLogDownloadCallbacks): Ditto.
(WTR::TestRunner::setAuthenticationUsername): Ditto.
(WTR::TestRunner::setAuthenticationPassword): Ditto.
(WTR::TestRunner::secureEventInputIsEnabled const): Use postSynchronousPageMessageReturningBoolean.
(WTR::TestRunner::setBlockAllPlugins): Use postPageMessage.
(WTR::TestRunner::setPluginSupportedMode): Ditto.
(WTR::TestRunner::failNextNewCodeBlock): Use mainFrameJSContext.
(WTR::TestRunner::numberOfDFGCompiles): Ditto.
(WTR::TestRunner::neverInlineFunction): Ditto.
(WTR::TestRunner::setShouldDecideNavigationPolicyAfterDelay): Use postPageMessage.
(WTR::TestRunner::setShouldDecideResponsePolicyAfterDelay): Ditto.
(WTR::TestRunner::setNavigationGesturesEnabled): Ditto.
(WTR::TestRunner::setIgnoresViewportScaleLimits): Ditto.
(WTR::TestRunner::setShouldDownloadUndisplayableMIMETypes): Ditto.
(WTR::TestRunner::setShouldAllowDeviceOrientationAndMotionAccess): Ditto.
(WTR::TestRunner::terminateNetworkProcess): Use postSynchronousPageMessage.
(WTR::TestRunner::terminateServiceWorkers): Ditto.
(WTR::TestRunner::setUseSeparateServiceWorkerProcess): Ditto.
(WTR::TestRunner::runUIScript): Use postPageMessage.
(WTR::TestRunner::runUIScriptImmediately): Ditto.
(WTR::TestRunner::runUIScriptCallback): Use mainFrameJSContext.
(WTR::TestRunner::setAllowedMenuActions): Use mainFrameJSContext, arrayLength,
and postPageMessage.
(WTR::TestRunner::installCustomMenuAction): Use postPageMessage.
(WTR::TestRunner::clearStatisticsDataForDomain): Use postSynchronousMessage.
(WTR::TestRunner::doesStatisticsDomainIDExistInDatabase): Use
postSynchronousPageMessageReturningBoolean.
(WTR::TestRunner::setStatisticsEnabled): Use postSynchronousMessage.
(WTR::TestRunner::isStatisticsEphemeral): Use postSynchronousPageMessageReturningBoolean.
(WTR::TestRunner::setStatisticsDebugMode): Use postMessage.
(WTR::TestRunner::setStatisticsPrevalentResourceForDebugMode): Ditto.
(WTR::TestRunner::setStatisticsLastSeen): Ditto.
(WTR::TestRunner::setStatisticsMergeStatistic): Ditto.
(WTR::TestRunner::setStatisticsExpiredStatistic): Ditto.
(WTR::TestRunner::setStatisticsPrevalentResource): Ditto.
(WTR::TestRunner::setStatisticsVeryPrevalentResource): Ditto.
(WTR::TestRunner::dumpResourceLoadStatistics): Use postSynchronousPageMessage.
(WTR::TestRunner::isStatisticsPrevalentResource): Use postSynchronousPageMessageReturningBoolean.
(WTR::TestRunner::isStatisticsVeryPrevalentResource): Ditto.
(WTR::TestRunner::isStatisticsRegisteredAsSubresourceUnder): Ditto.
(WTR::TestRunner::isStatisticsRegisteredAsSubFrameUnder): Ditto.
(WTR::TestRunner::isStatisticsRegisteredAsRedirectingTo): Ditto.
(WTR::TestRunner::setStatisticsHasHadUserInteraction): Use postMessage.
(WTR::TestRunner::isStatisticsHasHadUserInteraction): Use postSynchronousPageMessageReturningBoolean.
(WTR::TestRunner::isStatisticsOnlyInDatabaseOnce): Ditto.
(WTR::TestRunner::setStatisticsGrandfathered): Use postSynchronousMessage.
(WTR::TestRunner::setUseITPDatabase): Ditto.
(WTR::TestRunner::isStatisticsGrandfathered): Use postSynchronousPageMessageReturningBoolean.
(WTR::TestRunner::setStatisticsSubframeUnderTopFrameOrigin): Use postSynchronousMessage.
(WTR::TestRunner::setStatisticsSubresourceUnderTopFrameOrigin): Ditto.
(WTR::TestRunner::setStatisticsSubresourceUniqueRedirectTo): Ditto.
(WTR::TestRunner::setStatisticsSubresourceUniqueRedirectFrom): Ditto.
(WTR::TestRunner::setStatisticsTopFrameUniqueRedirectTo): Ditto.
(WTR::TestRunner::setStatisticsTopFrameUniqueRedirectFrom): Ditto.
(WTR::TestRunner::setStatisticsCrossSiteLoadWithLinkDecoration): Ditto.
(WTR::TestRunner::setStatisticsTimeToLiveUserInteraction): Ditto.
(WTR::TestRunner::statisticsDidRunTelemetryCallback): Use mainFrameJSContext.
(WTR::TestRunner::statisticsProcessStatisticsAndDataRecords): Use postSynchronousMessage.
(WTR::TestRunner::statisticsUpdateCookieBlocking): Use postMessage.
(WTR::TestRunner::statisticsSubmitTelemetry): Use postSynchronousMessage.
(WTR::TestRunner::setStatisticsNotifyPagesWhenDataRecordsWereScanned): Ditto.
(WTR::TestRunner::setStatisticsIsRunningTest): Ditto.
(WTR::TestRunner::setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval): Ditto.
(WTR::TestRunner::setStatisticsMinimumTimeBetweenDataRecordsRemoval): Ditto.
(WTR::TestRunner::setStatisticsGrandfatheringTime): Ditto.
(WTR::TestRunner::setStatisticsMaxStatisticsEntries): Ditto.
(WTR::TestRunner::setStatisticsPruneEntriesDownTo): Ditto.
(WTR::TestRunner::statisticsClearInMemoryAndPersistentStore): Use postMessage.
(WTR::TestRunner::statisticsClearInMemoryAndPersistentStoreModifiedSinceHours): Ditto.
(WTR::TestRunner::statisticsClearThroughWebsiteDataRemoval): Ditto.
(WTR::TestRunner::statisticsDeleteCookiesForHost): Use postSynchronousMessage.
(WTR::TestRunner::isStatisticsHasLocalStorage): Use postSynchronousPageMessageReturningBoolean.
(WTR::TestRunner::setStatisticsCacheMaxAgeCap): Use postSynchronousMessage.
(WTR::TestRunner::hasStatisticsIsolatedSession): Use postSynchronousPageMessageReturningBoolean.
(WTR::TestRunner::setStatisticsShouldDowngradeReferrer): Use postMessage.
(WTR::TestRunner::setStatisticsShouldBlockThirdPartyCookies): Ditto.
(WTR::TestRunner::setStatisticsFirstPartyWebsiteDataRemovalMode): Ditto.
(WTR::TestRunner::statisticsSetToSameSiteStrictCookies): Ditto.
(WTR::TestRunner::statisticsSetFirstPartyHostCNAMEDomain): Ditto.
(WTR::TestRunner::statisticsSetThirdPartyCNAMEDomain): Ditto.
(WTR::TestRunner::statisticsResetToConsistentState): Ditto.
(WTR::TestRunner::getAllStorageAccessEntries): Ditto.
(WTR::makeDomainsValue): Factored out. Use mainFrameJSContext.
(WTR::TestRunner::callDidReceiveAllStorageAccessEntriesCallback): Use makeDomainsValue.
(WTR::TestRunner::loadedSubresourceDomains): Use postMessage.
(WTR::TestRunner::callDidReceiveLoadedSubresourceDomainsCallback): Use makeDomainsValue.
(WTR::TestRunner::addMockMediaDevice): Use postSynchronousMessage.
(WTR::TestRunner::clearMockMediaDevices): Ditto.
(WTR::TestRunner::removeMockMediaDevice): Ditto.
(WTR::TestRunner::resetMockMediaDevices): Ditto.
(WTR::TestRunner::setMockCameraOrientation): Ditto.
(WTR::TestRunner::isMockRealtimeMediaSourceCenterEnabled): Use
postSynchronousMessageReturningBoolean.
(WTR::TestRunner::connectMockGamepad): Use postSynchronousMessage.
(WTR::TestRunner::disconnectMockGamepad): Ditto.
(WTR::TestRunner::setMockGamepadDetails): Ditto.
(WTR::TestRunner::setMockGamepadAxisValue): Ditto.
(WTR::TestRunner::setMockGamepadButtonValue): Ditto.
(WTR::TestRunner::setOpenPanelFiles): Use mainFrameJSContext, arrayLength, createJSString,
and postPageMessage.
(WTR::TestRunner::setOpenPanelFilesMediaIcon): Use mainFrameJSContext and postPageMessage.
(WTR::TestRunner::removeAllSessionCredentials): Use postMessage.
(WTR::TestRunner::clearDOMCache): Use postSynchronousMessage.
(WTR::TestRunner::clearDOMCaches): Ditto.
(WTR::TestRunner::hasDOMCache): Use postSynchronousPageMessageReturningBoolean.
(WTR::TestRunner::domCacheSize): Use postSynchronousPageMessageReturningUInt64.
(WTR::TestRunner::setAllowStorageQuotaIncrease): Use postSynchronousPageMessage.
(WTR::TestRunner::getApplicationManifestThen): Use postMessage.
(WTR::TestRunner::injectUserScript): Use postSynchronousMessage.
(WTR::TestRunner::sendDisplayConfigurationChangedMessageForTesting): Ditto.
(WTR::TestRunner::setServiceWorkerFetchTimeout): Ditto.
(WTR::TestRunner::addTestKeyToKeychain): Ditto.
(WTR::TestRunner::cleanUpKeychain): Ditto.
(WTR::TestRunner::keyExistsInKeychain): Use postSynchronousPageMessageReturningBoolean.
(WTR::TestRunner::serverTrustEvaluationCallbackCallsCount): Use
postSynchronousMessageReturningUInt64.
(WTR::TestRunner::setShouldDismissJavaScriptAlertsAsynchronously): Use
postSynchronousMessage.
(WTR::TestRunner::abortModal): Ditto.
(WTR::TestRunner::dumpAdClickAttribution): Use postSynchronousPageMessage.
(WTR::TestRunner::clearAdClickAttribution): Ditto.
(WTR::TestRunner::clearAdClickAttributionsThroughWebsiteDataRemoval): Ditto.
(WTR::TestRunner::setAdClickAttributionOverrideTimerForTesting): Ditto.
(WTR::TestRunner::setAdClickAttributionConversionURLForTesting): Ditto.
(WTR::TestRunner::markAdClickAttributionsAsExpiredForTesting): Ditto.
(WTR::TestRunner::setOffscreenCanvasEnabled): Use overridePreference.
(WTR::TestRunner::hasAppBoundSession): Use postSynchronousPageMessageReturningBoolean.
(WTR::TestRunner::clearAppBoundSession): Use postSynchronousMessage.
(WTR::TestRunner::setAppBoundDomains): Use mainFrameJSContext, arrayLength, createJSString,
and toWK.
(WTR::TestRunner::postMessage): Added.

  • WebKitTestRunner/InjectedBundle/TestRunner.h: Updated for the above. Also changed

overridePreference ot a static member function.

  • WebKitTestRunner/InjectedBundle/TextInputController.cpp:

(WTR::TextInputController::TextInputController): Deleted.
(WTR::TextInputController::~TextInputController): Deleted.
(WTR::TextInputController::makeWindowObject): Use setGlobalObjectProperty.
(WTR::arrayLength): Deleted. Use the one from JSBasics.h now.
(WTR::createCompositionHighlightData): Use setValue.

  • WebKitTestRunner/InjectedBundle/TextInputController.h: Updated for the above.
  • WebKitTestRunner/InjectedBundle/ios/AccessibilityControllerIOS.mm:

(WTR::AccessibilityController::platformName): Use createJSString.

  • WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm:

(WTR::createEmptyJSString): Deleted. Use createJSString from JSBasics.h now.
(WTR::AccessibilityUIElement::attributesOfLinkedUIElements): Use createJSString.
(WTR::AccessibilityUIElement::attributesOfDocumentLinks): Ditto.
(WTR::AccessibilityUIElement::attributesOfChildren): Ditto.
(WTR::AccessibilityUIElement::allAttributes): Ditto.
(WTR::AccessibilityUIElement::stringDescriptionOfAttributeValue): Ditto.
(WTR::AccessibilityUIElement::stringAttributeValue): Ditto.
(WTR::AccessibilityUIElement::parameterizedAttributeNames): Ditto.
(WTR::AccessibilityUIElement::role): Ditto.
(WTR::AccessibilityUIElement::subrole): Ditto.
(WTR::AccessibilityUIElement::computedRoleString): Ditto.
(WTR::AccessibilityUIElement::title): Ditto.
(WTR::AccessibilityUIElement::orientation const): Ditto.
(WTR::AccessibilityUIElement::language): Ditto.
(WTR::AccessibilityUIElement::valueDescription): Ditto.
(WTR::AccessibilityUIElement::isFocused const): Ditto.
(WTR::AccessibilityUIElement::isSelectedOptionActive const): Ditto.
(WTR::AccessibilityUIElement::isIndeterminate const): Ditto.
(WTR::AccessibilityUIElement::ariaDropEffects const): Ditto.
(WTR::AccessibilityUIElement::boundsForRange): Ditto.
(WTR::AccessibilityUIElement::attributesOfColumnHeaders): Ditto.
(WTR::AccessibilityUIElement::attributesOfRowHeaders): Ditto.
(WTR::AccessibilityUIElement::attributesOfColumns): Ditto.
(WTR::AccessibilityUIElement::attributesOfRows): Ditto.
(WTR::AccessibilityUIElement::attributesOfVisibleCells): Ditto.
(WTR::AccessibilityUIElement::attributesOfHeader): Ditto.
(WTR::AccessibilityUIElement::clearSelectedChildren const): Ditto.
(WTR::AccessibilityUIElement::accessibilityValue const): Ditto.
(WTR::AccessibilityUIElement::documentEncoding): Ditto.
(WTR::AccessibilityUIElement::documentURI): Ditto.
(WTR::AccessibilityUIElement::isSelectable const): Ditto.
(WTR::AccessibilityUIElement::isMultiSelectable const): Ditto.
(WTR::AccessibilityUIElement::isVisible const): Ditto.
(WTR::AccessibilityUIElement::isOffScreen const): Ditto.
(WTR::AccessibilityUIElement::isCollapsed const): Ditto.
(WTR::AccessibilityUIElement::isSingleLine const): Ditto.
(WTR::AccessibilityUIElement::isMultiLine const): Ditto.
(WTR::AccessibilityUIElement::takeFocus): Ditto.
(WTR::AccessibilityUIElement::takeSelection): Ditto.
(WTR::AccessibilityUIElement::addSelection): Ditto.
(WTR::AccessibilityUIElement::removeSelection): Ditto.
(WTR::AccessibilityUIElement::stringForTextMarkerRange): Ditto.

  • WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm:

(WTR::EventSenderProxy::EventSenderProxy): Initialize in the class definition.
(WTR::EventSenderProxy::~EventSenderProxy): Deleted.

  • WebKitTestRunner/InjectedBundle/mac/AccessibilityCommonMac.mm:

(WTR::makeJSArray): Return a JSObjectRef. Renamed from makeArrayRefForArray.
(WTR::makeJSObject): Return a JSObjectRef. Renamed from makeObjectRefForDictionary.
(WTR::makeValueRefForValue): Updated for the above.
(WTR::searchPredicateParameterizedAttributeForSearchCriteria): Use toWTFString
and arrayLength.

  • WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm:

(WTR::AccessibilityController::platformName): Use createJSString.

  • WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:

(WTR::createEmptyJSString): Deleted. Use createJSString from JSBasics.h instead.
(WTR::convertVectorToObjectArray): Deleted.
(WTR::makeJSArray): Renamed from convertVectorToObjectArray.
(WTR::selectTextParameterizedAttributeForCriteria): Use toWTFString and arrayLength.
(WTR::searchTextParameterizedAttributeForCriteria): Ditto.
(WTR::AccessibilityUIElement::rowHeaders const): Use makeJSArray.
(WTR::AccessibilityUIElement::columnHeaders const): Ditto.
(WTR::AccessibilityUIElement::uiElementArrayAttributeValue const): Ditto.
(WTR::AccessibilityUIElement::searchTextWithCriteria): Ditto.
(WTR::AccessibilityUIElement::accessibilityValue const): Use createJSString.
(WTR::AccessibilityUIElement::documentEncoding): Ditto.
(WTR::AccessibilityUIElement::documentURI): Ditto.

  • WebKitTestRunner/InjectedBundle/mac/TestRunnerMac.mm:

(WTR::TestRunner::inspectorTestStubURL): Remove locals.

  • WebKitTestRunner/StringFunctions.h: Added toWKString overload that converts from

a JSValueRef, JSStringRef, or JSRetainPtr<JSStringRef> and toWK overload that converts
from a const char*.

  • WebKitTestRunner/TestController.cpp:

(WTR::TestController::initialize): Use toWK.
(WTR::TestController::generateContextConfiguration const): Ditto.
(WTR::TestController::resetPreferencesToConsistentValues): Ditto.
(WTR::TestController::resetStateToConsistentValues): Use setValue.
(WTR::TestController::updateLiveDocumentsAfterTest): Ditto.
(WTR::TestController::checkForWorldLeaks): Use toWK.
(WTR::contentExtensionJSONPath): Use toSTD.
(WTR::TestController::configureContentExtensionForTest): Use toWK.
(WTR::TestController::didReceiveKeyDownMessageFromInjectedBundle): Use stringValue
and uint64Value.
(WTR::TestController::didReceiveLiveDocumentsList): Use dictionaryValue and
uint64Value.
(WTR::TestController::didReceiveMessageFromInjectedBundle): Use dictionaryValue,
stringValue, uint64Value, doubleValue, booleanValue.
(WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle): Ditto.
(WTR::TestController::setBlockAllPlugins): Use toWK.
(WTR::TestController::setPluginSupportedMode): Ditto.
(WTR::TestController::canAuthenticateAgainstProtectionSpace): Use auto.
(WTR::TestController::didFinishNavigation): Removed local.
(WTR::TestController::didReceiveAuthenticationChallenge): Use auto and toWTFString
instead of toSTD.
(WTR::TestController::setMockGeolocationPosition): Use Optional instead of pairs
of bool and double.
(WTR::TestController::handleCheckOfUserMediaPermissionForOrigin): Use toWK.
(WTR::TestController::decidePolicyForUserMediaPermissionRequestIfPossible): Ditto.
(WTR::TestController::updateBundleIdentifierInNetworkProcess): Use toWK.

  • WebKitTestRunner/TestController.h: Updated for the above.
  • WebKitTestRunner/TestInvocation.cpp:

(WTR::postPageMessage): Added.
(WTR::TestInvocation::TestIncovation): Use toWTFString.
(WTR::TestInvocation::createTestSettingsDictionary): Use auto and setValue.
(WTR::TestInvocation::invoke): Use postPageMessage and setValue.
(WTR::TestInvocation::didReceiveMessageFromInjectedBundle): Use postPageMessage
and stringValue.
(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle): Use
dictionaryValue, booleanValue, value, stringValue, doubleValue, and
optionalDoubleValue.
(WTR::TestInvocation::uiScriptDidComplete): Use postPageMessage and setValue.
(WTR::TestInvocation::didBeginSwipe): Use postPageMessage.
(WTR::TestInvocation::willEndSwipe): Ditto.
(WTR::TestInvocation::didEndSwipe): Ditto.
(WTR::TestInvocation::didRemoveSwipeSnapshot): Ditto.
(WTR::TestInvocation::notifyDownloadDone): Ditto.
(WTR::TestInvocation::didClearStatisticsInMemoryAndPersistentStore): Ditto.
(WTR::TestInvocation::didClearStatisticsThroughWebsiteDataRemoval): Ditto.
(WTR::TestInvocation::didSetShouldDowngradeReferrer): Ditto.
(WTR::TestInvocation::didSetShouldBlockThirdPartyCookies): Ditto.
(WTR::TestInvocation::didSetFirstPartyWebsiteDataRemovalMode): Ditto.
(WTR::TestInvocation::didSetToSameSiteStrictCookies): Ditto.
(WTR::TestInvocation::didSetFirstPartyHostCNAMEDomain): Ditto.
(WTR::TestInvocation::didSetThirdPartyCNAMEDomain): Ditto.
(WTR::TestInvocation::didResetStatisticsToConsistentState): Ditto.
(WTR::TestInvocation::didSetBlockCookiesForHost): Ditto.
(WTR::TestInvocation::didSetStatisticsDebugMode): Ditto.
(WTR::TestInvocation::didSetPrevalentResourceForDebugMode): Ditto.
(WTR::TestInvocation::didSetLastSeen): Ditto.
(WTR::TestInvocation::didMergeStatistic): Ditto.
(WTR::TestInvocation::didSetExpiredStatistic): Ditto.
(WTR::TestInvocation::didSetPrevalentResource): Ditto.
(WTR::TestInvocation::didSetVeryPrevalentResource): Ditto.
(WTR::TestInvocation::didSetHasHadUserInteraction): Ditto.
(WTR::TestInvocation::didReceiveAllStorageAccessEntries): Ditto.
(WTR::TestInvocation::didReceiveLoadedSubresourceDomains): Ditto.
(WTR::TestInvocation::didRemoveAllSessionCredentials): Ditto.
(WTR::TestInvocation::didSetAppBoundDomains): Ditto.
(WTR::TestInvocation::performCustomMenuAction): Ditto.

  • WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:

Added JSBasics.h to DictionaryFunctions.h to appropriate targets.

  • WebKitTestRunner/WorkQueueManager.cpp:

(WTR::ScriptItem::ScriptItem): Use toWK.
(WTR::WorkQueueManager::queueLoadHTMLString): Ditto.

  • WebKitTestRunner/cocoa/UIScriptControllerCocoa.h: Make most functions private.
  • WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm:

(WTR::UIScriptControllerCocoa::overridePreference): Use toWTFString.

  • WebKitTestRunner/ios/UIScriptControllerIOS.h: Marked the class final and made

most functions private.

  • WebKitTestRunner/ios/UIScriptControllerIOS.mm:

(WTR::arrayLength): Deleted. Use the one in JSBasics.h.
(WTR::parseModifierArray): Use the new toWTFString overload.
(WTR::UIScriptControllerIOS::typeCharacterUsingHardwareKeyboard): Ditto.

  • WebKitTestRunner/mac/EventSenderProxy.mm:

(WTR::EventSenderProxy::EventSenderProxy): Initialize in the class definition.
(WTR::EventSenderProxy::keyDown): Use toWTFString.

  • WebKitTestRunner/mac/UIScriptControllerMac.h: Marked the class final and made

most functions private.

Location:
trunk
Files:
1 added
79 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/Source/JavaScriptCore/API/JSRetainPtr.h

    r236032 r267761  
    11/*
    2  * Copyright (C) 2005-2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2005-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3030
    3131#include <JavaScriptCore/JSContextRef.h>
     32#include <JavaScriptCore/JSObjectRef.h>
    3233#include <JavaScriptCore/JSStringRef.h>
    3334#include <algorithm>
    3435
     36inline void JSRetain(JSClassRef context) { JSClassRetain(context); }
     37inline void JSRelease(JSClassRef context) { JSClassRelease(context); }
     38inline void JSRetain(JSGlobalContextRef context) { JSGlobalContextRetain(context); }
     39inline void JSRelease(JSGlobalContextRef context) { JSGlobalContextRelease(context); }
    3540inline void JSRetain(JSStringRef string) { JSStringRetain(string); }
    3641inline void JSRelease(JSStringRef string) { JSStringRelease(string); }
    37 inline void JSRetain(JSGlobalContextRef context) { JSGlobalContextRetain(context); }
    38 inline void JSRelease(JSGlobalContextRef context) { JSGlobalContextRelease(context); }
    3942
    4043enum AdoptTag { Adopt };
     
    7578};
    7679
     80JSRetainPtr<JSClassRef> adopt(JSClassRef);
    7781JSRetainPtr<JSStringRef> adopt(JSStringRef);
    7882JSRetainPtr<JSGlobalContextRef> adopt(JSGlobalContextRef);
     
    8185    : m_ptr(ptr)
    8286{
     87}
     88
     89inline JSRetainPtr<JSClassRef> adopt(JSClassRef o)
     90{
     91    return JSRetainPtr<JSClassRef>(Adopt, o);
    8392}
    8493
  • TabularUnified trunk/Source/JavaScriptCore/ChangeLog

    r267754 r267761  
     12020-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
    1102020-09-29  Yusuke Suzuki  <ysuzuki@apple.com>
    211
  • TabularUnified trunk/Tools/ChangeLog

    r267757 r267761  
     12020-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
     7512020-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
    17582020-09-29  Jonathan Bedard  <jbedard@apple.com>
    2759
  • TabularUnified trunk/Tools/DumpRenderTree/AccessibilityController.cpp

    r236032 r267761  
    11/*
    2  * Copyright (C) 2008, 2009, 2010 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2008-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3131
    3232#include "AccessibilityUIElement.h"
     33#include "JSBasics.h"
    3334
    3435// Static Value Getters
     
    4849// Object Creation
    4950
    50 void AccessibilityController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
     51void AccessibilityController::makeWindowObject(JSContextRef context)
    5152{
    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));
    5954}
    6055
     
    153148}
    154149
    155 JSClassRef AccessibilityController::getJSClass()
     150JSRetainPtr<JSClassRef> AccessibilityController::createJSClass()
    156151{
    157     static JSStaticFunction staticFunctions[] = {
     152    static constexpr JSStaticFunction functions[] = {
    158153        { "logFocusEvents", logFocusEventsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
    159154        { "logValueChangeEvents", logValueChangeEventsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
     
    167162        { 0, 0, 0 }
    168163    };
    169 
    170     static JSStaticValue staticValues[] = {
     164    static constexpr JSStaticValue values[] = {
    171165        { "focusedElement", getFocusedElementCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
    172166        { "rootElement", getRootElementCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
     
    175169        { 0, 0, 0, 0 }
    176170    };
    177 
    178     static JSClassDefinition classDefinition = {
    179         0, kJSClassAttributeNone, "AccessibilityController", 0, staticValues, staticFunctions,
     171    static const JSClassDefinition definition = {
     172        0, kJSClassAttributeNone, "AccessibilityController", 0, values, functions,
    180173        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    181174    };
    182 
    183     return JSClassCreate(&classDefinition);
     175    return adopt(JSClassCreate(&definition));
    184176}
    185177
  • TabularUnified trunk/Tools/DumpRenderTree/AccessibilityController.h

    r259843 r267761  
    11/*
    2  * Copyright (C) 2008, 2009, 2010 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2008-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4848    ~AccessibilityController();
    4949
    50     void makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception);
     50    void makeWindowObject(JSContextRef);
    5151
    5252    // Controller Methods - platform-independent implementations
     
    8484
    8585private:
    86     static JSClassRef getJSClass();
     86    static JSRetainPtr<JSClassRef> createJSClass();
    8787
    8888#if PLATFORM(WIN)
  • TabularUnified trunk/Tools/DumpRenderTree/AccessibilityUIElement.cpp

    r264000 r267761  
    207207    bool isDirectionNext = true;
    208208    JSValueRef searchKey = nullptr;
    209     JSRetainPtr<JSStringRef> searchText = nullptr;
     209    JSRetainPtr<JSStringRef> searchText;
    210210    bool visibleOnly = false;
    211211    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.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    432432    my ($self, $type, $argumentName) = @_;
    433433
    434     return "JSValueToNullableBoolean(context, $argumentName)" if $type->name eq "boolean" && $type->isNullable;
     434    return "toOptionalBool(context, $argumentName)" if $type->name eq "boolean" && $type->isNullable;
    435435    return "JSValueToBoolean(context, $argumentName)" if $type->name eq "boolean";
    436436    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);
    438438    return "JSValueToNumber(context, $argumentName, nullptr)" if $$self{codeGenerator}->IsPrimitiveType($type);
    439439    return "to" . _implementationClassName($type) . "(context, $argumentName)";
     
    473473
    474474    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;
    476476    return "JSValueMakeBoolean(context, ${expression})" if $returnType->name eq "boolean";
    477477    return "${expression}" if $returnType->name eq "object";
    478478    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);
    480480    return "toJS(context, WTF::getPtr(${expression}))";
    481481}
  • TabularUnified trunk/Tools/DumpRenderTree/GCController.cpp

    r236032 r267761  
    11/*
    2  * Copyright (C) 2007 Apple Inc. All rights reserved.
     2 * Copyright (C) 2007-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3030#include "GCController.h"
    3131
    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"
    4233
    4334// Static Functions
     
    4536static JSValueRef collectCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
    4637{
    47     GCController* controller = static_cast<GCController*>(JSObjectGetPrivate(thisObject));
    48     controller->collect();
     38    auto& controller = *static_cast<GCController*>(JSObjectGetPrivate(thisObject));
     39    controller.collect();
    4940    return JSValueMakeUndefined(context);
    5041}
     
    5243static JSValueRef collectOnAlternateThreadCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
    5344{
    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);
    6148    return JSValueMakeUndefined(context);
    6249}
     
    6451static JSValueRef getJSObjectCountCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
    6552{
    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());
    7055}
    7156
    7257// Object Creation
    7358
    74 void GCController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
     59void GCController::makeWindowObject(JSContextRef context)
    7560{
    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));
    8362}
    8463
    85 JSClassRef GCController::getJSClass()
     64JSRetainPtr<JSClassRef> GCController::createJSClass()
    8665{
    87     static JSStaticFunction staticFunctions[] = {
     66    static constexpr JSStaticFunction functions[] = {
    8867        { "collect", collectCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
    8968        { "collectOnAlternateThread", collectOnAlternateThreadCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
     
    9170        { 0, 0, 0 }
    9271    };
    93 
    94     static JSClassDefinition classDefinition = {
    95         0, kJSClassAttributeNone, "GCController", 0, 0, staticFunctions,
     72    static const JSClassDefinition definition = {
     73        0, kJSClassAttributeNone, "GCController", 0, 0, functions,
    9674        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    9775    };
    98 
    99     return JSClassCreate(&classDefinition);
     76    return adopt(JSClassCreate(&definition));
    10077}
  • TabularUnified trunk/Tools/DumpRenderTree/GCController.h

    r248762 r267761  
    2727 */
    2828
    29 #ifndef GCController_h
    30 #define GCController_h
     29#pragma once
    3130
    32 #include <JavaScriptCore/JSObjectRef.h>
     31#include <JavaScriptCore/JSRetainPtr.h>
    3332#include <wtf/FastMalloc.h>
    3433
     
    3635    WTF_MAKE_FAST_ALLOCATED;
    3736public:
    38     GCController();
    39     ~GCController();
    40 
    41     void makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception);
     37    void makeWindowObject(JSContextRef);
    4238
    4339    // Controller Methods - platfrom independant implementations
     
    4743
    4844private:
    49     static JSClassRef getJSClass();
     45    static JSRetainPtr<JSClassRef> createJSClass();
    5046};
    51 
    52 #endif // GCController_h
  • TabularUnified trunk/Tools/DumpRenderTree/TestRunner.cpp

    r267030 r267761  
    3131#include "TestRunner.h"
    3232
     33#include "JSBasics.h"
    3334#include "WebCoreTestSupport.h"
    3435#include "WorkQueue.h"
     
    3940#include <JavaScriptCore/JSArrayBufferView.h>
    4041#include <JavaScriptCore/JSCTestRunnerUtils.h>
    41 #include <JavaScriptCore/JSContextRef.h>
    4242#include <JavaScriptCore/JSGlobalObjectInlines.h>
    43 #include <JavaScriptCore/JSObjectRef.h>
    44 #include <JavaScriptCore/JSRetainPtr.h>
    4543#include <JavaScriptCore/TypedArrayInlines.h>
    4644#include <JavaScriptCore/VMInlines.h>
     
    490488static JSValueRef displayAndTrackRepaintsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
    491489{
    492     // Has mac & windows implementation
    493490    TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
    494491    controller->displayAndTrackRepaints();
     
    499496static JSValueRef encodeHostNameCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
    500497{
    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]);
    507502
    508503    TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
     
    513508static JSValueRef execCommandCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
    514509{
    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]);
    522514    // 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);
    531516
    532517    TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
     
    542527        return JSValueMakeUndefined(context);
    543528
    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);
    549531
    550532    TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
     
    567549        return JSValueMakeUndefined(context);
    568550
    569     auto name = adopt(JSValueToStringCopy(context, arguments[0], exception));
    570     ASSERT(!*exception);
     551    auto name = WTR::createJSString(context, arguments[0]);
    571552
    572553    TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
     
    580561        return JSValueMakeUndefined(context);
    581562
    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]);
    586565
    587566    // Should use `<!-- webkit-test-runner [ enableBackForwardCache=true ] -->` instead.
     
    663642        return JSValueMakeUndefined(context);
    664643
    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);
    674648
    675649    TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
     
    693667        ASSERT(!*exception);
    694668    } else
    695         baseURL = adopt(JSStringCreateWithUTF8CString(""));
     669        baseURL = WTR::createJSString();
    696670
    697671    TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
     
    20462020static void testRunnerObjectFinalize(JSObjectRef object)
    20472021{
    2048     TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(object));
    2049     controller->deref();
     2022    static_cast<TestRunner*>(JSObjectGetPrivate(object))->deref();
    20502023}
    20512024
    20522025// Object Creation
    20532026
    2054 void TestRunner::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
    2055 {
    2056     auto testRunnerStr = adopt(JSStringCreateWithUTF8CString("testRunner"));
     2027void TestRunner::makeWindowObject(JSContextRef context)
     2028{
    20572029    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
     2033JSRetainPtr<JSClassRef> TestRunner::createJSClass()
     2034{
     2035    static const JSClassDefinition definition = {
     2036        0, kJSClassAttributeNone, "TestRunner", 0, staticValues(), staticFunctions(),
    20722037        0, testRunnerObjectFinalize, 0, 0, 0, 0, 0, 0, 0, 0, 0
    20732038    };
    2074 
    2075     return JSClassCreate(&classDefinition);
     2039    return adopt(JSClassCreate(&definition));
    20762040}
    20772041
     
    21082072}
    21092073
    2110 JSStaticValue* TestRunner::staticValues()
    2111 {
    2112     static JSStaticValue staticValues[] = {
     2074const JSStaticValue* TestRunner::staticValues()
     2075{
     2076    static constexpr JSStaticValue values[] = {
    21132077        { "didCancelClientRedirect", getDidCancelClientRedirect, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
    21142078        { "timeout", getTimeoutCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
     
    21282092        { 0, 0, 0, 0 }
    21292093    };
    2130     return staticValues;
    2131 }
    2132 
    2133 JSStaticFunction* TestRunner::staticFunctions()
    2134 {
    2135     static JSStaticFunction staticFunctions[] = {
     2094    return values;
     2095}
     2096
     2097const JSStaticFunction* TestRunner::staticFunctions()
     2098{
     2099    static constexpr JSStaticFunction functions[] = {
    21362100        { "abortModal", abortModalCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
    21372101        { "addDisallowedURL", addDisallowedURLCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
     
    22982262    };
    22992263
    2300     return staticFunctions;
     2264    return functions;
    23012265}
    23022266
     
    23432307void TestRunner::waitToDumpWatchdogTimerFired()
    23442308{
    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());
    23532314
    23542315    notifyDone();
     
    24042365}
    24052366
    2406 typedef WTF::HashMap<unsigned, JSValueRef> CallbackMap;
     2367using CallbackMap = WTF::HashMap<unsigned, JSObjectRef>;
    24072368static CallbackMap& callbackMap()
    24082369{
     
    24112372}
    24122373
    2413 void TestRunner::cacheTestRunnerCallback(unsigned index, JSValueRef callback)
    2414 {
    2415     if (!callback)
     2374void TestRunner::cacheTestRunnerCallback(unsigned index, JSValueRef callbackValue)
     2375{
     2376    auto context = mainFrameJSContext();
     2377    if (!callbackValue || !JSValueIsObject(context, callbackValue))
    24162378        return;
     2379    auto callback = (JSObjectRef)callbackValue;
    24172380
    24182381    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);
    24202383        return;
    24212384    }
    24222385
    2423     JSContextRef context = mainFrameJSContext();
    24242386    JSValueProtect(context, callback);
    24252387    callbackMap().add(index, callback);
     
    24312393        return;
    24322394
    2433     JSContextRef context = 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);
    24362398        JSValueUnprotect(context, callback);
    24372399    }
     
    24402402void TestRunner::clearTestRunnerCallbacks()
    24412403{
    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);
    24492407    callbackMap().clear();
    24502408}
     
    25092467    if (!JSValueIsArray(context, filesValue))
    25102468        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);
    25172471
    25182472    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) {
    25212474        JSValueRef fileValue = JSObjectGetPropertyAtIndex(context, files, i, nullptr);
    25222475        if (!JSValueIsString(context, fileValue))
  • TabularUnified trunk/Tools/DumpRenderTree/TestRunner.h

    r267098 r267761  
    5555    void cleanup();
    5656
    57     void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
     57    void makeWindowObject(JSContextRef);
    5858
    5959    void addDisallowedURL(JSStringRef url);
     
    498498#endif
    499499
    500     static JSClassRef getJSClass();
    501     static JSStaticValue* staticValues();
    502     static JSStaticFunction* staticFunctions();
     500    static JSRetainPtr<JSClassRef> createJSClass();
     501    static const JSStaticValue* staticValues();
     502    static const JSStaticFunction* staticFunctions();
    503503};
  • TabularUnified trunk/Tools/DumpRenderTree/ios/AccessibilityControllerIOS.mm

    r236032 r267761  
    2525
    2626#import "config.h"
    27 #import "DumpRenderTree.h"
    2827#import "AccessibilityController.h"
    2928
     
    3130#import "AccessibilityNotificationHandler.h"
    3231#import "AccessibilityUIElement.h"
     32#import "DumpRenderTree.h"
     33#import "JSBasics.h"
    3334#import <Foundation/Foundation.h>
    3435#import <WebKit/WebFramePrivate.h>
     
    156157JSRetainPtr<JSStringRef> AccessibilityController::platformName() const
    157158{
    158     return adopt(JSStringCreateWithUTF8CString("ios"));
     159    return WTR::createJSString("ios");
    159160}
  • TabularUnified trunk/Tools/DumpRenderTree/ios/AccessibilityUIElementIOS.mm

    r264000 r267761  
    2525
    2626#import "config.h"
    27 #import "DumpRenderTree.h"
    2827#import "AccessibilityUIElement.h"
    2928
    3029#import "AccessibilityCommonMac.h"
    3130#import "AccessibilityNotificationHandler.h"
     31#import "DumpRenderTree.h"
     32#import "JSBasics.h"
    3233#import <Foundation/Foundation.h>
    3334#import <JavaScriptCore/JSStringRefCF.h>
     
    4142
    4243typedef void (*AXPostedNotificationCallback)(id element, NSString* notification, void* context);
    43 
    44 AccessibilityUIElement::AccessibilityUIElement(id element)
    45     : m_element(element)
    46 {
    47 }
    4844
    4945@interface NSObject (UIAccessibilityHidden)
     
    113109@end
    114110
    115 static JSRetainPtr<JSStringRef> createEmptyJSString()
    116 {
    117     return adopt(JSStringCreateWithCharacters(nullptr, 0));
     111AccessibilityUIElement::AccessibilityUIElement(id element)
     112    : m_element(element)
     113{
    118114}
    119115
     
    180176    return nullptr;
    181177}
    182 
    183178
    184179JSRetainPtr<JSStringRef> AccessibilityUIElement::url()
     
    292287AccessibilityUIElement AccessibilityUIElement::linkedUIElementAtIndex(unsigned index)
    293288{
    294     // FIXME: implement
    295289    return 0;
    296290}
     
    559553    id textMarkers = markerRange->platformTextMarkerRange();
    560554    if (!textMarkers || ![textMarkers isKindOfClass:[NSArray class]])
    561         return createEmptyJSString();
     555        return WTR::createJSString();
    562556    return [[m_element stringForTextMarkers:textMarkers] createJSStringRef];
    563557}
     
    682676JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfLinkedUIElements()
    683677{
    684     return createEmptyJSString();
     678    return WTR::createJSString();
    685679}
    686680
    687681JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfDocumentLinks()
    688682{
    689     return createEmptyJSString();
     683    return WTR::createJSString();
    690684}
    691685
    692686JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfChildren()
    693687{
    694     return createEmptyJSString();
     688    return WTR::createJSString();
    695689}
    696690
    697691JSRetainPtr<JSStringRef> AccessibilityUIElement::allAttributes()
    698692{
    699     return createEmptyJSString();
     693    return WTR::createJSString();
    700694}
    701695
     
    717711        return [[m_element accessibilityTextualContext] createJSStringRef];
    718712   
    719     return createEmptyJSString();
     713    return WTR::createJSString();
    720714}
    721715
     
    756750JSRetainPtr<JSStringRef> AccessibilityUIElement::parameterizedAttributeNames()
    757751{
    758     return createEmptyJSString();
     752    return WTR::createJSString();
    759753}
    760754
    761755JSRetainPtr<JSStringRef> AccessibilityUIElement::role()
    762756{
    763     return createEmptyJSString();
     757    return WTR::createJSString();
    764758}
    765759
    766760JSRetainPtr<JSStringRef> AccessibilityUIElement::subrole()
    767761{
    768     return createEmptyJSString();
     762    return WTR::createJSString();
    769763}
    770764
     
    790784JSRetainPtr<JSStringRef> AccessibilityUIElement::roleDescription()
    791785{
    792     return createEmptyJSString();
     786    return WTR::createJSString();
    793787}
    794788
    795789JSRetainPtr<JSStringRef> AccessibilityUIElement::computedRoleString()
    796790{
    797     return createEmptyJSString();
     791    return WTR::createJSString();
    798792}
    799793
    800794JSRetainPtr<JSStringRef> AccessibilityUIElement::title()
    801795{
    802     return createEmptyJSString();
     796    return WTR::createJSString();
    803797}
    804798
     
    810804JSRetainPtr<JSStringRef> AccessibilityUIElement::orientation() const
    811805{
    812     return createEmptyJSString();
     806    return WTR::createJSString();
    813807}
    814808
     
    820814JSRetainPtr<JSStringRef> AccessibilityUIElement::language()
    821815{
    822     return createEmptyJSString();
     816    return WTR::createJSString();
    823817}
    824818
     
    850844JSRetainPtr<JSStringRef> AccessibilityUIElement::valueDescription()
    851845{
    852     return createEmptyJSString();
     846    return WTR::createJSString();
    853847}
    854848
     
    870864bool AccessibilityUIElement::isFocused() const
    871865{
    872     // FIXME: implement
    873866    return false;
    874867}
     
    893886bool AccessibilityUIElement::isIndeterminate() const
    894887{
    895     // FIXME: implement
    896888    return false;
    897889}
     
    909901JSRetainPtr<JSStringRef> AccessibilityUIElement::ariaDropEffects() const
    910902{
    911     return createEmptyJSString();
     903    return WTR::createJSString();
    912904}
    913905
     
    919911JSRetainPtr<JSStringRef> AccessibilityUIElement::boundsForRange(unsigned location, unsigned length)
    920912{
    921     return createEmptyJSString();
     913    return WTR::createJSString();
    922914}
    923915
    924916JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfColumnHeaders()
    925917{
    926     return createEmptyJSString();
     918    return WTR::createJSString();
    927919}
    928920
    929921JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfRowHeaders()
    930922{
    931     return createEmptyJSString();
     923    return WTR::createJSString();
    932924}
    933925
    934926JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfColumns()
    935927{
    936     return createEmptyJSString();
     928    return WTR::createJSString();
    937929}
    938930
    939931JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfRows()
    940932{
    941     return createEmptyJSString();
     933    return WTR::createJSString();
    942934}
    943935
    944936JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfVisibleCells()
    945937{
    946     return createEmptyJSString();
     938    return WTR::createJSString();
    947939}
    948940
    949941JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfHeader()
    950942{
    951     return createEmptyJSString();
     943    return WTR::createJSString();
    952944}
    953945
     
    988980void AccessibilityUIElement::scrollToMakeVisible()
    989981{
    990     // FIXME: implement
    991982}
    992983
    993984void AccessibilityUIElement::scrollToMakeVisibleWithSubFocus(int x, int y, int width, int height)
    994985{
    995     // FIXME: implement
    996986}
    997987
    998988void AccessibilityUIElement::scrollToGlobalPoint(int x, int y)
    999989{
    1000     // FIXME: implement
    1001990}
    1002991
    1003992JSRetainPtr<JSStringRef> AccessibilityUIElement::selectedTextRange()
    1004993{
    1005     return createEmptyJSString();
     994    return WTR::createJSString();
    1006995}
    1007996
     
    10361025JSRetainPtr<JSStringRef> AccessibilityUIElement::accessibilityValue() const
    10371026{
    1038     // FIXME: implement
    1039     return createEmptyJSString();
     1027    return WTR::createJSString();
    10401028}
    10411029
    10421030void AccessibilityUIElement::clearSelectedChildren() const
    10431031{
    1044     // FIXME: implement
    10451032}
    10461033
    10471034JSRetainPtr<JSStringRef> AccessibilityUIElement::documentEncoding()
    10481035{
    1049     return createEmptyJSString();
     1036    return WTR::createJSString();
    10501037}
    10511038
    10521039JSRetainPtr<JSStringRef> AccessibilityUIElement::documentURI()
    10531040{
    1054     return createEmptyJSString();
     1041    return WTR::createJSString();
    10551042}
    10561043
     
    10841071bool AccessibilityUIElement::isFocusable() const
    10851072{
    1086     // FIXME: implement
    10871073    return false;
    10881074}
     
    10901076bool AccessibilityUIElement::isSelectable() const
    10911077{
    1092     // FIXME: implement
    10931078    return false;
    10941079}
     
    10961081bool AccessibilityUIElement::isMultiSelectable() const
    10971082{
    1098     // FIXME: implement
    10991083    return false;
    11001084}
     
    11021086bool AccessibilityUIElement::isSelectedOptionActive() const
    11031087{
    1104     // FIXME: implement
    11051088    return false;
    11061089}
     
    11081091bool AccessibilityUIElement::isVisible() const
    11091092{
    1110     // FIXME: implement
    11111093    return false;
    11121094}
     
    11141096bool AccessibilityUIElement::isOffScreen() const
    11151097{
    1116     // FIXME: implement
    11171098    return false;
    11181099}
     
    11201101bool AccessibilityUIElement::isCollapsed() const
    11211102{
    1122     // FIXME: implement
    11231103    return false;
    11241104}
     
    11311111bool AccessibilityUIElement::isSingleLine() const
    11321112{
    1133     // FIXME: implement
    11341113    return false;
    11351114}
     
    11371116bool AccessibilityUIElement::isMultiLine() const
    11381117{
    1139     // FIXME: implement
    11401118    return false;
    11411119}
     
    11531131void AccessibilityUIElement::takeFocus()
    11541132{
    1155     // FIXME: implement
    11561133}
    11571134
    11581135void AccessibilityUIElement::takeSelection()
    11591136{
    1160     // FIXME: implement
    11611137}
    11621138
    11631139void AccessibilityUIElement::addSelection()
    11641140{
    1165     // FIXME: implement
    11661141}
    11671142
    11681143void AccessibilityUIElement::removeSelection()
    11691144{
    1170     // FIXME: implement
    11711145}
    11721146
    11731147unsigned AccessibilityUIElement::uiElementCountForSearchPredicate(JSContextRef context, AccessibilityUIElement* startElement, bool isDirectionNext, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly, bool immediateDescendantsOnly)
    11741148{
    1175     // FIXME: implement
    11761149    return 0;
    11771150}
     
    12151188JSRetainPtr<JSStringRef> AccessibilityUIElement::classList() const
    12161189{
    1217     // FIXME: implement
    12181190    return nullptr;
    12191191}
     
    12211193void AccessibilityUIElement::uiElementArrayAttributeValue(JSStringRef, Vector<AccessibilityUIElement>&) const
    12221194{
    1223     // FIXME: implement
    12241195}
    12251196
    12261197void AccessibilityUIElement::columnHeaders(Vector<AccessibilityUIElement>&) const
    12271198{
    1228     // FIXME: implement
    12291199}
    12301200
    12311201void AccessibilityUIElement::rowHeaders(Vector<AccessibilityUIElement>&) const
    12321202{
    1233     // FIXME: implement
    12341203}
    12351204
  • TabularUnified trunk/Tools/DumpRenderTree/mac/AccessibilityCommonMac.h

    r260366 r267761  
    4242@end
    4343
    44 extern NSDictionary *searchPredicateParameterizedAttributeForSearchCriteria(JSContextRef, AccessibilityUIElement *startElement, bool isDirectionNext, unsigned resultsLimit, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly, bool immediateDescendantsOnly);
     44NSDictionary *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  
    3232#import "AccessibilityCommonMac.h"
    3333
     34#import "JSBasics.h"
    3435#import <JavaScriptCore/JSStringRefCF.h>
    3536
     
    5758
    5859    [parameterizedAttribute setObject:(isDirectionNext) ? @"AXDirectionNext" : @"AXDirectionPrevious" forKey:@"AXDirection"];
    59 
    6060    [parameterizedAttribute setObject:@(resultsLimit) forKey:@"AXResultsLimit"];
    6161
     
    6767                searchKeyParameter = [NSString stringWithJSStringRef:searchKeyString.get()];
    6868        } 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);
    7771            for (unsigned i = 0; i < searchKeyArrayLength; ++i) {
    7872                JSValueRef searchKeyValue = JSObjectGetPropertyAtIndex(context, searchKeyArray, i, nullptr);
     
    8983            [parameterizedAttribute setObject:searchKeyParameter forKey:@"AXSearchKey"];
    9084    }
    91    
     85
    9286    if (searchText && JSStringGetLength(searchText))
    9387        [parameterizedAttribute setObject:[NSString stringWithJSStringRef:searchText] forKey:@"AXSearchText"];
    94    
     88
    9589    [parameterizedAttribute setObject:@(visibleOnly) forKey:@"AXVisibleOnly"];
    96    
    9790    [parameterizedAttribute setObject:@(immediateDescendantsOnly) forKey:@"AXImmediateDescendantsOnly"];
    9891   
  • TabularUnified trunk/Tools/DumpRenderTree/mac/AccessibilityControllerMac.mm

    r236032 r267761  
    3131#import "AccessibilityNotificationHandler.h"
    3232#import "AccessibilityUIElement.h"
     33#import "JSBasics.h"
    3334#import <AppKit/NSColor.h>
    3435#import <Foundation/Foundation.h>
     
    159160JSRetainPtr<JSStringRef> AccessibilityController::platformName() const
    160161{
    161     return adopt(JSStringCreateWithUTF8CString("mac"));
     162    return WTR::createJSString("mac");
    162163}
  • TabularUnified trunk/Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm

    r264000 r267761  
    3030#import "AccessibilityNotificationHandler.h"
    3131#import "DumpRenderTree.h"
     32#import "JSBasics.h"
    3233#import <Foundation/Foundation.h>
    3334#import <JavaScriptCore/JSStringRefCF.h>
     
    8081- (void)_accessibilitySetValue:(id)value forAttribute:(NSString*)attributeName;
    8182@end
    82 
    83 static JSRetainPtr<JSStringRef> createEmptyJSString()
    84 {
    85     return adopt(JSStringCreateWithCharacters(nullptr, 0));
    86 }
    8783
    8884static Optional<AccessibilityUIElement> makeVectorElement(const AccessibilityUIElement*, id element)
     
    222218        }
    223219        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);
    232222            for (unsigned i = 0; i < searchStringsArrayLength; ++i) {
    233223                auto searchStringsString = adopt(JSValueToStringCopy(context, JSObjectGetPropertyAtIndex(context, searchStringsArray, i, nullptr), nullptr));
     
    263253                [searchStringsParameter addObject:[NSString stringWithJSStringRef:searchStringsString.get()]];
    264254        } 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);
    273257            for (unsigned i = 0; i < searchStringsArrayLength; ++i) {
    274258                auto searchStringsString = adopt(JSValueToStringCopy(context, JSObjectGetPropertyAtIndex(context, searchStringsArray, i, nullptr), nullptr));
     
    14471431void AccessibilityUIElement::clearSelectedChildren() const
    14481432{
    1449     // FIXME: implement
     1433    // FIXME: Implement this function.
    14501434}
    14511435
    14521436JSRetainPtr<JSStringRef> AccessibilityUIElement::accessibilityValue() const
    14531437{
    1454     // FIXME: implement
    1455     return createEmptyJSString();
     1438    // FIXME: Implement this function.
     1439    return WTR::createJSString();
    14561440}
    14571441
     
    14641448    END_AX_OBJC_EXCEPTIONS
    14651449   
    1466     return createEmptyJSString();
     1450    return WTR::createJSString();
    14671451}
    14681452
     
    14751459    END_AX_OBJC_EXCEPTIONS
    14761460   
    1477     return createEmptyJSString();
     1461    return WTR::createJSString();
    14781462}
    14791463
  • TabularUnified trunk/Tools/DumpRenderTree/mac/FrameLoadDelegate.mm

    r267640 r267761  
    312312- (void)didClearWindowObjectInStandardWorldForFrame:(WebFrame *)frame
    313313{
    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);
    328321
    329322    WebCoreTestSupport::injectInternalsObject(context);
    330323
    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"];
    362334}
    363335
     
    372344        return;
    373345
    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);
    375347}
    376348
  • TabularUnified trunk/Tools/DumpRenderTree/mac/TestRunnerMac.mm

    r265396 r267761  
    3333#import "DefaultPolicyDelegate.h"
    3434#import "EditingDelegate.h"
     35#import "JSBasics.h"
    3536#import "LayoutTestSpellChecker.h"
    3637#import "MockGeolocationProvider.h"
     
    671672    WebFindOptions options = 0;
    672673
    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) {
    682678        JSValueRef value = JSObjectGetPropertyAtIndex(context, optionsArray, i, 0);
    683679        if (!JSValueIsString(context, value))
  • TabularUnified trunk/Tools/DumpRenderTree/win/FrameLoadDelegate.cpp

    r267640 r267761  
    372372    frame->parentFrame(&parentFrame);
    373373
    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);
    387378
    388379    JSStringRef eventSenderStr = JSStringCreateWithUTF8CString("eventSender");
  • TabularUnified trunk/Tools/DumpRenderTree/win/TextInputController.cpp

    r231852 r267761  
    3131#include "TextInputController.h"
    3232
    33 #include <JavaScriptCore/JSRetainPtr.h>
     33#include "JSBasics.h"
    3434#include <wtf/RefPtr.h>
    3535
     
    163163// Object Creation
    164164
    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,
     165void TextInputController::makeWindowObject(JSContextRef context)
     166{
     167    WTR::setGlobalObjectProperty(context, "textInputController", JSObjectMake(context, createJSClass().get(), this));
     168}
     169
     170JSRetainPtr<JSClassRef> TextInputController::createJSClass()
     171{
     172    const JSClassDefinition classDefinition = {
     173        0, kJSClassAttributeNone, "TextInputController", 0, staticValues(), staticFunctions(),
    183174        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    184175    };
    185 
    186     return JSClassCreate(&classDefinition);
    187 }
    188 
    189 JSStaticValue* TextInputController::staticValues()
    190 {
    191     static JSStaticValue staticValues[] =
     176    return adopt(JSClassCreate(&classDefinition));
     177}
     178
     179const JSStaticValue* TextInputController::staticValues()
     180{
     181    static const JSStaticValue staticValues[] =
    192182    {
    193183        { 0, 0, 0, 0 }
     
    196186}
    197187
    198 JSStaticFunction* TextInputController::staticFunctions()
    199 {
    200     static JSStaticFunction staticFunctions[] = {
     188const JSStaticFunction* TextInputController::staticFunctions()
     189{
     190    static const JSStaticFunction staticFunctions[] = {
    201191        { "setMarkedText", setMarkedTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
    202192        { "hasMarkedText", hasMarkedTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  • TabularUnified trunk/Tools/DumpRenderTree/win/TextInputController.h

    r248762 r267761  
    2727 */
    2828 
    29 #ifndef TextInputController_h
    30 #define TextInputController_h
     29#pragma once
    3130
    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>
    3632#include <vector>
    3733#include <wtf/FastMalloc.h>
     
    4036    WTF_MAKE_FAST_ALLOCATED;
    4137public:
    42     void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
     38    void makeWindowObject(JSContextRef);
    4339
    4440    void setMarkedText(JSStringRef text, unsigned int from, unsigned int length);
     
    5147
    5248private:   
    53     static JSClassRef getJSClass();
    54     static JSStaticValue* staticValues();
    55     static JSStaticFunction* staticFunctions();
     49    static JSRetainPtr<JSClassRef> createJSClass();
     50    static const JSStaticValue* staticValues();
     51    static const JSStaticFunction* staticFunctions();
    5652};
    57 
    58 #endif // TextInputController_h
  • TabularUnified trunk/Tools/TestRunnerShared/Bindings/JSBasics.cpp

    r266988 r267761  
    2929namespace WTR {
    3030
    31 JSValueRef JSValueMakeBooleanOrNull(JSContextRef context, Optional<bool> value)
     31Optional<bool> toOptionalBool(JSContextRef context, JSValueRef value)
     32{
     33    return JSValueIsUndefined(context, value) || JSValueIsNull(context, value) ? WTF::nullopt : makeOptional(JSValueToBoolean(context, value));
     34}
     35
     36Optional<double> toOptionalDouble(JSContextRef context, JSValueRef value)
     37{
     38    return JSValueIsUndefined(context, value) || JSValueIsNull(context, value) ? WTF::nullopt : makeOptional(JSValueToNumber(context, value, nullptr));
     39}
     40
     41JSValueRef makeValue(JSContextRef context, Optional<bool> value)
    3242{
    3343    return value ? JSValueMakeBoolean(context, value.value()) : JSValueMakeNull(context);
    3444}
    3545
    36 Optional<bool> JSValueToNullableBoolean(JSContextRef context, JSValueRef value)
     46JSValueRef makeValue(JSContextRef context, JSStringRef string)
    3747{
    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);
    4449}
    4550
     
    4954}
    5055
     56JSRetainPtr<JSStringRef> createJSString(JSContextRef context, JSValueRef value)
     57{
     58    auto string = adopt(value ? JSValueToStringCopy(context, value, nullptr) : nullptr);
     59    return string ? string : createJSString("");
     60}
     61
    5162JSValueRef makeValue(JSContextRef context, const char* string)
    5263{
     
    5465}
    5566
     67JSValueRef property(JSContextRef context, JSObjectRef object, const char* name)
     68{
     69    return object ? JSObjectGetProperty(context, object, createJSString(name).get(), nullptr) : nullptr;
     70}
     71
     72JSRetainPtr<JSStringRef> stringProperty(JSContextRef context, JSObjectRef object, const char* name)
     73{
     74    return createJSString(context, property(context, object, name));
     75}
     76
     77bool 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
     83double 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
    5689JSObjectRef objectProperty(JSContextRef context, JSObjectRef object, const char* name)
    5790{
    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;
    6493}
    6594
     
    71100}
    72101
     102unsigned arrayLength(JSContextRef context, JSObjectRef object)
     103{
     104    return numericProperty(context, object, "length");
     105}
     106
    73107void setProperty(JSContextRef context, JSObjectRef object, const char* name, bool value)
    74108{
     
    76110}
    77111
     112void 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
     117void setGlobalObjectProperty(JSContextRef context, const char* name, JSValueRef value)
     118{
     119    JSObjectSetProperty(context, JSContextGetGlobalObject(context), createJSString(name).get(), value, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, nullptr);
     120}
     121
     122void setGlobalObjectProperty(JSContextRef context, const char* name, double value)
     123{
     124    setGlobalObjectProperty(context, name, JSValueMakeNumber(context, value));
     125}
     126
    78127JSValueRef call(JSContextRef context, JSObjectRef object, const char* name, std::initializer_list<JSValueRef> arguments)
    79128{
    80     if (!object)
    81         return nullptr;
    82129    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;
    86131}
    87132
     
    89134{
    90135    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;
    94137}
    95138
  • TabularUnified trunk/Tools/TestRunnerShared/Bindings/JSBasics.h

    r266988 r267761  
    3333namespace WTR {
    3434
    35 JSValueRef JSValueMakeBooleanOrNull(JSContextRef, Optional<bool>);
    36 Optional<bool> JSValueToNullableBoolean(JSContextRef, JSValueRef);
     35Optional<bool> toOptionalBool(JSContextRef, JSValueRef);
     36Optional<double> toOptionalDouble(JSContextRef, JSValueRef);
    3737
    38 JSValueRef JSValueMakeStringOrNull(JSContextRef, JSStringRef);
     38JSRetainPtr<JSStringRef> createJSString(const char* = "");
     39JSRetainPtr<JSStringRef> createJSString(JSContextRef, JSValueRef);
    3940
    40 JSRetainPtr<JSStringRef> createJSString(const char*);
    4141JSValueRef makeValue(JSContextRef, const char*);
     42JSValueRef makeValue(JSContextRef, Optional<bool>);
     43JSValueRef makeValue(JSContextRef, JSStringRef);
     44
     45JSValueRef property(JSContextRef, JSObjectRef, const char* name);
     46bool booleanProperty(JSContextRef, JSObjectRef, const char* name, bool defaultValue = false);
     47double numericProperty(JSContextRef, JSObjectRef, const char* name);
     48JSRetainPtr<JSStringRef> stringProperty(JSContextRef, JSObjectRef, const char* name);
     49unsigned arrayLength(JSContextRef, JSObjectRef);
    4250JSObjectRef objectProperty(JSContextRef, JSObjectRef, const char* name);
    4351JSObjectRef objectProperty(JSContextRef, JSObjectRef, std::initializer_list<const char*> names);
     52
    4453void setProperty(JSContextRef, JSObjectRef, const char* name, bool value);
     54void setProperty(JSContextRef, JSObjectRef, const char* name, double value);
     55
     56void setGlobalObjectProperty(JSContextRef, const char* name, JSValueRef);
     57void setGlobalObjectProperty(JSContextRef, const char* name, double value);
     58
    4559JSValueRef call(JSContextRef, JSObjectRef, const char* name, std::initializer_list<JSValueRef> arguments);
    4660JSObjectRef callConstructor(JSGlobalContextRef, const char* name, std::initializer_list<JSValueRef> arguments);
  • TabularUnified trunk/Tools/TestRunnerShared/Bindings/JSWrappable.h

    r266988 r267761  
    2626#pragma once
    2727
    28 #include <JavaScriptCore/JavaScript.h>
    2928#include <wtf/RefCounted.h>
     29
     30typedef struct OpaqueJSClass* JSClassRef;
    3031
    3132namespace WTR {
  • TabularUnified trunk/Tools/TestRunnerShared/Bindings/JSWrapper.h

    r266988 r267761  
    5151}
    5252
     53inline void setGlobalObjectProperty(JSContextRef context, const char* propertyName, JSWrappable* value)
     54{
     55    setGlobalObjectProperty(context, propertyName, JSWrapper::wrap(context, value));
     56}
     57
    5358} // namespace WTR
  • TabularUnified trunk/Tools/TestRunnerShared/EventSerialization/mac/EventSerializerMac.mm

    r236303 r267761  
    196196+ (NSDictionary *)dictionaryForEvent:(CGEventRef)rawEvent relativeToTime:(CGEventTimestamp)referenceTimestamp
    197197{
    198     RetainPtr<CGEventRef> plainEvent = adoptCF(CGEventCreate(NULL));
     198    auto plainEvent = adoptCF(CGEventCreate(NULL));
    199199    CGEventRef rawPlainEvent = plainEvent.get();
    200200
     
    227227+ (RetainPtr<CGEventRef>)createEventForDictionary:(NSDictionary *)dict inWindow:(NSWindow *)window relativeToTime:(CGEventTimestamp)referenceTimestamp
    228228{
    229     RetainPtr<CGEventRef> event = adoptCF(CGEventCreate(NULL));
     229    auto event = adoptCF(CGEventCreate(NULL));
    230230    CGEventRef rawEvent = event.get();
    231231
     
    265265+ (void)playStream:(NSArray<NSDictionary *> *)eventDicts window:(NSWindow *)window completionHandler:(void(^)())completionHandler
    266266{
    267     RetainPtr<EventStreamPlayer> player = adoptNS([[EventStreamPlayer alloc] init]);
     267    auto player = adoptNS([[EventStreamPlayer alloc] init]);
    268268
    269269    player->_remainingEventDictionaries = adoptNS([eventDicts mutableCopy]);
     
    283283    NSEvent *nsEvent = nil;
    284284    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];
    286286        if (CGEventGetTimestamp(event.get()) < mach_absolute_time()) {
    287287            nsEvent = [NSEvent eventWithCGEvent:event.get()];
  • TabularUnified trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptContext.cpp

    r267030 r267761  
    2727#include "UIScriptContext.h"
    2828
     29#include "JSBasics.h"
    2930#include "UIScriptController.h"
    30 #include <JavaScriptCore/JSContextRef.h>
    31 #include <JavaScriptCore/JSValueRef.h>
    3231#include <WebCore/FloatRect.h>
    3332
     
    4443{
    4544    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());
    5146}
    5247
     
    6762   
    6863    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());
    7265        tryToCompleteUIScriptForCurrentParentCallback();
    7366    }
     
    190183    JSObjectRef object = JSObjectMake(m_context.get(), nullptr, nullptr);
    191184
    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());
    196189   
    197190    return object;
  • TabularUnified trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h

    r267120 r267761  
    6464    virtual void waitForOutstandingCallbacks() { /* notImplemented(); */ }
    6565
    66     void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
     66    void makeWindowObject(JSContextRef);
    6767
    6868    // Transaction helpers
  • TabularUnified trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptControllerShared.cpp

    r267030 r267761  
    4242        DeviceOrientation::LandscapeRight
    4343    };
    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"))
    4746        return &values[0];
    48 
    49     if (option->string() == "portrait-upsidedown")
     47    if (JSStringIsEqualToUTF8CString(option.get(), "portrait-upsidedown"))
    5048        return &values[1];
    51 
    52     if (option->string() == "landscape-left")
     49    if (JSStringIsEqualToUTF8CString(option.get(), "landscape-left"))
    5350        return &values[2];
    54 
    55     if (option->string() == "landscape-right")
     51    if (JSStringIsEqualToUTF8CString(option.get(), "landscape-right"))
    5652        return &values[3];
    57 
    5853    return nullptr;
    5954}
     
    6964}
    7065
    71 void UIScriptController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
    72 {
    73     setProperty(context, windowObject, "uiController", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
     66void UIScriptController::makeWindowObject(JSContextRef context)
     67{
     68    setGlobalObjectProperty(context, "uiController", this);
    7469}
    7570
  • TabularUnified trunk/Tools/TestRunnerShared/cocoa/LayoutTestSpellChecker.mm

    r265396 r267761  
    2727#import "LayoutTestSpellChecker.h"
    2828
    29 #import <JavaScriptCore/JSRetainPtr.h>
     29#import "JSBasics.h"
    3030#import <objc/runtime.h>
    3131#import <wtf/Assertions.h>
     
    213213{
    214214    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");
    220220    auto results = adoptNS([[NSMutableDictionary alloc] init]);
    221221
     
    229229        for (size_t resultIndex = 0; resultIndex < JSPropertyNameArrayGetCount(resultsArrayPropertyNames); ++resultIndex) {
    230230            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));
    234234            auto replacementValue = JSObjectGetProperty(context, resultsObject, replacementPropertyName.get(), nullptr);
    235235            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()));
    240238            auto details = adoptNS([[NSMutableArray alloc] init]);
    241239            auto detailsValue = JSObjectGetProperty(context, resultsObject, detailsPropertyName.get(), nullptr);
  • TabularUnified trunk/Tools/WebKitTestRunner/EventSenderProxy.h

    r264488 r267761  
    113113#endif
    114114
    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 };
    122122    unsigned m_mouseButtonsCurrentlyDown { 0 };
    123123#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 };
    127128    Vector<struct wpe_input_touch_event_raw> m_touchEvents;
    128129    HashSet<unsigned, DefaultHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<unsigned>> m_updatedTouchEvents;
  • TabularUnified trunk/Tools/WebKitTestRunner/GeolocationProviderMock.cpp

    r228942 r267761  
    6464}
    6565
    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, double floorLevel)
     66void GeolocationProviderMock::setPosition(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitudeAccuracy, Optional<double> heading, Optional<double> speed, Optional<double> floorLevel)
    6767{
    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)));
    6969
    7070    m_hasError = false;
  • TabularUnified trunk/Tools/WebKitTestRunner/GeolocationProviderMock.h

    r248762 r267761  
    3838    ~GeolocationProviderMock();
    3939
    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, double floorLevel);
     40    void setPosition(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitudeAccuracy, Optional<double> heading, Optional<double> speed, Optional<double> floorLevel);
    4141    void setPositionUnavailableError(WKStringRef errorMessage);
    4242
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityController.cpp

    r265248 r267761  
    7676#endif
    7777
    78 void AccessibilityController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
    79 {
    80     setProperty(context, windowObject, "accessibilityController", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
     78void AccessibilityController::makeWindowObject(JSContextRef context)
     79{
     80    setGlobalObjectProperty(context, "accessibilityController", this);
    8181}
    8282
     
    9797
    9898#if PLATFORM(COCOA)
     99
    99100Ref<AccessibilityUIElement> AccessibilityController::rootElement()
    100101{
    101     WKBundlePageRef page = InjectedBundle::singleton().page()->page();
     102    auto page = InjectedBundle::singleton().page()->page();
    102103    PlatformUIElement root = static_cast<PlatformUIElement>(WKAccessibilityRootObject(page));
    103 
    104104    return AccessibilityUIElement::create(root);
    105105}
     
    107107Ref<AccessibilityUIElement> AccessibilityController::focusedElement()
    108108{
    109     WKBundlePageRef page = InjectedBundle::singleton().page()->page();
     109    auto page = InjectedBundle::singleton().page()->page();
    110110    PlatformUIElement focusedElement = static_cast<PlatformUIElement>(WKAccessibilityFocusedObject(page));
    111111    return AccessibilityUIElement::create(focusedElement);
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/AccessibilityController.h

    r265248 r267761  
    4646    ~AccessibilityController();
    4747
    48     void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
     48    void makeWindowObject(JSContextRef);
    4949    virtual JSClassRef wrapperClass();
    5050   
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/CodeGeneratorTestRunner.pm

    r266311 r267761  
    262262JSClassRef ${className}::${classRefGetter}()
    263263{
    264     static JSClassRef jsClass;
    265     if (!jsClass) {
     264    static const JSClassRef jsClass = [] {
    266265        JSClassDefinition definition = kJSClassDefinitionEmpty;
    267266        definition.className = "@{[$type->name]}";
     
    275274
    276275    push(@contents, <<EOF);
    277         jsClass = JSClassCreate(&definition);
    278     }
     276        return JSClassCreate(&definition);
     277    }();
    279278    return jsClass;
    280279}
     
    478477    my ($self, $type, $argumentName) = @_;
    479478
    480     return "JSValueToNullableBoolean(context, $argumentName)" if $type->name eq "boolean" && $type->isNullable;
     479    return "toOptionalBool(context, $argumentName)" if $type->name eq "boolean" && $type->isNullable;
    481480    return "JSValueToBoolean(context, $argumentName)" if $type->name eq "boolean";
    482481    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;
    484484    return "JSValueToNumber(context, $argumentName, nullptr)" if $$self{codeGenerator}->IsPrimitiveType($type);
    485485    return "to" . _implementationClassName($type) . "(context, $argumentName)";
     
    500500    );
    501501
    502     my $nullValue = "0";
     502    my $nullValue = "nullptr";
    503503    if ($platformType eq "JSValueRef") {
    504504        $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;";
    514512}
    515513
     
    519517
    520518    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;
    522520    return "JSValueMakeBoolean(context, ${expression})" if $returnType->name eq "boolean";
    523521    return "${expression}" if $returnType->name eq "object";
    524522    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);
    526524    return "toJS(context, WTF::getPtr(${expression}))";
    527525}
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl

    r267750 r267761  
    216216    // Geolocation
    217217    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 object floorLevel);
     218    undefined setMockGeolocationPosition(double latitude, double longitude, double accuracy, optional double? altitude, optional double? altitudeAccuracy, optional double? heading, optional double? speed, optional double? floorLevel);
    219219    undefined setMockGeolocationPositionUnavailableError(DOMString errorMessage);
    220220    boolean isGeolocationProviderActive();
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp

    r261539 r267761  
    2727#include "EventSendingController.h"
    2828
     29#include "DictionaryFunctions.h"
    2930#include "InjectedBundle.h"
    3031#include "InjectedBundlePage.h"
    3132#include "JSEventSendingController.h"
    32 #include "StringFunctions.h"
    3333#include <WebKit/WKBundle.h>
    3434#include <WebKit/WKBundleFrame.h>
     
    5353
    5454#if ENABLE(CONTEXT_MENUS)
     55
    5556static JSValueRef menuItemClickCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t, const JSValueRef[], JSValueRef*)
    5657{
     
    6364{
    6465    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()));
    6667    return JSValueMakeString(context, toJS(wkTitle).get());
    6768}
     
    7374    MenuItemPrivateData* privateData = static_cast<MenuItemPrivateData*>(JSObjectGetPrivate(object));
    7475    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);
    8177    for (size_t i = 0; i < WKArrayGetSize(children.get()); ++i) {
    8278        auto item = static_cast<WKContextMenuItemRef>(WKArrayGetItemAtIndex(children.get(), i));
    8379        auto* privateData = new MenuItemPrivateData(InjectedBundle::singleton().page()->page(), item);
    84         JSObjectSetPropertyAtIndex(context, arrayObject, i, JSObjectMake(context, getMenuItemClass(), privateData), 0);
     80        JSObjectSetPropertyAtIndex(context, array, i, JSObjectMake(context, getMenuItemClass(), privateData), 0);
    8581    }
    86 
    87     return arrayResult;
     82    return array;
    8883}
    8984
     
    127122    return menuItemClass;
    128123}
     124
    129125#endif
    130126
    131 static WKEventModifiers parseModifier(JSStringRef modifier)
    132 {
    133     if (JSStringIsEqualToUTF8CString(modifier, "ctrlKey"))
     127static WKEventModifiers parseModifier(const JSRetainPtr<JSStringRef>& modifier)
     128{
     129    if (JSStringIsEqualToUTF8CString(modifier.get(), "ctrlKey"))
    134130        return kWKEventModifiersControlKey;
    135     if (JSStringIsEqualToUTF8CString(modifier, "shiftKey") || JSStringIsEqualToUTF8CString(modifier, "rangeSelectionKey"))
     131    if (JSStringIsEqualToUTF8CString(modifier.get(), "shiftKey") || JSStringIsEqualToUTF8CString(modifier.get(), "rangeSelectionKey"))
    136132        return kWKEventModifiersShiftKey;
    137     if (JSStringIsEqualToUTF8CString(modifier, "altKey"))
     133    if (JSStringIsEqualToUTF8CString(modifier.get(), "altKey"))
    138134        return kWKEventModifiersAltKey;
    139     if (JSStringIsEqualToUTF8CString(modifier, "metaKey"))
     135    if (JSStringIsEqualToUTF8CString(modifier.get(), "metaKey"))
    140136        return kWKEventModifiersMetaKey;
    141     if (JSStringIsEqualToUTF8CString(modifier, "capsLockKey"))
     137    if (JSStringIsEqualToUTF8CString(modifier.get(), "capsLockKey"))
    142138        return kWKEventModifiersCapsLockKey;
    143     if (JSStringIsEqualToUTF8CString(modifier, "addSelectionKey")) {
     139    if (JSStringIsEqualToUTF8CString(modifier.get(), "addSelectionKey")) {
    144140#if OS(MAC_OS_X)
    145141        return kWKEventModifiersMetaKey;
     
    151147}
    152148
    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
     151static 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
    161165
    162166static WKEventModifiers parseModifierArray(JSContextRef context, JSValueRef arrayValue)
     
    166170
    167171    // 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));
    172174
    173175    if (!JSValueIsObject(context, arrayValue))
     
    177179    WKEventModifiers modifiers = 0;
    178180    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));
    187183    }
    188184    return modifiers;
    189185}
    190186
     187static WKEventModifiers parseModifierArray(JSValueRef arrayValue)
     188{
     189    return parseModifierArray(WKBundleFrameGetJavaScriptContext(WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page())), arrayValue);
     190}
     191
    191192Ref<EventSendingController> EventSendingController::create()
    192193{
     
    194195}
    195196
    196 EventSendingController::EventSendingController()
    197 {
    198 }
    199 
    200 EventSendingController::~EventSendingController()
    201 {
    202 }
    203 
    204197JSClassRef EventSendingController::wrapperClass()
    205198{
     
    207200}
    208201
    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;
     202enum MouseState { MouseUp, MouseDown };
     203
     204static 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;
    231211}
    232212
    233213void EventSendingController::mouseDown(int button, JSValueRef modifierArray)
    234214{
    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)));
    245216}
    246217
    247218void EventSendingController::mouseUp(int button, JSValueRef modifierArray)
    248219{
    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)));
    258221}
    259222
    260223void EventSendingController::mouseMoveTo(int x, int y)
    261224{
    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)));
    277229    m_position = WKPointMake(x, y);
    278    
    279     WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
     230    postSynchronousPageMessage("EventSender", body);
    280231}
    281232
    282233void EventSendingController::mouseForceClick()
    283234{
    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);
    292238}
    293239
    294240void EventSendingController::startAndCancelMouseForceClick()
    295241{
    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);
    304245}
    305246
    306247void EventSendingController::mouseForceDown()
    307248{
    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);
    316252}
    317253
    318254void EventSendingController::mouseForceUp()
    319255{
    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);
    328259}
    329260
    330261void EventSendingController::mouseForceChanged(double force)
    331262{
    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);
    344267}
    345268
    346269void EventSendingController::leapForward(int milliseconds)
    347270{
    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);
    360275}
    361276
    362277void EventSendingController::scheduleAsynchronousClick()
    363278{
    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));
    376281}
    377282
    378283static WKRetainPtr<WKMutableDictionaryRef> createKeyDownMessageBody(JSStringRef key, WKEventModifiers modifiers, int location)
    379284{
    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;
    398291}
    399292
    400293void EventSendingController::keyDown(JSStringRef key, JSValueRef modifierArray, int location)
    401294{
    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));
    411296}
    412297
    413298void EventSendingController::scheduleAsynchronousKeyDown(JSStringRef key)
    414299{
    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));
    419301}
    420302
    421303void EventSendingController::mouseScrollBy(int x, int y)
    422304{
    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 
    438305    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);
    440312}
    441313
     
    476348void EventSendingController::mouseScrollByWithWheelAndMomentumPhases(int x, int y, JSStringRef phaseStr, JSStringRef momentumStr)
    477349{
    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 
    493350    uint64_t phase = cgEventPhaseFromString(phaseStr);
    494351    uint64_t momentum = cgEventMomentumPhaseFromString(momentumStr);
    495    
     352
    496353    if (phase == 4 /* kCGScrollPhaseEnded */ || phase == 8 /* kCGScrollPhaseCancelled */)
    497354        m_sentWheelPhaseEndOrCancel = true;
    498    
    499355    if (momentum == 3 /* kCGMomentumScrollPhaseEnd */)
    500356        m_sentWheelMomentumPhaseEnd = true;
    501357
    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 
    510358    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);
    512367}
    513368
    514369void EventSendingController::continuousMouseScrollBy(int x, int y, bool paged)
    515370{
    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);
    535376    // FIXME: This message should be asynchronous, as scrolling is intrinsically asynchronous.
    536377    // 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);
    538379}
    539380
    540381JSValueRef EventSendingController::contextClick()
    541382{
    542     WKBundlePageRef page = InjectedBundle::singleton().page()->page();
     383    auto page = InjectedBundle::singleton().page()->page();
    543384    WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(page);
    544385    JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
    545386#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);
    548389    if (!menuEntries)
    549         return arrayResult;
    550 
    551     JSObjectRef arrayObj = JSValueToObject(context, arrayResult, 0);
     390        return array;
     391
    552392    size_t entriesSize = WKArrayGetSize(menuEntries.get());
    553393    for (size_t i = 0; i < entriesSize; ++i) {
     
    556396        WKContextMenuItemRef item = static_cast<WKContextMenuItemRef>(WKArrayGetItemAtIndex(menuEntries.get(), i));
    557397        MenuItemPrivateData* privateData = new MenuItemPrivateData(page, item);
    558         JSObjectSetPropertyAtIndex(context, arrayObj, i, JSObjectMake(context, getMenuItemClass(), privateData), 0);
     398        JSObjectSetPropertyAtIndex(context, array, i, JSObjectMake(context, getMenuItemClass(), privateData), 0);
    559399    }
    560400
    561     return arrayResult;
     401    return array;
    562402#else
    563403    return JSValueMakeUndefined(context);
     
    616456        return nullptr;
    617457
    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 
    625458    static MonitorWheelEventsOptions options;
    626     options.resetLatching = resetLatching;
     459    options.resetLatching = booleanProperty(context, (JSObjectRef)argument, "resetLatching", true);
    627460    return &options;
    628461}
     
    630463void EventSendingController::monitorWheelEvents(MonitorWheelEventsOptions* options)
    631464{
    632     WKBundlePageRef page = InjectedBundle::singleton().page()->page();
     465    auto page = InjectedBundle::singleton().page()->page();
    633466   
    634467    m_sentWheelPhaseEndOrCancel = false;
     
    664497        return;
    665498
    666     WKBundlePageRef page = InjectedBundle::singleton().page()->page();
     499    auto page = InjectedBundle::singleton().page()->page();
    667500    WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(page);
    668501    JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
     
    684517
    685518#if ENABLE(TOUCH_EVENTS)
     519
    686520void EventSendingController::addTouchPoint(int x, int y)
    687521{
    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);
    704527}
    705528
    706529void EventSendingController::updateTouchPoint(int index, int x, int y)
    707530{
    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
     539void 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}
    760547
    761548void EventSendingController::setTouchPointRadius(int radiusX, int radiusY)
    762549{
    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);
    779555}
    780556
    781557void EventSendingController::touchStart()
    782558{
    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);
    791562}
    792563
    793564void EventSendingController::touchMove()
    794565{
    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);
    803569}
    804570
    805571void EventSendingController::touchEnd()
    806572{
    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);
    815576}
    816577
    817578void EventSendingController::touchCancel()
    818579{
    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);
    827583}
    828584
    829585void EventSendingController::clearTouchPoints()
    830586{
    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);
    839590}
    840591
    841592void EventSendingController::releaseTouchPoint(int index)
    842593{
    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);
    855598}
    856599
    857600void EventSendingController::cancelTouchPoint(int index)
    858601{
    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
    872608#endif
    873609
    874610// Object Creation
    875611
    876 void EventSendingController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
    877 {
    878     setProperty(context, windowObject, "eventSender", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
     612void EventSendingController::makeWindowObject(JSContextRef context)
     613{
     614    setGlobalObjectProperty(context, "eventSender", this);
    879615}
    880616
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.h

    r261539 r267761  
    3131#include <wtf/Ref.h>
    3232
     33typedef const struct OpaqueJSContext* JSContextRef;
     34typedef struct OpaqueJSString* JSStringRef;
     35typedef const struct OpaqueJSValue* JSValueRef;
     36
    3337namespace WTR {
    3438
    3539struct MonitorWheelEventsOptions {
    36     MonitorWheelEventsOptions(bool resetLatching = true)
    37         : resetLatching(resetLatching)
    38     { }
    39 
    4040    bool resetLatching { true };
    4141};
     
    4343MonitorWheelEventsOptions* toMonitorWheelEventsOptions(JSContextRef, JSValueRef);
    4444
    45 class EventSendingController : public JSWrappable {
     45class EventSendingController final : public JSWrappable {
    4646public:
    4747    static Ref<EventSendingController> create();
    48     virtual ~EventSendingController();
    4948
    50     void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
    51 
    52     // JSWrappable
    53     virtual JSClassRef wrapperClass();
     49    void makeWindowObject(JSContextRef);
    5450
    5551    void mouseDown(int button, JSValueRef modifierArray);
     
    7470    void scheduleAsynchronousKeyDown(JSStringRef key);
    7571
    76     // Zoom functions.
    7772    void textZoomIn();
    7873    void textZoomOut();
     
    8277
    8378#if ENABLE(TOUCH_EVENTS)
    84     // Touch events.
    8579    void addTouchPoint(int x, int y);
    8680    void updateTouchPoint(int index, int x, int y);
    87     void setTouchModifier(const JSStringRef &modifier, bool enable);
     81    void setTouchModifier(JSStringRef modifier, bool enable);
    8882    void setTouchPointRadius(int radiusX, int radiusY);
    8983    void touchStart();
     
    9791
    9892private:
    99     EventSendingController();
     93    EventSendingController() = default;
     94
     95    JSClassRef wrapperClass() final;
     96
    10097    WKPoint m_position;
    10198    bool m_sentWheelPhaseEndOrCancel { false };
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/GCController.cpp

    r208338 r267761  
    3838}
    3939
    40 GCController::GCController()
    41 {
    42 }
    43 
    44 GCController::~GCController()
    45 {
    46 }
    47 
    4840JSClassRef GCController::wrapperClass()
    4941{
     
    6658}
    6759
    68 // Object Creation
    69 
    70 void GCController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
     60void GCController::makeWindowObject(JSContextRef context)
    7161{
    72     setProperty(context, windowObject, "GCController", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
     62    setGlobalObjectProperty(context, "GCController", this);
    7363}
    7464
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/GCController.h

    r208338 r267761  
    2727
    2828#include "JSWrappable.h"
    29 #include <wtf/Ref.h>
     29#include <wtf/Forward.h>
     30
     31typedef const struct OpaqueJSContext* JSContextRef;
    3032
    3133namespace WTR {
    3234
    33 class GCController : public JSWrappable {
     35class GCController final : public JSWrappable {
    3436public:
    3537    static Ref<GCController> create();
    36     virtual ~GCController();
    3738
    38     void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
    39 
    40     // JSWrappable
    41     virtual JSClassRef wrapperClass();
     39    void makeWindowObject(JSContextRef);
    4240
    4341    void collect();
     
    4644
    4745private:
    48     GCController();
     46    GCController() = default;
     47
     48    JSClassRef wrapperClass() final;
    4949};
    5050
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp

    r266895 r267761  
    11/*
    2  * Copyright (C) 2010-2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2828
    2929#include "ActivateFonts.h"
     30#include "DictionaryFunctions.h"
    3031#include "InjectedBundlePage.h"
    31 #include "StringFunctions.h"
    3232#include "WebCoreTestSupport.h"
    3333#include <JavaScriptCore/Options.h>
     
    119119        return;
    120120
    121     WKRetainPtr<WKStringRef> messsageName = adoptWK(WKStringCreateWithUTF8CString("Initialization"));
    122121    WKTypeRef result = nullptr;
    123122    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
    124     WKBundlePostSynchronousMessage(m_bundle, messsageName.get(), nullptr, &result);
     123    WKBundlePostSynchronousMessage(m_bundle, toWK("Initialization").get(), nullptr, &result);
    125124    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"))
    133128        beginTesting(initializationDictionary.get(), BegingTestingMode::Resume);
    134129}
     
    175170}
    176171
    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());
     172WKBundlePageRef InjectedBundle::pageRef() const
     173{
     174    auto page = this->page();
     175    return page ? page->page() : nullptr;
     176}
     177
     178void InjectedBundle::didReceiveMessage(WKStringRef, WKTypeRef)
     179{
     180    WKBundlePostMessage(m_bundle, toWK("Error").get(), toWK("Unknown").get());
    187181}
    188182
    189183static void postGCTask(void* context)
    190184{
    191     WKBundlePageRef page = reinterpret_cast<WKBundlePageRef>(context);
     185    auto page = reinterpret_cast<WKBundlePageRef>(context);
    192186    InjectedBundle::singleton().reportLiveDocuments(page);
    193187    WKRelease(page);
     
    200194
    201195    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());
    205197}
    206198
     
    209201    if (WKStringIsEqualToUTF8CString(messageName, "BeginTest")) {
    210202        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());
    227208        beginTesting(messageBodyDictionary, BegingTestingMode::New);
    228209        return;
     
    231212    if (WKStringIsEqualToUTF8CString(messageName, "Reset")) {
    232213        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"))
    245218            WKBundleGarbageCollectJavaScriptObjects(m_bundle);
    246219
    247220#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");
    250222#endif
    251223       
    252         WKRetainPtr<WKStringRef> allowedHostsKey = adoptWK(WKStringCreateWithUTF8CString("AllowedHosts"));
    253         WKTypeRef allowedHostsValue = WKDictionaryGetItemForKey(messageBodyDictionary, allowedHostsKey.get());
     224        auto allowedHostsValue = value(messageBodyDictionary, "AllowedHosts");
    254225        if (allowedHostsValue && WKGetTypeID(allowedHostsValue) == WKArrayGetTypeID()) {
    255226            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)));
    263230        }
    264231
     
    267234        m_pixelResultIsPending = false;
    268235
    269         resetLocalSettings();
     236        setlocale(LC_ALL, "");
    270237        TestRunner::removeAllWebNotificationPermissions();
    271238
     
    276243    if (WKStringIsEqualToUTF8CString(messageName, "GetLiveDocuments")) {
    277244        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)));
    281246        return;
    282247    }
     
    429394        domains.reserveInitialCapacity(size);
    430395        for (size_t i = 0; i < size; ++i) {
    431             WKTypeRef item = WKArrayGetItemAtIndex(domainsArray, i);
     396            auto item = WKArrayGetItemAtIndex(domainsArray, i);
    432397            if (item && WKGetTypeID(item) == WKStringGetTypeID())
    433398                domains.append(toWTFString(static_cast<WKStringRef>(item)));
     
    447412        domains.reserveInitialCapacity(size);
    448413        for (size_t i = 0; i < size; ++i) {
    449             WKTypeRef item = WKArrayGetItemAtIndex(domainsArray, i);
     414            auto item = WKArrayGetItemAtIndex(domainsArray, i);
    450415            if (item && WKGetTypeID(item) == WKStringGetTypeID())
    451416                domains.uncheckedAppend(toWTFString(static_cast<WKStringRef>(item)));
     
    468433
    469434    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());
    481439        return;
    482440    }
     
    499457
    500458    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");
    524470
    525471        m_testRunner->statisticsDidRunTelemetryCallback(numberOfPrevalentResources, numberOfPrevalentResourcesWithUserInteraction, numberOfPrevalentResourcesWithoutUserInteraction, topPrevalentResourceWithUserInteractionDaysSinceUserInteraction, medianDaysSinceUserInteractionPrevalentResourceWithUserInteraction, top3NumberOfPrevalentResourcesWithUI, top3MedianSubFrameWithoutUI, top3MedianSubResourceWithoutUI, top3MedianUniqueRedirectsWithoutUI, top3MedianDataRecordsRemovedWithoutUI);
     
    542488    }
    543489
    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");
    569491}
    570492
     
    599521
    600522#if PLATFORM(IOS_FAMILY)
    601     WKBundlePageSetUseTestingViewportConfiguration(page()->page(), !booleanForKey(settings, "UseFlexibleViewport"));
     523    WKBundlePageSetUseTestingViewportConfiguration(page()->page(), !booleanValue(settings, "UseFlexibleViewport"));
    602524#endif
    603525
    604526#if PLATFORM(COCOA)
    605     WebCoreTestSupport::setAdditionalSupportedImageTypesForTesting(stringForKey(settings, "additionalSupportedImageTypes"));
     527    WebCoreTestSupport::setAdditionalSupportedImageTypesForTesting(toWTFString(stringValue(settings, "additionalSupportedImageTypes")));
    606528#endif
    607529
     
    661583#endif
    662584
    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());
    682594
    683595    closeOtherPages();
     
    692604    for (size_t i = 1; i < size; ++i)
    693605        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);
    697608}
    698609
     
    710621    if (output.isEmpty())
    711622        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");
    719626}
    720627
     
    725632    if (output.isEmpty())
    726633        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();
    733636    // We use WKBundlePagePostMessageIgnoringFullySynchronousMode() instead of WKBundlePagePostMessage() to make sure that all text output
    734637    // is done via asynchronous IPC, even if the connection is in fully synchronous mode due to a WKBundlePagePostSynchronousMessageForTesting()
    735638    // 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());
    737640}
    738641
    739642void InjectedBundle::postNewBeforeUnloadReturnValue(bool value)
    740643{
    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);
    744645}
    745646
    746647void InjectedBundle::postAddChromeInputField()
    747648{
    748     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("AddChromeInputField"));
    749     WKBundlePagePostMessage(page()->page(), messageName.get(), 0);
     649    postPageMessage("AddChromeInputField");
    750650}
    751651
    752652void InjectedBundle::postRemoveChromeInputField()
    753653{
    754     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("RemoveChromeInputField"));
    755     WKBundlePagePostMessage(page()->page(), messageName.get(), 0);
     654    postPageMessage("RemoveChromeInputField");
    756655}
    757656
    758657void InjectedBundle::postFocusWebView()
    759658{
    760     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("FocusWebView"));
    761     WKBundlePagePostMessage(page()->page(), messageName.get(), 0);
     659    postPageMessage("FocusWebView");
    762660}
    763661
    764662void InjectedBundle::postSetBackingScaleFactor(double backingScaleFactor)
    765663{
    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)));
    769665}
    770666
    771667void InjectedBundle::postSetWindowIsKey(bool isKey)
    772668{
    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);
    776670}
    777671
    778672void InjectedBundle::postSetViewSize(double width, double height)
    779673{
    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);
    794678}
    795679
    796680void InjectedBundle::postSimulateWebNotificationClick(uint64_t notificationID)
    797681{
    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)));
    801683}
    802684
    803685void InjectedBundle::postSetAddsVisitedLinks(bool addsVisitedLinks)
    804686{
    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)));
    808688}
    809689
    810690void InjectedBundle::setGeolocationPermission(bool enabled)
    811691{
    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
     695void 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);
    876707}
    877708
    878709void InjectedBundle::setMockGeolocationPositionUnavailableError(WKStringRef errorMessage)
    879710{
    880     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetMockGeolocationPositionUnavailableError"));
    881     WKBundlePagePostMessage(page()->page(), messageName.get(), errorMessage);
     711    postPageMessage("SetMockGeolocationPositionUnavailableError", errorMessage);
    882712}
    883713
    884714bool InjectedBundle::isGeolocationProviderActive() const
    885715{
    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());
    892719}
    893720
    894721unsigned InjectedBundle::imageCountInGeneralPasteboard() const
    895722{
    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());
    902726}
    903727
    904728void InjectedBundle::setUserMediaPermission(bool enabled)
    905729{
    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)));
    909731}
    910732
    911733void InjectedBundle::resetUserMediaPermission()
    912734{
    913     auto messageName = adoptWK(WKStringCreateWithUTF8CString("ResetUserMediaPermission"));
    914     WKBundlePagePostMessage(page()->page(), messageName.get(), 0);
     735    postPageMessage("ResetUserMediaPermission");
    915736}
    916737
    917738void InjectedBundle::setUserMediaPersistentPermissionForOrigin(bool permission, WKStringRef origin, WKStringRef parentOrigin)
    918739{
    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);
    933745}
    934746
    935747unsigned InjectedBundle::userMediaPermissionRequestCountForOrigin(WKStringRef origin, WKStringRef parentOrigin) const
    936748{
    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());
    951755}
    952756
    953757void InjectedBundle::resetUserMediaPermissionRequestCountForOrigin(WKStringRef origin, WKStringRef parentOrigin)
    954758{
    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);
    965763}
    966764
    967765void InjectedBundle::setCustomPolicyDelegate(bool enabled, bool permissive)
    968766{
    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);
    982771}
    983772
    984773void InjectedBundle::setHidden(bool hidden)
    985774{
    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);
    994778}
    995779
    996780void InjectedBundle::setCacheModel(int model)
    997781{
    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);
    1001783}
    1002784
     
    1006788        return false;
    1007789
    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);
    1012792
    1013793    // The IPC failed. This happens when swapping processes on navigation because the WebPageProxy unregisters itself
    1014794    // as a MessageReceiver from the old WebProcessProxy and register itself with the new WebProcessProxy instead.
    1015     if (!isEmpty)
     795    if (!result)
    1016796        return false;
    1017797
    1018     return !WKBooleanGetValue(isEmpty.get());
     798    auto isEmpty = booleanValue(adoptWK(result).get());
     799    return !isEmpty;
    1019800}
    1020801
    1021802void InjectedBundle::processWorkQueue()
    1022803{
    1023     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ProcessWorkQueue"));
    1024     WKBundlePagePostMessage(page()->page(), messageName.get(), 0);
     804    postPageMessage("ProcessWorkQueue");
    1025805}
    1026806
     
    1028808{
    1029809    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)));
    1034811}
    1035812
     
    1037814{
    1038815    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)));
    1043817}
    1044818
     
    1046820{
    1047821    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);
    1064827}
    1065828
     
    1067830{
    1068831    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);
    1088839}
    1089840
     
    1091842{
    1092843    m_useWorkQueue = true;
    1093 
    1094     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("QueueReload"));
    1095     WKBundlePagePostMessage(page()->page(), messageName.get(), 0);
     844    postPageMessage("QueueReload");
    1096845}
    1097846
     
    1099848{
    1100849    m_useWorkQueue = true;
    1101 
    1102     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("QueueLoadingScript"));
    1103     WKBundlePagePostMessage(page()->page(), messageName.get(), script);
     850    postPageMessage("QueueLoadingScript", script);
    1104851}
    1105852
     
    1107854{
    1108855    m_useWorkQueue = true;
    1109 
    1110     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("QueueNonLoadingScript"));
    1111     WKBundlePagePostMessage(page()->page(), messageName.get(), script);
     856    postPageMessage("QueueNonLoadingScript", script);
    1112857}
    1113858
     
    1144889}
    1145890
     891void postMessage(const char* name)
     892{
     893    postMessage(name, WKRetainPtr<WKTypeRef> { });
     894}
     895
     896void postMessage(const char* name, bool value)
     897{
     898    postMessage(name, adoptWK(WKBooleanCreate(value)));
     899}
     900
     901void postMessage(const char* name, unsigned value)
     902{
     903    postMessage(name, adoptWK(WKUInt64Create(value)));
     904}
     905
     906void postMessage(const char* name, JSStringRef value)
     907{
     908    postMessage(name, toWK(value));
     909}
     910
     911void postSynchronousMessage(const char* name)
     912{
     913    postSynchronousMessage(name, WKRetainPtr<WKTypeRef> { });
     914}
     915
     916void postSynchronousMessage(const char* name, bool value)
     917{
     918    postSynchronousMessage(name, adoptWK(WKBooleanCreate(value)));
     919}
     920
     921void postSynchronousMessage(const char* name, uint64_t value)
     922{
     923    postSynchronousMessage(name, adoptWK(WKUInt64Create(value)));
     924}
     925
     926void postSynchronousMessage(const char* name, unsigned value)
     927{
     928    uint64_t promotedValue = value;
     929    postSynchronousMessage(name, promotedValue);
     930}
     931
     932void postSynchronousMessage(const char* name, double value)
     933{
     934    postSynchronousMessage(name, adoptWK(WKDoubleCreate(value)));
     935}
     936
     937void postPageMessage(const char* name)
     938{
     939    postPageMessage(name, WKRetainPtr<WKTypeRef> { });
     940}
     941
     942void postPageMessage(const char* name, bool value)
     943{
     944    postPageMessage(name, adoptWK(WKBooleanCreate(value)));
     945}
     946
     947void postPageMessage(const char* name, const char* value)
     948{
     949    postPageMessage(name, toWK(value));
     950}
     951
     952void postPageMessage(const char* name, WKStringRef value)
     953{
     954    if (auto page = InjectedBundle::singleton().pageRef())
     955        WKBundlePagePostMessage(page, toWK(name).get(), value);
     956}
     957
     958void postSynchronousPageMessage(const char* name)
     959{
     960    postSynchronousPageMessage(name, WKRetainPtr<WKTypeRef> { });
     961}
     962
     963void postSynchronousPageMessage(const char* name, bool value)
     964{
     965    postSynchronousPageMessage(name, adoptWK(WKBooleanCreate(value)));
     966}
     967
    1146968} // namespace WTR
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h

    r258075 r267761  
    11/*
    2  * Copyright (C) 2010-2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    6464
    6565    InjectedBundlePage* page() const;
     66    WKBundlePageRef pageRef() const;
    6667    size_t pageCount() const { return m_pages.size(); }
    6768    void closeOtherPages();
     
    9798    // Geolocation.
    9899    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, double floorLevel);
     100    void setMockGeolocationPosition(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitudeAccuracy, Optional<double> heading, Optional<double> speed, Optional<double> floorLevel);
    100101    void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage);
    101102    bool isGeolocationProviderActive() const;
     
    165166
    166167    void platformInitialize(WKTypeRef initializationUserData);
    167     void resetLocalSettings();
    168168
    169169    enum class BegingTestingMode { New, Resume };
    170170    void beginTesting(WKDictionaryRef initialSettings, BegingTestingMode);
    171 
    172     bool booleanForKey(WKDictionaryRef, const char* key);
    173     String stringForKey(WKDictionaryRef, const char* key);
    174171
    175172    WKBundleRef m_bundle { nullptr };
     
    211208};
    212209
     210void postMessage(const char* name);
     211void postMessage(const char* name, bool value);
     212void postMessage(const char* name, int value);
     213void postMessage(const char* name, unsigned value);
     214void postMessage(const char* name, uint64_t value);
     215void postMessage(const char* name, const char* value);
     216void postMessage(const char* name, JSStringRef value);
     217void postMessage(const char* name, const void* value) = delete;
     218
     219void postSynchronousMessage(const char* name);
     220void postSynchronousMessage(const char* name, bool value);
     221void postSynchronousMessage(const char* name, int value);
     222void postSynchronousMessage(const char* name, unsigned value);
     223void postSynchronousMessage(const char* name, uint64_t value);
     224void postSynchronousMessage(const char* name, double value);
     225void postSynchronousMessage(const char* name, const char* value);
     226void postSynchronousMessage(const char* name, const void* value) = delete;
     227
     228void postPageMessage(const char* name);
     229void postPageMessage(const char* name, bool value);
     230void postPageMessage(const char* name, const char* value);
     231void postPageMessage(const char* name, WKStringRef value);
     232void postPageMessage(const char* name, const void* value) = delete;
     233
     234void postSynchronousPageMessage(const char* name);
     235void postSynchronousPageMessage(const char* name, bool value);
     236void postSynchronousPageMessage(const char* name, const char* value);
     237void postSynchronousPageMessage(const char* name, const void* value) = delete;
     238
     239template<typename T> void postMessage(const char* name, const WKRetainPtr<T>& value)
     240{
     241    WKBundlePostMessage(InjectedBundle::singleton().bundle(), toWK(name).get(), value.get());
     242}
     243
     244template<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
     249template<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
     255template<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
    213261} // namespace WTR
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp

    r267640 r267761  
    6161namespace WTR {
    6262
    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);
     63static double numericWindowProperty(WKBundleFrameRef frame, const char* name)
     64{
     65    auto context = WKBundleFrameGetJavaScriptContext(frame);
     66    return numericProperty(context, JSContextGetGlobalObject(context), name);
    8867}
    8968
    9069static WTF::String dumpPath(JSGlobalContextRef context, JSObjectRef nodeValue)
    9170{
    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;
    10775}
    10876
     
    12795        return "(null)";
    12896
    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);
    133100    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    );
    157112}
    158113
     
    161116    switch (type) {
    162117    case kWKFrameNavigationTypeLinkClicked:
    163         return adoptWK(WKStringCreateWithUTF8CString("link clicked"));
     118        return toWK("link clicked");
    164119    case kWKFrameNavigationTypeFormSubmitted:
    165         return adoptWK(WKStringCreateWithUTF8CString("form submitted"));
     120        return toWK("form submitted");
    166121    case kWKFrameNavigationTypeBackForward:
    167         return adoptWK(WKStringCreateWithUTF8CString("back/forward"));
     122        return toWK("back/forward");
    168123    case kWKFrameNavigationTypeReload:
    169         return adoptWK(WKStringCreateWithUTF8CString("reload"));
     124        return toWK("reload");
    170125    case kWKFrameNavigationTypeFormResubmitted:
    171         return adoptWK(WKStringCreateWithUTF8CString("form resubmitted"));
     126        return toWK("form resubmitted");
    172127    case kWKFrameNavigationTypeOther:
    173         return adoptWK(WKStringCreateWithUTF8CString("other"));
    174     }
    175     return adoptWK(WKStringCreateWithUTF8CString("illegal value"));
     128        return toWK("other");
     129    }
     130    return toWK("illegal value");
    176131}
    177132
     
    186141}
    187142
    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();
     143static WTF::String string(WKSecurityOriginRef origin)
     144{
     145    return makeString('{', toWTFString(adoptWK(WKSecurityOriginCopyProtocol(origin))), ", ", toWTFString(adoptWK(WKSecurityOriginCopyHost(origin))), ", ", WKSecurityOriginGetPort(origin), '}');
    200146}
    201147
    202148static WTF::String frameToStr(WKBundleFrameRef frame)
    203149{
    204     WKRetainPtr<WKStringRef> name = adoptWK(WKBundleFrameCopyName(frame));
     150    auto name = adoptWK(WKBundleFrameCopyName(frame));
    205151    StringBuilder stringBuilder;
    206152    if (WKBundleFrameIsMainFrame(frame)) {
     
    236182        return "(null)";
    237183
    238     WKRetainPtr<WKStringRef> schemeString = adoptWK(WKURLCopyScheme(fileUrl));
     184    auto schemeString = adoptWK(WKURLCopyScheme(fileUrl));
    239185    if (!isLocalFileScheme(schemeString.get()))
    240186        return toWTFString(adoptWK(WKURLCopyString(fileUrl)));
    241187
    242188    WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
    243     WKRetainPtr<WKURLRef> mainFrameURL = adoptWK(WKBundleFrameCopyURL(mainFrame));
     189    auto mainFrameURL = adoptWK(WKBundleFrameCopyURL(mainFrame));
    244190    if (!mainFrameURL)
    245191        mainFrameURL = adoptWK(WKBundleFrameCopyProvisionalURL(mainFrame));
     
    435381    WKBundleFrameFocus(frame);
    436382
    437     JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame);
    438     WebCoreTestSupport::resetInternalsObject(context);
     383    WebCoreTestSupport::resetInternalsObject(WKBundleFrameGetJavaScriptContext(frame));
    439384    assignedUrlsCache().clear();
    440385
     
    452397static void dumpFrameDescriptionSuitableForTestResult(WKBundleFrameRef frame, StringBuilder& stringBuilder)
    453398{
    454     WKRetainPtr<WKStringRef> name = adoptWK(WKBundleFrameCopyName(frame));
     399    auto name = adoptWK(WKBundleFrameCopyName(frame));
    455400    if (WKBundleFrameIsMainFrame(frame)) {
    456401        if (WKStringIsEmpty(name.get())) {
     
    487432static inline void dumpRequestDescriptionSuitableForTestResult(WKURLRequestRef request, StringBuilder& stringBuilder)
    488433{
    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 ");
    499439    if (WKStringIsEmpty(httpMethod.get()))
    500440        stringBuilder.appendLiteral("(none)");
    501441    else
    502442        stringBuilder.append(toWTFString(httpMethod));
    503 
    504443    stringBuilder.append('>');
    505444}
     
    507446static inline void dumpResponseDescriptionSuitableForTestResult(WKURLResponseRef response, StringBuilder& stringBuilder, bool shouldDumpResponseHeaders = false)
    508447{
    509     WKRetainPtr<WKURLRef> url = adoptWK(WKURLResponseCopyURL(response));
     448    auto url = adoptWK(WKURLResponseCopyURL(response));
    510449    if (!url) {
    511450        stringBuilder.appendLiteral("(null)");
     
    536475static inline void dumpErrorDescriptionSuitableForTestResult(WKErrorRef error, StringBuilder& stringBuilder)
    537476{
    538     WKRetainPtr<WKStringRef> errorDomain = adoptWK(WKErrorCopyDomain(error));
    539     int errorCode = WKErrorGetErrorCode(error);
     477    auto errorDomain = toWTFString(adoptWK(WKErrorCopyDomain(error)));
     478    auto errorCode = WKErrorGetErrorCode(error);
    540479
    541480    // 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";
    544483        errorCode = -999;
    545484    }
    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()))), '"');
    563491    stringBuilder.append('>');
    564492}
     
    696624
    697625    if (!injectedBundle.testRunner()->testURL()) {
    698         WKRetainPtr<WKURLRef> testURL = adoptWK(WKBundleFrameCopyProvisionalURL(frame));
     626        auto testURL = adoptWK(WKBundleFrameCopyProvisionalURL(frame));
    699627        injectedBundle.testRunner()->setTestURL(testURL.get());
    700628    }
     
    775703static void dumpFrameScrollPosition(WKBundleFrameRef frame, StringBuilder& stringBuilder, FrameNamePolicy shouldIncludeFrameName = ShouldNotIncludeFrameName)
    776704{
    777     double x = numericWindowPropertyValue(frame, "pageXOffset");
    778     double y = numericWindowPropertyValue(frame, "pageYOffset");
     705    double x = numericWindowProperty(frame, "pageXOffset");
     706    double y = numericWindowProperty(frame, "pageYOffset");
    779707    if (fabs(x) <= 0.00000001 && fabs(y) <= 0.00000001)
    780708        return;
    781709
    782710    if (shouldIncludeFrameName) {
    783         WKRetainPtr<WKStringRef> name = adoptWK(WKBundleFrameCopyName(frame));
     711        auto name = adoptWK(WKBundleFrameCopyName(frame));
    784712        stringBuilder.appendLiteral("frame '");
    785713        stringBuilder.append(toWTFString(name));
     
    795723static void dumpDescendantFrameScrollPositions(WKBundleFrameRef frame, StringBuilder& stringBuilder)
    796724{
    797     WKRetainPtr<WKArrayRef> childFrames = adoptWK(WKBundleFrameCopyChildFrames(frame));
     725    auto childFrames = adoptWK(WKBundleFrameCopyChildFrames(frame));
    798726    size_t size = WKArrayGetSize(childFrames.get());
    799727    for (size_t i = 0; i < size; ++i) {
     
    811739}
    812740
    813 static JSRetainPtr<JSStringRef> toJS(const char* string)
    814 {
    815     return adopt(JSStringCreateWithUTF8CString(string));
    816 }
    817 
    818741static bool hasDocumentElement(WKBundleFrameRef frame)
    819742{
    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" });
    835745}
    836746
     
    855765static void dumpDescendantFramesText(WKBundleFrameRef frame, StringBuilder& stringBuilder)
    856766{
    857     WKRetainPtr<WKArrayRef> childFrames = adoptWK(WKBundleFrameCopyChildFrames(frame));
     767    auto childFrames = adoptWK(WKBundleFrameCopyChildFrames(frame));
    858768    size_t size = WKArrayGetSize(childFrames.get());
    859769    for (size_t i = 0; i < size; ++i) {
    860770        WKBundleFrameRef subframe = static_cast<WKBundleFrameRef>(WKArrayGetItemAtIndex(childFrames.get(), i));
    861         WKRetainPtr<WKStringRef> subframeName = adoptWK(WKBundleFrameCopyName(subframe));
     771        auto subframeName = adoptWK(WKBundleFrameCopyName(subframe));
    862772
    863773        // DumpRenderTree ignores empty frames, so do the same thing here.
     
    885795{
    886796#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()));
    890800    stringBuilder.append(cfString.get());
    891801#endif
     
    903813
    904814    WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page);
    905     WKRetainPtr<WKURLRef> urlRef = adoptWK(WKBundleFrameCopyURL(frame));
     815    auto urlRef = adoptWK(WKBundleFrameCopyURL(frame));
    906816    String url = toWTFString(adoptWK(WKURLCopyString(urlRef.get())));
    907     WKRetainPtr<WKStringRef> mimeType = adoptWK(WKBundleFrameCopyMIMETypeForResourceWithURL(frame, urlRef.get()));
     817    auto mimeType = adoptWK(WKBundleFrameCopyMIMETypeForResourceWithURL(frame, urlRef.get()));
    908818    if (url.find("dumpAsText/") != notFound || WKStringIsEqualToUTF8CString(mimeType.get(), "text/plain"))
    909819        injectedBundle.testRunner()->dumpAsText(false);
     
    1019929        return;
    1020930
    1021     JSGlobalContextRef context = WKBundleFrameGetJavaScriptContextForWorld(frame, world);
    1022     JSObjectRef window = JSContextGetGlobalObject(context);
     931    auto context = WKBundleFrameGetJavaScriptContextForWorld(frame, world);
    1023932
    1024933    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);
    1034942#if HAVE(ACCESSIBILITY)
    1035     injectedBundle.accessibilityController()->makeWindowObject(context, window, &exception);
     943    injectedBundle.accessibilityController()->makeWindowObject(context);
    1036944#endif
    1037945
     
    11371045        return;
    11381046
    1139     WKRetainPtr<WKURLRef> url = adoptWK(WKURLRequestCopyURL(request));
     1047    auto url = adoptWK(WKURLRequestCopyURL(request));
    11401048    assignedUrlsCache().add(identifier, pathSuitableForTestResult(url.get()));
    11411049}
     
    11761084        return nullptr;
    11771085
    1178     WKRetainPtr<WKURLRef> redirectURL = adoptWK(WKURLResponseCopyURL(response));
     1086    auto redirectURL = adoptWK(WKURLResponseCopyURL(response));
    11791087    if (injectedBundle.isTestRunning() && injectedBundle.testRunner()->willSendRequestReturnsNullOnRedirect() && redirectURL) {
    11801088        injectedBundle.outputText("Returning null for this redirect\n");
     
    11821090    }
    11831091
    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()));
    11881096    if (host && !WKStringIsEmpty(host.get())
    11891097        && isHTTPOrHTTPSScheme(scheme.get())
     
    11931101        if (injectedBundle.isTestRunning()) {
    11941102            WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(m_page);
    1195             WKRetainPtr<WKURLRef> mainFrameURL = adoptWK(WKBundleFrameCopyURL(mainFrame));
     1103            auto mainFrameURL = adoptWK(WKBundleFrameCopyURL(mainFrame));
    11961104            if (!mainFrameURL || WKStringIsEqualToUTF8CString(adoptWK(WKURLCopyString(mainFrameURL.get())).get(), "about:blank"))
    11971105                mainFrameURL = adoptWK(WKBundleFrameCopyProvisionalURL(mainFrame));
    11981106
    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()));
    12011109            mainFrameIsExternal = isHTTPOrHTTPSScheme(mainFrameScheme.get()) && !isLocalHost(mainFrameHost.get());
    12021110        }
     
    12151123        if (!body.isEmpty()) {
    12161124            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()));
    12181126            return WKURLRequestCopySettingHTTPBody(request, body.get());
    12191127        }
     
    12431151        return;
    12441152
    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));
    12481156
    12491157    StringBuilder stringBuilder;
     
    13511259        stringBuilder.appendLiteral(" - decidePolicyForNavigationAction\n");
    13521260        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");
    13571263        stringBuilder.append('\n');
    13581264        injectedBundle.outputText(stringBuilder.toString());
     
    13621268        return WKBundlePagePolicyActionPassThrough;
    13631269
    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()));
    13661272
    13671273    StringBuilder stringBuilder;
    13681274    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()))));
    13761279    stringBuilder.appendLiteral(" with navigation type \'");
    13771280    stringBuilder.append(toWTFString(NavigationTypeToString(WKBundleNavigationActionGetNavigationType(navigationAction))));
    13781281    stringBuilder.appendLiteral("\'");
    1379     WKRetainPtr<WKBundleHitTestResultRef> hitTestResultRef = adoptWK(WKBundleNavigationActionCopyHitTestResult(navigationAction));
     1282    auto hitTestResultRef = adoptWK(WKBundleNavigationActionCopyHitTestResult(navigationAction));
    13801283    if (hitTestResultRef) {
    1381         WKRetainPtr<WKBundleNodeHandleRef> nodeHandleRef = adoptWK(WKBundleHitTestResultCopyNodeHandle(hitTestResultRef.get()));
     1284        auto nodeHandleRef = adoptWK(WKBundleHitTestResultCopyNodeHandle(hitTestResultRef.get()));
    13821285        stringBuilder.appendLiteral(" originating from ");
    13831286        stringBuilder.append(dumpPath(m_page, m_world.get(), nodeHandleRef.get()));
     
    14011304    auto& injectedBundle = InjectedBundle::singleton();
    14021305    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"));
    14091307    }
    14101308
     
    14721370static WTF::String lastFileURLPathComponent(const WTF::String& path)
    14731371{
    1474     size_t pos = path.find("file://");
     1372    auto pos = path.find("file://");
    14751373    ASSERT(WTF::notFound != pos);
    14761374
    1477     WTF::String tmpPath = path.substring(pos + 7);
     1375    auto tmpPath = path.substring(pos + 7);
    14781376    if (tmpPath.length() < 2) // Keep the lone slash to avoid empty output.
    14791377        return tmpPath;
     
    15221420        return;
    15231421
    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'));
    15291423}
    15301424
     
    15601454        // sufficient to just get a range of 10000 to determine if we were
    15611455        // 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'));
    15711458    }
    15721459
     
    15811468{
    15821469    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'));
    15921472
    15931473    uint64_t defaultQuota = 5 * 1024 * 1024;
     
    16021482        if (defaultQuota < expectedUsageBytes && expectedUsageBytes <= maxQuota) {
    16031483            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'));
    16101485        }
    16111486    }
     
    16761551        return true;
    16771552
    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'));
    16851555    return injectedBundle.testRunner()->shouldAllowEditing();
    16861556}
     
    16921562        return true;
    16931563
    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'));
    17011566    return injectedBundle.testRunner()->shouldAllowEditing();
    17021567}
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp

    r267750 r267761  
    11/*
    2  * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727#include "TestRunner.h"
    2828
     29#include "DictionaryFunctions.h"
    2930#include "InjectedBundle.h"
    3031#include "InjectedBundlePage.h"
    3132#include "JSTestRunner.h"
    3233#include "PlatformWebView.h"
    33 #include "StringFunctions.h"
    3434#include "TestController.h"
    3535#include <JavaScriptCore/JSCTestRunnerUtils.h>
     
    7070
    7171TestRunner::TestRunner()
    72     : m_userStyleSheetLocation(adoptWK(WKStringCreateWithUTF8CString("")))
     72    : m_userStyleSheetLocation(toWK(""))
    7373{
    7474    platformInitialize();
     
    8484}
    8585
     86static WKBundlePageRef page()
     87{
     88    return InjectedBundle::singleton().page()->page();
     89}
     90
     91static WKBundleFrameRef mainFrame()
     92{
     93    return WKBundlePageGetMainFrame(page());
     94}
     95
     96static JSContextRef mainFrameJSContext()
     97{
     98    return WKBundleFrameGetJavaScriptContext(mainFrame());
     99}
     100
    86101void TestRunner::display()
    87102{
    88     WKBundlePageRef page = InjectedBundle::singleton().page()->page();
    89     WKBundlePageForceRepaint(page);
     103    WKBundlePageForceRepaint(page());
    90104}
    91105
    92106void TestRunner::displayAndTrackRepaints()
    93107{
    94     WKBundlePageRef page = InjectedBundle::singleton().page()->page();
     108    auto page = WTR::page();
    95109    WKBundlePageForceRepaint(page);
    96110    WKBundlePageSetTracksRepaints(page, true);
     
    98112}
    99113
     114static WKRetainPtr<WKDoubleRef> toWK(double value)
     115{
     116    return adoptWK(WKDoubleCreate(value));
     117}
     118
     119static 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
     133template<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
     140template<typename T> static bool postSynchronousMessageReturningBoolean(const char* name, const WKRetainPtr<T>& value)
     141{
     142    return booleanValue(postSynchronousMessageWithReturnValue(name, value));
     143}
     144
     145static bool postSynchronousMessageReturningBoolean(const char* name)
     146{
     147    return postSynchronousMessageReturningBoolean(name, WKRetainPtr<WKTypeRef> { });
     148}
     149
     150template<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
     157template<typename T> static bool postSynchronousPageMessageReturningBoolean(const char* name, const WKRetainPtr<T>& value)
     158{
     159    return booleanValue(postSynchronousPageMessageWithReturnValue(name, value));
     160}
     161
     162static bool postSynchronousPageMessageReturningBoolean(const char* name)
     163{
     164    return postSynchronousPageMessageReturningBoolean(name, WKRetainPtr<WKTypeRef> { });
     165}
     166
     167static bool postSynchronousPageMessageReturningBoolean(const char* name, JSStringRef string)
     168{
     169    return postSynchronousPageMessageReturningBoolean(name, toWK(string));
     170}
     171
     172template<typename T> static uint64_t postSynchronousPageMessageReturningUInt64(const char* name, const WKRetainPtr<T>& value)
     173{
     174    return uint64Value(postSynchronousPageMessageWithReturnValue(name, value));
     175}
     176
     177static uint64_t postSynchronousMessageReturningUInt64(const char* name)
     178{
     179    return uint64Value(postSynchronousMessageWithReturnValue(name, WKRetainPtr<WKTypeRef> { }));
     180}
     181
     182static bool postSynchronousPageMessageReturningUInt64(const char* name, JSStringRef string)
     183{
     184    return postSynchronousPageMessageReturningUInt64(name, toWK(string));
     185}
     186
     187static 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
    100193bool TestRunner::shouldDumpPixels() const
    101194{
    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");
    107196}
    108197
    109198void TestRunner::setDumpPixels(bool dumpPixels)
    110199{
    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);
    114201}
    115202
     
    123210WhatToDump TestRunner::whatToDump() const
    124211{
    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"));
    130213}
    131214
    132215void TestRunner::setWhatToDump(WhatToDump whatToDump)
    133216{
    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));
    137218}
    138219
     
    159240void TestRunner::waitUntilDone()
    160241{
    161     auto& injectedBundle = InjectedBundle::singleton();
    162     RELEASE_ASSERT(injectedBundle.isTestRunning());
     242    RELEASE_ASSERT(InjectedBundle::singleton().isTestRunning());
    163243
    164244    setWaitUntilDone(true);
     
    167247void TestRunner::setWaitUntilDone(bool value)
    168248{
    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);
    172250}
    173251
    174252bool TestRunner::shouldWaitUntilDone() const
    175253{
    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");
    181255}
    182256
     
    211285void TestRunner::setShouldDumpFrameLoadCallbacks(bool value)
    212286{
    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);
    216288}
    217289
    218290bool TestRunner::shouldDumpFrameLoadCallbacks()
    219291{
    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");
    225293}
    226294
     
    232300void TestRunner::addUserScript(JSStringRef source, bool runAtStart, bool allFrames)
    233301{
    234     WKRetainPtr<WKStringRef> sourceWK = toWK(source);
    235 
    236     WKBundlePageAddUserScript(InjectedBundle::singleton().page()->page(), sourceWK.get(),
     302    WKBundlePageAddUserScript(page(), toWK(source).get(),
    237303        (runAtStart ? kWKInjectAtDocumentStart : kWKInjectAtDocumentEnd),
    238304        (allFrames ? kWKInjectInAllFrames : kWKInjectInTopFrameOnly));
     
    241307void TestRunner::addUserStyleSheet(JSStringRef source, bool allFrames)
    242308{
    243     WKRetainPtr<WKStringRef> sourceWK = toWK(source);
    244 
    245     WKBundlePageAddUserStyleSheet(InjectedBundle::singleton().page()->page(), sourceWK.get(),
     309    WKBundlePageAddUserStyleSheet(page(), toWK(source).get(),
    246310        (allFrames ? kWKInjectInAllFrames : kWKInjectInTopFrameOnly));
    247311}
     
    254318void TestRunner::execCommand(JSStringRef name, JSStringRef showUI, JSStringRef value)
    255319{
    256     WKBundlePageExecuteEditingCommand(InjectedBundle::singleton().page()->page(), toWK(name).get(), toWK(value).get());
     320    WKBundlePageExecuteEditingCommand(page(), toWK(name).get(), toWK(value).get());
    257321}
    258322
    259323static Optional<WKFindOptions> findOptionsFromArray(JSValueRef optionsArrayAsValue)
    260324{
    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);
    270328    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));
    279331        if (JSStringIsEqualToUTF8CString(optionName.get(), "CaseInsensitive"))
    280332            options |= kWKFindOptionsCaseInsensitive;
     
    297349{
    298350    if (auto options = findOptionsFromArray(optionsArrayAsValue))
    299         return WKBundlePageFindString(InjectedBundle::singleton().page()->page(), toWK(target).get(), *options);
     351        return WKBundlePageFindString(page(), toWK(target).get(), *options);
    300352
    301353    return false;
     
    305357{
    306358    if (auto options = findOptionsFromArray(optionsArrayAsValue))
    307         return WKBundlePageFindStringMatches(InjectedBundle::singleton().page()->page(), toWK(target).get(), *options);
     359        WKBundlePageFindStringMatches(page(), toWK(target).get(), *options);
    308360}
    309361
     
    311363{
    312364    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();
    316366    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);
    320368
    321369    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);
    325372        if (!JSValueIsNumber(context, value))
    326373            continue;
    327374
    328         auto index = adoptWK(WKUInt64Create(std::round(JSValueToNumber(context, value, nullptr))));
     375        auto index = adoptWK(WKUInt64Create(JSValueToNumber(context, value, nullptr)));
    329376        WKArrayAppendItem(indices.get(), index.get());
    330377    }
     
    335382{
    336383    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);
    342385}
    343386
     
    349392void TestRunner::syncLocalStorage()
    350393{
    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);
    354395}
    355396
    356397void TestRunner::clearAllApplicationCaches()
    357398{
    358     WKBundlePageClearApplicationCache(InjectedBundle::singleton().page()->page());
     399    WKBundlePageClearApplicationCache(page());
    359400}
    360401
    361402void TestRunner::clearApplicationCacheForOrigin(JSStringRef origin)
    362403{
    363     WKBundlePageClearApplicationCacheForOrigin(InjectedBundle::singleton().page()->page(), toWK(origin).get());
     404    WKBundlePageClearApplicationCacheForOrigin(page(), toWK(origin).get());
    364405}
    365406
    366407void TestRunner::setAppCacheMaximumSize(uint64_t size)
    367408{
    368     WKBundlePageSetAppCacheMaximumSize(InjectedBundle::singleton().page()->page(), size);
     409    WKBundlePageSetAppCacheMaximumSize(page(), size);
    369410}
    370411
    371412long long TestRunner::applicationCacheDiskUsageForOrigin(JSStringRef origin)
    372413{
    373     return WKBundlePageGetAppCacheUsageForOrigin(InjectedBundle::singleton().page()->page(), toWK(origin).get());
     414    return WKBundlePageGetAppCacheUsageForOrigin(page(), toWK(origin).get());
    374415}
    375416
     
    382423{
    383424    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);
    387426    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);
    391429    }
    392 
    393     return arrayResult;
     430    return array;
    394431}
    395432
    396433JSValueRef TestRunner::originsWithApplicationCache()
    397434{
    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());
    406436}
    407437
    408438bool TestRunner::isCommandEnabled(JSStringRef name)
    409439{
    410     return WKBundlePageIsEditingCommandEnabled(InjectedBundle::singleton().page()->page(), toWK(name).get());
     440    return WKBundlePageIsEditingCommandEnabled(page(), toWK(name).get());
    411441}
    412442
    413443void TestRunner::setCanOpenWindows()
    414444{
    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);
    418446}
    419447
    420448void TestRunner::setXSSAuditorEnabled(bool enabled)
    421449{
    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);
    425451}
    426452
    427453void TestRunner::setMediaDevicesEnabled(bool enabled)
    428454{
    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);
    432456}
    433457
    434458void TestRunner::setWebRTCMDNSICECandidatesEnabled(bool enabled)
    435459{
    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);
    439461}
    440462
    441463void TestRunner::setCustomUserAgent(JSStringRef userAgent)
    442464{
    443     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetCustomUserAgent"));
    444     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), toWK(userAgent).get(), nullptr);
     465    postSynchronousMessage("SetCustomUserAgent", toWK(userAgent));
    445466}
    446467
    447468void TestRunner::setWebAPIStatisticsEnabled(bool enabled)
    448469{
    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);
    452471}
    453472
    454473void TestRunner::setModernMediaControlsEnabled(bool enabled)
    455474{
    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);
    459476}
    460477
    461478void TestRunner::setWebGL2Enabled(bool enabled)
    462479{
    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);
    466481}
    467482
    468483void TestRunner::setWritableStreamAPIEnabled(bool enabled)
    469484{
    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);
    473486}
    474487
    475488void TestRunner::setTransformStreamAPIEnabled(bool enabled)
    476489{
    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);
    480491}
    481492
    482493void TestRunner::setReadableByteStreamAPIEnabled(bool enabled)
    483494{
    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);
    487496}
    488497
    489498void TestRunner::setEncryptedMediaAPIEnabled(bool enabled)
    490499{
    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);
    494501}
    495502
    496503void TestRunner::setPictureInPictureAPIEnabled(bool enabled)
    497504{
    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);
    501506}
    502507
    503508void TestRunner::setGenericCueAPIEnabled(bool enabled)
    504509{
    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);
    508511}
    509512
    510513void TestRunner::setAllowsAnySSLCertificate(bool enabled)
    511514{
    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);
    518517}
    519518
    520519void TestRunner::setShouldSwapToEphemeralSessionOnNextNavigation(bool shouldSwap)
    521520{
    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);
    527522}
    528523
    529524void TestRunner::setShouldSwapToDefaultSessionOnNextNavigation(bool shouldSwap)
    530525{
    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);
    536527}
    537528
     
    556547void TestRunner::setPluginsEnabled(bool enabled)
    557548{
    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);
    561550}
    562551
     
    592581{
    593582    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);
    596584}
    597585
     
    601589        return;
    602590
    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());
    605592}
    606593
     
    609596    auto& injectedBundle = InjectedBundle::singleton();
    610597    // 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());
    613599    setWhatToDump(WhatToDump::Audio);
    614600    setDumpPixels(false);
     
    622608void TestRunner::clearBackForwardList()
    623609{
    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
     613void TestRunner::makeWindowObject(JSContextRef context)
     614{
     615    setGlobalObjectProperty(context, "testRunner", this);
    632616}
    633617
    634618void TestRunner::showWebInspector()
    635619{
    636     WKBundleInspectorShow(WKBundlePageGetInspector(InjectedBundle::singleton().page()->page()));
     620    WKBundleInspectorShow(WKBundlePageGetInspector(page()));
    637621}
    638622
    639623void TestRunner::closeWebInspector()
    640624{
    641     WKBundleInspectorClose(WKBundlePageGetInspector(InjectedBundle::singleton().page()->page()));
     625    WKBundleInspectorClose(WKBundlePageGetInspector(page()));
    642626}
    643627
    644628void TestRunner::evaluateInWebInspector(JSStringRef script)
    645629{
    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
     633using WorldMap = WTF::HashMap<unsigned, WKRetainPtr<WKBundleScriptWorldRef>>;
    651634static WorldMap& worldMap()
    652635{
     
    657640unsigned TestRunner::worldIDForWorld(WKBundleScriptWorldRef world)
    658641{
    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;
    663646    }
    664 
    665647    return 0;
    666648}
     
    682664    WKBundleFrameRef frame = WKBundleFrameForJavaScriptContext(context);
    683665    if (!frame)
    684         frame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
     666        frame = mainFrame();
    685667
    686668    JSGlobalContextRef jsContext = WKBundleFrameGetJavaScriptContextForWorld(frame, world.get());
     
    697679void TestRunner::setTextDirection(JSStringRef direction)
    698680{
    699     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
    700     return WKBundleFrameSetTextDirection(mainFrame, toWK(direction).get());
     681    return WKBundleFrameSetTextDirection(mainFrame(), toWK(direction).get());
    701682}
    702683   
     
    708689bool TestRunner::didReceiveServerRedirectForProvisionalNavigation() const
    709690{
    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");
    715692}
    716693
    717694void TestRunner::clearDidReceiveServerRedirectForProvisionalNavigation()
    718695{
    719     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ClearDidReceiveServerRedirectForProvisionalNavigation"));
    720     WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, nullptr);
     696    postSynchronousPageMessage("ClearDidReceiveServerRedirectForProvisionalNavigation");
    721697}
    722698
     
    731707}
    732708
    733 typedef WTF::HashMap<unsigned, JSValueRef> CallbackMap;
     709using CallbackMap = WTF::HashMap<unsigned, JSObjectRef>;
    734710static CallbackMap& callbackMap()
    735711{
     
    784760    if (!callback)
    785761        return;
    786 
     762    auto context = mainFrameJSContext();
     763    if (!JSValueIsObject(context, callback))
     764        return;
    787765    if (callbackMap().contains(index)) {
    788766        InjectedBundle::singleton().outputText(makeString("FAIL: Tried to install a second TestRunner callback for the same event (id ", index, ")\n\n"));
    789767        return;
    790768    }
    791 
    792     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
    793     JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
    794769    JSValueProtect(context, callback);
    795     callbackMap().add(index, callback);
     770    callbackMap().add(index, const_cast<JSObjectRef>(callback));
    796771}
    797772
    798773static void callTestRunnerCallback(unsigned index, size_t argumentCount = 0, const JSValueRef arguments[] = nullptr)
    799774{
    800     if (!callbackMap().contains(index))
     775    auto callback = callbackMap().take(index);
     776    if (!callback)
    801777        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();
    805779    JSObjectCallAsFunction(context, callback, JSContextGetGlobalObject(context), argumentCount, arguments, 0);
    806780    JSValueUnprotect(context, callback);
     
    809783void TestRunner::clearTestRunnerCallbacks()
    810784{
    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));
    818788    callbackMap().clear();
    819789}
     
    895865void TestRunner::setAlwaysAcceptCookies(bool accept)
    896866{
    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);
    902868}
    903869
    904870void TestRunner::setOnlyAcceptFirstPartyCookies(bool accept)
    905871{
    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);
    911873}
    912874
     
    925887    m_userStyleSheetEnabled = enabled;
    926888
    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();
    929891    auto& injectedBundle = InjectedBundle::singleton();
    930892    WKBundleSetUserStyleSheetLocation(injectedBundle.bundle(), injectedBundle.pageGroup(), location);
     
    933895void TestRunner::setUserStyleSheetLocation(JSStringRef location)
    934896{
    935     m_userStyleSheetLocation = adoptWK(WKStringCreateWithJSString(location));
     897    m_userStyleSheetLocation = toWK(location);
    936898
    937899    if (m_userStyleSheetEnabled)
     
    947909void TestRunner::setTabKeyCyclesThroughElements(bool enabled)
    948910{
    949     auto& injectedBundle = InjectedBundle::singleton();
    950     WKBundleSetTabKeyCyclesThroughElements(injectedBundle.bundle(), injectedBundle.page()->page(), enabled);
     911    WKBundleSetTabKeyCyclesThroughElements(InjectedBundle::singleton().bundle(), page(), enabled);
    951912}
    952913
     
    974935void TestRunner::grantWebNotificationPermission(JSStringRef origin)
    975936{
    976     WKRetainPtr<WKStringRef> originWK = toWK(origin);
     937    WKBundleSetWebNotificationPermission(InjectedBundle::singleton().bundle(), page(), toWK(origin).get(), true);
     938}
     939
     940void TestRunner::denyWebNotificationPermission(JSStringRef origin)
     941{
     942    WKBundleSetWebNotificationPermission(InjectedBundle::singleton().bundle(), page(), toWK(origin).get(), false);
     943}
     944
     945void TestRunner::removeAllWebNotificationPermissions()
     946{
     947    WKBundleRemoveAllWebNotificationPermissions(InjectedBundle::singleton().bundle(), page());
     948}
     949
     950void TestRunner::simulateWebNotificationClick(JSValueRef notification)
     951{
    977952    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
     956void TestRunner::setGeolocationPermission(bool enabled)
     957{
     958    // FIXME: This should be done by frame.
     959    InjectedBundle::singleton().setGeolocationPermission(enabled);
     960}
     961
     962bool TestRunner::isGeolocationProviderActive()
     963{
     964    return InjectedBundle::singleton().isGeolocationProviderActive();
     965}
     966
     967void 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
     972void TestRunner::setMockGeolocationPositionUnavailableError(JSStringRef message)
     973{
     974    InjectedBundle::singleton().setMockGeolocationPositionUnavailableError(toWK(message).get());
     975}
     976
     977void TestRunner::setUserMediaPermission(bool enabled)
     978{
     979    // FIXME: This should be done by frame.
     980    InjectedBundle::singleton().setUserMediaPermission(enabled);
     981}
     982
     983void TestRunner::resetUserMediaPermission()
     984{
     985    // FIXME: This should be done by frame.
     986    InjectedBundle::singleton().resetUserMediaPermission();
     987}
     988
     989bool TestRunner::isDoingMediaCapture() const
     990{
     991    return postSynchronousPageMessageReturningBoolean("IsDoingMediaCapture");
     992}
     993
     994void TestRunner::setUserMediaPersistentPermissionForOrigin(bool permission, JSStringRef origin, JSStringRef parentOrigin)
     995{
     996    InjectedBundle::singleton().setUserMediaPersistentPermissionForOrigin(permission, toWK(origin).get(), toWK(parentOrigin).get());
     997}
     998
     999unsigned TestRunner::userMediaPermissionRequestCountForOrigin(JSStringRef origin, JSStringRef parentOrigin) const
     1000{
     1001    return InjectedBundle::singleton().userMediaPermissionRequestCountForOrigin(toWK(origin).get(), toWK(parentOrigin).get());
     1002}
     1003
     1004void TestRunner::resetUserMediaPermissionRequestCountForOrigin(JSStringRef origin, JSStringRef parentOrigin)
     1005{
     1006    InjectedBundle::singleton().resetUserMediaPermissionRequestCountForOrigin(toWK(origin).get(), toWK(parentOrigin).get());
     1007}
     1008
     1009bool TestRunner::callShouldCloseOnWebView()
     1010{
     1011    return WKBundleFrameCallShouldCloseOnWebView(mainFrame());
     1012}
     1013
     1014void TestRunner::queueBackNavigation(unsigned howFarBackward)
     1015{
     1016    InjectedBundle::singleton().queueBackNavigation(howFarBackward);
     1017}
     1018
     1019void TestRunner::queueForwardNavigation(unsigned howFarForward)
     1020{
     1021    InjectedBundle::singleton().queueForwardNavigation(howFarForward);
     1022}
     1023
     1024void TestRunner::queueLoad(JSStringRef url, JSStringRef target, bool shouldOpenExternalURLs)
     1025{
    9841026    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()));
    11291030    injectedBundle.queueLoad(urlStringWK.get(), toWK(target).get(), shouldOpenExternalURLs);
    11301031}
     
    11321033void TestRunner::queueLoadHTMLString(JSStringRef content, JSStringRef baseURL, JSStringRef unreachableURL)
    11331034{
    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());
    11391038}
    11401039
     
    11461045void TestRunner::queueLoadingScript(JSStringRef script)
    11471046{
    1148     WKRetainPtr<WKStringRef> scriptWK = toWK(script);
    1149     InjectedBundle::singleton().queueLoadingScript(scriptWK.get());
     1047    InjectedBundle::singleton().queueLoadingScript(toWK(script).get());
    11501048}
    11511049
    11521050void TestRunner::queueNonLoadingScript(JSStringRef script)
    11531051{
    1154     WKRetainPtr<WKStringRef> scriptWK = toWK(script);
    1155     InjectedBundle::singleton().queueNonLoadingScript(scriptWK.get());
     1052    InjectedBundle::singleton().queueNonLoadingScript(toWK(script).get());
    11561053}
    11571054
    11581055void TestRunner::setRejectsProtectionSpaceAndContinueForAuthenticationChallenges(bool value)
    11591056{
    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);
    11631058}
    11641059   
    11651060void TestRunner::setHandlesAuthenticationChallenges(bool handlesAuthenticationChallenges)
    11661061{
    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);
    11701063}
    11711064
    11721065void TestRunner::setShouldLogCanAuthenticateAgainstProtectionSpace(bool value)
    11731066{
    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);
    11771068}
    11781069
    11791070void TestRunner::setShouldLogDownloadCallbacks(bool value)
    11801071{
    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);
    11841073}
    11851074
    11861075void TestRunner::setAuthenticationUsername(JSStringRef username)
    11871076{
    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));
    11911078}
    11921079
    11931080void TestRunner::setAuthenticationPassword(JSStringRef password)
    11941081{
    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));
    11981083}
    11991084
    12001085bool TestRunner::secureEventInputIsEnabled() const
    12011086{
    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");
    12071088}
    12081089
    12091090void TestRunner::setBlockAllPlugins(bool shouldBlock)
    12101091{
    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);
    12141093}
    12151094
    12161095void TestRunner::setPluginSupportedMode(JSStringRef mode)
    12171096{
    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));
    12211098}
    12221099
    12231100JSValueRef TestRunner::failNextNewCodeBlock()
    12241101{
    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
     1105JSValueRef TestRunner::numberOfDFGCompiles(JSValueRef function)
     1106{
     1107    return JSC::numberOfDFGCompiles(mainFrameJSContext(), function);
     1108}
     1109
     1110JSValueRef TestRunner::neverInlineFunction(JSValueRef function)
     1111{
     1112    return JSC::setNeverInline(mainFrameJSContext(), function);
    12421113}
    12431114
     
    12451116{
    12461117    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);
    12501119}
    12511120
     
    12531122{
    12541123    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);
    12581125}
    12591126
    12601127void TestRunner::setNavigationGesturesEnabled(bool value)
    12611128{
    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);
    12651130}
    12661131
    12671132void TestRunner::setIgnoresViewportScaleLimits(bool value)
    12681133{
    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);
    12721135}
    12731136
    12741137void TestRunner::setShouldDownloadUndisplayableMIMETypes(bool value)
    12751138{
    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);
    12791140}
    12801141
    12811142void TestRunner::setShouldAllowDeviceOrientationAndMotionAccess(bool value)
    12821143{
    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);
    12861145}
    12871146
    12881147void TestRunner::terminateNetworkProcess()
    12891148{
    1290     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("TerminateNetworkProcess"));
    1291     WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, nullptr);
     1149    postSynchronousPageMessage("TerminateNetworkProcess");
    12921150}
    12931151
    12941152void TestRunner::terminateServiceWorkers()
    12951153{
    1296     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("TerminateServiceWorkers"));
    1297     WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, nullptr);
     1154    postSynchronousPageMessage("TerminateServiceWorkers");
    12981155}
    12991156
    13001157void TestRunner::setUseSeparateServiceWorkerProcess(bool value)
    13011158{
    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);
    13051160}
    13061161
     
    13151170    unsigned callbackID = nextUIScriptCallbackID();
    13161171    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    }));
    13321176}
    13331177
     
    13361180    unsigned callbackID = nextUIScriptCallbackID();
    13371181    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    }));
    13531186}
    13541187
    13551188void TestRunner::runUIScriptCallback(unsigned callbackID, JSStringRef result)
    13561189{
    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);
    13611191    callTestRunnerCallback(callbackID, 1, &resultValue);
    13621192}
     
    13641194void TestRunner::setAllowedMenuActions(JSValueRef actions)
    13651195{
    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();
    13731198    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());
    13871203    }
    1388 
    1389     WKBundlePagePostMessage(page, messageName.get(), messageBody.get());
     1204    postPageMessage("SetAllowedMenuActions", messageBody);
    13901205}
    13911206
     
    13931208{
    13941209    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    }));
    14081214}
    14091215
     
    14501256void TestRunner::clearStatisticsDataForDomain(JSStringRef domain)
    14511257{
    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));
    14551259}
    14561260
    14571261bool TestRunner::doesStatisticsDomainIDExistInDatabase(unsigned domainID)
    14581262{
    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    }));
    14791266}
    14801267
    14811268void TestRunner::setStatisticsEnabled(bool value)
    14821269{
    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);
    14861271}
    14871272
    14881273bool TestRunner::isStatisticsEphemeral()
    14891274{
    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");
    14951276}
    14961277
     
    14981279{
    14991280    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);
    15041282}
    15051283
     
    15121290{
    15131291    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);
    15181293}
    15191294
     
    15271302    cacheTestRunnerCallback(SetStatisticsLastSeenCallbackID, completionHandler);
    15281303
    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    }));
    15501308}
    15511309
     
    15591317    cacheTestRunnerCallback(SetStatisticsMergeStatisticCallbackID, completionHandler);
    15601318
    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    }));
    16041331}
    16051332
     
    16131340    cacheTestRunnerCallback(SetStatisticsExpiredStatisticCallbackID, completionHandler);
    16141341
    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    }));
    16401348}
    16411349
     
    16491357    cacheTestRunnerCallback(SetStatisticsPrevalentResourceCallbackID, completionHandler);
    16501358
    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    }));
    16741363}
    16751364
     
    16831372    cacheTestRunnerCallback(SetStatisticsVeryPrevalentResourceCallbackID, completionHandler);
    16841373
    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    }));
    17081378}
    17091379
     
    17151385void TestRunner::dumpResourceLoadStatistics()
    17161386{
    1717     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("dumpResourceLoadStatistics"));
    1718     WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, nullptr);
     1387    postSynchronousPageMessage("dumpResourceLoadStatistics");
    17191388}
    17201389
    17211390bool TestRunner::isStatisticsPrevalentResource(JSStringRef hostName)
    17221391{
    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);
    17291393}
    17301394
    17311395bool TestRunner::isStatisticsVeryPrevalentResource(JSStringRef hostName)
    17321396{
    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);
    17391398}
    17401399
    17411400bool TestRunner::isStatisticsRegisteredAsSubresourceUnder(JSStringRef subresourceHost, JSStringRef topFrameHost)
    17421401{
    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    }));
    17661406}
    17671407
    17681408bool TestRunner::isStatisticsRegisteredAsSubFrameUnder(JSStringRef subFrameHost, JSStringRef topFrameHost)
    17691409{
    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    }));
    17931414}
    17941415
    17951416bool TestRunner::isStatisticsRegisteredAsRedirectingTo(JSStringRef hostRedirectedFrom, JSStringRef hostRedirectedTo)
    17961417{
    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    }));
    18201422}
    18211423
     
    18241426    cacheTestRunnerCallback(SetStatisticsHasHadUserInteractionCallbackID, completionHandler);
    18251427
    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    }));
    18491432}
    18501433
     
    18561439bool TestRunner::isStatisticsHasHadUserInteraction(JSStringRef hostName)
    18571440{
    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);
    18641442}
    18651443
    18661444bool TestRunner::isStatisticsOnlyInDatabaseOnce(JSStringRef subHost, JSStringRef topHost)
    18671445{
    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    }));
    18921450}
    18931451
    18941452void TestRunner::setStatisticsGrandfathered(JSStringRef hostName, bool value)
    18951453{
    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    }));
    19191458}
    19201459
    19211460bool TestRunner::isStatisticsGrandfathered(JSStringRef hostName)
    19221461{
    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);
    19291463}
    19301464
    19311465void TestRunner::setStatisticsSubframeUnderTopFrameOrigin(JSStringRef hostName, JSStringRef topFrameHostName)
    19321466{
    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    }));
    19531471}
    19541472
    19551473void TestRunner::setStatisticsSubresourceUnderTopFrameOrigin(JSStringRef hostName, JSStringRef topFrameHostName)
    19561474{
    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    }));
    19771479}
    19781480
    19791481void TestRunner::setStatisticsSubresourceUniqueRedirectTo(JSStringRef hostName, JSStringRef hostNameRedirectedTo)
    19801482{
    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    }));
    20011487}
    20021488
     
    20041490void TestRunner::setStatisticsSubresourceUniqueRedirectFrom(JSStringRef hostName, JSStringRef hostNameRedirectedFrom)
    20051491{
    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    }));
    20261496}
    20271497
    20281498void TestRunner::setStatisticsTopFrameUniqueRedirectTo(JSStringRef hostName, JSStringRef hostNameRedirectedTo)
    20291499{
    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    }));
    20501504}
    20511505
    20521506void TestRunner::setStatisticsTopFrameUniqueRedirectFrom(JSStringRef hostName, JSStringRef hostNameRedirectedFrom)
    20531507{
    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    }));
    20741512}
    20751513
    20761514void TestRunner::setStatisticsCrossSiteLoadWithLinkDecoration(JSStringRef fromHost, JSStringRef toHost)
    20771515{
    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    }));
    20981520}
    20991521
    21001522void TestRunner::setStatisticsTimeToLiveUserInteraction(double seconds)
    21011523{
    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);
    21051525}
    21061526
     
    21401560void TestRunner::statisticsDidRunTelemetryCallback(unsigned numberOfPrevalentResources, unsigned numberOfPrevalentResourcesWithUserInteraction, unsigned numberOfPrevalentResourcesWithoutUserInteraction, unsigned topPrevalentResourceWithUserInteractionDaysSinceUserInteraction, unsigned medianDaysSinceUserInteractionPrevalentResourceWithUserInteraction, unsigned top3NumberOfPrevalentResourcesWithUI, unsigned top3MedianSubFrameWithoutUI, unsigned top3MedianSubResourceWithoutUI, unsigned top3MedianUniqueRedirectsWithoutUI, unsigned top3MedianDataRecordsRemovedWithoutUI)
    21411561{
    2142     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
    2143     JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
    2144    
    21451562    String string = makeString("{ \"numberOfPrevalentResources\" : ", numberOfPrevalentResources, ", \"numberOfPrevalentResourcesWithUserInteraction\" : ", numberOfPrevalentResourcesWithUserInteraction, ", \"numberOfPrevalentResourcesWithoutUserInteraction\" : ", numberOfPrevalentResourcesWithoutUserInteraction, ", \"topPrevalentResourceWithUserInteractionDaysSinceUserInteraction\" : ", topPrevalentResourceWithUserInteractionDaysSinceUserInteraction, ", \"medianDaysSinceUserInteractionPrevalentResourceWithUserInteraction\" : ", medianDaysSinceUserInteractionPrevalentResourceWithUserInteraction, ", \"top3NumberOfPrevalentResourcesWithUI\" : ", top3NumberOfPrevalentResourcesWithUI, ", \"top3MedianSubFrameWithoutUI\" : ", top3MedianSubFrameWithoutUI, ", \"top3MedianSubResourceWithoutUI\" : ", top3MedianSubResourceWithoutUI, ", \"top3MedianUniqueRedirectsWithoutUI\" : ", top3MedianUniqueRedirectsWithoutUI, ", \"top3MedianDataRecordsRemovedWithoutUI\" : ", top3MedianDataRecordsRemovedWithoutUI, " }");
    21461563   
    2147     JSValueRef result = JSValueMakeFromJSONString(context, adopt(JSStringCreateWithUTF8CString(string.utf8().data())).get());
     1564    JSValueRef result = JSValueMakeFromJSONString(mainFrameJSContext(), createJSString(string.utf8().data()).get());
    21481565
    21491566    callTestRunnerCallback(StatisticsDidRunTelemetryCallbackID, 1, &result);
     
    21571574void TestRunner::statisticsProcessStatisticsAndDataRecords()
    21581575{
    2159     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsProcessStatisticsAndDataRecords"));
    2160     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr);
     1576    postSynchronousMessage("StatisticsProcessStatisticsAndDataRecords");
    21611577}
    21621578
     
    21651581    cacheTestRunnerCallback(StatisticsDidSetBlockCookiesForHostCallbackID, completionHandler);
    21661582
    2167     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsUpdateCookieBlocking"));
    2168     WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr);
     1583    postMessage("StatisticsUpdateCookieBlocking");
    21691584}
    21701585
     
    21761591void TestRunner::statisticsSubmitTelemetry()
    21771592{
    2178     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsSubmitTelemetry"));
    2179     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr);
     1593    postSynchronousMessage("StatisticsSubmitTelemetry");
    21801594}
    21811595
    21821596void TestRunner::setStatisticsNotifyPagesWhenDataRecordsWereScanned(bool value)
    21831597{
    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);
    21871599}
    21881600
    21891601void TestRunner::setStatisticsIsRunningTest(bool value)
    21901602{
    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);
    21941604}
    21951605
    21961606void TestRunner::setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool value)
    21971607{
    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);
    22011609}
    22021610
    22031611void TestRunner::setStatisticsMinimumTimeBetweenDataRecordsRemoval(double seconds)
    22041612{
    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);
    22081614}
    22091615
    22101616void TestRunner::setStatisticsGrandfatheringTime(double seconds)
    22111617{
    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);
    22151619}
    22161620
    22171621void TestRunner::setStatisticsMaxStatisticsEntries(unsigned entries)
    22181622{
    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);
    22221624}
    22231625   
    22241626void TestRunner::setStatisticsPruneEntriesDownTo(unsigned entries)
    22251627{
    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);
    22291629}
    22301630   
     
    22321632{
    22331633    cacheTestRunnerCallback(StatisticsDidClearInMemoryAndPersistentStoreCallbackID, callback);
    2234 
    2235     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsClearInMemoryAndPersistentStore"));
    2236     WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr);
     1634    postMessage("StatisticsClearInMemoryAndPersistentStore");
    22371635}
    22381636
     
    22401638{
    22411639    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);
    22461641}
    22471642
     
    22491644{
    22501645    cacheTestRunnerCallback(StatisticsDidClearThroughWebsiteDataRemovalCallbackID, callback);
    2251    
    2252     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsClearThroughWebsiteDataRemoval"));
    2253     WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr);
     1646    postMessage("StatisticsClearThroughWebsiteDataRemoval");
    22541647}
    22551648
    22561649void TestRunner::statisticsDeleteCookiesForHost(JSStringRef hostName, bool includeHttpOnlyCookies)
    22571650{
    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    }));
    22801655}
    22811656
    22821657bool TestRunner::isStatisticsHasLocalStorage(JSStringRef hostName)
    22831658{
    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);
    22901660}
    22911661
    22921662void TestRunner::setStatisticsCacheMaxAgeCap(double seconds)
    22931663{
    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);
    22971665}
    22981666
    22991667bool TestRunner::hasStatisticsIsolatedSession(JSStringRef hostName)
    23001668{
    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);
    23071670}
    23081671
     
    23131676   
    23141677    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);
    23181679    m_hasSetDowngradeReferrerCallback = true;
    23191680}
     
    23311692
    23321693    cacheTestRunnerCallback(StatisticsDidSetShouldBlockThirdPartyCookiesCallbackID, completionHandler);
    2333     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsShouldBlockThirdPartyCookies"));
     1694    auto messageName = "SetStatisticsShouldBlockThirdPartyCookies";
    23341695    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);
    23381698    m_hasSetBlockThirdPartyCookiesCallback = true;
    23391699}
     
    23511711
    23521712    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);
    23561714    m_hasSetFirstPartyWebsiteDataRemovalModeCallback = true;
    23571715}
     
    23761734{
    23771735    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);
    23821737}
    23831738
     
    23911746{
    23921747    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    }));
    24141752}
    24151753
     
    24221760{
    24231761    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));
    24281763}
    24291764
     
    24361771{
    24371772    cacheTestRunnerCallback(StatisticsDidResetToConsistentStateCallbackID, completionHandler);
    2438    
    2439     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("StatisticsResetToConsistentState"));
    2440     WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr);
     1773
     1774    postMessage("StatisticsResetToConsistentState");
    24411775}
    24421776
     
    24791813{
    24801814    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
     1818static JSValueRef makeDomainsValue(const Vector<String>& domains)
     1819{
     1820    StringBuilder builder;
     1821    builder.append('[');
    24931822    bool firstDomain = true;
    24941823    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;
    25021826    }
    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}
     1830void TestRunner::callDidReceiveAllStorageAccessEntriesCallback(Vector<String>& domains)
     1831{
     1832    auto result = makeDomainsValue(domains);
    25071833    callTestRunnerCallback(AllStorageAccessEntriesCallbackID, 1, &result);
    25081834}
     
    25111837{
    25121838    cacheTestRunnerCallback(LoadedSubresourceDomainsCallbackID, callback);
    2513    
    2514     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("LoadedSubresourceDomains"));
    2515     WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr);
     1839    postMessage("LoadedSubresourceDomains");
    25161840}
    25171841
    25181842void TestRunner::callDidReceiveLoadedSubresourceDomainsCallback(Vector<String>&& domains)
    25191843{
    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);
    25391845    callTestRunnerCallback(LoadedSubresourceDomainsCallbackID, 1, &result);
    25401846}
     
    25421848void TestRunner::addMockMediaDevice(JSStringRef persistentId, JSStringRef label, const char* type)
    25431849{
    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    }));
    25701855}
    25711856
     
    25871872void TestRunner::clearMockMediaDevices()
    25881873{
    2589     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ClearMockMediaDevices"));
    2590     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr);
     1874    postSynchronousMessage("ClearMockMediaDevices");
    25911875}
    25921876
    25931877void TestRunner::removeMockMediaDevice(JSStringRef persistentId)
    25941878{
    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));
    25991880}
    26001881
    26011882void TestRunner::resetMockMediaDevices()
    26021883{
    2603     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ResetMockMediaDevices"));
    2604     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr);
     1884    postSynchronousMessage("ResetMockMediaDevices");
    26051885}
    26061886
    26071887void TestRunner::setMockCameraOrientation(unsigned orientation)
    26081888{
    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);
    26121890}
    26131891
    26141892bool TestRunner::isMockRealtimeMediaSourceCenterEnabled()
    26151893{
    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");
    26211895}
    26221896
    26231897#if PLATFORM(MAC)
     1898
    26241899void TestRunner::connectMockGamepad(unsigned index)
    26251900{
    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);
    26301902}
    26311903
    26321904void TestRunner::disconnectMockGamepad(unsigned index)
    26331905{
    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);
    26381907}
    26391908
    26401909void TestRunner::setMockGamepadDetails(unsigned index, JSStringRef gamepadID, JSStringRef mapping, unsigned axisCount, unsigned buttonCount)
    26411910{
    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    }));
    26741918}
    26751919
    26761920void TestRunner::setMockGamepadAxisValue(unsigned index, unsigned axisIndex, double value)
    26771921{
    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    }));
    27041927}
    27051928
    27061929void TestRunner::setMockGamepadButtonValue(unsigned index, unsigned buttonIndex, double value)
    27071930{
    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
    27351938#else
     1939
    27361940void TestRunner::connectMockGamepad(unsigned)
    27371941{
     
    27531957{
    27541958}
     1959
    27551960#endif // PLATFORM(MAC)
    27561961
    27571962void TestRunner::setOpenPanelFiles(JSValueRef filesValue)
    27581963{
    2759     WKBundlePageRef page = InjectedBundle::singleton().page()->page();
    2760     JSContextRef context = WKBundleFrameGetJavaScriptContext(WKBundlePageGetMainFrame(page));
     1964    JSContextRef context = mainFrameJSContext();
    27611965
    27621966    if (!JSValueIsArray(context, filesValue))
    27631967        return;
    27641968
    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;
    27711970    auto fileURLs = adoptWK(WKMutableArrayCreate());
    2772     auto filesLength = static_cast<size_t>(JSValueToNumber(context, filesLengthValue, nullptr));
     1971    auto filesLength = arrayLength(context, files);
    27731972    for (size_t i = 0; i < filesLength; ++i) {
    27741973        JSValueRef fileValue = JSObjectGetPropertyAtIndex(context, files, i, nullptr);
     
    27761975            continue;
    27771976
    2778         auto file = adopt(JSValueToStringCopy(context, fileValue, nullptr));
     1977        auto file = createJSString(context, fileValue);
    27791978        size_t fileBufferSize = JSStringGetMaximumUTF8CStringSize(file.get()) + 1;
    27801979        auto fileBuffer = makeUniqueArray<char>(fileBufferSize);
     
    27901989    }
    27911990
    2792     static auto messageName = adoptWK(WKStringCreateWithUTF8CString("SetOpenPanelFileURLs"));
    2793     WKBundlePagePostMessage(page, messageName.get(), fileURLs.get());
     1991    postPageMessage("SetOpenPanelFileURLs", fileURLs);
    27941992}
    27951993
     
    27971995{
    27981996#if PLATFORM(IOS_FAMILY)
    2799     WKBundlePageRef page = InjectedBundle::singleton().page()->page();
    2800     JSContextRef context = WKBundleFrameGetJavaScriptContext(WKBundlePageGetMainFrame(page));
    2801 
    2802     auto& injectedBundle = InjectedBundle::singleton();
    28031997    // 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);
    28082000#else
    28092001    UNUSED_PARAM(data);
     
    28142006{
    28152007    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);
    28212009}
    28222010
     
    28282016void TestRunner::clearDOMCache(JSStringRef origin)
    28292017{
    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));
    28332019}
    28342020
    28352021void TestRunner::clearDOMCaches()
    28362022{
    2837     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("ClearDOMCaches"));
    2838     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr);
     2023    postSynchronousMessage("ClearDOMCaches");
    28392024}
    28402025
    28412026bool TestRunner::hasDOMCache(JSStringRef origin)
    28422027{
    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);
    28492029}
    28502030
    28512031uint64_t TestRunner::domCacheSize(JSStringRef origin)
    28522032{
    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);
    28582034}
    28592035
    28602036void TestRunner::setAllowStorageQuotaIncrease(bool willIncrease)
    28612037{
    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);
    28652039}
    28662040
     
    28682042{
    28692043    cacheTestRunnerCallback(GetApplicationManifestCallbackID, callback);
    2870    
    2871     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("GetApplicationManifest"));
    2872     WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr);
     2044    postMessage("GetApplicationManifest");
    28732045}
    28742046
     
    28902062void TestRunner::injectUserScript(JSStringRef script)
    28912063{
    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));
    28952065}
    28962066
    28972067void TestRunner::sendDisplayConfigurationChangedMessageForTesting()
    28982068{
    2899     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SendDisplayConfigurationChangedMessageForTesting"));
    2900     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr);
     2069    postSynchronousMessage("SendDisplayConfigurationChangedMessageForTesting");
    29012070}
    29022071
    29032072void TestRunner::setServiceWorkerFetchTimeout(double seconds)
    29042073{
    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);
    29082075}
    29092076
     
    29112078void TestRunner::addTestKeyToKeychain(JSStringRef privateKeyBase64, JSStringRef attrLabel, JSStringRef applicationTagBase64)
    29122079{
    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
     2087void TestRunner::cleanUpKeychain(JSStringRef attrLabel, JSStringRef applicationLabelBase64)
     2088{
     2089    if (!applicationLabelBase64) {
     2090        postSynchronousMessage("CleanUpKeychain", createWKDictionary({
     2091            { "AttrLabel", toWK(attrLabel) },
     2092        }));
     2093        return;
    29332094    }
    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    }));
    29682099}
    29692100
    29702101bool TestRunner::keyExistsInKeychain(JSStringRef attrLabel, JSStringRef applicationLabelBase64)
    29712102{
    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    }));
    29982107}
    29992108
    30002109unsigned long TestRunner::serverTrustEvaluationCallbackCallsCount()
    30012110{
    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");
    30072112}
    30082113
    30092114void TestRunner::setShouldDismissJavaScriptAlertsAsynchronously(bool shouldDismissAsynchronously)
    30102115{
    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);
    30142117}
    30152118
    30162119void TestRunner::abortModal()
    30172120{
    3018     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("AbortModal"));
    3019     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr);
     2121    postSynchronousMessage("AbortModal");
    30202122}
    30212123
    30222124void TestRunner::dumpAdClickAttribution()
    30232125{
    3024     auto messageName = adoptWK(WKStringCreateWithUTF8CString("DumpAdClickAttribution"));
    3025     WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, nullptr);
     2126    postSynchronousPageMessage("DumpAdClickAttribution");
    30262127}
    30272128
    30282129void TestRunner::clearAdClickAttribution()
    30292130{
    3030     auto messageName = adoptWK(WKStringCreateWithUTF8CString("ClearAdClickAttribution"));
    3031     WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, nullptr);
     2131    postSynchronousPageMessage("ClearAdClickAttribution");
    30322132}
    30332133
    30342134void TestRunner::clearAdClickAttributionsThroughWebsiteDataRemoval()
    30352135{
    3036     auto messageName = adoptWK(WKStringCreateWithUTF8CString("ClearAdClickAttributionsThroughWebsiteDataRemoval"));
    3037     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr);
     2136    postSynchronousMessage("ClearAdClickAttributionsThroughWebsiteDataRemoval");
    30382137}
    30392138
    30402139void TestRunner::setAdClickAttributionOverrideTimerForTesting(bool value)
    30412140{
    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);
    30452142}
    30462143
    30472144void TestRunner::setAdClickAttributionConversionURLForTesting(JSStringRef urlString)
    30482145{
    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())));
    30532148}
    30542149
    30552150void TestRunner::markAdClickAttributionsAsExpiredForTesting()
    30562151{
    3057     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("MarkAdClickAttributionsAsExpiredForTesting"));
    3058     WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, nullptr);
     2152    postSynchronousPageMessage("MarkAdClickAttributionsAsExpiredForTesting");
    30592153}
    30602154
    30612155void TestRunner::setOffscreenCanvasEnabled(bool enabled)
    30622156{
    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);
    30662158}
    30672159
    30682160bool TestRunner::hasAppBoundSession()
    30692161{
    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");
    30762163}
    30772164
    30782165void TestRunner::clearAppBoundSession()
    30792166{
    3080     auto messageName = adoptWK(WKStringCreateWithUTF8CString("ClearAppBoundSession"));
    3081     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), nullptr, nullptr);
     2167    postSynchronousMessage("ClearAppBoundSession");
    30822168}
    30832169
     
    30862172    cacheTestRunnerCallback(DidSetAppBoundDomainsCallbackID, completionHandler);
    30872173
    3088     JSContextRef context = WKBundleFrameGetJavaScriptContext(WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page()));
    3089 
     2174    auto context = mainFrameJSContext();
    30902175    if (!JSValueIsArray(context, originArray))
    30912176        return;
    30922177
    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);
    30992179    auto originURLs = adoptWK(WKMutableArrayCreate());
    3100     auto originsLength = static_cast<size_t>(JSValueToNumber(context, originsLengthValue, nullptr));
    3101     for (size_t i = 0; i < originsLength; ++i) {
     2180    auto originsLength = arrayLength(context, origins);
     2181    for (unsigned i = 0; i < originsLength; ++i) {
    31022182        JSValueRef originValue = JSObjectGetPropertyAtIndex(context, origins, i, nullptr);
    31032183        if (!JSValueIsString(context, originValue))
    31042184            continue;
    31052185
    3106         auto origin = adopt(JSValueToStringCopy(context, originValue, nullptr));
     2186        auto origin = createJSString(context, originValue);
    31072187        size_t originBufferSize = JSStringGetMaximumUTF8CStringSize(origin.get()) + 1;
    31082188        auto originBuffer = makeUniqueArray<char>(originBufferSize);
     
    31122192    }
    31132193
    3114     auto messageName = adoptWK(WKStringCreateWithUTF8CString("SetAppBoundDomains"));
     2194    auto messageName = toWK("SetAppBoundDomains");
    31152195    WKBundlePostMessage(InjectedBundle::singleton().bundle(), messageName.get(), originURLs.get());
    31162196}
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

    r267750 r267761  
    4747    virtual JSClassRef wrapperClass();
    4848
    49     void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
     49    void makeWindowObject(JSContextRef);
    5050
    5151    bool isIOSFamily() const
     
    254254    bool willSendRequestReturnsNullOnRedirect() const { return m_willSendRequestReturnsNullOnRedirect; }
    255255    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); }
    257257    String willSendRequestHTTPBody() const { return m_willSendRequestHTTPBody; }
    258258
     
    287287    void callSetBackingScaleFactorCallback();
    288288
    289     void overridePreference(JSStringRef preference, JSStringRef value);
     289    static void overridePreference(JSStringRef preference, JSStringRef value);
    290290
    291291    // Cookies testing
     
    305305    // Geolocation.
    306306    void setGeolocationPermission(bool);
    307     void setMockGeolocationPosition(double latitude, double longitude, double accuracy, JSValueRef altitude, JSValueRef altitudeAccuracy, JSValueRef heading, JSValueRef speed, JSValueRef floorLevel);
     307    void setMockGeolocationPosition(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitudeAccuracy, Optional<double> heading, Optional<double> speed, Optional<double> floorLevel);
    308308    void setMockGeolocationPositionUnavailableError(JSStringRef message);
    309309    bool isGeolocationProviderActive();
     
    336336
    337337    JSValueRef failNextNewCodeBlock();
    338     JSValueRef numberOfDFGCompiles(JSValueRef theFunction);
    339     JSValueRef neverInlineFunction(JSValueRef theFunction);
     338    JSValueRef numberOfDFGCompiles(JSValueRef function);
     339    JSValueRef neverInlineFunction(JSValueRef function);
    340340
    341341    bool shouldDecideNavigationPolicyAfterDelay() const { return m_shouldDecideNavigationPolicyAfterDelay; }
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/TextInputController.cpp

    r255532 r267761  
    2727#include "TextInputController.h"
    2828
     29#include "DictionaryFunctions.h"
    2930#include "InjectedBundle.h"
    3031#include "InjectedBundlePage.h"
     
    4142}
    4243
    43 TextInputController::TextInputController()
    44 {
    45 }
    46 
    47 TextInputController::~TextInputController()
    48 {
    49 }
    50 
    5144JSClassRef TextInputController::wrapperClass()
    5245{
     
    5447}
    5548
    56 void TextInputController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
     49void TextInputController::makeWindowObject(JSContextRef context)
    5750{
    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);
    6752}
    6853
     
    7358
    7459    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))
    9265            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);
    11267        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")));
    11671        WKArrayAppendItem(result, dictionary.get());
    11772    }
    118 
    11973    return result;
    12074}
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/TextInputController.h

    r255532 r267761  
    2929#include <wtf/Ref.h>
    3030
     31typedef const struct OpaqueJSContext* JSContextRef;
     32typedef struct OpaqueJSString* JSStringRef;
     33typedef const struct OpaqueJSValue* JSValueRef;
     34
    3135namespace WTR {
    3236
    33 class TextInputController : public JSWrappable {
     37class TextInputController final : public JSWrappable {
    3438public:
    3539    static Ref<TextInputController> create();
    36     virtual ~TextInputController();
    3740
    38     // JSWrappable
    39     virtual JSClassRef wrapperClass();
    40 
    41     void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
     41    void makeWindowObject(JSContextRef);
    4242
    4343    void setMarkedText(JSStringRef text, int from, int length, bool suppressUnderline, JSValueRef highlights);
     
    4747
    4848private:
    49     TextInputController();
     49    TextInputController() = default;
     50
     51    JSClassRef wrapperClass() final;
    5052};
    5153
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/cocoa/ActivateFontsCocoa.mm

    r261153 r267761  
    137137void installFakeHelvetica(WKStringRef configuration)
    138138{
    139     RetainPtr<CFStringRef> configurationString = adoptCF(WKStringCopyCFString(kCFAllocatorDefault, configuration));
     139    auto configurationString = adoptCF(WKStringCopyCFString(kCFAllocatorDefault, configuration));
    140140    NSURL *resourceURL = [resourcesDirectoryURL() URLByAppendingPathComponent:[NSString stringWithFormat:@"FakeHelvetica-%@.ttf", configurationString.get()] isDirectory:NO];
    141141    CFErrorRef error = nullptr;
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/cocoa/InjectedBundlePageCocoa.mm

    r240641 r267761  
    4848String InjectedBundlePage::platformResponseMimeType(WKURLResponseRef response)
    4949{
    50     RetainPtr<NSURLResponse> nsURLResponse = adoptNS(WKURLResponseCopyNSURLResponse(response));
     50    auto nsURLResponse = adoptNS(WKURLResponseCopyNSURLResponse(response));
    5151    return [nsURLResponse.get() MIMEType];
    5252}
     
    5454uint64_t InjectedBundlePage::responseHeaderCount(WKURLResponseRef response)
    5555{
    56     RetainPtr<NSURLResponse> nsURLResponse = adoptNS(WKURLResponseCopyNSURLResponse(response));
     56    auto nsURLResponse = adoptNS(WKURLResponseCopyNSURLResponse(response));
    5757    if (![nsURLResponse isKindOfClass:[NSHTTPURLResponse class]])
    5858        return { };
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityControllerIOS.mm

    r236032 r267761  
    6363JSRetainPtr<JSStringRef> AccessibilityController::platformName()
    6464{
    65     return adopt(JSStringCreateWithUTF8CString("ios"));
     65    return WTR::createJSString("ios");
    6666}
    6767
     
    9090RefPtr<AccessibilityUIElement> AccessibilityController::accessibleElementById(JSStringRef idAttribute)
    9191{
    92     WKBundlePageRef page = InjectedBundle::singleton().page()->page();
     92    auto page = InjectedBundle::singleton().page()->page();
    9393    id root = static_cast<PlatformUIElement>(WKAccessibilityRootObject(page));
    9494
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/ios/AccessibilityUIElementIOS.mm

    r264235 r267761  
    137137namespace WTR {
    138138
    139 static JSRetainPtr<JSStringRef> createEmptyJSString()
    140 {
    141     return adopt(JSStringCreateWithCharacters(nullptr, 0));
    142 }
    143 
    144139static JSRetainPtr<JSStringRef> concatenateAttributeAndValue(NSString *attribute, NSString *value)
    145140{
     
    331326JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfLinkedUIElements()
    332327{
    333     return createEmptyJSString();
     328    return createJSString();
    334329}
    335330
    336331JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfDocumentLinks()
    337332{
    338     return createEmptyJSString();
     333    return createJSString();
    339334}
    340335
    341336JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfChildren()
    342337{
    343     return createEmptyJSString();
     338    return createJSString();
    344339}
    345340
    346341JSRetainPtr<JSStringRef> AccessibilityUIElement::allAttributes()
    347342{
    348     return createEmptyJSString();
     343    return createJSString();
    349344}
    350345
    351346JSRetainPtr<JSStringRef> AccessibilityUIElement::stringDescriptionOfAttributeValue(JSStringRef attribute)
    352347{
    353     return createEmptyJSString();
     348    return createJSString();
    354349}
    355350
     
    383378        return [[m_element accessibilityTextualContext] createJSStringRef];
    384379   
    385     return createEmptyJSString();
     380    return createJSString();
    386381}
    387382
     
    444439JSRetainPtr<JSStringRef> AccessibilityUIElement::parameterizedAttributeNames()
    445440{
    446     return createEmptyJSString();
     441    return createJSString();
    447442}
    448443
    449444JSRetainPtr<JSStringRef> AccessibilityUIElement::role()
    450445{
    451     return createEmptyJSString();
     446    return createJSString();
    452447}
    453448
    454449JSRetainPtr<JSStringRef> AccessibilityUIElement::subrole()
    455450{
    456     return createEmptyJSString();
     451    return createJSString();
    457452}
    458453
     
    464459JSRetainPtr<JSStringRef> AccessibilityUIElement::computedRoleString()
    465460{
    466     // FIXME: implement
    467     return createEmptyJSString();
     461    return createJSString();
    468462}
    469463
    470464JSRetainPtr<JSStringRef> AccessibilityUIElement::title()
    471465{
    472     return createEmptyJSString();
     466    return createJSString();
    473467}
    474468
     
    480474JSRetainPtr<JSStringRef> AccessibilityUIElement::orientation() const
    481475{
    482     return createEmptyJSString();
     476    return createJSString();
    483477}
    484478
     
    490484JSRetainPtr<JSStringRef> AccessibilityUIElement::language()
    491485{
    492     return createEmptyJSString();
     486    return createJSString();
    493487}
    494488
     
    550544JSRetainPtr<JSStringRef> AccessibilityUIElement::valueDescription()
    551545{
    552     return createEmptyJSString();
     546    return createJSString();
    553547}
    554548
     
    585579bool AccessibilityUIElement::isFocused() const
    586580{
    587     // FIXME: implement
    588581    return false;
    589582}
     
    597590bool AccessibilityUIElement::isSelectedOptionActive() const
    598591{
    599     // FIXME: implement
    600592    return false;
    601593}
     
    603595bool AccessibilityUIElement::isIndeterminate() const
    604596{
    605     // FIXME: implement
    606597    return false;
    607598}
     
    639630JSRetainPtr<JSStringRef> AccessibilityUIElement::ariaDropEffects() const
    640631{
    641     return createEmptyJSString();
     632    return createJSString();
    642633}
    643634
     
    660651JSRetainPtr<JSStringRef> AccessibilityUIElement::boundsForRange(unsigned location, unsigned length)
    661652{
    662     return createEmptyJSString();
     653    return createJSString();
    663654}
    664655
     
    714705JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfColumnHeaders()
    715706{
    716     return createEmptyJSString();
     707    return createJSString();
    717708}
    718709
    719710JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfRowHeaders()
    720711{
    721     return createEmptyJSString();
     712    return createJSString();
    722713}
    723714
    724715JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfColumns()
    725716{
    726     return createEmptyJSString();
     717    return createJSString();
    727718}
    728719
    729720JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfRows()
    730721{
    731     return createEmptyJSString();
     722    return createJSString();
    732723}
    733724
    734725JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfVisibleCells()
    735726{
    736     return createEmptyJSString();
     727    return createJSString();
    737728}
    738729
    739730JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfHeader()
    740731{
    741     return createEmptyJSString();
     732    return createJSString();
    742733}
    743734
     
    904895void AccessibilityUIElement::clearSelectedChildren() const
    905896{
    906     // FIXME: implement
    907897}
    908898
    909899JSRetainPtr<JSStringRef> AccessibilityUIElement::accessibilityValue() const
    910900{
    911     // FIXME: implement
    912     return createEmptyJSString();
     901    return createJSString();
    913902}
    914903
    915904JSRetainPtr<JSStringRef> AccessibilityUIElement::documentEncoding()
    916905{
    917     return createEmptyJSString();
     906    return createJSString();
    918907}
    919908
    920909JSRetainPtr<JSStringRef> AccessibilityUIElement::documentURI()
    921910{
    922     return createEmptyJSString();
     911    return createJSString();
    923912}
    924913
     
    10171006bool AccessibilityUIElement::isSelectable() const
    10181007{
    1019     // FIXME: implement
    10201008    return false;
    10211009}
     
    10231011bool AccessibilityUIElement::isMultiSelectable() const
    10241012{
    1025     // FIXME: implement
    10261013    return false;
    10271014}
     
    10291016bool AccessibilityUIElement::isVisible() const
    10301017{
    1031     // FIXME: implement
    10321018    return false;
    10331019}
     
    10351021bool AccessibilityUIElement::isOffScreen() const
    10361022{
    1037     // FIXME: implement
    10381023    return false;
    10391024}
     
    10411026bool AccessibilityUIElement::isCollapsed() const
    10421027{
    1043     // FIXME: implement
    10441028    return false;
    10451029}
     
    10531037bool AccessibilityUIElement::isSingleLine() const
    10541038{
    1055     // FIXME: implement
    10561039    return false;
    10571040}
     
    10591042bool AccessibilityUIElement::isMultiLine() const
    10601043{
    1061     // FIXME: implement
    10621044    return false;
    10631045}
     
    10751057void AccessibilityUIElement::takeFocus()
    10761058{
    1077     // FIXME: implement
    10781059}
    10791060
    10801061void AccessibilityUIElement::takeSelection()
    10811062{
    1082     // FIXME: implement
    10831063}
    10841064
    10851065void AccessibilityUIElement::addSelection()
    10861066{
    1087     // FIXME: implement
    10881067}
    10891068
    10901069void AccessibilityUIElement::removeSelection()
    10911070{
    1092     // FIXME: implement
    10931071}
    10941072
     
    11371115    id textMarkers = markerRange->platformTextMarkerRange();
    11381116    if (![textMarkers isKindOfClass:[NSArray class]])
    1139         return createEmptyJSString();
     1117        return createJSString();
    11401118    return [[m_element stringForTextMarkers:textMarkers] createJSStringRef];
    11411119}
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm

    r214586 r267761  
    3737EventSenderProxy::EventSenderProxy(TestController* testController)
    3838    : 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)
    4739{
    4840    UNUSED_PARAM(m_testController);
     
    5143}
    5244
    53 EventSenderProxy::~EventSenderProxy()
    54 {
    55 }
     45EventSenderProxy::~EventSenderProxy() = default;
    5646
    5747void EventSenderProxy::updateClickCountForButton(int button)
     
    7161void EventSenderProxy::mouseDown(unsigned buttonNumber, WKEventModifiers modifiers)
    7262{
    73     // Write me.
    7463}
    7564
    7665void EventSenderProxy::mouseUp(unsigned buttonNumber, WKEventModifiers modifiers)
    7766{
    78     // Write me.
    7967}
    8068
    8169void EventSenderProxy::mouseMoveTo(double x, double y)
    8270{
    83     // Write me.
    8471}
    8572
     
    9178void EventSenderProxy::keyDown(WKStringRef key, WKEventModifiers modifiers, unsigned keyLocation)
    9279{
    93     // Write me.
    9480}
    9581
    9682void EventSenderProxy::mouseScrollBy(int x, int y)
    9783{
    98     // Write me.
    9984}
    10085
    10186void EventSenderProxy::mouseScrollByWithWheelAndMomentumPhases(int x, int y, int phase, int momentum)
    10287{
    103     // Write me.
    10488}
    10589
    10690void EventSenderProxy::continuousMouseScrollBy(int x, int y, bool paged)
    10791{
    108     // Write me.
    10992}
    11093
    11194#if ENABLE(TOUCH_EVENTS)
     95
    11296void EventSenderProxy::addTouchPoint(int x, int y)
    11397{
    114     // Write me.
    11598}
    11699
    117100void EventSenderProxy::updateTouchPoint(int index, int x, int y)
    118101{
    119     // Write me.
    120102}
    121103
    122104void EventSenderProxy::setTouchModifier(WKEventModifiers, bool enable)
    123105{
    124     // Write me.
    125106}
    126107
    127108void EventSenderProxy::setTouchPointRadius(int radiusX, int radiusY)
    128109{
    129     // Write me.
    130110}
    131111
    132112void EventSenderProxy::touchStart()
    133113{
    134     // Write me.
    135114}
    136115
    137116void EventSenderProxy::touchMove()
    138117{
    139     // Write me.
    140118}
    141119
    142120void EventSenderProxy::touchEnd()
    143121{
    144     // Write me.
    145122}
    146123
    147124void EventSenderProxy::touchCancel()
    148125{
    149     // Write me.
    150126}
    151127
    152128void EventSenderProxy::clearTouchPoints()
    153129{
    154     // Write me.
    155130}
    156131
    157132void EventSenderProxy::releaseTouchPoint(int index)
    158133{
    159     // Write me.
    160134}
    161135
    162136void EventSenderProxy::cancelTouchPoint(int index)
    163137{
    164     // Write me.
    165138}
     139
    166140#endif
    167141
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityCommonMac.mm

    r262244 r267761  
    3333
    3434#import "JSWrapper.h"
     35#import "StringFunctions.h"
    3536#import <JavaScriptCore/JSStringRefCF.h>
    3637#import <objc/runtime.h>
     
    6263}
    6364
    64 static JSValueRef makeArrayRefForArray(JSContextRef context, NSArray *array)
     65static JSObjectRef makeJSArray(JSContextRef context, NSArray *array)
    6566{
    6667    NSUInteger count = array.count;
    6768    JSValueRef arguments[count];
    68 
    6969    for (NSUInteger i = 0; i < count; i++)
    7070        arguments[i] = makeValueRefForValue(context, [array objectAtIndex:i]);
    71 
    7271    return JSObjectMakeArray(context, count, arguments, nullptr);
    7372}
    7473
    75 static JSValueRef makeObjectRefForDictionary(JSContextRef context, NSDictionary *dictionary)
     74static JSObjectRef makeJSObject(JSContextRef context, NSDictionary *dictionary)
    7675{
    77     JSObjectRef object = JSObjectMake(context, nullptr, nullptr);
    78 
     76    auto object = JSObjectMake(context, nullptr, nullptr);
    7977    [dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *) {
    8078        if (JSValueRef propertyValue = makeValueRefForValue(context, obj))
    8179            JSObjectSetProperty(context, object, [key createJSStringRef].get(), propertyValue, kJSPropertyAttributeNone, nullptr);
    8280    }];
    83 
    8481    return object;
    8582}
     
    9794        return toJS(context, WTR::AccessibilityUIElement::create(static_cast<PlatformUIElement>(value)).ptr());
    9895    if ([value isKindOfClass:[NSDictionary class]])
    99         return makeObjectRefForDictionary(context, value);
     96        return makeJSObject(context, value);
    10097    if ([value isKindOfClass:[NSArray class]])
    101         return makeArrayRefForArray(context, value);
     98        return makeJSArray(context, value);
    10299    return nullptr;
    103100}
     
    116113    if (searchKey) {
    117114        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)) {
    123118            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);
    131120            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];
    140125            }
    141126        }
     
    145130
    146131    if (searchText && JSStringGetLength(searchText))
    147         [parameterizedAttribute setObject:[NSString stringWithJSStringRef:searchText] forKey:@"AXSearchText"];
     132        [parameterizedAttribute setObject:toWTFString(searchText) forKey:@"AXSearchText"];
    148133
    149134    [parameterizedAttribute setObject:@(visibleOnly) forKey:@"AXVisibleOnly"];
    150 
    151135    [parameterizedAttribute setObject:@(immediateDescendantsOnly) forKey:@"AXImmediateDescendantsOnly"];
    152136
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm

    r261081 r267761  
    3636#import "InjectedBundle.h"
    3737#import "InjectedBundlePage.h"
     38#import "JSBasics.h"
    3839#import <JavaScriptCore/JSStringRefCF.h>
    3940#import <WebKit/WKBundle.h>
     
    9798RefPtr<AccessibilityUIElement> AccessibilityController::accessibleElementById(JSStringRef idAttribute)
    9899{
    99     WKBundlePageRef page = InjectedBundle::singleton().page()->page();
     100    auto page = InjectedBundle::singleton().page()->page();
    100101    PlatformUIElement root = static_cast<PlatformUIElement>(WKAccessibilityRootObject(page));
    101102
     
    112113JSRetainPtr<JSStringRef> AccessibilityController::platformName()
    113114{
    114     return adopt(JSStringCreateWithUTF8CString("mac"));
     115    return WTR::createJSString("mac");
    115116}
    116117
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm

    r265259 r267761  
    3333#import "InjectedBundle.h"
    3434#import "InjectedBundlePage.h"
    35 
     35#import "JSBasics.h"
    3636#import <AppKit/NSAccessibility.h>
    3737#import <Foundation/Foundation.h>
     
    8787
    8888namespace WTR {
    89 
    90 static JSRetainPtr<JSStringRef> createEmptyJSString()
    91 {
    92     return adopt(JSStringCreateWithCharacters(nullptr, 0));
    93 }
    9489
    9590RefPtr<AccessibilityController> AccessibilityUIElement::s_controller;
     
    207202static NSString *attributesOfElement(id accessibilityObject)
    208203{
    209     RetainPtr<NSArray> attributes = supportedAttributes(accessibilityObject);
     204    auto attributes = supportedAttributes(accessibilityObject);
    210205
    211206    NSMutableString* attributesString = [NSMutableString string];
     
    228223}
    229224
    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);
     225template<typename T> static JSObjectRef makeJSArray(JSContextRef context, const Vector<T>& elements)
     226{
     227    auto array = JSObjectMakeArray(context, 0, 0, 0);
    235228    size_t elementCount = elements.size();
    236229    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;
    240232}
    241233
     
    274266    if (searchStrings) {
    275267        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 {
    282271            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))];
    295275        }
    296276        [parameterizedAttribute setObject:searchStringsParameter forKey:@"AXSelectTextSearchStrings"];
     
    315295    if (searchStrings) {
    316296        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 {
    322300            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))];
    335304        }
    336305        [parameterizedAttribute setObject:searchStringsParameter forKey:@"AXSearchTextSearchStrings"];
     
    402371    if ([value isKindOfClass:[NSArray class]])
    403372        elements = makeVector<RefPtr<AccessibilityUIElement>>(value);
    404     return convertVectorToObjectArray<RefPtr<AccessibilityUIElement>>(context, elements);
     373    return makeJSArray(context, elements);
    405374    END_AX_OBJC_EXCEPTIONS
    406375}
     
    416385    if ([value isKindOfClass:[NSArray class]])
    417386        elements = makeVector<RefPtr<AccessibilityUIElement>>(value);
    418     return convertVectorToObjectArray<RefPtr<AccessibilityUIElement>>(context, elements);
     387    return makeJSArray(context, elements);
    419388    END_AX_OBJC_EXCEPTIONS
    420389}
     
    608577    Vector<RefPtr<AccessibilityUIElement>> elements;
    609578    getUIElementsWithAttribute(attribute, elements);
    610     return convertVectorToObjectArray<RefPtr<AccessibilityUIElement>>(context, elements);
     579    return makeJSArray(context, elements);
    611580}
    612581
     
    977946bool AccessibilityUIElement::isSelectedOptionActive() const
    978947{
    979     // FIXME: implement
    980948    return false;
    981949}
     
    12301198    id result = [m_element accessibilityAttributeValue:@"AXSearchTextWithCriteria" forParameter:parameterizedAttribute];
    12311199    if ([result isKindOfClass:[NSArray class]])
    1232         return convertVectorToObjectArray<RefPtr<AccessibilityTextMarkerRange>>(context, makeVector<RefPtr<AccessibilityTextMarkerRange>>(result));
     1200        return makeJSArray(context, makeVector<RefPtr<AccessibilityTextMarkerRange>>(result));
    12331201    END_AX_OBJC_EXCEPTIONS
    12341202
     
    15471515void AccessibilityUIElement::clearSelectedChildren() const
    15481516{
    1549     // FIXME: implement
    15501517}
    15511518
    15521519JSRetainPtr<JSStringRef> AccessibilityUIElement::accessibilityValue() const
    15531520{
    1554     // FIXME: implement
    1555     return createEmptyJSString();
     1521    return createJSString();
    15561522}
    15571523
     
    15631529        return [value createJSStringRef];
    15641530    END_AX_OBJC_EXCEPTIONS
    1565    
    1566     return createEmptyJSString();
     1531    return createJSString();
    15671532}
    15681533
     
    15741539        return [value createJSStringRef];
    15751540    END_AX_OBJC_EXCEPTIONS
    1576    
    1577     return createEmptyJSString();
     1541    return createJSString();
    15781542}
    15791543
     
    15841548    return [[url absoluteString] createJSStringRef];   
    15851549    END_AX_OBJC_EXCEPTIONS
    1586    
    15871550    return nullptr;
    15881551}
     
    16231586    result = [m_element accessibilityIsAttributeSettable:NSAccessibilityFocusedAttribute];
    16241587    END_AX_OBJC_EXCEPTIONS
    1625    
    16261588    return result;
    16271589}
     
    16491611bool AccessibilityUIElement::isVisible() const
    16501612{
    1651     // FIXME: implement
    16521613    return false;
    16531614}
     
    16551616bool AccessibilityUIElement::isOffScreen() const
    16561617{
    1657     // FIXME: implement
    16581618    return false;
    16591619}
     
    16611621bool AccessibilityUIElement::isCollapsed() const
    16621622{
    1663     // FIXME: implement
    16641623    return false;
    16651624}
     
    16761635bool AccessibilityUIElement::isSingleLine() const
    16771636{
    1678     // FIXME: implement
    16791637    return false;
    16801638}
     
    16821640bool AccessibilityUIElement::isMultiLine() const
    16831641{
    1684     // FIXME: implement
    16851642    return false;
    16861643}
     
    17151672void AccessibilityUIElement::takeSelection()
    17161673{
    1717     // FIXME: implement
    17181674}
    17191675
    17201676void AccessibilityUIElement::addSelection()
    17211677{
    1722     // FIXME: implement
    17231678}
    17241679
    17251680void AccessibilityUIElement::removeSelection()
    17261681{
    1727     // FIXME: implement
    17281682}
    17291683
  • TabularUnified trunk/Tools/WebKitTestRunner/InjectedBundle/mac/TestRunnerMac.mm

    r245419 r267761  
    4747    return nullptr;
    4848#else
    49     CFBundleRef inspectorBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.WebInspectorUI"));
     49    auto inspectorBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.WebInspectorUI"));
    5050    if (!inspectorBundle)
    5151        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;
    5954#endif
    6055}
  • TabularUnified trunk/Tools/WebKitTestRunner/StringFunctions.h

    r263164 r267761  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
    33 * Copyright (C) 2010 University of Szeged. All rights reserved.
    44 *
     
    2525 */
    2626
    27 #ifndef StringFunctions_h
    28 #define StringFunctions_h
     27#pragma once
    2928
    30 #include <JavaScriptCore/JSRetainPtr.h>
    31 #include <JavaScriptCore/JavaScript.h>
     29#include "JSBasics.h"
    3230#include <WebKit/WKRetainPtr.h>
    3331#include <WebKit/WKString.h>
    3432#include <WebKit/WKStringPrivate.h>
    35 #include <WebKit/WKURL.h>
    3633#include <sstream>
    3734#include <string>
     
    4542namespace WTR {
    4643
    47 // Conversion functions
     44WKRetainPtr<WKStringRef> toWKString(JSContextRef, JSValueRef);
     45WTF::String toWTFString(JSContextRef, JSValueRef);
    4846
    4947inline WKRetainPtr<WKStringRef> toWK(JSStringRef string)
     
    5755}
    5856
     57inline WKRetainPtr<WKStringRef> toWK(const char* string)
     58{
     59    return adoptWK(WKStringCreateWithUTF8CString(string));
     60}
     61
    5962inline WKRetainPtr<WKStringRef> toWK(const WTF::String& string)
    6063{
    61     return adoptWK(WKStringCreateWithUTF8CString(string.utf8().data()));
     64    return toWK(string.utf8().data());
    6265}
    6366
     
    8790inline WTF::String toWTFString(WKStringRef string)
    8891{
     92    if (!string)
     93        return nullString();
    8994    size_t bufferSize = WKStringGetMaximumUTF8CStringSize(string);
    9095    auto buffer = makeUniqueWithoutFastMallocCheck<char[]>(bufferSize);
     
    100105}
    101106
     107inline WTF::String toWTFString(JSStringRef string)
     108{
     109    return toWTFString(toWK(string));
     110}
     111
     112inline WTF::String toWTFString(const JSRetainPtr<JSStringRef>& string)
     113{
     114    return toWTFString(string.get());
     115}
     116
     117inline WKRetainPtr<WKStringRef> toWKString(JSContextRef context, JSValueRef value)
     118{
     119    return toWK(createJSString(context, value).get());
     120}
     121
     122inline 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
    102128} // namespace WTR
    103 
    104 #endif // StringFunctions_h
  • TabularUnified trunk/Tools/WebKitTestRunner/TestController.cpp

    r267750 r267761  
    2727#include "TestController.h"
    2828
     29#include "DictionaryFunctions.h"
    2930#include "EventSenderProxy.h"
    3031#include "Options.h"
    3132#include "PlatformWebView.h"
    32 #include "StringFunctions.h"
    3333#include "TestInvocation.h"
    3434#include "WebCoreTestSupport.h"
     
    495495#endif
    496496
    497     WKRetainPtr<WKStringRef> pageGroupIdentifier = adoptWK(WKStringCreateWithUTF8CString("WebKitTestRunnerPageGroup"));
    498     m_pageGroup.adopt(WKPageGroupCreateWithIdentifier(pageGroupIdentifier.get()));
     497    m_pageGroup.adopt(WKPageGroupCreateWithIdentifier(toWK("WebKitTestRunnerPageGroup").get()));
    499498
    500499    m_eventSenderProxy = makeUnique<EventSenderProxy>(this);
     
    508507    WKContextConfigurationSetIgnoreSynchronousMessagingTimeoutsForTesting(configuration.get(), options.ignoreSynchronousMessagingTimeouts);
    509508
    510     WKRetainPtr<WKMutableArrayRef> overrideLanguages = adoptWK(WKMutableArrayCreate());
     509    auto overrideLanguages = adoptWK(WKMutableArrayCreate());
    511510    for (auto& language : options.overrideLanguages)
    512         WKArrayAppendItem(overrideLanguages.get(), adoptWK(WKStringCreateWithUTF8CString(language.utf8().data())).get());
     511        WKArrayAppendItem(overrideLanguages.get(), toWK(language).get());
    513512    WKContextConfigurationSetOverrideLanguages(configuration.get(), overrideLanguages.get());
    514513
     
    844843
    845844    // 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());
    851848
    852849#if ENABLE(INPUT_TYPE_DATE)
    853     static WKStringRef inputTypeDateFeature = WKStringCreateWithUTF8CString("InputTypeDateEnabled");
    854     WKPreferencesSetInternalDebugFeatureForKey(preferences, true, inputTypeDateFeature);
     850    WKPreferencesSetInternalDebugFeatureForKey(preferences, true, toWK("InputTypeDateEnabled").get());
    855851#endif
    856852#if ENABLE(INPUT_TYPE_DATETIMELOCAL)
    857     static WKStringRef inputTypeDateTimeLocalFeature = WKStringCreateWithUTF8CString("InputTypeDateTimeLocalEnabled");
    858     WKPreferencesSetInternalDebugFeatureForKey(preferences, true, inputTypeDateTimeLocalFeature);
     853    WKPreferencesSetInternalDebugFeatureForKey(preferences, true, toWK("InputTypeDateTimeLocalEnabled").get());
    859854#endif
    860855#if ENABLE(INPUT_TYPE_MONTH)
    861     static WKStringRef inputTypeMonthFeature = WKStringCreateWithUTF8CString("InputTypeMonthEnabled");
    862     WKPreferencesSetInternalDebugFeatureForKey(preferences, true, inputTypeMonthFeature);
     856    WKPreferencesSetInternalDebugFeatureForKey(preferences, true, toWK("InputTypeMonthEnabled").get());
    863857#endif
    864858#if ENABLE(INPUT_TYPE_TIME)
    865     static WKStringRef inputTypeTimeFeature = WKStringCreateWithUTF8CString("InputTypeTimeEnabled");
    866     WKPreferencesSetInternalDebugFeatureForKey(preferences, true, inputTypeTimeFeature);
     859    WKPreferencesSetInternalDebugFeatureForKey(preferences, true, toWK("InputTypeTimeEnabled").get());
    867860#endif
    868861#if ENABLE(INPUT_TYPE_WEEK)
    869     static WKStringRef inputTypeWeekFeature = WKStringCreateWithUTF8CString("InputTypeWeekEnabled");
    870     WKPreferencesSetInternalDebugFeatureForKey(preferences, true, inputTypeWeekFeature);
     862    WKPreferencesSetInternalDebugFeatureForKey(preferences, true, toWK("InputTypeWeekEnabled").get());
    871863#endif
    872864
     
    921913    WKPreferencesSetPageCacheEnabled(preferences, options.enableBackForwardCache);
    922914
    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());
    933916
    934917    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());
    942925    WKPreferencesSetAsynchronousSpellCheckingEnabled(preferences, false);
    943926#if ENABLE(MEDIA_SOURCE)
     
    1011994    WKPageSetCustomUserAgent(m_mainWebView->page(), nullptr);
    1012995
    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);
    10271004
    10281005#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);
    10321007#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());
    10391011
    10401012#if PLATFORM(COCOA)
     
    10421014#endif
    10431015
    1044     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), resetMessageBody.get());
     1016    WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), toWK("Reset").get(), resetMessageBody.get());
    10451017
    10461018    WKContextSetShouldUseFontSmoothing(TestController::singleton().context(), false);
     
    12041176    AsyncTask([]() {
    12051177        // 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);
    12081179    }, 5_s).run();
    12091180}
     
    12161187    AsyncTask([]() {
    12171188        // 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);
    12201190    }, 20_s).run();
    12211191}
     
    13251295
    13261296#if !PLATFORM(COCOA)
     1297
    13271298void TestController::setAllowsAnySSLCertificate(bool allows)
    13281299{
     
    14011372static std::string parseStringTestHeaderValueAsRelativePath(const std::string& value, const std::string& pathOrURL)
    14021373{
    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()));
    14051376    return toSTD(adoptWK(WKURLCopyPath(relativeURL.get())));
    14061377}
     
    14161387    if (filename.empty()) {
    14171388        // 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());
    14201390    }
    14211391
     
    16161586
    16171587#if ENABLE(CONTENT_EXTENSIONS) && !PLATFORM(COCOA)
     1588
    16181589struct ContentExtensionStoreCallbackContext {
    16191590    explicit ContentExtensionStoreCallbackContext(TestController& controller)
     
    16431614        return path + ".json";
    16441615
    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
    16541619void TestController::configureContentExtensionForTest(const TestInvocation& test)
    16551620{
     
    16711636
    16721637    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);
    16761641    auto extensionStore = adoptWK(WKUserContentExtensionStoreCreate(storePath.get()));
    16771642    ASSERT(extensionStore);
    16781643
    1679     auto filterIdentifier = adoptWK(WKStringCreateWithUTF8CString("TestContentExtension"));
     1644    auto filterIdentifier = toWK("TestContentExtension");
    16801645
    16811646    ContentExtensionStoreCallbackContext context(*this);
     
    17021667    WKUserContentControllerRemoveAllUserContentFilters(userContentController());
    17031668
    1704     auto storePath = adoptWK(WKStringCreateWithUTF8CString(contentExtensionsPath));
     1669    auto storePath = toWK(contentExtensionsPath);
    17051670    auto extensionStore = adoptWK(WKUserContentExtensionStoreCreate(storePath.get()));
    17061671    ASSERT(extensionStore);
    17071672
    1708     auto filterIdentifier = adoptWK(WKStringCreateWithUTF8CString("TestContentExtension"));
     1673    auto filterIdentifier = toWK("TestContentExtension");
    17091674
    17101675    ContentExtensionStoreCallbackContext context(*this);
     
    17131678    ASSERT(!context.filter);
    17141679}
    1715 #else // ENABLE(CONTENT_EXTENSIONS)
     1680
     1681#endif // ENABLE(CONTENT_EXTENSIONS) && !PLATFORM(COCOA)
     1682
     1683#if !ENABLE(CONTENT_EXTENSIONS)
     1684
    17161685void TestController::configureContentExtensionForTest(const TestInvocation&)
    17171686{
     
    17211690{
    17221691}
    1723 #endif // ENABLE(CONTENT_EXTENSIONS)
    1724 #endif // !PLATFORM(COCOA)
     1692
     1693#endif // !ENABLE(CONTENT_EXTENSIONS)
    17251694
    17261695class CommandTokenizer {
     
    17281697    explicit CommandTokenizer(const std::string& input)
    17291698        : m_input(input)
    1730         , m_posNextSeparator(0)
    17311699    {
    17321700        pump();
     
    17411709    const std::string& m_input;
    17421710    std::string m_next;
    1743     size_t m_posNextSeparator;
     1711    size_t m_posNextSeparator { 0 };
    17441712};
    17451713
     
    18151783    TestOptions options = testOptionsForTest(command);
    18161784
    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);
    18191786
    18201787    if (command.shouldDumpPixels || m_shouldDumpPixelsForAllTests)
     
    19451912}
    19461913
    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);
     1914void TestController::didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef dictionary, bool synchronous)
     1915{
     1916    m_eventSenderProxy->keyDown(stringValue(dictionary, "Key"), uint64Value(dictionary, "Modifiers"), uint64Value(dictionary, "Location"));
    19591917}
    19601918
     
    19651923    HashMap<uint64_t, String> documentInfo;
    19661924    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")));
    19791927    }
    19801928
     
    20081956            return;
    20091957
    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"));
    20291963            return;
    20301964        }
    20311965
    2032         if (WKStringIsEqualToUTF8CString(subMessageName, "KeyDown")) {
    2033             didReceiveKeyDownMessageFromInjectedBundle(messageBodyDictionary, false);
     1966        if (WKStringIsEqualToUTF8CString(subMessageName, "MouseUp")) {
     1967            m_eventSenderProxy->mouseUp(uint64Value(dictionary, "Button"), uint64Value(dictionary, "Modifiers"));
    20341968            return;
    20351969        }
    20361970
    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);
    20461973            return;
    20471974        }
    20481975
     1976        if (WKStringIsEqualToUTF8CString(subMessageName, "MouseScrollBy")) {
     1977            m_eventSenderProxy->mouseScrollBy(doubleValue(dictionary, "X"), doubleValue(dictionary, "Y"));
     1978            return;
     1979        }
     1980
    20491981        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");
    20621986            m_eventSenderProxy->mouseScrollByWithWheelAndMomentumPhases(x, y, phase, momentum);
    2063 
    20641987            return;
    20651988        }
     
    20842007            return completionHandler(nullptr);
    20852008
    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");
    20912011
    20922012        if (WKStringIsEqualToUTF8CString(subMessageName, "KeyDown")) {
    2093             didReceiveKeyDownMessageFromInjectedBundle(messageBodyDictionary, true);
    2094 
     2013            didReceiveKeyDownMessageFromInjectedBundle(dictionary, true);
    20952014            return completionHandler(nullptr);
    20962015        }
    20972016
    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"));
    21102019            return completionHandler(nullptr);
    21112020        }
    21122021
     2022        if (WKStringIsEqualToUTF8CString(subMessageName, "MouseUp")) {
     2023            m_eventSenderProxy->mouseUp(uint64Value(dictionary, "Button"), uint64Value(dictionary, "Modifiers"));
     2024            return completionHandler(nullptr);
     2025        }
     2026
    21132027        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"));
    21222029            return completionHandler(nullptr);
    21232030        }
     
    21452052
    21462053        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"));
    21512055            return completionHandler(nullptr);
    21522056        }
     
    21542058
    21552059        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");
    21662063            m_eventSenderProxy->continuousMouseScrollBy(x, y, paged);
    21672064            return completionHandler(nullptr);
     
    21692066
    21702067        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"));
    21752069            return completionHandler(nullptr);
    21762070        }
     
    21782072#if ENABLE(TOUCH_EVENTS)
    21792073        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"));
    21872075            return completionHandler(nullptr);
    21882076        }
    21892077
    21902078        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");
    22002082            m_eventSenderProxy->updateTouchPoint(index, x, y);
    22012083            return completionHandler(nullptr);
     
    22032085
    22042086        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");
    22112089            m_eventSenderProxy->setTouchModifier(modifier, enable);
    22122090            return completionHandler(nullptr);
     
    22142092
    22152093        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");
    22222096            m_eventSenderProxy->setTouchPointRadius(x, y);
    22232097            return completionHandler(nullptr);
     
    22502124
    22512125        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"));
    22552127            return completionHandler(nullptr);
    22562128        }
    22572129
    22582130        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"));
    22622132            return completionHandler(nullptr);
    22632133        }
     
    22762146
    22772147    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;
    22802151        return setHTTPCookieAcceptPolicy(policy, WTFMove(completionHandler));
    22812152    }
    22822153
    22832154    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;
    22862158        return setHTTPCookieAcceptPolicy(policy, WTFMove(completionHandler));
    22872159    }
     
    24042276#if PLATFORM(MAC)
    24052277    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());
    24122280#endif
    24132281}
     
    24242292    }
    24252293
    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");
    24392302
    24402303    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());
    24432306        return;
    24442307    }
    24452308
    24462309    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());
    24492312        return;
    24502313    }
     
    24922355    if (m_shouldLogCanAuthenticateAgainstProtectionSpace)
    24932356        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)));
    24982360        return host == "localhost" || host == "127.0.0.1" || (m_allowAnyHTTPSCertificateForAllowedHosts && m_allowedHosts.find(host) != m_allowedHosts.end());
    24992361    }
    2500    
    2501     return authenticationScheme <= kWKProtectionSpaceAuthenticationSchemeHTTPDigest || authenticationScheme == kWKProtectionSpaceAuthenticationSchemeOAuth;
     2362    return scheme <= kWKProtectionSpaceAuthenticationSchemeHTTPDigest || scheme == kWKProtectionSpaceAuthenticationSchemeOAuth;
    25022363}
    25032364
     
    25072368        return;
    25082369
    2509     WKRetainPtr<WKURLRef> wkURL = adoptWK(WKFrameCopyURL(WKPageGetMainFrame(page)));
    2510     if (!WKURLIsEqual(wkURL.get(), blankURL()))
     2370    if (!WKURLIsEqual(adoptWK(WKFrameCopyURL(WKPageGetMainFrame(page))).get(), blankURL()))
    25112371        return;
    25122372
     
    25282388
    25292389        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));
    25312391            WKAuthenticationDecisionListenerUseCredential(decisionListener, credential.get());
    25322392            return;
     
    25422402    }
    25432403
    2544     std::string host = toSTD(adoptWK(WKProtectionSpaceCopyHost(protectionSpace)).get());
     2404    auto host = toWTFString(adoptWK(WKProtectionSpaceCopyHost(protectionSpace)).get());
    25452405    int port = WKProtectionSpaceGetPort(protectionSpace);
    2546     String message = makeString(host.c_str(), ':', port, " - didReceiveAuthenticationChallenge - ", toString(authenticationScheme), " - ");
     2406    String message = makeString(host, ':', port, " - didReceiveAuthenticationChallenge - ", toString(authenticationScheme), " - ");
    25472407    if (!m_handlesAuthenticationChallenges)
    25482408        message.append("Simulating cancelled authentication sheet\n");
     
    25552415        return;
    25562416    }
    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));
    25602418    WKAuthenticationDecisionListenerUseCredential(decisionListener, credential.get());
    25612419}
    25622420
    2563    
     2421
    25642422// WKContextDownloadClient
    25652423
     
    27052563}
    27062564
    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, double floorLevel)
    2708 {
    2709     m_geolocationProvider->setPosition(latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed, providesFloorLevel, floorLevel);
     2565void 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);
    27102568}
    27112569
     
    28572715    auto originHash = userMediaOriginHash(userMediaDocumentOrigin, topLevelDocumentOrigin);
    28582716    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());
    28622718}
    28632719
     
    29152771        }
    29162772
    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));
    29192775
    29202776        if (!WKArrayGetSize(videoDeviceUIDs.get()) && !WKArrayGetSize(audioDeviceUIDs.get())) {
     
    29272783            videoDeviceUID = reinterpret_cast<WKStringRef>(WKArrayGetItemAtIndex(videoDeviceUIDs.get(), 0));
    29282784        else
    2929             videoDeviceUID = adoptWK(WKStringCreateWithUTF8CString(""));
     2785            videoDeviceUID = toWK("");
    29302786
    29312787        WKRetainPtr<WKStringRef> audioDeviceUID;
     
    29332789            audioDeviceUID = reinterpret_cast<WKStringRef>(WKArrayGetItemAtIndex(audioDeviceUIDs.get(), 0));
    29342790        else
    2935             audioDeviceUID = adoptWK(WKStringCreateWithUTF8CString(""));
     2791            audioDeviceUID = toWK("");
    29362792
    29372793        WKUserMediaPermissionRequestAllow(request, audioDeviceUID.get(), videoDeviceUID.get());
     
    30572913        return;
    30582914
    3059     // URL
    30602915    auto url = adoptWK(WKNavigationDataCopyURL(navigationData));
    30612916    auto urlString = toWTFString(adoptWK(WKURLCopyString(url.get())));
    3062     // Title
    30632917    auto title = toWTFString(adoptWK(WKNavigationDataCopyTitle(navigationData)));
    3064     // HTTP method
    30652918    auto request = adoptWK(WKNavigationDataCopyOriginalRequest(navigationData));
    30662919    auto method = toWTFString(adoptWK(WKURLRequestCopyHTTPMethod(request.get())));
     
    32073060    Vector<String> resultDomains;
    32083061    for (unsigned i = 0; i < WKArrayGetSize(domainList); i++) {
    3209         auto domain =  reinterpret_cast<WKStringRef>(WKArrayGetItemAtIndex(domainList, i));
     3062        auto domain = reinterpret_cast<WKStringRef>(WKArrayGetItemAtIndex(domainList, i));
    32103063        auto buffer = std::vector<char>(WKStringGetMaximumUTF8CStringSize(domain));
    32113064        auto stringLength = WKStringGetUTF8CString(domain, buffer.data(), buffer.size());
     
    39723825{
    39733826    InAppBrowserPrivacyCallbackContext context(*this);
    3974     WKWebsiteDataStoreUpdateBundleIdentifierInNetworkProcess(TestController::websiteDataStore(), adoptWK(WKStringCreateWithUTF8CString(bundleIdentifier.utf8().data())).get(), &context, inAppBrowserPrivacyVoidResultCallback);
     3827    WKWebsiteDataStoreUpdateBundleIdentifierInNetworkProcess(TestController::websiteDataStore(), toWK(bundleIdentifier).get(), &context, inAppBrowserPrivacyVoidResultCallback);
    39753828    runUntil(context.done, noTimeout);
    39763829}
  • TabularUnified trunk/Tools/WebKitTestRunner/TestController.h

    r267750 r267761  
    141141    // Geolocation.
    142142    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, double floorLevel);
     143    void setMockGeolocationPosition(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitudeAccuracy, Optional<double> heading, Optional<double> speed, Optional<double> floorLevel);
    144144    void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage);
    145145    void handleGeolocationPermissionRequest(WKGeolocationPermissionRequestRef);
  • TabularUnified trunk/Tools/WebKitTestRunner/TestInvocation.cpp

    r267750 r267761  
    2828#include "TestInvocation.h"
    2929
     30#include "DictionaryFunctions.h"
    3031#include "PlatformWebView.h"
    31 #include "StringFunctions.h"
    3232#include "TestController.h"
    3333#include "UIScriptController.h"
     
    6767namespace WTR {
    6868
     69static void postPageMessage(const char* name, const WKRetainPtr<WKTypeRef>& body)
     70{
     71    WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), toWK(name).get(), body.get());
     72}
     73
     74static void postPageMessage(const char* name)
     75{
     76    postPageMessage(name, WKRetainPtr<WKTypeRef> { });
     77}
     78
    6979TestInvocation::TestInvocation(WKURLRef url, const TestOptions& options)
    7080    : m_options(options)
     
    7282    , m_waitToDumpWatchdogTimer(RunLoop::main(), this, &TestInvocation::waitToDumpWatchdogTimerFired)
    7383{
    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());
    8485
    8586    // FIXME: Avoid mutating the setting via a test directory like this.
     
    130131WKRetainPtr<WKMutableDictionaryRef> TestInvocation::createTestSettingsDictionary()
    131132{
    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());
    154139    return beginTestMessageBody;
    155140}
     
    169154    // FIXME: We should clear out visited links here.
    170155
    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());
    174157
    175158    m_startedTesting = true;
     
    328311
    329312    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")) {
    333314            m_gotInitialResponse = true;
    334315            TestController::singleton().notifyDone();
    335316            return;
    336317        }
    337 
    338318        ASSERT_NOT_REACHED();
    339319    }
    340320
    341321    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");
    349324        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"));
    352326            ASSERT(!m_pixelResult || m_dumpPixels);
    353327        }
    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"));
    361330        done();
    362331        return;
     
    364333
    365334    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)));
    369336        return;
    370337    }
    371338
    372339    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());
    376341        return;
    377342    }
    378343
    379344    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));
    383346        return;
    384347    }
     
    386349    if (WKStringIsEqualToUTF8CString(messageName, "AddChromeInputField")) {
    387350        TestController::singleton().mainWebView()->addChromeInputField();
    388         WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallAddChromeInputFieldCallback"));
    389         WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     351        postPageMessage("CallAddChromeInputFieldCallback");
    390352        return;
    391353    }
     
    393355    if (WKStringIsEqualToUTF8CString(messageName, "RemoveChromeInputField")) {
    394356        TestController::singleton().mainWebView()->removeChromeInputField();
    395         WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallRemoveChromeInputFieldCallback"));
    396         WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     357        postPageMessage("CallRemoveChromeInputFieldCallback");
    397358        return;
    398359    }
     
    400361    if (WKStringIsEqualToUTF8CString(messageName, "FocusWebView")) {
    401362        TestController::singleton().mainWebView()->makeWebViewFirstResponder();
    402         WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallFocusWebViewCallback"));
    403         WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     363        postPageMessage("CallFocusWebViewCallback");
    404364        return;
    405365    }
    406366
    407367    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");
    414370        return;
    415371    }
    416372
    417373    if (WKStringIsEqualToUTF8CString(messageName, "SimulateWebNotificationClick")) {
    418         ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
    419         uint64_t notificationID = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody));
     374        uint64_t notificationID = uint64Value(messageBody);
    420375        TestController::singleton().simulateWebNotificationClick(notificationID);
    421376        return;
     
    423378
    424379    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));
    428381        return;
    429382    }
    430383
    431384    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));
    435386        return;
    436387    }
    437388
    438389    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);
    495400        return;
    496401    }
    497402
    498403    if (WKStringIsEqualToUTF8CString(messageName, "SetMockGeolocationPositionUnavailableError")) {
    499         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
    500         WKStringRef errorMessage = static_cast<WKStringRef>(messageBody);
     404        WKStringRef errorMessage = stringValue(messageBody);
    501405        TestController::singleton().setMockGeolocationPositionUnavailableError(errorMessage);
    502406        return;
     
    504408
    505409    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));
    509411        return;
    510412    }
     
    516418
    517419    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");
    531424        TestController::singleton().setUserMediaPersistentPermissionForOrigin(permission, originWK, parentOriginWK);
    532425        return;
     
    534427
    535428    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");
    545432        TestController::singleton().resetUserMediaPermissionRequestCountForOrigin(originWK, parentOriginWK);
    546433        return;
     
    548435
    549436    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");
    561440        TestController::singleton().setCustomPolicyDelegate(enabled, permissive);
    562441        return;
     
    564443
    565444    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"));
    574447        return;
    575448    }
    576449
    577450    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");
    582453        return;
    583454    }
    584455
    585456    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));
    589458        return;
    590459    }
    591460
    592461    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));
    596463        return;
    597464    }
    598465
    599466    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);
    613472        return;
    614473    }
    615474
    616475    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");
    629480        TestController::singleton().workQueueManager().queueLoadHTMLString(toWTFString(contentWK), baseURLWK ? toWTFString(baseURLWK) : String(), unreachableURLWK ? toWTFString(unreachableURLWK) : String());
    630481        return;
     
    637488
    638489    if (WKStringIsEqualToUTF8CString(messageName, "QueueLoadingScript")) {
    639         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
    640         WKStringRef script = static_cast<WKStringRef>(messageBody);
     490        WKStringRef script = stringValue(messageBody);
    641491        TestController::singleton().workQueueManager().queueLoadingScript(toWTFString(script));
    642492        return;
     
    644494
    645495    if (WKStringIsEqualToUTF8CString(messageName, "QueueNonLoadingScript")) {
    646         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
    647         WKStringRef script = static_cast<WKStringRef>(messageBody);
     496        WKStringRef script = stringValue(messageBody);
    648497        TestController::singleton().workQueueManager().queueNonLoadingScript(toWTFString(script));
    649498        return;
     
    651500
    652501    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));
    656503        return;
    657504    }
    658505
    659506    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));
    663508        return;
    664509    }
    665510
    666511    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));
    670513        return;
    671514    }
    672515
    673516    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));
    677518        return;
    678519    }
    679520
    680521    if (WKStringIsEqualToUTF8CString(messageName, "SetAuthenticationUsername")) {
    681         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
    682         WKStringRef username = static_cast<WKStringRef>(messageBody);
     522        WKStringRef username = stringValue(messageBody);
    683523        TestController::singleton().setAuthenticationUsername(toWTFString(username));
    684524        return;
     
    686526
    687527    if (WKStringIsEqualToUTF8CString(messageName, "SetAuthenticationPassword")) {
    688         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
    689         WKStringRef password = static_cast<WKStringRef>(messageBody);
     528        WKStringRef password = stringValue(messageBody);
    690529        TestController::singleton().setAuthenticationPassword(toWTFString(password));
    691530        return;
     
    693532
    694533    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));
    698535        return;
    699536    }
    700537
    701538    if (WKStringIsEqualToUTF8CString(messageName, "SetPluginSupportedMode")) {
    702         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
    703         WKStringRef mode = static_cast<WKStringRef>(messageBody);
     539        WKStringRef mode = stringValue(messageBody);
    704540        TestController::singleton().setPluginSupportedMode(toWTFString(mode));
    705541        return;
     
    707543
    708544    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));
    712546        return;
    713547    }
    714548
    715549    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));
    719551        return;
    720552    }
    721553
    722554    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));
    726556        return;
    727557    }
    728558   
    729559    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));
    733561        return;
    734562    }
    735563
    736564    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));
    740566        return;
    741567    }
    742568
    743569    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));
    747571        return;
    748572    }
    749573
    750574    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);
    754576        return;
    755577    }
    756578
    757579    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);
    761581        return;
    762582    }
    763583
    764584    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;
    770587        invocationData->testInvocation = this;
    771         invocationData->callbackID = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, callbackIDKey.get())));
    772         invocationData->scriptString = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, scriptKey.get()));
     588        invocationData->callbackID = uint64Value(messageBodyDictionary, "CallbackID");
     589        invocationData->scriptString = stringValue(messageBodyDictionary, "Script");
    773590        m_pendingUIScriptInvocationData = invocationData;
    774591        WKPageCallAfterNextPresentationUpdate(TestController::singleton().mainWebView()->page(), invocationData, runUISideScriptAfterUpdateCallback);
     
    777594
    778595    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;
    784598        invocationData->testInvocation = this;
    785         invocationData->callbackID = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, callbackIDKey.get())));
    786         invocationData->scriptString = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, scriptKey.get()));
     599        invocationData->callbackID = uint64Value(messageBodyDictionary, "CallbackID");
     600        invocationData->scriptString = stringValue(messageBodyDictionary, "Script");
    787601        m_pendingUIScriptInvocationData = invocationData;
    788602        runUISideScriptImmediately(nullptr, invocationData);
     
    792606    if (WKStringIsEqualToUTF8CString(messageName, "InstallCustomMenuAction")) {
    793607        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);
    799611        return;
    800612    }
     
    806618        actions.reserveInitialCapacity(size);
    807619        for (size_t index = 0; index < size; ++index)
    808             actions.append(toWTFString(static_cast<WKStringRef>(WKArrayGetItemAtIndex(messageBodyArray, index))));
     620            actions.append(toWTFString(stringValue(WKArrayGetItemAtIndex(messageBodyArray, index))));
    809621        TestController::singleton().setAllowedMenuActions(actions);
    810622        return;
     
    829641
    830642    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));
    834644        return;
    835645    }
    836646
    837647    if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsPrevalentResourceForDebugMode")) {
    838         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
    839         WKStringRef hostName = static_cast<WKStringRef>(messageBody);
     648        WKStringRef hostName = stringValue(messageBody);
    840649        TestController::singleton().setStatisticsPrevalentResourceForDebugMode(hostName);
    841650        return;
     
    843652
    844653    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);
    855658        return;
    856659    }
    857660
    858661    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);
    886674        return;
    887675    }
    888676   
    889677    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);
    905684        return;
    906685    }
    907686
    908687    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);
    919692        return;
    920693    }
    921694
    922695    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);
    933700        return;
    934701    }
     
    945712
    946713    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));
    950715        return;
    951716    }
    952717
    953718    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));
    957720        return;
    958721    }
    959722
    960723    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));
    964725        return;
    965726    }
    966727
    967728    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));
    971730        return;
    972731    }
    973732
    974733    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");
    984737        TestController::singleton().setStatisticsFirstPartyHostCNAMEDomain(firstPartyURLString, cnameURLString);
    985738        return;
     
    987740
    988741    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));
    992743        return;
    993744    }
     
    1013764#ifdef __BLOCKS__
    1014765        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");
    1017767        });
    1018768#else
     
    1024774
    1025775    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);
    1036780        return;
    1037781    }
     
    1044788    if (WKStringIsEqualToUTF8CString(messageName, "SetAppBoundDomains")) {
    1045789        ASSERT(WKGetTypeID(messageBody) == WKArrayGetTypeID());
    1046         WKArrayRef originURLs = static_cast<WKArrayRef>(messageBody);
    1047         TestController::singleton().setAppBoundDomains(originURLs);
     790        TestController::singleton().setAppBoundDomains(static_cast<WKArrayRef>(messageBody));
    1048791        return;
    1049792    }
     
    1056799    if (WKStringIsEqualToUTF8CString(messageName, "Initialization")) {
    1057800        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);
    1061802        return settings;
    1062803    }
    1063804
    1064805    if (WKStringIsEqualToUTF8CString(messageName, "SetDumpPixels")) {
    1065         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
    1066         m_dumpPixels = WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody));
     806        m_dumpPixels = booleanValue(messageBody);
    1067807        return nullptr;
    1068808    }
     
    1071811
    1072812    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));
    1075814        return nullptr;
    1076815    }
     
    1079818
    1080819    if (WKStringIsEqualToUTF8CString(messageName, "SetWaitUntilDone")) {
    1081         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
    1082         setWaitUntilDone(static_cast<unsigned char>(WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody))));
     820        setWaitUntilDone(booleanValue(messageBody));
    1083821        return nullptr;
    1084822    }
     
    1087825
    1088826    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);
    1091828        return nullptr;
    1092829    }
     
    1095832
    1096833    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);
    1099835        return nullptr;
    1100836    }
    1101837
    1102838    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));
    1106840        return nullptr;
    1107841    }
    1108842
    1109843    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()));
    1128853
    1129854    if (WKStringIsEqualToUTF8CString(messageName, "SetCacheModel")) {
    1130         ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());
    1131         uint64_t model = WKUInt64GetValue(static_cast<WKUInt64Ref>(messageBody));
     855        uint64_t model = uint64Value(messageBody);
    1132856        WKWebsiteDataStoreSetCacheModelSynchronouslyForTesting(TestController::singleton().websiteDataStore(), model);
    1133857        return nullptr;
    1134858    }
    1135859
    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()));
    1146865
    1147866    if (WKStringIsEqualToUTF8CString(messageName, "ClearDidReceiveServerRedirectForProvisionalNavigation")) {
     
    1151870
    1152871    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()));
    1155874#else
    1156         WKRetainPtr<WKBooleanRef> result = adoptWK(WKBooleanCreate(false));
     875        return adoptWK(WKBooleanCreate(false));
    1157876#endif
    1158         return result;
    1159877    }
    1160878
    1161879    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));
    1164881        return nullptr;
    1165882    }
    1166883
    1167884    if (WKStringIsEqualToUTF8CString(messageName, "SetAllowsAnySSLCertificate")) {
    1168         TestController::singleton().setAllowsAnySSLCertificate(WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody)));
     885        TestController::singleton().setAllowsAnySSLCertificate(booleanValue(messageBody));
    1169886        return nullptr;
    1170887    }
    1171888   
    1172889    if (WKStringIsEqualToUTF8CString(messageName, "SetShouldSwapToEphemeralSessionOnNextNavigation")) {
    1173         TestController::singleton().setShouldSwapToEphemeralSessionOnNextNavigation(WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody)));
     890        TestController::singleton().setShouldSwapToEphemeralSessionOnNextNavigation(booleanValue(messageBody));
    1174891        return nullptr;
    1175892    }
    1176893   
    1177894    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()));
    1187901   
    1188902    if (WKStringIsEqualToUTF8CString(messageName, "DeleteAllIndexedDatabases")) {
     
    1192906
    1193907    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");
    1205912        TestController::singleton().addMockMediaDevice(persistentID, label, type);
    1206913        return nullptr;
     
    1213920
    1214921    if (WKStringIsEqualToUTF8CString(messageName, "RemoveMockMediaDevice")) {
    1215         WKStringRef persistentId = static_cast<WKStringRef>(messageBody);
    1216 
    1217         TestController::singleton().removeMockMediaDevice(persistentId);
     922        TestController::singleton().removeMockMediaDevice(stringValue(messageBody));
    1218923        return nullptr;
    1219924    }
     
    1225930
    1226931    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()));
    1240941
    1241942#if PLATFORM(MAC)
    1242943    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));
    1248945        return nullptr;
    1249946    }
    1250947
    1251948    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));
    1257950        return nullptr;
    1258951    }
    1259952
    1260953    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);
    1277961        return nullptr;
    1278962    }
    1279963
    1280964    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);
    1294970        return nullptr;
    1295971    }
    1296972
    1297973    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);
    1311979        return nullptr;
    1312980    }
     
    1314982
    1315983    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");
    1325987        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()));
    1333993   
    1334994    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));
    1339996        return nullptr;
    1340997    }
    1341998
    1342999    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));
    13501004    }
    13511005
    13521006    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));
    13561008        return nullptr;
    13571009    }
    13581010
    13591011    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()));
    13631013    }
    13641014   
     
    13691019
    13701020    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));
    13771023    }
    13781024
    13791025    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));
    13861028    }
    13871029   
    13881030    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");
    13981034        bool isRegisteredAsSubresourceUnder = TestController::singleton().isStatisticsRegisteredAsSubresourceUnder(subresourceHost, topFrameHost);
    1399         WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(isRegisteredAsSubresourceUnder));
    1400         return result;
     1035        return adoptWK(WKBooleanCreate(isRegisteredAsSubresourceUnder));
    14011036    }
    14021037   
    14031038    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");
    14131042        bool isRegisteredAsSubFrameUnder = TestController::singleton().isStatisticsRegisteredAsSubFrameUnder(subFrameHost, topFrameHost);
    1414         WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(isRegisteredAsSubFrameUnder));
    1415         return result;
     1043        return adoptWK(WKBooleanCreate(isRegisteredAsSubFrameUnder));
    14161044    }
    14171045   
    14181046    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");
    14281050        bool isRegisteredAsRedirectingTo = TestController::singleton().isStatisticsRegisteredAsRedirectingTo(hostRedirectedFrom, hostRedirectedTo);
    1429         WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(isRegisteredAsRedirectingTo));
    1430         return result;
     1051        return adoptWK(WKBooleanCreate(isRegisteredAsRedirectingTo));
    14311052    }
    14321053
    14331054    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));
    14401057    }
    14411058   
    14421059    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");
    14521063        bool statisticInDatabaseOnce = TestController::singleton().isStatisticsOnlyInDatabaseOnce(subHost, topHost);
    14531064        return adoptWK(WKBooleanCreate(statisticInDatabaseOnce));
     
    14551066   
    14561067    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);
    14671072        return nullptr;
    14681073    }
    14691074   
    14701075    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));
    14771078    }
    14781079   
    14791080    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");
    14891084        TestController::singleton().setStatisticsSubframeUnderTopFrameOrigin(hostName, topFrameHostName);
    14901085        return nullptr;
     
    14921087   
    14931088    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");
    15031092        TestController::singleton().setStatisticsSubresourceUnderTopFrameOrigin(hostName, topFrameHostName);
    15041093        return nullptr;
     
    15061095   
    15071096    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");
    15171100        TestController::singleton().setStatisticsSubresourceUniqueRedirectTo(hostName, hostNameRedirectedTo);
    15181101        return nullptr;
     
    15201103
    15211104    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");
    15311108        TestController::singleton().setStatisticsSubresourceUniqueRedirectFrom(hostName, hostNameRedirectedFrom);
    15321109        return nullptr;
     
    15341111   
    15351112    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");
    15451116        TestController::singleton().setStatisticsTopFrameUniqueRedirectTo(hostName, hostNameRedirectedTo);
    15461117        return nullptr;
     
    15481119   
    15491120    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");
    15591124        TestController::singleton().setStatisticsTopFrameUniqueRedirectFrom(hostName, hostNameRedirectedFrom);
    15601125        return nullptr;
     
    15621127   
    15631128    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");
    15731132        TestController::singleton().setStatisticsCrossSiteLoadWithLinkDecoration(fromHost, toHost);
    15741133        return nullptr;
     
    15761135
    15771136    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));
    15811138        return nullptr;
    15821139    }
     
    15931150
    15941151    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));
    15981153        return nullptr;
    15991154    }
    16001155
    16011156    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));
    16051158        return nullptr;
    16061159    }
    16071160   
    16081161    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));
    16121163        return nullptr;
    16131164    }
    16141165
    16151166    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));
    16191168        return nullptr;
    16201169    }
    16211170   
    16221171    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));
    16261173        return nullptr;
    16271174    }
    16281175   
    16291176    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));
    16331178        return nullptr;
    16341179    }
    16351180   
    16361181    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));
    16401183        return nullptr;
    16411184    }
    16421185
    16431186    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);
    16541191        return nullptr;
    16551192    }
    16561193
    16571194    if (WKStringIsEqualToUTF8CString(messageName, "IsStatisticsHasLocalStorage")) {
    1658         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
    1659        
    1660         WKStringRef hostName = static_cast<WKStringRef>(messageBody);
     1195        auto hostName = stringValue(messageBody);
    16611196        bool hasLocalStorage = TestController::singleton().isStatisticsHasLocalStorage(hostName);
    16621197        auto result = adoptWK(WKBooleanCreate(hasLocalStorage));
     
    16651200
    16661201    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));
    16701203        return nullptr;
    16711204    }
    16721205
    16731206    if (WKStringIsEqualToUTF8CString(messageName, "HasStatisticsIsolatedSession")) {
    1674         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
    1675        
    1676         WKStringRef hostName = static_cast<WKStringRef>(messageBody);
     1207        auto hostName = stringValue(messageBody);
    16771208        bool hasIsolatedSession = TestController::singleton().hasStatisticsIsolatedSession(hostName);
    16781209        auto result = adoptWK(WKBooleanCreate(hasIsolatedSession));
     
    16811212
    16821213    if (WKStringIsEqualToUTF8CString(messageName, "ClearDOMCache")) {
    1683         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
    1684         WKStringRef origin = static_cast<WKStringRef>(messageBody);
    1685 
     1214        auto origin = stringValue(messageBody);
    16861215        TestController::singleton().clearDOMCache(origin);
    16871216        return nullptr;
     
    16941223
    16951224    if (WKStringIsEqualToUTF8CString(messageName, "HasDOMCache")) {
    1696         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
    1697         WKStringRef origin = static_cast<WKStringRef>(messageBody);
    1698 
     1225        auto origin = stringValue(messageBody);
    16991226        bool hasDOMCache = TestController::singleton().hasDOMCache(origin);
    1700         WKRetainPtr<WKTypeRef> result = adoptWK(WKBooleanCreate(hasDOMCache));
    1701         return result;
     1227        return adoptWK(WKBooleanCreate(hasDOMCache));
    17021228    }
    17031229
    17041230    if (WKStringIsEqualToUTF8CString(messageName, "DOMCacheSize")) {
    1705         ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
    1706         WKStringRef origin = static_cast<WKStringRef>(messageBody);
    1707 
     1231        auto origin = stringValue(messageBody);
    17081232        auto domCacheSize = TestController::singleton().domCacheSize(origin);
    1709         WKRetainPtr<WKTypeRef> result = adoptWK(WKUInt64Create(domCacheSize));
    1710         return result;
     1233        return adoptWK(WKUInt64Create(domCacheSize));
    17111234    }
    17121235
    17131236    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));
    17171238        return nullptr;
    17181239    }
    17191240
    17201241    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));
    17251243        return nullptr;
    17261244    }
     
    17321250
    17331251    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));
    17371253        return nullptr;
    17381254    }
    17391255
    17401256    if (WKStringIsEqualToUTF8CString(messageName, "SetUseSeparateServiceWorkerProcess")) {
    1741         ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
    1742         auto useSeparateServiceWorkerProcess = WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody));
     1257        auto useSeparateServiceWorkerProcess = booleanValue(messageBody);
    17431258        WKContextSetUseSeparateServiceWorkerProcess(TestController::singleton().context(), useSeparateServiceWorkerProcess);
    17441259        return nullptr;
     
    17581273
    17591274    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");
    17721279        TestController::singleton().addTestKeyToKeychain(toWTFString(privateKeyWK), toWTFString(attrLabelWK), toWTFString(applicationTagWK));
    17731280        return nullptr;
     
    17751282
    17761283    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");
    17861287        TestController::singleton().cleanUpKeychain(toWTFString(attrLabelWK), applicationLabelWK ? toWTFString(applicationLabelWK) : String());
    17871288        return nullptr;
     
    17891290
    17901291    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");
    18001295        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()));
    18091301
    18101302    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));
    18141304        return nullptr;
    18151305    }
     
    18411331
    18421332    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));
    18461334        return nullptr;
    18471335    }
     
    18491337    if (WKStringIsEqualToUTF8CString(messageName, "SetAdClickAttributionConversionURLForTesting")) {
    18501338        ASSERT(WKGetTypeID(messageBody) == WKURLGetTypeID());
    1851         WKURLRef url = static_cast<WKURLRef>(messageBody);
    1852         TestController::singleton().setAdClickAttributionConversionURLForTesting(url);
     1339        TestController::singleton().setAdClickAttributionConversionURLForTesting(static_cast<WKURLRef>(messageBody));
    18531340        return nullptr;
    18541341    }
     
    18951382void TestInvocation::uiScriptDidComplete(const String& result, unsigned scriptCallbackID)
    18961383{
    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);
    19081388}
    19091389
     
    19151395void TestInvocation::didBeginSwipe()
    19161396{
    1917     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidBeginSwipeCallback"));
    1918     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1397    postPageMessage("CallDidBeginSwipeCallback");
    19191398}
    19201399
    19211400void TestInvocation::willEndSwipe()
    19221401{
    1923     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallWillEndSwipeCallback"));
    1924     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1402    postPageMessage("CallWillEndSwipeCallback");
    19251403}
    19261404
    19271405void TestInvocation::didEndSwipe()
    19281406{
    1929     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidEndSwipeCallback"));
    1930     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1407    postPageMessage("CallDidEndSwipeCallback");
    19311408}
    19321409
    19331410void TestInvocation::didRemoveSwipeSnapshot()
    19341411{
    1935     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidRemoveSwipeSnapshotCallback"));
    1936     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1412    postPageMessage("CallDidRemoveSwipeSnapshotCallback");
    19371413}
    19381414
    19391415void TestInvocation::notifyDownloadDone()
    19401416{
    1941     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("NotifyDownloadDone"));
    1942     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1417    postPageMessage("NotifyDownloadDone");
    19431418}
    19441419
    19451420void TestInvocation::didClearStatisticsInMemoryAndPersistentStore()
    19461421{
    1947     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidClearStatisticsInMemoryAndPersistentStore"));
    1948     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1422    postPageMessage("CallDidClearStatisticsInMemoryAndPersistentStore");
    19491423}
    19501424
    19511425void TestInvocation::didClearStatisticsThroughWebsiteDataRemoval()
    19521426{
    1953     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidClearStatisticsThroughWebsiteDataRemoval"));
    1954     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1427    postPageMessage("CallDidClearStatisticsThroughWebsiteDataRemoval");
    19551428}
    19561429
    19571430void TestInvocation::didSetShouldDowngradeReferrer()
    19581431{
    1959     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetShouldDowngradeReferrer"));
    1960     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1432    postPageMessage("CallDidSetShouldDowngradeReferrer");
    19611433}
    19621434
    19631435void TestInvocation::didSetShouldBlockThirdPartyCookies()
    19641436{
    1965     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetShouldBlockThirdPartyCookies"));
    1966     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), nullptr);
     1437    postPageMessage("CallDidSetShouldBlockThirdPartyCookies");
    19671438}
    19681439
    19691440void TestInvocation::didSetFirstPartyWebsiteDataRemovalMode()
    19701441{
    1971     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetFirstPartyWebsiteDataRemovalMode"));
    1972     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), nullptr);
     1442    postPageMessage("CallDidSetFirstPartyWebsiteDataRemovalMode");
    19731443}
    19741444
    19751445void TestInvocation::didSetToSameSiteStrictCookies()
    19761446{
    1977     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetToSameSiteStrictCookies"));
    1978     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), nullptr);
     1447    postPageMessage("CallDidSetToSameSiteStrictCookies");
    19791448}
    19801449
    19811450void TestInvocation::didSetFirstPartyHostCNAMEDomain()
    19821451{
    1983     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetFirstPartyHostCNAMEDomain"));
    1984     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), nullptr);
     1452    postPageMessage("CallDidSetFirstPartyHostCNAMEDomain");
    19851453}
    19861454
    19871455void TestInvocation::didSetThirdPartyCNAMEDomain()
    19881456{
    1989     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetThirdPartyCNAMEDomain"));
    1990     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), nullptr);
     1457    postPageMessage("CallDidSetThirdPartyCNAMEDomain");
    19911458}
    19921459
    19931460void TestInvocation::didResetStatisticsToConsistentState()
    19941461{
    1995     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidResetStatisticsToConsistentState"));
    1996     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1462    postPageMessage("CallDidResetStatisticsToConsistentState");
    19971463}
    19981464
    19991465void TestInvocation::didSetBlockCookiesForHost()
    20001466{
    2001     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetBlockCookiesForHost"));
    2002     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1467    postPageMessage("CallDidSetBlockCookiesForHost");
    20031468}
    20041469
    20051470void TestInvocation::didSetStatisticsDebugMode()
    20061471{
    2007     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetStatisticsDebugMode"));
    2008     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1472    postPageMessage("CallDidSetStatisticsDebugMode");
    20091473}
    20101474
    20111475void TestInvocation::didSetPrevalentResourceForDebugMode()
    20121476{
    2013     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetPrevalentResourceForDebugMode"));
    2014     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1477    postPageMessage("CallDidSetPrevalentResourceForDebugMode");
    20151478}
    20161479
    20171480void TestInvocation::didSetLastSeen()
    20181481{
    2019     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetLastSeen"));
    2020     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1482    postPageMessage("CallDidSetLastSeen");
    20211483}
    20221484
    20231485void TestInvocation::didMergeStatistic()
    20241486{
    2025     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidMergeStatistic"));
    2026     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1487    postPageMessage("CallDidMergeStatistic");
    20271488}
    20281489
    20291490void TestInvocation::didSetExpiredStatistic()
    20301491{
    2031     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetExpiredStatistic"));
    2032     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1492    postPageMessage("CallDidSetExpiredStatistic");
    20331493}
    20341494
    20351495void TestInvocation::didSetPrevalentResource()
    20361496{
    2037     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetPrevalentResource"));
    2038     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1497    postPageMessage("CallDidSetPrevalentResource");
    20391498}
    20401499
    20411500void TestInvocation::didSetVeryPrevalentResource()
    20421501{
    2043     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetVeryPrevalentResource"));
    2044     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1502    postPageMessage("CallDidSetVeryPrevalentResource");
    20451503}
    20461504
    20471505void TestInvocation::didSetHasHadUserInteraction()
    20481506{
    2049     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetHasHadUserInteraction"));
    2050     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1507    postPageMessage("CallDidSetHasHadUserInteraction");
    20511508}
    20521509
    20531510void TestInvocation::didReceiveAllStorageAccessEntries(Vector<String>&& domains)
    20541511{
    2055     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidReceiveAllStorageAccessEntries"));
    2056    
    2057     WKRetainPtr<WKMutableArrayRef> messageBody = adoptWK(WKMutableArrayCreate());
     1512    auto messageBody = adoptWK(WKMutableArrayCreate());
    20581513    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);
    20621516}
    20631517
    20641518void TestInvocation::didReceiveLoadedSubresourceDomains(Vector<String>&& domains)
    20651519{
    2066     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidReceiveLoadedSubresourceDomains"));
    2067    
    2068     WKRetainPtr<WKMutableArrayRef> messageBody = adoptWK(WKMutableArrayCreate());
     1520    auto messageBody = adoptWK(WKMutableArrayCreate());
    20691521    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);
    20731524}
    20741525
    20751526void TestInvocation::didRemoveAllSessionCredentials()
    20761527{
    2077     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidRemoveAllSessionCredentialsCallback"));
    2078     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1528    postPageMessage("CallDidRemoveAllSessionCredentialsCallback");
    20791529}
    20801530
    20811531void TestInvocation::didSetAppBoundDomains()
    20821532{
    2083     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetAppBoundDomains"));
    2084     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), nullptr);
     1533    postPageMessage("CallDidSetAppBoundDomains");
    20851534}
    20861535
     
    20971546void TestInvocation::performCustomMenuAction()
    20981547{
    2099     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("PerformCustomMenuAction"));
    2100     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
     1548    postPageMessage("PerformCustomMenuAction");
    21011549}
    21021550
  • TabularUnified trunk/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj

    r267120 r267761  
    356356                841CC00E181185BF0042E9B6 /* Options.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Options.h; sourceTree = "<group>"; };
    357357                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>"; };
    358360                93764176210D736000A3DAAE /* WebKitTestRunnerWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebKitTestRunnerWindow.mm; sourceTree = "<group>"; };
    359361                93764177210D736100A3DAAE /* WebKitTestRunnerWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitTestRunnerWindow.h; sourceTree = "<group>"; };
     
    893895                        children = (
    894896                                378D442213346D00006A777B /* config.h */,
     897                                9338D1BE250BD9DD00E827F6 /* DictionaryFunctions.h */,
    895898                                BC99A4841208901A007E9F08 /* StringFunctions.h */,
    896899                                9B36A270209453A0003E0651 /* WhatToDump.h */,
  • TabularUnified trunk/Tools/WebKitTestRunner/WebNotificationProvider.cpp

    r244390 r267761  
    127127    removeGlobalIDFromIDMap(m_localToGlobalNotificationIDMap, id);
    128128
    129     WKRetainPtr<WKUInt64Ref> wkID = adoptWK(WKUInt64Create(id));
    130     WKRetainPtr<WKMutableArrayRef> array = adoptWK(WKMutableArrayCreate());
     129    auto wkID = adoptWK(WKUInt64Create(id));
     130    auto array = adoptWK(WKMutableArrayCreate());
    131131    WKArrayAppendItem(array.get(), wkID.get());
    132132    WKNotificationManagerProviderDidCloseNotifications(notificationManager, array.get());
     
    145145    WKRetainPtr<WKNotificationManagerRef> guard(manager);
    146146    m_ownedNotifications.remove(iterator);
    147     WKRetainPtr<WKMutableArrayRef> array = adoptWK(WKMutableArrayCreate());
     147    auto array = adoptWK(WKMutableArrayCreate());
    148148    for (uint64_t notificationID : toRemove) {
    149149        bool success = m_owningManager.remove(notificationID);
     
    174174        if (notificationPair.value.isEmpty())
    175175            continue;
    176         WKRetainPtr<WKMutableArrayRef> array = adoptWK(WKMutableArrayCreate());
     176        auto array = adoptWK(WKMutableArrayCreate());
    177177        for (uint64_t notificationID : notificationPair.value)
    178178            WKArrayAppendItem(array.get(), adoptWK(WKUInt64Create(notificationID)).get());
  • TabularUnified trunk/Tools/WebKitTestRunner/WorkQueueManager.cpp

    r244390 r267761  
    2828
    2929#include "PlatformWebView.h"
     30#include "StringFunctions.h"
    3031#include "TestController.h"
    3132#include <WebKit/WKPage.h>
     
    7677public:
    7778    explicit ScriptItem(const String& script)
    78         : m_script(adoptWK(WKStringCreateWithUTF8CString(script.utf8().data())))
     79        : m_script(toWK(script))
    7980    {
    8081    }
     
    162163    public:
    163164        LoadHTMLStringItem(const String& content, const String& baseURL, const String& unreachableURL)
    164             : m_content(adoptWK(WKStringCreateWithUTF8CString(content.utf8().data())))
     165            : m_content(toWK(content))
    165166            , m_baseURL(adoptWK(WKURLCreateWithUTF8CString(baseURL.utf8().data())))
    166167            , m_unreachableURL(adoptWK(WKURLCreateWithUTF8CString(unreachableURL.utf8().data())))
  • TabularUnified trunk/Tools/WebKitTestRunner/cg/TestInvocationCG.cpp

    r263759 r267761  
    5353
    5454    // 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());
    5656    CGContextRef context = CGBitmapContextCreate(0, pixelsWide, pixelsHigh, 8, rowBytes, colorSpace.get(), kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);
    5757    if (!context)
     
    6464static CGContextRef createCGContextFromImage(WKImageRef wkImage)
    6565{
    66     RetainPtr<CGImageRef> image = adoptCF(WKImageCreateCGImage(wkImage));
     66    auto image = adoptCF(WKImageCreateCGImage(wkImage));
    6767    return createCGContextFromCGImage(image.get());
    6868}
     
    110110static void dumpBitmap(CGContextRef bitmapContext, const char* checksum)
    111111{
    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));
    115115    CGImageDestinationAddImage(imageDest.get(), image.get(), 0);
    116116    CGImageDestinationFinalize(imageDest.get());
  • TabularUnified trunk/Tools/WebKitTestRunner/cocoa/CrashReporterInfo.mm

    r264957 r267761  
    3636static String testPathFromURL(WKURLRef url)
    3737{
    38     RetainPtr<CFURLRef> cfURL = adoptCF(WKURLCopyCFURL(kCFAllocatorDefault, url));
     38    auto cfURL = adoptCF(WKURLCopyCFURL(kCFAllocatorDefault, url));
    3939    if (!cfURL)
    4040        return String();
    4141
    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()));
    4444
    4545    String schemeString(schemeCFString.get());
     
    5858        return String();
    5959
    60     RetainPtr<CFStringRef> hostCFString = adoptCF(CFURLCopyHostName(cfURL.get()));
     60    auto hostCFString = adoptCF(CFURLCopyHostName(cfURL.get()));
    6161    String hostString(hostCFString.get());
    6262    if (hostString == "127.0.0.1")
  • TabularUnified trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm

    r267088 r267761  
    143143void TestController::platformCreateWebView(WKPageConfigurationRef, const TestOptions& options)
    144144{
    145     RetainPtr<WKWebViewConfiguration> copiedConfiguration = adoptNS([globalWebViewConfiguration copy]);
     145    auto copiedConfiguration = adoptNS([globalWebViewConfiguration copy]);
    146146
    147147#if PLATFORM(IOS_FAMILY)
  • TabularUnified trunk/Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.mm

    r265211 r267761  
    9191IGNORE_WARNINGS_END
    9292{
    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]);
    9494    [self draggingUpdated:draggingInfo.get()];
    9595}
  • TabularUnified trunk/Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.h

    r267120 r267761  
    3333
    3434class UIScriptControllerCocoa : public UIScriptControllerCommon {
    35 public:
     35protected:
     36    explicit UIScriptControllerCocoa(UIScriptContext&);
     37    TestRunnerWKWebView *webView() const;
     38
     39    void doAsyncTask(JSValueRef) override;
     40
     41private:
    3642    void setViewScale(double) override;
    3743    void setMinimumEffectiveWidth(double) override;
    3844    void becomeFirstResponder() override;
    3945    void resignFirstResponder() override;
    40     void doAsyncTask(JSValueRef) override;
    4146    void removeViewFromWindow(JSValueRef) override;
    4247    void addViewToWindow(JSValueRef) override;
     
    6065    void insertAttachmentForFilePath(JSStringRef filePath, JSStringRef contentType, JSValueRef callback) override;
    6166
    62 protected:
    63     explicit UIScriptControllerCocoa(UIScriptContext&);
    64     TestRunnerWKWebView *webView() const;
    65 
    66 private:
    6767    void completeTaskAsynchronouslyAfterActivityStateUpdate(unsigned callbackID);
    6868};
  • TabularUnified trunk/Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm

    r267120 r267761  
    136136void UIScriptControllerCocoa::overridePreference(JSStringRef preferenceRef, JSStringRef valueRef)
    137137{
    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();
    144140}
    145141
    146142void UIScriptControllerCocoa::findString(JSStringRef string, unsigned long options, unsigned long maxCount)
    147143{
    148     [webView() _findString:toWTFString(toWK(string)) options:options maxCount:maxCount];
     144    [webView() _findString:toWTFString(string) options:options maxCount:maxCount];
    149145}
    150146
    151147JSObjectRef UIScriptControllerCocoa::contentsOfUserInterfaceItem(JSStringRef interfaceItem) const
    152148{
    153     NSDictionary *contentDictionary = [webView() _contentsOfUserInterfaceItem:toWTFString(toWK(interfaceItem))];
     149    NSDictionary *contentDictionary = [webView() _contentsOfUserInterfaceItem:toWTFString(interfaceItem)];
    154150    return JSValueToObject(m_context->jsContext(), [JSValue valueWithObject:contentDictionary inContext:[JSContext contextWithJSGlobalContextRef:m_context->jsContext()]].JSValueRef, nullptr);
    155151}
     
    220216{
    221217    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) {
    228222        if (!m_context)
    229223            return;
  • TabularUnified trunk/Tools/WebKitTestRunner/ios/HIDEventGenerator.mm

    r259843 r267761  
    190190- (void)_sendIOHIDKeyboardEvent:(uint64_t)timestamp usage:(uint32_t)usage isKeyDown:(bool)isKeyDown
    191191{
    192     RetainPtr<IOHIDEventRef> eventRef = adoptCF(IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault,
     192    auto eventRef = adoptCF(IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault,
    193193        timestamp,
    194194        kHIDPage_KeyboardOrKeypad,
     
    362362
    363363    uint64_t machTime = mach_absolute_time();
    364     RetainPtr<IOHIDEventRef> eventRef = adoptCF(IOHIDEventCreateDigitizerEvent(kCFAllocatorDefault, machTime,
     364    auto eventRef = adoptCF(IOHIDEventCreateDigitizerEvent(kCFAllocatorDefault, machTime,
    365365        kIOHIDDigitizerTransducerTypeHand,
    366366        0,
     
    454454
    455455    if (eventRef) {
    456         RetainPtr<IOHIDEventRef> strongEvent = eventRef;
     456        auto strongEvent = retainPtr(eventRef);
    457457        dispatch_async(dispatch_get_main_queue(), ^{
    458458            uint32_t contextID = [UIApplication sharedApplication].keyWindow._contextId;
     
    513513    }
    514514   
    515     RetainPtr<IOHIDEventRef> eventRef = adoptCF([self _createIOHIDEventType:handEventType]);
     515    auto eventRef = adoptCF([self _createIOHIDEventType:handEventType]);
    516516    [self _sendHIDEvent:eventRef.get()];
    517517}
     
    530530    }
    531531
    532     RetainPtr<IOHIDEventRef> eventRef = adoptCF([self _createIOHIDEventType:HandEventTouched]);
     532    auto eventRef = adoptCF([self _createIOHIDEventType:HandEventTouched]);
    533533    [self _sendHIDEvent:eventRef.get()];
    534534}
     
    564564    }
    565565   
    566     RetainPtr<IOHIDEventRef> eventRef = adoptCF([self _createIOHIDEventType:HandEventLifted]);
     566    auto eventRef = adoptCF([self _createIOHIDEventType:HandEventLifted]);
    567567    [self _sendHIDEvent:eventRef.get()];
    568568   
     
    642642    _activePoints[0].altitudeAngle = M_PI_2 - altitudeAngle;
    643643
    644     RetainPtr<IOHIDEventRef> eventRef = adoptCF([self _createIOHIDEventType:StylusEventTouched]);
     644    auto eventRef = adoptCF([self _createIOHIDEventType:StylusEventTouched]);
    645645    [self _sendHIDEvent:eventRef.get()];
    646646}
     
    656656    _activePoints[0].altitudeAngle = M_PI_2 - altitudeAngle;
    657657
    658     RetainPtr<IOHIDEventRef> eventRef = adoptCF([self _createIOHIDEventType:StylusEventMoved]);
     658    auto eventRef = adoptCF([self _createIOHIDEventType:StylusEventMoved]);
    659659    [self _sendHIDEvent:eventRef.get()];
    660660}
     
    669669    _activePoints[0].altitudeAngle = 0;
    670670
    671     RetainPtr<IOHIDEventRef> eventRef = adoptCF([self _createIOHIDEventType:StylusEventLifted]);
     671    auto eventRef = adoptCF([self _createIOHIDEventType:StylusEventLifted]);
    672672    [self _sendHIDEvent:eventRef.get()];
    673673}
     
    10221022    ASSERT([NSThread isMainThread]);
    10231023
    1024     RetainPtr<IOHIDEventRef> eventRef = adoptCF([self _createIOHIDEventWithInfo:eventInfo]);
     1024    auto eventRef = adoptCF([self _createIOHIDEventWithInfo:eventInfo]);
    10251025    [self _sendHIDEvent:eventRef.get()];
    10261026}
  • TabularUnified trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.h

    r266342 r267761  
    2626#pragma once
    2727
     28#if PLATFORM(IOS_FAMILY)
     29
    2830#import "UIScriptControllerCocoa.h"
    2931#import <wtf/BlockPtr.h>
    30 
    31 #if PLATFORM(IOS_FAMILY)
    3232
    3333namespace WebCore {
     
    3838namespace WTR {
    3939
    40 class UIScriptControllerIOS : public UIScriptControllerCocoa {
     40class UIScriptControllerIOS final : public UIScriptControllerCocoa {
    4141public:
    4242    explicit UIScriptControllerIOS(UIScriptContext& context)
     
    4545    }
    4646
     47private:
    4748    void waitForOutstandingCallbacks() override;
    4849    void doAfterPresentationUpdate(JSValueRef) override;
     
    157158    void clearAllCallbacks() override;
    158159
    159 private:
    160160    void waitForModalTransitionToFinish() const;
    161161    void waitForSingleTapToReset() const;
  • TabularUnified trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

    r266342 r267761  
    6969}
    7070
    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 
    7971static Vector<String> parseModifierArray(JSContextRef context, JSValueRef arrayValue)
    8072{
     
    8375
    8476    // 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) };
    8979
    9080    if (!JSValueIsObject(context, arrayValue))
     
    9484    Vector<String> modifiers;
    9585    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)));
    10688    return modifiers;
    10789}
     
    515497
    516498    // 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);
    521502    }).get()];
    522503}
     
    535516    // Key can be either a single Unicode code point or the name of a special key (e.g. "downArrow").
    536517    // 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)];
    538519    [[HIDEventGenerator sharedHIDEventGenerator] sendMarkerHIDEventWithCompletionBlock:^{ /* Do nothing */ }];
    539520}
     
    543524    // Key can be either a single Unicode code point or the name of a special key (e.g. "downArrow").
    544525    // 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)];
    546527    [[HIDEventGenerator sharedHIDEventGenerator] sendMarkerHIDEventWithCompletionBlock:^{ /* Do nothing */ }];
    547528}
     
    551532    // Character can be either a single Unicode code point or the name of a special key (e.g. "downArrow").
    552533    // HIDEventGenerator knows how to map these special keys to the appropriate keycode.
    553     String inputString = toWTFString(toWK(character));
     534    auto inputString = toWTFString(character);
    554535    auto modifierFlags = parseModifierArray(m_context->jsContext(), modifierArray);
    555536
     
    728709
    729710    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] {
    731712        dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
    732713            // applyAutocorrection can call its completion handler synchronously,
     
    11581139void UIScriptControllerIOS::setKeyboardInputModeIdentifier(JSStringRef identifier)
    11591140{
    1160     TestController::singleton().setKeyboardInputModeIdentifier(toWTFString(toWK(identifier)));
     1141    TestController::singleton().setKeyboardInputModeIdentifier(toWTFString(identifier));
    11611142}
    11621143
     
    11791160JSObjectRef UIScriptControllerIOS::attachmentInfo(JSStringRef jsAttachmentIdentifier)
    11801161{
    1181     auto attachmentIdentifier = toWTFString(toWK(jsAttachmentIdentifier));
     1162    auto attachmentIdentifier = toWTFString(jsAttachmentIdentifier);
    11821163    _WKAttachment *attachment = [webView() _attachmentForIdentifier:attachmentIdentifier];
    11831164    _WKAttachmentInfo *attachmentInfo = attachment.info;
  • TabularUnified trunk/Tools/WebKitTestRunner/mac/EventSenderProxy.mm

    r267281 r267761  
    273273EventSenderProxy::EventSenderProxy(TestController* testController)
    274274    : 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
     278EventSenderProxy::~EventSenderProxy() = default;
    289279
    290280void EventSenderProxy::updateClickCountForButton(int button)
     
    395385RetainPtr<NSEvent> EventSenderProxy::beginPressureEvent(int stage)
    396386{
    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)
    398388        globalLocation:([m_testController->mainWebView()->platformWindow() convertRectToScreen:NSMakeRect(m_position.x, m_position.y, 1, 1)].origin)
    399389        stage:stage
     
    410400RetainPtr<NSEvent> EventSenderProxy::pressureChangeEvent(int stage, float pressure, EventSenderProxy::PressureChangeDirection direction)
    411401{
    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)
    413403        globalLocation:([m_testController->mainWebView()->platformWindow() convertRectToScreen:NSMakeRect(m_position.x, m_position.y, 1, 1)].origin)
    414404        stage:stage
     
    432422    sendMouseDownToStartPressureEvents();
    433423
    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);
    438428    NSEvent *mouseUp = [NSEvent mouseEventWithType:NSEventTypeLeftMouseUp
    439429        location:NSMakePoint(m_position.x, m_position.y)
     
    469459    sendMouseDownToStartPressureEvents();
    470460
    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);
    474464    NSEvent *mouseUp = [NSEvent mouseEventWithType:NSEventTypeLeftMouseUp
    475465        location:NSMakePoint(m_position.x, m_position.y)
     
    504494    sendMouseDownToStartPressureEvents();
    505495
    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);
    509499
    510500    NSView *targetView = [m_testController->mainWebView()->platformView() hitTest:[beginPressure locationInWindow]];
     
    527517void EventSenderProxy::mouseForceUp()
    528518{
    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);
    532522
    533523    // Since AppKit does not implement forceup/down as mouse events, we need to send two pressure events to detect
     
    552542    int stage = force < 1 ? 1 : 2;
    553543    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);
    556546
    557547    NSView *targetView = [m_testController->mainWebView()->platformView() hitTest:[beginPressure locationInWindow]];
     
    612602void EventSenderProxy::keyDown(WKStringRef key, WKEventModifiers modifiers, unsigned keyLocation)
    613603{
    614     NSString* character = [NSString stringWithCString:toSTD(key).c_str()
    615                                    encoding:[NSString defaultCStringEncoding]];
     604    NSString* character = toWTFString(key);
    616605
    617606    NSString *eventCharacter = character;
     
    833822void EventSenderProxy::mouseScrollBy(int x, int y)
    834823{
    835     RetainPtr<CGEventRef> cgScrollEvent = adoptCF(CGEventCreateScrollWheelEvent2(0, kCGScrollEventUnitLine, 2, y, x, 0));
     824    auto cgScrollEvent = adoptCF(CGEventCreateScrollWheelEvent2(0, kCGScrollEventUnitLine, 2, y, x, 0));
    836825
    837826    // Set the CGEvent location in flipped coords relative to the first screen, which
     
    860849void EventSenderProxy::mouseScrollByWithWheelAndMomentumPhases(int x, int y, int phase, int momentum)
    861850{
    862     RetainPtr<CGEventRef> cgScrollEvent = adoptCF(CGEventCreateScrollWheelEvent2(0, kCGScrollEventUnitLine, 2, y, x, 0));
     851    auto cgScrollEvent = adoptCF(CGEventCreateScrollWheelEvent2(0, kCGScrollEventUnitLine, 2, y, x, 0));
    863852
    864853    // Set the CGEvent location in flipped coords relative to the first screen, which
  • TabularUnified trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm

    r259843 r267761  
    6565        [[NSUserDefaults standardUserDefaults] setValue:@YES forKey:@"WebKit2UseRemoteLayerTreeDrawingArea"];
    6666
    67     RetainPtr<WKWebViewConfiguration> copiedConfiguration = adoptNS([configuration copy]);
     67    auto copiedConfiguration = adoptNS([configuration copy]);
    6868    WKPreferencesSetThreadedScrollingEnabled((__bridge WKPreferencesRef)[copiedConfiguration preferences], m_options.useThreadedScrolling);
    6969
  • TabularUnified trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm

    r265396 r267761  
    185185        return;
    186186
    187     RetainPtr<CFURLRef> testURL = adoptCF(WKURLCopyCFURL(kCFAllocatorDefault, test.url()));
     187    auto testURL = adoptCF(WKURLCopyCFURL(kCFAllocatorDefault, test.url()));
    188188    NSURL *filterURL = [(__bridge NSURL *)testURL.get() URLByAppendingPathExtension:@"json"];
    189189
     
    372372static WKRetainPtr<WKArrayRef> generateFontAllowList()
    373373{
    374     WKRetainPtr<WKMutableArrayRef> result = adoptWK(WKMutableArrayCreate());
     374    auto result = adoptWK(WKMutableArrayCreate());
    375375    for (NSString *fontFamily in allowedFontFamilySet()) {
    376376        NSArray *fontsForFamily = [[NSFontManager sharedFontManager] availableMembersOfFontFamily:fontFamily];
    377         WKRetainPtr<WKStringRef> familyInFont = adoptWK(WKStringCreateWithUTF8CString([fontFamily UTF8String]));
     377        auto familyInFont = adoptWK(WKStringCreateWithUTF8CString([fontFamily UTF8String]));
    378378        WKArrayAppendItem(result.get(), familyInFont.get());
    379379        for (NSArray *fontInfo in fontsForFamily) {
    380380            // 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]));
    382382            WKArrayAppendItem(result.get(), fontName.get());
    383383        }
     
    395395    // and if we haven't created one yet, the default one will be created on disk.
    396396    // Making the shared cache memory-only avoids touching the file system.
    397     RetainPtr<NSURLCache> sharedCache =
     397    auto sharedCache =
    398398        adoptNS([[NSURLCache alloc] initWithMemoryCapacity:1024 * 1024
    399399                                      diskCapacity:0
  • TabularUnified trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.h

    r266461 r267761  
    3232namespace WTR {
    3333
    34 class UIScriptControllerMac : public UIScriptControllerCocoa {
     34class UIScriptControllerMac final : public UIScriptControllerCocoa {
    3535public:
    3636    explicit UIScriptControllerMac(UIScriptContext& context)
     
    3939    }
    4040
     41private:
    4142    void replaceTextAtRange(JSStringRef, int, int) override;
    4243    void zoomToScale(double, JSValueRef) override;
     
    6364    void activateAtPoint(long x, long y, JSValueRef callback) override;
    6465
    65 private:
    6666    NSTableView *dataListSuggestionsTableView() const;
    6767};
  • TabularUnified trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm

    r266461 r267761  
    215215void UIScriptControllerMac::playBackEventStream(JSStringRef eventStream, JSValueRef callback)
    216216{
    217     RetainPtr<CFStringRef> stream = adoptCF(JSStringCopyCFString(kCFAllocatorDefault, eventStream));
     217    auto stream = adoptCF(JSStringCopyCFString(kCFAllocatorDefault, eventStream));
    218218    playBackEvents(webView(), m_context, (__bridge NSString *)stream.get(), callback);
    219219}
Note: See TracChangeset for help on using the changeset viewer.