• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <wtf/RefCounted.h>
35 #include <string>
36 #include <vector>
37 
38 class LayoutTestController : public RefCounted<LayoutTestController> {
39 public:
40     LayoutTestController(const std::string& testPathOrURL, const std::string& expectedPixelHash);
41     ~LayoutTestController();
42 
43     void makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception);
44 
45     void addDisallowedURL(JSStringRef url);
46     void clearAllDatabases();
47     void clearBackForwardList();
48     void clearPersistentUserStyleSheet();
49     JSStringRef copyDecodedHostName(JSStringRef name);
50     JSStringRef copyEncodedHostName(JSStringRef name);
51     void disableImageLoading();
52     void dispatchPendingLoadRequests();
53     void display();
54     void execCommand(JSStringRef name, JSStringRef value);
55     JSRetainPtr<JSStringRef> counterValueForElementById(JSStringRef id);
56     bool isCommandEnabled(JSStringRef name);
57     void keepWebHistory();
58     void notifyDone();
59     int numberOfPages(float pageWidthInPixels, float pageHeightInPixels);
60     void overridePreference(JSStringRef key, JSStringRef value);
61     int pageNumberForElementById(JSStringRef id, float pageWidthInPixels, float pageHeightInPixels);
62     JSStringRef pathToLocalResource(JSContextRef, JSStringRef url);
63     void queueBackNavigation(int howFarBackward);
64     void queueForwardNavigation(int howFarForward);
65     void queueLoad(JSStringRef url, JSStringRef target);
66     void queueLoadingScript(JSStringRef script);
67     void queueNonLoadingScript(JSStringRef script);
68     void queueReload();
69     void removeAllVisitedLinks();
70     void setAcceptsEditing(bool acceptsEditing);
71     void setAllowUniversalAccessFromFileURLs(bool);
72     void setAppCacheMaximumSize(unsigned long long quota);
73     void setAuthorAndUserStylesEnabled(bool);
74     void setCacheModel(int);
75     void setCustomPolicyDelegate(bool setDelegate, bool permissive);
76     void setDatabaseQuota(unsigned long long quota);
77     void setDomainRelaxationForbiddenForURLScheme(bool forbidden, JSStringRef scheme);
78     void setIconDatabaseEnabled(bool iconDatabaseEnabled);
79     void setJavaScriptProfilingEnabled(bool profilingEnabled);
80     void setMainFrameIsFirstResponder(bool flag);
81     void setMockGeolocationError(int code, JSStringRef message);
82     void setMockGeolocationPosition(double latitude, double longitude, double accuracy);
83     void setPersistentUserStyleSheetLocation(JSStringRef path);
84     void setPopupBlockingEnabled(bool flag);
85     void setPrivateBrowsingEnabled(bool flag);
86     void setSelectTrailingWhitespaceEnabled(bool flag);
87     void setSmartInsertDeleteEnabled(bool flag);
88     void setTabKeyCyclesThroughElements(bool cycles);
89     void setUseDashboardCompatibilityMode(bool flag);
90     void setUserStyleSheetEnabled(bool flag);
91     void setUserStyleSheetLocation(JSStringRef path);
92     void setXSSAuditorEnabled(bool flag);
93     void setFrameSetFlatteningEnabled(bool enable);
94 
95     void waitForPolicyDelegate();
96     size_t webHistoryItemCount();
97     unsigned workerThreadCount() const;
98     int windowCount();
99 
100     void grantDesktopNotificationPermission(JSStringRef origin);
101     bool checkDesktopNotificationPermission(JSStringRef origin);
102 
103     bool elementDoesAutoCompleteForElementWithId(JSStringRef id);
104 
dumpAsPDF()105     bool dumpAsPDF() const { return m_dumpAsPDF; }
setDumpAsPDF(bool dumpAsPDF)106     void setDumpAsPDF(bool dumpAsPDF) { m_dumpAsPDF = dumpAsPDF; }
107 
dumpAsText()108     bool dumpAsText() const { return m_dumpAsText; }
setDumpAsText(bool dumpAsText)109     void setDumpAsText(bool dumpAsText) { m_dumpAsText = dumpAsText; }
110 
dumpBackForwardList()111     bool dumpBackForwardList() const { return m_dumpBackForwardList; }
setDumpBackForwardList(bool dumpBackForwardList)112     void setDumpBackForwardList(bool dumpBackForwardList) { m_dumpBackForwardList = dumpBackForwardList; }
113 
dumpChildFrameScrollPositions()114     bool dumpChildFrameScrollPositions() const { return m_dumpChildFrameScrollPositions; }
setDumpChildFrameScrollPositions(bool dumpChildFrameScrollPositions)115     void setDumpChildFrameScrollPositions(bool dumpChildFrameScrollPositions) { m_dumpChildFrameScrollPositions = dumpChildFrameScrollPositions; }
116 
dumpChildFramesAsText()117     bool dumpChildFramesAsText() const { return m_dumpChildFramesAsText; }
setDumpChildFramesAsText(bool dumpChildFramesAsText)118     void setDumpChildFramesAsText(bool dumpChildFramesAsText) { m_dumpChildFramesAsText = dumpChildFramesAsText; }
119 
dumpDatabaseCallbacks()120     bool dumpDatabaseCallbacks() const { return m_dumpDatabaseCallbacks; }
setDumpDatabaseCallbacks(bool dumpDatabaseCallbacks)121     void setDumpDatabaseCallbacks(bool dumpDatabaseCallbacks) { m_dumpDatabaseCallbacks = dumpDatabaseCallbacks; }
122 
dumpDOMAsWebArchive()123     bool dumpDOMAsWebArchive() const { return m_dumpDOMAsWebArchive; }
setDumpDOMAsWebArchive(bool dumpDOMAsWebArchive)124     void setDumpDOMAsWebArchive(bool dumpDOMAsWebArchive) { m_dumpDOMAsWebArchive = dumpDOMAsWebArchive; }
125 
dumpEditingCallbacks()126     bool dumpEditingCallbacks() const { return m_dumpEditingCallbacks; }
setDumpEditingCallbacks(bool dumpEditingCallbacks)127     void setDumpEditingCallbacks(bool dumpEditingCallbacks) { m_dumpEditingCallbacks = dumpEditingCallbacks; }
128 
dumpFrameLoadCallbacks()129     bool dumpFrameLoadCallbacks() const { return m_dumpFrameLoadCallbacks; }
setDumpFrameLoadCallbacks(bool dumpFrameLoadCallbacks)130     void setDumpFrameLoadCallbacks(bool dumpFrameLoadCallbacks) { m_dumpFrameLoadCallbacks = dumpFrameLoadCallbacks; }
131 
dumpHistoryDelegateCallbacks()132     bool dumpHistoryDelegateCallbacks() const { return m_dumpHistoryDelegateCallbacks; }
setDumpHistoryDelegateCallbacks(bool dumpHistoryDelegateCallbacks)133     void setDumpHistoryDelegateCallbacks(bool dumpHistoryDelegateCallbacks) { m_dumpHistoryDelegateCallbacks = dumpHistoryDelegateCallbacks; }
134 
dumpResourceLoadCallbacks()135     bool dumpResourceLoadCallbacks() const { return m_dumpResourceLoadCallbacks; }
setDumpResourceLoadCallbacks(bool dumpResourceLoadCallbacks)136     void setDumpResourceLoadCallbacks(bool dumpResourceLoadCallbacks) { m_dumpResourceLoadCallbacks = dumpResourceLoadCallbacks; }
137 
dumpResourceResponseMIMETypes()138     bool dumpResourceResponseMIMETypes() const { return m_dumpResourceResponseMIMETypes; }
setDumpResourceResponseMIMETypes(bool dumpResourceResponseMIMETypes)139     void setDumpResourceResponseMIMETypes(bool dumpResourceResponseMIMETypes) { m_dumpResourceResponseMIMETypes = dumpResourceResponseMIMETypes; }
140 
dumpSelectionRect()141     bool dumpSelectionRect() const { return m_dumpSelectionRect; }
setDumpSelectionRect(bool dumpSelectionRect)142     void setDumpSelectionRect(bool dumpSelectionRect) { m_dumpSelectionRect = dumpSelectionRect; }
143 
dumpSourceAsWebArchive()144     bool dumpSourceAsWebArchive() const { return m_dumpSourceAsWebArchive; }
setDumpSourceAsWebArchive(bool dumpSourceAsWebArchive)145     void setDumpSourceAsWebArchive(bool dumpSourceAsWebArchive) { m_dumpSourceAsWebArchive = dumpSourceAsWebArchive; }
146 
dumpStatusCallbacks()147     bool dumpStatusCallbacks() const { return m_dumpStatusCallbacks; }
setDumpStatusCallbacks(bool dumpStatusCallbacks)148     void setDumpStatusCallbacks(bool dumpStatusCallbacks) { m_dumpStatusCallbacks = dumpStatusCallbacks; }
149 
dumpTitleChanges()150     bool dumpTitleChanges() const { return m_dumpTitleChanges; }
setDumpTitleChanges(bool dumpTitleChanges)151     void setDumpTitleChanges(bool dumpTitleChanges) { m_dumpTitleChanges = dumpTitleChanges; }
152 
dumpVisitedLinksCallback()153     bool dumpVisitedLinksCallback() const { return m_dumpVisitedLinksCallback; }
setDumpVisitedLinksCallback(bool dumpVisitedLinksCallback)154     void setDumpVisitedLinksCallback(bool dumpVisitedLinksCallback) { m_dumpVisitedLinksCallback = dumpVisitedLinksCallback; }
155 
dumpWillCacheResponse()156     bool dumpWillCacheResponse() const { return m_dumpWillCacheResponse; }
setDumpWillCacheResponse(bool dumpWillCacheResponse)157     void setDumpWillCacheResponse(bool dumpWillCacheResponse) { m_dumpWillCacheResponse = dumpWillCacheResponse; }
158 
callCloseOnWebViews()159     bool callCloseOnWebViews() const { return m_callCloseOnWebViews; }
setCallCloseOnWebViews(bool callCloseOnWebViews)160     void setCallCloseOnWebViews(bool callCloseOnWebViews) { m_callCloseOnWebViews = callCloseOnWebViews; }
161 
canOpenWindows()162     bool canOpenWindows() const { return m_canOpenWindows; }
setCanOpenWindows(bool canOpenWindows)163     void setCanOpenWindows(bool canOpenWindows) { m_canOpenWindows = canOpenWindows; }
164 
closeRemainingWindowsWhenComplete()165     bool closeRemainingWindowsWhenComplete() const { return m_closeRemainingWindowsWhenComplete; }
setCloseRemainingWindowsWhenComplete(bool closeRemainingWindowsWhenComplete)166     void setCloseRemainingWindowsWhenComplete(bool closeRemainingWindowsWhenComplete) { m_closeRemainingWindowsWhenComplete = closeRemainingWindowsWhenComplete; }
167 
newWindowsCopyBackForwardList()168     bool newWindowsCopyBackForwardList() const { return m_newWindowsCopyBackForwardList; }
setNewWindowsCopyBackForwardList(bool newWindowsCopyBackForwardList)169     void setNewWindowsCopyBackForwardList(bool newWindowsCopyBackForwardList) { m_newWindowsCopyBackForwardList = newWindowsCopyBackForwardList; }
170 
stopProvisionalFrameLoads()171     bool stopProvisionalFrameLoads() const { return m_stopProvisionalFrameLoads; }
setStopProvisionalFrameLoads(bool stopProvisionalFrameLoads)172     void setStopProvisionalFrameLoads(bool stopProvisionalFrameLoads) { m_stopProvisionalFrameLoads = stopProvisionalFrameLoads; }
173 
testOnscreen()174     bool testOnscreen() const { return m_testOnscreen; }
setTestOnscreen(bool testOnscreen)175     void setTestOnscreen(bool testOnscreen) { m_testOnscreen = testOnscreen; }
176 
testRepaint()177     bool testRepaint() const { return m_testRepaint; }
setTestRepaint(bool testRepaint)178     void setTestRepaint(bool testRepaint) { m_testRepaint = testRepaint; }
179 
testRepaintSweepHorizontally()180     bool testRepaintSweepHorizontally() const { return m_testRepaintSweepHorizontally; }
setTestRepaintSweepHorizontally(bool testRepaintSweepHorizontally)181     void setTestRepaintSweepHorizontally(bool testRepaintSweepHorizontally) { m_testRepaintSweepHorizontally = testRepaintSweepHorizontally; }
182 
waitToDump()183     bool waitToDump() const { return m_waitToDump; }
184     void setWaitToDump(bool waitToDump);
185     void waitToDumpWatchdogTimerFired();
186 
willSendRequestReturnsNull()187     bool willSendRequestReturnsNull() const { return m_willSendRequestReturnsNull; }
setWillSendRequestReturnsNull(bool returnsNull)188     void setWillSendRequestReturnsNull(bool returnsNull) { m_willSendRequestReturnsNull = returnsNull; }
189 
willSendRequestReturnsNullOnRedirect()190     bool willSendRequestReturnsNullOnRedirect() const { return m_willSendRequestReturnsNullOnRedirect; }
setWillSendRequestReturnsNullOnRedirect(bool returnsNull)191     void setWillSendRequestReturnsNullOnRedirect(bool returnsNull) { m_willSendRequestReturnsNullOnRedirect = returnsNull; }
192 
windowIsKey()193     bool windowIsKey() const { return m_windowIsKey; }
194     void setWindowIsKey(bool windowIsKey);
195 
alwaysAcceptCookies()196     bool alwaysAcceptCookies() const { return m_alwaysAcceptCookies; }
197     void setAlwaysAcceptCookies(bool alwaysAcceptCookies);
198 
handlesAuthenticationChallenges()199     bool handlesAuthenticationChallenges() const { return m_handlesAuthenticationChallenges; }
setHandlesAuthenticationChallenges(bool handlesAuthenticationChallenges)200     void setHandlesAuthenticationChallenges(bool handlesAuthenticationChallenges) { m_handlesAuthenticationChallenges = handlesAuthenticationChallenges; }
201 
authenticationUsername()202     const std::string& authenticationUsername() const { return m_authenticationUsername; }
setAuthenticationUsername(std::string username)203     void setAuthenticationUsername(std::string username) { m_authenticationUsername = username; }
204 
authenticationPassword()205     const std::string& authenticationPassword() const { return m_authenticationPassword; }
setAuthenticationPassword(std::string password)206     void setAuthenticationPassword(std::string password) { m_authenticationPassword = password; }
207 
globalFlag()208     bool globalFlag() const { return m_globalFlag; }
setGlobalFlag(bool globalFlag)209     void setGlobalFlag(bool globalFlag) { m_globalFlag = globalFlag; }
210 
testPathOrURL()211     const std::string& testPathOrURL() const { return m_testPathOrURL; }
expectedPixelHash()212     const std::string& expectedPixelHash() const { return m_expectedPixelHash; }
213 
214     bool pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId);
215     bool pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId);
216     bool sampleSVGAnimationForElementAtTime(JSStringRef animationId, double time, JSStringRef elementId);
217     unsigned numberOfActiveAnimations() const;
218 
219     void whiteListAccessFromOrigin(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains);
220 
221     void addUserScript(JSStringRef source, bool runAtStart);
222     void addUserStyleSheet(JSStringRef source);
223 
224     void setGeolocationPermission(bool allow);
isGeolocationPermissionSet()225     bool isGeolocationPermissionSet() const { return m_isGeolocationPermissionSet; }
geolocationPermission()226     bool geolocationPermission() const { return m_geolocationPermission; }
227 
228     void showWebInspector();
229     void closeWebInspector();
230     void setTimelineProfilingEnabled(bool enabled);
231     void evaluateInWebInspector(long callId, JSStringRef script);
232     void evaluateScriptInIsolatedWorld(unsigned worldId, JSObjectRef globalObject, JSStringRef script);
233 
234     void setPOSIXLocale(JSStringRef locale);
235 
236 private:
237     bool m_dumpAsPDF;
238     bool m_dumpAsText;
239     bool m_dumpBackForwardList;
240     bool m_dumpChildFrameScrollPositions;
241     bool m_dumpChildFramesAsText;
242     bool m_dumpDOMAsWebArchive;
243     bool m_dumpDatabaseCallbacks;
244     bool m_dumpEditingCallbacks;
245     bool m_dumpFrameLoadCallbacks;
246     bool m_dumpHistoryDelegateCallbacks;
247     bool m_dumpResourceLoadCallbacks;
248     bool m_dumpResourceResponseMIMETypes;
249     bool m_dumpSelectionRect;
250     bool m_dumpSourceAsWebArchive;
251     bool m_dumpStatusCallbacks;
252     bool m_dumpTitleChanges;
253     bool m_dumpVisitedLinksCallback;
254     bool m_dumpWillCacheResponse;
255     bool m_callCloseOnWebViews;
256     bool m_canOpenWindows;
257     bool m_closeRemainingWindowsWhenComplete;
258     bool m_newWindowsCopyBackForwardList;
259     bool m_stopProvisionalFrameLoads;
260     bool m_testOnscreen;
261     bool m_testRepaint;
262     bool m_testRepaintSweepHorizontally;
263     bool m_waitToDump; // True if waitUntilDone() has been called, but notifyDone() has not yet been called.
264     bool m_willSendRequestReturnsNull;
265     bool m_willSendRequestReturnsNullOnRedirect;
266     bool m_windowIsKey;
267     bool m_alwaysAcceptCookies;
268     bool m_globalFlag;
269     bool m_isGeolocationPermissionSet;
270     bool m_geolocationPermission;
271     bool m_handlesAuthenticationChallenges;
272 
273     std::string m_authenticationUsername;
274     std::string m_authenticationPassword;
275     std::string m_testPathOrURL;
276     std::string m_expectedPixelHash;    // empty string if no hash
277 
278     // origins which have been granted desktop notification access
279     std::vector<JSStringRef> m_desktopNotificationAllowedOrigins;
280 
281     static JSClassRef getJSClass();
282     static JSStaticValue* staticValues();
283     static JSStaticFunction* staticFunctions();
284 };
285 
286 #endif // LayoutTestController_h
287