TestController.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright (C) 2010 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 TestController_h
  26. #define TestController_h
  27. #include "WebNotificationProvider.h"
  28. #include "WorkQueueManager.h"
  29. #include <GeolocationProviderMock.h>
  30. #include <WebKit2/WKRetainPtr.h>
  31. #include <string>
  32. #include <vector>
  33. #include <wtf/OwnPtr.h>
  34. #include <wtf/Vector.h>
  35. namespace WTR {
  36. class TestInvocation;
  37. class PlatformWebView;
  38. class EventSenderProxy;
  39. // FIXME: Rename this TestRunner?
  40. class TestController {
  41. public:
  42. static TestController& shared();
  43. static const unsigned viewWidth;
  44. static const unsigned viewHeight;
  45. static const unsigned w3cSVGViewWidth;
  46. static const unsigned w3cSVGViewHeight;
  47. TestController(int argc, const char* argv[]);
  48. ~TestController();
  49. bool verbose() const { return m_verbose; }
  50. WKStringRef injectedBundlePath() { return m_injectedBundlePath.get(); }
  51. WKStringRef testPluginDirectory() { return m_testPluginDirectory.get(); }
  52. PlatformWebView* mainWebView() { return m_mainWebView.get(); }
  53. WKContextRef context() { return m_context.get(); }
  54. void ensureViewSupportsOptions(WKDictionaryRef options);
  55. // Runs the run loop until `done` is true or the timeout elapses.
  56. enum TimeoutDuration { ShortTimeout, LongTimeout, NoTimeout, CustomTimeout };
  57. bool useWaitToDumpWatchdogTimer() { return m_useWaitToDumpWatchdogTimer; }
  58. void runUntil(bool& done, TimeoutDuration);
  59. void notifyDone();
  60. int getCustomTimeout();
  61. bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
  62. void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
  63. void simulateWebNotificationClick(uint64_t notificationID);
  64. // Geolocation.
  65. void setGeolocationPermission(bool);
  66. void setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed);
  67. void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage);
  68. void handleGeolocationPermissionRequest(WKGeolocationPermissionRequestRef);
  69. // Policy delegate.
  70. void setCustomPolicyDelegate(bool enabled, bool permissive);
  71. // Page Visibility.
  72. void setVisibilityState(WKPageVisibilityState, bool isInitialState);
  73. bool resetStateToConsistentValues();
  74. WorkQueueManager& workQueueManager() { return m_workQueueManager; }
  75. void setHandlesAuthenticationChallenges(bool value) { m_handlesAuthenticationChallenges = value; }
  76. void setAuthenticationUsername(String username) { m_authenticationUsername = username; }
  77. void setAuthenticationPassword(String password) { m_authenticationPassword = password; }
  78. private:
  79. void initialize(int argc, const char* argv[]);
  80. void createWebViewWithOptions(WKDictionaryRef);
  81. void run();
  82. void runTestingServerLoop();
  83. bool runTest(const char* pathOrURL);
  84. void platformInitialize();
  85. void platformDestroy();
  86. void platformInitializeContext();
  87. void platformRunUntil(bool& done, double timeout);
  88. void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
  89. void initializeInjectedBundlePath();
  90. void initializeTestPluginDirectory();
  91. void decidePolicyForGeolocationPermissionRequestIfPossible();
  92. // WKContextInjectedBundleClient
  93. static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*);
  94. static void didReceiveSynchronousMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData, const void*);
  95. void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
  96. WKRetainPtr<WKTypeRef> didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
  97. void didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef messageBodyDictionary, bool synchronous);
  98. // WKPageLoaderClient
  99. static void didCommitLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
  100. void didCommitLoadForFrame(WKPageRef, WKFrameRef);
  101. static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void*);
  102. void didFinishLoadForFrame(WKPageRef, WKFrameRef);
  103. static void processDidCrash(WKPageRef, const void* clientInfo);
  104. void processDidCrash();
  105. static void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef, const void*);
  106. void decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef);
  107. static void unavailablePluginButtonClicked(WKPageRef, WKPluginUnavailabilityReason, WKDictionaryRef, const void*);
  108. static void didReceiveAuthenticationChallengeInFrame(WKPageRef, WKFrameRef, WKAuthenticationChallengeRef, const void *clientInfo);
  109. void didReceiveAuthenticationChallengeInFrame(WKPageRef, WKFrameRef, WKAuthenticationChallengeRef);
  110. // WKPagePolicyClient
  111. static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
  112. void decidePolicyForNavigationAction(WKFramePolicyListenerRef);
  113. static void decidePolicyForResponse(WKPageRef, WKFrameRef, WKURLResponseRef, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
  114. void decidePolicyForResponse(WKFrameRef, WKURLResponseRef, WKFramePolicyListenerRef);
  115. static WKPageRef createOtherPage(WKPageRef oldPage, WKURLRequestRef, WKDictionaryRef, WKEventModifiers, WKEventMouseButton, const void*);
  116. static void runModal(WKPageRef, const void* clientInfo);
  117. static void runModal(PlatformWebView*);
  118. static const char* libraryPathForTesting();
  119. static const char* platformLibraryPathForTesting();
  120. OwnPtr<TestInvocation> m_currentInvocation;
  121. bool m_verbose;
  122. bool m_printSeparators;
  123. bool m_usingServerMode;
  124. bool m_gcBetweenTests;
  125. bool m_shouldDumpPixelsForAllTests;
  126. std::vector<std::string> m_paths;
  127. WKRetainPtr<WKStringRef> m_injectedBundlePath;
  128. WKRetainPtr<WKStringRef> m_testPluginDirectory;
  129. WebNotificationProvider m_webNotificationProvider;
  130. OwnPtr<PlatformWebView> m_mainWebView;
  131. WKRetainPtr<WKContextRef> m_context;
  132. WKRetainPtr<WKPageGroupRef> m_pageGroup;
  133. enum State {
  134. Initial,
  135. Resetting,
  136. RunningTest
  137. };
  138. State m_state;
  139. bool m_doneResetting;
  140. double m_longTimeout;
  141. double m_shortTimeout;
  142. double m_noTimeout;
  143. bool m_useWaitToDumpWatchdogTimer;
  144. bool m_forceNoTimeout;
  145. int m_timeout;
  146. bool m_didPrintWebProcessCrashedMessage;
  147. bool m_shouldExitWhenWebProcessCrashes;
  148. bool m_beforeUnloadReturnValue;
  149. OwnPtr<GeolocationProviderMock> m_geolocationProvider;
  150. Vector<WKRetainPtr<WKGeolocationPermissionRequestRef> > m_geolocationPermissionRequests;
  151. bool m_isGeolocationPermissionSet;
  152. bool m_isGeolocationPermissionAllowed;
  153. bool m_policyDelegateEnabled;
  154. bool m_policyDelegatePermissive;
  155. bool m_handlesAuthenticationChallenges;
  156. String m_authenticationUsername;
  157. String m_authenticationPassword;
  158. #if PLATFORM(MAC) || PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
  159. OwnPtr<EventSenderProxy> m_eventSenderProxy;
  160. #endif
  161. #if PLATFORM(QT)
  162. class RunLoop;
  163. RunLoop* m_runLoop;
  164. #endif
  165. WorkQueueManager m_workQueueManager;
  166. };
  167. } // namespace WTR
  168. #endif // TestController_h