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_
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
21 class WebBatteryStatus
;
22 class WebDeviceMotionData
;
23 class WebDeviceOrientationData
;
31 struct WebPluginParams
;
41 class TextureLayerClient
;
42 class SharedBitmapManager
;
45 namespace test_runner
{
47 class DeviceLightData
;
48 class GamepadController
;
50 class WebTestProxyBase
;
51 struct TestPreferences
;
53 class WebTestDelegate
{
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
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
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
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
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 // Enables mock geofencing service while running a layout test.
165 // |service_available| indicates if the mock service should mock geofencing
166 // being available or not.
167 virtual void SetGeofencingMockProvider(bool service_available
) = 0;
169 // Disables mock geofencing service while running a layout test.
170 virtual void ClearGeofencingMockProvider() = 0;
172 // Set the mock geofencing position while running a layout test.
173 virtual void SetGeofencingMockPosition(double latitude
, double longitude
) = 0;
175 // Controls which WebView should be focused.
176 virtual void SetFocus(WebTestProxyBase
* proxy
, bool focus
) = 0;
178 // Controls whether all cookies should be accepted or writing cookies in a
179 // third-party context is blocked.
180 virtual void SetAcceptAllCookies(bool accept
) = 0;
182 // The same as RewriteLayoutTestsURL unless the resource is a path starting
183 // with /tmp/, then return a file URL to a temporary file.
184 virtual std::string
PathToLocalResource(const std::string
& resource
) = 0;
186 // Sets the POSIX locale of the current process.
187 virtual void SetLocale(const std::string
& locale
) = 0;
189 // Invoked when the test finished.
190 virtual void TestFinished() = 0;
192 // Invoked when the embedder should close all but the main WebView.
193 virtual void CloseRemainingWindows() = 0;
195 virtual void DeleteAllCookies() = 0;
197 // Returns the length of the back/forward history of the main WebView.
198 virtual int NavigationEntryCount() = 0;
200 // The following trigger navigations on the main WebViwe.
201 virtual void GoToOffset(int offset
) = 0;
202 virtual void Reload() = 0;
203 virtual void LoadURLForFrame(const blink::WebURL
& url
,
204 const std::string
& frame_name
) = 0;
206 // Returns true if resource requests to external URLs should be permitted.
207 virtual bool AllowExternalPages() = 0;
209 // Returns a text dump the back/forward history for the WebView associated
210 // with the given WebTestProxyBase.
211 virtual std::string
DumpHistoryForWindow(WebTestProxyBase
* proxy
) = 0;
213 // Fetch the manifest for a given WebView from the given url.
214 virtual void FetchManifest(
215 blink::WebView
* view
,
217 const base::Callback
<void(const blink::WebURLResponse
& response
,
218 const std::string
& data
)>& callback
) = 0;
220 // Sends a message to the LayoutTestPermissionManager in order for it to
221 // update its database.
222 virtual void SetPermission(const std::string
& permission_name
,
223 const std::string
& permission_value
,
225 const GURL
& embedding_origin
) = 0;
227 // Clear all the permissions set via SetPermission().
228 virtual void ResetPermissions() = 0;
230 // Creates cc::TextureLayer for TestPlugin.
231 virtual scoped_refptr
<cc::TextureLayer
> CreateTextureLayerForMailbox(
232 cc::TextureLayerClient
* client
) = 0;
234 // Instantiates WebLayerImpl for TestPlugin.
235 virtual blink::WebLayer
* InstantiateWebLayer(
236 scoped_refptr
<cc::TextureLayer
> layer
) = 0;
238 virtual cc::SharedBitmapManager
* GetSharedBitmapManager() = 0;
240 // Causes the beforeinstallprompt event to be sent to the renderer with a
241 // request id of |request_id|. |event_platforms| are the platforms to be sent
242 // with the event. Once the event listener completes, |callback| will be
243 // called with a boolean argument. This argument will be true if the event is
244 // canceled, and false otherwise.
245 virtual void DispatchBeforeInstallPromptEvent(
247 const std::vector
<std::string
>& event_platforms
,
248 const base::Callback
<void(bool)>& callback
) = 0;
250 // Resolve the promise associated with the beforeinstallprompt even with
251 // request id |request_id|. The promise is resolved with a result.platform set
252 // to |platform|. If |platform| is not empty, result.outcome will be
253 // 'accepted', otherwise it will be 'dismissed'.
254 virtual void ResolveBeforeInstallPromptPromise(
256 const std::string
& platform
) = 0;
258 virtual blink::WebPlugin
* CreatePluginPlaceholder(
259 blink::WebLocalFrame
* frame
,
260 const blink::WebPluginParams
& params
) = 0;
262 virtual void OnWebTestProxyBaseDestroy(WebTestProxyBase
* proxy
) = 0;
265 } // namespace test_runner
267 #endif // COMPONENTS_TEST_RUNNER_WEB_TEST_DELEGATE_H_