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 <WebKit/WKBundleScriptWorld.h>
32 #include <WebKit/WKRetainPtr.h>
34 #include <wtf/PassRefPtr.h>
37 #include <wtf/RetainPtr.h>
38 #include <CoreFoundation/CFRunLoop.h>
39 typedef RetainPtr<CFRunLoopTimerRef> PlatformTimerRef;
41 #include <wtf/gobject/GMainLoopSource.h>
42 typedef GMainLoopSource PlatformTimerRef;
44 typedef Ecore_Timer* PlatformTimerRef;
49 class TestRunner : public JSWrappable {
51 static PassRefPtr<TestRunner> create();
52 virtual ~TestRunner();
55 virtual JSClassRef wrapperClass();
57 void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
60 WKURLRef testURL() const { return m_testURL.get(); }
61 void setTestURL(WKURLRef url) { m_testURL = url; }
62 void dumpAsText(bool dumpPixels);
63 void waitForPolicyDelegate();
64 void dumpChildFramesAsText() { m_whatToDump = AllFramesText; }
70 void dumpBackForwardList() { m_shouldDumpBackForwardListsForAllWindows = true; }
71 void dumpChildFrameScrollPositions() { m_shouldDumpAllFrameScrollPositions = true; }
72 void dumpEditingCallbacks() { m_dumpEditingCallbacks = true; }
73 void dumpSelectionRect() { m_dumpSelectionRect = true; }
74 void dumpStatusCallbacks() { m_dumpStatusCallbacks = true; }
75 void dumpTitleChanges() { m_dumpTitleChanges = true; }
76 void dumpFullScreenCallbacks() { m_dumpFullScreenCallbacks = true; }
77 void dumpFrameLoadCallbacks() { setShouldDumpFrameLoadCallbacks(true); }
78 void dumpProgressFinishedCallback() { setShouldDumpProgressFinishedCallback(true); }
79 void dumpResourceLoadCallbacks() { m_dumpResourceLoadCallbacks = true; }
80 void dumpResourceResponseMIMETypes() { m_dumpResourceResponseMIMETypes = true; }
81 void dumpWillCacheResponse() { m_dumpWillCacheResponse = true; }
82 void dumpApplicationCacheDelegateCallbacks() { m_dumpApplicationCacheDelegateCallbacks = true; }
83 void dumpDatabaseCallbacks() { m_dumpDatabaseCallbacks = true; }
84 void dumpDOMAsWebArchive() { m_whatToDump = DOMAsWebArchive; }
86 void setShouldDumpFrameLoadCallbacks(bool value) { m_dumpFrameLoadCallbacks = value; }
87 void setShouldDumpProgressFinishedCallback(bool value) { m_dumpProgressFinishedCallback = value; }
90 void keepWebHistory();
91 void setAcceptsEditing(bool value) { m_shouldAllowEditing = value; }
92 void setCanOpenWindows(bool);
93 void setCloseRemainingWindowsWhenComplete(bool value) { m_shouldCloseExtraWindows = value; }
94 void setXSSAuditorEnabled(bool);
95 void setAllowUniversalAccessFromFileURLs(bool);
96 void setAllowFileAccessFromFileURLs(bool);
97 void setPluginsEnabled(bool);
98 void setJavaScriptCanAccessClipboard(bool);
99 void setPrivateBrowsingEnabled(bool);
100 void setPopupBlockingEnabled(bool);
101 void setAuthorAndUserStylesEnabled(bool);
102 void setCustomPolicyDelegate(bool enabled, bool permissive = false);
103 void addOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains);
104 void removeOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains);
105 void setUserStyleSheetEnabled(bool);
106 void setUserStyleSheetLocation(JSStringRef);
107 void setSpatialNavigationEnabled(bool);
108 void setTabKeyCyclesThroughElements(bool);
109 void setSerializeHTTPLoads();
110 void dispatchPendingLoadRequests();
111 void setCacheModel(int);
112 void setAsynchronousSpellCheckingEnabled(bool);
114 // Special DOM functions.
115 void clearBackForwardList();
116 void execCommand(JSStringRef name, JSStringRef argument);
117 bool isCommandEnabled(JSStringRef name);
118 unsigned windowCount();
121 void testRepaint() { m_testRepaint = true; }
122 void repaintSweepHorizontally() { m_testRepaintSweepHorizontally = true; }
125 // UserContent testing.
126 void addUserScript(JSStringRef source, bool runAtStart, bool allFrames);
127 void addUserStyleSheet(JSStringRef source, bool allFrames);
129 // Text search testing.
130 bool findString(JSStringRef, JSValueRef optionsArray);
133 void clearAllDatabases();
134 void setDatabaseQuota(uint64_t);
135 JSRetainPtr<JSStringRef> pathToLocalResource(JSStringRef);
138 void clearAllApplicationCaches();
139 void clearApplicationCacheForOrigin(JSStringRef origin);
140 void setAppCacheMaximumSize(uint64_t);
141 long long applicationCacheDiskUsageForOrigin(JSStringRef origin);
142 void disallowIncreaseForApplicationCacheQuota();
143 bool shouldDisallowIncreaseForApplicationCacheQuota() { return m_disallowIncreaseForApplicationCacheQuota; }
144 JSValueRef originsWithApplicationCache();
147 bool isPageBoxVisible(int pageIndex);
148 bool isPrinting() { return m_isPrinting; }
149 void setPrinting() { m_isPrinting = true; }
152 void setHandlesAuthenticationChallenges(bool);
153 void setAuthenticationUsername(JSStringRef);
154 void setAuthenticationPassword(JSStringRef);
156 void setValueForUser(JSContextRef, JSValueRef element, JSStringRef value);
159 void setAudioResult(JSContextRef, JSValueRef data);
161 void setBlockAllPlugins(bool shouldBlock);
163 enum WhatToDump { RenderTree, MainFrameText, AllFramesText, Audio, DOMAsWebArchive };
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(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 double databaseDefaultQuota() const { return m_databaseDefaultQuota; }
221 void setDatabaseDefaultQuota(double quota) { m_databaseDefaultQuota = quota; }
223 double databaseMaxQuota() const { return m_databaseMaxQuota; }
224 void setDatabaseMaxQuota(double quota) { m_databaseMaxQuota = quota; }
226 void addChromeInputField(JSValueRef);
227 void removeChromeInputField(JSValueRef);
228 void focusWebView(JSValueRef);
229 void setBackingScaleFactor(double, JSValueRef);
231 void setWindowIsKey(bool);
233 void callAddChromeInputFieldCallback();
234 void callRemoveChromeInputFieldCallback();
235 void callFocusWebViewCallback();
236 void callSetBackingScaleFactorCallback();
238 void overridePreference(JSStringRef preference, JSStringRef value);
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);
259 void setUserMediaPermission(bool);
261 void setPageVisibility(JSStringRef state);
262 void resetPageVisibility();
264 bool callShouldCloseOnWebView();
266 void setCustomTimeout(int duration);
269 void queueBackNavigation(unsigned howFarBackward);
270 void queueForwardNavigation(unsigned howFarForward);
271 void queueLoad(JSStringRef url, JSStringRef target);
272 void queueLoadHTMLString(JSStringRef content, JSStringRef baseURL, JSStringRef unreachableURL);
274 void queueLoadingScript(JSStringRef script);
275 void queueNonLoadingScript(JSStringRef script);
277 bool secureEventInputIsEnabled() const;
279 JSValueRef numberOfDFGCompiles(JSValueRef theFunction);
280 JSValueRef neverInlineFunction(JSValueRef theFunction);
283 static const double waitToDumpWatchdogTimerInterval;
287 void platformInitialize();
288 void initializeWaitToDumpWatchdogTimerIfNeeded();
290 WKRetainPtr<WKURLRef> m_testURL; // Set by InjectedBundlePage once provisional load starts.
292 WhatToDump m_whatToDump;
293 bool m_shouldDumpAllFrameScrollPositions;
294 bool m_shouldDumpBackForwardListsForAllWindows;
296 bool m_shouldAllowEditing;
297 bool m_shouldCloseExtraWindows;
299 bool m_dumpEditingCallbacks;
300 bool m_dumpStatusCallbacks;
301 bool m_dumpTitleChanges;
303 bool m_dumpSelectionRect;
304 bool m_dumpFullScreenCallbacks;
305 bool m_dumpFrameLoadCallbacks;
306 bool m_dumpProgressFinishedCallback;
307 bool m_dumpResourceLoadCallbacks;
308 bool m_dumpResourceResponseMIMETypes;
309 bool m_dumpWillCacheResponse;
310 bool m_dumpApplicationCacheDelegateCallbacks;
311 bool m_dumpDatabaseCallbacks;
312 bool m_disallowIncreaseForApplicationCacheQuota;
313 bool m_waitToDump; // True if waitUntilDone() has been called, but notifyDone() has not yet been called.
315 bool m_testRepaintSweepHorizontally;
318 bool m_willSendRequestReturnsNull;
319 bool m_willSendRequestReturnsNullOnRedirect;
320 bool m_shouldStopProvisionalFrameLoads;
322 bool m_policyDelegateEnabled;
323 bool m_policyDelegatePermissive;
326 bool m_customFullScreenBehavior;
330 double m_databaseDefaultQuota;
331 double m_databaseMaxQuota;
333 bool m_userStyleSheetEnabled;
334 WKRetainPtr<WKStringRef> m_userStyleSheetLocation;
336 PlatformTimerRef m_waitToDumpWatchdogTimer;
341 #endif // TestRunner_h