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