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