Provide a runtime flag to run-webkit-tests that shows the test view
[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 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     bool shouldShowWebView() const { return m_shouldShowWebView; }
79
80     void configureViewForTest(const TestInvocation&);
81     
82     bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
83     void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
84
85     void simulateWebNotificationClick(uint64_t notificationID);
86
87     // Geolocation.
88     void setGeolocationPermission(bool);
89     void setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed);
90     void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage);
91     void handleGeolocationPermissionRequest(WKGeolocationPermissionRequestRef);
92
93     // MediaStream.
94     void setUserMediaPermission(bool);
95     void handleUserMediaPermissionRequest(WKUserMediaPermissionRequestRef);
96
97     // Policy delegate.
98     void setCustomPolicyDelegate(bool enabled, bool permissive);
99
100     // Page Visibility.
101     void setHidden(bool);
102
103     bool resetStateToConsistentValues();
104     void resetPreferencesToConsistentValues();
105
106     void terminateWebContentProcess();
107     void reattachPageToWebProcess();
108
109     static const char* webProcessName();
110     static const char* networkProcessName();
111
112     WorkQueueManager& workQueueManager() { return m_workQueueManager; }
113
114     void setHandlesAuthenticationChallenges(bool value) { m_handlesAuthenticationChallenges = value; }
115     void setAuthenticationUsername(String username) { m_authenticationUsername = username; }
116     void setAuthenticationPassword(String password) { m_authenticationPassword = password; }
117
118     void setBlockAllPlugins(bool shouldBlock) { m_shouldBlockAllPlugins = shouldBlock; }
119
120     void setShouldLogHistoryClientCallbacks(bool shouldLog) { m_shouldLogHistoryClientCallbacks = shouldLog; }
121
122     bool isCurrentInvocation(TestInvocation* invocation) const { return invocation == m_currentInvocation.get(); }
123
124 private:
125     void initialize(int argc, const char* argv[]);
126     void createWebViewWithOptions(WKDictionaryRef);
127     void run();
128
129     void runTestingServerLoop();
130     bool runTest(const char* pathOrURL);
131
132     void platformInitialize();
133     void platformDestroy();
134     void platformInitializeContext();
135     void platformResetPreferencesToConsistentValues();
136     void platformConfigureViewForTest(const TestInvocation&);
137     void platformWillRunTest(const TestInvocation&);
138     void platformRunUntil(bool& done, double timeout);
139     void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
140     void initializeInjectedBundlePath();
141     void initializeTestPluginDirectory();
142
143     void updateWebViewSizeForTest(const TestInvocation&);
144     void updateWindowScaleForTest(PlatformWebView*, const TestInvocation&);
145     void updateLayoutTypeForTest(const TestInvocation&);
146
147     void decidePolicyForGeolocationPermissionRequestIfPossible();
148     void decidePolicyForUserMediaPermissionRequestIfPossible();
149
150     // WKContextInjectedBundleClient
151     static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
152     static void didReceiveSynchronousMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
153
154     // WKPageInjectedBundleClient
155     static void didReceivePageMessageFromInjectedBundle(WKPageRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
156     static void didReceiveSynchronousPageMessageFromInjectedBundle(WKPageRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
157     void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
158     WKRetainPtr<WKTypeRef> didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
159
160     void didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef messageBodyDictionary, bool synchronous);
161
162     // WKContextClient
163     static void networkProcessDidCrash(WKContextRef, const void*);
164     void networkProcessDidCrash();
165
166     // WKPageNavigationClient
167     static void didCommitNavigation(WKPageRef, WKNavigationRef, WKTypeRef userData, const void*);
168     void didCommitNavigation(WKPageRef, WKNavigationRef);
169
170     static void didFinishNavigation(WKPageRef, WKNavigationRef, WKTypeRef userData, const void*);
171     void didFinishNavigation(WKPageRef, WKNavigationRef);
172
173     static void processDidCrash(WKPageRef, const void* clientInfo);
174     void processDidCrash();
175
176     static WKPluginLoadPolicy decidePolicyForPluginLoad(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription, const void* clientInfo);
177     WKPluginLoadPolicy decidePolicyForPluginLoad(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription);
178     
179
180     static void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef, const void*);
181     void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef);
182
183     static void unavailablePluginButtonClicked(WKPageRef, WKPluginUnavailabilityReason, WKDictionaryRef, const void*);
184
185     static bool canAuthenticateAgainstProtectionSpace(WKPageRef, WKProtectionSpaceRef, const void *clientInfo);
186
187     static void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef, const void *clientInfo);
188     void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef);
189
190     static void decidePolicyForNavigationAction(WKPageRef, WKNavigationActionRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
191     void decidePolicyForNavigationAction(WKFramePolicyListenerRef);
192
193     static void decidePolicyForNavigationResponse(WKPageRef, WKNavigationResponseRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
194     void decidePolicyForNavigationResponse(WKNavigationResponseRef, WKFramePolicyListenerRef);
195
196     // WKContextHistoryClient
197     static void didNavigateWithNavigationData(WKContextRef, WKPageRef, WKNavigationDataRef, WKFrameRef, const void*);
198     void didNavigateWithNavigationData(WKNavigationDataRef, WKFrameRef);
199
200     static void didPerformClientRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*);
201     void didPerformClientRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef);
202
203     static void didPerformServerRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*);
204     void didPerformServerRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef);
205
206     static void didUpdateHistoryTitle(WKContextRef, WKPageRef, WKStringRef title, WKURLRef, WKFrameRef, const void*);
207     void didUpdateHistoryTitle(WKStringRef title, WKURLRef, WKFrameRef);
208
209     static WKPageRef createOtherPage(WKPageRef oldPage, WKURLRequestRef, WKDictionaryRef, WKEventModifiers, WKEventMouseButton, const void*);
210
211     static void runModal(WKPageRef, const void* clientInfo);
212     static void runModal(PlatformWebView*);
213
214     static const char* libraryPathForTesting();
215     static const char* platformLibraryPathForTesting();
216
217     std::unique_ptr<TestInvocation> m_currentInvocation;
218
219     bool m_verbose;
220     bool m_printSeparators;
221     bool m_usingServerMode;
222     bool m_gcBetweenTests;
223     bool m_shouldDumpPixelsForAllTests;
224     std::vector<std::string> m_paths;
225     std::vector<std::string> m_allowedHosts;
226     WKRetainPtr<WKStringRef> m_injectedBundlePath;
227     WKRetainPtr<WKStringRef> m_testPluginDirectory;
228
229     WebNotificationProvider m_webNotificationProvider;
230
231     std::unique_ptr<PlatformWebView> m_mainWebView;
232     WKRetainPtr<WKContextRef> m_context;
233     WKRetainPtr<WKPageGroupRef> m_pageGroup;
234
235     enum State {
236         Initial,
237         Resetting,
238         RunningTest
239     };
240     State m_state;
241     bool m_doneResetting;
242
243     bool m_useWaitToDumpWatchdogTimer;
244     bool m_forceNoTimeout;
245
246     bool m_didPrintWebProcessCrashedMessage;
247     bool m_shouldExitWhenWebProcessCrashes;
248     
249     bool m_beforeUnloadReturnValue;
250
251     std::unique_ptr<GeolocationProviderMock> m_geolocationProvider;
252     Vector<WKRetainPtr<WKGeolocationPermissionRequestRef> > m_geolocationPermissionRequests;
253     bool m_isGeolocationPermissionSet;
254     bool m_isGeolocationPermissionAllowed;
255
256     Vector<WKRetainPtr<WKUserMediaPermissionRequestRef>> m_userMediaPermissionRequests;
257     bool m_isUserMediaPermissionSet;
258     bool m_isUserMediaPermissionAllowed;
259
260     bool m_policyDelegateEnabled;
261     bool m_policyDelegatePermissive;
262
263     bool m_handlesAuthenticationChallenges;
264     String m_authenticationUsername;
265     String m_authenticationPassword;
266
267     bool m_shouldBlockAllPlugins;
268
269     bool m_forceComplexText;
270     bool m_shouldUseAcceleratedDrawing;
271     bool m_shouldUseRemoteLayerTree;
272
273     bool m_shouldLogHistoryClientCallbacks;
274     bool m_shouldShowWebView;
275
276     std::unique_ptr<EventSenderProxy> m_eventSenderProxy;
277
278     WorkQueueManager m_workQueueManager;
279 };
280
281 } // namespace WTR
282
283 #endif // TestController_h