b43c55c28665dfe65f42215aebc40271b3254c64
[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     String dumpAdClickAttribution();
298     void clearAdClickAttribution();
299
300 private:
301     WKRetainPtr<WKPageConfigurationRef> generatePageConfiguration(WKContextConfigurationRef);
302     WKRetainPtr<WKContextConfigurationRef> generateContextConfiguration(const TestOptions&) const;
303     void initialize(int argc, const char* argv[]);
304     void createWebViewWithOptions(const TestOptions&);
305     void run();
306
307     void runTestingServerLoop();
308     bool runTest(const char* pathOrURL);
309     
310     // Returns false if timed out.
311     bool waitForCompletion(const WTF::Function<void ()>&, WTF::Seconds timeout);
312
313     bool handleControlCommand(const char* command);
314
315     void platformInitialize();
316     void platformDestroy();
317     WKContextRef platformAdjustContext(WKContextRef, WKContextConfigurationRef);
318     void platformInitializeContext();
319     void platformAddTestOptions(TestOptions&) const;
320     void platformCreateWebView(WKPageConfigurationRef, const TestOptions&);
321     static PlatformWebView* platformCreateOtherPage(PlatformWebView* parentView, WKPageConfigurationRef, const TestOptions&);
322     void platformResetPreferencesToConsistentValues();
323     void platformResetStateToConsistentValues(const TestOptions&);
324 #if PLATFORM(COCOA)
325     void cocoaPlatformInitialize();
326     void cocoaResetStateToConsistentValues(const TestOptions&);
327 #endif
328     void platformConfigureViewForTest(const TestInvocation&);
329     void platformWillRunTest(const TestInvocation&);
330     void platformRunUntil(bool& done, WTF::Seconds timeout);
331     void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
332     WKContextRef platformContext();
333     WKPreferencesRef platformPreferences();
334     void initializeInjectedBundlePath();
335     void initializeTestPluginDirectory();
336
337     void ensureViewSupportsOptionsForTest(const TestInvocation&);
338     TestOptions testOptionsForTest(const TestCommand&) const;
339     void updatePlatformSpecificTestOptionsForTest(TestOptions&, const std::string& pathOrURL) const;
340
341     void updateWebViewSizeForTest(const TestInvocation&);
342     void updateWindowScaleForTest(PlatformWebView*, const TestInvocation&);
343
344     void updateLiveDocumentsAfterTest();
345     void checkForWorldLeaks();
346
347     void didReceiveLiveDocumentsList(WKArrayRef);
348     void findAndDumpWorldLeaks();
349
350     void decidePolicyForGeolocationPermissionRequestIfPossible();
351     void decidePolicyForUserMediaPermissionRequestIfPossible();
352
353     // WKContextInjectedBundleClient
354     static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
355     static void didReceiveSynchronousMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
356     static WKTypeRef getInjectedBundleInitializationUserData(WKContextRef, const void *clientInfo);
357
358     // WKPageInjectedBundleClient
359     static void didReceivePageMessageFromInjectedBundle(WKPageRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
360     static void didReceiveSynchronousPageMessageFromInjectedBundle(WKPageRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
361     void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
362     WKRetainPtr<WKTypeRef> didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
363     WKRetainPtr<WKTypeRef> getInjectedBundleInitializationUserData();
364
365     void didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef messageBodyDictionary, bool synchronous);
366
367     // WKContextClient
368     static void networkProcessDidCrash(WKContextRef, const void*);
369     void networkProcessDidCrash();
370
371     // WKPageNavigationClient
372     static void didCommitNavigation(WKPageRef, WKNavigationRef, WKTypeRef userData, const void*);
373     void didCommitNavigation(WKPageRef, WKNavigationRef);
374
375     static void didFinishNavigation(WKPageRef, WKNavigationRef, WKTypeRef userData, const void*);
376     void didFinishNavigation(WKPageRef, WKNavigationRef);
377
378     // WKContextDownloadClient
379     static void downloadDidStart(WKContextRef, WKDownloadRef, const void*);
380     void downloadDidStart(WKContextRef, WKDownloadRef);
381     static WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef, WKStringRef filename, bool* allowOverwrite, const void *clientInfo);
382     WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef, WKStringRef filename, bool*& allowOverwrite);
383     static void downloadDidFinish(WKContextRef, WKDownloadRef, const void*);
384     void downloadDidFinish(WKContextRef, WKDownloadRef);
385     static void downloadDidFail(WKContextRef, WKDownloadRef, WKErrorRef, const void*);
386     void downloadDidFail(WKContextRef, WKDownloadRef, WKErrorRef);
387     static void downloadDidCancel(WKContextRef, WKDownloadRef, const void*);
388     void downloadDidCancel(WKContextRef, WKDownloadRef);
389     static void downloadDidReceiveServerRedirectToURL(WKContextRef, WKDownloadRef, WKURLRef, const void*);
390     void downloadDidReceiveServerRedirectToURL(WKContextRef, WKDownloadRef, WKURLRef);
391     
392     static void processDidCrash(WKPageRef, const void* clientInfo);
393     void processDidCrash();
394
395     static void didBeginNavigationGesture(WKPageRef, const void*);
396     static void willEndNavigationGesture(WKPageRef, WKBackForwardListItemRef, const void*);
397     static void didEndNavigationGesture(WKPageRef, WKBackForwardListItemRef, const void*);
398     static void didRemoveNavigationGestureSnapshot(WKPageRef, const void*);
399     void didBeginNavigationGesture(WKPageRef);
400     void willEndNavigationGesture(WKPageRef, WKBackForwardListItemRef);
401     void didEndNavigationGesture(WKPageRef, WKBackForwardListItemRef);
402     void didRemoveNavigationGestureSnapshot(WKPageRef);
403
404     static WKPluginLoadPolicy decidePolicyForPluginLoad(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription, const void* clientInfo);
405     WKPluginLoadPolicy decidePolicyForPluginLoad(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription);
406     
407
408     static void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef, const void*);
409     void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef);
410
411     static void unavailablePluginButtonClicked(WKPageRef, WKPluginUnavailabilityReason, WKDictionaryRef, const void*);
412
413     static void didReceiveServerRedirectForProvisionalNavigation(WKPageRef, WKNavigationRef, WKTypeRef, const void*);
414     void didReceiveServerRedirectForProvisionalNavigation(WKPageRef, WKNavigationRef, WKTypeRef);
415
416     static bool canAuthenticateAgainstProtectionSpace(WKPageRef, WKProtectionSpaceRef, const void*);
417     bool canAuthenticateAgainstProtectionSpace(WKPageRef, WKProtectionSpaceRef);
418
419     static void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef, const void*);
420     void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef);
421
422     static void decidePolicyForNavigationAction(WKPageRef, WKNavigationActionRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
423     void decidePolicyForNavigationAction(WKFramePolicyListenerRef);
424
425     static void decidePolicyForNavigationResponse(WKPageRef, WKNavigationResponseRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
426     void decidePolicyForNavigationResponse(WKNavigationResponseRef, WKFramePolicyListenerRef);
427
428     // WKContextHistoryClient
429     static void didNavigateWithNavigationData(WKContextRef, WKPageRef, WKNavigationDataRef, WKFrameRef, const void*);
430     void didNavigateWithNavigationData(WKNavigationDataRef, WKFrameRef);
431
432     static void didPerformClientRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*);
433     void didPerformClientRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef);
434
435     static void didPerformServerRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*);
436     void didPerformServerRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef);
437
438     static void didUpdateHistoryTitle(WKContextRef, WKPageRef, WKStringRef title, WKURLRef, WKFrameRef, const void*);
439     void didUpdateHistoryTitle(WKStringRef title, WKURLRef, WKFrameRef);
440
441     static WKPageRef createOtherPage(WKPageRef, WKPageConfigurationRef, WKNavigationActionRef, WKWindowFeaturesRef, const void*);
442     WKPageRef createOtherPage(PlatformWebView* parentView, WKPageConfigurationRef, WKNavigationActionRef, WKWindowFeaturesRef);
443
444     static void runModal(WKPageRef, const void* clientInfo);
445     static void runModal(PlatformWebView*);
446
447     static const char* libraryPathForTesting();
448     static const char* platformLibraryPathForTesting();
449
450     std::unique_ptr<TestInvocation> m_currentInvocation;
451 #if PLATFORM(COCOA)
452     std::unique_ptr<ClassMethodSwizzler> m_calendarSwizzler;
453     RetainPtr<NSString> m_overriddenCalendarIdentifier;
454 #endif // PLATFORM(COCOA)
455     bool m_verbose { false };
456     bool m_printSeparators { false };
457     bool m_usingServerMode { false };
458     bool m_gcBetweenTests { false };
459     bool m_shouldDumpPixelsForAllTests { false };
460     std::vector<std::string> m_paths;
461     std::set<std::string> m_allowedHosts;
462     WKRetainPtr<WKStringRef> m_injectedBundlePath;
463     WKRetainPtr<WKStringRef> m_testPluginDirectory;
464
465     WebNotificationProvider m_webNotificationProvider;
466
467     std::unique_ptr<PlatformWebView> m_mainWebView;
468     WKRetainPtr<WKContextRef> m_context;
469     WKRetainPtr<WKPageGroupRef> m_pageGroup;
470     WKRetainPtr<WKUserContentControllerRef> m_userContentController;
471
472 #if PLATFORM(IOS_FAMILY)
473     Vector<std::unique_ptr<InstanceMethodSwizzler>> m_inputModeSwizzlers;
474     RetainPtr<UIKeyboardInputMode> m_overriddenKeyboardInputMode;
475 #endif
476
477     enum State {
478         Initial,
479         Resetting,
480         RunningTest
481     };
482     State m_state { Initial };
483     bool m_doneResetting { false };
484
485     bool m_useWaitToDumpWatchdogTimer { true };
486     bool m_forceNoTimeout { false };
487
488     bool m_didPrintWebProcessCrashedMessage { false };
489     bool m_shouldExitWhenWebProcessCrashes { true };
490     
491     bool m_beforeUnloadReturnValue { true };
492
493     std::unique_ptr<GeolocationProviderMock> m_geolocationProvider;
494     Vector<WKRetainPtr<WKGeolocationPermissionRequestRef> > m_geolocationPermissionRequests;
495     bool m_isGeolocationPermissionSet { false };
496     bool m_isGeolocationPermissionAllowed { false };
497
498     HashMap<String, RefPtr<OriginSettings>> m_cachedUserMediaPermissions;
499
500     typedef Vector<std::pair<String, WKRetainPtr<WKUserMediaPermissionRequestRef>>> PermissionRequestList;
501     PermissionRequestList m_userMediaPermissionRequests;
502
503     bool m_isUserMediaPermissionSet { false };
504     bool m_isUserMediaPermissionAllowed { false };
505
506     bool m_policyDelegateEnabled { false };
507     bool m_policyDelegatePermissive { false };
508     bool m_shouldDownloadUndisplayableMIMETypes { false };
509
510     bool m_rejectsProtectionSpaceAndContinueForAuthenticationChallenges { false };
511     bool m_handlesAuthenticationChallenges { false };
512     String m_authenticationUsername;
513     String m_authenticationPassword;
514
515     bool m_shouldBlockAllPlugins { false };
516     String m_unsupportedPluginMode;
517
518     bool m_forceComplexText { false };
519     bool m_shouldUseAcceleratedDrawing { false };
520     bool m_shouldUseRemoteLayerTree { false };
521
522     bool m_shouldLogCanAuthenticateAgainstProtectionSpace { false };
523     bool m_shouldLogDownloadCallbacks { false };
524     bool m_shouldLogHistoryClientCallbacks { false };
525     bool m_shouldShowWebView { false };
526     
527     bool m_shouldShowTouches { false };
528     bool m_checkForWorldLeaks { false };
529
530     bool m_allowAnyHTTPSCertificateForAllowedHosts { false };
531     
532     bool m_shouldDecideNavigationPolicyAfterDelay { false };
533     bool m_shouldDecideResponsePolicyAfterDelay { false };
534
535     bool m_didReceiveServerRedirectForProvisionalNavigation { false };
536
537     WKRetainPtr<WKArrayRef> m_openPanelFileURLs;
538
539     std::unique_ptr<EventSenderProxy> m_eventSenderProxy;
540
541     WorkQueueManager m_workQueueManager;
542
543     struct AbandonedDocumentInfo {
544         String testURL;
545         String abandonedDocumentURL;
546
547         AbandonedDocumentInfo() = default;
548         AbandonedDocumentInfo(String inTestURL, String inAbandonedDocumentURL)
549             : testURL(inTestURL)
550             , abandonedDocumentURL(inAbandonedDocumentURL)
551         { }
552     };
553     HashMap<uint64_t, AbandonedDocumentInfo> m_abandonedDocumentInfo;
554
555     uint64_t m_serverTrustEvaluationCallbackCallsCount { 0 };
556     bool m_shouldDismissJavaScriptAlertsAsynchronously { false };
557 };
558
559 struct TestCommand {
560     std::string pathOrURL;
561     std::string absolutePath;
562     std::string expectedPixelHash;
563     WTF::Seconds timeout;
564     bool shouldDumpPixels { false };
565     bool dumpJSConsoleLogInStdErr { false };
566 };
567
568 } // namespace WTR