| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_TEST_RUNNER_WEB_TEST_DELEGATE_H_ | |
| 6 #define COMPONENTS_TEST_RUNNER_WEB_TEST_DELEGATE_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/callback_forward.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "third_party/WebKit/public/platform/WebString.h" | |
| 15 #include "third_party/WebKit/public/platform/WebURL.h" | |
| 16 #include "third_party/WebKit/public/platform/WebVector.h" | |
| 17 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationType.h" | |
| 18 | |
| 19 #define WEBTESTRUNNER_NEW_HISTORY_CAPTURE | |
| 20 | |
| 21 namespace base { | |
| 22 class DictionaryValue; | |
| 23 } | |
| 24 | |
| 25 namespace blink { | |
| 26 class WebDeviceMotionData; | |
| 27 class WebDeviceOrientationData; | |
| 28 class WebFrame; | |
| 29 class WebInputEvent; | |
| 30 class WebLocalFrame; | |
| 31 class WebMediaStream; | |
| 32 class WebPlugin; | |
| 33 struct WebPluginParams; | |
| 34 struct WebSize; | |
| 35 class WebURLRequest; | |
| 36 class WebURLResponse; | |
| 37 class WebView; | |
| 38 } | |
| 39 | |
| 40 namespace cc { | |
| 41 class SharedBitmapManager; | |
| 42 } | |
| 43 | |
| 44 namespace test_runner { | |
| 45 | |
| 46 class GamepadController; | |
| 47 class WebTask; | |
| 48 class WebWidgetTestProxyBase; | |
| 49 struct TestPreferences; | |
| 50 | |
| 51 class WebTestDelegate { | |
| 52 public: | |
| 53 // Set and clear the edit command to execute on the next call to | |
| 54 // WebViewClient::handleCurrentKeyboardEvent(). | |
| 55 virtual void ClearEditCommand() = 0; | |
| 56 virtual void SetEditCommand(const std::string& name, | |
| 57 const std::string& value) = 0; | |
| 58 | |
| 59 // Sets gamepad provider to be used for tests. | |
| 60 virtual void SetGamepadProvider(GamepadController* controller) = 0; | |
| 61 | |
| 62 // Set data to return when registering via | |
| 63 // Platform::setDeviceLightListener(). | |
| 64 virtual void SetDeviceLightData(const double data) = 0; | |
| 65 // Set data to return when registering via | |
| 66 // Platform::setDeviceMotionListener(). | |
| 67 virtual void SetDeviceMotionData(const blink::WebDeviceMotionData& data) = 0; | |
| 68 // Set data to return when registering via | |
| 69 // Platform::setDeviceOrientationListener(). | |
| 70 virtual void SetDeviceOrientationData( | |
| 71 const blink::WebDeviceOrientationData& data) = 0; | |
| 72 | |
| 73 // Add a message to the text dump for the layout test. | |
| 74 virtual void PrintMessage(const std::string& message) = 0; | |
| 75 | |
| 76 // The delegate takes ownership of the WebTask objects and is responsible | |
| 77 // for deleting them. | |
| 78 virtual void PostTask(const base::Closure& task) = 0; | |
| 79 virtual void PostDelayedTask(const base::Closure& task, long long ms) = 0; | |
| 80 | |
| 81 // Register a new isolated filesystem with the given files, and return the | |
| 82 // new filesystem id. | |
| 83 virtual blink::WebString RegisterIsolatedFileSystem( | |
| 84 const blink::WebVector<blink::WebString>& absolute_filenames) = 0; | |
| 85 | |
| 86 // Gets the current time in milliseconds since the UNIX epoch. | |
| 87 virtual long long GetCurrentTimeInMillisecond() = 0; | |
| 88 | |
| 89 // Convert the provided relative path into an absolute path. | |
| 90 virtual blink::WebString GetAbsoluteWebStringFromUTF8Path( | |
| 91 const std::string& path) = 0; | |
| 92 | |
| 93 // Reads in the given file and returns its contents as data URL. | |
| 94 virtual blink::WebURL LocalFileToDataURL(const blink::WebURL& file_url) = 0; | |
| 95 | |
| 96 // Replaces file:///tmp/LayoutTests/ with the actual path to the | |
| 97 // LayoutTests directory, or rewrite URLs generated from absolute | |
| 98 // path links in web-platform-tests. | |
| 99 virtual blink::WebURL RewriteLayoutTestsURL(const std::string& utf8_url, | |
| 100 bool is_wpt_mode) = 0; | |
| 101 | |
| 102 // Manages the settings to used for layout tests. | |
| 103 virtual TestPreferences* Preferences() = 0; | |
| 104 virtual void ApplyPreferences() = 0; | |
| 105 | |
| 106 // Enables or disables synchronous resize mode. When enabled, all | |
| 107 // window-sizing machinery is | |
| 108 // short-circuited inside the renderer. This mode is necessary for some tests | |
| 109 // that were written | |
| 110 // before browsers had multi-process architecture and rely on window resizes | |
| 111 // to happen synchronously. | |
| 112 // The function has "unfortunate" it its name because we must strive to remove | |
| 113 // all tests | |
| 114 // that rely on this... well, unfortunate behavior. See | |
| 115 // http://crbug.com/309760 for the plan. | |
| 116 virtual void UseUnfortunateSynchronousResizeMode(bool enable) = 0; | |
| 117 | |
| 118 // Controls auto resize mode. | |
| 119 virtual void EnableAutoResizeMode(const blink::WebSize& min_size, | |
| 120 const blink::WebSize& max_size) = 0; | |
| 121 virtual void DisableAutoResizeMode(const blink::WebSize& new_size) = 0; | |
| 122 | |
| 123 // Clears DevTools' localStorage when an inspector test is started. | |
| 124 virtual void ClearDevToolsLocalStorage() = 0; | |
| 125 | |
| 126 // Opens and closes the inspector. | |
| 127 virtual void ShowDevTools(const std::string& settings, | |
| 128 const std::string& frontend_url) = 0; | |
| 129 virtual void CloseDevTools() = 0; | |
| 130 | |
| 131 // Evaluate the given script in the DevTools agent. | |
| 132 virtual void EvaluateInWebInspector(int call_id, | |
| 133 const std::string& script) = 0; | |
| 134 | |
| 135 // Evaluate the given script in the inspector overlay page. | |
| 136 virtual std::string EvaluateInWebInspectorOverlay( | |
| 137 const std::string& script) = 0; | |
| 138 | |
| 139 // Controls WebSQL databases. | |
| 140 virtual void ClearAllDatabases() = 0; | |
| 141 virtual void SetDatabaseQuota(int quota) = 0; | |
| 142 | |
| 143 // Controls Web Notifications. | |
| 144 virtual void SimulateWebNotificationClick( | |
| 145 const std::string& title, | |
| 146 int action_index, | |
| 147 const base::NullableString16& reply) = 0; | |
| 148 virtual void SimulateWebNotificationClose(const std::string& title, | |
| 149 bool by_user) = 0; | |
| 150 | |
| 151 // Controls the device scale factor of the main WebView for hidpi tests. | |
| 152 virtual void SetDeviceScaleFactor(float factor) = 0; | |
| 153 | |
| 154 // When use-zoom-for-dsf mode is enabled, this returns the scale to | |
| 155 // convert from window coordinates to viewport coordinates. When | |
| 156 // use-zoom-for-dsf is disabled, this return always 1.0f. | |
| 157 virtual float GetWindowToViewportScale() = 0; | |
| 158 | |
| 159 // Converts |event| from screen coordinates used by test_runner::EventSender | |
| 160 // into coordinates that are understood by the widget associated with | |
| 161 // |web_widget_test_proxy_base|. Returns nullptr if no transformation was | |
| 162 // necessary (e.g. for a keyboard event OR if widget requires no scaling | |
| 163 // and has coordinates starting at (0,0)). | |
| 164 virtual std::unique_ptr<blink::WebInputEvent> | |
| 165 TransformScreenToWidgetCoordinates( | |
| 166 test_runner::WebWidgetTestProxyBase* web_widget_test_proxy_base, | |
| 167 const blink::WebInputEvent& event) = 0; | |
| 168 | |
| 169 // Gets WebWidgetTestProxyBase associated with |frame| (associated with either | |
| 170 // a RenderView or a RenderWidget for the local root). | |
| 171 virtual test_runner::WebWidgetTestProxyBase* GetWebWidgetTestProxyBase( | |
| 172 blink::WebLocalFrame* frame) = 0; | |
| 173 | |
| 174 // Enable zoom-for-dsf option. | |
| 175 virtual void EnableUseZoomForDSF() = 0; | |
| 176 | |
| 177 // Returns whether or not the use-zoom-for-dsf flag is enabled. | |
| 178 virtual bool IsUseZoomForDSFEnabled() = 0; | |
| 179 | |
| 180 // Change the device color profile while running a layout test. | |
| 181 virtual void SetDeviceColorProfile(const std::string& name) = 0; | |
| 182 | |
| 183 // Set the bluetooth adapter while running a layout test, uses Mojo to | |
| 184 // communicate with the browser. | |
| 185 virtual void SetBluetoothFakeAdapter(const std::string& adapter_name, | |
| 186 const base::Closure& callback) = 0; | |
| 187 | |
| 188 // If |enable| is true makes the Bluetooth chooser record its input and wait | |
| 189 // for instructions from the test program on how to proceed. Otherwise | |
| 190 // fall backs to the browser's default chooser. | |
| 191 virtual void SetBluetoothManualChooser(bool enable) = 0; | |
| 192 | |
| 193 // Returns the events recorded since the last call to this function. | |
| 194 virtual void GetBluetoothManualChooserEvents( | |
| 195 const base::Callback<void(const std::vector<std::string>& events)>& | |
| 196 callback) = 0; | |
| 197 | |
| 198 // Calls the BluetoothChooser::EventHandler with the arguments here. Valid | |
| 199 // event strings are: | |
| 200 // * "cancel" - simulates the user canceling the chooser. | |
| 201 // * "select" - simulates the user selecting a device whose device ID is in | |
| 202 // |argument|. | |
| 203 virtual void SendBluetoothManualChooserEvent(const std::string& event, | |
| 204 const std::string& argument) = 0; | |
| 205 | |
| 206 // Controls which WebView should be focused. | |
| 207 virtual void SetFocus(blink::WebView* web_view, bool focus) = 0; | |
| 208 | |
| 209 // Controls whether all cookies should be accepted or writing cookies in a | |
| 210 // third-party context is blocked. | |
| 211 virtual void SetBlockThirdPartyCookies(bool block) = 0; | |
| 212 | |
| 213 // The same as RewriteLayoutTestsURL unless the resource is a path starting | |
| 214 // with /tmp/, then return a file URL to a temporary file. | |
| 215 virtual std::string PathToLocalResource(const std::string& resource) = 0; | |
| 216 | |
| 217 // Sets the POSIX locale of the current process. | |
| 218 virtual void SetLocale(const std::string& locale) = 0; | |
| 219 | |
| 220 // Invoked when layout test runtime flags change. | |
| 221 virtual void OnLayoutTestRuntimeFlagsChanged( | |
| 222 const base::DictionaryValue& changed_values) = 0; | |
| 223 | |
| 224 // Invoked when the test finished. | |
| 225 virtual void TestFinished() = 0; | |
| 226 | |
| 227 // Invoked when the embedder should close all but the main WebView. | |
| 228 virtual void CloseRemainingWindows() = 0; | |
| 229 | |
| 230 virtual void DeleteAllCookies() = 0; | |
| 231 | |
| 232 // Returns the length of the back/forward history of the main WebView. | |
| 233 virtual int NavigationEntryCount() = 0; | |
| 234 | |
| 235 // The following trigger navigations on the main WebView. | |
| 236 virtual void GoToOffset(int offset) = 0; | |
| 237 virtual void Reload() = 0; | |
| 238 virtual void LoadURLForFrame(const blink::WebURL& url, | |
| 239 const std::string& frame_name) = 0; | |
| 240 | |
| 241 // Returns true if resource requests to external URLs should be permitted. | |
| 242 virtual bool AllowExternalPages() = 0; | |
| 243 | |
| 244 // Fetch the manifest for a given WebView from the given url. | |
| 245 virtual void FetchManifest( | |
| 246 blink::WebView* view, | |
| 247 const GURL& url, | |
| 248 const base::Callback<void(const blink::WebURLResponse& response, | |
| 249 const std::string& data)>& callback) = 0; | |
| 250 | |
| 251 // Sends a message to the LayoutTestPermissionManager in order for it to | |
| 252 // update its database. | |
| 253 virtual void SetPermission(const std::string& permission_name, | |
| 254 const std::string& permission_value, | |
| 255 const GURL& origin, | |
| 256 const GURL& embedding_origin) = 0; | |
| 257 | |
| 258 // Clear all the permissions set via SetPermission(). | |
| 259 virtual void ResetPermissions() = 0; | |
| 260 | |
| 261 // Add content MediaStream classes to the Blink MediaStream ones. | |
| 262 virtual bool AddMediaStreamVideoSourceAndTrack( | |
| 263 blink::WebMediaStream* stream) = 0; | |
| 264 virtual bool AddMediaStreamAudioSourceAndTrack( | |
| 265 blink::WebMediaStream* stream) = 0; | |
| 266 | |
| 267 virtual cc::SharedBitmapManager* GetSharedBitmapManager() = 0; | |
| 268 | |
| 269 // Causes the beforeinstallprompt event to be sent to the renderer. | |
| 270 // |event_platforms| are the platforms to be sent with the event. Once the | |
| 271 // event listener completes, |callback| will be called with a boolean | |
| 272 // argument. This argument will be true if the event is canceled, and false | |
| 273 // otherwise. | |
| 274 virtual void DispatchBeforeInstallPromptEvent( | |
| 275 const std::vector<std::string>& event_platforms, | |
| 276 const base::Callback<void(bool)>& callback) = 0; | |
| 277 | |
| 278 // Resolves the in-flight beforeinstallprompt event userChoice promise with a | |
| 279 // platform of |platform|. | |
| 280 virtual void ResolveBeforeInstallPromptPromise( | |
| 281 const std::string& platform) = 0; | |
| 282 | |
| 283 virtual blink::WebPlugin* CreatePluginPlaceholder( | |
| 284 blink::WebLocalFrame* frame, | |
| 285 const blink::WebPluginParams& params) = 0; | |
| 286 | |
| 287 virtual float GetDeviceScaleFactor() const = 0; | |
| 288 | |
| 289 // Run all pending idle tasks, and then run callback. | |
| 290 virtual void RunIdleTasks(const base::Closure& callback) = 0; | |
| 291 | |
| 292 // Forces a text input state update for the client of WebFrameWidget | |
| 293 // associated with |frame|. | |
| 294 virtual void ForceTextInputStateUpdate(blink::WebFrame* frame) = 0; | |
| 295 | |
| 296 // PlzNavigate | |
| 297 // Indicates if the navigation was initiated by the browser or renderer. | |
| 298 virtual bool IsNavigationInitiatedByRenderer( | |
| 299 const blink::WebURLRequest& request) = 0; | |
| 300 }; | |
| 301 | |
| 302 } // namespace test_runner | |
| 303 | |
| 304 #endif // COMPONENTS_TEST_RUNNER_WEB_TEST_DELEGATE_H_ | |
| OLD | NEW |