TestRunner.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. #ifndef TestRunner_h
  26. #define TestRunner_h
  27. #include "JSWrappable.h"
  28. #include <JavaScriptCore/JSRetainPtr.h>
  29. #include <WebKit2/WKBundleScriptWorld.h>
  30. #include <WebKit2/WKRetainPtr.h>
  31. #include <string>
  32. #include <wtf/PassRefPtr.h>
  33. #if PLATFORM(MAC)
  34. #include <wtf/RetainPtr.h>
  35. #include <CoreFoundation/CFRunLoop.h>
  36. typedef RetainPtr<CFRunLoopTimerRef> PlatformTimerRef;
  37. #elif PLATFORM(WIN)
  38. typedef UINT_PTR PlatformTimerRef;
  39. #elif PLATFORM(QT)
  40. #include <QTimer>
  41. typedef QTimer PlatformTimerRef;
  42. #elif PLATFORM(GTK)
  43. typedef unsigned int PlatformTimerRef;
  44. #elif PLATFORM(MANX)
  45. typedef void* PlatformTimerRef;
  46. #elif PLATFORM(EFL)
  47. #if USE(EO)
  48. typedef struct _Eo Ecore_Timer;
  49. #else
  50. typedef struct _Ecore_Timer Ecore_Timer;
  51. #endif
  52. typedef Ecore_Timer* PlatformTimerRef;
  53. #endif
  54. namespace WTR {
  55. class TestRunner : public JSWrappable {
  56. public:
  57. static PassRefPtr<TestRunner> create();
  58. virtual ~TestRunner();
  59. // JSWrappable
  60. virtual JSClassRef wrapperClass();
  61. void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
  62. // The basics.
  63. void dumpAsText(bool dumpPixels);
  64. void waitForPolicyDelegate();
  65. void dumpChildFramesAsText() { m_whatToDump = AllFramesText; }
  66. void waitUntilDone();
  67. void notifyDone();
  68. double preciseTime();
  69. // Other dumping.
  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; }
  85. void setShouldDumpFrameLoadCallbacks(bool value) { m_dumpFrameLoadCallbacks = value; }
  86. void setShouldDumpProgressFinishedCallback(bool value) { m_dumpProgressFinishedCallback = value; }
  87. // Special options.
  88. void keepWebHistory();
  89. void setAcceptsEditing(bool value) { m_shouldAllowEditing = value; }
  90. void setCanOpenWindows(bool);
  91. void setCloseRemainingWindowsWhenComplete(bool value) { m_shouldCloseExtraWindows = value; }
  92. void setXSSAuditorEnabled(bool);
  93. void setAllowUniversalAccessFromFileURLs(bool);
  94. void setAllowFileAccessFromFileURLs(bool);
  95. void setPluginsEnabled(bool);
  96. void setJavaScriptCanAccessClipboard(bool);
  97. void setPrivateBrowsingEnabled(bool);
  98. void setPopupBlockingEnabled(bool);
  99. void setAuthorAndUserStylesEnabled(bool);
  100. void setCustomPolicyDelegate(bool enabled, bool permissive = false);
  101. void addOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains);
  102. void removeOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef destinationProtocol, JSStringRef destinationHost, bool allowDestinationSubdomains);
  103. void setUserStyleSheetEnabled(bool);
  104. void setUserStyleSheetLocation(JSStringRef);
  105. void setSpatialNavigationEnabled(bool);
  106. void setTabKeyCyclesThroughElements(bool);
  107. void setSerializeHTTPLoads();
  108. void dispatchPendingLoadRequests();
  109. void setCacheModel(int);
  110. void setAsynchronousSpellCheckingEnabled(bool);
  111. // Special DOM functions.
  112. void clearBackForwardList();
  113. void execCommand(JSStringRef name, JSStringRef argument);
  114. bool isCommandEnabled(JSStringRef name);
  115. unsigned windowCount();
  116. // Repaint testing.
  117. void testRepaint() { m_testRepaint = true; }
  118. void repaintSweepHorizontally() { m_testRepaintSweepHorizontally = true; }
  119. void display();
  120. // UserContent testing.
  121. void addUserScript(JSStringRef source, bool runAtStart, bool allFrames);
  122. void addUserStyleSheet(JSStringRef source, bool allFrames);
  123. // Text search testing.
  124. bool findString(JSStringRef, JSValueRef optionsArray);
  125. // Local storage
  126. void clearAllDatabases();
  127. void setDatabaseQuota(uint64_t);
  128. JSRetainPtr<JSStringRef> pathToLocalResource(JSStringRef);
  129. // Application Cache
  130. void clearAllApplicationCaches();
  131. void clearApplicationCacheForOrigin(JSStringRef origin);
  132. void setAppCacheMaximumSize(uint64_t);
  133. long long applicationCacheDiskUsageForOrigin(JSStringRef origin);
  134. void setApplicationCacheOriginQuota(unsigned long long);
  135. void disallowIncreaseForApplicationCacheQuota();
  136. bool shouldDisallowIncreaseForApplicationCacheQuota() { return m_disallowIncreaseForApplicationCacheQuota; }
  137. JSValueRef originsWithApplicationCache();
  138. // Printing
  139. bool isPageBoxVisible(int pageIndex);
  140. bool isPrinting() { return m_isPrinting; }
  141. void setPrinting() { m_isPrinting = true; }
  142. // Authentication
  143. void setHandlesAuthenticationChallenges(bool);
  144. void setAuthenticationUsername(JSStringRef);
  145. void setAuthenticationPassword(JSStringRef);
  146. void setValueForUser(JSContextRef, JSValueRef element, JSStringRef value);
  147. // Audio testing.
  148. void setAudioResult(JSContextRef, JSValueRef data);
  149. enum WhatToDump { RenderTree, MainFrameText, AllFramesText, Audio, DOMAsWebArchive };
  150. WhatToDump whatToDump() const { return m_whatToDump; }
  151. bool shouldDumpAllFrameScrollPositions() const { return m_shouldDumpAllFrameScrollPositions; }
  152. bool shouldDumpBackForwardListsForAllWindows() const { return m_shouldDumpBackForwardListsForAllWindows; }
  153. bool shouldDumpEditingCallbacks() const { return m_dumpEditingCallbacks; }
  154. bool shouldDumpMainFrameScrollPosition() const { return m_whatToDump == RenderTree; }
  155. bool shouldDumpStatusCallbacks() const { return m_dumpStatusCallbacks; }
  156. bool shouldDumpTitleChanges() const { return m_dumpTitleChanges; }
  157. bool shouldDumpPixels() const { return m_dumpPixels; }
  158. bool shouldDumpFullScreenCallbacks() const { return m_dumpFullScreenCallbacks; }
  159. bool shouldDumpFrameLoadCallbacks() const { return m_dumpFrameLoadCallbacks; }
  160. bool shouldDumpProgressFinishedCallback() const { return m_dumpProgressFinishedCallback; }
  161. bool shouldDumpResourceLoadCallbacks() const { return m_dumpResourceLoadCallbacks; }
  162. bool shouldDumpResourceResponseMIMETypes() const { return m_dumpResourceResponseMIMETypes; }
  163. bool shouldDumpWillCacheResponse() const { return m_dumpWillCacheResponse; }
  164. bool shouldDumpApplicationCacheDelegateCallbacks() const { return m_dumpApplicationCacheDelegateCallbacks; }
  165. bool shouldDumpDatabaseCallbacks() const { return m_dumpDatabaseCallbacks; }
  166. bool shouldDumpSelectionRect() const { return m_dumpSelectionRect; }
  167. bool isPolicyDelegateEnabled() const { return m_policyDelegateEnabled; }
  168. bool isPolicyDelegatePermissive() const { return m_policyDelegatePermissive; }
  169. bool waitToDump() const { return m_waitToDump; }
  170. void waitToDumpWatchdogTimerFired();
  171. void invalidateWaitToDumpWatchdogTimer();
  172. bool shouldAllowEditing() const { return m_shouldAllowEditing; }
  173. bool shouldCloseExtraWindowsAfterRunningTest() const { return m_shouldCloseExtraWindows; }
  174. void evaluateScriptInIsolatedWorld(JSContextRef, unsigned worldID, JSStringRef script);
  175. static unsigned worldIDForWorld(WKBundleScriptWorldRef);
  176. void showWebInspector();
  177. void closeWebInspector();
  178. void evaluateInWebInspector(long callId, JSStringRef script);
  179. void setPOSIXLocale(JSStringRef);
  180. bool willSendRequestReturnsNull() const { return m_willSendRequestReturnsNull; }
  181. void setWillSendRequestReturnsNull(bool f) { m_willSendRequestReturnsNull = f; }
  182. bool willSendRequestReturnsNullOnRedirect() const { return m_willSendRequestReturnsNullOnRedirect; }
  183. void setWillSendRequestReturnsNullOnRedirect(bool f) { m_willSendRequestReturnsNullOnRedirect = f; }
  184. void setTextDirection(JSStringRef);
  185. void setShouldStayOnPageAfterHandlingBeforeUnload(bool);
  186. void setDefersLoading(bool);
  187. void setStopProvisionalFrameLoads() { m_shouldStopProvisionalFrameLoads = true; }
  188. bool shouldStopProvisionalFrameLoads() const { return m_shouldStopProvisionalFrameLoads; }
  189. bool globalFlag() const { return m_globalFlag; }
  190. void setGlobalFlag(bool value) { m_globalFlag = value; }
  191. void addChromeInputField(JSValueRef);
  192. void removeChromeInputField(JSValueRef);
  193. void focusWebView(JSValueRef);
  194. void setBackingScaleFactor(double, JSValueRef);
  195. void setWindowIsKey(bool);
  196. void callAddChromeInputFieldCallback();
  197. void callRemoveChromeInputFieldCallback();
  198. void callFocusWebViewCallback();
  199. void callSetBackingScaleFactorCallback();
  200. void overridePreference(JSStringRef preference, JSStringRef value);
  201. // Cookies testing
  202. void setAlwaysAcceptCookies(bool);
  203. // Custom full screen behavior.
  204. void setHasCustomFullScreenBehavior(bool value) { m_customFullScreenBehavior = value; }
  205. bool hasCustomFullScreenBehavior() const { return m_customFullScreenBehavior; }
  206. // Web notifications.
  207. void grantWebNotificationPermission(JSStringRef origin);
  208. void denyWebNotificationPermission(JSStringRef origin);
  209. void removeAllWebNotificationPermissions();
  210. void simulateWebNotificationClick(JSValueRef notification);
  211. // Geolocation.
  212. void setGeolocationPermission(bool);
  213. void setMockGeolocationPosition(double latitude, double longitude, double accuracy, JSValueRef altitude, JSValueRef altitudeAccuracy, JSValueRef heading, JSValueRef speed);
  214. void setMockGeolocationPositionUnavailableError(JSStringRef message);
  215. JSRetainPtr<JSStringRef> platformName();
  216. void setPageVisibility(JSStringRef state);
  217. void resetPageVisibility();
  218. bool callShouldCloseOnWebView();
  219. void setCustomTimeout(int duration);
  220. // Work queue.
  221. void queueBackNavigation(unsigned howFarBackward);
  222. void queueForwardNavigation(unsigned howFarForward);
  223. void queueLoad(JSStringRef url, JSStringRef target);
  224. void queueLoadHTMLString(JSStringRef content, JSStringRef baseURL, JSStringRef unreachableURL);
  225. void queueReload();
  226. void queueLoadingScript(JSStringRef script);
  227. void queueNonLoadingScript(JSStringRef script);
  228. bool secureEventInputIsEnabled() const;
  229. private:
  230. static const double waitToDumpWatchdogTimerInterval;
  231. TestRunner();
  232. void platformInitialize();
  233. void initializeWaitToDumpWatchdogTimerIfNeeded();
  234. WhatToDump m_whatToDump;
  235. bool m_shouldDumpAllFrameScrollPositions;
  236. bool m_shouldDumpBackForwardListsForAllWindows;
  237. bool m_shouldAllowEditing;
  238. bool m_shouldCloseExtraWindows;
  239. bool m_dumpEditingCallbacks;
  240. bool m_dumpStatusCallbacks;
  241. bool m_dumpTitleChanges;
  242. bool m_dumpPixels;
  243. bool m_dumpSelectionRect;
  244. bool m_dumpFullScreenCallbacks;
  245. bool m_dumpFrameLoadCallbacks;
  246. bool m_dumpProgressFinishedCallback;
  247. bool m_dumpResourceLoadCallbacks;
  248. bool m_dumpResourceResponseMIMETypes;
  249. bool m_dumpWillCacheResponse;
  250. bool m_dumpApplicationCacheDelegateCallbacks;
  251. bool m_dumpDatabaseCallbacks;
  252. bool m_disallowIncreaseForApplicationCacheQuota;
  253. bool m_waitToDump; // True if waitUntilDone() has been called, but notifyDone() has not yet been called.
  254. bool m_testRepaint;
  255. bool m_testRepaintSweepHorizontally;
  256. bool m_isPrinting;
  257. bool m_willSendRequestReturnsNull;
  258. bool m_willSendRequestReturnsNullOnRedirect;
  259. bool m_shouldStopProvisionalFrameLoads;
  260. bool m_policyDelegateEnabled;
  261. bool m_policyDelegatePermissive;
  262. bool m_globalFlag;
  263. bool m_customFullScreenBehavior;
  264. int m_timeout;
  265. bool m_userStyleSheetEnabled;
  266. WKRetainPtr<WKStringRef> m_userStyleSheetLocation;
  267. PlatformTimerRef m_waitToDumpWatchdogTimer;
  268. };
  269. } // namespace WTR
  270. #endif // TestRunner_h