Remove setDefersLoading infrastructure from WebKit2
[WebKit-https.git] / Tools / WebKitTestRunner / TestController.h
1 /*
2  * Copyright (C) 2010, 2015-2017 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 "WebNotificationProvider.h"
30 #include "WorkQueueManager.h"
31 #include <WebKit/WKRetainPtr.h>
32 #include <set>
33 #include <string>
34 #include <vector>
35 #include <wtf/HashMap.h>
36 #include <wtf/Noncopyable.h>
37 #include <wtf/Seconds.h>
38 #include <wtf/Vector.h>
39 #include <wtf/text/StringHash.h>
40
41 #if PLATFORM(COCOA)
42 #include "ClassMethodSwizzler.h"
43 #include "InstanceMethodSwizzler.h"
44 #endif
45
46 OBJC_CLASS NSString;
47 OBJC_CLASS UIKeyboardInputMode;
48 OBJC_CLASS WKWebViewConfiguration;
49
50 namespace WTR {
51
52 class TestInvocation;
53 class OriginSettings;
54 class PlatformWebView;
55 class EventSenderProxy;
56 struct TestCommand;
57 struct TestOptions;
58
59 class AsyncTask {
60 public:
61     AsyncTask(WTF::Function<void ()>&& task, WTF::Seconds timeout)
62         : m_task(WTFMove(task))
63         , m_timeout(timeout)
64     {
65         ASSERT(!currentTask());
66     }
67
68     // Returns false on timeout.
69     bool run();
70
71     void taskComplete()
72     {
73         m_taskDone = true;
74     }
75
76     static AsyncTask* currentTask();
77
78 private:
79     static AsyncTask* m_currentTask;
80
81     WTF::Function<void ()> m_task;
82     WTF::Seconds m_timeout;
83     bool m_taskDone { false };
84 };
85
86 // FIXME: Rename this TestRunner?
87 class TestController {
88 public:
89     static TestController& singleton();
90
91     static const unsigned viewWidth;
92     static const unsigned viewHeight;
93
94     static const unsigned w3cSVGViewWidth;
95     static const unsigned w3cSVGViewHeight;
96
97     static const WTF::Seconds defaultShortTimeout;
98     static const WTF::Seconds noTimeout;
99
100     TestController(int argc, const char* argv[]);
101     ~TestController();
102
103     bool verbose() const { return m_verbose; }
104
105     WKStringRef injectedBundlePath() const { return m_injectedBundlePath.get(); }
106     WKStringRef testPluginDirectory() const { return m_testPluginDirectory.get(); }
107
108     PlatformWebView* mainWebView() { return m_mainWebView.get(); }
109     WKContextRef context() { return m_context.get(); }
110     WKUserContentControllerRef userContentController() { return m_userContentController.get(); }
111
112     EventSenderProxy* eventSenderProxy() { return m_eventSenderProxy.get(); }
113
114     bool shouldUseRemoteLayerTree() const { return m_shouldUseRemoteLayerTree; }
115     
116     // Runs the run loop until `done` is true or the timeout elapses.
117     bool useWaitToDumpWatchdogTimer() { return m_useWaitToDumpWatchdogTimer; }
118     void runUntil(bool& done, WTF::Seconds timeout);
119     void notifyDone();
120
121     bool shouldShowWebView() const { return m_shouldShowWebView; }
122     bool usingServerMode() const { return m_usingServerMode; }
123     void configureViewForTest(const TestInvocation&);
124     
125     bool shouldShowTouches() const { return m_shouldShowTouches; }
126     
127     bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
128     void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
129
130     void simulateWebNotificationClick(uint64_t notificationID);
131
132     // Geolocation.
133     void setGeolocationPermission(bool);
134     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);
135     void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage);
136     void handleGeolocationPermissionRequest(WKGeolocationPermissionRequestRef);
137     bool isGeolocationProviderActive() const;
138
139     // MediaStream.
140     String saltForOrigin(WKFrameRef, String);
141     void getUserMediaInfoForOrigin(WKFrameRef, WKStringRef originKey, bool&, WKRetainPtr<WKStringRef>&);
142     WKStringRef getUserMediaSaltForOrigin(WKFrameRef, WKStringRef originKey);
143     void setUserMediaPermission(bool);
144     void resetUserMediaPermission();
145     void setUserMediaPersistentPermissionForOrigin(bool, WKStringRef userMediaDocumentOriginString, WKStringRef topLevelDocumentOriginString);
146     void handleUserMediaPermissionRequest(WKFrameRef, WKSecurityOriginRef, WKSecurityOriginRef, WKUserMediaPermissionRequestRef);
147     void handleCheckOfUserMediaPermissionForOrigin(WKFrameRef, WKSecurityOriginRef, WKSecurityOriginRef, const WKUserMediaPermissionCheckRef&);
148     OriginSettings& settingsForOrigin(const String&);
149     unsigned userMediaPermissionRequestCountForOrigin(WKStringRef userMediaDocumentOriginString, WKStringRef topLevelDocumentOriginString);
150     void resetUserMediaPermissionRequestCountForOrigin(WKStringRef userMediaDocumentOriginString, WKStringRef topLevelDocumentOriginString);
151
152     // Content Extensions.
153     void configureContentExtensionForTest(const TestInvocation&);
154     void resetContentExtensions();
155
156     // Policy delegate.
157     void setCustomPolicyDelegate(bool enabled, bool permissive);
158
159     // Page Visibility.
160     void setHidden(bool);
161
162     unsigned imageCountInGeneralPasteboard() const;
163
164     enum class ResetStage { BeforeTest, AfterTest };
165     bool resetStateToConsistentValues(const TestOptions&, ResetStage);
166     void resetPreferencesToConsistentValues(const TestOptions&);
167
168     void willDestroyWebView();
169
170     void terminateWebContentProcess();
171     void reattachPageToWebProcess();
172
173     static const char* webProcessName();
174     static const char* networkProcessName();
175     static const char* databaseProcessName();
176
177     WorkQueueManager& workQueueManager() { return m_workQueueManager; }
178
179     void setRejectsProtectionSpaceAndContinueForAuthenticationChallenges(bool value) { m_rejectsProtectionSpaceAndContinueForAuthenticationChallenges = value; }
180     void setHandlesAuthenticationChallenges(bool value) { m_handlesAuthenticationChallenges = value; }
181     void setAuthenticationUsername(String username) { m_authenticationUsername = username; }
182     void setAuthenticationPassword(String password) { m_authenticationPassword = password; }
183     void setAllowsAnySSLCertificate(bool);
184
185     void setBlockAllPlugins(bool shouldBlock);
186     void setPluginSupportedMode(const String&);
187
188     void setShouldLogHistoryClientCallbacks(bool shouldLog) { m_shouldLogHistoryClientCallbacks = shouldLog; }
189     void setShouldLogCanAuthenticateAgainstProtectionSpace(bool shouldLog) { m_shouldLogCanAuthenticateAgainstProtectionSpace = shouldLog; }
190     void setShouldLogDownloadCallbacks(bool shouldLog) { m_shouldLogDownloadCallbacks = shouldLog; }
191
192     bool isCurrentInvocation(TestInvocation* invocation) const { return invocation == m_currentInvocation.get(); }
193
194     void setShouldDecideNavigationPolicyAfterDelay(bool value) { m_shouldDecideNavigationPolicyAfterDelay = value; }
195     void setShouldDecideResponsePolicyAfterDelay(bool value) { m_shouldDecideResponsePolicyAfterDelay = value; }
196
197     void setNavigationGesturesEnabled(bool value);
198     void setIgnoresViewportScaleLimits(bool);
199
200     void setShouldDownloadUndisplayableMIMETypes(bool value) { m_shouldDownloadUndisplayableMIMETypes = value; }
201
202     void setStatisticsDebugMode(bool value);
203     void setStatisticsPrevalentResourceForDebugMode(WKStringRef hostName);
204     void setStatisticsLastSeen(WKStringRef hostName, double seconds);
205     void setStatisticsPrevalentResource(WKStringRef hostName, bool value);
206     void setStatisticsVeryPrevalentResource(WKStringRef hostName, bool value);
207     String dumpResourceLoadStatistics();
208     bool isStatisticsPrevalentResource(WKStringRef hostName);
209     bool isStatisticsVeryPrevalentResource(WKStringRef hostName);
210     bool isStatisticsRegisteredAsSubresourceUnder(WKStringRef subresourceHost, WKStringRef topFrameHost);
211     bool isStatisticsRegisteredAsSubFrameUnder(WKStringRef subFrameHost, WKStringRef topFrameHost);
212     bool isStatisticsRegisteredAsRedirectingTo(WKStringRef hostRedirectedFrom, WKStringRef hostRedirectedTo);
213     void setStatisticsHasHadUserInteraction(WKStringRef hostName, bool value);
214     bool isStatisticsHasHadUserInteraction(WKStringRef hostName);
215     void setStatisticsGrandfathered(WKStringRef hostName, bool value);
216     bool isStatisticsGrandfathered(WKStringRef hostName);
217     void setStatisticsSubframeUnderTopFrameOrigin(WKStringRef hostName, WKStringRef topFrameHostName);
218     void setStatisticsSubresourceUnderTopFrameOrigin(WKStringRef hostName, WKStringRef topFrameHostName);
219     void setStatisticsSubresourceUniqueRedirectTo(WKStringRef hostName, WKStringRef hostNameRedirectedTo);
220     void setStatisticsSubresourceUniqueRedirectFrom(WKStringRef host, WKStringRef hostRedirectedFrom);
221     void setStatisticsTopFrameUniqueRedirectTo(WKStringRef host, WKStringRef hostRedirectedTo);
222     void setStatisticsTopFrameUniqueRedirectFrom(WKStringRef host, WKStringRef hostRedirectedFrom);
223     void setStatisticsTimeToLiveUserInteraction(double seconds);
224     void statisticsProcessStatisticsAndDataRecords();
225     void statisticsUpdateCookieBlocking();
226     void statisticsSubmitTelemetry();
227     void setStatisticsNotifyPagesWhenDataRecordsWereScanned(bool);
228     void setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool);
229     void setStatisticsNotifyPagesWhenTelemetryWasCaptured(bool value);
230     void setStatisticsMinimumTimeBetweenDataRecordsRemoval(double);
231     void setStatisticsGrandfatheringTime(double seconds);
232     void setStatisticsMaxStatisticsEntries(unsigned);
233     void setStatisticsPruneEntriesDownTo(unsigned);
234     void statisticsClearInMemoryAndPersistentStore();
235     void statisticsClearInMemoryAndPersistentStoreModifiedSinceHours(unsigned);
236     void statisticsClearThroughWebsiteDataRemoval();
237     void setStatisticsCacheMaxAgeCap(double seconds);
238     void statisticsResetToConsistentState();
239
240     void getAllStorageAccessEntries();
241
242     WKArrayRef openPanelFileURLs() const { return m_openPanelFileURLs.get(); }
243     void setOpenPanelFileURLs(WKArrayRef fileURLs) { m_openPanelFileURLs = fileURLs; }
244
245     void terminateNetworkProcess();
246     void terminateServiceWorkerProcess();
247
248     void removeAllSessionCredentials();
249
250     void ClearIndexedDatabases();
251
252     void clearServiceWorkerRegistrations();
253
254     void clearDOMCache(WKStringRef origin);
255     void clearDOMCaches();
256     bool hasDOMCache(WKStringRef origin);
257     uint64_t domCacheSize(WKStringRef origin);
258     void allowCacheStorageQuotaIncrease();
259
260     void setIDBPerOriginQuota(uint64_t);
261
262     bool didReceiveServerRedirectForProvisionalNavigation() const { return m_didReceiveServerRedirectForProvisionalNavigation; }
263     void clearDidReceiveServerRedirectForProvisionalNavigation() { m_didReceiveServerRedirectForProvisionalNavigation = false; }
264
265     void addMockMediaDevice(WKStringRef persistentID, WKStringRef label, WKStringRef type);
266     void clearMockMediaDevices();
267     void removeMockMediaDevice(WKStringRef persistentID);
268     void resetMockMediaDevices();
269
270     void injectUserScript(WKStringRef);
271     
272     void sendDisplayConfigurationChangedMessageForTesting();
273
274     void setWebAuthenticationMockConfiguration(WKDictionaryRef);
275     void addTestKeyToKeychain(const String& privateKeyBase64, const String& attrLabel, const String& applicationTagBase64);
276     void cleanUpKeychain(const String& attrLabel);
277     bool keyExistsInKeychain(const String& attrLabel, const String& applicationTagBase64);
278
279 #if PLATFORM(COCOA)
280     RetainPtr<NSString> getOverriddenCalendarIdentifier() const;
281     void setDefaultCalendarType(NSString *identifier);
282 #endif // PLATFORM(COCOA)
283
284 #if PLATFORM(IOS_FAMILY)
285     void setKeyboardInputModeIdentifier(const String&);
286     UIKeyboardInputMode *overriddenKeyboardInputMode() const { return m_overriddenKeyboardInputMode.get(); }
287 #endif
288
289     bool canDoServerTrustEvaluationInNetworkProcess() const;
290     uint64_t serverTrustEvaluationCallbackCallsCount() const { return m_serverTrustEvaluationCallbackCallsCount; }
291
292     void setShouldDismissJavaScriptAlertsAsynchronously(bool);
293     void handleJavaScriptAlert(WKPageRunJavaScriptAlertResultListenerRef);
294
295     bool isDoingMediaCapture() const;
296
297 private:
298     WKRetainPtr<WKPageConfigurationRef> generatePageConfiguration(WKContextConfigurationRef);
299     WKRetainPtr<WKContextConfigurationRef> generateContextConfiguration(const TestOptions&) const;
300     void initialize(int argc, const char* argv[]);
301     void createWebViewWithOptions(const TestOptions&);
302     void run();
303
304     void runTestingServerLoop();
305     bool runTest(const char* pathOrURL);
306     
307     // Returns false if timed out.
308     bool waitForCompletion(const WTF::Function<void ()>&, WTF::Seconds timeout);
309
310     bool handleControlCommand(const char* command);
311
312     void platformInitialize();
313     void platformDestroy();
314     WKContextRef platformAdjustContext(WKContextRef, WKContextConfigurationRef);
315     void platformInitializeContext();
316     void platformAddTestOptions(TestOptions&) const;
317     void platformCreateWebView(WKPageConfigurationRef, const TestOptions&);
318     static PlatformWebView* platformCreateOtherPage(PlatformWebView* parentView, WKPageConfigurationRef, const TestOptions&);
319     void platformResetPreferencesToConsistentValues();
320     void platformResetStateToConsistentValues(const TestOptions&);
321 #if PLATFORM(COCOA)
322     void cocoaPlatformInitialize();
323     void cocoaResetStateToConsistentValues(const TestOptions&);
324 #endif
325     void platformConfigureViewForTest(const TestInvocation&);
326     void platformWillRunTest(const TestInvocation&);
327     void platformRunUntil(bool& done, WTF::Seconds timeout);
328     void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
329     WKContextRef platformContext();
330     WKPreferencesRef platformPreferences();
331     void initializeInjectedBundlePath();
332     void initializeTestPluginDirectory();
333
334     void ensureViewSupportsOptionsForTest(const TestInvocation&);
335     TestOptions testOptionsForTest(const TestCommand&) const;
336     void updatePlatformSpecificTestOptionsForTest(TestOptions&, const std::string& pathOrURL) const;
337
338     void updateWebViewSizeForTest(const TestInvocation&);
339     void updateWindowScaleForTest(PlatformWebView*, const TestInvocation&);
340
341     void updateLiveDocumentsAfterTest();
342     void checkForWorldLeaks();
343
344     void didReceiveLiveDocumentsList(WKArrayRef);
345     void findAndDumpWorldLeaks();
346
347     void decidePolicyForGeolocationPermissionRequestIfPossible();
348     void decidePolicyForUserMediaPermissionRequestIfPossible();
349
350     // WKContextInjectedBundleClient
351     static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
352     static void didReceiveSynchronousMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
353     static WKTypeRef getInjectedBundleInitializationUserData(WKContextRef, const void *clientInfo);
354
355     // WKPageInjectedBundleClient
356     static void didReceivePageMessageFromInjectedBundle(WKPageRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
357     static void didReceiveSynchronousPageMessageFromInjectedBundle(WKPageRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
358     void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
359     WKRetainPtr<WKTypeRef> didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
360     WKRetainPtr<WKTypeRef> getInjectedBundleInitializationUserData();
361
362     void didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef messageBodyDictionary, bool synchronous);
363
364     // WKContextClient
365     static void networkProcessDidCrash(WKContextRef, const void*);
366     void networkProcessDidCrash();
367
368     // WKPageNavigationClient
369     static void didCommitNavigation(WKPageRef, WKNavigationRef, WKTypeRef userData, const void*);
370     void didCommitNavigation(WKPageRef, WKNavigationRef);
371
372     static void didFinishNavigation(WKPageRef, WKNavigationRef, WKTypeRef userData, const void*);
373     void didFinishNavigation(WKPageRef, WKNavigationRef);
374
375     // WKContextDownloadClient
376     static void downloadDidStart(WKContextRef, WKDownloadRef, const void*);
377     void downloadDidStart(WKContextRef, WKDownloadRef);
378     static WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef, WKStringRef filename, bool* allowOverwrite, const void *clientInfo);
379     WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef, WKStringRef filename, bool*& allowOverwrite);
380     static void downloadDidFinish(WKContextRef, WKDownloadRef, const void*);
381     void downloadDidFinish(WKContextRef, WKDownloadRef);
382     static void downloadDidFail(WKContextRef, WKDownloadRef, WKErrorRef, const void*);
383     void downloadDidFail(WKContextRef, WKDownloadRef, WKErrorRef);
384     static void downloadDidCancel(WKContextRef, WKDownloadRef, const void*);
385     void downloadDidCancel(WKContextRef, WKDownloadRef);
386     static void downloadDidReceiveServerRedirectToURL(WKContextRef, WKDownloadRef, WKURLRef, const void*);
387     void downloadDidReceiveServerRedirectToURL(WKContextRef, WKDownloadRef, WKURLRef);
388     
389     static void processDidCrash(WKPageRef, const void* clientInfo);
390     void processDidCrash();
391
392     static void didBeginNavigationGesture(WKPageRef, const void*);
393     static void willEndNavigationGesture(WKPageRef, WKBackForwardListItemRef, const void*);
394     static void didEndNavigationGesture(WKPageRef, WKBackForwardListItemRef, const void*);
395     static void didRemoveNavigationGestureSnapshot(WKPageRef, const void*);
396     void didBeginNavigationGesture(WKPageRef);
397     void willEndNavigationGesture(WKPageRef, WKBackForwardListItemRef);
398     void didEndNavigationGesture(WKPageRef, WKBackForwardListItemRef);
399     void didRemoveNavigationGestureSnapshot(WKPageRef);
400
401     static WKPluginLoadPolicy decidePolicyForPluginLoad(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription, const void* clientInfo);
402     WKPluginLoadPolicy decidePolicyForPluginLoad(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription);
403     
404
405     static void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef, const void*);
406     void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef);
407
408     static void unavailablePluginButtonClicked(WKPageRef, WKPluginUnavailabilityReason, WKDictionaryRef, const void*);
409
410     static void didReceiveServerRedirectForProvisionalNavigation(WKPageRef, WKNavigationRef, WKTypeRef, const void*);
411     void didReceiveServerRedirectForProvisionalNavigation(WKPageRef, WKNavigationRef, WKTypeRef);
412
413     static bool canAuthenticateAgainstProtectionSpace(WKPageRef, WKProtectionSpaceRef, const void*);
414     bool canAuthenticateAgainstProtectionSpace(WKPageRef, WKProtectionSpaceRef);
415
416     static void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef, const void*);
417     void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef);
418
419     static void decidePolicyForNavigationAction(WKPageRef, WKNavigationActionRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
420     void decidePolicyForNavigationAction(WKFramePolicyListenerRef);
421
422     static void decidePolicyForNavigationResponse(WKPageRef, WKNavigationResponseRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
423     void decidePolicyForNavigationResponse(WKNavigationResponseRef, WKFramePolicyListenerRef);
424
425     // WKContextHistoryClient
426     static void didNavigateWithNavigationData(WKContextRef, WKPageRef, WKNavigationDataRef, WKFrameRef, const void*);
427     void didNavigateWithNavigationData(WKNavigationDataRef, WKFrameRef);
428
429     static void didPerformClientRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*);
430     void didPerformClientRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef);
431
432     static void didPerformServerRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*);
433     void didPerformServerRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef);
434
435     static void didUpdateHistoryTitle(WKContextRef, WKPageRef, WKStringRef title, WKURLRef, WKFrameRef, const void*);
436     void didUpdateHistoryTitle(WKStringRef title, WKURLRef, WKFrameRef);
437
438     static WKPageRef createOtherPage(WKPageRef, WKPageConfigurationRef, WKNavigationActionRef, WKWindowFeaturesRef, const void*);
439     WKPageRef createOtherPage(PlatformWebView* parentView, WKPageConfigurationRef, WKNavigationActionRef, WKWindowFeaturesRef);
440
441     static void runModal(WKPageRef, const void* clientInfo);
442     static void runModal(PlatformWebView*);
443
444     static const char* libraryPathForTesting();
445     static const char* platformLibraryPathForTesting();
446
447     std::unique_ptr<TestInvocation> m_currentInvocation;
448 #if PLATFORM(COCOA)
449     std::unique_ptr<ClassMethodSwizzler> m_calendarSwizzler;
450     RetainPtr<NSString> m_overriddenCalendarIdentifier;
451 #endif // PLATFORM(COCOA)
452     bool m_verbose { false };
453     bool m_printSeparators { false };
454     bool m_usingServerMode { false };
455     bool m_gcBetweenTests { false };
456     bool m_shouldDumpPixelsForAllTests { false };
457     std::vector<std::string> m_paths;
458     std::set<std::string> m_allowedHosts;
459     WKRetainPtr<WKStringRef> m_injectedBundlePath;
460     WKRetainPtr<WKStringRef> m_testPluginDirectory;
461
462     WebNotificationProvider m_webNotificationProvider;
463
464     std::unique_ptr<PlatformWebView> m_mainWebView;
465     WKRetainPtr<WKContextRef> m_context;
466     WKRetainPtr<WKPageGroupRef> m_pageGroup;
467     WKRetainPtr<WKUserContentControllerRef> m_userContentController;
468
469 #if PLATFORM(IOS_FAMILY)
470     Vector<std::unique_ptr<InstanceMethodSwizzler>> m_inputModeSwizzlers;
471     RetainPtr<UIKeyboardInputMode> m_overriddenKeyboardInputMode;
472 #endif
473
474     enum State {
475         Initial,
476         Resetting,
477         RunningTest
478     };
479     State m_state { Initial };
480     bool m_doneResetting { false };
481
482     bool m_useWaitToDumpWatchdogTimer { true };
483     bool m_forceNoTimeout { false };
484
485     bool m_didPrintWebProcessCrashedMessage { false };
486     bool m_shouldExitWhenWebProcessCrashes { true };
487     
488     bool m_beforeUnloadReturnValue { true };
489
490     std::unique_ptr<GeolocationProviderMock> m_geolocationProvider;
491     Vector<WKRetainPtr<WKGeolocationPermissionRequestRef> > m_geolocationPermissionRequests;
492     bool m_isGeolocationPermissionSet { false };
493     bool m_isGeolocationPermissionAllowed { false };
494
495     HashMap<String, RefPtr<OriginSettings>> m_cachedUserMediaPermissions;
496
497     typedef Vector<std::pair<String, WKRetainPtr<WKUserMediaPermissionRequestRef>>> PermissionRequestList;
498     PermissionRequestList m_userMediaPermissionRequests;
499
500     bool m_isUserMediaPermissionSet { false };
501     bool m_isUserMediaPermissionAllowed { false };
502
503     bool m_policyDelegateEnabled { false };
504     bool m_policyDelegatePermissive { false };
505     bool m_shouldDownloadUndisplayableMIMETypes { false };
506
507     bool m_rejectsProtectionSpaceAndContinueForAuthenticationChallenges { false };
508     bool m_handlesAuthenticationChallenges { false };
509     String m_authenticationUsername;
510     String m_authenticationPassword;
511
512     bool m_shouldBlockAllPlugins { false };
513     String m_unsupportedPluginMode;
514
515     bool m_forceComplexText { false };
516     bool m_shouldUseAcceleratedDrawing { false };
517     bool m_shouldUseRemoteLayerTree { false };
518
519     bool m_shouldLogCanAuthenticateAgainstProtectionSpace { false };
520     bool m_shouldLogDownloadCallbacks { false };
521     bool m_shouldLogHistoryClientCallbacks { false };
522     bool m_shouldShowWebView { false };
523     
524     bool m_shouldShowTouches { false };
525     bool m_checkForWorldLeaks { false };
526
527     bool m_allowAnyHTTPSCertificateForAllowedHosts { false };
528     
529     bool m_shouldDecideNavigationPolicyAfterDelay { false };
530     bool m_shouldDecideResponsePolicyAfterDelay { false };
531
532     bool m_didReceiveServerRedirectForProvisionalNavigation { false };
533
534     WKRetainPtr<WKArrayRef> m_openPanelFileURLs;
535
536     std::unique_ptr<EventSenderProxy> m_eventSenderProxy;
537
538     WorkQueueManager m_workQueueManager;
539
540     struct AbandonedDocumentInfo {
541         String testURL;
542         String abandonedDocumentURL;
543
544         AbandonedDocumentInfo() = default;
545         AbandonedDocumentInfo(String inTestURL, String inAbandonedDocumentURL)
546             : testURL(inTestURL)
547             , abandonedDocumentURL(inAbandonedDocumentURL)
548         { }
549     };
550     HashMap<uint64_t, AbandonedDocumentInfo> m_abandonedDocumentInfo;
551
552     uint64_t m_serverTrustEvaluationCallbackCallsCount { 0 };
553     bool m_shouldDismissJavaScriptAlertsAsynchronously { false };
554 };
555
556 struct TestCommand {
557     std::string pathOrURL;
558     std::string absolutePath;
559     std::string expectedPixelHash;
560     WTF::Seconds timeout;
561     bool shouldDumpPixels { false };
562     bool dumpJSConsoleLogInStdErr { false };
563 };
564
565 } // namespace WTR