2 * Copyright (C) 2010 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 "WebNotificationProvider.h"
30 #include <GeolocationProviderMock.h>
31 #include <WebKit2/WKRetainPtr.h>
34 #include <wtf/OwnPtr.h>
35 #include <wtf/Vector.h>
40 class PlatformWebView;
41 class EventSenderProxy;
43 // FIXME: Rename this TestRunner?
44 class TestController {
46 static TestController& shared();
48 TestController(int argc, const char* argv[]);
51 bool verbose() const { return m_verbose; }
53 WKStringRef injectedBundlePath() { return m_injectedBundlePath.get(); }
54 WKStringRef testPluginDirectory() { return m_testPluginDirectory.get(); }
56 PlatformWebView* mainWebView() { return m_mainWebView.get(); }
57 WKContextRef context() { return m_context.get(); }
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);
65 bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
66 void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
68 void simulateWebNotificationClick(uint64_t notificationID);
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);
77 void setCustomPolicyDelegate(bool enabled, bool permissive);
79 bool resetStateToConsistentValues();
82 void initialize(int argc, const char* argv[]);
85 void runTestingServerLoop();
86 bool runTest(const char* pathOrURL);
88 void platformInitialize();
89 void platformInitializeContext();
90 void platformRunUntil(bool& done, double timeout);
91 void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
92 void initializeInjectedBundlePath();
93 void initializeTestPluginDirectory();
95 void decidePolicyForGeolocationPermissionRequestIfPossible();
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);
103 // WKPageLoaderClient
104 static void didCommitLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
105 void didCommitLoadForFrame(WKPageRef, WKFrameRef);
107 static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
108 void didFinishLoadForFrame(WKPageRef, WKFrameRef);
110 static void processDidCrash(WKPageRef, const void* clientInfo);
111 void processDidCrash();
113 static void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef, const void*);
114 void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef);
116 // WKPagePolicyClient
117 static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
118 void decidePolicyForNavigationAction(WKFramePolicyListenerRef);
120 static void decidePolicyForResponse(WKPageRef, WKFrameRef, WKURLResponseRef, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
121 void decidePolicyForResponse(WKFramePolicyListenerRef);
123 static WKPageRef createOtherPage(WKPageRef oldPage, WKURLRequestRef, WKDictionaryRef, WKEventModifiers, WKEventMouseButton, const void*);
125 static void runModal(WKPageRef, const void* clientInfo);
126 static void runModal(PlatformWebView*);
128 static const char* libraryPathForTesting();
129 static const char* platformLibraryPathForTesting();
131 OwnPtr<TestInvocation> m_currentInvocation;
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;
141 WebNotificationProvider m_webNotificationProvider;
143 OwnPtr<PlatformWebView> m_mainWebView;
144 WKRetainPtr<WKContextRef> m_context;
145 WKRetainPtr<WKPageGroupRef> m_pageGroup;
153 bool m_doneResetting;
155 double m_longTimeout;
156 double m_shortTimeout;
158 bool m_useWaitToDumpWatchdogTimer;
159 bool m_forceNoTimeout;
161 bool m_didPrintWebProcessCrashedMessage;
162 bool m_shouldExitWhenWebProcessCrashes;
164 bool m_beforeUnloadReturnValue;
166 OwnPtr<GeolocationProviderMock> m_geolocationProvider;
167 Vector<WKRetainPtr<WKGeolocationPermissionRequestRef> > m_geolocationPermissionRequests;
168 bool m_isGeolocationPermissionSet;
169 bool m_isGeolocationPermissionAllowed;
171 bool m_policyDelegateEnabled;
172 bool m_policyDelegatePermissive;
174 EventSenderProxy* m_eventSenderProxy;
179 #endif // TestController_h