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