Crash when following a Google search link to Twitter with Limit Adult Content enabled
[WebKit-https.git] / Tools / WebKitTestRunner / TestController.h
1 /*
2  * Copyright (C) 2010, 2015 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 #ifndef TestController_h
27 #define TestController_h
28
29 #include "GeolocationProviderMock.h"
30 #include "WebNotificationProvider.h"
31 #include "WorkQueueManager.h"
32 #include <WebKit/WKRetainPtr.h>
33 #include <string>
34 #include <vector>
35 #include <wtf/Vector.h>
36
37 OBJC_CLASS WKWebViewConfiguration;
38
39 namespace WTR {
40
41 class TestInvocation;
42 class PlatformWebView;
43 class EventSenderProxy;
44 struct ViewOptions;
45
46 // FIXME: Rename this TestRunner?
47 class TestController {
48 public:
49     static TestController& singleton();
50
51     static const unsigned viewWidth;
52     static const unsigned viewHeight;
53
54     static const unsigned w3cSVGViewWidth;
55     static const unsigned w3cSVGViewHeight;
56
57     static const double shortTimeout;
58     static const double noTimeout;
59
60     TestController(int argc, const char* argv[]);
61     ~TestController();
62
63     bool verbose() const { return m_verbose; }
64
65     WKStringRef injectedBundlePath() { return m_injectedBundlePath.get(); }
66     WKStringRef testPluginDirectory() { return m_testPluginDirectory.get(); }
67
68     PlatformWebView* mainWebView() { return m_mainWebView.get(); }
69     WKContextRef context() { return m_context.get(); }
70
71     EventSenderProxy* eventSenderProxy() { return m_eventSenderProxy.get(); }
72
73     bool shouldUseRemoteLayerTree() const { return m_shouldUseRemoteLayerTree; }
74     
75     // Runs the run loop until `done` is true or the timeout elapses.
76     bool useWaitToDumpWatchdogTimer() { return m_useWaitToDumpWatchdogTimer; }
77     void runUntil(bool& done, double timeoutSeconds);
78     void notifyDone();
79
80     bool shouldShowWebView() const { return m_shouldShowWebView; }
81
82     void configureViewForTest(const TestInvocation&);
83     
84     bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
85     void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
86
87     void simulateWebNotificationClick(uint64_t notificationID);
88
89     // Geolocation.
90     void setGeolocationPermission(bool);
91     void setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed);
92     void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage);
93     void handleGeolocationPermissionRequest(WKGeolocationPermissionRequestRef);
94     bool isGeolocationProviderActive() const;
95
96     // MediaStream.
97     void setUserMediaPermission(bool);
98     void handleUserMediaPermissionRequest(WKUserMediaPermissionRequestRef);
99
100     // Policy delegate.
101     void setCustomPolicyDelegate(bool enabled, bool permissive);
102
103     // Page Visibility.
104     void setHidden(bool);
105
106     bool resetStateToConsistentValues();
107     void resetPreferencesToConsistentValues();
108
109     void terminateWebContentProcess();
110     void reattachPageToWebProcess();
111
112     static const char* webProcessName();
113     static const char* networkProcessName();
114
115     WorkQueueManager& workQueueManager() { return m_workQueueManager; }
116
117     void setHandlesAuthenticationChallenges(bool value) { m_handlesAuthenticationChallenges = value; }
118     void setAuthenticationUsername(String username) { m_authenticationUsername = username; }
119     void setAuthenticationPassword(String password) { m_authenticationPassword = password; }
120
121     void setBlockAllPlugins(bool shouldBlock) { m_shouldBlockAllPlugins = shouldBlock; }
122
123     void setShouldLogHistoryClientCallbacks(bool shouldLog) { m_shouldLogHistoryClientCallbacks = shouldLog; }
124
125     bool isCurrentInvocation(TestInvocation* invocation) const { return invocation == m_currentInvocation.get(); }
126
127     void setShouldDecideNavigationPolicyAfterDelay(bool value) { m_shouldDecideNavigationPolicyAfterDelay = value; }
128
129 private:
130     void initialize(int argc, const char* argv[]);
131     void createWebViewWithOptions(const ViewOptions&);
132     void run();
133
134     void runTestingServerLoop();
135     bool runTest(const char* pathOrURL);
136
137     void platformInitialize();
138     void platformDestroy();
139     WKContextRef platformAdjustContext(WKContextRef, WKContextConfigurationRef);
140     void platformInitializeContext();
141     void platformCreateWebView(WKPageConfigurationRef, const ViewOptions&);
142     static PlatformWebView* platformCreateOtherPage(PlatformWebView* parentView, WKPageConfigurationRef, const ViewOptions&);
143     void platformResetPreferencesToConsistentValues();
144     void platformResetStateToConsistentValues();
145     void platformConfigureViewForTest(const TestInvocation&);
146     void platformWillRunTest(const TestInvocation&);
147     void platformRunUntil(bool& done, double timeout);
148     void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
149     WKPreferencesRef platformPreferences();
150     void initializeInjectedBundlePath();
151     void initializeTestPluginDirectory();
152
153     void ensureViewSupportsOptionsForTest(const TestInvocation&);
154     ViewOptions viewOptionsForTest(const TestInvocation&) const;
155     void updatePlatformSpecificViewOptionsForTest(ViewOptions&, const TestInvocation&) const;
156
157     void updateWebViewSizeForTest(const TestInvocation&);
158     void updateWindowScaleForTest(PlatformWebView*, const TestInvocation&);
159
160     void decidePolicyForGeolocationPermissionRequestIfPossible();
161     void decidePolicyForUserMediaPermissionRequestIfPossible();
162
163     // WKContextInjectedBundleClient
164     static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
165     static void didReceiveSynchronousMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
166
167     // WKPageInjectedBundleClient
168     static void didReceivePageMessageFromInjectedBundle(WKPageRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
169     static void didReceiveSynchronousPageMessageFromInjectedBundle(WKPageRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
170     void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
171     WKRetainPtr<WKTypeRef> didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
172
173     void didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef messageBodyDictionary, bool synchronous);
174
175     // WKContextClient
176     static void networkProcessDidCrash(WKContextRef, const void*);
177     void networkProcessDidCrash();
178
179     // WKPageNavigationClient
180     static void didCommitNavigation(WKPageRef, WKNavigationRef, WKTypeRef userData, const void*);
181     void didCommitNavigation(WKPageRef, WKNavigationRef);
182
183     static void didFinishNavigation(WKPageRef, WKNavigationRef, WKTypeRef userData, const void*);
184     void didFinishNavigation(WKPageRef, WKNavigationRef);
185
186     static void processDidCrash(WKPageRef, const void* clientInfo);
187     void processDidCrash();
188
189     static WKPluginLoadPolicy decidePolicyForPluginLoad(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription, const void* clientInfo);
190     WKPluginLoadPolicy decidePolicyForPluginLoad(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription);
191     
192
193     static void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef, const void*);
194     void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef);
195
196     static void unavailablePluginButtonClicked(WKPageRef, WKPluginUnavailabilityReason, WKDictionaryRef, const void*);
197
198     static bool canAuthenticateAgainstProtectionSpace(WKPageRef, WKProtectionSpaceRef, const void *clientInfo);
199
200     static void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef, const void *clientInfo);
201     void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef);
202
203     static void decidePolicyForNavigationAction(WKPageRef, WKNavigationActionRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
204     void decidePolicyForNavigationAction(WKFramePolicyListenerRef);
205
206     static void decidePolicyForNavigationResponse(WKPageRef, WKNavigationResponseRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
207     void decidePolicyForNavigationResponse(WKNavigationResponseRef, WKFramePolicyListenerRef);
208
209     // WKContextHistoryClient
210     static void didNavigateWithNavigationData(WKContextRef, WKPageRef, WKNavigationDataRef, WKFrameRef, const void*);
211     void didNavigateWithNavigationData(WKNavigationDataRef, WKFrameRef);
212
213     static void didPerformClientRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*);
214     void didPerformClientRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef);
215
216     static void didPerformServerRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*);
217     void didPerformServerRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef);
218
219     static void didUpdateHistoryTitle(WKContextRef, WKPageRef, WKStringRef title, WKURLRef, WKFrameRef, const void*);
220     void didUpdateHistoryTitle(WKStringRef title, WKURLRef, WKFrameRef);
221
222     static WKPageRef createOtherPage(WKPageRef, WKPageConfigurationRef, WKNavigationActionRef, WKWindowFeaturesRef, const void*);
223
224     static void runModal(WKPageRef, const void* clientInfo);
225     static void runModal(PlatformWebView*);
226
227     static const char* libraryPathForTesting();
228     static const char* platformLibraryPathForTesting();
229
230     std::unique_ptr<TestInvocation> m_currentInvocation;
231
232     bool m_verbose;
233     bool m_printSeparators;
234     bool m_usingServerMode;
235     bool m_gcBetweenTests;
236     bool m_shouldDumpPixelsForAllTests;
237     std::vector<std::string> m_paths;
238     std::vector<std::string> m_allowedHosts;
239     WKRetainPtr<WKStringRef> m_injectedBundlePath;
240     WKRetainPtr<WKStringRef> m_testPluginDirectory;
241
242     WebNotificationProvider m_webNotificationProvider;
243
244     std::unique_ptr<PlatformWebView> m_mainWebView;
245     WKRetainPtr<WKContextRef> m_context;
246     WKRetainPtr<WKPageGroupRef> m_pageGroup;
247     WKRetainPtr<WKPageConfigurationRef> m_configuration;
248
249     enum State {
250         Initial,
251         Resetting,
252         RunningTest
253     };
254     State m_state;
255     bool m_doneResetting;
256
257     bool m_useWaitToDumpWatchdogTimer;
258     bool m_forceNoTimeout;
259
260     bool m_didPrintWebProcessCrashedMessage;
261     bool m_shouldExitWhenWebProcessCrashes;
262     
263     bool m_beforeUnloadReturnValue;
264
265     std::unique_ptr<GeolocationProviderMock> m_geolocationProvider;
266     Vector<WKRetainPtr<WKGeolocationPermissionRequestRef> > m_geolocationPermissionRequests;
267     bool m_isGeolocationPermissionSet;
268     bool m_isGeolocationPermissionAllowed;
269
270     Vector<WKRetainPtr<WKUserMediaPermissionRequestRef>> m_userMediaPermissionRequests;
271     bool m_isUserMediaPermissionSet;
272     bool m_isUserMediaPermissionAllowed;
273
274     bool m_policyDelegateEnabled;
275     bool m_policyDelegatePermissive;
276
277     bool m_handlesAuthenticationChallenges;
278     String m_authenticationUsername;
279     String m_authenticationPassword;
280
281     bool m_shouldBlockAllPlugins;
282
283     bool m_forceComplexText;
284     bool m_shouldUseAcceleratedDrawing;
285     bool m_shouldUseRemoteLayerTree;
286
287     bool m_shouldLogHistoryClientCallbacks;
288     bool m_shouldShowWebView;
289
290     bool m_shouldDecideNavigationPolicyAfterDelay { false };
291
292     std::unique_ptr<EventSenderProxy> m_eventSenderProxy;
293
294     WorkQueueManager m_workQueueManager;
295 };
296
297 } // namespace WTR
298
299 #endif // TestController_h