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_WEB_TEST_DELEGATE_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_TEST_DELEGATE_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,
45 const std::string& value) = 0;
47 // Sets gamepad provider to be used for tests.
48 virtual void SetGamepadProvider(
49 scoped_ptr<RendererGamepadProvider> provider) = 0;
51 // Set data to return when registering via
52 // Platform::setDeviceLightListener().
53 virtual void SetDeviceLightData(const double data) = 0;
54 // Set data to return when registering via
55 // Platform::setDeviceMotionListener().
56 virtual void SetDeviceMotionData(const blink::WebDeviceMotionData& data) = 0;
57 // Set data to return when registering via
58 // Platform::setDeviceOrientationListener().
59 virtual void SetDeviceOrientationData(
60 const blink::WebDeviceOrientationData& data) = 0;
62 // Set orientation to set when registering via
63 // Platform::setScreenOrientationListener().
64 virtual void SetScreenOrientation(
65 const blink::WebScreenOrientationType& orientation) = 0;
67 // Reset the screen orientation data used for testing.
68 virtual void ResetScreenOrientation() = 0;
70 // Notifies blink about a change in battery status.
71 virtual void DidChangeBatteryStatus(
72 const blink::WebBatteryStatus& status) = 0;
74 // Add a message to the text dump for the layout test.
75 virtual void PrintMessage(const std::string& message) = 0;
77 // The delegate takes ownership of the WebTask objects and is responsible
79 virtual void PostTask(WebTask* task) = 0;
80 virtual void PostDelayedTask(WebTask* task, long long ms) = 0;
82 // Register a new isolated filesystem with the given files, and return the
84 virtual blink::WebString RegisterIsolatedFileSystem(
85 const blink::WebVector<blink::WebString>& absolute_filenames) = 0;
87 // Gets the current time in milliseconds since the UNIX epoch.
88 virtual long long GetCurrentTimeInMillisecond() = 0;
90 // Convert the provided relative path into an absolute path.
91 virtual blink::WebString GetAbsoluteWebStringFromUTF8Path(
92 const std::string& path) = 0;
94 // Reads in the given file and returns its contents as data URL.
95 virtual blink::WebURL LocalFileToDataURL(const blink::WebURL& file_url) = 0;
97 // Replaces file:///tmp/LayoutTests/ with the actual path to the
98 // LayoutTests directory.
99 virtual blink::WebURL RewriteLayoutTestsURL(const std::string& utf8_url) = 0;
101 // Manages the settings to used for layout tests.
102 virtual TestPreferences* Preferences() = 0;
103 virtual void ApplyPreferences() = 0;
105 // Enables or disables synchronous resize mode. When enabled, all
106 // window-sizing machinery is
107 // short-circuited inside the renderer. This mode is necessary for some tests
109 // before browsers had multi-process architecture and rely on window resizes
110 // to happen synchronously.
111 // The function has "unfortunate" it its name because we must strive to remove
113 // that rely on this... well, unfortunate behavior. See
114 // http://crbug.com/309760 for the plan.
115 virtual void UseUnfortunateSynchronousResizeMode(bool enable) = 0;
117 // Controls auto resize mode.
118 virtual void EnableAutoResizeMode(const blink::WebSize& min_size,
119 const blink::WebSize& max_size) = 0;
120 virtual void DisableAutoResizeMode(const blink::WebSize& new_size) = 0;
122 // Clears DevTools' localStorage when an inspector test is started.
123 virtual void ClearDevToolsLocalStorage() = 0;
125 // Opens and closes the inspector.
126 virtual void ShowDevTools(const std::string& settings,
127 const std::string& frontend_url) = 0;
128 virtual void CloseDevTools() = 0;
130 // Evaluate the given script in the DevTools agent.
131 virtual void EvaluateInWebInspector(long call_id,
132 const std::string& script) = 0;
134 // Controls WebSQL databases.
135 virtual void ClearAllDatabases() = 0;
136 virtual void SetDatabaseQuota(int quota) = 0;
138 // Controls Web Notification permissions.
139 virtual blink::WebNotificationPresenter::Permission
140 CheckWebNotificationPermission(const GURL& origin) = 0;
141 virtual void GrantWebNotificationPermission(const GURL& origin,
142 bool permission_granted) = 0;
143 virtual void ClearWebNotificationPermissions() = 0;
145 // Controls the device scale factor of the main WebView for hidpi tests.
146 virtual void SetDeviceScaleFactor(float factor) = 0;
148 // Change the device color profile while running a layout test.
149 virtual void SetDeviceColorProfile(const std::string& name) = 0;
151 // Controls which WebView should be focused.
152 virtual void SetFocus(WebTestProxyBase* proxy, bool focus) = 0;
154 // Controls whether all cookies should be accepted or writing cookies in a
155 // third-party context is blocked.
156 virtual void SetAcceptAllCookies(bool accept) = 0;
158 // The same as RewriteLayoutTestsURL unless the resource is a path starting
159 // with /tmp/, then return a file URL to a temporary file.
160 virtual std::string PathToLocalResource(const std::string& resource) = 0;
162 // Sets the POSIX locale of the current process.
163 virtual void SetLocale(const std::string& locale) = 0;
165 // Invoked when the test finished.
166 virtual void TestFinished() = 0;
168 // Invoked when the embedder should close all but the main WebView.
169 virtual void CloseRemainingWindows() = 0;
171 virtual void DeleteAllCookies() = 0;
173 // Returns the length of the back/forward history of the main WebView.
174 virtual int NavigationEntryCount() = 0;
176 // The following trigger navigations on the main WebViwe.
177 virtual void GoToOffset(int offset) = 0;
178 virtual void Reload() = 0;
179 virtual void LoadURLForFrame(const blink::WebURL& url,
180 const std::string& frame_name) = 0;
182 // Returns true if resource requests to external URLs should be permitted.
183 virtual bool AllowExternalPages() = 0;
185 // Returns a text dump the back/forward history for the WebView associated
186 // with the given WebTestProxyBase.
187 virtual std::string DumpHistoryForWindow(WebTestProxyBase* proxy) = 0;
190 } // namespace content
192 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_TEST_DELEGATE_H_