Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / components / test_runner / web_test_delegate.h
blob190618059bf6f53936a04e997fad4496f5d27f35
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.
5 #ifndef COMPONENTS_TEST_RUNNER_WEB_TEST_DELEGATE_H_
6 #define COMPONENTS_TEST_RUNNER_WEB_TEST_DELEGATE_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback_forward.h"
12 #include "base/memory/ref_counted.h"
13 #include "third_party/WebKit/public/platform/WebString.h"
14 #include "third_party/WebKit/public/platform/WebURL.h"
15 #include "third_party/WebKit/public/platform/WebVector.h"
16 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScreenOrientationType.h"
18 #define WEBTESTRUNNER_NEW_HISTORY_CAPTURE
20 namespace blink {
21 class WebBatteryStatus;
22 class WebDeviceMotionData;
23 class WebDeviceOrientationData;
24 class WebFrame;
25 class WebGamepad;
26 class WebGamepads;
27 class WebHistoryItem;
28 class WebLayer;
29 class WebLocalFrame;
30 class WebPlugin;
31 struct WebPluginParams;
32 class WebURLResponse;
33 class WebView;
34 struct WebRect;
35 struct WebSize;
36 struct WebURLError;
39 namespace cc {
40 class TextureLayer;
41 class TextureLayerClient;
42 class SharedBitmapManager;
45 namespace test_runner {
47 class DeviceLightData;
48 class GamepadController;
49 class WebTask;
50 class WebTestProxyBase;
51 struct TestPreferences;
53 class WebTestDelegate {
54 public:
55 // Set and clear the edit command to execute on the next call to
56 // WebViewClient::handleCurrentKeyboardEvent().
57 virtual void ClearEditCommand() = 0;
58 virtual void SetEditCommand(const std::string& name,
59 const std::string& value) = 0;
61 // Sets gamepad provider to be used for tests.
62 virtual void SetGamepadProvider(GamepadController* controller) = 0;
64 // Set data to return when registering via
65 // Platform::setDeviceLightListener().
66 virtual void SetDeviceLightData(const double data) = 0;
67 // Set data to return when registering via
68 // Platform::setDeviceMotionListener().
69 virtual void SetDeviceMotionData(const blink::WebDeviceMotionData& data) = 0;
70 // Set data to return when registering via
71 // Platform::setDeviceOrientationListener().
72 virtual void SetDeviceOrientationData(
73 const blink::WebDeviceOrientationData& data) = 0;
75 // Set orientation to set when registering via
76 // Platform::setScreenOrientationListener().
77 virtual void SetScreenOrientation(
78 const blink::WebScreenOrientationType& orientation) = 0;
80 // Reset the screen orientation data used for testing.
81 virtual void ResetScreenOrientation() = 0;
83 // Notifies blink about a change in battery status.
84 virtual void DidChangeBatteryStatus(
85 const blink::WebBatteryStatus& status) = 0;
87 // Add a message to the text dump for the layout test.
88 virtual void PrintMessage(const std::string& message) = 0;
90 // The delegate takes ownership of the WebTask objects and is responsible
91 // for deleting them.
92 virtual void PostTask(WebTask* task) = 0;
93 virtual void PostDelayedTask(WebTask* task, long long ms) = 0;
95 // Register a new isolated filesystem with the given files, and return the
96 // new filesystem id.
97 virtual blink::WebString RegisterIsolatedFileSystem(
98 const blink::WebVector<blink::WebString>& absolute_filenames) = 0;
100 // Gets the current time in milliseconds since the UNIX epoch.
101 virtual long long GetCurrentTimeInMillisecond() = 0;
103 // Convert the provided relative path into an absolute path.
104 virtual blink::WebString GetAbsoluteWebStringFromUTF8Path(
105 const std::string& path) = 0;
107 // Reads in the given file and returns its contents as data URL.
108 virtual blink::WebURL LocalFileToDataURL(const blink::WebURL& file_url) = 0;
110 // Replaces file:///tmp/LayoutTests/ with the actual path to the
111 // LayoutTests directory.
112 virtual blink::WebURL RewriteLayoutTestsURL(const std::string& utf8_url) = 0;
114 // Manages the settings to used for layout tests.
115 virtual TestPreferences* Preferences() = 0;
116 virtual void ApplyPreferences() = 0;
118 // Enables or disables synchronous resize mode. When enabled, all
119 // window-sizing machinery is
120 // short-circuited inside the renderer. This mode is necessary for some tests
121 // that were written
122 // before browsers had multi-process architecture and rely on window resizes
123 // to happen synchronously.
124 // The function has "unfortunate" it its name because we must strive to remove
125 // all tests
126 // that rely on this... well, unfortunate behavior. See
127 // http://crbug.com/309760 for the plan.
128 virtual void UseUnfortunateSynchronousResizeMode(bool enable) = 0;
130 // Controls auto resize mode.
131 virtual void EnableAutoResizeMode(const blink::WebSize& min_size,
132 const blink::WebSize& max_size) = 0;
133 virtual void DisableAutoResizeMode(const blink::WebSize& new_size) = 0;
135 // Clears DevTools' localStorage when an inspector test is started.
136 virtual void ClearDevToolsLocalStorage() = 0;
138 // Opens and closes the inspector.
139 virtual void ShowDevTools(const std::string& settings,
140 const std::string& frontend_url) = 0;
141 virtual void CloseDevTools() = 0;
143 // Evaluate the given script in the DevTools agent.
144 virtual void EvaluateInWebInspector(long call_id,
145 const std::string& script) = 0;
147 // Controls WebSQL databases.
148 virtual void ClearAllDatabases() = 0;
149 virtual void SetDatabaseQuota(int quota) = 0;
151 // Controls Web Notifications.
152 virtual void SimulateWebNotificationClick(const std::string& title,
153 int action_index) = 0;
155 // Controls the device scale factor of the main WebView for hidpi tests.
156 virtual void SetDeviceScaleFactor(float factor) = 0;
158 // Change the device color profile while running a layout test.
159 virtual void SetDeviceColorProfile(const std::string& name) = 0;
161 // Change the bluetooth test data while running a layout test.
162 virtual void SetBluetoothMockDataSet(const std::string& data_set) = 0;
164 // Makes the Bluetooth chooser record its input and wait for instructions from
165 // the test program on how to proceed.
166 virtual void SetBluetoothManualChooser() = 0;
168 // Returns the events recorded since the last call to this function.
169 virtual std::vector<std::string> GetBluetoothManualChooserEvents() = 0;
171 // Calls the BluetoothChooser::EventHandler with the arguments here. Valid
172 // event strings are:
173 // * "cancel" - simulates the user canceling the chooser.
174 // * "select" - simulates the user selecting a device whose device ID is in
175 // |argument|.
176 virtual void SendBluetoothManualChooserEvent(const std::string& event,
177 const std::string& argument) = 0;
179 // Enables mock geofencing service while running a layout test.
180 // |service_available| indicates if the mock service should mock geofencing
181 // being available or not.
182 virtual void SetGeofencingMockProvider(bool service_available) = 0;
184 // Disables mock geofencing service while running a layout test.
185 virtual void ClearGeofencingMockProvider() = 0;
187 // Set the mock geofencing position while running a layout test.
188 virtual void SetGeofencingMockPosition(double latitude, double longitude) = 0;
190 // Controls which WebView should be focused.
191 virtual void SetFocus(WebTestProxyBase* proxy, bool focus) = 0;
193 // Controls whether all cookies should be accepted or writing cookies in a
194 // third-party context is blocked.
195 virtual void SetAcceptAllCookies(bool accept) = 0;
197 // The same as RewriteLayoutTestsURL unless the resource is a path starting
198 // with /tmp/, then return a file URL to a temporary file.
199 virtual std::string PathToLocalResource(const std::string& resource) = 0;
201 // Sets the POSIX locale of the current process.
202 virtual void SetLocale(const std::string& locale) = 0;
204 // Invoked when the test finished.
205 virtual void TestFinished() = 0;
207 // Invoked when the embedder should close all but the main WebView.
208 virtual void CloseRemainingWindows() = 0;
210 virtual void DeleteAllCookies() = 0;
212 // Returns the length of the back/forward history of the main WebView.
213 virtual int NavigationEntryCount() = 0;
215 // The following trigger navigations on the main WebViwe.
216 virtual void GoToOffset(int offset) = 0;
217 virtual void Reload() = 0;
218 virtual void LoadURLForFrame(const blink::WebURL& url,
219 const std::string& frame_name) = 0;
221 // Returns true if resource requests to external URLs should be permitted.
222 virtual bool AllowExternalPages() = 0;
224 // Returns a text dump the back/forward history for the WebView associated
225 // with the given WebTestProxyBase.
226 virtual std::string DumpHistoryForWindow(WebTestProxyBase* proxy) = 0;
228 // Fetch the manifest for a given WebView from the given url.
229 virtual void FetchManifest(
230 blink::WebView* view,
231 const GURL& url,
232 const base::Callback<void(const blink::WebURLResponse& response,
233 const std::string& data)>& callback) = 0;
235 // Sends a message to the LayoutTestPermissionManager in order for it to
236 // update its database.
237 virtual void SetPermission(const std::string& permission_name,
238 const std::string& permission_value,
239 const GURL& origin,
240 const GURL& embedding_origin) = 0;
242 // Clear all the permissions set via SetPermission().
243 virtual void ResetPermissions() = 0;
245 virtual cc::SharedBitmapManager* GetSharedBitmapManager() = 0;
247 // Causes the beforeinstallprompt event to be sent to the renderer with a
248 // request id of |request_id|. |event_platforms| are the platforms to be sent
249 // with the event. Once the event listener completes, |callback| will be
250 // called with a boolean argument. This argument will be true if the event is
251 // canceled, and false otherwise.
252 virtual void DispatchBeforeInstallPromptEvent(
253 int request_id,
254 const std::vector<std::string>& event_platforms,
255 const base::Callback<void(bool)>& callback) = 0;
257 // Resolve the promise associated with the beforeinstallprompt even with
258 // request id |request_id|. The promise is resolved with a result.platform set
259 // to |platform|. If |platform| is not empty, result.outcome will be
260 // 'accepted', otherwise it will be 'dismissed'.
261 virtual void ResolveBeforeInstallPromptPromise(
262 int request_id,
263 const std::string& platform) = 0;
265 virtual blink::WebPlugin* CreatePluginPlaceholder(
266 blink::WebLocalFrame* frame,
267 const blink::WebPluginParams& params) = 0;
269 virtual void OnWebTestProxyBaseDestroy(WebTestProxyBase* proxy) = 0;
272 } // namespace test_runner
274 #endif // COMPONENTS_TEST_RUNNER_WEB_TEST_DELEGATE_H_