2
* Copyright (C) 2010, 2011, 2012 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.
29
#include "JSWrappable.h"
30
#include <JavaScriptCore/JSRetainPtr.h>
31
#include <WebKit2/WKBundleScriptWorld.h>
32
#include <WebKit2/WKRetainPtr.h>
34
#include <wtf/PassRefPtr.h>
37
#include <wtf/RetainPtr.h>
38
#include <CoreFoundation/CFRunLoop.h>
39
typedef RetainPtr<CFRunLoopTimerRef> PlatformTimerRef;
41
typedef UINT_PTR PlatformTimerRef;
44
typedef QTimer PlatformTimerRef;
46
typedef unsigned int PlatformTimerRef;
48
typedef struct _Ecore_Timer Ecore_Timer;
49
typedef Ecore_Timer* PlatformTimerRef;
54
class TestRunner : public JSWrappable {
56
static PassRefPtr<TestRunner> create();
57
virtual ~TestRunner();
60
virtual JSClassRef wrapperClass();
62
void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
65
void dumpAsText(bool dumpPixels);
66
void waitForPolicyDelegate();
67
void dumpChildFramesAsText() { m_whatToDump = AllFramesText; }
73
void dumpBackForwardList() { m_shouldDumpBackForwardListsForAllWindows = true; }
74
void dumpChildFrameScrollPositions() { m_shouldDumpAllFrameScrollPositions = true; }
75
void dumpEditingCallbacks() { m_dumpEditingCallbacks = true; }
76
void dumpSelectionRect() { m_dumpSelectionRect = true; }
77
void dumpStatusCallbacks() { m_dumpStatusCallbacks = true; }
78
void dumpTitleChanges() { m_dumpTitleChanges = true; }
79
void dumpFullScreenCallbacks() { m_dumpFullScreenCallbacks = true; }
80
void dumpFrameLoadCallbacks() { setShouldDumpFrameLoadCallbacks(true); }
81
void dumpProgressFinishedCallback() { setShouldDumpProgressFinishedCallback(true); }
82
void dumpResourceLoadCallbacks() { m_dumpResourceLoadCallbacks = true; }
83
void dumpResourceResponseMIMETypes() { m_dumpResourceResponseMIMETypes = true; }
84
void dumpWillCacheResponse() { m_dumpWillCacheResponse = true; }
85
void dumpApplicationCacheDelegateCallbacks() { m_dumpApplicationCacheDelegateCallbacks = true; }
86
void dumpDatabaseCallbacks() { m_dumpDatabaseCallbacks = true; }
88
void setShouldDumpFrameLoadCallbacks(bool value) { m_dumpFrameLoadCallbacks = value; }
89
void setShouldDumpProgressFinishedCallback(bool value) { m_dumpProgressFinishedCallback = value; }
92
void keepWebHistory();
93
void setAcceptsEditing(bool value) { m_shouldAllowEditing = value; }
94
void setCanOpenWindows(bool);
95
void setCloseRemainingWindowsWhenComplete(bool value) { m_shouldCloseExtraWindows = value; }
96
void setXSSAuditorEnabled(bool);
97
void setAllowUniversalAccessFromFileURLs(bool);
98
void setAllowFileAccessFromFileURLs(bool);
99
void setFrameFlatteningEnabled(bool);
100
void setPluginsEnabled(bool);
101
void setJavaScriptCanAccessClipboard(bool);
102
void setPrivateBrowsingEnabled(bool);
103
void setPopupBlockingEnabled(bool);
104
void setAuthorAndUserStylesEnabled(bool);
105
void setCustomPolicyDelegate(bool enabled, bool permissive = false);
106
void addOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains);
107
void removeOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains);
108
void setUserStyleSheetEnabled(bool);
109
void setUserStyleSheetLocation(JSStringRef);
110
void setMinimumTimerInterval(double seconds); // Interval specified in seconds.
111
void setSpatialNavigationEnabled(bool);
112
void setTabKeyCyclesThroughElements(bool);
113
void setSerializeHTTPLoads();
114
void dispatchPendingLoadRequests();
115
void setCacheModel(int);
117
// Special DOM functions.
118
JSValueRef computedStyleIncludingVisitedInfo(JSValueRef element);
119
void clearBackForwardList();
120
void execCommand(JSStringRef name, JSStringRef argument);
121
bool isCommandEnabled(JSStringRef name);
122
JSRetainPtr<JSStringRef> markerTextForListItem(JSValueRef element);
123
unsigned windowCount();
126
void testRepaint() { m_testRepaint = true; }
127
void repaintSweepHorizontally() { m_testRepaintSweepHorizontally = true; }
130
// Animation testing.
131
unsigned numberOfActiveAnimations() const;
132
bool pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId);
133
bool pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId);
134
void suspendAnimations();
136
// UserContent testing.
137
void addUserScript(JSStringRef source, bool runAtStart, bool allFrames);
138
void addUserStyleSheet(JSStringRef source, bool allFrames);
140
// Text search testing.
141
bool findString(JSStringRef, JSValueRef optionsArray);
144
void clearAllDatabases();
145
void setDatabaseQuota(uint64_t);
146
JSRetainPtr<JSStringRef> pathToLocalResource(JSStringRef);
149
void clearAllApplicationCaches();
150
void clearApplicationCacheForOrigin(JSStringRef origin);
151
void setAppCacheMaximumSize(uint64_t);
152
long long applicationCacheDiskUsageForOrigin(JSStringRef origin);
153
void setApplicationCacheOriginQuota(unsigned long long);
154
void disallowIncreaseForApplicationCacheQuota();
155
bool shouldDisallowIncreaseForApplicationCacheQuota() { return m_disallowIncreaseForApplicationCacheQuota; }
156
JSValueRef originsWithApplicationCache();
159
bool isPageBoxVisible(int pageIndex);
161
void setValueForUser(JSContextRef, JSValueRef element, JSStringRef value);
163
enum WhatToDump { RenderTree, MainFrameText, AllFramesText };
164
WhatToDump whatToDump() const { return m_whatToDump; }
166
bool shouldDumpAllFrameScrollPositions() const { return m_shouldDumpAllFrameScrollPositions; }
167
bool shouldDumpBackForwardListsForAllWindows() const { return m_shouldDumpBackForwardListsForAllWindows; }
168
bool shouldDumpEditingCallbacks() const { return m_dumpEditingCallbacks; }
169
bool shouldDumpMainFrameScrollPosition() const { return m_whatToDump == RenderTree; }
170
bool shouldDumpStatusCallbacks() const { return m_dumpStatusCallbacks; }
171
bool shouldDumpTitleChanges() const { return m_dumpTitleChanges; }
172
bool shouldDumpPixels() const { return m_dumpPixels; }
173
bool shouldDumpFullScreenCallbacks() const { return m_dumpFullScreenCallbacks; }
174
bool shouldDumpFrameLoadCallbacks() const { return m_dumpFrameLoadCallbacks; }
175
bool shouldDumpProgressFinishedCallback() const { return m_dumpProgressFinishedCallback; }
176
bool shouldDumpResourceLoadCallbacks() const { return m_dumpResourceLoadCallbacks; }
177
bool shouldDumpResourceResponseMIMETypes() const { return m_dumpResourceResponseMIMETypes; }
178
bool shouldDumpWillCacheResponse() const { return m_dumpWillCacheResponse; }
179
bool shouldDumpApplicationCacheDelegateCallbacks() const { return m_dumpApplicationCacheDelegateCallbacks; }
180
bool shouldDumpDatabaseCallbacks() const { return m_dumpDatabaseCallbacks; }
181
bool shouldDumpSelectionRect() const { return m_dumpSelectionRect; }
183
bool isPolicyDelegateEnabled() const { return m_policyDelegateEnabled; }
184
bool isPolicyDelegatePermissive() const { return m_policyDelegatePermissive; }
186
bool waitToDump() const { return m_waitToDump; }
187
void waitToDumpWatchdogTimerFired();
188
void invalidateWaitToDumpWatchdogTimer();
190
bool shouldAllowEditing() const { return m_shouldAllowEditing; }
192
bool shouldCloseExtraWindowsAfterRunningTest() const { return m_shouldCloseExtraWindows; }
194
void evaluateScriptInIsolatedWorld(JSContextRef, unsigned worldID, JSStringRef script);
195
static unsigned worldIDForWorld(WKBundleScriptWorldRef);
197
void showWebInspector();
198
void closeWebInspector();
199
void evaluateInWebInspector(long callId, JSStringRef script);
201
void setPOSIXLocale(JSStringRef);
203
bool willSendRequestReturnsNull() const { return m_willSendRequestReturnsNull; }
204
void setWillSendRequestReturnsNull(bool f) { m_willSendRequestReturnsNull = f; }
205
bool willSendRequestReturnsNullOnRedirect() const { return m_willSendRequestReturnsNullOnRedirect; }
206
void setWillSendRequestReturnsNullOnRedirect(bool f) { m_willSendRequestReturnsNullOnRedirect = f; }
208
void setTextDirection(JSStringRef);
210
void setShouldStayOnPageAfterHandlingBeforeUnload(bool);
212
void setDefersLoading(bool);
214
void setStopProvisionalFrameLoads() { m_shouldStopProvisionalFrameLoads = true; }
215
bool shouldStopProvisionalFrameLoads() const { return m_shouldStopProvisionalFrameLoads; }
217
bool globalFlag() const { return m_globalFlag; }
218
void setGlobalFlag(bool value) { m_globalFlag = value; }
220
unsigned workerThreadCount();
222
void addChromeInputField(JSValueRef);
223
void removeChromeInputField(JSValueRef);
224
void focusWebView(JSValueRef);
225
void setBackingScaleFactor(double, JSValueRef);
227
void setWindowIsKey(bool);
229
void callAddChromeInputFieldCallback();
230
void callRemoveChromeInputFieldCallback();
231
void callFocusWebViewCallback();
232
void callSetBackingScaleFactorCallback();
234
void overridePreference(JSStringRef preference, JSStringRef value);
236
// Web intents testing.
237
void sendWebIntentResponse(JSStringRef reply);
238
void deliverWebIntent(JSStringRef action, JSStringRef type, JSStringRef data);
241
void setAlwaysAcceptCookies(bool);
243
// Custom full screen behavior.
244
void setHasCustomFullScreenBehavior(bool value) { m_customFullScreenBehavior = value; }
245
bool hasCustomFullScreenBehavior() const { return m_customFullScreenBehavior; }
247
// Web notifications.
248
void grantWebNotificationPermission(JSStringRef origin);
249
void denyWebNotificationPermission(JSStringRef origin);
250
void removeAllWebNotificationPermissions();
251
void simulateWebNotificationClick(JSValueRef notification);
254
void setGeolocationPermission(bool);
255
void setMockGeolocationPosition(double latitude, double longitude, double accuracy, JSValueRef altitude, JSValueRef altitudeAccuracy, JSValueRef heading, JSValueRef speed);
256
void setMockGeolocationPositionUnavailableError(JSStringRef message);
258
JSRetainPtr<JSStringRef> platformName();
260
void setPageVisibility(JSStringRef state);
261
void resetPageVisibility();
263
bool callShouldCloseOnWebView();
266
void queueBackNavigation(unsigned howFarBackward);
267
void queueForwardNavigation(unsigned howFarForward);
268
void queueLoad(JSStringRef url, JSStringRef target);
269
void queueLoadHTMLString(JSStringRef content, JSStringRef baseURL, JSStringRef unreachableURL);
271
void queueLoadingScript(JSStringRef script);
272
void queueNonLoadingScript(JSStringRef script);
275
static const double waitToDumpWatchdogTimerInterval;
279
void platformInitialize();
280
void initializeWaitToDumpWatchdogTimerIfNeeded();
282
WhatToDump m_whatToDump;
283
bool m_shouldDumpAllFrameScrollPositions;
284
bool m_shouldDumpBackForwardListsForAllWindows;
286
bool m_shouldAllowEditing;
287
bool m_shouldCloseExtraWindows;
289
bool m_dumpEditingCallbacks;
290
bool m_dumpStatusCallbacks;
291
bool m_dumpTitleChanges;
293
bool m_dumpSelectionRect;
294
bool m_dumpFullScreenCallbacks;
295
bool m_dumpFrameLoadCallbacks;
296
bool m_dumpProgressFinishedCallback;
297
bool m_dumpResourceLoadCallbacks;
298
bool m_dumpResourceResponseMIMETypes;
299
bool m_dumpWillCacheResponse;
300
bool m_dumpApplicationCacheDelegateCallbacks;
301
bool m_dumpDatabaseCallbacks;
302
bool m_disallowIncreaseForApplicationCacheQuota;
303
bool m_waitToDump; // True if waitUntilDone() has been called, but notifyDone() has not yet been called.
305
bool m_testRepaintSweepHorizontally;
307
bool m_willSendRequestReturnsNull;
308
bool m_willSendRequestReturnsNullOnRedirect;
309
bool m_shouldStopProvisionalFrameLoads;
311
bool m_policyDelegateEnabled;
312
bool m_policyDelegatePermissive;
315
bool m_customFullScreenBehavior;
317
bool m_userStyleSheetEnabled;
318
WKRetainPtr<WKStringRef> m_userStyleSheetLocation;
320
PlatformTimerRef m_waitToDumpWatchdogTimer;
325
#endif // TestRunner_h