~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010, 2011, 2012 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 TestRunner_h
 
27
#define TestRunner_h
 
28
 
 
29
#include "JSWrappable.h"
 
30
#include <JavaScriptCore/JSRetainPtr.h>
 
31
#include <WebKit2/WKBundleScriptWorld.h>
 
32
#include <WebKit2/WKRetainPtr.h>
 
33
#include <string>
 
34
#include <wtf/PassRefPtr.h>
 
35
 
 
36
#if PLATFORM(MAC)
 
37
#include <wtf/RetainPtr.h>
 
38
#include <CoreFoundation/CFRunLoop.h>
 
39
typedef RetainPtr<CFRunLoopTimerRef> PlatformTimerRef;
 
40
#elif PLATFORM(WIN)
 
41
typedef UINT_PTR PlatformTimerRef;
 
42
#elif PLATFORM(QT)
 
43
#include <QTimer>
 
44
typedef QTimer PlatformTimerRef;
 
45
#elif PLATFORM(GTK)
 
46
typedef unsigned int PlatformTimerRef;
 
47
#elif PLATFORM(EFL)
 
48
typedef struct _Ecore_Timer Ecore_Timer;
 
49
typedef Ecore_Timer* PlatformTimerRef;
 
50
#endif
 
51
 
 
52
namespace WTR {
 
53
 
 
54
class TestRunner : public JSWrappable {
 
55
public:
 
56
    static PassRefPtr<TestRunner> create();
 
57
    virtual ~TestRunner();
 
58
 
 
59
    // JSWrappable
 
60
    virtual JSClassRef wrapperClass();
 
61
 
 
62
    void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
 
63
 
 
64
    // The basics.
 
65
    void dumpAsText(bool dumpPixels);
 
66
    void waitForPolicyDelegate();
 
67
    void dumpChildFramesAsText() { m_whatToDump = AllFramesText; }
 
68
    void waitUntilDone();
 
69
    void notifyDone();
 
70
    double preciseTime();
 
71
 
 
72
    // Other dumping.
 
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; }
 
87
 
 
88
    void setShouldDumpFrameLoadCallbacks(bool value) { m_dumpFrameLoadCallbacks = value; }
 
89
    void setShouldDumpProgressFinishedCallback(bool value) { m_dumpProgressFinishedCallback = value; }
 
90
 
 
91
    // Special options.
 
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);
 
116
 
 
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();
 
124
 
 
125
    // Repaint testing.
 
126
    void testRepaint() { m_testRepaint = true; }
 
127
    void repaintSweepHorizontally() { m_testRepaintSweepHorizontally = true; }
 
128
    void display();
 
129
 
 
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();
 
135
    
 
136
    // UserContent testing.
 
137
    void addUserScript(JSStringRef source, bool runAtStart, bool allFrames);
 
138
    void addUserStyleSheet(JSStringRef source, bool allFrames);
 
139
 
 
140
    // Text search testing.
 
141
    bool findString(JSStringRef, JSValueRef optionsArray);
 
142
 
 
143
    // Local storage
 
144
    void clearAllDatabases();
 
145
    void setDatabaseQuota(uint64_t);
 
146
    JSRetainPtr<JSStringRef> pathToLocalResource(JSStringRef);
 
147
 
 
148
    // Application Cache
 
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();
 
157
 
 
158
    // Printing
 
159
    bool isPageBoxVisible(int pageIndex);
 
160
 
 
161
    void setValueForUser(JSContextRef, JSValueRef element, JSStringRef value);
 
162
 
 
163
    enum WhatToDump { RenderTree, MainFrameText, AllFramesText };
 
164
    WhatToDump whatToDump() const { return m_whatToDump; }
 
165
 
 
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; }
 
182
 
 
183
    bool isPolicyDelegateEnabled() const { return m_policyDelegateEnabled; }
 
184
    bool isPolicyDelegatePermissive() const { return m_policyDelegatePermissive; }
 
185
 
 
186
    bool waitToDump() const { return m_waitToDump; }
 
187
    void waitToDumpWatchdogTimerFired();
 
188
    void invalidateWaitToDumpWatchdogTimer();
 
189
 
 
190
    bool shouldAllowEditing() const { return m_shouldAllowEditing; }
 
191
 
 
192
    bool shouldCloseExtraWindowsAfterRunningTest() const { return m_shouldCloseExtraWindows; }
 
193
 
 
194
    void evaluateScriptInIsolatedWorld(JSContextRef, unsigned worldID, JSStringRef script);
 
195
    static unsigned worldIDForWorld(WKBundleScriptWorldRef);
 
196
 
 
197
    void showWebInspector();
 
198
    void closeWebInspector();
 
