<https://webkit.org/b/42704> WebKitTestRunner needs to print history delegate information
[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     void setShouldLogHistoryClientCallbacks(bool shouldLog) { m_shouldLogHistoryClientCallbacks = shouldLog; }
108
109 private:
110     void initialize(int argc, const char* argv[]);
111     void createWebViewWithOptions(WKDictionaryRef);
112     void run();
113
114     void runTestingServerLoop();
115     bool runTest(const char* pathOrURL);
116
117     void platformInitialize();
118     void platformDestroy();
119     void platformInitializeContext();
120     void platformRunUntil(bool& done, double timeout);
121     void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
122     void initializeInjectedBundlePath();
123     void initializeTestPluginDirectory();
124
125     void decidePolicyForGeolocationPermissionRequestIfPossible();
126
127     // WKContextInjectedBundleClient
128     static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
129     static void didReceiveSynchronousMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
130     void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
131     WKRetainPtr<WKTypeRef> didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
132
133     void didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef messageBodyDictionary, bool synchronous);
134
135     // WKPageLoaderClient
136     static void didCommitLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
137     void didCommitLoadForFrame(WKPageRef, WKFrameRef);
138
139     static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
140     void didFinishLoadForFrame(WKPageRef, WKFrameRef);
141
142     static void processDidCrash(WKPageRef, const void* clientInfo);
143     void processDidCrash();
144
145     static WKPluginLoadPolicy pluginLoadPolicy(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription, const void* clientInfo);
146     WKPluginLoadPolicy pluginLoadPolicy(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription);
147     
148
149     static void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef, const void*);
150     void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef);
151
152     static void unavailablePluginButtonClicked(WKPageRef, WKPluginUnavailabilityReason, WKDictionaryRef, const void*);
153
154     static void didReceiveAuthenticationChallengeInFrame(WKPageRef, WKFrameRef, WKAuthenticationChallengeRef, const void *clientInfo);
155     void didReceiveAuthenticationChallengeInFrame(WKPageRef, WKFrameRef, WKAuthenticationChallengeRef);
156
157     // WKPagePolicyClient
158     static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKFrameRef, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
159     void decidePolicyForNavigationAction(WKFramePolicyListenerRef);
160
161     static void decidePolicyForResponse(WKPageRef, WKFrameRef, WKURLResponseRef, WKURLRequestRef, bool canShowMIMEType, WKFramePolicyListenerRef, WKTypeRef, const void*);
162     void decidePolicyForResponse(WKFrameRef, WKURLResponseRef, WKFramePolicyListenerRef);
163
164     // WKContextHistoryClient
165     static void didNavigateWithNavigationData(WKContextRef, WKPageRef, WKNavigationDataRef, WKFrameRef, const void*);
166     void didNavigateWithNavigationData(WKNavigationDataRef, WKFrameRef);
167
168     static void didPerformClientRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*);
169     void didPerformClientRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef);
170
171     static void didPerformServerRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*);
172     void didPerformServerRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef);
173
174     static void didUpdateHistoryTitle(WKContextRef, WKPageRef, WKStringRef title, WKURLRef, WKFrameRef, const void*);
175     void didUpdateHistoryTitle(WKStringRef title, WKURLRef, WKFrameRef);
176
177     static WKPageRef createOtherPage(WKPageRef oldPage, WKURLRequestRef, WKDictionaryRef, WKEventModifiers, WKEventMouseButton, const void*);
178
179     static void runModal(WKPageRef, const void* clientInfo);
180     static void runModal(PlatformWebView*);
181
182     static const char* libraryPathForTesting();
183     static const char* platformLibraryPathForTesting();
184
185     OwnPtr<TestInvocation> m_currentInvocation;
186
187     bool m_verbose;
188     bool m_printSeparators;
189     bool m_usingServerMode;
190     bool m_gcBetweenTests;
191     bool m_shouldDumpPixelsForAllTests;
192     std::vector<std::string> m_paths;
193     WKRetainPtr<WKStringRef> m_injectedBundlePath;
194     WKRetainPtr<WKStringRef> m_testPluginDirectory;
195
196     WebNotificationProvider m_webNotificationProvider;
197
198     OwnPtr<PlatformWebView> m_mainWebView;
199     WKRetainPtr<WKContextRef> m_context;
200     WKRetainPtr<WKPageGroupRef> m_pageGroup;
201
202     enum State {
203         Initial,
204         Resetting,
205         RunningTest
206     };
207     State m_state;
208     bool m_doneResetting;
209
210     double m_longTimeout;
211     double m_shortTimeout;
212     double m_noTimeout;
213     bool m_useWaitToDumpWatchdogTimer;
214     bool m_forceNoTimeout;
215
216     int m_timeout;
217
218     bool m_didPrintWebProcessCrashedMessage;
219     bool m_shouldExitWhenWebProcessCrashes;
220     
221     bool m_beforeUnloadReturnValue;
222
223     OwnPtr<GeolocationProviderMock> m_geolocationProvider;
224     Vector<WKRetainPtr<WKGeolocationPermissionRequestRef> > m_geolocationPermissionRequests;
225     bool m_isGeolocationPermissionSet;
226     bool m_isGeolocationPermissionAllowed;
227
228     bool m_policyDelegateEnabled;
229     bool m_policyDelegatePermissive;
230
231     bool m_handlesAuthenticationChallenges;
232     String m_authenticationUsername;
233     String m_authenticationPassword;
234
235     bool m_shouldBlockAllPlugins;
236
237     bool m_forceComplexText;
238     bool m_shouldUseAcceleratedDrawing;
239     bool m_shouldUseRemoteLayerTree;
240
241     bool m_shouldLogHistoryClientCallbacks;
242
243     OwnPtr<EventSenderProxy> m_eventSenderProxy;
244
245     WorkQueueManager m_workQueueManager;
246 };
247
248 } // namespace WTR
249
250 #endif // TestController_h