diff options
Diffstat (limited to 'Tools/WebKitTestRunner/TestController.cpp')
-rw-r--r-- | Tools/WebKitTestRunner/TestController.cpp | 1648 |
1 files changed, 1351 insertions, 297 deletions
diff --git a/Tools/WebKitTestRunner/TestController.cpp b/Tools/WebKitTestRunner/TestController.cpp index 397815e63..df5392e74 100644 --- a/Tools/WebKitTestRunner/TestController.cpp +++ b/Tools/WebKitTestRunner/TestController.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2014-2017 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,33 +31,55 @@ #include "PlatformWebView.h" #include "StringFunctions.h" #include "TestInvocation.h" -#include <WebKit2/WKAuthenticationChallenge.h> -#include <WebKit2/WKAuthenticationDecisionListener.h> -#include <WebKit2/WKContextPrivate.h> -#include <WebKit2/WKCredential.h> -#include <WebKit2/WKIconDatabase.h> -#include <WebKit2/WKNotification.h> -#include <WebKit2/WKNotificationManager.h> -#include <WebKit2/WKNotificationPermissionRequest.h> -#include <WebKit2/WKNumber.h> -#include <WebKit2/WKPageGroup.h> -#include <WebKit2/WKPagePrivate.h> -#include <WebKit2/WKPreferencesPrivate.h> -#include <WebKit2/WKRetainPtr.h> +#include "WebCoreTestSupport.h" +#include <WebCore/UUID.h> +#include <WebKit/WKArray.h> +#include <WebKit/WKAuthenticationChallenge.h> +#include <WebKit/WKAuthenticationDecisionListener.h> +#include <WebKit/WKContextConfigurationRef.h> +#include <WebKit/WKContextPrivate.h> +#include <WebKit/WKCookieManager.h> +#include <WebKit/WKCredential.h> +#include <WebKit/WKFrameHandleRef.h> +#include <WebKit/WKFrameInfoRef.h> +#include <WebKit/WKIconDatabase.h> +#include <WebKit/WKNavigationResponseRef.h> +#include <WebKit/WKNotification.h> +#include <WebKit/WKNotificationManager.h> +#include <WebKit/WKNotificationPermissionRequest.h> +#include <WebKit/WKNumber.h> +#include <WebKit/WKOpenPanelResultListener.h> +#include <WebKit/WKPageGroup.h> +#include <WebKit/WKPageInjectedBundleClient.h> +#include <WebKit/WKPagePrivate.h> +#include <WebKit/WKPluginInformation.h> +#include <WebKit/WKPreferencesRefPrivate.h> +#include <WebKit/WKProtectionSpace.h> +#include <WebKit/WKResourceLoadStatisticsManager.h> +#include <WebKit/WKRetainPtr.h> +#include <WebKit/WKSecurityOriginRef.h> +#include <WebKit/WKTextChecker.h> +#include <WebKit/WKUserMediaPermissionCheck.h> #include <algorithm> #include <cstdio> #include <ctype.h> +#include <fstream> +#include <runtime/InitializeThreading.h> #include <stdlib.h> #include <string> -#include <wtf/PassOwnPtr.h> +#include <unistd.h> +#include <wtf/CryptographicallyRandomNumber.h> +#include <wtf/HexNumber.h> +#include <wtf/MainThread.h> +#include <wtf/RefCounted.h> +#include <wtf/RunLoop.h> +#include <wtf/SetForScope.h> #include <wtf/text/CString.h> +#include <wtf/text/WTFString.h> -#if PLATFORM(MAC) -#include <WebKit2/WKPagePrivateMac.h> -#endif - -#if !PLATFORM(MAC) -#include <WebKit2/WKTextChecker.h> +#if PLATFORM(COCOA) +#include <WebKit/WKContextPrivateMac.h> +#include <WebKit/WKPagePrivateMac.h> #endif namespace WTR { @@ -68,12 +90,9 @@ const unsigned TestController::viewHeight = 600; const unsigned TestController::w3cSVGViewWidth = 480; const unsigned TestController::w3cSVGViewHeight = 360; -// defaultLongTimeout + defaultShortTimeout should be less than 80, -// the default timeout value of the test harness so we can detect an -// unresponsive web process. -static const double defaultLongTimeout = 60; -static const double defaultShortTimeout = 15; -static const double defaultNoTimeout = -1; +const double TestController::defaultShortTimeout = 5.0; + +const double TestController::noTimeout = -1; static WKURLRef blankURL() { @@ -81,40 +100,21 @@ static WKURLRef blankURL() 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::shared() +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_longTimeout(defaultLongTimeout) - , m_shortTimeout(defaultShortTimeout) - , m_noTimeout(defaultNoTimeout) - , m_useWaitToDumpWatchdogTimer(true) - , m_forceNoTimeout(false) - , m_timeout(0) - , 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) { initialize(argc, argv); controller = this; @@ -124,7 +124,9 @@ TestController::TestController(int argc, const char* argv[]) TestController::~TestController() { - WKIconDatabaseClose(WKContextGetIconDatabase(m_context.get())); + // The context will be null if WebKitTestRunner was in server mode, but ran no tests. + if (m_context) + WKIconDatabaseClose(WKContextGetIconDatabase(m_context.get())); platformDestroy(); } @@ -144,7 +146,13 @@ static void setWindowFrame(WKPageRef page, WKRect frame, const void* clientInfo) static bool runBeforeUnloadConfirmPanel(WKPageRef page, WKStringRef message, WKFrameRef frame, const void*) { printf("CONFIRM NAVIGATION: %s\n", toSTD(message).c_str()); - return TestController::shared().beforeUnloadReturnValue(); + return TestController::singleton().beforeUnloadReturnValue(); +} + +static void runOpenPanel(WKPageRef page, WKFrameRef frame, WKOpenPanelParametersRef parameters, WKOpenPanelResultListenerRef resultListenerRef, const void*) +{ + printf("OPEN FILE PANEL\n"); + WKOpenPanelResultListenerCancel(resultListenerRef); } void TestController::runModal(WKPageRef page, const void* clientInfo) @@ -177,34 +185,44 @@ static void unfocus(WKPageRef page, const void* clientInfo) static void decidePolicyForGeolocationPermissionRequest(WKPageRef, WKFrameRef, WKSecurityOriginRef, WKGeolocationPermissionRequestRef permissionRequest, const void* clientInfo) { - TestController::shared().handleGeolocationPermissionRequest(permissionRequest); + TestController::singleton().handleGeolocationPermissionRequest(permissionRequest); } -int TestController::getCustomTimeout() +static void decidePolicyForUserMediaPermissionRequest(WKPageRef, WKFrameRef frame, WKSecurityOriginRef userMediaDocumentOrigin, WKSecurityOriginRef topLevelDocumentOrigin, WKUserMediaPermissionRequestRef permissionRequest, const void* clientInfo) { - return m_timeout; + TestController::singleton().handleUserMediaPermissionRequest(frame, userMediaDocumentOrigin, topLevelDocumentOrigin, permissionRequest); } -WKPageRef TestController::createOtherPage(WKPageRef oldPage, WKURLRequestRef, WKDictionaryRef, WKEventModifiers, WKEventMouseButton, const void* clientInfo) +static void checkUserMediaPermissionForOrigin(WKPageRef, WKFrameRef frame, WKSecurityOriginRef userMediaDocumentOrigin, WKSecurityOriginRef topLevelDocumentOrigin, WKUserMediaPermissionCheckRef checkRequest, const void*) +{ + TestController::singleton().handleCheckOfUserMediaPermissionForOrigin(frame, userMediaDocumentOrigin, topLevelDocumentOrigin, checkRequest); +} + +static void requestPointerLock(WKPageRef page, const void*) +{ + WKPageDidAllowPointerLock(page); +} + +WKPageRef TestController::createOtherPage(WKPageRef oldPage, WKPageConfigurationRef configuration, WKNavigationActionRef navigationAction, WKWindowFeaturesRef windowFeatures, const void *clientInfo) { PlatformWebView* parentView = static_cast<PlatformWebView*>(const_cast<void*>(clientInfo)); - PlatformWebView* view = new PlatformWebView(WKPageGetContext(oldPage), WKPageGetPageGroup(oldPage), oldPage, parentView->options()); + PlatformWebView* view = platformCreateOtherPage(parentView, configuration, parentView->options()); WKPageRef newPage = view->page(); view->resizeTo(800, 600); - WKPageUIClientV2 otherPageUIClient = { - { 2, view }, + WKPageUIClientV8 otherPageUIClient = { + { 8, view }, 0, // createNewPage_deprecatedForUseWithV0 0, // showPage closeOtherPage, 0, // takeFocus focus, unfocus, - 0, // runJavaScriptAlert - 0, // runJavaScriptConfirm - 0, // runJavaScriptPrompt + 0, // runJavaScriptAlert_deprecatedForUseWithV0 + 0, // runJavaScriptAlert_deprecatedForUseWithV0 + 0, // runJavaScriptAlert_deprecatedForUseWithV0 0, // setStatusText 0, // mouseDidMoveOverElement_deprecatedForUseWithV0 0, // missingPluginButtonClicked @@ -224,7 +242,7 @@ WKPageRef TestController::createOtherPage(WKPageRef oldPage, WKURLRequestRef, WK 0, // didDraw 0, // pageDidScroll 0, // exceededDatabaseQuota - 0, // runOpenPanel + runOpenPanel, decidePolicyForGeolocationPermissionRequest, 0, // headerHeight 0, // footerHeight @@ -235,18 +253,66 @@ WKPageRef TestController::createOtherPage(WKPageRef oldPage, WKURLRequestRef, WK 0, // didCompleteRubberBandForMainFrame 0, // saveDataToFileInDownloadsFolder 0, // shouldInterruptJavaScript - createOtherPage, + 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, + 0, // runBeforeUnloadConfirmPanel + 0, // fullscreenMayReturnToInline + requestPointerLock, + 0, }; 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; } @@ -262,12 +328,14 @@ const char* TestController::libraryPathForTesting() return platformLibraryPathForTesting(); } - void TestController::initialize(int argc, const char* argv[]) { + JSC::initializeThreading(); + RunLoop::initializeMainRunLoop(); + platformInitialize(); - Options options(defaultLongTimeout, defaultShortTimeout); + Options options; OptionsHandler optionsHandler(options); if (argc < 2) { @@ -277,8 +345,6 @@ void TestController::initialize(int argc, const char* argv[]) if (!optionsHandler.parse(argc, argv)) exit(1); - m_longTimeout = options.longTimeout; - m_shortTimeout = options.shortTimeout; m_useWaitToDumpWatchdogTimer = options.useWaitToDumpWatchdogTimer; m_forceNoTimeout = options.forceNoTimeout; m_verbose = options.verbose; @@ -288,6 +354,8 @@ void TestController::initialize(int argc, const char* argv[]) 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 @@ -305,32 +373,50 @@ void TestController::initialize(int argc, const char* argv[]) initializeInjectedBundlePath(); initializeTestPluginDirectory(); +#if PLATFORM(MAC) + WebCoreTestSupport::installMockGamepadProvider(); +#endif WKRetainPtr<WKStringRef> pageGroupIdentifier(AdoptWK, WKStringCreateWithUTF8CString("WebKitTestRunnerPageGroup")); m_pageGroup.adopt(WKPageGroupCreateWithIdentifier(pageGroupIdentifier.get())); +} - m_context.adopt(WKContextCreateWithInjectedBundlePath(injectedBundlePath())); - m_geolocationProvider = adoptPtr(new GeolocationProviderMock(m_context.get())); - -#if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED > 1080) - WKContextSetUsesNetworkProcess(m_context.get(), true); - WKContextSetProcessModel(m_context.get(), kWKProcessModelMultipleSecondaryProcesses); -#endif +WKRetainPtr<WKContextConfigurationRef> 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); - // WebCore::pathByAppendingComponent is not used here because of the namespace, - // which leads us to this ugly #ifdef and file path concatenation. const char separator = '/'; - WKContextSetApplicationCacheDirectory(m_context.get(), toWK(temporaryFolder + separator + "ApplicationCache").get()); - WKContextSetDatabaseDirectory(m_context.get(), toWK(temporaryFolder + separator + "Databases").get()); - WKContextSetLocalStorageDirectory(m_context.get(), toWK(temporaryFolder + separator + "LocalStorage").get()); - WKContextSetDiskCacheDirectory(m_context.get(), toWK(temporaryFolder + separator + "Cache").get()); - WKContextSetCookieStorageDirectory(m_context.get(), toWK(temporaryFolder + separator + "Cookies").get()); - WKContextSetIconDatabasePath(m_context.get(), toWK(temporaryFolder + separator + "IconDatabase" + separator + "WebpageIcons.db").get()); + 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<WKPageConfigurationRef> TestController::generatePageConfiguration(WKContextConfigurationRef configuration) +{ + m_context = platformAdjustContext(adoptWK(WKContextCreateWithConfiguration(configuration)).get(), configuration); + + m_geolocationProvider = std::make_unique<GeolocationProviderMock>(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 <http://127.0.0.1:8000/favicon.ico> 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()); } + WKContextSetDiskCacheSpeculativeValidationEnabled(m_context.get(), true); WKContextUseTestingNetworkSession(m_context.get()); WKContextSetCacheModel(m_context.get(), kWKCacheModelDocumentBrowser); @@ -340,10 +426,30 @@ void TestController::initialize(int argc, const char* argv[]) { 1, this }, didReceiveMessageFromInjectedBundle, didReceiveSynchronousMessageFromInjectedBundle, - 0 // getInjectedBundleInitializationUserData + getInjectedBundleInitializationUserData, }; WKContextSetInjectedBundleClient(m_context.get(), &injectedBundleClient.base); + WKContextClientV2 contextClient = { + { 2, this }, + 0, // plugInAutoStartOriginHashesChanged + networkProcessDidCrash, + 0, // plugInInformationBecameAvailable + 0, // copyWebCryptoMasterKey + databaseProcessDidCrash, + }; + 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); @@ -354,34 +460,40 @@ void TestController::initialize(int argc, const char* argv[]) if (m_forceComplexText) WKContextSetAlwaysUsesComplexTextCodePath(m_context.get(), true); - // Some preferences (notably mock scroll bars setting) currently cannot be re-applied to an existing view, so we need to set them now. - resetPreferencesToConsistentValues(); - - WKRetainPtr<WKMutableDictionaryRef> viewOptions; - if (m_shouldUseRemoteLayerTree) { - viewOptions = adoptWK(WKMutableDictionaryCreate()); - WKRetainPtr<WKStringRef> useRemoteLayerTreeKey = adoptWK(WKStringCreateWithUTF8CString("RemoteLayerTree")); - WKRetainPtr<WKBooleanRef> useRemoteLayerTreeValue = adoptWK(WKBooleanCreate(m_shouldUseRemoteLayerTree)); - WKDictionarySetItem(viewOptions.get(), useRemoteLayerTreeKey.get(), useRemoteLayerTreeValue.get()); - } - - createWebViewWithOptions(viewOptions.get()); + 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(WKDictionaryRef options) +void TestController::createWebViewWithOptions(const TestOptions& options) { - m_mainWebView = adoptPtr(new PlatformWebView(m_context.get(), m_pageGroup.get(), 0, options)); - WKPageUIClientV2 pageUIClient = { - { 2, m_mainWebView.get() }, + auto contextConfiguration = generateContextConfiguration(); + + WKRetainPtr<WKMutableArrayRef> 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(options); + + platformCreateWebView(configuration.get(), options); + WKPageUIClientV8 pageUIClient = { + { 8, m_mainWebView.get() }, 0, // createNewPage_deprecatedForUseWithV0 0, // showPage 0, // close 0, // takeFocus focus, unfocus, - 0, // runJavaScriptAlert - 0, // runJavaScriptConfirm - 0, // runJavaScriptPrompt + 0, // runJavaScriptAlert_deprecatedForUseWithV0 + 0, // runJavaScriptAlert_deprecatedForUseWithV0 + 0, // runJavaScriptAlert_deprecatedForUseWithV0 0, // setStatusText 0, // mouseDidMoveOverElement_deprecatedForUseWithV0 0, // missingPluginButtonClicked @@ -401,7 +513,7 @@ void TestController::createWebViewWithOptions(WKDictionaryRef options) 0, // didDraw 0, // pageDidScroll 0, // exceededDatabaseQuota, - 0, // runOpenPanel + runOpenPanel, decidePolicyForGeolocationPermissionRequest, 0, // headerHeight 0, // footerHeight @@ -412,98 +524,128 @@ void TestController::createWebViewWithOptions(WKDictionaryRef options) 0, // didCompleteRubberBandForMainFrame 0, // saveDataToFileInDownloadsFolder 0, // shouldInterruptJavaScript - createOtherPage, + 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, + 0, // runBeforeUnloadConfirmPanel + 0, // fullscreenMayReturnToInline + requestPointerLock, + 0, }; WKPageSetPageUIClient(m_mainWebView->page(), &pageUIClient.base); - WKPageLoaderClientV4 pageLoaderClient = { - { 4, this }, - 0, // didStartProvisionalLoadForFrame - 0, // didReceiveServerRedirectForProvisionalLoadForFrame - 0, // didFailProvisionalLoadWithErrorForFrame - didCommitLoadForFrame, - 0, // didFinishDocumentLoadForFrame - didFinishLoadForFrame, - 0, // didFailLoadWithErrorForFrame - 0, // didSameDocumentNavigationForFrame - 0, // didReceiveTitleForFrame - 0, // didFirstLayoutForFrame - 0, // didFirstVisuallyNonEmptyLayoutForFrame - 0, // didRemoveFrameFromHierarchy - 0, // didFailToInitializePlugin - 0, // didDisplayInsecureContentForFrame - 0, // canAuthenticateAgainstProtectionSpaceInFrame - didReceiveAuthenticationChallengeInFrame, // didReceiveAuthenticationChallengeInFrame - 0, // didStartProgress - 0, // didChangeProgress - 0, // didFinishProgress - 0, // didBecomeUnresponsive - 0, // didBecomeResponsive + 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, - 0, // didChangeBackForwardList - 0, // shouldGoToBackForwardListItem - 0, // didRunInsecureContentForFrame - 0, // didDetectXSSForFrame - 0, // didNewFirstVisuallyNonEmptyLayout_unavailable - 0, // willGoToBackForwardListItem - 0, // interactionOccurredWhileProcessUnresponsive - 0, // pluginDidFail_deprecatedForUseWithV1 - 0, // didReceiveIntentForFrame - 0, // registerIntentServiceForFrame - 0, // didLayout - 0, // pluginLoadPolicy_deprecatedForUseWithV2 - 0, // pluginDidFail - pluginLoadPolicy, // pluginLoadPolicy - 0, // webGLLoadPolicy + copyWebCryptoMasterKey, + didBeginNavigationGesture, + willEndNavigationGesture, + didEndNavigationGesture, + didRemoveNavigationGestureSnapshot }; - WKPageSetPageLoaderClient(m_mainWebView->page(), &pageLoaderClient.base); - - WKPagePolicyClientV1 pagePolicyClient = { - { 1, this }, - 0, // decidePolicyForNavigationAction_deprecatedForUseWithV0 - 0, // decidePolicyForNewWindowAction - 0, // decidePolicyForResponse_deprecatedForUseWithV0 - 0, // unableToImplementPolicy - decidePolicyForNavigationAction, - decidePolicyForResponse, + WKPageSetPageNavigationClient(m_mainWebView->page(), &pageNavigationClient.base); + + WKContextDownloadClientV0 downloadClient = { + { 0, this }, + downloadDidStart, + 0, // didReceiveAuthenticationChallenge + 0, // didReceiveResponse + 0, // didReceiveData + 0, // shouldDecodeSourceDataOfMIMEType + decideDestinationWithSuggestedFilename, + 0, // didCreateDestination + downloadDidFinish, + downloadDidFail, + downloadDidCancel, + 0 // processDidCrash; + }; + WKContextSetDownloadClient(context(), &downloadClient.base); + + // this should just be done on the page? + WKPageInjectedBundleClientV0 injectedBundleClient = { + { 0, this }, + didReceivePageMessageFromInjectedBundle, + didReceiveSynchronousPageMessageFromInjectedBundle }; - WKPageSetPagePolicyClient(m_mainWebView->page(), &pagePolicyClient.base); + 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::ensureViewSupportsOptions(WKDictionaryRef options) +void TestController::ensureViewSupportsOptionsForTest(const TestInvocation& test) { - if (m_mainWebView && !m_mainWebView->viewSupportsOptions(options)) { - WKPageSetPageUIClient(m_mainWebView->page(), 0); - WKPageSetPageLoaderClient(m_mainWebView->page(), 0); - WKPageSetPagePolicyClient(m_mainWebView->page(), 0); + 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); - resetStateToConsistentValues(); + m_mainWebView = nullptr; } + + createWebViewWithOptions(options); + + if (!resetStateToConsistentValues(options)) + TestInvocation::dumpWebProcessUnresponsiveness("<unknown> - TestController::run - Failed to reset state to consistent values\n"); } -void TestController::resetPreferencesToConsistentValues() +void TestController::resetPreferencesToConsistentValues(const TestOptions& options) { // Reset preferences - WKPreferencesRef preferences = WKPageGroupGetPreferences(m_pageGroup.get()); + WKPreferencesRef preferences = platformPreferences(); WKPreferencesResetTestRunnerOverrides(preferences); + WKPreferencesEnableAllExperimentalFeatures(preferences); + WKPreferencesSetPageVisibilityBasedProcessSuppressionEnabled(preferences, false); WKPreferencesSetOfflineWebApplicationCacheEnabled(preferences, true); WKPreferencesSetFontSmoothingLevel(preferences, kWKFontSmoothingLevelNoSubpixelAntiAliasing); WKPreferencesSetXSSAuditorEnabled(preferences, false); WKPreferencesSetWebAudioEnabled(preferences, true); + WKPreferencesSetMediaStreamEnabled(preferences, true); WKPreferencesSetDeveloperExtrasEnabled(preferences, true); - WKPreferencesSetJavaScriptExperimentsEnabled(preferences, true); + WKPreferencesSetJavaScriptRuntimeFlags(preferences, kWKJavaScriptRuntimeFlagsAllEnabled); WKPreferencesSetJavaScriptCanOpenWindowsAutomatically(preferences, true); WKPreferencesSetJavaScriptCanAccessClipboard(preferences, true); WKPreferencesSetDOMPasteAllowed(preferences, true); @@ -518,7 +660,14 @@ void TestController::resetPreferencesToConsistentValues() WKPreferencesSetArtificialPluginInitializationDelayEnabled(preferences, false); WKPreferencesSetTabToLinksEnabled(preferences, false); WKPreferencesSetInteractiveFormValidationEnabled(preferences, true); - WKPreferencesSetMockScrollbarsEnabled(preferences, true); + + WKPreferencesSetMockScrollbarsEnabled(preferences, options.useMockScrollbars); + WKPreferencesSetNeedsSiteSpecificQuirks(preferences, options.needsSiteSpecificQuirks); + WKPreferencesSetIntersectionObserverEnabled(preferences, options.enableIntersectionObserver); + WKPreferencesSetModernMediaControlsEnabled(preferences, options.enableModernMediaControls); + + static WKStringRef defaultTextEncoding = WKStringCreateWithUTF8CString("ISO-8859-1"); + WKPreferencesSetDefaultTextEncodingName(preferences, defaultTextEncoding); static WKStringRef standardFontFamily = WKStringCreateWithUTF8CString("Times"); static WKStringRef cursiveFontFamily = WKStringCreateWithUTF8CString("Apple Chancery"); @@ -528,6 +677,7 @@ void TestController::resetPreferencesToConsistentValues() static WKStringRef sansSerifFontFamily = WKStringCreateWithUTF8CString("Helvetica"); static WKStringRef serifFontFamily = WKStringCreateWithUTF8CString("Times"); + WKPreferencesSetMinimumFontSize(preferences, 0); WKPreferencesSetStandardFontFamily(preferences, standardFontFamily); WKPreferencesSetCursiveFontFamily(preferences, cursiveFontFamily); WKPreferencesSetFantasyFontFamily(preferences, fantasyFontFamily); @@ -535,21 +685,40 @@ void TestController::resetPreferencesToConsistentValues() WKPreferencesSetPictographFontFamily(preferences, pictographFontFamily); WKPreferencesSetSansSerifFontFamily(preferences, sansSerifFontFamily); WKPreferencesSetSerifFontFamily(preferences, serifFontFamily); - WKPreferencesSetScreenFontSubstitutionEnabled(preferences, true); 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); + + WKPreferencesSetResourceTimingEnabled(preferences, true); + + WKPreferencesSetMediaPlaybackAllowsInline(preferences, true); + WKPreferencesSetInlineMediaPlaybackRequiresPlaysInlineAttribute(preferences, false); + + WKCookieManagerDeleteAllCookies(WKContextGetCookieManager(m_context.get())); + + WKPreferencesSetMockCaptureDevicesEnabled(preferences, true); + + platformResetPreferencesToConsistentValues(); } -bool TestController::resetStateToConsistentValues() +bool TestController::resetStateToConsistentValues(const TestOptions& options) { - m_state = Resetting; - + SetForScope<State> 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<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("Reset")); WKRetainPtr<WKMutableDictionaryRef> resetMessageBody = adoptWK(WKMutableDictionaryCreate()); @@ -557,39 +726,58 @@ bool TestController::resetStateToConsistentValues() WKRetainPtr<WKBooleanRef> shouldGCValue = adoptWK(WKBooleanCreate(m_gcBetweenTests)); WKDictionarySetItem(resetMessageBody.get(), shouldGCKey.get(), shouldGCValue.get()); - WKContextPostMessageToInjectedBundle(TestController::shared().context(), messageName.get(), resetMessageBody.get()); + WKRetainPtr<WKStringRef> allowedHostsKey = adoptWK(WKStringCreateWithUTF8CString("AllowedHosts")); + WKRetainPtr<WKMutableArrayRef> allowedHostsValue = adoptWK(WKMutableArrayCreate()); + for (auto& host : m_allowedHosts) { + WKRetainPtr<WKStringRef> 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); - WKContextSetShouldUseFontSmoothing(TestController::shared().context(), false); + WKContextSetCacheModel(TestController::singleton().context(), kWKCacheModelDocumentBrowser); - WKContextSetCacheModel(TestController::shared().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 = adoptPtr(new EventSenderProxy(this)); + m_eventSenderProxy = std::make_unique<EventSenderProxy>(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(); + resetPreferencesToConsistentValues(options); -#if !PLATFORM(MAC) +#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 + // Make sure the view is in the window (a test can unparent it). + m_mainWebView->addToWindow(); + + // 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. + // EFL uses 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 + WKPageSetMuted(m_mainWebView->page(), true); + + WKPageClearUserMediaState(m_mainWebView->page()); + // Reset notification permissions m_webNotificationProvider.reset(); @@ -598,33 +786,250 @@ bool TestController::resetStateToConsistentValues() m_isGeolocationPermissionSet = false; m_isGeolocationPermissionAllowed = false; + // Reset UserMedia permissions. + m_userMediaPermissionRequests.clear(); + m_cachedUserMediaPermissions.clear(); + m_isUserMediaPermissionSet = false; + m_isUserMediaPermissionAllowed = false; + // Reset Custom Policy Delegate. setCustomPolicyDelegate(false, false); + m_shouldDownloadUndisplayableMIMETypes = false; + m_workQueueManager.clearWorkQueue(); + m_rejectsProtectionSpaceAndContinueForAuthenticationChallenges = false; m_handlesAuthenticationChallenges = false; m_authenticationUsername = String(); m_authenticationPassword = String(); m_shouldBlockAllPlugins = false; + m_shouldLogHistoryClientCallbacks = false; + m_shouldLogCanAuthenticateAgainstProtectionSpace = false; + + setHidden(false); + + platformResetStateToConsistentValues(); + // Reset main page back to about:blank m_doneResetting = false; + m_shouldDecideNavigationPolicyAfterDelay = false; + + setNavigationGesturesEnabled(false); + + setIgnoresViewportScaleLimits(options.ignoresViewportScaleLimits); + WKPageLoadURL(m_mainWebView->page(), blankURL()); - runUntil(m_doneResetting, ShortTimeout); + runUntil(m_doneResetting, m_currentInvocation->shortTimeout()); return m_doneResetting; } -struct TestCommand { - TestCommand() : shouldDumpPixels(false), timeout(0) { } +void TestController::terminateWebContentProcess() +{ + WKPageTerminate(m_mainWebView->page()); +} - std::string pathOrURL; - bool shouldDumpPixels; - std::string expectedPixelHash; - int timeout; -}; +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, m_currentInvocation->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 +} + +const char* TestController::databaseProcessName() +{ + // FIXME: Find a way to not hardcode the process name. +#if PLATFORM(COCOA) + return "com.apple.WebKit.Databases.Development"; +#else + return "DatabaseProcess"; +#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<char>(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<char[]> buffer; + if (isAbsolutePath) { + buffer = std::make_unique<char[]>(prefixLength + length + 1); + strcpy(buffer.get(), filePrefix); + strcpy(buffer.get() + prefixLength, pathOrURL); + } else { + buffer = std::make_unique<char[]>(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, const std::string& absolutePath) +{ + std::string filename = absolutePath; + if (filename.empty()) { + // Gross. Need to reduce conversions between all the string types and URLs. + WKRetainPtr<WKURLRef> wkURL(AdoptWK, createTestURL(pathOrURL.c_str())); + 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); + if (key == "useMockScrollbars") + testOptions.useMockScrollbars = parseBooleanTestHeaderValue(value); + if (key == "needsSiteSpecificQuirks") + testOptions.needsSiteSpecificQuirks = parseBooleanTestHeaderValue(value); + if (key == "ignoresViewportScaleLimits") + testOptions.ignoresViewportScaleLimits = parseBooleanTestHeaderValue(value); + if (key == "useCharacterSelectionGranularity") + testOptions.useCharacterSelectionGranularity = parseBooleanTestHeaderValue(value); + if (key == "enableIntersectionObserver") + testOptions.enableIntersectionObserver = parseBooleanTestHeaderValue(value); + if (key == "enableModernMediaControls") + testOptions.enableModernMediaControls = parseBooleanTestHeaderValue(value); + if (key == "enablePointerLock") + testOptions.enablePointerLock = parseBooleanTestHeaderValue(value); + pairStart = pairEnd + 1; + } +} + +TestOptions TestController::testOptionsForTest(const TestCommand& command) const +{ + TestOptions options(command.pathOrURL); + + options.useRemoteLayerTree = m_shouldUseRemoteLayerTree; + options.shouldShowWebView = m_shouldShowWebView; + + updatePlatformSpecificTestOptionsForTest(options, command.pathOrURL); + updateTestOptionsFromTestHeader(options, command.pathOrURL, command.absolutePath); + + 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().deviceScaleFactor); +} + +void TestController::configureViewForTest(const TestInvocation& test) +{ + ensureViewSupportsOptionsForTest(test); + updateWebViewSizeForTest(test); + updateWindowScaleForTest(mainWebView(), test); + + platformConfigureViewForTest(test); +} class CommandTokenizer { public: @@ -696,7 +1101,11 @@ TestCommand parseInputLine(const std::string& inputLine) result.shouldDumpPixels = true; if (tokenizer.hasNext()) result.expectedPixelHash = tokenizer.next(); - } else + } else if (arg == std::string("--dump-jsconsolelog-in-stderr")) + result.dumpJSConsoleLogInStdErr = true; + else if (arg == std::string("--absolutePath")) + result.absolutePath = tokenizer.next(); + else die(inputLine); } return result; @@ -704,18 +1113,26 @@ TestCommand parseInputLine(const std::string& inputLine) bool TestController::runTest(const char* inputLine) { + WKTextCheckerSetTestingMode(true); TestCommand command = parseInputLine(std::string(inputLine)); m_state = RunningTest; + + TestOptions options = testOptionsForTest(command); + + WKRetainPtr<WKURLRef> wkURL(AdoptWK, createTestURL(command.pathOrURL.c_str())); + m_currentInvocation = std::make_unique<TestInvocation>(wkURL.get(), options); - m_currentInvocation = adoptPtr(new TestInvocation(command.pathOrURL)); if (command.shouldDumpPixels || m_shouldDumpPixelsForAllTests) m_currentInvocation->setIsPixelTest(command.expectedPixelHash); if (command.timeout > 0) m_currentInvocation->setCustomTimeout(command.timeout); + m_currentInvocation->setDumpJSConsoleLogInStdErr(command.dumpJSConsoleLogInStdErr); + + platformWillRunTest(*m_currentInvocation); m_currentInvocation->invoke(); - m_currentInvocation.clear(); + m_currentInvocation = nullptr; return true; } @@ -738,11 +1155,6 @@ void TestController::runTestingServerLoop() void TestController::run() { - if (!resetStateToConsistentValues()) { - TestInvocation::dumpWebProcessUnresponsiveness("<unknown> - TestController::run - Failed to reset state to consistent values\n"); - return; - } - if (m_usingServerMode) runTestingServerLoop(); else { @@ -753,26 +1165,10 @@ void TestController::run() } } -void TestController::runUntil(bool& done, TimeoutDuration timeoutDuration) +void TestController::runUntil(bool& done, double timeout) { - double timeout = m_noTimeout; - if (!m_forceNoTimeout) { - switch (timeoutDuration) { - case ShortTimeout: - timeout = m_shortTimeout; - break; - case LongTimeout: - timeout = m_longTimeout; - break; - case CustomTimeout: - timeout = m_timeout; - break; - case NoTimeout: - default: - timeout = m_noTimeout; - break; - } - } + if (m_forceNoTimeout) + timeout = noTimeout; platformRunUntil(done, timeout); } @@ -789,6 +1185,33 @@ void TestController::didReceiveSynchronousMessageFromInjectedBundle(WKContextRef *returnData = static_cast<TestController*>(const_cast<void*>(clientInfo))->didReceiveSynchronousMessageFromInjectedBundle(messageName, messageBody).leakRef(); } +WKTypeRef TestController::getInjectedBundleInitializationUserData(WKContextRef, const void* clientInfo) +{ + return static_cast<TestController*>(const_cast<void*>(clientInfo))->getInjectedBundleInitializationUserData().leakRef(); +} + +// WKPageInjectedBundleClient + +void TestController::didReceivePageMessageFromInjectedBundle(WKPageRef page, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo) +{ + static_cast<TestController*>(const_cast<void*>(clientInfo))->didReceiveMessageFromInjectedBundle(messageName, messageBody); +} + +void TestController::didReceiveSynchronousPageMessageFromInjectedBundle(WKPageRef page, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void* clientInfo) +{ + *returnData = static_cast<TestController*>(const_cast<void*>(clientInfo))->didReceiveSynchronousMessageFromInjectedBundle(messageName, messageBody).leakRef(); +} + +void TestController::networkProcessDidCrash(WKContextRef context, const void *clientInfo) +{ + static_cast<TestController*>(const_cast<void*>(clientInfo))->networkProcessDidCrash(); +} + +void TestController::databaseProcessDidCrash(WKContextRef context, const void *clientInfo) +{ + static_cast<TestController*>(const_cast<void*>(clientInfo))->databaseProcessDidCrash(); +} + void TestController::didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef messageBodyDictionary, bool synchronous) { WKRetainPtr<WKStringRef> keyKey = adoptWK(WKStringCreateWithUTF8CString("Key")); @@ -800,18 +1223,15 @@ void TestController::didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef WKRetainPtr<WKStringRef> locationKey = adoptWK(WKStringCreateWithUTF8CString("Location")); unsigned location = static_cast<unsigned>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, locationKey.get())))); - if (synchronous) - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true); - m_eventSenderProxy->keyDown(key, modifiers, location); - - if (synchronous) - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false); } void TestController::didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody) { if (WKStringIsEqualToUTF8CString(messageName, "EventSender")) { + if (m_state != RunningTest) + return; + ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); @@ -826,7 +1246,6 @@ void TestController::didReceiveMessageFromInjectedBundle(WKStringRef messageName WKEventModifiers modifiers = static_cast<WKEventModifiers>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, modifiersKey.get())))); // Forward to WebProcess - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false); if (WKStringIsEqualToUTF8CString(subMessageName, "MouseDown")) m_eventSenderProxy->mouseDown(button, modifiers); else @@ -841,6 +1260,53 @@ void TestController::didReceiveMessageFromInjectedBundle(WKStringRef messageName return; } + if (WKStringIsEqualToUTF8CString(subMessageName, "MouseScrollBy")) { + WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X")); + double x = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))); + + WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); + double y = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))); + + // Forward to WebProcess + m_eventSenderProxy->mouseScrollBy(x, y); + return; + } + + if (WKStringIsEqualToUTF8CString(subMessageName, "MouseScrollByWithWheelAndMomentumPhases")) { + WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X")); + double x = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))); + + WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); + double y = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))); + + WKRetainPtr<WKStringRef> phaseKey = adoptWK(WKStringCreateWithUTF8CString("Phase")); + int phase = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, phaseKey.get())))); + WKRetainPtr<WKStringRef> momentumKey = adoptWK(WKStringCreateWithUTF8CString("Momentum")); + int momentum = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, momentumKey.get())))); + + // Forward to WebProcess + m_eventSenderProxy->mouseScrollByWithWheelAndMomentumPhases(x, y, phase, momentum); + + return; + } + + if (WKStringIsEqualToUTF8CString(subMessageName, "SwipeGestureWithWheelAndMomentumPhases")) { + WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X")); + double x = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))); + + WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); + double y = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))); + + WKRetainPtr<WKStringRef> phaseKey = adoptWK(WKStringCreateWithUTF8CString("Phase")); + int phase = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, phaseKey.get())))); + WKRetainPtr<WKStringRef> momentumKey = adoptWK(WKStringCreateWithUTF8CString("Momentum")); + int momentum = static_cast<int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, momentumKey.get())))); + + m_eventSenderProxy->swipeGestureWithWheelAndMomentumPhases(x, y, phase, momentum); + + return; + } + ASSERT_NOT_REACHED(); } @@ -853,6 +1319,9 @@ void TestController::didReceiveMessageFromInjectedBundle(WKStringRef messageName WKRetainPtr<WKTypeRef> TestController::didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody) { if (WKStringIsEqualToUTF8CString(messageName, "EventSender")) { + if (m_state != RunningTest) + return nullptr; + ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody); @@ -873,12 +1342,10 @@ WKRetainPtr<WKTypeRef> TestController::didReceiveSynchronousMessageFromInjectedB WKEventModifiers modifiers = static_cast<WKEventModifiers>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, modifiersKey.get())))); // Forward to WebProcess - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true); if (WKStringIsEqualToUTF8CString(subMessageName, "MouseDown")) m_eventSenderProxy->mouseDown(button, modifiers); else m_eventSenderProxy->mouseUp(button, modifiers); - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false); return 0; } @@ -890,25 +1357,39 @@ WKRetainPtr<WKTypeRef> TestController::didReceiveSynchronousMessageFromInjectedB double y = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))); // Forward to WebProcess - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true); m_eventSenderProxy->mouseMoveTo(x, y); - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false); return 0; } - if (WKStringIsEqualToUTF8CString(subMessageName, "MouseScrollBy")) { - WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X")); - double x = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, xKey.get()))); +#if PLATFORM(MAC) + if (WKStringIsEqualToUTF8CString(subMessageName, "MouseForceClick")) { + m_eventSenderProxy->mouseForceClick(); + return 0; + } - WKRetainPtr<WKStringRef> yKey = adoptWK(WKStringCreateWithUTF8CString("Y")); - double y = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, yKey.get()))); + if (WKStringIsEqualToUTF8CString(subMessageName, "StartAndCancelMouseForceClick")) { + m_eventSenderProxy->startAndCancelMouseForceClick(); + return 0; + } - // Forward to WebProcess - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true); - m_eventSenderProxy->mouseScrollBy(x, y); - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false); + if (WKStringIsEqualToUTF8CString(subMessageName, "MouseForceDown")) { + m_eventSenderProxy->mouseForceDown(); + return 0; + } + + if (WKStringIsEqualToUTF8CString(subMessageName, "MouseForceUp")) { + m_eventSenderProxy->mouseForceUp(); + return 0; + } + + if (WKStringIsEqualToUTF8CString(subMessageName, "MouseForceChanged")) { + WKRetainPtr<WKStringRef> forceKey = adoptWK(WKStringCreateWithUTF8CString("Force")); + double force = WKDoubleGetValue(static_cast<WKDoubleRef>(WKDictionaryGetItemForKey(messageBodyDictionary, forceKey.get()))); + + m_eventSenderProxy->mouseForceChanged(force); return 0; } +#endif // PLATFORM(MAC) if (WKStringIsEqualToUTF8CString(subMessageName, "ContinuousMouseScrollBy")) { WKRetainPtr<WKStringRef> xKey = adoptWK(WKStringCreateWithUTF8CString("X")); @@ -921,9 +1402,7 @@ WKRetainPtr<WKTypeRef> TestController::didReceiveSynchronousMessageFromInjectedB bool paged = static_cast<bool>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, pagedKey.get())))); // Forward to WebProcess - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true); m_eventSenderProxy->continuousMouseScrollBy(x, y, paged); - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false); return 0; } @@ -984,30 +1463,22 @@ WKRetainPtr<WKTypeRef> TestController::didReceiveSynchronousMessageFromInjectedB } if (WKStringIsEqualToUTF8CString(subMessageName, "TouchStart")) { - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true); m_eventSenderProxy->touchStart(); - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "TouchMove")) { - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true); m_eventSenderProxy->touchMove(); - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "TouchEnd")) { - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true); m_eventSenderProxy->touchEnd(); - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false); return 0; } if (WKStringIsEqualToUTF8CString(subMessageName, "TouchCancel")) { - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), true); m_eventSenderProxy->touchCancel(); - WKPageSetShouldSendEventsSynchronously(mainWebView()->page(), false); return 0; } @@ -1035,21 +1506,47 @@ WKRetainPtr<WKTypeRef> TestController::didReceiveSynchronousMessageFromInjectedB return m_currentInvocation->didReceiveSynchronousMessageFromInjectedBundle(messageName, messageBody); } -// WKPageLoaderClient +WKRetainPtr<WKTypeRef> TestController::getInjectedBundleInitializationUserData() +{ + return nullptr; +} -void TestController::didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef, const void* clientInfo) +// WKContextClient + +void TestController::networkProcessDidCrash() { - static_cast<TestController*>(const_cast<void*>(clientInfo))->didCommitLoadForFrame(page, frame); + pid_t pid = WKContextGetNetworkProcessIdentifier(m_context.get()); + fprintf(stderr, "#CRASHED - %s (pid %ld)\n", networkProcessName(), static_cast<long>(pid)); + exit(1); } -void TestController::didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef, const void* clientInfo) +void TestController::databaseProcessDidCrash() { - static_cast<TestController*>(const_cast<void*>(clientInfo))->didFinishLoadForFrame(page, frame); + pid_t pid = WKContextGetDatabaseProcessIdentifier(m_context.get()); + fprintf(stderr, "#CRASHED - %s (pid %ld)\n", databaseProcessName(), static_cast<long>(pid)); + exit(1); } -void TestController::didReceiveAuthenticationChallengeInFrame(WKPageRef page, WKFrameRef frame, WKAuthenticationChallengeRef authenticationChallenge, const void *clientInfo) +// WKPageNavigationClient + +void TestController::didCommitNavigation(WKPageRef page, WKNavigationRef navigation, WKTypeRef, const void* clientInfo) { - static_cast<TestController*>(const_cast<void*>(clientInfo))->didReceiveAuthenticationChallengeInFrame(page, frame, authenticationChallenge); + static_cast<TestController*>(const_cast<void*>(clientInfo))->didCommitNavigation(page, navigation); +} + +void TestController::didFinishNavigation(WKPageRef page, WKNavigationRef navigation, WKTypeRef, const void* clientInfo) +{ + static_cast<TestController*>(const_cast<void*>(clientInfo))->didFinishNavigation(page, navigation); +} + +bool TestController::canAuthenticateAgainstProtectionSpace(WKPageRef page, WKProtectionSpaceRef protectionSpace, const void* clientInfo) +{ + return static_cast<TestController*>(const_cast<void*>(clientInfo))->canAuthenticateAgainstProtectionSpace(page, protectionSpace); +} + +void TestController::didReceiveAuthenticationChallenge(WKPageRef page, WKAuthenticationChallengeRef authenticationChallenge, const void *clientInfo) +{ + static_cast<TestController*>(const_cast<void*>(clientInfo))->didReceiveAuthenticationChallenge(page, /*frame,*/ authenticationChallenge); } void TestController::processDidCrash(WKPageRef page, const void* clientInfo) @@ -1057,52 +1554,114 @@ void TestController::processDidCrash(WKPageRef page, const void* clientInfo) static_cast<TestController*>(const_cast<void*>(clientInfo))->processDidCrash(); } -WKPluginLoadPolicy TestController::pluginLoadPolicy(WKPageRef page, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription, const void* clientInfo) +void TestController::didBeginNavigationGesture(WKPageRef page, const void *clientInfo) +{ + static_cast<TestController*>(const_cast<void*>(clientInfo))->didBeginNavigationGesture(page); +} + +void TestController::willEndNavigationGesture(WKPageRef page, WKBackForwardListItemRef backForwardListItem, const void *clientInfo) +{ + static_cast<TestController*>(const_cast<void*>(clientInfo))->willEndNavigationGesture(page, backForwardListItem); +} + +void TestController::didEndNavigationGesture(WKPageRef page, WKBackForwardListItemRef backForwardListItem, const void *clientInfo) +{ + static_cast<TestController*>(const_cast<void*>(clientInfo))->didEndNavigationGesture(page, backForwardListItem); +} + +void TestController::didRemoveNavigationGestureSnapshot(WKPageRef page, const void *clientInfo) +{ + static_cast<TestController*>(const_cast<void*>(clientInfo))->didRemoveNavigationGestureSnapshot(page); +} + +WKPluginLoadPolicy TestController::decidePolicyForPluginLoad(WKPageRef page, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription, const void* clientInfo) { - return static_cast<TestController*>(const_cast<void*>(clientInfo))->pluginLoadPolicy(page, currentPluginLoadPolicy, pluginInformation, unavailabilityDescription); + return static_cast<TestController*>(const_cast<void*>(clientInfo))->decidePolicyForPluginLoad(page, currentPluginLoadPolicy, pluginInformation, unavailabilityDescription); } -WKPluginLoadPolicy TestController::pluginLoadPolicy(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* 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::didCommitLoadForFrame(WKPageRef page, WKFrameRef frame) +void TestController::didCommitNavigation(WKPageRef page, WKNavigationRef navigation) { - if (!WKFrameIsMainFrame(frame)) - return; - mainWebView()->focus(); } -void TestController::didFinishLoadForFrame(WKPageRef page, WKFrameRef frame) +bool TestController::canAuthenticateAgainstProtectionSpace(WKPageRef page, WKProtectionSpaceRef protectionSpace) { - if (m_state != Resetting) - return; + if (m_shouldLogCanAuthenticateAgainstProtectionSpace) + m_currentInvocation->outputText("canAuthenticateAgainstProtectionSpace\n"); + 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; +} - if (!WKFrameIsMainFrame(frame)) +void TestController::didFinishNavigation(WKPageRef page, WKNavigationRef navigation) +{ + if (m_state != Resetting) return; - WKRetainPtr<WKURLRef> wkURL(AdoptWK, WKFrameCopyURL(frame)); + WKRetainPtr<WKURLRef> wkURL(AdoptWK, WKFrameCopyURL(WKPageGetMainFrame(page))); if (!WKURLIsEqual(wkURL.get(), blankURL())) return; m_doneResetting = true; - shared().notifyDone(); + singleton().notifyDone(); } -void TestController::didReceiveAuthenticationChallengeInFrame(WKPageRef page, WKFrameRef frame, WKAuthenticationChallengeRef authenticationChallenge) +void TestController::didReceiveAuthenticationChallenge(WKPageRef page, WKAuthenticationChallengeRef authenticationChallenge) { - String message; + 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<WKCredentialRef> credential = adoptWK(WKCredentialCreate(toWK("accept server trust").get(), toWK("").get(), kWKCredentialPersistenceNone)); + WKAuthenticationDecisionListenerUseCredential(decisionListener, credential.get()); + return; + } + + if (m_rejectsProtectionSpaceAndContinueForAuthenticationChallenges) { + m_currentInvocation->outputText("Simulating reject protection space and continue for authentication challenge\n"); + WKAuthenticationDecisionListenerRejectProtectionSpaceAndContinue(decisionListener); + 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 = "<unknown> - didReceiveAuthenticationChallenge - Simulating cancelled authentication sheet\n"; + message.append("Simulating cancelled authentication sheet\n"); else - message = String::format("<unknown> - didReceiveAuthenticationChallenge - Responding with %s:%s\n", m_authenticationUsername.utf8().data(), m_authenticationPassword.utf8().data()); + message.append(String::format("Responding with %s:%s\n", m_authenticationUsername.utf8().data(), m_authenticationPassword.utf8().data())); m_currentInvocation->outputText(message); - WKAuthenticationDecisionListenerRef decisionListener = WKAuthenticationChallengeGetDecisionListener(authenticationChallenge); if (!m_handlesAuthenticationChallenges) { WKAuthenticationDecisionListenerUseCredential(decisionListener, 0); return; @@ -1113,17 +1672,103 @@ void TestController::didReceiveAuthenticationChallengeInFrame(WKPageRef page, WK WKAuthenticationDecisionListenerUseCredential(decisionListener, credential.get()); } + +// WKContextDownloadClient + +void TestController::downloadDidStart(WKContextRef context, WKDownloadRef download, const void* clientInfo) +{ + static_cast<TestController*>(const_cast<void*>(clientInfo))->downloadDidStart(context, download); +} + +WKStringRef TestController::decideDestinationWithSuggestedFilename(WKContextRef context, WKDownloadRef download, WKStringRef filename, bool* allowOverwrite, const void* clientInfo) +{ + return static_cast<TestController*>(const_cast<void*>(clientInfo))->decideDestinationWithSuggestedFilename(context, download, filename, allowOverwrite); +} + +void TestController::downloadDidFinish(WKContextRef context, WKDownloadRef download, const void* clientInfo) +{ + static_cast<TestController*>(const_cast<void*>(clientInfo))->downloadDidFinish(context, download); +} + +void TestController::downloadDidFail(WKContextRef context, WKDownloadRef download, WKErrorRef error, const void* clientInfo) +{ + static_cast<TestController*>(const_cast<void*>(clientInfo))->downloadDidFail(context, download, error); +} + +void TestController::downloadDidCancel(WKContextRef context, WKDownloadRef download, const void* clientInfo) +{ + static_cast<TestController*>(const_cast<void*>(clientInfo))->downloadDidCancel(context, download); +} + +void TestController::downloadDidStart(WKContextRef context, WKDownloadRef download) +{ + m_currentInvocation->outputText("Download started.\n"); +} + +WKStringRef TestController::decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef, WKStringRef filename, bool*& allowOverwrite) +{ + String suggestedFilename = toWTFString(filename); + + StringBuilder builder; + builder.append("Downloading URL with suggested filename \""); + builder.append(suggestedFilename); + builder.append("\"\n"); + + m_currentInvocation->outputText(builder.toString()); + + const char* dumpRenderTreeTemp = libraryPathForTesting(); + if (!dumpRenderTreeTemp) + return nullptr; + + *allowOverwrite = true; + String temporaryFolder = String::fromUTF8(dumpRenderTreeTemp); + if (suggestedFilename.isEmpty()) + suggestedFilename = "Unknown"; + + return toWK(temporaryFolder + "/" + suggestedFilename).leakRef(); +} + +void TestController::downloadDidFinish(WKContextRef, WKDownloadRef) +{ + m_currentInvocation->outputText("Download completed.\n"); + m_currentInvocation->notifyDownloadDone(); +} + +void TestController::downloadDidFail(WKContextRef, WKDownloadRef, WKErrorRef error) +{ + String message = String::format("Download failed.\n"); + m_currentInvocation->outputText(message); + + WKRetainPtr<WKStringRef> errorDomain = adoptWK(WKErrorCopyDomain(error)); + WKRetainPtr<WKStringRef> errorDescription = adoptWK(WKErrorCopyLocalizedDescription(error)); + int errorCode = WKErrorGetErrorCode(error); + + StringBuilder errorBuilder; + errorBuilder.append("Failed: "); + errorBuilder.append(toWTFString(errorDomain)); + errorBuilder.append(", code="); + errorBuilder.appendNumber(errorCode); + errorBuilder.append(", description="); + errorBuilder.append(toWTFString(errorDescription)); + errorBuilder.append("\n"); + + m_currentInvocation->outputText(errorBuilder.toString()); + m_currentInvocation->notifyDownloadDone(); +} + +void TestController::downloadDidCancel(WKContextRef, WKDownloadRef) +{ + m_currentInvocation->outputText("Download cancelled.\n"); + m_currentInvocation->notifyDownloadDone(); +} + 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(MAC) pid_t pid = WKPageGetProcessIdentifier(m_mainWebView->page()); - fprintf(stderr, "#CRASHED - WebProcess (pid %ld)\n", static_cast<long>(pid)); -#else - fputs("#CRASHED - WebProcess\n", stderr); -#endif + fprintf(stderr, "#CRASHED - %s (pid %ld)\n", webProcessName(), static_cast<long>(pid)); fflush(stderr); m_didPrintWebProcessCrashedMessage = true; } @@ -1132,9 +1777,29 @@ void TestController::processDidCrash() 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); + m_webNotificationProvider.simulateWebNotificationClick(mainWebView()->page(), notificationID); } void TestController::setGeolocationPermission(bool enabled) @@ -1160,16 +1825,223 @@ void TestController::handleGeolocationPermissionRequest(WKGeolocationPermissionR decidePolicyForGeolocationPermissionRequestIfPossible(); } -void TestController::setCustomPolicyDelegate(bool enabled, bool permissive) +bool TestController::isGeolocationProviderActive() const { - m_policyDelegateEnabled = enabled; - m_policyDelegatePermissive = permissive; + return m_geolocationProvider->isActive(); +} + +static String originUserVisibleName(WKSecurityOriginRef origin) +{ + if (!origin) + return emptyString(); + + std::string host = toSTD(adoptWK(WKSecurityOriginCopyHost(origin))).c_str(); + std::string protocol = toSTD(adoptWK(WKSecurityOriginCopyProtocol(origin))).c_str(); + + if (!host.length() || !protocol.length()) + return emptyString(); + + unsigned short port = WKSecurityOriginGetPort(origin); + if (port) + return String::format("%s://%s:%d", protocol.c_str(), host.c_str(), port); + + return String::format("%s://%s", protocol.c_str(), host.c_str()); +} + +static String userMediaOriginHash(WKSecurityOriginRef userMediaDocumentOrigin, WKSecurityOriginRef topLevelDocumentOrigin) +{ + String userMediaDocumentOriginString = originUserVisibleName(userMediaDocumentOrigin); + String topLevelDocumentOriginString = originUserVisibleName(topLevelDocumentOrigin); + + if (topLevelDocumentOriginString.isEmpty()) + return userMediaDocumentOriginString; + + return String::format("%s-%s", userMediaDocumentOriginString.utf8().data(), topLevelDocumentOriginString.utf8().data()); +} + +static String userMediaOriginHash(WKStringRef userMediaDocumentOriginString, WKStringRef topLevelDocumentOriginString) +{ + auto userMediaDocumentOrigin = adoptWK(WKSecurityOriginCreateFromString(userMediaDocumentOriginString)); + if (!WKStringGetLength(topLevelDocumentOriginString)) + return userMediaOriginHash(userMediaDocumentOrigin.get(), nullptr); + + auto topLevelDocumentOrigin = adoptWK(WKSecurityOriginCreateFromString(topLevelDocumentOriginString)); + return userMediaOriginHash(userMediaDocumentOrigin.get(), topLevelDocumentOrigin.get()); +} + +void TestController::setUserMediaPermission(bool enabled) +{ + m_isUserMediaPermissionSet = true; + m_isUserMediaPermissionAllowed = enabled; + decidePolicyForUserMediaPermissionRequestIfPossible(); +} + +static String createCanonicalUUIDString() +{ + unsigned randomData[4]; + cryptographicallyRandomValues(reinterpret_cast<unsigned char*>(randomData), sizeof(randomData)); + + // Format as Version 4 UUID. + StringBuilder builder; + builder.reserveCapacity(36); + appendUnsignedAsHexFixedSize(randomData[0], builder, 8, Lowercase); + builder.append('-'); + appendUnsignedAsHexFixedSize(randomData[1] >> 16, builder, 4, Lowercase); + builder.appendLiteral("-4"); + appendUnsignedAsHexFixedSize(randomData[1] & 0x00000fff, builder, 3, Lowercase); + builder.append('-'); + appendUnsignedAsHexFixedSize((randomData[2] >> 30) | 0x8, builder, 1, Lowercase); + appendUnsignedAsHexFixedSize((randomData[2] >> 16) & 0x00000fff, builder, 3, Lowercase); + builder.append('-'); + appendUnsignedAsHexFixedSize(randomData[2] & 0x0000ffff, builder, 4, Lowercase); + appendUnsignedAsHexFixedSize(randomData[3], builder, 8, Lowercase); + return builder.toString(); +} + +class OriginSettings : public RefCounted<OriginSettings> { +public: + explicit OriginSettings() + { + } + + bool persistentPermission() const { return m_persistentPermission; } + void setPersistentPermission(bool permission) { m_persistentPermission = permission; } + + String persistentSalt() const { return m_persistentSalt; } + void setPersistentSalt(const String& salt) { m_persistentSalt = salt; } + + HashMap<uint64_t, String>& ephemeralSalts() { return m_ephemeralSalts; } + + void incrementRequestCount() { ++m_requestCount; } + void resetRequestCount() { m_requestCount = 0; } + unsigned requestCount() const { return m_requestCount; } + +private: + HashMap<uint64_t, String> m_ephemeralSalts; + String m_persistentSalt; + unsigned m_requestCount { 0 }; + bool m_persistentPermission { false }; +}; + +String TestController::saltForOrigin(WKFrameRef frame, String originHash) +{ + auto& settings = settingsForOrigin(originHash); + auto& ephemeralSalts = settings.ephemeralSalts(); + auto frameInfo = adoptWK(WKFrameCreateFrameInfo(frame)); + auto frameHandle = WKFrameInfoGetFrameHandleRef(frameInfo.get()); + uint64_t frameIdentifier = WKFrameHandleGetFrameID(frameHandle); + String frameSalt = ephemeralSalts.get(frameIdentifier); + + if (settings.persistentPermission()) { + if (frameSalt.length()) + return frameSalt; + + if (!settings.persistentSalt().length()) + settings.setPersistentSalt(createCanonicalUUIDString()); + + return settings.persistentSalt(); + } + + if (!frameSalt.length()) { + frameSalt = createCanonicalUUIDString(); + ephemeralSalts.add(frameIdentifier, frameSalt); + } + + return frameSalt; +} + +void TestController::setUserMediaPersistentPermissionForOrigin(bool permission, WKStringRef userMediaDocumentOriginString, WKStringRef topLevelDocumentOriginString) +{ + auto originHash = userMediaOriginHash(userMediaDocumentOriginString, topLevelDocumentOriginString); + auto& settings = settingsForOrigin(originHash); + settings.setPersistentPermission(permission); +} + +void TestController::handleCheckOfUserMediaPermissionForOrigin(WKFrameRef frame, WKSecurityOriginRef userMediaDocumentOrigin, WKSecurityOriginRef topLevelDocumentOrigin, const WKUserMediaPermissionCheckRef& checkRequest) +{ + auto originHash = userMediaOriginHash(userMediaDocumentOrigin, topLevelDocumentOrigin); + auto salt = saltForOrigin(frame, originHash); + WKRetainPtr<WKStringRef> saltString = adoptWK(WKStringCreateWithUTF8CString(salt.utf8().data())); + + WKUserMediaPermissionCheckSetUserMediaAccessInfo(checkRequest, saltString.get(), settingsForOrigin(originHash).persistentPermission()); } -void TestController::setVisibilityState(WKPageVisibilityState visibilityState, bool isInitialState) +void TestController::handleUserMediaPermissionRequest(WKFrameRef frame, WKSecurityOriginRef userMediaDocumentOrigin, WKSecurityOriginRef topLevelDocumentOrigin, WKUserMediaPermissionRequestRef request) { - setHidden(visibilityState != kWKPageVisibilityStateVisible); - WKPageSetVisibilityState(m_mainWebView->page(), visibilityState, isInitialState); + auto originHash = userMediaOriginHash(userMediaDocumentOrigin, topLevelDocumentOrigin); + m_userMediaPermissionRequests.append(std::make_pair(originHash, request)); + decidePolicyForUserMediaPermissionRequestIfPossible(); +} + +OriginSettings& TestController::settingsForOrigin(const String& originHash) +{ + RefPtr<OriginSettings> settings = m_cachedUserMediaPermissions.get(originHash); + if (!settings) { + settings = adoptRef(*new OriginSettings()); + m_cachedUserMediaPermissions.add(originHash, settings); + } + + return *settings; +} + +unsigned TestController::userMediaPermissionRequestCountForOrigin(WKStringRef userMediaDocumentOriginString, WKStringRef topLevelDocumentOriginString) +{ + auto originHash = userMediaOriginHash(userMediaDocumentOriginString, topLevelDocumentOriginString); + return settingsForOrigin(originHash).requestCount(); +} + +void TestController::resetUserMediaPermissionRequestCountForOrigin(WKStringRef userMediaDocumentOriginString, WKStringRef topLevelDocumentOriginString) +{ + auto originHash = userMediaOriginHash(userMediaDocumentOriginString, topLevelDocumentOriginString); + settingsForOrigin(originHash).resetRequestCount(); +} + +void TestController::decidePolicyForUserMediaPermissionRequestIfPossible() +{ + if (!m_isUserMediaPermissionSet) + return; + + for (auto& pair : m_userMediaPermissionRequests) { + auto originHash = pair.first; + auto request = pair.second.get(); + + auto& settings = settingsForOrigin(originHash); + settings.incrementRequestCount(); + + if (!m_isUserMediaPermissionAllowed && !settings.persistentPermission()) { + WKUserMediaPermissionRequestDeny(request, kWKPermissionDenied); + continue; + } + + WKRetainPtr<WKArrayRef> audioDeviceUIDs = adoptWK(WKUserMediaPermissionRequestAudioDeviceUIDs(request)); + WKRetainPtr<WKArrayRef> videoDeviceUIDs = adoptWK(WKUserMediaPermissionRequestVideoDeviceUIDs(request)); + + if (!WKArrayGetSize(videoDeviceUIDs.get()) && !WKArrayGetSize(audioDeviceUIDs.get())) { + WKUserMediaPermissionRequestDeny(request, kWKNoConstraints); + continue; + } + + WKRetainPtr<WKStringRef> videoDeviceUID; + if (WKArrayGetSize(videoDeviceUIDs.get())) + videoDeviceUID = reinterpret_cast<WKStringRef>(WKArrayGetItemAtIndex(videoDeviceUIDs.get(), 0)); + else + videoDeviceUID = adoptWK(WKStringCreateWithUTF8CString("")); + + WKRetainPtr<WKStringRef> audioDeviceUID; + if (WKArrayGetSize(audioDeviceUIDs.get())) + audioDeviceUID = reinterpret_cast<WKStringRef>(WKArrayGetItemAtIndex(audioDeviceUIDs.get(), 0)); + else + audioDeviceUID = adoptWK(WKStringCreateWithUTF8CString("")); + + WKUserMediaPermissionRequestAllow(request, audioDeviceUID.get(), videoDeviceUID.get()); + } + m_userMediaPermissionRequests.clear(); +} + +void TestController::setCustomPolicyDelegate(bool enabled, bool permissive) +{ + m_policyDelegateEnabled = enabled; + m_policyDelegatePermissive = permissive; } void TestController::decidePolicyForGeolocationPermissionRequestIfPossible() @@ -1189,7 +2061,7 @@ void TestController::decidePolicyForGeolocationPermissionRequestIfPossible() void TestController::decidePolicyForNotificationPermissionRequest(WKPageRef page, WKSecurityOriginRef origin, WKNotificationPermissionRequestRef request, const void*) { - TestController::shared().decidePolicyForNotificationPermissionRequest(page, origin, request); + TestController::singleton().decidePolicyForNotificationPermissionRequest(page, origin, request); } void TestController::decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef request) @@ -1202,37 +2074,219 @@ void TestController::unavailablePluginButtonClicked(WKPageRef, WKPluginUnavailab printf("MISSING PLUGIN BUTTON PRESSED\n"); } -void TestController::decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKFrameRef, WKURLRequestRef, WKFramePolicyListenerRef listener, WKTypeRef, const void* clientInfo) +void TestController::decidePolicyForNavigationAction(WKPageRef, WKNavigationActionRef navigationAction, WKFramePolicyListenerRef listener, WKTypeRef, const void* clientInfo) { static_cast<TestController*>(const_cast<void*>(clientInfo))->decidePolicyForNavigationAction(listener); } void TestController::decidePolicyForNavigationAction(WKFramePolicyListenerRef listener) { - if (m_policyDelegateEnabled && !m_policyDelegatePermissive) { - WKFramePolicyListenerIgnore(listener); - return; - } + WKRetainPtr<WKFramePolicyListenerRef> retainedListener { listener }; + const bool shouldIgnore { m_policyDelegateEnabled && !m_policyDelegatePermissive }; + auto decisionFunction = [shouldIgnore, retainedListener]() { + if (shouldIgnore) + WKFramePolicyListenerIgnore(retainedListener.get()); + else + WKFramePolicyListenerUse(retainedListener.get()); + }; - WKFramePolicyListenerUse(listener); + if (m_shouldDecideNavigationPolicyAfterDelay) + RunLoop::main().dispatch(WTFMove(decisionFunction)); + else + decisionFunction(); } -void TestController::decidePolicyForResponse(WKPageRef, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef, bool canShowMIMEType, WKFramePolicyListenerRef listener, WKTypeRef, const void* clientInfo) +void TestController::decidePolicyForNavigationResponse(WKPageRef, WKNavigationResponseRef navigationResponse, WKFramePolicyListenerRef listener, WKTypeRef, const void* clientInfo) { - static_cast<TestController*>(const_cast<void*>(clientInfo))->decidePolicyForResponse(frame, response, listener); + static_cast<TestController*>(const_cast<void*>(clientInfo))->decidePolicyForNavigationResponse(navigationResponse, listener); } -void TestController::decidePolicyForResponse(WKFrameRef frame, WKURLResponseRef response, WKFramePolicyListenerRef 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. - WKRetainPtr<WKStringRef> wkMIMEType(AdoptWK, WKURLResponseCopyMIMEType(response)); - if (WKFrameCanShowMIMEType(frame, wkMIMEType.get())) { + if (WKNavigationResponseCanShowMIMEType(navigationResponse)) { WKFramePolicyListenerUse(listener); return; } - WKFramePolicyListenerIgnore(listener); + if (m_shouldDownloadUndisplayableMIMETypes) + WKFramePolicyListenerDownload(listener); + else + WKFramePolicyListenerIgnore(listener); +} + +void TestController::didNavigateWithNavigationData(WKContextRef, WKPageRef, WKNavigationDataRef navigationData, WKFrameRef frame, const void* clientInfo) +{ + static_cast<TestController*>(const_cast<void*>(clientInfo))->didNavigateWithNavigationData(navigationData, frame); } +void TestController::didNavigateWithNavigationData(WKNavigationDataRef navigationData, WKFrameRef) +{ + if (m_state != RunningTest) + return; + + if (!m_shouldLogHistoryClientCallbacks) + return; + + // URL + WKRetainPtr<WKURLRef> urlWK = adoptWK(WKNavigationDataCopyURL(navigationData)); + WKRetainPtr<WKStringRef> urlStringWK = adoptWK(WKURLCopyString(urlWK.get())); + // Title + WKRetainPtr<WKStringRef> titleWK = adoptWK(WKNavigationDataCopyTitle(navigationData)); + // HTTP method + WKRetainPtr<WKURLRequestRef> requestWK = adoptWK(WKNavigationDataCopyOriginalRequest(navigationData)); + WKRetainPtr<WKStringRef> 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<TestController*>(const_cast<void*>(clientInfo))->didPerformClientRedirect(sourceURL, destinationURL, frame); +} + +void TestController::didPerformClientRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef) +{ + if (m_state != RunningTest) + return; + + if (!m_shouldLogHistoryClientCallbacks) + return; + + WKRetainPtr<WKStringRef> sourceStringWK = adoptWK(WKURLCopyString(sourceURL)); + WKRetainPtr<WKStringRef> 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<TestController*>(const_cast<void*>(clientInfo))->didPerformServerRedirect(sourceURL, destinationURL, frame); +} + +void TestController::didPerformServerRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef) +{ + if (m_state != RunningTest) + return; + + if (!m_shouldLogHistoryClientCallbacks) + return; + + WKRetainPtr<WKStringRef> sourceStringWK = adoptWK(WKURLCopyString(sourceURL)); + WKRetainPtr<WKStringRef> 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<TestController*>(const_cast<void*>(clientInfo))->didUpdateHistoryTitle(title, URL, frame); +} + +void TestController::didUpdateHistoryTitle(WKStringRef title, WKURLRef URL, WKFrameRef) +{ + if (m_state != RunningTest) + return; + + if (!m_shouldLogHistoryClientCallbacks) + return; + + WKRetainPtr<WKStringRef> 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); +} + +void TestController::setIgnoresViewportScaleLimits(bool ignoresViewportScaleLimits) +{ + WKPageSetIgnoresViewportScaleLimits(m_mainWebView->page(), ignoresViewportScaleLimits); +} + +void TestController::setStatisticsPrevalentResource(WKStringRef hostName, bool value) +{ + WKResourceLoadStatisticsManagerSetPrevalentResource(hostName, value); +} + +bool TestController::isStatisticsPrevalentResource(WKStringRef hostName) +{ + return WKResourceLoadStatisticsManagerIsPrevalentResource(hostName); +} + +void TestController::setStatisticsHasHadUserInteraction(WKStringRef hostName, bool value) +{ + WKResourceLoadStatisticsManagerSetHasHadUserInteraction(hostName, value); +} + +bool TestController::isStatisticsHasHadUserInteraction(WKStringRef hostName) +{ + return WKResourceLoadStatisticsManagerIsHasHadUserInteraction(hostName); +} + +void TestController::setStatisticsTimeToLiveUserInteraction(double seconds) +{ + WKResourceLoadStatisticsManagerSetTimeToLiveUserInteraction(seconds); +} + +void TestController::statisticsFireDataModificationHandler() +{ + WKResourceLoadStatisticsManagerFireDataModificationHandler(); +} + +void TestController::setStatisticsNotifyPagesWhenDataRecordsWereScanned(bool value) +{ + WKResourceLoadStatisticsManagerSetNotifyPagesWhenDataRecordsWereScanned(value); +} + +void TestController::setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool value) +{ + WKResourceLoadStatisticsManagerSetShouldClassifyResourcesBeforeDataRecordsRemoval(value); +} + +void TestController::setStatisticsMinimumTimeBetweeenDataRecordsRemoval(double seconds) +{ + WKResourceLoadStatisticsManagerSetMinimumTimeBetweeenDataRecordsRemoval(seconds); +} +void TestController::statisticsResetToConsistentState() +{ + WKResourceLoadStatisticsManagerResetToConsistentState(); +} + +#if !PLATFORM(COCOA) +void TestController::platformWillRunTest(const TestInvocation&) +{ +} + +void TestController::platformCreateWebView(WKPageConfigurationRef configuration, const TestOptions& options) +{ + m_mainWebView = std::make_unique<PlatformWebView>(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() +{ + +} + +unsigned TestController::imageCountInGeneralPasteboard() const +{ + return 0; +} + +#endif + } // namespace WTR |