REGRESSION (r129478-r129480): http/tests/loading/text-content-type-with-binary-extens...
[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 <GeolocationProviderMock.h>
31 #include <WebKit2/WKRetainPtr.h>
32 #include <string>
33 #include <vector>
34 #include <wtf/OwnPtr.h>
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& shared();
47
48     TestController(int argc, const char* argv[]);
49     ~TestController();
50
51     bool verbose() const { return m_verbose; }
52
53     WKStringRef injectedBundlePath() { return m_injectedBundlePath.get(); }
54     WKStringRef testPluginDirectory() { return m_testPluginDirectory.get(); }
55
56     PlatformWebView* mainWebView() { return m_mainWebView.get(); }
57     WKContextRef context() { return m_context.get(); }
58
59     // Runs the run loop until `done` is true or the timeout elapses.
60     enum TimeoutDuration { ShortTimeout, LongTimeout, NoTimeout };
61     bool useWaitToDumpWatchdogTimer() { return m_useWaitToDumpWatchdogTimer; }
62     void runUntil(bool& done, TimeoutDuration);
63     void notifyDone();
64     
65     bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
66     void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
67
68     void simulateWebNotificationClick(uint64_t notificationID);
69
70     // Geolocation.
71     void setGeolocationPermission(bool);
72     void setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed);
73     void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage);
74     void handleGeolocationPermissionRequest(WKGeolocationPermissionRequestRef);
75
76     // Policy delegate.
77     void setCustomPolicyDelegate(bool enabled, bool permissive);
78
79     bool resetStateToConsistentValues();
80
81 private:
82     void initialize(int argc, const char* argv[]);
83     void run();
84
85     void runTestingServerLoop();
86     bool runTest(const char* pathOrURL);
87
88     void platformInitialize();
89     void platformInitializeContext();
90     void platformRunUntil(bool& done, double timeout);
91     void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
92     void initializeInjectedBundlePath();
93     void initializeTestPluginDirectory();
94
95     void decidePolicyForGeolocationPermissionRequestIfPossible();
96
97     // WKContextInjectedBundleClient
98     static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
99     static void didReceiveSynchronousMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
100     void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
101     WKRetainPtr<WKTypeRef> didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
102
103     // WKPageLoaderClient
104     static void didCommitLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
105     void didCommitLoadForFrame(WKPageRef, WKFrameRef);
106
107     static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
108     void didFinishLoadForFrame(WKPageRef, WKFrameRef);
109
110     static void processDidCrash(WKPageRef, const void* clientInfo);
111     void processDidCrash();
112
113     static void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef, const void*);
114     void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef);
115
116     // WKPagePolicyClient
117     static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
118     void decidePolicyForNavigationAction(WKFramePolicyListenerRef);
119
120     static void decidePolicyForResponse(WKPageRef, WKFrameRef, WKURLResponseRef, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
121     void decidePolicyForResponse(WKFramePolicyListenerRef);
122
123     static WKPageRef createOtherPage(WKPageRef oldPage, WKURLRequestRef, WKDictionaryRef, WKEventModifiers, WKEventMouseButton, const void*);
124
125     static void runModal(WKPageRef, const void* clientInfo);
126     static void runModal(PlatformWebView*);
127
128     static const char* libraryPathForTesting();
129     static const char* platformLibraryPathForTesting();
130
131     OwnPtr<TestInvocation> m_currentInvocation;
132
133     bool m_verbose;
134     bool m_printSeparators;
135     bool m_usingServerMode;
136     bool m_gcBetweenTests;
137     std::vector<std::string> m_paths;
138     WKRetainPtr<WKStringRef> m_injectedBundlePath;
139     WKRetainPtr<WKStringRef> m_testPluginDirectory;
140
141     WebNotificationProvider m_webNotificationProvider;
142
143     OwnPtr<PlatformWebView> m_mainWebView;
144     WKRetainPtr<WKContextRef> m_context;
145     WKRetainPtr<WKPageGroupRef> m_pageGroup;
146
147     enum State {
148         Initial,
149         Resetting,
150         RunningTest
151     };
152     State m_state;
153     bool m_doneResetting;
154
155     double m_longTimeout;
156     double m_shortTimeout;
157     double m_noTimeout;
158     bool m_useWaitToDumpWatchdogTimer;
159     bool m_forceNoTimeout;
160
161     bool m_didPrintWebProcessCrashedMessage;
162     bool m_shouldExitWhenWebProcessCrashes;
163     
164     bool m_beforeUnloadReturnValue;
165
166     OwnPtr<GeolocationProviderMock> m_geolocationProvider;
167     Vector<WKRetainPtr<WKGeolocationPermissionRequestRef> > m_geolocationPermissionRequests;
168     bool m_isGeolocationPermissionSet;
169     bool m_isGeolocationPermissionAllowed;
170
171     bool m_policyDelegateEnabled;
172     bool m_policyDelegatePermissive;
173
174     EventSenderProxy* m_eventSenderProxy;
175 };
176
177 } // namespace WTR
178
179 #endif // TestController_h