Service Worker Fetch events should time out.
[WebKit-https.git] / Tools / WebKitTestRunner / TestController.h
1 /*
2  * Copyright (C) 2010-2019 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #pragma once
27
28 #include "GeolocationProviderMock.h"
29 #include "TestOptions.h"
30 #include "WebNotificationProvider.h"
31 #include "WorkQueueManager.h"
32 #include <WebKit/WKRetainPtr.h>
33 #include <set>
34 #include <string>
35 #include <vector>
36 #include <wtf/HashMap.h>
37 #include <wtf/Noncopyable.h>
38 #include <wtf/Seconds.h>
39 #include <wtf/Vector.h>
40 #include <wtf/text/StringHash.h>
41
42 #if PLATFORM(COCOA)
43 #include "ClassMethodSwizzler.h"
44 #include "InstanceMethodSwizzler.h"
45 #endif
46
47 OBJC_CLASS NSString;
48 OBJC_CLASS UIKeyboardInputMode;
49 OBJC_CLASS WKWebViewConfiguration;
50
51 namespace WTR {
52
53 class TestInvocation;
54 class OriginSettings;
55 class PlatformWebView;
56 class EventSenderProxy;
57 struct TestCommand;
58 struct TestOptions;
59
60 class AsyncTask {
61 public:
62     AsyncTask(WTF::Function<void ()>&& task, WTF::Seconds timeout)
63         : m_task(WTFMove(task))
64         , m_timeout(timeout)
65     {
66         ASSERT(!currentTask());
67     }
68
69     // Returns false on timeout.
70     bool run();
71
72     void taskComplete()
73     {
74         m_taskDone = true;
75     }
76
77     static AsyncTask* currentTask();
78
79 private:
80     static AsyncTask* m_currentTask;
81
82     WTF::Function<void ()> m_task;
83     WTF::Seconds m_timeout;
84     bool m_taskDone { false };
85 };
86
87 // FIXME: Rename this TestRunner?
88 class TestController {
89 public:
90     static TestController& singleton();
91     static WKWebsiteDataStoreRef websiteDataStore();
92
93     static const unsigned viewWidth;
94     static const unsigned viewHeight;
95
96     static const unsigned w3cSVGViewWidth;
97     static const unsigned w3cSVGViewHeight;
98
99     static const WTF::Seconds defaultShortTimeout;
100     static const WTF::Seconds noTimeout;
101
102     TestController(int argc, const char* argv[]);
103     ~TestController();
104
105     bool verbose() const { return m_verbose; }
106
107     WKStringRef injectedBundlePath() const { return m_injectedBundlePath.get(); }
108     WKStringRef testPluginDirectory() const { return m_testPluginDirectory.get(); }
109
110     PlatformWebView* mainWebView() { return m_mainWebView.get(); }
111     WKContextRef context() { return m_context.get(); }
112     WKUserContentControllerRef userContentController() { return m_userContentController.get(); }
113
114     EventSenderProxy* eventSenderProxy() { return m_eventSenderProxy.get(); }
115
116     bool shouldUseRemoteLayerTree() const { return m_shouldUseRemoteLayerTree; }
117     
118     // Runs the run loop until `done` is true or the timeout elapses.
119     bool useWaitToDumpWatchdogTimer() { return m_useWaitToDumpWatchdogTimer; }
120     void runUntil(bool& done, WTF::Seconds timeout);
121     void notifyDone();
122
123     bool shouldShowWebView() const { return m_shouldShowWebView; }
124     bool usingServerMode() const { return m_usingServerMode; }
125     void configureViewForTest(const TestInvocation&);
126     
127     bool shouldShowTouches() const { return m_shouldShowTouches; }
128     
129     bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
130     void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
131
132     void simulateWebNotificationClick(uint64_t notificationID);
133
134     // Geolocation.
135     void setGeolocationPermission(bool);
136     void setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed, bool providesFloorLevel, double floorLevel);
137     void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage);
138     void handleGeolocationPermissionRequest(WKGeolocationPermissionRequestRef);
139     bool isGeolocationProviderActive() const;
140
141     // MediaStream.
142     String saltForOrigin(WKFrameRef, String);
143     void getUserMediaInfoForOrigin(WKFrameRef, WKStringRef originKey, bool&, WKRetainPtr<WKStringRef>&);
144     WKStringRef getUserMediaSaltForOrigin(WKFrameRef, WKStringRef originKey);
145     void setUserMediaPermission(bool);
146     void resetUserMediaPermission();
147     void setUserMediaPersistentPermissionForOrigin(bool, WKStringRef userMediaDocumentOriginString, WKStringRef topLevelDocumentOriginString);
148     void handleUserMediaPermissionRequest(WKFrameRef, WKSecurityOriginRef, WKSecurityOriginRef, WKUserMediaPermissionRequestRef);
149     void handleCheckOfUserMediaPermissionForOrigin(WKFrameRef, WKSecurityOriginRef, WKSecurityOriginRef, const WKUserMediaPermissionCheckRef&);
150     OriginSettings& settingsForOrigin(const String&);
151     unsigned userMediaPermissionRequestCountForOrigin(WKStringRef userMediaDocumentOriginString, WKStringRef topLevelDocumentOriginString);
152     void resetUserMediaPermissionRequestCountForOrigin(WKStringRef userMediaDocumentOriginString, WKStringRef topLevelDocumentOriginString);
153
154     // Device Orientation / Motion.
155     bool handleDeviceOrientationAndMotionAccessRequest(WKSecurityOriginRef);
156
157     // Content Extensions.
158     void configureContentExtensionForTest(const TestInvocation&);
159     void resetContentExtensions();
160
161     // Policy delegate.
162     void setCustomPolicyDelegate(bool enabled, bool permissive);
163
164     // Page Visibility.
165     void setHidden(bool);
166
167     unsigned imageCountInGeneralPasteboard() const;
168
169     enum class ResetStage { BeforeTest, AfterTest };
170     bool resetStateToConsistentValues(const TestOptions&, ResetStage);
171     void resetPreferencesToConsistentValues(const TestOptions&);
172
173     void willDestroyWebView();
174
175     void terminateWebContentProcess();
176     void reattachPageToWebProcess();
177
178     static const char* webProcessName();
179     static const char* networkProcessName();
180     static const char* databaseProcessName();
181
182     WorkQueueManager& workQueueManager() { return m_workQueueManager; }
183
184     void setRejectsProtectionSpaceAndContinueForAuthenticationChallenges(bool value) { m_rejectsProtectionSpaceAndContinueForAuthenticationChallenges = value; }
185     void setHandlesAuthenticationChallenges(bool value) { m_handlesAuthenticationChallenges = value; }
186     void setAuthenticationUsername(String username) { m_authenticationUsername = username; }
187     void setAuthenticationPassword(String password) { m_authenticationPassword = password; }
188     void setAllowsAnySSLCertificate(bool);
189     void setShouldSwapToEphemeralSessionOnNextNavigation(bool value) { m_shouldSwapToEphemeralSessionOnNextNavigation = value; }
190     void setShouldSwapToDefaultSessionOnNextNavigation(bool value) { m_shouldSwapToDefaultSessionOnNextNavigation = value; }
191
192     void setBlockAllPlugins(bool shouldBlock);
193     void setPluginSupportedMode(const String&);
194
195     void setShouldLogHistoryClientCallbacks(bool shouldLog) { m_shouldLogHistoryClientCallbacks = shouldLog; }
196     void setShouldLogCanAuthenticateAgainstProtectionSpace(bool shouldLog) { m_shouldLogCanAuthenticateAgainstProtectionSpace = shouldLog; }
197     void setShouldLogDownloadCallbacks(bool shouldLog) { m_shouldLogDownloadCallbacks = shouldLog; }
198
199     bool isCurrentInvocation(TestInvocation* invocation) const { return invocation == m_currentInvocation.get(); }
200
201     void setShouldDecideNavigationPolicyAfterDelay(bool value) { m_shouldDecideNavigationPolicyAfterDelay = value; }
202     void setShouldDecideResponsePolicyAfterDelay(bool value) { m_shouldDecideResponsePolicyAfterDelay = value; }
203
204     void setNavigationGesturesEnabled(bool value);
205     void setIgnoresViewportScaleLimits(bool);
206
207     void setShouldDownloadUndisplayableMIMETypes(bool value) { m_shouldDownloadUndisplayableMIMETypes = value; }
208     void setShouldAllowDeviceOrientationAndMotionAccess(bool value) { m_shouldAllowDeviceOrientationAndMotionAccess = value; }
209
210     void setStatisticsDebugMode(bool value);
211     void setStatisticsPrevalentResourceForDebugMode(WKStringRef hostName);
212     void setStatisticsLastSeen(WKStringRef hostName, double seconds);
213     void setStatisticsMergeStatistic(WKStringRef host, WKStringRef topFrameDomain1, WKStringRef topFrameDomain2, double lastSeen, bool hadUserInteraction, double mostRecentUserInteraction, bool isGrandfathered, bool isPrevalent, bool isVeryPrevalent, int dataRecordsRemoved);
214     void setStatisticsPrevalentResource(WKStringRef hostName, bool value);
215     void setStatisticsVeryPrevalentResource(WKStringRef hostName, bool value);
216     String dumpResourceLoadStatistics();
217     bool isStatisticsPrevalentResource(WKStringRef hostName);
218     bool isStatisticsVeryPrevalentResource(WKStringRef hostName);
219     bool isStatisticsRegisteredAsSubresourceUnder(WKStringRef subresourceHost, WKStringRef topFrameHost);
220     bool isStatisticsRegisteredAsSubFrameUnder(WKStringRef subFrameHost, WKStringRef topFrameHost);
221     bool isStatisticsRegisteredAsRedirectingTo(WKStringRef hostRedirectedFrom, WKStringRef hostRedirectedTo);
222     void setStatisticsHasHadUserInteraction(WKStringRef hostName, bool value);
223     bool isStatisticsHasHadUserInteraction(WKStringRef hostName);
224     bool isStatisticsOnlyInDatabaseOnce(WKStringRef subHost, WKStringRef topHost);
225     void setStatisticsGrandfathered(WKStringRef hostName, bool value);
226     bool isStatisticsGrandfathered(WKStringRef hostName);
227     void setUseITPDatabase(bool value);
228     void setStatisticsSubframeUnderTopFrameOrigin(WKStringRef hostName, WKStringRef topFrameHostName);
229     void setStatisticsSubresourceUnderTopFrameOrigin(WKStringRef hostName, WKStringRef topFrameHostName);
230     void setStatisticsSubresourceUniqueRedirectTo(WKStringRef hostName, WKStringRef hostNameRedirectedTo);
231     void setStatisticsSubresourceUniqueRedirectFrom(WKStringRef host, WKStringRef hostRedirectedFrom);
232     void setStatisticsTopFrameUniqueRedirectTo(WKStringRef host, WKStringRef hostRedirectedTo);
233     void setStatisticsTopFrameUniqueRedirectFrom(WKStringRef host, WKStringRef hostRedirectedFrom);
234     void setStatisticsCrossSiteLoadWithLinkDecoration(WKStringRef fromHost, WKStringRef toHost);
235     void setStatisticsTimeToLiveUserInteraction(double seconds);
236     void statisticsProcessStatisticsAndDataRecords();
237     void statisticsUpdateCookieBlocking();
238     void statisticsSubmitTelemetry();
239     void setStatisticsNotifyPagesWhenDataRecordsWereScanned(bool);
240     void setStatisticsIsRunningTest(bool);
241     void setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool);
242     void setStatisticsNotifyPagesWhenTelemetryWasCaptured(bool value);
243     void setStatisticsMinimumTimeBetweenDataRecordsRemoval(double);
244     void setStatisticsGrandfatheringTime(double seconds);
245     void setStatisticsMaxStatisticsEntries(unsigned);
246     void setStatisticsPruneEntriesDownTo(unsigned);
247     void statisticsClearInMemoryAndPersistentStore();
248     void statisticsClearInMemoryAndPersistentStoreModifiedSinceHours(unsigned);
249     void statisticsClearThroughWebsiteDataRemoval();
250     void statisticsDeleteCookiesForHost(WKStringRef host, bool includeHttpOnlyCookies);
251     bool isStatisticsHasLocalStorage(WKStringRef hostName);
252     void setStatisticsCacheMaxAgeCap(double seconds);
253     bool hasStatisticsIsolatedSession(WKStringRef hostName);
254     void setStatisticsShouldDowngradeReferrer(bool value);
255     void statisticsResetToConsistentState();
256
257     void getAllStorageAccessEntries();
258
259     WKArrayRef openPanelFileURLs() const { return m_openPanelFileURLs.get(); }
260     void setOpenPanelFileURLs(WKArrayRef fileURLs) { m_openPanelFileURLs = fileURLs; }
261
262 #if PLATFORM(IOS_FAMILY)
263     WKDataRef openPanelFileURLsMediaIcon() const { return m_openPanelFileURLsMediaIcon.get(); }
264     void setOpenPanelFileURLsMediaIcon(WKDataRef mediaIcon) { m_openPanelFileURLsMediaIcon = mediaIcon; }
265 #endif
266
267     void terminateNetworkProcess();
268     void terminateServiceWorkerProcess();
269
270     void removeAllSessionCredentials();
271
272     void clearIndexedDatabases();
273     void clearLocalStorage();
274     void syncLocalStorage();
275
276     void clearServiceWorkerRegistrations();
277
278     void clearDOMCache(WKStringRef origin);
279     void clearDOMCaches();
280     bool hasDOMCache(WKStringRef origin);
281     uint64_t domCacheSize(WKStringRef origin);
282
283     void setAllowStorageQuotaIncrease(bool);
284
285     bool didReceiveServerRedirectForProvisionalNavigation() const { return m_didReceiveServerRedirectForProvisionalNavigation; }
286     void clearDidReceiveServerRedirectForProvisionalNavigation() { m_didReceiveServerRedirectForProvisionalNavigation = false; }
287
288     void addMockMediaDevice(WKStringRef persistentID, WKStringRef label, WKStringRef type);
289     void clearMockMediaDevices();
290     void removeMockMediaDevice(WKStringRef persistentID);
291     void resetMockMediaDevices();
292
293     void injectUserScript(WKStringRef);
294     
295     void sendDisplayConfigurationChangedMessageForTesting();
296
297     void setServiceWorkerFetchTimeoutForTesting(double seconds);
298
299     void setWebAuthenticationMockConfiguration(WKDictionaryRef);
300     void addTestKeyToKeychain(const String& privateKeyBase64, const String& attrLabel, const String& applicationTagBase64);
301     void cleanUpKeychain(const String& attrLabel, const String& applicationTagBase64);
302     bool keyExistsInKeychain(const String& attrLabel, const String& applicationTagBase64);
303
304 #if PLATFORM(COCOA)
305     RetainPtr<NSString> getOverriddenCalendarIdentifier() const;
306     void setDefaultCalendarType(NSString *identifier);
307 #endif // PLATFORM(COCOA)
308
309 #if PLATFORM(IOS_FAMILY)
310     void setKeyboardInputModeIdentifier(const String&);
311     UIKeyboardInputMode *overriddenKeyboardInputMode() const { return m_overriddenKeyboardInputMode.get(); }
312 #endif
313
314     void setAllowedMenuActions(const Vector<String>&);
315     void installCustomMenuAction(const String& name, bool dismissesAutomatically);
316
317     uint64_t serverTrustEvaluationCallbackCallsCount() const { return m_serverTrustEvaluationCallbackCallsCount; }
318
319     void setShouldDismissJavaScriptAlertsAsynchronously(bool);
320     void handleJavaScriptAlert(WKPageRunJavaScriptAlertResultListenerRef);
321     void abortModal();
322
323     bool isDoingMediaCapture() const;
324
325     String dumpAdClickAttribution();
326     void clearAdClickAttribution();
327     void clearAdClickAttributionsThroughWebsiteDataRemoval();
328     void setAdClickAttributionOverrideTimerForTesting(bool value);
329     void setAdClickAttributionConversionURLForTesting(WKURLRef);
330     void markAdClickAttributionsAsExpiredForTesting();
331
332 private:
333     WKRetainPtr<WKPageConfigurationRef> generatePageConfiguration(const TestOptions&);
334     WKRetainPtr<WKContextConfigurationRef> generateContextConfiguration(const TestOptions::ContextOptions&) const;
335     void initialize(int argc, const char* argv[]);
336     void createWebViewWithOptions(const TestOptions&);
337     void run();
338
339     void runTestingServerLoop();
340     bool runTest(const char* pathOrURL);
341     
342     // Returns false if timed out.
343     bool waitForCompletion(const WTF::Function<void ()>&, WTF::Seconds timeout);
344
345     bool handleControlCommand(const char* command);
346
347     void platformInitialize();
348     void platformDestroy();
349     WKContextRef platformAdjustContext(WKContextRef, WKContextConfigurationRef);
350     void platformInitializeContext();
351     void platformAddTestOptions(TestOptions&) const;
352     void platformCreateWebView(WKPageConfigurationRef, const TestOptions&);
353     static PlatformWebView* platformCreateOtherPage(PlatformWebView* parentView, WKPageConfigurationRef, const TestOptions&);
354     void platformResetPreferencesToConsistentValues();
355     void platformResetStateToConsistentValues(const TestOptions&);
356 #if PLATFORM(COCOA)
357     void cocoaPlatformInitialize();
358     void cocoaResetStateToConsistentValues(const TestOptions&);
359 #endif
360     void platformConfigureViewForTest(const TestInvocation&);
361     void platformWillRunTest(const TestInvocation&);
362     void platformRunUntil(bool& done, WTF::Seconds timeout);
363     void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
364     WKContextRef platformContext();
365     WKPreferencesRef platformPreferences();
366     void initializeInjectedBundlePath();
367     void initializeTestPluginDirectory();
368
369     void ensureViewSupportsOptionsForTest(const TestInvocation&);
370     TestOptions testOptionsForTest(const TestCommand&) const;
371     void updatePlatformSpecificTestOptionsForTest(TestOptions&, const std::string& pathOrURL) const;
372
373     void updateWebViewSizeForTest(const TestInvocation&);
374     void updateWindowScaleForTest(PlatformWebView*, const TestInvocation&);
375
376     void updateLiveDocumentsAfterTest();
377     void checkForWorldLeaks();
378
379     void didReceiveLiveDocumentsList(WKArrayRef);
380     void dumpResponse(const String&);
381     void findAndDumpWebKitProcessIdentifiers();
382     void findAndDumpWorldLeaks();
383
384     void decidePolicyForGeolocationPermissionRequestIfPossible();
385     void decidePolicyForUserMediaPermissionRequestIfPossible();
386
387     // WKContextInjectedBundleClient
388     static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
389     static void didReceiveSynchronousMessageFromInjectedBundleWithListener(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, WKMessageListenerRef, const void*);
390     static WKTypeRef getInjectedBundleInitializationUserData(WKContextRef, const void *clientInfo);
391
392     // WKPageInjectedBundleClient
393     static void didReceivePageMessageFromInjectedBundle(WKPageRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
394     static void didReceiveSynchronousPageMessageFromInjectedBundleWithListener(WKPageRef, WKStringRef messageName, WKTypeRef messageBody, WKMessageListenerRef, const void*);
395     void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
396     void didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody, WKMessageListenerRef);
397     WKRetainPtr<WKTypeRef> getInjectedBundleInitializationUserData();
398
399     void didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef messageBodyDictionary, bool synchronous);
400
401     // WKContextClient
402     static void networkProcessDidCrash(WKContextRef, const void*);
403     void networkProcessDidCrash();
404
405     // WKPageNavigationClient
406     static void didCommitNavigation(WKPageRef, WKNavigationRef, WKTypeRef userData, const void*);
407     void didCommitNavigation(WKPageRef, WKNavigationRef);
408
409     static void didFinishNavigation(WKPageRef, WKNavigationRef, WKTypeRef userData, const void*);
410     void didFinishNavigation(WKPageRef, WKNavigationRef);
411
412     // WKContextDownloadClient
413     static void downloadDidStart(WKContextRef, WKDownloadRef, const void*);
414     void downloadDidStart(WKContextRef, WKDownloadRef);
415     static WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef, WKStringRef filename, bool* allowOverwrite, const void *clientInfo);
416     WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef, WKStringRef filename, bool*& allowOverwrite);
417     static void downloadDidFinish(WKContextRef, WKDownloadRef, const void*);
418     void downloadDidFinish(WKContextRef, WKDownloadRef);
419     static void downloadDidFail(WKContextRef, WKDownloadRef, WKErrorRef, const void*);
420     void downloadDidFail(WKContextRef, WKDownloadRef, WKErrorRef);
421     static void downloadDidCancel(WKContextRef, WKDownloadRef, const void*);
422     void downloadDidCancel(WKContextRef, WKDownloadRef);
423     static void downloadDidReceiveServerRedirectToURL(WKContextRef, WKDownloadRef, WKURLRef, const void*);
424     void downloadDidReceiveServerRedirectToURL(WKContextRef, WKDownloadRef, WKURLRef);
425     
426     static void processDidCrash(WKPageRef, const void* clientInfo);
427     void processDidCrash();
428
429     static void didBeginNavigationGesture(WKPageRef, const void*);
430     static void willEndNavigationGesture(WKPageRef, WKBackForwardListItemRef, const void*);
431     static void didEndNavigationGesture(WKPageRef, WKBackForwardListItemRef, const void*);
432     static void didRemoveNavigationGestureSnapshot(WKPageRef, const void*);
433     void didBeginNavigationGesture(WKPageRef);
434     void willEndNavigationGesture(WKPageRef, WKBackForwardListItemRef);
435     void didEndNavigationGesture(WKPageRef, WKBackForwardListItemRef);
436     void didRemoveNavigationGestureSnapshot(WKPageRef);
437
438     static WKPluginLoadPolicy decidePolicyForPluginLoad(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription, const void* clientInfo);
439     WKPluginLoadPolicy decidePolicyForPluginLoad(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription);
440     
441
442     static void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef, const void*);
443     void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef);
444
445     static void unavailablePluginButtonClicked(WKPageRef, WKPluginUnavailabilityReason, WKDictionaryRef, const void*);
446
447     static void didReceiveServerRedirectForProvisionalNavigation(WKPageRef, WKNavigationRef, WKTypeRef, const void*);
448     void didReceiveServerRedirectForProvisionalNavigation(WKPageRef, WKNavigationRef, WKTypeRef);
449
450     static bool canAuthenticateAgainstProtectionSpace(WKPageRef, WKProtectionSpaceRef, const void*);
451     bool canAuthenticateAgainstProtectionSpace(WKPageRef, WKProtectionSpaceRef);
452
453     static void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef, const void*);
454     void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef);
455
456     static void decidePolicyForNavigationAction(WKPageRef, WKNavigationActionRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
457     void decidePolicyForNavigationAction(WKNavigationActionRef, WKFramePolicyListenerRef);
458
459     static void decidePolicyForNavigationResponse(WKPageRef, WKNavigationResponseRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
460     void decidePolicyForNavigationResponse(WKNavigationResponseRef, WKFramePolicyListenerRef);
461
462     // WKContextHistoryClient
463     static void didNavigateWithNavigationData(WKContextRef, WKPageRef, WKNavigationDataRef, WKFrameRef, const void*);
464     void didNavigateWithNavigationData(WKNavigationDataRef, WKFrameRef);
465
466     static void didPerformClientRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*);
467     void didPerformClientRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef);
468
469     static void didPerformServerRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*);
470     void didPerformServerRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef);
471
472     static void didUpdateHistoryTitle(WKContextRef, WKPageRef, WKStringRef title, WKURLRef, WKFrameRef, const void*);
473     void didUpdateHistoryTitle(WKStringRef title, WKURLRef, WKFrameRef);
474
475     static WKPageRef createOtherPage(WKPageRef, WKPageConfigurationRef, WKNavigationActionRef, WKWindowFeaturesRef, const void*);
476     WKPageRef createOtherPage(PlatformWebView* parentView, WKPageConfigurationRef, WKNavigationActionRef, WKWindowFeaturesRef);
477
478     static void runModal(WKPageRef, const void* clientInfo);
479     static void runModal(PlatformWebView*);
480
481 #if PLATFORM(COCOA)
482     static void finishCreatingPlatformWebView(PlatformWebView*, const TestOptions&);
483     void configureContentMode(WKWebViewConfiguration *, const TestOptions&);
484 #endif
485
486     static const char* libraryPathForTesting();
487     static const char* platformLibraryPathForTesting();
488
489     std::unique_ptr<TestInvocation> m_currentInvocation;
490 #if PLATFORM(COCOA)
491     std::unique_ptr<ClassMethodSwizzler> m_calendarSwizzler;
492     RetainPtr<NSString> m_overriddenCalendarIdentifier;
493 #endif // PLATFORM(COCOA)
494     bool m_verbose { false };
495     bool m_printSeparators { false };
496     bool m_usingServerMode { false };
497     bool m_gcBetweenTests { false };
498     bool m_shouldDumpPixelsForAllTests { false };
499     std::vector<std::string> m_paths;
500     std::set<std::string> m_allowedHosts;
501     WKRetainPtr<WKStringRef> m_injectedBundlePath;
502     WKRetainPtr<WKStringRef> m_testPluginDirectory;
503
504     WebNotificationProvider m_webNotificationProvider;
505
506     std::unique_ptr<PlatformWebView> m_mainWebView;
507     WKRetainPtr<WKContextRef> m_context;
508     Optional<TestOptions::ContextOptions> m_contextOptions;
509     WKRetainPtr<WKPageGroupRef> m_pageGroup;
510     WKRetainPtr<WKUserContentControllerRef> m_userContentController;
511
512 #if PLATFORM(IOS_FAMILY)
513     Vector<std::unique_ptr<InstanceMethodSwizzler>> m_inputModeSwizzlers;
514     RetainPtr<UIKeyboardInputMode> m_overriddenKeyboardInputMode;
515     Vector<std::unique_ptr<InstanceMethodSwizzler>> m_presentPopoverSwizzlers;
516 #endif
517
518     enum State {
519         Initial,
520         Resetting,
521         RunningTest
522     };
523     State m_state { Initial };
524     bool m_doneResetting { false };
525
526     bool m_useWaitToDumpWatchdogTimer { true };
527     bool m_forceNoTimeout { false };
528
529     bool m_didPrintWebProcessCrashedMessage { false };
530     bool m_shouldExitWhenWebProcessCrashes { true };
531     
532     bool m_beforeUnloadReturnValue { true };
533
534     std::unique_ptr<GeolocationProviderMock> m_geolocationProvider;
535     Vector<WKRetainPtr<WKGeolocationPermissionRequestRef> > m_geolocationPermissionRequests;
536     bool m_isGeolocationPermissionSet { false };
537     bool m_isGeolocationPermissionAllowed { false };
538
539     HashMap<String, RefPtr<OriginSettings>> m_cachedUserMediaPermissions;
540
541     typedef Vector<std::pair<String, WKRetainPtr<WKUserMediaPermissionRequestRef>>> PermissionRequestList;
542     PermissionRequestList m_userMediaPermissionRequests;
543
544     bool m_isUserMediaPermissionSet { false };
545     bool m_isUserMediaPermissionAllowed { false };
546
547     bool m_policyDelegateEnabled { false };
548     bool m_policyDelegatePermissive { false };
549     bool m_shouldDownloadUndisplayableMIMETypes { false };
550     bool m_shouldAllowDeviceOrientationAndMotionAccess { false };
551
552     bool m_rejectsProtectionSpaceAndContinueForAuthenticationChallenges { false };
553     bool m_handlesAuthenticationChallenges { false };
554     String m_authenticationUsername;
555     String m_authenticationPassword;
556
557     bool m_shouldBlockAllPlugins { false };
558     String m_unsupportedPluginMode;
559
560     bool m_forceComplexText { false };
561     bool m_shouldUseAcceleratedDrawing { false };
562     bool m_shouldUseRemoteLayerTree { false };
563
564     bool m_shouldLogCanAuthenticateAgainstProtectionSpace { false };
565     bool m_shouldLogDownloadCallbacks { false };
566     bool m_shouldLogHistoryClientCallbacks { false };
567     bool m_shouldShowWebView { false };
568     
569     bool m_shouldShowTouches { false };
570     bool m_checkForWorldLeaks { false };
571
572     bool m_allowAnyHTTPSCertificateForAllowedHosts { false };
573     
574     bool m_shouldDecideNavigationPolicyAfterDelay { false };
575     bool m_shouldDecideResponsePolicyAfterDelay { false };
576
577     bool m_didReceiveServerRedirectForProvisionalNavigation { false };
578
579     WKRetainPtr<WKArrayRef> m_openPanelFileURLs;
580 #if PLATFORM(IOS_FAMILY)
581     WKRetainPtr<WKDataRef> m_openPanelFileURLsMediaIcon;
582 #endif
583
584     std::unique_ptr<EventSenderProxy> m_eventSenderProxy;
585
586     WorkQueueManager m_workQueueManager;
587
588     struct AbandonedDocumentInfo {
589         String testURL;
590         String abandonedDocumentURL;
591
592         AbandonedDocumentInfo() = default;
593         AbandonedDocumentInfo(String inTestURL, String inAbandonedDocumentURL)
594             : testURL(inTestURL)
595             , abandonedDocumentURL(inAbandonedDocumentURL)
596         { }
597     };
598     HashMap<uint64_t, AbandonedDocumentInfo> m_abandonedDocumentInfo;
599
600     uint64_t m_serverTrustEvaluationCallbackCallsCount { 0 };
601     bool m_shouldDismissJavaScriptAlertsAsynchronously { false };
602     bool m_allowsAnySSLCertificate { true };
603     bool m_shouldSwapToEphemeralSessionOnNextNavigation { false };
604     bool m_shouldSwapToDefaultSessionOnNextNavigation { false };
605 };
606
607 struct TestCommand {
608     std::string pathOrURL;
609     std::string absolutePath;
610     std::string expectedPixelHash;
611     WTF::Seconds timeout;
612     bool shouldDumpPixels { false };
613     bool dumpJSConsoleLogInStdErr { false };
614 };
615
616 } // namespace WTR