1 /* |
|
2 * Copyright (C) 2007, 2008, 2009 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 * |
|
8 * 1. Redistributions of source code must retain the above copyright |
|
9 * notice, this list of conditions and the following disclaimer. |
|
10 * 2. Redistributions in binary form must reproduce the above copyright |
|
11 * notice, this list of conditions and the following disclaimer in the |
|
12 * documentation and/or other materials provided with the distribution. |
|
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
|
14 * its contributors may be used to endorse or promote products derived |
|
15 * from this software without specific prior written permission. |
|
16 * |
|
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
|
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 |
|
29 #ifndef LayoutTestController_h |
|
30 #define LayoutTestController_h |
|
31 |
|
32 #include <JavaScriptCore/JSObjectRef.h> |
|
33 #include <JavaScriptCore/JSRetainPtr.h> |
|
34 #include <set> |
|
35 #include <string> |
|
36 #include <vector> |
|
37 #include <wtf/PassRefPtr.h> |
|
38 #include <wtf/RefCounted.h> |
|
39 |
|
40 class LayoutTestController : public RefCounted<LayoutTestController> { |
|
41 public: |
|
42 static PassRefPtr<LayoutTestController> create(const std::string& testPathOrURL, const std::string& expectedPixelHash); |
|
43 ~LayoutTestController(); |
|
44 |
|
45 void makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception); |
|
46 |
|
47 void addDisallowedURL(JSStringRef url); |
|
48 void clearAllDatabases(); |
|
49 void clearBackForwardList(); |
|
50 void clearPersistentUserStyleSheet(); |
|
51 bool callShouldCloseOnWebView(); |
|
52 JSStringRef copyDecodedHostName(JSStringRef name); |
|
53 JSStringRef copyEncodedHostName(JSStringRef name); |
|
54 void disableImageLoading(); |
|
55 void dispatchPendingLoadRequests(); |
|
56 void display(); |
|
57 void execCommand(JSStringRef name, JSStringRef value); |
|
58 JSRetainPtr<JSStringRef> counterValueForElementById(JSStringRef id); |
|
59 bool isCommandEnabled(JSStringRef name); |
|
60 void keepWebHistory(); |
|
61 JSValueRef computedStyleIncludingVisitedInfo(JSContextRef, JSValueRef); |
|
62 void notifyDone(); |
|
63 int numberOfPages(float pageWidthInPixels, float pageHeightInPixels); |
|
64 void overridePreference(JSStringRef key, JSStringRef value); |
|
65 int pageNumberForElementById(JSStringRef id, float pageWidthInPixels, float pageHeightInPixels); |
|
66 JSRetainPtr<JSStringRef> pageProperty(const char* propertyName, int pageNumber) const; |
|
67 JSRetainPtr<JSStringRef> pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const; |
|
68 bool isPageBoxVisible(int pageNumber) const; |
|
69 JSStringRef pathToLocalResource(JSContextRef, JSStringRef url); |
|
70 void queueBackNavigation(int howFarBackward); |
|
71 void queueForwardNavigation(int howFarForward); |
|
72 void queueLoad(JSStringRef url, JSStringRef target); |
|
73 void queueLoadHTMLString(JSStringRef content, JSStringRef baseURL); |
|
74 void queueLoadingScript(JSStringRef script); |
|
75 void queueNonLoadingScript(JSStringRef script); |
|
76 void queueReload(); |
|
77 void removeAllVisitedLinks(); |
|
78 void setAcceptsEditing(bool acceptsEditing); |
|
79 void setAllowUniversalAccessFromFileURLs(bool); |
|
80 void setAllowFileAccessFromFileURLs(bool); |
|
81 void setAppCacheMaximumSize(unsigned long long quota); |
|
82 void setAuthorAndUserStylesEnabled(bool); |
|
83 void setCacheModel(int); |
|
84 void setCustomPolicyDelegate(bool setDelegate, bool permissive); |
|
85 void setDatabaseQuota(unsigned long long quota); |
|
86 void setDomainRelaxationForbiddenForURLScheme(bool forbidden, JSStringRef scheme); |
|
87 void setIconDatabaseEnabled(bool iconDatabaseEnabled); |
|
88 void setJavaScriptProfilingEnabled(bool profilingEnabled); |
|
89 void setJavaScriptCanAccessClipboard(bool flag); |
|
90 void setMainFrameIsFirstResponder(bool flag); |
|
91 void setMockGeolocationError(int code, JSStringRef message); |
|
92 void setMockGeolocationPosition(double latitude, double longitude, double accuracy); |
|
93 void setPersistentUserStyleSheetLocation(JSStringRef path); |
|
94 void setPluginsEnabled(bool flag); |
|
95 void setPopupBlockingEnabled(bool flag); |
|
96 void setPrivateBrowsingEnabled(bool flag); |
|
97 void setSelectTrailingWhitespaceEnabled(bool flag); |
|
98 void setSmartInsertDeleteEnabled(bool flag); |
|
99 void setTabKeyCyclesThroughElements(bool cycles); |
|
100 void setUseDashboardCompatibilityMode(bool flag); |
|
101 void setUserStyleSheetEnabled(bool flag); |
|
102 void setUserStyleSheetLocation(JSStringRef path); |
|
103 void setXSSAuditorEnabled(bool flag); |
|
104 void setFrameFlatteningEnabled(bool enable); |
|
105 void setSpatialNavigationEnabled(bool enable); |
|
106 void setScrollbarPolicy(JSStringRef orientation, JSStringRef policy); |
|
107 void setEditingBehavior(const char* editingBehavior); |
|
108 |
|
109 void waitForPolicyDelegate(); |
|
110 size_t webHistoryItemCount(); |
|
111 unsigned workerThreadCount() const; |
|
112 int windowCount(); |
|
113 |
|
114 void grantDesktopNotificationPermission(JSStringRef origin); |
|
115 bool checkDesktopNotificationPermission(JSStringRef origin); |
|
116 |
|
117 bool elementDoesAutoCompleteForElementWithId(JSStringRef id); |
|
118 |
|
119 bool dumpAsPDF() const { return m_dumpAsPDF; } |
|
120 void setDumpAsPDF(bool dumpAsPDF) { m_dumpAsPDF = dumpAsPDF; } |
|
121 |
|
122 bool dumpAsText() const { return m_dumpAsText; } |
|
123 void setDumpAsText(bool dumpAsText) { m_dumpAsText = dumpAsText; } |
|
124 |
|
125 bool generatePixelResults() const { return m_generatePixelResults; } |
|
126 void setGeneratePixelResults(bool generatePixelResults) { m_generatePixelResults = generatePixelResults; } |
|
127 |
|
128 bool dumpBackForwardList() const { return m_dumpBackForwardList; } |
|
129 void setDumpBackForwardList(bool dumpBackForwardList) { m_dumpBackForwardList = dumpBackForwardList; } |
|
130 |
|
131 bool dumpChildFrameScrollPositions() const { return m_dumpChildFrameScrollPositions; } |
|
132 void setDumpChildFrameScrollPositions(bool dumpChildFrameScrollPositions) { m_dumpChildFrameScrollPositions = dumpChildFrameScrollPositions; } |
|
133 |
|
134 bool dumpChildFramesAsText() const { return m_dumpChildFramesAsText; } |
|
135 void setDumpChildFramesAsText(bool dumpChildFramesAsText) { m_dumpChildFramesAsText = dumpChildFramesAsText; } |
|
136 |
|
137 bool dumpDatabaseCallbacks() const { return m_dumpDatabaseCallbacks; } |
|
138 void setDumpDatabaseCallbacks(bool dumpDatabaseCallbacks) { m_dumpDatabaseCallbacks = dumpDatabaseCallbacks; } |
|
139 |
|
140 bool dumpDOMAsWebArchive() const { return m_dumpDOMAsWebArchive; } |
|
141 void setDumpDOMAsWebArchive(bool dumpDOMAsWebArchive) { m_dumpDOMAsWebArchive = dumpDOMAsWebArchive; } |
|
142 |
|
143 bool dumpEditingCallbacks() const { return m_dumpEditingCallbacks; } |
|
144 void setDumpEditingCallbacks(bool dumpEditingCallbacks) { m_dumpEditingCallbacks = dumpEditingCallbacks; } |
|
145 |
|
146 bool dumpFrameLoadCallbacks() const { return m_dumpFrameLoadCallbacks; } |
|
147 void setDumpFrameLoadCallbacks(bool dumpFrameLoadCallbacks) { m_dumpFrameLoadCallbacks = dumpFrameLoadCallbacks; } |
|
148 |
|
149 bool dumpHistoryDelegateCallbacks() const { return m_dumpHistoryDelegateCallbacks; } |
|
150 void setDumpHistoryDelegateCallbacks(bool dumpHistoryDelegateCallbacks) { m_dumpHistoryDelegateCallbacks = dumpHistoryDelegateCallbacks; } |
|
151 |
|
152 bool dumpResourceLoadCallbacks() const { return m_dumpResourceLoadCallbacks; } |
|
153 void setDumpResourceLoadCallbacks(bool dumpResourceLoadCallbacks) { m_dumpResourceLoadCallbacks = dumpResourceLoadCallbacks; } |
|
154 |
|
155 bool dumpResourceResponseMIMETypes() const { return m_dumpResourceResponseMIMETypes; } |
|
156 void setDumpResourceResponseMIMETypes(bool dumpResourceResponseMIMETypes) { m_dumpResourceResponseMIMETypes = dumpResourceResponseMIMETypes; } |
|
157 |
|
158 bool dumpSelectionRect() const { return m_dumpSelectionRect; } |
|
159 void setDumpSelectionRect(bool dumpSelectionRect) { m_dumpSelectionRect = dumpSelectionRect; } |
|
160 |
|
161 bool dumpSourceAsWebArchive() const { return m_dumpSourceAsWebArchive; } |
|
162 void setDumpSourceAsWebArchive(bool dumpSourceAsWebArchive) { m_dumpSourceAsWebArchive = dumpSourceAsWebArchive; } |
|
163 |
|
164 bool dumpStatusCallbacks() const { return m_dumpStatusCallbacks; } |
|
165 void setDumpStatusCallbacks(bool dumpStatusCallbacks) { m_dumpStatusCallbacks = dumpStatusCallbacks; } |
|
166 |
|
167 bool dumpTitleChanges() const { return m_dumpTitleChanges; } |
|
168 void setDumpTitleChanges(bool dumpTitleChanges) { m_dumpTitleChanges = dumpTitleChanges; } |
|
169 |
|
170 bool dumpIconChanges() const { return m_dumpIconChanges; } |
|
171 void setDumpIconChanges(bool dumpIconChanges) { m_dumpIconChanges = dumpIconChanges; } |
|
172 |
|
173 bool dumpVisitedLinksCallback() const { return m_dumpVisitedLinksCallback; } |
|
174 void setDumpVisitedLinksCallback(bool dumpVisitedLinksCallback) { m_dumpVisitedLinksCallback = dumpVisitedLinksCallback; } |
|
175 |
|
176 bool dumpWillCacheResponse() const { return m_dumpWillCacheResponse; } |
|
177 void setDumpWillCacheResponse(bool dumpWillCacheResponse) { m_dumpWillCacheResponse = dumpWillCacheResponse; } |
|
178 |
|
179 bool callCloseOnWebViews() const { return m_callCloseOnWebViews; } |
|
180 void setCallCloseOnWebViews(bool callCloseOnWebViews) { m_callCloseOnWebViews = callCloseOnWebViews; } |
|
181 |
|
182 bool canOpenWindows() const { return m_canOpenWindows; } |
|
183 void setCanOpenWindows(bool canOpenWindows) { m_canOpenWindows = canOpenWindows; } |
|
184 |
|
185 bool closeRemainingWindowsWhenComplete() const { return m_closeRemainingWindowsWhenComplete; } |
|
186 void setCloseRemainingWindowsWhenComplete(bool closeRemainingWindowsWhenComplete) { m_closeRemainingWindowsWhenComplete = closeRemainingWindowsWhenComplete; } |
|
187 |
|
188 bool newWindowsCopyBackForwardList() const { return m_newWindowsCopyBackForwardList; } |
|
189 void setNewWindowsCopyBackForwardList(bool newWindowsCopyBackForwardList) { m_newWindowsCopyBackForwardList = newWindowsCopyBackForwardList; } |
|
190 |
|
191 bool stopProvisionalFrameLoads() const { return m_stopProvisionalFrameLoads; } |
|
192 void setStopProvisionalFrameLoads(bool stopProvisionalFrameLoads) { m_stopProvisionalFrameLoads = stopProvisionalFrameLoads; } |
|
193 |
|
194 bool testOnscreen() const { return m_testOnscreen; } |
|
195 void setTestOnscreen(bool testOnscreen) { m_testOnscreen = testOnscreen; } |
|
196 |
|
197 bool testRepaint() const { return m_testRepaint; } |
|
198 void setTestRepaint(bool testRepaint) { m_testRepaint = testRepaint; } |
|
199 |
|
200 bool testRepaintSweepHorizontally() const { return m_testRepaintSweepHorizontally; } |
|
201 void setTestRepaintSweepHorizontally(bool testRepaintSweepHorizontally) { m_testRepaintSweepHorizontally = testRepaintSweepHorizontally; } |
|
202 |
|
203 bool waitToDump() const { return m_waitToDump; } |
|
204 void setWaitToDump(bool waitToDump); |
|
205 void waitToDumpWatchdogTimerFired(); |
|
206 |
|
207 const std::set<std::string>& willSendRequestClearHeaders() const { return m_willSendRequestClearHeaders; } |
|
208 void setWillSendRequestClearHeader(std::string header) { m_willSendRequestClearHeaders.insert(header); } |
|
209 |
|
210 bool willSendRequestReturnsNull() const { return m_willSendRequestReturnsNull; } |
|
211 void setWillSendRequestReturnsNull(bool returnsNull) { m_willSendRequestReturnsNull = returnsNull; } |
|
212 |
|
213 bool willSendRequestReturnsNullOnRedirect() const { return m_willSendRequestReturnsNullOnRedirect; } |
|
214 void setWillSendRequestReturnsNullOnRedirect(bool returnsNull) { m_willSendRequestReturnsNullOnRedirect = returnsNull; } |
|
215 |
|
216 bool windowIsKey() const { return m_windowIsKey; } |
|
217 void setWindowIsKey(bool windowIsKey); |
|
218 |
|
219 bool alwaysAcceptCookies() const { return m_alwaysAcceptCookies; } |
|
220 void setAlwaysAcceptCookies(bool alwaysAcceptCookies); |
|
221 |
|
222 bool handlesAuthenticationChallenges() const { return m_handlesAuthenticationChallenges; } |
|
223 void setHandlesAuthenticationChallenges(bool handlesAuthenticationChallenges) { m_handlesAuthenticationChallenges = handlesAuthenticationChallenges; } |
|
224 |
|
225 bool isPrinting() const { return m_isPrinting; } |
|
226 void setIsPrinting(bool isPrinting) { m_isPrinting = isPrinting; } |
|
227 |
|
228 const std::string& authenticationUsername() const { return m_authenticationUsername; } |
|
229 void setAuthenticationUsername(std::string username) { m_authenticationUsername = username; } |
|
230 |
|
231 const std::string& authenticationPassword() const { return m_authenticationPassword; } |
|
232 void setAuthenticationPassword(std::string password) { m_authenticationPassword = password; } |
|
233 |
|
234 bool globalFlag() const { return m_globalFlag; } |
|
235 void setGlobalFlag(bool globalFlag) { m_globalFlag = globalFlag; } |
|
236 |
|
237 bool deferMainResourceDataLoad() const { return m_deferMainResourceDataLoad; } |
|
238 void setDeferMainResourceDataLoad(bool flag) { m_deferMainResourceDataLoad = flag; } |
|
239 |
|
240 const std::string& testPathOrURL() const { return m_testPathOrURL; } |
|
241 const std::string& expectedPixelHash() const { return m_expectedPixelHash; } |
|
242 |
|
243 bool pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId); |
|
244 bool pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId); |
|
245 bool sampleSVGAnimationForElementAtTime(JSStringRef animationId, double time, JSStringRef elementId); |
|
246 unsigned numberOfActiveAnimations() const; |
|
247 |
|
248 void addOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains); |
|
249 void removeOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains); |
|
250 |
|
251 void addUserScript(JSStringRef source, bool runAtStart, bool allFrames); |
|
252 void addUserStyleSheet(JSStringRef source, bool allFrames); |
|
253 |
|
254 void setGeolocationPermission(bool allow); |
|
255 bool isGeolocationPermissionSet() const { return m_isGeolocationPermissionSet; } |
|
256 bool geolocationPermission() const { return m_geolocationPermission; } |
|
257 |
|
258 void setDeveloperExtrasEnabled(bool); |
|
259 void showWebInspector(); |
|
260 void closeWebInspector(); |
|
261 void setTimelineProfilingEnabled(bool enabled); |
|
262 void evaluateInWebInspector(long callId, JSStringRef script); |
|
263 void evaluateScriptInIsolatedWorld(unsigned worldId, JSObjectRef globalObject, JSStringRef script); |
|
264 |
|
265 void setPOSIXLocale(JSStringRef locale); |
|
266 |
|
267 void setWebViewEditable(bool); |
|
268 |
|
269 void abortModal(); |
|
270 |
|
271 // The following API test functions should probably be moved to platform-specific |
|
272 // unit tests outside of DRT once they exist. |
|
273 void apiTestNewWindowDataLoadBaseURL(JSStringRef utf8Data, JSStringRef baseURL); |
|
274 void apiTestGoToCurrentBackForwardItem(); |
|
275 |
|
276 // Simulate a request an embedding application could make, populating per-session credential storage. |
|
277 void authenticateSession(JSStringRef url, JSStringRef username, JSStringRef password); |
|
278 |
|
279 JSRetainPtr<JSStringRef> layerTreeAsText() const; |
|
280 |
|
281 JSRetainPtr<JSStringRef> markerTextForListItem(JSContextRef context, JSValueRef nodeObject) const; |
|
282 |
|
283 static const unsigned maxViewWidth; |
|
284 static const unsigned maxViewHeight; |
|
285 |
|
286 private: |
|
287 LayoutTestController(const std::string& testPathOrURL, const std::string& expectedPixelHash); |
|
288 |
|
289 bool m_dumpAsPDF; |
|
290 bool m_dumpAsText; |
|
291 bool m_dumpBackForwardList; |
|
292 bool m_dumpChildFrameScrollPositions; |
|
293 bool m_dumpChildFramesAsText; |
|
294 bool m_dumpDOMAsWebArchive; |
|
295 bool m_dumpDatabaseCallbacks; |
|
296 bool m_dumpEditingCallbacks; |
|
297 bool m_dumpFrameLoadCallbacks; |
|
298 bool m_dumpHistoryDelegateCallbacks; |
|
299 bool m_dumpResourceLoadCallbacks; |
|
300 bool m_dumpResourceResponseMIMETypes; |
|
301 bool m_dumpSelectionRect; |
|
302 bool m_dumpSourceAsWebArchive; |
|
303 bool m_dumpStatusCallbacks; |
|
304 bool m_dumpTitleChanges; |
|
305 bool m_dumpIconChanges; |
|
306 bool m_dumpVisitedLinksCallback; |
|
307 bool m_dumpWillCacheResponse; |
|
308 bool m_generatePixelResults; |
|
309 bool m_callCloseOnWebViews; |
|
310 bool m_canOpenWindows; |
|
311 bool m_closeRemainingWindowsWhenComplete; |
|
312 bool m_newWindowsCopyBackForwardList; |
|
313 bool m_stopProvisionalFrameLoads; |
|
314 bool m_testOnscreen; |
|
315 bool m_testRepaint; |
|
316 bool m_testRepaintSweepHorizontally; |
|
317 bool m_waitToDump; // True if waitUntilDone() has been called, but notifyDone() has not yet been called. |
|
318 bool m_willSendRequestReturnsNull; |
|
319 bool m_willSendRequestReturnsNullOnRedirect; |
|
320 bool m_windowIsKey; |
|
321 bool m_alwaysAcceptCookies; |
|
322 bool m_globalFlag; |
|
323 bool m_isGeolocationPermissionSet; |
|
324 bool m_geolocationPermission; |
|
325 bool m_handlesAuthenticationChallenges; |
|
326 bool m_isPrinting; |
|
327 bool m_deferMainResourceDataLoad; |
|
328 |
|
329 std::string m_authenticationUsername; |
|
330 std::string m_authenticationPassword; |
|
331 std::string m_testPathOrURL; |
|
332 std::string m_expectedPixelHash; // empty string if no hash |
|
333 |
|
334 std::set<std::string> m_willSendRequestClearHeaders; |
|
335 |
|
336 // origins which have been granted desktop notification access |
|
337 std::vector<JSStringRef> m_desktopNotificationAllowedOrigins; |
|
338 |
|
339 static JSClassRef getJSClass(); |
|
340 static JSStaticValue* staticValues(); |
|
341 static JSStaticFunction* staticFunctions(); |
|
342 }; |
|
343 |
|
344 #endif // LayoutTestController_h |
|