ec26901b4c91e3cab4d77aefbc95758d0c9a53f9
[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 <WebKit2/WKRetainPtr.h>
33 #include <string>
34 #include <vector>
35 #include <wtf/OwnPtr.h>
36 #include <wtf/Vector.h>
37
38 namespace WTR {
39
40 class TestInvocation;
41 class PlatformWebView;
42 class EventSenderProxy;
43
44 // FIXME: Rename this TestRunner?
45 class TestController {
46 public:
47     static TestController& shared();
48
49     static const unsigned viewWidth;
50     static const unsigned viewHeight;
51
52     static const unsigned w3cSVGViewWidth;
53     static const unsigned w3cSVGViewHeight;
54
55     TestController(int argc, const char* argv[]);
56     ~TestController();
57
58     bool verbose() const { return m_verbose; }
59
60     WKStringRef injectedBundlePath() { return m_injectedBundlePath.get(); }
61     WKStringRef testPluginDirectory() { return m_testPluginDirectory.get(); }
62
63     PlatformWebView* mainWebView() { return m_mainWebView.get(); }
64     WKContextRef context() { return m_context.get(); }
65
66     EventSenderProxy* eventSenderProxy() { return m_eventSenderProxy.get(); }
67
68     void ensureViewSupportsOptions(WKDictionaryRef options);
69     bool shouldUseRemoteLayerTree() const { return m_shouldUseRemoteLayerTree; }
70     
71     // Runs the run loop until `done` is true or the timeout elapses.
72     enum TimeoutDuration { ShortTimeout, LongTimeout, NoTimeout, CustomTimeout };
73     bool useWaitToDumpWatchdogTimer() { return m_useWaitToDumpWatchdogTimer; }
74     void runUntil(bool& done, TimeoutDuration);
75     void notifyDone();
76
77     int getCustomTimeout();
78     
79     bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
80     void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
81
82     void simulateWebNotificationClick(uint64_t notificationID);
83
84     // Geolocation.
85     void setGeolocationPermission(bool);
86     void setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed);
87     void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage);
88     void handleGeolocationPermissionRequest(WKGeolocationPermissionRequestRef);
89
90     // Policy delegate.
91     void setCustomPolicyDelegate(bool enabled, bool permissive);
92
93     // Page Visibility.
94     void setHidden(bool);
95
96     bool resetStateToConsistentValues();
97     void resetPreferencesToConsistentValues();
98
99     WorkQueueManager& workQueueManager() { return m_workQueueManager; }
100
101     void setHandlesAuthenticationChallenges(bool value) { m_handlesAuthenticationChallenges = value; }
102     void setAuthenticationUsername(String username) { m_authenticationUsername = username; }
103     void setAuthenticationPassword(String password) { m_authenticationPassword = password; }
104
105     void setBlockAllPlugins(bool shouldBlock) { m_shouldBlockAllPlugins = shouldBlock; }
106
107 private:
108     void initialize(int argc, const char* argv[]);
109     void createWebViewWithOptions(WKDictionaryRef);
110     void run();
111
112     void runTestingServerLoop();
113     bool runTest(const char* pathOrURL);
114
115     void platformInitialize();
116     void platformDestroy();
117     void platformInitializeContext();
118     void platformRunUntil(bool& done, double timeout);
119     void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
120     void initializeInjectedBundlePath();
121     void initializeTestPluginDirectory();
122
123     void decidePolicyForGeolocationPermissionRequestIfPossible();
124
125     // WKContextInjectedBundleClient
126     static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
127     static void didReceiveSynchronousMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
128     void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
129     WKRetainPtr<WKTypeRef> didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
130
131     void didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef messageBodyDictionary, bool synchronous);
132
133     // WKPageLoaderClient
134     static void didCommitLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
135     void didCommitLoadForFrame(WKPageRef, WKFrameRef);
136
137     static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
138     void didFinishLoadForFrame(WKPageRef, WKFrameRef);
139
140     static void processDidCrash(WKPageRef, const void* clientInfo);
141     void processDidCrash();
142
143     static WKPluginLoadPolicy pluginLoadPolicy(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription, const void* clientInfo);
144     WKPluginLoadPolicy pluginLoadPolicy(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription);
145     
146
147     static void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef, const void*);
148     void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef);
149
150     static void unavailablePluginButtonClicked(WKPageRef, WKPluginUnavailabilityReason, WKDictionaryRef, const void*);
151
152     static void didReceiveAuthenticationChallengeInFrame(WKPageRef, WKFrameRef, WKAuthenticationChallengeRef, const void *clientInfo);
153     void didReceiveAuthenticationChallengeInFrame(WKPageRef, WKFrameRef, WKAuthenticationChallengeRef);
154
155     // WKPagePolicyClient
156     static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKFrameRef, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
157     void decidePolicyForNavigationAction(WKFramePolicyListenerRef);
158
159     static void decidePolicyForResponse(WKPageRef, WKFrameRef, WKURLResponseRef, WKURLRequestRef, bool canShowMIMEType, WKFramePolicyListenerRef, WKTypeRef, const void*);
160     void decidePolicyForResponse(WKFrameRef, WKURLResponseRef, WKFramePolicyListenerRef);
161
162     static WKPageRef createOtherPage(WKPageRef oldPage, WKURLRequestRef, WKDictionaryRef, WKEventModifiers, WKEventMouseButton, const void*);
163
164     static void runModal(WKPageRef, const void* clientInfo);
165     static void runModal(PlatformWebView*);
166
167     static const char* libraryPathForTesting();
168     static const char* platformLibraryPathForTesting();
169
170     OwnPtr<TestInvocation> m_currentInvocation;
171
172     bool m_verbose;
173     bool m_printSeparators;
174     bool m_usingServerMode;
175     bool m_gcBetweenTests;
176     bool m_shouldDumpPixelsForAllTests;
177     std::vector<std::string> m_paths;
178     WKRetainPtr<WKStringRef> m_injectedBundlePath;
179     WKRetainPtr<WKStringRef> m_testPluginDirectory;
180
181     WebNotificationProvider m_webNotificationProvider;
182
183     OwnPtr<PlatformWebView> m_mainWebView;
184     WKRetainPtr<WKContextRef> m_context;
185     WKRetainPtr<WKPageGroupRef> m_pageGroup;
186
187     enum State {
188         Initial,
189         Resetting,
190         RunningTest
191     };
192     State m_state;
193     bool m_doneResetting;
194
195     double m_longTimeout;
196     double m_shortTimeout;
197     double m_noTimeout;
198     bool m_useWaitToDumpWatchdogTimer;
199     bool m_forceNoTimeout;
200
201     int m_timeout;
202
203     bool m_didPrintWebProcessCrashedMessage;
204     bool m_shouldExitWhenWebProcessCrashes;
205     
206     bool m_beforeUnloadReturnValue;
207
208     OwnPtr<GeolocationProviderMock> m_geolocationProvider;
209     Vector<WKRetainPtr<WKGeolocationPermissionRequestRef> > m_geolocationPermissionRequests;
210     bool m_isGeolocationPermissionSet;
211     bool m_isGeolocationPermissionAllowed;
212
213     bool m_policyDelegateEnabled;
214     bool m_policyDelegatePermissive;
215
216     bool m_handlesAuthenticationChallenges;
217     String m_authenticationUsername;
218     String m_authenticationPassword;
219
220     bool m_shouldBlockAllPlugins;
221
222     bool m_forceComplexText;
223     bool m_shouldUseAcceleratedDrawing;
224     bool m_shouldUseRemoteLayerTree;
225
226     OwnPtr<EventSenderProxy> m_eventSenderProxy;
227
228     WorkQueueManager m_workQueueManager;
229 };
230
231 } // namespace WTR
232
233 #endif // TestController_h