2 * Copyright (C) 2010, 2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef TestController_h
27 #define TestController_h
29 #include "GeolocationProviderMock.h"
30 #include "WebNotificationProvider.h"
31 #include "WorkQueueManager.h"
32 #include <WebKit/WKRetainPtr.h>
35 #include <wtf/Vector.h>
37 OBJC_CLASS WKWebViewConfiguration;
42 class PlatformWebView;
43 class EventSenderProxy;
46 // FIXME: Rename this TestRunner?
47 class TestController {
49 static TestController& singleton();
51 static const unsigned viewWidth;
52 static const unsigned viewHeight;
54 static const unsigned w3cSVGViewWidth;
55 static const unsigned w3cSVGViewHeight;
57 static const double shortTimeout;
58 static const double noTimeout;
60 TestController(int argc, const char* argv[]);
63 bool verbose() const { return m_verbose; }
65 WKStringRef injectedBundlePath() const { return m_injectedBundlePath.get(); }
66 WKStringRef testPluginDirectory() const { return m_testPluginDirectory.get(); }
68 PlatformWebView* mainWebView() { return m_mainWebView.get(); }
69 WKContextRef context() { return m_context.get(); }
71 EventSenderProxy* eventSenderProxy() { return m_eventSenderProxy.get(); }
73 bool shouldUseRemoteLayerTree() const { return m_shouldUseRemoteLayerTree; }
75 // Runs the run loop until `done` is true or the timeout elapses.
76 bool useWaitToDumpWatchdogTimer() { return m_useWaitToDumpWatchdogTimer; }
77 void runUntil(bool& done, double timeoutSeconds);
80 bool shouldShowWebView() const { return m_shouldShowWebView; }
82 void configureViewForTest(const TestInvocation&);
84 bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
85 void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
87 void simulateWebNotificationClick(uint64_t notificationID);
90 void setGeolocationPermission(bool);
91 void setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed);
92 void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage);
93 void handleGeolocationPermissionRequest(WKGeolocationPermissionRequestRef);
94 bool isGeolocationProviderActive() const;
97 void setUserMediaPermission(bool);
98 void handleUserMediaPermissionRequest(WKUserMediaPermissionRequestRef);
101 void setCustomPolicyDelegate(bool enabled, bool permissive);
104 void setHidden(bool);
106 bool resetStateToConsistentValues();
107 void resetPreferencesToConsistentValues();
109 void terminateWebContentProcess();
110 void reattachPageToWebProcess();
112 static const char* webProcessName();
113 static const char* networkProcessName();
115 WorkQueueManager& workQueueManager() { return m_workQueueManager; }
117 void setHandlesAuthenticationChallenges(bool value) { m_handlesAuthenticationChallenges = value; }
118 void setAuthenticationUsername(String username) { m_authenticationUsername = username; }
119 void setAuthenticationPassword(String password) { m_authenticationPassword = password; }
121 void setBlockAllPlugins(bool shouldBlock) { m_shouldBlockAllPlugins = shouldBlock; }
123 void setShouldLogHistoryClientCallbacks(bool shouldLog) { m_shouldLogHistoryClientCallbacks = shouldLog; }
125 bool isCurrentInvocation(TestInvocation* invocation) const { return invocation == m_currentInvocation.get(); }
127 void setShouldDecideNavigationPolicyAfterDelay(bool value) { m_shouldDecideNavigationPolicyAfterDelay = value; }
129 void setNavigationGesturesEnabled(bool value);
132 WKRetainPtr<WKPageConfigurationRef> generatePageConfiguration(WKContextConfigurationRef);
133 WKRetainPtr<WKContextConfigurationRef> generateContextConfiguration() const;
134 void initialize(int argc, const char* argv[]);
135 void createWebViewWithOptions(const TestOptions&);
138 void runTestingServerLoop();
139 bool runTest(const char* pathOrURL);
141 void platformInitialize();
142 void platformDestroy();
143 WKContextRef platformAdjustContext(WKContextRef, WKContextConfigurationRef);
144 void platformInitializeContext();
145 void platformCreateWebView(WKPageConfigurationRef, const TestOptions&);
146 static PlatformWebView* platformCreateOtherPage(PlatformWebView* parentView, WKPageConfigurationRef, const TestOptions&);
147 void platformResetPreferencesToConsistentValues();
148 void platformResetStateToConsistentValues();
150 void cocoaResetStateToConsistentValues();
152 void platformConfigureViewForTest(const TestInvocation&);
153 void platformWillRunTest(const TestInvocation&);
154 void platformRunUntil(bool& done, double timeout);
155 void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
156 WKPreferencesRef platformPreferences();
157 void initializeInjectedBundlePath();
158 void initializeTestPluginDirectory();
160 void ensureViewSupportsOptionsForTest(const TestInvocation&);
161 TestOptions testOptionsForTest(const TestInvocation&) const;
162 void updatePlatformSpecificTestOptionsForTest(TestOptions&, const TestInvocation&) const;
164 void updateWebViewSizeForTest(const TestInvocation&);
165 void updateWindowScaleForTest(PlatformWebView*, const TestInvocation&);
167 void decidePolicyForGeolocationPermissionRequestIfPossible();
168 void decidePolicyForUserMediaPermissionRequestIfPossible();
170 // WKContextInjectedBundleClient
171 static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
172 static void didReceiveSynchronousMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
174 // WKPageInjectedBundleClient
175 static void didReceivePageMessageFromInjectedBundle(WKPageRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
176 static void didReceiveSynchronousPageMessageFromInjectedBundle(WKPageRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
177 void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
178 WKRetainPtr<WKTypeRef> didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
180 void didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef messageBodyDictionary, bool synchronous);
183 static void networkProcessDidCrash(WKContextRef, const void*);
184 void networkProcessDidCrash();
186 // WKPageNavigationClient
187 static void didCommitNavigation(WKPageRef, WKNavigationRef, WKTypeRef userData, const void*);
188 void didCommitNavigation(WKPageRef, WKNavigationRef);
190 static void didFinishNavigation(WKPageRef, WKNavigationRef, WKTypeRef userData, const void*);
191 void didFinishNavigation(WKPageRef, WKNavigationRef);
193 static void processDidCrash(WKPageRef, const void* clientInfo);
194 void processDidCrash();
196 static void didBeginNavigationGesture(WKPageRef, const void*);
197 static void willEndNavigationGesture(WKPageRef, WKBackForwardListItemRef, const void*);
198 static void didEndNavigationGesture(WKPageRef, WKBackForwardListItemRef, const void*);
199 static void didRemoveNavigationGestureSnapshot(WKPageRef, const void*);
200 void didBeginNavigationGesture(WKPageRef);
201 void willEndNavigationGesture(WKPageRef, WKBackForwardListItemRef);
202 void didEndNavigationGesture(WKPageRef, WKBackForwardListItemRef);
203 void didRemoveNavigationGestureSnapshot(WKPageRef);
205 static WKPluginLoadPolicy decidePolicyForPluginLoad(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription, const void* clientInfo);
206 WKPluginLoadPolicy decidePolicyForPluginLoad(WKPageRef, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInformation, WKStringRef* unavailabilityDescription);
209 static void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef, const void*);
210 void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef);
212 static void unavailablePluginButtonClicked(WKPageRef, WKPluginUnavailabilityReason, WKDictionaryRef, const void*);
214 static bool canAuthenticateAgainstProtectionSpace(WKPageRef, WKProtectionSpaceRef, const void *clientInfo);
216 static void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef, const void *clientInfo);
217 void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef);
219 static void decidePolicyForNavigationAction(WKPageRef, WKNavigationActionRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
220 void decidePolicyForNavigationAction(WKFramePolicyListenerRef);
222 static void decidePolicyForNavigationResponse(WKPageRef, WKNavigationResponseRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
223 void decidePolicyForNavigationResponse(WKNavigationResponseRef, WKFramePolicyListenerRef);
225 // WKContextHistoryClient
226 static void didNavigateWithNavigationData(WKContextRef, WKPageRef, WKNavigationDataRef, WKFrameRef, const void*);
227 void didNavigateWithNavigationData(WKNavigationDataRef, WKFrameRef);
229 static void didPerformClientRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*);
230 void didPerformClientRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef);
232 static void didPerformServerRedirect(WKContextRef, WKPageRef, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void*);
233 void didPerformServerRedirect(WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef);
235 static void didUpdateHistoryTitle(WKContextRef, WKPageRef, WKStringRef title, WKURLRef, WKFrameRef, const void*);
236 void didUpdateHistoryTitle(WKStringRef title, WKURLRef, WKFrameRef);
238 static WKPageRef createOtherPage(WKPageRef, WKPageConfigurationRef, WKNavigationActionRef, WKWindowFeaturesRef, const void*);
240 static void runModal(WKPageRef, const void* clientInfo);
241 static void runModal(PlatformWebView*);
243 static const char* libraryPathForTesting();
244 static const char* platformLibraryPathForTesting();
246 std::unique_ptr<TestInvocation> m_currentInvocation;
249 bool m_printSeparators;
250 bool m_usingServerMode;
251 bool m_gcBetweenTests;
252 bool m_shouldDumpPixelsForAllTests;
253 std::vector<std::string> m_paths;
254 std::vector<std::string> m_allowedHosts;
255 WKRetainPtr<WKStringRef> m_injectedBundlePath;
256 WKRetainPtr<WKStringRef> m_testPluginDirectory;
258 WebNotificationProvider m_webNotificationProvider;
260 std::unique_ptr<PlatformWebView> m_mainWebView;
261 WKRetainPtr<WKContextRef> m_context;
262 WKRetainPtr<WKPageGroupRef> m_pageGroup;
270 bool m_doneResetting;
272 bool m_useWaitToDumpWatchdogTimer;
273 bool m_forceNoTimeout;
275 bool m_didPrintWebProcessCrashedMessage;
276 bool m_shouldExitWhenWebProcessCrashes;
278 bool m_beforeUnloadReturnValue;
280 std::unique_ptr<GeolocationProviderMock> m_geolocationProvider;
281 Vector<WKRetainPtr<WKGeolocationPermissionRequestRef> > m_geolocationPermissionRequests;
282 bool m_isGeolocationPermissionSet;
283 bool m_isGeolocationPermissionAllowed;
285 Vector<WKRetainPtr<WKUserMediaPermissionRequestRef>> m_userMediaPermissionRequests;
286 bool m_isUserMediaPermissionSet;
287 bool m_isUserMediaPermissionAllowed;
289 bool m_policyDelegateEnabled;
290 bool m_policyDelegatePermissive;
292 bool m_handlesAuthenticationChallenges;
293 String m_authenticationUsername;
294 String m_authenticationPassword;
296 bool m_shouldBlockAllPlugins;
298 bool m_forceComplexText;
299 bool m_shouldUseAcceleratedDrawing;
300 bool m_shouldUseRemoteLayerTree;
302 bool m_shouldLogHistoryClientCallbacks;
303 bool m_shouldShowWebView;
305 bool m_shouldDecideNavigationPolicyAfterDelay { false };
307 std::unique_ptr<EventSenderProxy> m_eventSenderProxy;
309 WorkQueueManager m_workQueueManager;
314 #endif // TestController_h