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 <map> 35 #include <set> 36 #include <string> 37 #include <vector> 38 #include <wtf/PassRefPtr.h> 39 #include <wtf/RefCounted.h> 40 41 class LayoutTestController : public RefCounted<LayoutTestController> { 42 public: 43 static PassRefPtr<LayoutTestController> create(const std::string& testPathOrURL, const std::string& expectedPixelHash); 44 ~LayoutTestController(); 45 46 void makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception); 47 48 void addDisallowedURL(JSStringRef url); 49 void addURLToRedirect(std::string origin, std::string destination); 50 const std::string& redirectionDestinationForURL(std::string); 51 void clearAllApplicationCaches(); 52 void clearAllDatabases(); 53 void clearApplicationCacheForOrigin(JSStringRef name); 54 void clearBackForwardList(); 55 void clearPersistentUserStyleSheet(); 56 bool callShouldCloseOnWebView(); 57 JSStringRef copyDecodedHostName(JSStringRef name); 58 JSStringRef copyEncodedHostName(JSStringRef name); 59 JSRetainPtr<JSStringRef> counterValueForElementById(JSStringRef id); 60 void disableImageLoading(); 61 void dispatchPendingLoadRequests(); 62 void display(); 63 void displayInvalidatedRegion(); 64 void execCommand(JSStringRef name, JSStringRef value); 65 bool findString(JSContextRef, JSStringRef, JSObjectRef optionsArray); 66 JSValueRef originsWithApplicationCache(JSContextRef); 67 bool isCommandEnabled(JSStringRef name); 68 void keepWebHistory(); 69 JSValueRef computedStyleIncludingVisitedInfo(JSContextRef, JSValueRef); 70 JSValueRef nodesFromRect(JSContextRef, JSValueRef, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping); 71 void notifyDone(); 72 int numberOfPages(float pageWidthInPixels, float pageHeightInPixels); 73 int numberOfPendingGeolocationPermissionRequests(); 74 void overridePreference(JSStringRef key, JSStringRef value); 75 int pageNumberForElementById(JSStringRef id, float pageWidthInPixels, float pageHeightInPixels); 76 JSRetainPtr<JSStringRef> pageProperty(const char* propertyName, int pageNumber) const; 77 JSRetainPtr<JSStringRef> pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const; 78 bool isPageBoxVisible(int pageNumber) const; 79 JSStringRef pathToLocalResource(JSContextRef, JSStringRef url); 80 void queueBackNavigation(int howFarBackward); 81 void queueForwardNavigation(int howFarForward); 82 void queueLoad(JSStringRef url, JSStringRef target); 83 void queueLoadHTMLString(JSStringRef content, JSStringRef baseURL); 84 void queueLoadAlternateHTMLString(JSStringRef content, JSStringRef baseURL, JSStringRef unreachableURL); 85 void queueLoadingScript(JSStringRef script); 86 void queueNonLoadingScript(JSStringRef script); 87 void queueReload(); 88 void removeAllVisitedLinks(); 89 void setAcceptsEditing(bool acceptsEditing); 90 void setAllowUniversalAccessFromFileURLs(bool); 91 void setAllowFileAccessFromFileURLs(bool); 92 void setAppCacheMaximumSize(unsigned long long quota); 93 void setApplicationCacheOriginQuota(unsigned long long quota); 94 void setAuthorAndUserStylesEnabled(bool); 95 void setAutofilled(JSContextRef, JSValueRef nodeObject, bool autofilled); 96 void setCacheModel(int); 97 void setCustomPolicyDelegate(bool setDelegate, bool permissive); 98 void setDatabaseQuota(unsigned long long quota); 99 void setDomainRelaxationForbiddenForURLScheme(bool forbidden, JSStringRef scheme); 100 void setIconDatabaseEnabled(bool iconDatabaseEnabled); 101 void setJavaScriptProfilingEnabled(bool profilingEnabled); 102 void setJavaScriptCanAccessClipboard(bool flag); 103 void setMainFrameIsFirstResponder(bool flag); 104 void setMockDeviceOrientation(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma); 105 void setMockGeolocationError(int code, JSStringRef message); 106 void setMockGeolocationPosition(double latitude, double longitude, double accuracy); 107 void addMockSpeechInputResult(JSStringRef result, double confidence, JSStringRef language); 108 void setPersistentUserStyleSheetLocation(JSStringRef path); 109 void setPluginsEnabled(bool flag); 110 void setPopupBlockingEnabled(bool flag); 111 void setPrivateBrowsingEnabled(bool flag); 112 void setSelectTrailingWhitespaceEnabled(bool flag); 113 void setSmartInsertDeleteEnabled(bool flag); 114 void setTabKeyCyclesThroughElements(bool cycles); 115 void setUseDashboardCompatibilityMode(bool flag); 116 void setUserStyleSheetEnabled(bool flag); 117 void setUserStyleSheetLocation(JSStringRef path); 118 void setValueForUser(JSContextRef, JSValueRef nodeObject, JSStringRef value); 119 void setViewModeMediaFeature(JSStringRef mode); 120 void setXSSAuditorEnabled(bool flag); 121 void setFrameFlatteningEnabled(bool enable); 122 void setSpatialNavigationEnabled(bool enable); 123 void setScrollbarPolicy(JSStringRef orientation, JSStringRef policy); 124 void setEditingBehavior(const char* editingBehavior); 125 JSValueRef shadowRoot(JSContextRef, JSValueRef); 126 127 void waitForPolicyDelegate(); 128 size_t webHistoryItemCount(); 129 unsigned workerThreadCount() const; 130 int windowCount(); 131 132 void grantDesktopNotificationPermission(JSStringRef origin); 133 bool checkDesktopNotificationPermission(JSStringRef origin); 134 135 bool elementDoesAutoCompleteForElementWithId(JSStringRef id); 136 137 bool dumpAsAudio() const { return m_dumpAsAudio; } 138 void setDumpAsAudio(bool dumpAsAudio) { m_dumpAsAudio = dumpAsAudio; } 139 140 bool dumpAsPDF() const { return m_dumpAsPDF; } 141 void setDumpAsPDF(bool dumpAsPDF) { m_dumpAsPDF = dumpAsPDF; } 142 143 bool dumpAsText() const { return m_dumpAsText; } 144 void setDumpAsText(bool dumpAsText) { m_dumpAsText = dumpAsText; } 145 146 bool generatePixelResults() const { return m_generatePixelResults; } 147 void setGeneratePixelResults(bool generatePixelResults) { m_generatePixelResults = generatePixelResults; } 148 149 bool dumpApplicationCacheDelegateCallbacks() const { return m_dumpApplicationCacheDelegateCallbacks; } 150 void setDumpApplicationCacheDelegateCallbacks(bool dumpCallbacks) { m_dumpApplicationCacheDelegateCallbacks = dumpCallbacks; } 151 152 bool dumpBackForwardList() const { return m_dumpBackForwardList; } 153 void setDumpBackForwardList(bool dumpBackForwardList) { m_dumpBackForwardList = dumpBackForwardList; } 154 155 bool dumpChildFrameScrollPositions() const { return m_dumpChildFrameScrollPositions; } 156 void setDumpChildFrameScrollPositions(bool dumpChildFrameScrollPositions) { m_dumpChildFrameScrollPositions = dumpChildFrameScrollPositions; } 157 158 bool dumpChildFramesAsText() const { return m_dumpChildFramesAsText; } 159 void setDumpChildFramesAsText(bool dumpChildFramesAsText) { m_dumpChildFramesAsText = dumpChildFramesAsText; } 160 161 bool dumpDatabaseCallbacks() const { return m_dumpDatabaseCallbacks; } 162 void setDumpDatabaseCallbacks(bool dumpDatabaseCallbacks) { m_dumpDatabaseCallbacks = dumpDatabaseCallbacks; } 163 164 bool dumpDOMAsWebArchive() const { return m_dumpDOMAsWebArchive; } 165 void setDumpDOMAsWebArchive(bool dumpDOMAsWebArchive) { m_dumpDOMAsWebArchive = dumpDOMAsWebArchive; } 166 167 bool dumpEditingCallbacks() const { return m_dumpEditingCallbacks; } 168 void setDumpEditingCallbacks(bool dumpEditingCallbacks) { m_dumpEditingCallbacks = dumpEditingCallbacks; } 169 170 bool dumpFrameLoadCallbacks() const { return m_dumpFrameLoadCallbacks; } 171 void setDumpFrameLoadCallbacks(bool dumpFrameLoadCallbacks) { m_dumpFrameLoadCallbacks = dumpFrameLoadCallbacks; } 172 173 bool dumpUserGestureInFrameLoadCallbacks() const { return m_dumpUserGestureInFrameLoadCallbacks; } 174 void setDumpUserGestureInFrameLoadCallbacks(bool dumpUserGestureInFrameLoadCallbacks) { m_dumpUserGestureInFrameLoadCallbacks = dumpUserGestureInFrameLoadCallbacks; } 175 176 bool dumpHistoryDelegateCallbacks() const { return m_dumpHistoryDelegateCallbacks; } 177 void setDumpHistoryDelegateCallbacks(bool dumpHistoryDelegateCallbacks) { m_dumpHistoryDelegateCallbacks = dumpHistoryDelegateCallbacks; } 178 179 bool dumpResourceLoadCallbacks() const { return m_dumpResourceLoadCallbacks; } 180 void setDumpResourceLoadCallbacks(bool dumpResourceLoadCallbacks) { m_dumpResourceLoadCallbacks = dumpResourceLoadCallbacks; } 181 182 bool dumpResourceResponseMIMETypes() const { return m_dumpResourceResponseMIMETypes; } 183 void setDumpResourceResponseMIMETypes(bool dumpResourceResponseMIMETypes) { m_dumpResourceResponseMIMETypes = dumpResourceResponseMIMETypes; } 184 185 bool dumpSelectionRect() const { return m_dumpSelectionRect; } 186 void setDumpSelectionRect(bool dumpSelectionRect) { m_dumpSelectionRect = dumpSelectionRect; } 187 188 bool dumpSourceAsWebArchive() const { return m_dumpSourceAsWebArchive; } 189 void setDumpSourceAsWebArchive(bool dumpSourceAsWebArchive) { m_dumpSourceAsWebArchive = dumpSourceAsWebArchive; } 190 191 bool dumpStatusCallbacks() const { return m_dumpStatusCallbacks; } 192 void setDumpStatusCallbacks(bool dumpStatusCallbacks) { m_dumpStatusCallbacks = dumpStatusCallbacks; } 193 194 bool dumpTitleChanges() const { return m_dumpTitleChanges; } 195 void setDumpTitleChanges(bool dumpTitleChanges) { m_dumpTitleChanges = dumpTitleChanges; } 196 197 bool dumpIconChanges() const { return m_dumpIconChanges; } 198 void setDumpIconChanges(bool dumpIconChanges) { m_dumpIconChanges = dumpIconChanges; } 199 200 bool dumpVisitedLinksCallback() const { return m_dumpVisitedLinksCallback; } 201 void setDumpVisitedLinksCallback(bool dumpVisitedLinksCallback) { m_dumpVisitedLinksCallback = dumpVisitedLinksCallback; } 202 203 bool dumpWillCacheResponse() const { return m_dumpWillCacheResponse; } 204 void setDumpWillCacheResponse(bool dumpWillCacheResponse) { m_dumpWillCacheResponse = dumpWillCacheResponse; } 205 206 bool callCloseOnWebViews() const { return m_callCloseOnWebViews; } 207 void setCallCloseOnWebViews(bool callCloseOnWebViews) { m_callCloseOnWebViews = callCloseOnWebViews; } 208 209 bool canOpenWindows() const { return m_canOpenWindows; } 210 void setCanOpenWindows(bool canOpenWindows) { m_canOpenWindows = canOpenWindows; } 211 212 bool closeRemainingWindowsWhenComplete() const { return m_closeRemainingWindowsWhenComplete; } 213 void setCloseRemainingWindowsWhenComplete(bool closeRemainingWindowsWhenComplete) { m_closeRemainingWindowsWhenComplete = closeRemainingWindowsWhenComplete; } 214 215 bool newWindowsCopyBackForwardList() const { return m_newWindowsCopyBackForwardList; } 216 void setNewWindowsCopyBackForwardList(bool newWindowsCopyBackForwardList) { m_newWindowsCopyBackForwardList = newWindowsCopyBackForwardList; } 217 218 bool stopProvisionalFrameLoads() const { return m_stopProvisionalFrameLoads; } 219 void setStopProvisionalFrameLoads(bool stopProvisionalFrameLoads) { m_stopProvisionalFrameLoads = stopProvisionalFrameLoads; } 220 221 bool testOnscreen() const { return m_testOnscreen; } 222 void setTestOnscreen(bool testOnscreen) { m_testOnscreen = testOnscreen; } 223 224 bool testRepaint() const { return m_testRepaint; } 225 void setTestRepaint(bool testRepaint) { m_testRepaint = testRepaint; } 226 227 bool testRepaintSweepHorizontally() const { return m_testRepaintSweepHorizontally; } 228 void setTestRepaintSweepHorizontally(bool testRepaintSweepHorizontally) { m_testRepaintSweepHorizontally = testRepaintSweepHorizontally; } 229 230 bool waitToDump() const { return m_waitToDump; } 231 void setWaitToDump(bool waitToDump); 232 void waitToDumpWatchdogTimerFired(); 233 234 const std::set<std::string>& willSendRequestClearHeaders() const { return m_willSendRequestClearHeaders; } 235 void setWillSendRequestClearHeader(std::string header) { m_willSendRequestClearHeaders.insert(header); } 236 237 bool willSendRequestReturnsNull() const { return m_willSendRequestReturnsNull; } 238 void setWillSendRequestReturnsNull(bool returnsNull) { m_willSendRequestReturnsNull = returnsNull; } 239 240 bool willSendRequestReturnsNullOnRedirect() const { return m_willSendRequestReturnsNullOnRedirect; } 241 void setWillSendRequestReturnsNullOnRedirect(bool returnsNull) { m_willSendRequestReturnsNullOnRedirect = returnsNull; } 242 243 bool windowIsKey() const { return m_windowIsKey; } 244 void setWindowIsKey(bool windowIsKey); 245 246 bool alwaysAcceptCookies() const { return m_alwaysAcceptCookies; } 247 void setAlwaysAcceptCookies(bool alwaysAcceptCookies); 248 249 bool handlesAuthenticationChallenges() const { return m_handlesAuthenticationChallenges; } 250 void setHandlesAuthenticationChallenges(bool handlesAuthenticationChallenges) { m_handlesAuthenticationChallenges = handlesAuthenticationChallenges; } 251 252 bool isPrinting() const { return m_isPrinting; } 253 void setIsPrinting(bool isPrinting) { m_isPrinting = isPrinting; } 254 255 const std::string& authenticationUsername() const { return m_authenticationUsername; } 256 void setAuthenticationUsername(std::string username) { m_authenticationUsername = username; } 257 258 const std::string& authenticationPassword() const { return m_authenticationPassword; } 259 void setAuthenticationPassword(std::string password) { m_authenticationPassword = password; } 260 261 bool globalFlag() const { return m_globalFlag; } 262 void setGlobalFlag(bool globalFlag) { m_globalFlag = globalFlag; } 263 264 bool deferMainResourceDataLoad() const { return m_deferMainResourceDataLoad; } 265 void setDeferMainResourceDataLoad(bool flag) { m_deferMainResourceDataLoad = flag; } 266 267 const std::string& testPathOrURL() const { return m_testPathOrURL; } 268 const std::string& expectedPixelHash() const { return m_expectedPixelHash; } 269 270 const std::string& encodedAudioData() const { return m_encodedAudioData; } 271 void setEncodedAudioData(const std::string& encodedAudioData) { m_encodedAudioData = encodedAudioData; } 272 273 bool pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId); 274 bool pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId); 275 bool sampleSVGAnimationForElementAtTime(JSStringRef animationId, double time, JSStringRef elementId); 276 unsigned numberOfActiveAnimations() const; 277 void suspendAnimations() const; 278 void resumeAnimations() const; 279 280 void addOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains); 281 void removeOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains); 282 283 void addUserScript(JSStringRef source, bool runAtStart, bool allFrames); 284 void addUserStyleSheet(JSStringRef source, bool allFrames); 285 286 void setGeolocationPermission(bool allow); 287 bool isGeolocationPermissionSet() const { return m_isGeolocationPermissionSet; } 288 bool geolocationPermission() const { return m_geolocationPermission; } 289 290 void setDeveloperExtrasEnabled(bool); 291 void setAsynchronousSpellCheckingEnabled(bool); 292 void showWebInspector(); 293 void closeWebInspector(); 294 void setTimelineProfilingEnabled(bool enabled); 295 void evaluateInWebInspector(long callId, JSStringRef script); 296 void evaluateScriptInIsolatedWorld(unsigned worldId, JSObjectRef globalObject, JSStringRef script); 297 298 void setPOSIXLocale(JSStringRef locale); 299 300 void setWebViewEditable(bool); 301 302 void abortModal(); 303 304 bool hasSpellingMarker(int from, int length); 305 bool hasGrammarMarker(int from, int length); 306 307 void dumpConfigurationForViewport(int deviceDPI, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight); 308 309 static void setSerializeHTTPLoads(bool serialize); 310 311 // The following API test functions should probably be moved to platform-specific 312 // unit tests outside of DRT once they exist. 313 void apiTestNewWindowDataLoadBaseURL(JSStringRef utf8Data, JSStringRef baseURL); 314 void apiTestGoToCurrentBackForwardItem(); 315 316 // Simulate a request an embedding application could make, populating per-session credential storage. 317 void authenticateSession(JSStringRef url, JSStringRef username, JSStringRef password); 318 319 JSRetainPtr<JSStringRef> layerTreeAsText() const; 320 321 JSRetainPtr<JSStringRef> markerTextForListItem(JSContextRef context, JSValueRef nodeObject) const; 322 323 JSValueRef originsWithLocalStorage(JSContextRef); 324 void deleteAllLocalStorage(); 325 void deleteLocalStorageForOrigin(JSStringRef originIdentifier); 326 void observeStorageTrackerNotifications(unsigned number); 327 void syncLocalStorage(); 328 329 void setShouldPaintBrokenImage(bool); 330 bool shouldPaintBrokenImage() const { return m_shouldPaintBrokenImage; } 331 332 static const unsigned maxViewWidth; 333 static const unsigned maxViewHeight; 334 335 void setMinimumTimerInterval(double); 336 337 private: 338 LayoutTestController(const std::string& testPathOrURL, const std::string& expectedPixelHash); 339 340 void setGeolocationPermissionCommon(bool allow); 341 342 bool m_dumpApplicationCacheDelegateCallbacks; 343 bool m_dumpAsAudio; 344 bool m_dumpAsPDF; 345 bool m_dumpAsText; 346 bool m_dumpBackForwardList; 347 bool m_dumpChildFrameScrollPositions; 348 bool m_dumpChildFramesAsText; 349 bool m_dumpDOMAsWebArchive; 350 bool m_dumpDatabaseCallbacks; 351 bool m_dumpEditingCallbacks; 352 bool m_dumpFrameLoadCallbacks; 353 bool m_dumpUserGestureInFrameLoadCallbacks; 354 bool m_dumpHistoryDelegateCallbacks; 355 bool m_dumpResourceLoadCallbacks; 356 bool m_dumpResourceResponseMIMETypes; 357 bool m_dumpSelectionRect; 358 bool m_dumpSourceAsWebArchive; 359 bool m_dumpStatusCallbacks; 360 bool m_dumpTitleChanges; 361 bool m_dumpIconChanges; 362 bool m_dumpVisitedLinksCallback; 363 bool m_dumpWillCacheResponse; 364 bool m_generatePixelResults; 365 bool m_callCloseOnWebViews; 366 bool m_canOpenWindows; 367 bool m_closeRemainingWindowsWhenComplete; 368 bool m_newWindowsCopyBackForwardList; 369 bool m_stopProvisionalFrameLoads; 370 bool m_testOnscreen; 371 bool m_testRepaint; 372 bool m_testRepaintSweepHorizontally; 373 bool m_waitToDump; // True if waitUntilDone() has been called, but notifyDone() has not yet been called. 374 bool m_willSendRequestReturnsNull; 375 bool m_willSendRequestReturnsNullOnRedirect; 376 bool m_windowIsKey; 377 bool m_alwaysAcceptCookies; 378 bool m_globalFlag; 379 bool m_isGeolocationPermissionSet; 380 bool m_geolocationPermission; 381 bool m_handlesAuthenticationChallenges; 382 bool m_isPrinting; 383 bool m_deferMainResourceDataLoad; 384 bool m_shouldPaintBrokenImage; 385 386 std::string m_authenticationUsername; 387 std::string m_authenticationPassword; 388 std::string m_testPathOrURL; 389 std::string m_expectedPixelHash; // empty string if no hash 390 391 std::set<std::string> m_willSendRequestClearHeaders; 392 393 // base64 encoded WAV audio data is stored here. 394 std::string m_encodedAudioData; 395 396 // origins which have been granted desktop notification access 397 std::vector<JSStringRef> m_desktopNotificationAllowedOrigins; 398 399 std::map<std::string, std::string> m_URLsToRedirect; 400 401 static JSClassRef getJSClass(); 402 static JSStaticValue* staticValues(); 403 static JSStaticFunction* staticFunctions(); 404 }; 405 406 #endif // LayoutTestController_h 407