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