199
    void evaluateInWebInspector(long callId, JSStringRef script);
 
200
 
 
201
    void setPOSIXLocale(JSStringRef);
 
202
 
 
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; }
 
207
 
 
208
    void setTextDirection(JSStringRef);
 
209
 
 
210
    void setShouldStayOnPageAfterHandlingBeforeUnload(bool);
 
211
 
 
212
    void setDefersLoading(bool);
 
213
 
 
214
    void setStopProvisionalFrameLoads() { m_shouldStopProvisionalFrameLoads = true; }
 
215
    bool shouldStopProvisionalFrameLoads() const { return m_shouldStopProvisionalFrameLoads; }
 
216
    
 
217
    bool globalFlag() const { return m_globalFlag; }
 
218
    void setGlobalFlag(bool value) { m_globalFlag = value; }
 
219
 
 
220
    unsigned workerThreadCount();
 
221
    
 
222
    void addChromeInputField(JSValueRef);
 
223
    void removeChromeInputField(JSValueRef);
 
224
    void focusWebView(JSValueRef);
 
225
    void setBackingScaleFactor(double, JSValueRef);
 
226
 
 
227
    void setWindowIsKey(bool);
 
228
 
 
229
    void callAddChromeInputFieldCallback();
 
230
    void callRemoveChromeInputFieldCallback();
 
231
    void callFocusWebViewCallback();
 
232
    void callSetBackingScaleFactorCallback();
 
233
 
 
234
    void overridePreference(JSStringRef preference, JSStringRef value);
 
235
 
 
236
    // Web intents testing.
 
237
    void sendWebIntentResponse(JSStringRef reply);
 
238
    void deliverWebIntent(JSStringRef action, JSStringRef type, JSStringRef data);
 
239
 
 
240
    // Cookies testing
 
241
    void setAlwaysAcceptCookies(bool);
 
242
 
 
243
    // Custom full screen behavior.
 
244
    void setHasCustomFullScreenBehavior(bool value) { m_customFullScreenBehavior = value; }
 
245
    bool hasCustomFullScreenBehavior() const { return m_customFullScreenBehavior; }
 
246
 
 
247
    // Web notifications.
 
248
    void grantWebNotificationPermission(JSStringRef origin);
 
249
    void denyWebNotificationPermission(JSStringRef origin);
 
250
    void removeAllWebNotificationPermissions();
 
251
    void simulateWebNotificationClick(JSValueRef notification);
 
252
 
 
253
    // Geolocation.
 
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);
 
257
 
 
258
    JSRetainPtr<JSStringRef> platformName();
 
259
 
 
260
    void setPageVisibility(JSStringRef state);
 
261
    void resetPageVisibility();
 
262
 
 
263
    bool callShouldCloseOnWebView();
 
264
 
 
265
    // Work queue.
 
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);
 
270
    void queueReload();
 
271
    void queueLoadingScript(JSStringRef script);
 
272
    void queueNonLoadingScript(JSStringRef script);
 
273
 
 
274
private:
 
275
    static const double waitToDumpWatchdogTimerInterval;
 
276
 
 
277
    TestRunner();
 
278
 
 
279
    void platformInitialize();
 
280
    void initializeWaitToDumpWatchdogTimerIfNeeded();
 
281
 
 
282
    WhatToDump m_whatToDump;
 
283
    bool m_shouldDumpAllFrameScrollPositions;
 
284
    bool m_shouldDumpBackForwardListsForAllWindows;
 
285
 
 
286
    bool m_shouldAllowEditing;
 
287
    bool m_shouldCloseExtraWindows;
 
288
 
 
289
    bool m_dumpEditingCallbacks;
 
290
    bool m_dumpStatusCallbacks;
 
291
    bool m_dumpTitleChanges;
 
292
    bool m_dumpPixels;
 
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.
 
304
    bool m_testRepaint;
 
305
    bool m_testRepaintSweepHorizontally;
 
306
 
 
307
    bool m_willSendRequestReturnsNull;
 
308
    bool m_willSendRequestReturnsNullOnRedirect;
 
309
    bool m_shouldStopProvisionalFrameLoads;
 
310
 
 
311
    bool m_policyDelegateEnabled;
 
312
    bool m_policyDelegatePermissive;
 
313
    
 
314
    bool m_globalFlag;
 
315
    bool m_customFullScreenBehavior;
 
316
 
 
317
    bool m_userStyleSheetEnabled;
 
318
    WKRetainPtr<WKStringRef> m_userStyleSheetLocation;
 
319
 
 
320
    PlatformTimerRef m_waitToDumpWatchdogTimer;
 
321
};
 
322
 
 
323
} // namespace WTR
 
324
 
 
325
#endif // TestRunner_h