/* * Copyright (C) 2010, 2014-2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" #include "TestController.h" #include "EventSenderProxy.h" #include "Options.h" #include "PlatformWebView.h" #include "StringFunctions.h" #include "TestInvocation.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if PLATFORM(COCOA) #include #include #endif #if !PLATFORM(COCOA) #include #endif namespace WTR { const unsigned TestController::viewWidth = 800; const unsigned TestController::viewHeight = 600; const unsigned TestController::w3cSVGViewWidth = 480; const unsigned TestController::w3cSVGViewHeight = 360; #if ASAN_ENABLED const double TestController::shortTimeout = 10.0; #else const double TestController::shortTimeout = 5.0; #endif const double TestController::noTimeout = -1; static WKURLRef blankURL() { static WKURLRef staticBlankURL = WKURLCreateWithUTF8CString("about:blank"); return staticBlankURL; } static WKDataRef copyWebCryptoMasterKey(WKPageRef, const void*) { // Any 128 bit key would do, all we need for testing is to implement the callback. return WKDataCreate((const uint8_t*)"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", 16); } static TestController* controller; TestController& TestController::singleton() { ASSERT(controller); return *controller; } TestController::TestController(int argc, const char* argv[]) : m_verbose(false) , m_printSeparators(false) , m_usingServerMode(false) , m_gcBetweenTests(false) , m_shouldDumpPixelsForAllTests(false) , m_state(Initial) , m_doneResetting(false) , m_useWaitToDumpWatchdogTimer(true) , m_forceNoTimeout(false) , m_didPrintWebProcessCrashedMessage(false) , m_shouldExitWhenWebProcessCrashes(true) , m_beforeUnloadReturnValue(true) , m_isGeolocationPermissionSet(false) , m_isGeolocationPermissionAllowed(false) , m_policyDelegateEnabled(false) , m_policyDelegatePermissive(false) , m_handlesAuthenticationChallenges(false) , m_shouldBlockAllPlugins(false) , m_forceComplexText(false) , m_shouldUseAcceleratedDrawing(false) , m_shouldUseRemoteLayerTree(false) , m_shouldLogHistoryClientCallbacks(false) , m_shouldShowWebView(false) { initialize(argc, argv); controller = this; run(); controller = 0; } TestController::~TestController() { // The context will be null if WebKitTestRunner was in server mode, but ran no tests. if (m_context) WKIconDatabaseClose(WKContextGetIconDatabase(m_context.get())); platformDestroy(); } static WKRect getWindowFrame(WKPageRef page, const void* clientInfo) { PlatformWebView* view = static_cast(const_cast(clientInfo)); return view->windowFrame(); } static void setWindowFrame(WKPageRef page, WKRect frame, const void* clientInfo) { PlatformWebView* view = static_cast(const_cast(clientInfo)); view->setWindowFrame(frame); } static bool runBeforeUnloadConfirmPanel(WKPageRef page, WKStringRef message, WKFrameRef frame, const void*) { printf("CONFIRM NAVIGATION: %s\n", toSTD(message).c_str()); return TestController::singleton().beforeUnloadReturnValue(); } void TestController::runModal(WKPageRef page, const void* clientInfo) { PlatformWebView* view = static_cast(const_cast(clientInfo)); view->setWindowIsKey(false); runModal(view); view->setWindowIsKey(true); } static void closeOtherPage(WKPageRef page, const void* clientInfo) { WKPageClose(page); PlatformWebView* view = static_cast(const_cast(clientInfo)); delete view; } static void focus(WKPageRef page, const void* clientInfo) { PlatformWebView* view = static_cast(const_cast(clientInfo)); view->focus(); view->setWindowIsKey(true); } static void unfocus(WKPageRef page, const void* clientInfo) { PlatformWebView* view = static_cast(const_cast(clientInfo)); view->setWindowIsKey(false); } static void decidePolicyForGeolocationPermissionRequest(WKPageRef, WKFrameRef, WKSecurityOriginRef, WKGeolocationPermissionRequestRef permissionRequest, const void* clientInfo) { TestController::singleton().handleGeolocationPermissionRequest(permissionRequest); } static void decidePolicyForUserMediaPermissionRequest(WKPageRef, WKFrameRef, WKSecurityOriginRef origin, WKUserMediaPermissionRequestRef permissionRequest, const void* clientInfo) { TestController::singleton().handleUserMediaPermissionRequest(origin, permissionRequest); } static void checkUserMediaPermissionForOrigin(WKPageRef, WKFrameRef, WKSecurityOriginRef origin, WKUserMediaPermissionCheckRef checkRequest, const void*) { TestController::singleton().handleCheckOfUserMediaPermissionForOrigin(origin, checkRequest); } WKPageRef TestController::createOtherPage(WKPageRef oldPage, WKPageConfigurationRef configuration, WKNavigationActionRef navigationAction, WKWindowFeaturesRef windowFeatures, const void *clientInfo) { PlatformWebView* parentView = static_cast(const_cast(clientInfo)); PlatformWebView* view = platformCreateOtherPage(parentView, configuration, parentView->options()); WKPageRef newPage = view->page(); view->resizeTo(800, 600); WKPageUIClientV6 otherPageUIClient = { { 6, view }, 0, // createNewPage_deprecatedForUseWithV0 0, // showPage closeOtherPage, 0, // takeFocus focus, unfocus, 0, // runJavaScriptAlert_deprecatedForUseWithV0 0, // runJavaScriptAlert_deprecatedForUseWithV0 0, // runJavaScriptAlert_deprecatedForUseWithV0 0, // setStatusText 0, // mouseDidMoveOverElement_deprecatedForUseWithV0 0, // missingPluginButtonClicked 0, // didNotHandleKeyEvent 0, // didNotHandleWheelEvent 0, // toolbarsAreVisible 0, // setToolbarsAreVisible 0, // menuBarIsVisible 0, // setMenuBarIsVisible 0, // statusBarIsVisible 0, // setStatusBarIsVisible 0, // isResizable 0, // setIsResizable getWindowFrame, setWindowFrame, runBeforeUnloadConfirmPanel, 0, // didDraw 0, // pageDidScroll 0, // exceededDatabaseQuota 0, // runOpenPanel decidePolicyForGeolocationPermissionRequest, 0, // headerHeight 0, // footerHeight 0, // drawHeader 0, // drawFooter 0, // printFrame runModal, 0, // didCompleteRubberBandForMainFrame 0, // saveDataToFileInDownloadsFolder 0, // shouldInterruptJavaScript 0, // createNewPage_deprecatedForUseWithV1 0, // mouseDidMoveOverElement 0, // decidePolicyForNotificationPermissionRequest 0, // unavailablePluginButtonClicked_deprecatedForUseWithV1 0, // showColorPicker 0, // hideColorPicker 0, // unavailablePluginButtonClicked 0, // pinnedStateDidChange 0, // didBeginTrackingPotentialLongMousePress 0, // didRecognizeLongMousePress 0, // didCancelTrackingPotentialLongMousePress 0, // isPlayingAudioDidChange decidePolicyForUserMediaPermissionRequest, 0, // didClickAutofillButton 0, // runJavaScriptAlert 0, // runJavaScriptConfirm 0, // runJavaScriptPrompt 0, // mediaSessionMetadataDidChange createOtherPage, 0, // runJavaScriptAlert 0, // runJavaScriptConfirm 0, // runJavaScriptPrompt checkUserMediaPermissionForOrigin, }; WKPageSetPageUIClient(newPage, &otherPageUIClient.base); WKPageNavigationClientV0 pageNavigationClient = { { 0, &TestController::singleton() }, decidePolicyForNavigationAction, decidePolicyForNavigationResponse, decidePolicyForPluginLoad, 0, // didStartProvisionalNavigation 0, // didReceiveServerRedirectForProvisionalNavigation 0, // didFailProvisionalNavigation 0, // didCommitNavigation 0, // didFinishNavigation 0, // didFailNavigation 0, // didFailProvisionalLoadInSubframe 0, // didFinishDocumentLoad 0, // didSameDocumentNavigation 0, // renderingProgressDidChange canAuthenticateAgainstProtectionSpace, didReceiveAuthenticationChallenge, processDidCrash, copyWebCryptoMasterKey, didBeginNavigationGesture, willEndNavigationGesture, didEndNavigationGesture, didRemoveNavigationGestureSnapshot }; WKPageSetPageNavigationClient(newPage, &pageNavigationClient.base); view->didInitializeClients(); TestController::singleton().updateWindowScaleForTest(view, *TestController::singleton().m_currentInvocation); WKRetain(newPage); return newPage; } const char* TestController::libraryPathForTesting() { // FIXME: This may not be sufficient to prevent interactions/crashes // when running more than one copy of DumpRenderTree. // See https://bugs.webkit.org/show_bug.cgi?id=10906 char* dumpRenderTreeTemp = getenv("DUMPRENDERTREE_TEMP"); if (dumpRenderTreeTemp) return dumpRenderTreeTemp; return platformLibraryPathForTesting(); } void TestController::initialize(int argc, const char* argv[]) { JSC::initializeThreading(); WTF::initializeMainThread(); RunLoop::initializeMainRunLoop(); platformInitialize(); Options options; OptionsHandler optionsHandler(options); if (argc < 2) { optionsHandler.printHelp(); exit(1); } if (!optionsHandler.parse(argc, argv)) exit(1); m_useWaitToDumpWatchdogTimer = options.useWaitToDumpWatchdogTimer; m_forceNoTimeout = options.forceNoTimeout; m_verbose = options.verbose; m_gcBetweenTests = options.gcBetweenTests; m_shouldDumpPixelsForAllTests = options.shouldDumpPixelsForAllTests; m_forceComplexText = options.forceComplexText; m_shouldUseAcceleratedDrawing = options.shouldUseAcceleratedDrawing; m_shouldUseRemoteLayerTree = options.shouldUseRemoteLayerTree; m_paths = options.paths; m_allowedHosts = options.allowedHosts; m_shouldShowWebView = options.shouldShowWebView; if (options.printSupportedFeatures) { // FIXME: On Windows, DumpRenderTree uses this to expose whether it supports 3d // transforms and accelerated compositing. When we support those features, we // should match DRT's behavior. exit(0); } m_usingServerMode = (m_paths.size() == 1 && m_paths[0] == "-"); if (m_usingServerMode) m_printSeparators = true; else m_printSeparators = m_paths.size() > 1; initializeInjectedBundlePath(); initializeTestPluginDirectory(); WKRetainPtr pageGroupIdentifier(AdoptWK, WKStringCreateWithUTF8CString("WebKitTestRunnerPageGroup")); m_pageGroup.adopt(WKPageGroupCreateWithIdentifier(pageGroupIdentifier.get())); } WKRetainPtr TestController::generateContextConfiguration() const { auto configuration = adoptWK(WKContextConfigurationCreate()); WKContextConfigurationSetInjectedBundlePath(configuration.get(), injectedBundlePath()); WKContextConfigurationSetFullySynchronousModeIsAllowedForTesting(configuration.get(), true); if (const char* dumpRenderTreeTemp = libraryPathForTesting()) { String temporaryFolder = String::fromUTF8(dumpRenderTreeTemp); const char separator = '/'; WKContextConfigurationSetApplicationCacheDirectory(configuration.get(), toWK(temporaryFolder + separator + "ApplicationCache").get()); WKContextConfigurationSetDiskCacheDirectory(configuration.get(), toWK(temporaryFolder + separator + "Cache").get()); WKContextConfigurationSetIndexedDBDatabaseDirectory(configuration.get(), toWK(temporaryFolder + separator + "Databases" + separator + "IndexedDB").get()); WKContextConfigurationSetLocalStorageDirectory(configuration.get(), toWK(temporaryFolder + separator + "LocalStorage").get()); WKContextConfigurationSetWebSQLDatabaseDirectory(configuration.get(), toWK(temporaryFolder + separator + "Databases" + separator + "WebSQL").get()); WKContextConfigurationSetMediaKeysStorageDirectory(configuration.get(), toWK(temporaryFolder + separator + "MediaKeys").get()); } return configuration; } WKRetainPtr TestController::generatePageConfiguration(WKContextConfigurationRef configuration) { m_context = platformAdjustContext(adoptWK(WKContextCreateWithConfiguration(configuration)).get(), configuration); m_geolocationProvider = std::make_unique(m_context.get()); if (const char* dumpRenderTreeTemp = libraryPathForTesting()) { String temporaryFolder = String::fromUTF8(dumpRenderTreeTemp); // FIXME: This should be migrated to WKContextConfigurationRef. // Disable icon database to avoid fetching and making tests flaky. // Invividual tests can enable it using testRunner.setIconDatabaseEnabled, although it's not currently supported in WebKitTestRunner. WKContextSetIconDatabasePath(m_context.get(), toWK(emptyString()).get()); } WKContextUseTestingNetworkSession(m_context.get()); WKContextSetCacheModel(m_context.get(), kWKCacheModelDocumentBrowser); platformInitializeContext(); WKContextInjectedBundleClientV1 injectedBundleClient = { { 1, this }, didReceiveMessageFromInjectedBundle, didReceiveSynchronousMessageFromInjectedBundle, 0 // getInjectedBundleInitializationUserData }; WKContextSetInjectedBundleClient(m_context.get(), &injectedBundleClient.base); WKContextClientV1 contextClient = { { 1, this }, 0, // plugInAutoStartOriginHashesChanged networkProcessDidCrash, 0, // plugInInformationBecameAvailable 0, // copyWebCryptoMasterKey }; WKContextSetClient(m_context.get(), &contextClient.base); WKContextHistoryClientV0 historyClient = { { 0, this }, didNavigateWithNavigationData, didPerformClientRedirect, didPerformServerRedirect, didUpdateHistoryTitle, 0, // populateVisitedLinks }; WKContextSetHistoryClient(m_context.get(), &historyClient.base); WKNotificationManagerRef notificationManager = WKContextGetNotificationManager(m_context.get()); WKNotificationProviderV0 notificationKit = m_webNotificationProvider.provider(); WKNotificationManagerSetProvider(notificationManager, ¬ificationKit.base); if (testPluginDirectory()) WKContextSetAdditionalPluginsDirectory(m_context.get(), testPluginDirectory()); if (m_forceComplexText) WKContextSetAlwaysUsesComplexTextCodePath(m_context.get(), true); auto pageConfiguration = adoptWK(WKPageConfigurationCreate()); WKPageConfigurationSetContext(pageConfiguration.get(), m_context.get()); WKPageConfigurationSetPageGroup(pageConfiguration.get(), m_pageGroup.get()); WKPageConfigurationSetUserContentController(pageConfiguration.get(), adoptWK(WKUserContentControllerCreate()).get()); return pageConfiguration; } void TestController::createWebViewWithOptions(const TestOptions& options) { auto contextConfiguration = generateContextConfiguration(); WKRetainPtr overrideLanguages = adoptWK(WKMutableArrayCreate()); for (auto& language : options.overrideLanguages) WKArrayAppendItem(overrideLanguages.get(), adoptWK(WKStringCreateWithUTF8CString(language.utf8().data())).get()); WKContextConfigurationSetOverrideLanguages(contextConfiguration.get(), overrideLanguages.get()); auto configuration = generatePageConfiguration(contextConfiguration.get()); // Some preferences (notably mock scroll bars setting) currently cannot be re-applied to an existing view, so we need to set them now. // FIXME: Migrate these preferences to WKContextConfigurationRef. resetPreferencesToConsistentValues(); platformCreateWebView(configuration.get(), options); WKPageUIClientV6 pageUIClient = { { 6, m_mainWebView.get() }, 0, // createNewPage_deprecatedForUseWithV0 0, // showPage 0, // close 0, // takeFocus focus, unfocus, 0, // runJavaScriptAlert_deprecatedForUseWithV0 0, // runJavaScriptAlert_deprecatedForUseWithV0 0, // runJavaScriptAlert_deprecatedForUseWithV0 0, // setStatusText 0, // mouseDidMoveOverElement_deprecatedForUseWithV0 0, // missingPluginButtonClicked 0, // didNotHandleKeyEvent 0, // didNotHandleWheelEvent 0, // toolbarsAreVisible 0, // setToolbarsAreVisible 0, // menuBarIsVisible 0, // setMenuBarIsVisible 0, // statusBarIsVisible 0, // setStatusBarIsVisible 0, // isResizable 0, // setIsResizable getWindowFrame, setWindowFrame, runBeforeUnloadConfirmPanel, 0, // didDraw 0, // pageDidScroll 0, // exceededDatabaseQuota, 0, // runOpenPanel decidePolicyForGeolocationPermissionRequest, 0, // headerHeight 0, // footerHeight 0, // drawHeader 0, // drawFooter 0, // printFrame runModal, 0, // didCompleteRubberBandForMainFrame 0, // saveDataToFileInDownloadsFolder 0, // shouldInterruptJavaScript 0, // createNewPage_deprecatedForUseWithV1 0, // mouseDidMoveOverElement decidePolicyForNotificationPermissionRequest, // decidePolicyForNotificationPermissionRequest 0, // unavailablePluginButtonClicked_deprecatedForUseWithV1 0, // showColorPicker 0, // hideColorPicker unavailablePluginButtonClicked, 0, // pinnedStateDidChange 0, // didBeginTrackingPotentialLongMousePress 0, // didRecognizeLongMousePress 0, // didCancelTrackingPotentialLongMousePress 0, // isPlayingAudioDidChange decidePolicyForUserMediaPermissionRequest, 0, // didClickAutofillButton 0, // runJavaScriptAlert 0, // runJavaScriptConfirm 0, // runJavaScriptPrompt 0, // mediaSessionMetadataDidChange createOtherPage, 0, // runJavaScriptAlert 0, // runJavaScriptConfirm 0, // runJavaScriptPrompt checkUserMediaPermissionForOrigin, }; WKPageSetPageUIClient(m_mainWebView->page(), &pageUIClient.base); WKPageNavigationClientV0 pageNavigationClient = { { 0, this }, decidePolicyForNavigationAction, decidePolicyForNavigationResponse, decidePolicyForPluginLoad, 0, // didStartProvisionalNavigation 0, // didReceiveServerRedirectForProvisionalNavigation 0, // didFailProvisionalNavigation didCommitNavigation, didFinishNavigation, 0, // didFailNavigation 0, // didFailProvisionalLoadInSubframe 0, // didFinishDocumentLoad 0, // didSameDocumentNavigation 0, // renderingProgressDidChange canAuthenticateAgainstProtectionSpace, didReceiveAuthenticationChallenge, processDidCrash, copyWebCryptoMasterKey, didBeginNavigationGesture, willEndNavigationGesture, didEndNavigationGesture, didRemoveNavigationGestureSnapshot }; WKPageSetPageNavigationClient(m_mainWebView->page(), &pageNavigationClient.base); // this should just be done on the page? WKPageInjectedBundleClientV0 injectedBundleClient = { { 0, this }, didReceivePageMessageFromInjectedBundle, didReceiveSynchronousPageMessageFromInjectedBundle }; WKPageSetPageInjectedBundleClient(m_mainWebView->page(), &injectedBundleClient.base); m_mainWebView->didInitializeClients(); // Generally, the tests should default to running at 1x. updateWindowScaleForTest() will adjust the scale to // something else for specific tests that need to run at a different window scale. m_mainWebView->changeWindowScaleIfNeeded(1); } void TestController::ensureViewSupportsOptionsForTest(const TestInvocation& test) { auto options = test.options(); if (m_mainWebView) { if (m_mainWebView->viewSupportsOptions(options)) return; WKPageSetPageUIClient(m_mainWebView->page(), nullptr); WKPageSetPageNavigationClient(m_mainWebView->page(), nullptr); WKPageClose(m_mainWebView->page()); m_mainWebView = nullptr; } createWebViewWithOptions(options); if (!resetStateToConsistentValues()) TestInvocation::dumpWebProcessUnresponsiveness(" - TestController::run - Failed to reset state to consistent values\n"); } void TestController::resetPreferencesToConsistentValues() { // Reset preferences WKPreferencesRef preferences = platformPreferences(); WKPreferencesResetTestRunnerOverrides(preferences); WKPreferencesSetPageVisibilityBasedProcessSuppressionEnabled(preferences, false); WKPreferencesSetOfflineWebApplicationCacheEnabled(preferences, true); WKPreferencesSetFontSmoothingLevel(preferences, kWKFontSmoothingLevelNoSubpixelAntiAliasing); WKPreferencesSetAntialiasedFontDilationEnabled(preferences, false); WKPreferencesSetXSSAuditorEnabled(preferences, false); WKPreferencesSetWebAudioEnabled(preferences, true); WKPreferencesSetMediaStreamEnabled(preferences, true); WKPreferencesSetDeveloperExtrasEnabled(preferences, true); WKPreferencesSetJavaScriptRuntimeFlags(preferences, kWKJavaScriptRuntimeFlagsAllEnabled); WKPreferencesSetJavaScriptCanOpenWindowsAutomatically(preferences, true); WKPreferencesSetJavaScriptCanAccessClipboard(preferences, true); WKPreferencesSetDOMPasteAllowed(preferences, true); WKPreferencesSetUniversalAccessFromFileURLsAllowed(preferences, true); WKPreferencesSetFileAccessFromFileURLsAllowed(preferences, true); #if ENABLE(FULLSCREEN_API) WKPreferencesSetFullScreenEnabled(preferences, true); #endif WKPreferencesSetPageCacheEnabled(preferences, false); WKPreferencesSetAsynchronousPluginInitializationEnabled(preferences, false); WKPreferencesSetAsynchronousPluginInitializationEnabledForAllPlugins(preferences, false); WKPreferencesSetArtificialPluginInitializationDelayEnabled(preferences, false); WKPreferencesSetTabToLinksEnabled(preferences, false); WKPreferencesSetInteractiveFormValidationEnabled(preferences, true); WKPreferencesSetMockScrollbarsEnabled(preferences, true); static WKStringRef defaultTextEncoding = WKStringCreateWithUTF8CString("ISO-8859-1"); WKPreferencesSetDefaultTextEncodingName(preferences, defaultTextEncoding); #if !PLATFORM(QT) static WKStringRef standardFontFamily = WKStringCreateWithUTF8CString("Times"); static WKStringRef cursiveFontFamily = WKStringCreateWithUTF8CString("Apple Chancery"); static WKStringRef fantasyFontFamily = WKStringCreateWithUTF8CString("Papyrus"); static WKStringRef fixedFontFamily = WKStringCreateWithUTF8CString("Courier"); static WKStringRef pictographFontFamily = WKStringCreateWithUTF8CString("Apple Color Emoji"); static WKStringRef sansSerifFontFamily = WKStringCreateWithUTF8CString("Helvetica"); static WKStringRef serifFontFamily = WKStringCreateWithUTF8CString("Times"); WKPreferencesSetStandardFontFamily(preferences, standardFontFamily); WKPreferencesSetCursiveFontFamily(preferences, cursiveFontFamily); WKPreferencesSetFantasyFontFamily(preferences, fantasyFontFamily); WKPreferencesSetFixedFontFamily(preferences, fixedFontFamily); WKPreferencesSetPictographFontFamily(preferences, pictographFontFamily); WKPreferencesSetSansSerifFontFamily(preferences, sansSerifFontFamily); WKPreferencesSetSerifFontFamily(preferences, serifFontFamily); #endif WKPreferencesSetAsynchronousSpellCheckingEnabled(preferences, false); #if ENABLE(WEB_AUDIO) WKPreferencesSetMediaSourceEnabled(preferences, true); #endif WKPreferencesSetHiddenPageDOMTimerThrottlingEnabled(preferences, false); WKPreferencesSetHiddenPageCSSAnimationSuspensionEnabled(preferences, false); WKPreferencesSetAcceleratedDrawingEnabled(preferences, m_shouldUseAcceleratedDrawing); // FIXME: We should be testing the default. WKPreferencesSetStorageBlockingPolicy(preferences, kWKAllowAllStorage); WKPreferencesSetMediaPlaybackAllowsInline(preferences, true); WKPreferencesSetInlineMediaPlaybackRequiresPlaysInlineAttribute(preferences, false); WKCookieManagerDeleteAllCookies(WKContextGetCookieManager(m_context.get())); platformResetPreferencesToConsistentValues(); } bool TestController::resetStateToConsistentValues() { TemporaryChange changeState(m_state, Resetting); m_beforeUnloadReturnValue = true; // This setting differs between the antique and modern Mac WebKit2 API. // For now, maintain the antique behavior, because some tests depend on it! // FIXME: We should be testing the default. WKPageSetBackgroundExtendsBeyondPage(m_mainWebView->page(), false); WKRetainPtr messageName = adoptWK(WKStringCreateWithUTF8CString("Reset")); WKRetainPtr resetMessageBody = adoptWK(WKMutableDictionaryCreate()); WKRetainPtr shouldGCKey = adoptWK(WKStringCreateWithUTF8CString("ShouldGC")); WKRetainPtr shouldGCValue = adoptWK(WKBooleanCreate(m_gcBetweenTests)); WKDictionarySetItem(resetMessageBody.get(), shouldGCKey.get(), shouldGCValue.get()); WKRetainPtr allowedHostsKey = adoptWK(WKStringCreateWithUTF8CString("AllowedHosts")); WKRetainPtr allowedHostsValue = adoptWK(WKMutableArrayCreate()); for (auto& host : m_allowedHosts) { WKRetainPtr wkHost = adoptWK(WKStringCreateWithUTF8CString(host.c_str())); WKArrayAppendItem(allowedHostsValue.get(), wkHost.get()); } WKDictionarySetItem(resetMessageBody.get(), allowedHostsKey.get(), allowedHostsValue.get()); WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), resetMessageBody.get()); WKContextSetShouldUseFontSmoothing(TestController::singleton().context(), false); WKContextSetCacheModel(TestController::singleton().context(), kWKCacheModelDocumentBrowser); WKContextClearCachedCredentials(TestController::singleton().context()); // FIXME: This function should also ensure that there is only one page open. // Reset the EventSender for each test. m_eventSenderProxy = std::make_unique(this); // FIXME: Is this needed? Nothing in TestController changes preferences during tests, and if there is // some other code doing this, it should probably be responsible for cleanup too. resetPreferencesToConsistentValues(); #if !PLATFORM(COCOA) WKTextCheckerContinuousSpellCheckingEnabledStateChanged(true); #endif // In the case that a test using the chrome input field failed, be sure to clean up for the next test. m_mainWebView->removeChromeInputField(); m_mainWebView->focus(); // Re-set to the default backing scale factor by setting the custom scale factor to 0. WKPageSetCustomBackingScaleFactor(m_mainWebView->page(), 0); WKPageClearWheelEventTestTrigger(m_mainWebView->page()); #if PLATFORM(EFL) // EFL use a real window while other ports such as Qt don't. // In EFL, we need to resize the window to the original size after calls to window.resizeTo. WKRect rect = m_mainWebView->windowFrame(); m_mainWebView->setWindowFrame(WKRectMake(rect.origin.x, rect.origin.y, TestController::viewWidth, TestController::viewHeight)); #endif // Reset notification permissions m_webNotificationProvider.reset(); // Reset Geolocation permissions. m_geolocationPermissionRequests.clear(); m_isGeolocationPermissionSet = false; m_isGeolocationPermissionAllowed = false; // Reset UserMedia permissions. m_userMediaPermissionRequests.clear(); m_userMediaOriginPermissions = nullptr; m_isUserMediaPermissionSet = false; m_isUserMediaPermissionAllowed = false; // Reset Custom Policy Delegate. setCustomPolicyDelegate(false, false); m_workQueueManager.clearWorkQueue(); m_handlesAuthenticationChallenges = false; m_authenticationUsername = String(); m_authenticationPassword = String(); m_shouldBlockAllPlugins = false; m_shouldLogHistoryClientCallbacks = false; setHidden(false); platformResetStateToConsistentValues(); // Reset main page back to about:blank m_doneResetting = false; m_shouldDecideNavigationPolicyAfterDelay = false; setNavigationGesturesEnabled(false); WKPageLoadURL(m_mainWebView->page(), blankURL()); runUntil(m_doneResetting, shortTimeout); return m_doneResetting; } void TestController::terminateWebContentProcess() { WKPageTerminate(m_mainWebView->page()); } void TestController::reattachPageToWebProcess() { // Loading a web page is the only way to reattach an existing page to a process. m_doneResetting = false; WKPageLoadURL(m_mainWebView->page(), blankURL()); runUntil(m_doneResetting, shortTimeout); } const char* TestController::webProcessName() { // FIXME: Find a way to not hardcode the process name. #if PLATFORM(COCOA) return "com.apple.WebKit.WebContent.Development"; #else return "WebProcess"; #endif } const char* TestController::networkProcessName() { // FIXME: Find a way to not hardcode the process name. #if PLATFORM(COCOA) return "com.apple.WebKit.Networking.Development"; #else return "NetworkProcess"; #endif } static std::string testPath(WKURLRef url) { auto scheme = adoptWK(WKURLCopyScheme(url)); if (WKStringIsEqualToUTF8CStringIgnoringCase(scheme.get(), "file")) { auto path = adoptWK(WKURLCopyPath(url)); auto buffer = std::vector(WKStringGetMaximumUTF8CStringSize(path.get())); auto length = WKStringGetUTF8CString(path.get(), buffer.data(), buffer.size()); return std::string(buffer.data(), length); } return std::string(); } static WKURLRef createTestURL(const char* pathOrURL) { if (strstr(pathOrURL, "http://") || strstr(pathOrURL, "https://") || strstr(pathOrURL, "file://")) return WKURLCreateWithUTF8CString(pathOrURL); // Creating from filesytem path. size_t length = strlen(pathOrURL); if (!length) return 0; const char separator = '/'; bool isAbsolutePath = pathOrURL[0] == separator; const char* filePrefix = "file://"; static const size_t prefixLength = strlen(filePrefix); std::unique_ptr buffer; if (isAbsolutePath) { buffer = std::make_unique(prefixLength + length + 1); strcpy(buffer.get(), filePrefix); strcpy(buffer.get() + prefixLength, pathOrURL); } else { buffer = std::make_unique(prefixLength + PATH_MAX + length + 2); // 1 for the separator strcpy(buffer.get(), filePrefix); if (!getcwd(buffer.get() + prefixLength, PATH_MAX)) return 0; size_t numCharacters = strlen(buffer.get()); buffer[numCharacters] = separator; strcpy(buffer.get() + numCharacters + 1, pathOrURL); } return WKURLCreateWithUTF8CString(buffer.get()); } static bool parseBooleanTestHeaderValue(const std::string& value) { if (value == "true") return true; if (value == "false") return false; LOG_ERROR("Found unexpected value '%s' for boolean option. Expected 'true' or 'false'.", value.c_str()); return false; } static void updateTestOptionsFromTestHeader(TestOptions& testOptions, const std::string& pathOrURL) { // Gross. Need to reduce conversions between all the string types and URLs. WKRetainPtr wkURL(AdoptWK, createTestURL(pathOrURL.c_str())); std::string filename = testPath(wkURL.get()); if (filename.empty()) return; std::string options; std::ifstream testFile(filename.data()); if (!testFile.good()) return; getline(testFile, options); std::string beginString("webkit-test-runner [ "); std::string endString(" ]"); size_t beginLocation = options.find(beginString); if (beginLocation == std::string::npos) return; size_t endLocation = options.find(endString, beginLocation); if (endLocation == std::string::npos) { LOG_ERROR("Could not find end of test header in %s", filename.c_str()); return; } std::string pairString = options.substr(beginLocation + beginString.size(), endLocation - (beginLocation + beginString.size())); size_t pairStart = 0; while (pairStart < pairString.size()) { size_t pairEnd = pairString.find(" ", pairStart); if (pairEnd == std::string::npos) pairEnd = pairString.size(); size_t equalsLocation = pairString.find("=", pairStart); if (equalsLocation == std::string::npos) { LOG_ERROR("Malformed option in test header (could not find '=' character) in %s", filename.c_str()); break; } auto key = pairString.substr(pairStart, equalsLocation - pairStart); auto value = pairString.substr(equalsLocation + 1, pairEnd - (equalsLocation + 1)); if (key == "language") String(value.c_str()).split(",", false, testOptions.overrideLanguages); if (key == "useThreadedScrolling") testOptions.useThreadedScrolling = parseBooleanTestHeaderValue(value); if (key == "useFlexibleViewport") testOptions.useFlexibleViewport = parseBooleanTestHeaderValue(value); if (key == "useDataDetection") testOptions.useDataDetection = parseBooleanTestHeaderValue(value); pairStart = pairEnd + 1; } } TestOptions TestController::testOptionsForTest(const std::string& pathOrURL) const { TestOptions options(pathOrURL); options.useRemoteLayerTree = m_shouldUseRemoteLayerTree; options.shouldShowWebView = m_shouldShowWebView; updatePlatformSpecificTestOptionsForTest(options, pathOrURL); updateTestOptionsFromTestHeader(options, pathOrURL); return options; } void TestController::updateWebViewSizeForTest(const TestInvocation& test) { unsigned width = viewWidth; unsigned height = viewHeight; if (test.options().isSVGTest) { width = w3cSVGViewWidth; height = w3cSVGViewHeight; } mainWebView()->resizeTo(width, height); } void TestController::updateWindowScaleForTest(PlatformWebView* view, const TestInvocation& test) { view->changeWindowScaleIfNeeded(test.options().isHiDPITest ? 2 : 1); } void TestController::configureViewForTest(const TestInvocation& test) { ensureViewSupportsOptionsForTest(test); updateWebViewSizeForTest(test); updateWindowScaleForTest(mainWebView(), test); platformConfigureViewForTest(test); } struct TestCommand { TestCommand() : shouldDumpPixels(false), timeout(0) { } std::string pathOrURL; bool shouldDumpPixels; std::string expectedPixelHash; int timeout; }; class CommandTokenizer { public: explicit CommandTokenizer(const std::string& input) : m_input(input) , m_posNextSeparator(0) { pump(); } bool hasNext() const; std::string next(); private: void pump(); static const char kSeparator = '\''; const std::string& m_input; std::string m_next; size_t m_posNextSeparator; }; void CommandTokenizer::pump() { if (m_posNextSeparator == std::string::npos || m_posNextSeparator == m_input.size()) { m_next = std::string(); return; } size_t start = m_posNextSeparator ? m_posNextSeparator + 1 : 0; m_posNextSeparator = m_input.find(kSeparator, start); size_t size = m_posNextSeparator == std::string::npos ? std::string::npos : m_posNextSeparator - start; m_next = std::string(m_input, start, size); } std::string CommandTokenizer::next() { ASSERT(hasNext()); std::string oldNext = m_next; pump(); return oldNext; } bool CommandTokenizer::hasNext() const { return !m_next.empty(); } NO_RETURN static void die(const std::string& inputLine) { fprintf(stderr, "Unexpected input line: %s\n", inputLine.c_str()); exit(1); } TestCommand parseInputLine(const std::string& inputLine) { TestCommand result; CommandTokenizer tokenizer(inputLine); if (!tokenizer.hasNext()) die(inputLine); std::string arg = tokenizer.next(); result.pathOrURL = arg; while (tokenizer.hasNext()) { arg = tokenizer.next(); if (arg == std::string("--timeout")) { std::string timeoutToken = tokenizer.next(); result.timeout = atoi(timeoutToken.c_str()); } else if (arg == std::string("-p") || arg == std::string("--pixel-test")) { result.shouldDumpPixels = true; if (tokenizer.hasNext()) result.expectedPixelHash = tokenizer.next(); } else die(inputLine); } return result; } bool TestController::runTest(const char* inputLine) { TestCommand command = parseInputLine(std::string(inputLine)); m_state = RunningTest; TestOptions options = testOptionsForTest(command.pathOrURL); WKRetainPtr wkURL(AdoptWK, createTestURL(command.pathOrURL.c_str())); m_currentInvocation = std::make_unique(wkURL.get(), options); if (command.shouldDumpPixels || m_shouldDumpPixelsForAllTests) m_currentInvocation->setIsPixelTest(command.expectedPixelHash); if (command.timeout > 0) m_currentInvocation->setCustomTimeout(command.timeout); platformWillRunTest(*m_currentInvocation); m_currentInvocation->invoke(); m_currentInvocation = nullptr; return true; } void TestController::runTestingServerLoop() { char filenameBuffer[2048]; while (fgets(filenameBuffer, sizeof(filenameBuffer), stdin)) { char* newLineCharacter = strchr(filenameBuffer, '\n'); if (newLineCharacter) *newLineCharacter = '\0'; if (strlen(filenameBuffer) == 0) continue; if (!runTest(filenameBuffer)) break; } } void TestController::run() { if (m_usingServerMode) runTestingServerLoop(); else { for (size_t i = 0; i < m_paths.size(); ++i) { if (!runTest(m_paths[i].c_str())) break; } } } void TestController::runUntil(bool& done, double timeout) { if (m_forceNoTimeout) timeout = noTimeout; platformRunUntil(done, timeout); } // WKContextInjectedBundleClient void TestController::didReceiveMessageFromInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo) { static_cast(const_cast(clientInfo))->didReceiveMessageFromInjectedBundle(messageName, messageBody); } void TestController::didReceiveSynchronousMessageFromInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void* clientInfo) { *returnData = static_cast(const_cast(clientInfo))->didReceiveSynchronousMessageFromInjectedBundle(messageName, messageBody).leakRef(); } // WKPageInjectedBundleClient void TestController::didReceivePageMessageFromInjectedBundle(WKPageRef page, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo) { static_cast(const_cast(clientInfo))->didReceiveMessageFromInjectedBundle(messageName, messageBody); } void TestController::didReceiveSynchronousPageMessageFromInjectedBundle(WKPageRef page, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void* clientInfo) { *returnData = static_cast(const_cast(clientInfo))->didReceiveSynchronousMessageFromInjectedBundle(messageName, messageBody).leakRef(); } void TestController::networkProcessDidCrash(WKContextRef context, const void *clientInfo) { static_cast(const_cast(clientInfo))->networkProcessDidCrash(); } void TestController::didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef messageBodyDictionary, bool synchronous) { WKRetainPtr keyKey = adoptWK(WKStringCreateWithUTF8CString("Key")); WKStringRef key = static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, keyKey.get())); WKRetainPtr modifiersKey = adoptWK(WKStringCreateWithUTF8CString("Modifiers")); WKEventModifiers modifiers = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, modifiersKey.get())))); WKRetainPtr locationKey = adoptWK(WKStringCreateWithUTF8CString("Location")); unsigned location = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, locationKey.get())))); m_eventSenderProxy->keyDown(key, modifiers, location); } void TestController::didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody) { if (WKStringIsEqualToUTF8CString(messageName, "EventSender")) { if (m_state != RunningTest) return; ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); WKDictionaryRef messageBodyDictionary = static_cast(messageBody); WKRetainPtr subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage")); WKStringRef subMessageName = static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, subMessageKey.get())); if (WKStringIsEqualToUTF8CString(subMessageName, "MouseDown") || WKStringIsEqualToUTF8CString(subMessageName, "MouseUp")) { WKRetainPtr buttonKey = adoptWK(WKStringCreateWithUTF8CString("Button")); unsigned button = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, buttonKey.get())))); WKRetainPtr modifiersKey = adoptWK(WKStringCreateWithUTF8CString("Modifiers")); WKEventModifiers modifiers = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, modifiersKey.get())))); // Forward to WebProcess if (WKStringIsEqualToUTF8CString(subMessageName, "MouseDown")) m_eventSenderProxy->mouseDown(button, modifiers); else m_eventSenderProxy->mouseUp(button, modifiers); return; } if (WKStringIsEqualToUTF8CString(subMessageName, "KeyDown")) { didReceiveKeyDownMessageFromInjectedBundle(messageBodyDictionary, false); return; } if (WKStringIsEqualToUTF8CString(subMessageName, "MouseScrollBy")) { WKRetainPtr xKey = adoptWK(WKStringCreateWithUTF8CString("X")); double x = WKDoubleGetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))); WKRetainPtr yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); double y = WKDoubleGetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))); // Forward to WebProcess m_eventSenderProxy->mouseScrollBy(x, y); return; } if (WKStringIsEqualToUTF8CString(subMessageName, "MouseScrollByWithWheelAndMomentumPhases")) { WKRetainPtr xKey = adoptWK(WKStringCreateWithUTF8CString("X")); double x = WKDoubleGetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))); WKRetainPtr yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); double y = WKDoubleGetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))); WKRetainPtr phaseKey = adoptWK(WKStringCreateWithUTF8CString("Phase")); int phase = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, phaseKey.get())))); WKRetainPtr momentumKey = adoptWK(WKStringCreateWithUTF8CString("Momentum")); int momentum = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, momentumKey.get())))); // Forward to WebProcess m_eventSenderProxy->mouseScrollByWithWheelAndMomentumPhases(x, y, phase, momentum); return; } if (WKStringIsEqualToUTF8CString(subMessageName, "SwipeGestureWithWheelAndMomentumPhases")) { WKRetainPtr xKey = adoptWK(WKStringCreateWithUTF8CString("X")); double x = WKDoubleGetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))); WKRetainPtr yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); double y = WKDoubleGetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))); WKRetainPtr phaseKey = adoptWK(WKStringCreateWithUTF8CString("Phase")); int phase = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, phaseKey.get())))); WKRetainPtr momentumKey = adoptWK(WKStringCreateWithUTF8CString("Momentum")); int momentum = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, momentumKey.get())))); m_eventSenderProxy->swipeGestureWithWheelAndMomentumPhases(x, y, phase, momentum); return; } ASSERT_NOT_REACHED(); } if (!m_currentInvocation) return; m_currentInvocation->didReceiveMessageFromInjectedBundle(messageName, messageBody); } WKRetainPtr TestController::didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody) { if (WKStringIsEqualToUTF8CString(messageName, "EventSender")) { if (m_state != RunningTest) return nullptr; ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); WKDictionaryRef messageBodyDictionary = static_cast(messageBody); WKRetainPtr subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage")); WKStringRef subMessageName = static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, subMessageKey.get())); if (WKStringIsEqualToUTF8CString(subMessageName, "KeyDown")) { didReceiveKeyDownMessageFromInjectedBundle(messageBodyDictionary, true); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "MouseDown") || WKStringIsEqualToUTF8CString(subMessageName, "MouseUp")) { WKRetainPtr buttonKey = adoptWK(WKStringCreateWithUTF8CString("Button")); unsigned button = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, buttonKey.get())))); WKRetainPtr modifiersKey = adoptWK(WKStringCreateWithUTF8CString("Modifiers")); WKEventModifiers modifiers = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, modifiersKey.get())))); // Forward to WebProcess if (WKStringIsEqualToUTF8CString(subMessageName, "MouseDown")) m_eventSenderProxy->mouseDown(button, modifiers); else m_eventSenderProxy->mouseUp(button, modifiers); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "MouseMoveTo")) { WKRetainPtr xKey = adoptWK(WKStringCreateWithUTF8CString("X")); double x = WKDoubleGetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))); WKRetainPtr yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); double y = WKDoubleGetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))); // Forward to WebProcess m_eventSenderProxy->mouseMoveTo(x, y); return 0; } #if PLATFORM(MAC) if (WKStringIsEqualToUTF8CString(subMessageName, "MouseForceClick")) { m_eventSenderProxy->mouseForceClick(); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "StartAndCancelMouseForceClick")) { m_eventSenderProxy->startAndCancelMouseForceClick(); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "MouseForceDown")) { m_eventSenderProxy->mouseForceDown(); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "MouseForceUp")) { m_eventSenderProxy->mouseForceUp(); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "MouseForceChanged")) { WKRetainPtr forceKey = adoptWK(WKStringCreateWithUTF8CString("Force")); double force = WKDoubleGetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, forceKey.get()))); m_eventSenderProxy->mouseForceChanged(force); return 0; } #endif // PLATFORM(MAC) if (WKStringIsEqualToUTF8CString(subMessageName, "ContinuousMouseScrollBy")) { WKRetainPtr xKey = adoptWK(WKStringCreateWithUTF8CString("X")); double x = WKDoubleGetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))); WKRetainPtr yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); double y = WKDoubleGetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))); WKRetainPtr pagedKey = adoptWK(WKStringCreateWithUTF8CString("Paged")); bool paged = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, pagedKey.get())))); // Forward to WebProcess m_eventSenderProxy->continuousMouseScrollBy(x, y, paged); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "LeapForward")) { WKRetainPtr timeKey = adoptWK(WKStringCreateWithUTF8CString("TimeInMilliseconds")); unsigned time = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, timeKey.get())))); m_eventSenderProxy->leapForward(time); return 0; } #if ENABLE(TOUCH_EVENTS) if (WKStringIsEqualToUTF8CString(subMessageName, "AddTouchPoint")) { WKRetainPtr xKey = adoptWK(WKStringCreateWithUTF8CString("X")); int x = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get())))); WKRetainPtr yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); int y = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get())))); m_eventSenderProxy->addTouchPoint(x, y); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "UpdateTouchPoint")) { WKRetainPtr indexKey = adoptWK(WKStringCreateWithUTF8CString("Index")); int index = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, indexKey.get())))); WKRetainPtr xKey = adoptWK(WKStringCreateWithUTF8CString("X")); int x = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get())))); WKRetainPtr yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); int y = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get())))); m_eventSenderProxy->updateTouchPoint(index, x, y); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "SetTouchModifier")) { WKRetainPtr modifierKey = adoptWK(WKStringCreateWithUTF8CString("Modifier")); WKEventModifiers modifier = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, modifierKey.get())))); WKRetainPtr enableKey = adoptWK(WKStringCreateWithUTF8CString("Enable")); bool enable = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, enableKey.get())))); m_eventSenderProxy->setTouchModifier(modifier, enable); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "SetTouchPointRadius")) { WKRetainPtr xKey = adoptWK(WKStringCreateWithUTF8CString("RadiusX")); int x = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get())))); WKRetainPtr yKey = adoptWK(WKStringCreateWithUTF8CString("RadiusY")); int y = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get())))); m_eventSenderProxy->setTouchPointRadius(x, y); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "TouchStart")) { m_eventSenderProxy->touchStart(); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "TouchMove")) { m_eventSenderProxy->touchMove(); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "TouchEnd")) { m_eventSenderProxy->touchEnd(); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "TouchCancel")) { m_eventSenderProxy->touchCancel(); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "ClearTouchPoints")) { m_eventSenderProxy->clearTouchPoints(); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "ReleaseTouchPoint")) { WKRetainPtr indexKey = adoptWK(WKStringCreateWithUTF8CString("Index")); int index = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, indexKey.get())))); m_eventSenderProxy->releaseTouchPoint(index); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "CancelTouchPoint")) { WKRetainPtr indexKey = adoptWK(WKStringCreateWithUTF8CString("Index")); int index = static_cast(WKUInt64GetValue(static_cast(WKDictionaryGetItemForKey(messageBodyDictionary, indexKey.get())))); m_eventSenderProxy->cancelTouchPoint(index); return 0; } #endif ASSERT_NOT_REACHED(); } return m_currentInvocation->didReceiveSynchronousMessageFromInjectedBundle(messageName, messageBody); } // WKContextClient void TestController::networkProcessDidCrash() { #if PLATFORM(COCOA) pid_t pid = WKContextGetNetworkProcessIdentifier(m_context.get()); fprintf(stderr, "#CRASHED - %s (pid %ld)\n", networkProcessName(), static_cast(pid)); #else fprintf(stderr, "#CRASHED - %s\n", networkProcessName()); #endif exit(1); } // WKPageNavigationClient void TestController::didCommitNavigation(WKPageRef page, WKNavigationRef navigation, WKTypeRef, const void* clientInfo) { static_cast(const_cast(clientInfo))->didCommitNavigation(page, navigation); } void TestController::didFinishNavigation(WKPageRef page, WKNavigationRef navigation, WKTypeRef, const void* clientInfo) { static_cast(const_cast(clientInfo))->didFinishNavigation(page, navigation); } bool TestController::canAuthenticateAgainstProtectionSpace(WKPageRef, WKProtectionSpaceRef protectionSpace, const void*) { WKProtectionSpaceAuthenticationScheme authenticationScheme = WKProtectionSpaceGetAuthenticationScheme(protectionSpace); if (authenticationScheme == kWKProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested) { std::string host = toSTD(adoptWK(WKProtectionSpaceCopyHost(protectionSpace)).get()); return host == "localhost" || host == "127.0.0.1"; } return authenticationScheme <= kWKProtectionSpaceAuthenticationSchemeHTTPDigest; } void TestController::didReceiveAuthenticationChallenge(WKPageRef page, WKAuthenticationChallengeRef authenticationChallenge, const void *clientInfo) { static_cast(const_cast(clientInfo))->didReceiveAuthenticationChallenge(page, /*frame,*/ authenticationChallenge); } void TestController::processDidCrash(WKPageRef page, const void* clientInfo) { static_cast(const_cast(clientInfo))->processDidCrash(); } void TestController::didBeginNavigationGesture(WKPageRef page, const void *clientInfo) { static_cast(const_cast(clientInfo))->didBeginNavigationGesture(page); } void TestController::willEndNavigationGesture(WKPageRef page, WKBackForwardListItemRef backForwardListItem, const void *clientInfo) { static_cast(const_cast(clientInfo))->willEndNavigationGesture(page, backForwardListItem); } void TestController::didEndNavigationGesture(WKPageRef page, WKBackForwardListItemRef backForwardListItem, const void *clientInfo) { static_cast(const_cast(clientInfo))->didEndNavigationGesture(page, backForwardListItem); } void TestController::didRemoveNavigationGestureSnapshot(WKPageRef page, const void *clientInfo) { static_cast(const_cast(clientInfo))->didRemoveNavigationGestureSnapshot(page); } WKPluginLoadPolicy TestController::decidePolicyForPluginLoad(WKPageRef page, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription, const void* clientInfo) { return static_cast(const_cast(clientInfo))->decidePolicyForPluginLoad(page, currentPluginLoadPolicy, pluginInformation, unavailabilityDescription); } WKPluginLoadPolicy TestController::decidePolicyForPluginLoad(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription) { if (m_shouldBlockAllPlugins) return kWKPluginLoadPolicyBlocked; #if PLATFORM(MAC) WKStringRef bundleIdentifier = (WKStringRef)WKDictionaryGetItemForKey(pluginInformation, WKPluginInformationBundleIdentifierKey()); if (!bundleIdentifier) return currentPluginLoadPolicy; if (WKStringIsEqualToUTF8CString(bundleIdentifier, "com.apple.QuickTime Plugin.plugin")) return currentPluginLoadPolicy; if (WKStringIsEqualToUTF8CString(bundleIdentifier, "com.apple.testnetscapeplugin")) return currentPluginLoadPolicy; RELEASE_ASSERT_NOT_REACHED(); // Please don't use any other plug-ins in tests, as they will not be installed on all machines. #else return currentPluginLoadPolicy; #endif } void TestController::didCommitNavigation(WKPageRef page, WKNavigationRef navigation) { mainWebView()->focus(); } void TestController::didFinishNavigation(WKPageRef page, WKNavigationRef navigation) { if (m_state != Resetting) return; WKRetainPtr wkURL(AdoptWK, WKFrameCopyURL(WKPageGetMainFrame(page))); if (!WKURLIsEqual(wkURL.get(), blankURL())) return; m_doneResetting = true; singleton().notifyDone(); } void TestController::didReceiveAuthenticationChallenge(WKPageRef page, WKAuthenticationChallengeRef authenticationChallenge) { WKProtectionSpaceRef protectionSpace = WKAuthenticationChallengeGetProtectionSpace(authenticationChallenge); WKAuthenticationDecisionListenerRef decisionListener = WKAuthenticationChallengeGetDecisionListener(authenticationChallenge); if (WKProtectionSpaceGetAuthenticationScheme(protectionSpace) == kWKProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested) { // Any non-empty credential signals to accept the server trust. Since the cross-platform API // doesn't expose a way to create a credential from server trust, we use a password credential. WKRetainPtr credential = adoptWK(WKCredentialCreate(toWK("accept server trust").get(), toWK("").get(), kWKCredentialPersistenceNone)); WKAuthenticationDecisionListenerUseCredential(decisionListener, credential.get()); return; } std::string host = toSTD(adoptWK(WKProtectionSpaceCopyHost(protectionSpace)).get()); int port = WKProtectionSpaceGetPort(protectionSpace); String message = String::format("%s:%d - didReceiveAuthenticationChallenge - ", host.c_str(), port); if (!m_handlesAuthenticationChallenges) message.append("Simulating cancelled authentication sheet\n"); else message.append(String::format("Responding with %s:%s\n", m_authenticationUsername.utf8().data(), m_authenticationPassword.utf8().data())); m_currentInvocation->outputText(message); if (!m_handlesAuthenticationChallenges) { WKAuthenticationDecisionListenerUseCredential(decisionListener, 0); return; } WKRetainPtr username(AdoptWK, WKStringCreateWithUTF8CString(m_authenticationUsername.utf8().data())); WKRetainPtr password(AdoptWK, WKStringCreateWithUTF8CString(m_authenticationPassword.utf8().data())); WKRetainPtr credential(AdoptWK, WKCredentialCreate(username.get(), password.get(), kWKCredentialPersistenceForSession)); WKAuthenticationDecisionListenerUseCredential(decisionListener, credential.get()); } void TestController::processDidCrash() { // This function can be called multiple times when crash logs are being saved on Windows, so // ensure we only print the crashed message once. if (!m_didPrintWebProcessCrashedMessage) { #if PLATFORM(COCOA) pid_t pid = WKPageGetProcessIdentifier(m_mainWebView->page()); fprintf(stderr, "#CRASHED - %s (pid %ld)\n", webProcessName(), static_cast(pid)); #else fprintf(stderr, "#CRASHED - %s\n", webProcessName()); #endif fflush(stderr); m_didPrintWebProcessCrashedMessage = true; } if (m_shouldExitWhenWebProcessCrashes) exit(1); } void TestController::didBeginNavigationGesture(WKPageRef) { m_currentInvocation->didBeginSwipe(); } void TestController::willEndNavigationGesture(WKPageRef, WKBackForwardListItemRef) { m_currentInvocation->willEndSwipe(); } void TestController::didEndNavigationGesture(WKPageRef, WKBackForwardListItemRef) { m_currentInvocation->didEndSwipe(); } void TestController::didRemoveNavigationGestureSnapshot(WKPageRef) { m_currentInvocation->didRemoveSwipeSnapshot(); } void TestController::simulateWebNotificationClick(uint64_t notificationID) { m_webNotificationProvider.simulateWebNotificationClick(notificationID); } void TestController::setGeolocationPermission(bool enabled) { m_isGeolocationPermissionSet = true; m_isGeolocationPermissionAllowed = enabled; decidePolicyForGeolocationPermissionRequestIfPossible(); } 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) { m_geolocationProvider->setPosition(latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed); } void TestController::setMockGeolocationPositionUnavailableError(WKStringRef errorMessage) { m_geolocationProvider->setPositionUnavailableError(errorMessage); } void TestController::handleGeolocationPermissionRequest(WKGeolocationPermissionRequestRef geolocationPermissionRequest) { m_geolocationPermissionRequests.append(geolocationPermissionRequest); decidePolicyForGeolocationPermissionRequestIfPossible(); } bool TestController::isGeolocationProviderActive() const { return m_geolocationProvider->isActive(); } static WKStringRef originUserVisibleName(WKSecurityOriginRef origin) { std::string host = toSTD(adoptWK(WKSecurityOriginCopyHost(origin))).c_str(); std::string protocol = toSTD(adoptWK(WKSecurityOriginCopyProtocol(origin))).c_str(); unsigned short port = WKSecurityOriginGetPort(origin); String userVisibleName; if (port) userVisibleName = String::format("%s://%s:%d", protocol.c_str(), host.c_str(), port); else userVisibleName = String::format("%s://%s", protocol.c_str(), host.c_str()); return WKStringCreateWithUTF8CString(userVisibleName.utf8().data()); } void TestController::setUserMediaPermission(bool enabled) { m_isUserMediaPermissionSet = true; m_isUserMediaPermissionAllowed = enabled; decidePolicyForUserMediaPermissionRequestIfPossible(); } void TestController::setUserMediaPermissionForOrigin(bool permission, WKStringRef originString) { if (!m_userMediaOriginPermissions) m_userMediaOriginPermissions = adoptWK(WKMutableDictionaryCreate()); WKRetainPtr allowed = adoptWK(WKBooleanCreate(permission)); WKRetainPtr origin = adoptWK(WKSecurityOriginCreateFromString(originString)); WKDictionarySetItem(m_userMediaOriginPermissions.get(), originUserVisibleName(origin.get()), allowed.get()); } void TestController::handleCheckOfUserMediaPermissionForOrigin(WKSecurityOriginRef origin, const WKUserMediaPermissionCheckRef& checkRequest) { bool allowed = false; if (m_userMediaOriginPermissions) { WKRetainPtr originString = originUserVisibleName(origin); WKBooleanRef value = static_cast(WKDictionaryGetItemForKey(m_userMediaOriginPermissions.get(), originString.get())); if (value && WKGetTypeID(value) == WKBooleanGetTypeID()) allowed = WKBooleanGetValue(value); } WKUserMediaPermissionCheckSetHasPersistentPermission(checkRequest, allowed); } void TestController::handleUserMediaPermissionRequest(WKSecurityOriginRef origin, WKUserMediaPermissionRequestRef request) { m_userMediaPermissionRequests.append(std::make_pair(origin, request)); decidePolicyForUserMediaPermissionRequestIfPossible(); } void TestController::decidePolicyForUserMediaPermissionRequestIfPossible() { if (!m_isUserMediaPermissionSet) return; for (auto& pair : m_userMediaPermissionRequests) { auto request = pair.second.get(); WKRetainPtr audioDeviceUIDs = WKUserMediaPermissionRequestAudioDeviceUIDs(request); WKRetainPtr videoDeviceUIDs = WKUserMediaPermissionRequestVideoDeviceUIDs(request); if (m_isUserMediaPermissionAllowed && (WKArrayGetSize(videoDeviceUIDs.get()) || WKArrayGetSize(audioDeviceUIDs.get()))) { WKRetainPtr videoDeviceUID; if (WKArrayGetSize(videoDeviceUIDs.get())) videoDeviceUID = reinterpret_cast(WKArrayGetItemAtIndex(videoDeviceUIDs.get(), 0)); else videoDeviceUID = WKStringCreateWithUTF8CString(""); WKRetainPtr audioDeviceUID; if (WKArrayGetSize(audioDeviceUIDs.get())) audioDeviceUID = reinterpret_cast(WKArrayGetItemAtIndex(audioDeviceUIDs.get(), 0)); else audioDeviceUID = WKStringCreateWithUTF8CString(""); WKUserMediaPermissionRequestAllow(request, audioDeviceUID.get(), videoDeviceUID.get()); } else WKUserMediaPermissionRequestDeny(request); } m_userMediaPermissionRequests.clear(); } void TestController::setCustomPolicyDelegate(bool enabled, bool permissive) { m_policyDelegateEnabled = enabled; m_policyDelegatePermissive = permissive; } void TestController::decidePolicyForGeolocationPermissionRequestIfPossible() { if (!m_isGeolocationPermissionSet) return; for (size_t i = 0; i < m_geolocationPermissionRequests.size(); ++i) { WKGeolocationPermissionRequestRef permissionRequest = m_geolocationPermissionRequests[i].get(); if (m_isGeolocationPermissionAllowed) WKGeolocationPermissionRequestAllow(permissionRequest); else WKGeolocationPermissionRequestDeny(permissionRequest); } m_geolocationPermissionRequests.clear(); } void TestController::decidePolicyForNotificationPermissionRequest(WKPageRef page, WKSecurityOriginRef origin, WKNotificationPermissionRequestRef request, const void*) { TestController::singleton().decidePolicyForNotificationPermissionRequest(page, origin, request); } void TestController::decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef request) { WKNotificationPermissionRequestAllow(request); } void TestController::unavailablePluginButtonClicked(WKPageRef, WKPluginUnavailabilityReason, WKDictionaryRef, const void*) { printf("MISSING PLUGIN BUTTON PRESSED\n"); } void TestController::decidePolicyForNavigationAction(WKPageRef, WKNavigationActionRef navigationAction, WKFramePolicyListenerRef listener, WKTypeRef, const void* clientInfo) { static_cast(const_cast(clientInfo))->decidePolicyForNavigationAction(listener); } void TestController::decidePolicyForNavigationAction(WKFramePolicyListenerRef listener) { WKRetainPtr retainedListener { listener }; const bool shouldIgnore { m_policyDelegateEnabled && !m_policyDelegatePermissive }; std::function decisionFunction = [shouldIgnore, retainedListener]() { if (shouldIgnore) WKFramePolicyListenerIgnore(retainedListener.get()); else WKFramePolicyListenerUse(retainedListener.get()); }; if (m_shouldDecideNavigationPolicyAfterDelay) RunLoop::main().dispatch(decisionFunction); else decisionFunction(); } void TestController::decidePolicyForNavigationResponse(WKPageRef, WKNavigationResponseRef navigationResponse, WKFramePolicyListenerRef listener, WKTypeRef, const void* clientInfo) { static_cast(const_cast(clientInfo))->decidePolicyForNavigationResponse(navigationResponse, listener); } void TestController::decidePolicyForNavigationResponse(WKNavigationResponseRef navigationResponse, WKFramePolicyListenerRef listener) { // Even though Response was already checked by WKBundlePagePolicyClient, the check did not include plugins // so we have to re-check again. if (WKNavigationResponseCanShowMIMEType(navigationResponse)) { WKFramePolicyListenerUse(listener); return; } WKFramePolicyListenerIgnore(listener); } void TestController::didNavigateWithNavigationData(WKContextRef, WKPageRef, WKNavigationDataRef navigationData, WKFrameRef frame, const void* clientInfo) { static_cast(const_cast(clientInfo))->didNavigateWithNavigationData(navigationData, frame); } void TestController::didNavigateWithNavigationData(WKNavigationDataRef navigationData, WKFrameRef) { if (m_state != RunningTest) return; if (!m_shouldLogHistoryClientCallbacks) return; // URL WKRetainPtr urlWK = adoptWK(WKNavigationDataCopyURL(navigationData)); WKRetainPtr urlStringWK = adoptWK(WKURLCopyString(urlWK.get())); // Title WKRetainPtr titleWK = adoptWK(WKNavigationDataCopyTitle(navigationData)); // HTTP method WKRetainPtr requestWK = adoptWK(WKNavigationDataCopyOriginalRequest(navigationData)); WKRetainPtr methodWK = adoptWK(WKURLRequestCopyHTTPMethod(requestWK.get())); // FIXME: Determine whether the navigation was successful / a client redirect rather than hard-coding the message here. m_currentInvocation->outputText(String::format("WebView navigated to url \"%s\" with title \"%s\" with HTTP equivalent method \"%s\". The navigation was successful and was not a client redirect.\n", toSTD(urlStringWK).c_str(), toSTD(titleWK).c_str(), toSTD(methodWK).c_str())); } void TestController::didPerformClientRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef frame, const void* clientInfo) { static_cast(const_cast(clientInfo))->didPerformClientRedirect(sourceURL, destinationURL, frame); } void TestController::didPerformClientRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef) { if (m_state != RunningTest) return; if (!m_shouldLogHistoryClientCallbacks) return; WKRetainPtr sourceStringWK = adoptWK(WKURLCopyString(sourceURL)); WKRetainPtr destinationStringWK = adoptWK(WKURLCopyString(destinationURL)); m_currentInvocation->outputText(String::format("WebView performed a client redirect from \"%s\" to \"%s\".\n", toSTD(sourceStringWK).c_str(), toSTD(destinationStringWK).c_str())); } void TestController::didPerformServerRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef frame, const void* clientInfo) { static_cast(const_cast(clientInfo))->didPerformServerRedirect(sourceURL, destinationURL, frame); } void TestController::didPerformServerRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef) { if (m_state != RunningTest) return; if (!m_shouldLogHistoryClientCallbacks) return; WKRetainPtr sourceStringWK = adoptWK(WKURLCopyString(sourceURL)); WKRetainPtr destinationStringWK = adoptWK(WKURLCopyString(destinationURL)); m_currentInvocation->outputText(String::format("WebView performed a server redirect from \"%s\" to \"%s\".\n", toSTD(sourceStringWK).c_str(), toSTD(destinationStringWK).c_str())); } void TestController::didUpdateHistoryTitle(WKContextRef, WKPageRef, WKStringRef title, WKURLRef URL, WKFrameRef frame, const void* clientInfo) { static_cast(const_cast(clientInfo))->didUpdateHistoryTitle(title, URL, frame); } void TestController::didUpdateHistoryTitle(WKStringRef title, WKURLRef URL, WKFrameRef) { if (m_state != RunningTest) return; if (!m_shouldLogHistoryClientCallbacks) return; WKRetainPtr urlStringWK(AdoptWK, WKURLCopyString(URL)); m_currentInvocation->outputText(String::format("WebView updated the title for history URL \"%s\" to \"%s\".\n", toSTD(urlStringWK).c_str(), toSTD(title).c_str())); } void TestController::setNavigationGesturesEnabled(bool value) { m_mainWebView->setNavigationGesturesEnabled(value); } #if !PLATFORM(COCOA) void TestController::platformWillRunTest(const TestInvocation&) { } void TestController::platformCreateWebView(WKPageConfigurationRef configuration, const TestOptions& options) { m_mainWebView = std::make_unique(configuration, options); } PlatformWebView* TestController::platformCreateOtherPage(PlatformWebView* parentView, WKPageConfigurationRef configuration, const TestOptions& options) { return new PlatformWebView(configuration, options); } WKContextRef TestController::platformAdjustContext(WKContextRef context, WKContextConfigurationRef contextConfiguration) { return context; } void TestController::platformResetStateToConsistentValues() { } #endif } // namespace WTR