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 CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTDELEGATE_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTDELEGATE_H_
10 #include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
11 #include "third_party/WebKit/public/platform/WebString.h"
12 #include "third_party/WebKit/public/platform/WebURL.h"
13 #include "third_party/WebKit/public/platform/WebVector.h"
14 #include "third_party/WebKit/public/web/WebNotificationPresenter.h"
16 #define WEBTESTRUNNER_NEW_HISTORY_CAPTURE
19 class WebBatteryStatus;
20 class WebDeviceMotionData;
21 class WebDeviceOrientationData;
33 class DeviceLightData;
34 class RendererGamepadProvider;
36 class WebTestProxyBase;
37 struct TestPreferences;
39 class WebTestDelegate {
41 // Set and clear the edit command to execute on the next call to
42 // WebViewClient::handleCurrentKeyboardEvent().
43 virtual void clearEditCommand() = 0;
44 virtual void setEditCommand(const std::string& name, const std::string& value) = 0;
46 // Sets gamepad provider to be used for tests.
47 virtual void setGamepadProvider(RendererGamepadProvider*) = 0;
49 // Set data to return when registering via
50 // Platform::setDeviceLightListener().
51 virtual void setDeviceLightData(const double) = 0;
52 // Set data to return when registering via
53 // Platform::setDeviceMotionListener().
54 virtual void setDeviceMotionData(const blink::WebDeviceMotionData&) = 0;
55 // Set data to return when registering via Platform::setDeviceOrientationListener().
56 virtual void setDeviceOrientationData(const blink::WebDeviceOrientationData&) = 0;
58 // Set orientation to set when registering via Platform::setScreenOrientationListener().
59 virtual void setScreenOrientation(const blink::WebScreenOrientationType&) = 0;
61 // Reset the screen orientation data used for testing.
62 virtual void resetScreenOrientation() = 0;
64 // Notifies blink about a change in battery status.
65 virtual void didChangeBatteryStatus(const blink::WebBatteryStatus&) = 0;
67 // Add a message to the text dump for the layout test.
68 virtual void printMessage(const std::string& message) = 0;
70 // The delegate takes ownership of the WebTask objects and is responsible
72 virtual void postTask(WebTask*) = 0;
73 virtual void postDelayedTask(WebTask*, long long ms) = 0;
75 // Register a new isolated filesystem with the given files, and return the
77 virtual blink::WebString registerIsolatedFileSystem(const blink::WebVector<blink::WebString>& absoluteFilenames) = 0;
79 // Gets the current time in milliseconds since the UNIX epoch.
80 virtual long long getCurrentTimeInMillisecond() = 0;
82 // Convert the provided relative path into an absolute path.
83 virtual blink::WebString getAbsoluteWebStringFromUTF8Path(const std::string& path) = 0;
85 // Reads in the given file and returns its contents as data URL.
86 virtual blink::WebURL localFileToDataURL(const blink::WebURL&) = 0;
88 // Replaces file:///tmp/LayoutTests/ with the actual path to the
89 // LayoutTests directory.
90 virtual blink::WebURL rewriteLayoutTestsURL(const std::string& utf8URL) = 0;
92 // Manages the settings to used for layout tests.
93 virtual TestPreferences* preferences() = 0;
94 virtual void applyPreferences() = 0;
96 // Enables or disables synchronous resize mode. When enabled, all window-sizing machinery is
97 // short-circuited inside the renderer. This mode is necessary for some tests that were written
98 // before browsers had multi-process architecture and rely on window resizes to happen synchronously.
99 // The function has "unfortunate" it its name because we must strive to remove all tests
100 // that rely on this... well, unfortunate behavior. See http://crbug.com/309760 for the plan.
101 virtual void useUnfortunateSynchronousResizeMode(bool) = 0;
103 // Controls auto resize mode.
104 virtual void enableAutoResizeMode(const blink::WebSize& minSize, const blink::WebSize& maxSize) = 0;
105 virtual void disableAutoResizeMode(const blink::WebSize&) = 0;
107 // Clears DevTools' localStorage when an inspector test is started.
108 virtual void clearDevToolsLocalStorage() = 0;
110 // Opens and closes the inspector.
111 virtual void showDevTools(const std::string& settings,
112 const std::string& frontend_url) = 0;
113 virtual void closeDevTools() = 0;
115 // Evaluate the given script in the DevTools agent.
116 virtual void evaluateInWebInspector(long callID, const std::string& script) = 0;
118 // Controls WebSQL databases.
119 virtual void clearAllDatabases() = 0;
120 virtual void setDatabaseQuota(int) = 0;
122 // Controls Web Notification permissions.
123 virtual blink::WebNotificationPresenter::Permission
124 checkWebNotificationPermission(const GURL& origin) = 0;
125 virtual void grantWebNotificationPermission(const GURL& origin,
126 bool permission_granted) = 0;
127 virtual void clearWebNotificationPermissions() = 0;
129 // Controls the device scale factor of the main WebView for hidpi tests.
130 virtual void setDeviceScaleFactor(float) = 0;
132 // Change the device color profile while running a layout test.
133 virtual void setDeviceColorProfile(const std::string& name) = 0;
135 // Controls which WebView should be focused.
136 virtual void setFocus(WebTestProxyBase*, bool) = 0;
138 // Controls whether all cookies should be accepted or writing cookies in a
139 // third-party context is blocked.
140 virtual void setAcceptAllCookies(bool) = 0;
142 // The same as rewriteLayoutTestsURL unless the resource is a path starting
143 // with /tmp/, then return a file URL to a temporary file.
144 virtual std::string pathToLocalResource(const std::string& resource) = 0;
146 // Sets the POSIX locale of the current process.
147 virtual void setLocale(const std::string&) = 0;
149 // Invoked when the test finished.
150 virtual void testFinished() = 0;
152 // Invoked when the embedder should close all but the main WebView.
153 virtual void closeRemainingWindows() = 0;
155 virtual void deleteAllCookies() = 0;
157 // Returns the length of the back/forward history of the main WebView.
158 virtual int navigationEntryCount() = 0;
160 // The following trigger navigations on the main WebViwe.
161 virtual void goToOffset(int offset) = 0;
162 virtual void reload() = 0;
163 virtual void loadURLForFrame(const blink::WebURL&, const std::string& frameName) = 0;
165 // Returns true if resource requests to external URLs should be permitted.
166 virtual bool allowExternalPages() = 0;
168 // Returns a text dump the back/forward history for the WebView associated
169 // with the given WebTestProxyBase.
170 virtual std::string dumpHistoryForWindow(WebTestProxyBase*) = 0;
173 } // namespace content
175 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTDELEGATE_H_