WebKitTestRunner needs support for setHandlesAuthenticationChallenges
[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 "WebNotificationProvider.h"
30 #include "WorkQueueManager.h"
31 #include <GeolocationProviderMock.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     TestController(int argc, const char* argv[]);
50     ~TestController();
51
52     bool verbose() const { return m_verbose; }
53
54     WKStringRef injectedBundlePath() { return m_injectedBundlePath.get(); }
55     WKStringRef testPluginDirectory() { return m_testPluginDirectory.get(); }
56
57     PlatformWebView* mainWebView() { return m_mainWebView.get(); }
58     WKContextRef context() { return m_context.get(); }
59
60     void ensureViewSupportsOptions(WKDictionaryRef options);
61     
62     // Runs the run loop until `done` is true or the timeout elapses.
63     enum TimeoutDuration { ShortTimeout, LongTimeout, NoTimeout };
64     bool useWaitToDumpWatchdogTimer() { return m_useWaitToDumpWatchdogTimer; }
65     void runUntil(bool& done, TimeoutDuration);
66     void notifyDone();
67     
68     bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
69     void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
70
71     void simulateWebNotificationClick(uint64_t notificationID);
72
73     // Geolocation.
74     void setGeolocationPermission(bool);
75     void setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed);
76     void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage);
77     void handleGeolocationPermissionRequest(WKGeolocationPermissionRequestRef);
78
79     // Policy delegate.
80     void setCustomPolicyDelegate(bool enabled, bool permissive);
81
82     bool resetStateToConsistentValues();
83
84     WorkQueueManager& workQueueManager() { return m_workQueueManager; }
85
86     void setHandlesAuthenticationChallenges(bool value) { m_handlesAuthenticationChallenges = value; }
87     void setAuthenticationUsername(String username) { m_authenticationUsername = username; }
88     void setAuthenticationPassword(String password) { m_authenticationPassword = password; }
89
90 private:
91     void initialize(int argc, const char* argv[]);
92     void createWebViewWithOptions(WKDictionaryRef);
93     void run();
94
95     void runTestingServerLoop();
96     bool runTest(const char* pathOrURL);
97
98     void platformInitialize();
99     void platformDestroy();
100     void platformInitializeContext();
101     void platformRunUntil(bool& done, double timeout);
102     void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
103     void initializeInjectedBundlePath();
104     void initializeTestPluginDirectory();
105
106     void decidePolicyForGeolocationPermissionRequestIfPossible();
107
108     // WKContextInjectedBundleClient
109     static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
110     static void didReceiveSynchronousMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
111     void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
112     WKRetainPtr<WKTypeRef> didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
113
114     // WKPageLoaderClient
115     static void didCommitLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
116     void didCommitLoadForFrame(WKPageRef, WKFrameRef);
117
118     static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
119     void didFinishLoadForFrame(WKPageRef, WKFrameRef);
120
121     static void processDidCrash(WKPageRef, const void* clientInfo);
122     void processDidCrash();
123
124     static void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef, const void*);
125     void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef);
126
127     static void unavailablePluginButtonClicked(WKPageRef, WKPluginUnavailabilityReason, WKStringRef, WKStringRef, WKStringRef, const void*);
128
129     static void didReceiveAuthenticationChallengeInFrame(WKPageRef, WKFrameRef, WKAuthenticationChallengeRef, const void *clientInfo);
130     void didReceiveAuthenticationChallengeInFrame(WKPageRef, WKFrameRef, WKAuthenticationChallengeRef);
131
132     // WKPagePolicyClient
133     static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
134     void decidePolicyForNavigationAction(WKFramePolicyListenerRef);
135
136     static void decidePolicyForResponse(WKPageRef, WKFrameRef, WKURLResponseRef, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
137     void decidePolicyForResponse(WKFrameRef, WKURLResponseRef, WKFramePolicyListenerRef);
138
139     static WKPageRef createOtherPage(WKPageRef oldPage, WKURLRequestRef, WKDictionaryRef, WKEventModifiers, WKEventMouseButton, const void*);
140
141     static void runModal(WKPageRef, const void* clientInfo);
142     static void runModal(PlatformWebView*);
143
144     static const char* libraryPathForTesting();
145     static const char* platformLibraryPathForTesting();
146
147     OwnPtr<TestInvocation> m_currentInvocation;
148
149     bool m_verbose;
150     bool m_printSeparators;
151     bool m_usingServerMode;
152     bool m_gcBetweenTests;
153     bool m_shouldDumpPixelsForAllTests;
154     std::vector<std::string> m_paths;
155     WKRetainPtr<WKStringRef> m_injectedBundlePath;
156     WKRetainPtr<WKStringRef> m_testPluginDirectory;
157
158     WebNotificationProvider m_webNotificationProvider;
159
160     OwnPtr<PlatformWebView> m_mainWebView;
161     WKRetainPtr<WKContextRef> m_context;
162     WKRetainPtr<WKPageGroupRef> m_pageGroup;
163
164     enum State {
165         Initial,
166         Resetting,
167         RunningTest
168     };
169     State m_state;
170     bool m_doneResetting;
171
172     double m_longTimeout;
173     double m_shortTimeout;
174     double m_noTimeout;
175     bool m_useWaitToDumpWatchdogTimer;
176     bool m_forceNoTimeout;
177
178     bool m_didPrintWebProcessCrashedMessage;
179     bool m_shouldExitWhenWebProcessCrashes;
180     
181     bool m_beforeUnloadReturnValue;
182
183     OwnPtr<GeolocationProviderMock> m_geolocationProvider;
184     Vector<WKRetainPtr<WKGeolocationPermissionRequestRef> > m_geolocationPermissionRequests;
185     bool m_isGeolocationPermissionSet;
186     bool m_isGeolocationPermissionAllowed;
187
188     bool m_policyDelegateEnabled;
189     bool m_policyDelegatePermissive;
190
191     bool m_handlesAuthenticationChallenges;
192     String m_authenticationUsername;
193     String m_authenticationPassword;
194
195 #if PLATFORM(MAC) || PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
196     OwnPtr<EventSenderProxy> m_eventSenderProxy;
197 #endif
198
199 #if PLATFORM(QT)
200     class RunLoop;
201     RunLoop* m_runLoop;
202 #endif
203
204     WorkQueueManager m_workQueueManager;
205 };
206
207 } // namespace WTR
208
209 #endif // TestController_h