blob: f7ce3d6fef7b0631582e74f0d549531757fadeec [file] [log] [blame]
[email protected]97f9a7952014-03-14 11:50:331// Copyright 2014 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
danakj89f47082020-09-02 17:53:435#ifndef CONTENT_WEB_TEST_RENDERER_TEST_RUNNER_H_
6#define CONTENT_WEB_TEST_RENDERER_TEST_RUNNER_H_
[email protected]97f9a7952014-03-14 11:50:337
avi5dd91f82015-12-25 22:30:468#include <stdint.h>
9
dcheng82beb4f2016-04-26 00:35:0210#include <memory>
[email protected]97f9a7952014-03-14 11:50:3311#include <set>
12#include <string>
benwells0c0d3f12015-05-25 01:03:1713#include <vector>
[email protected]97f9a7952014-03-14 11:50:3314
danakj754eaff2020-03-31 17:46:5815#include "base/callback_forward.h"
Brett Wilsoncc8623d2017-09-12 03:28:1016#include "base/containers/circular_deque.h"
danakjaa87f0092020-07-07 17:13:4317#include "base/containers/flat_set.h"
Marijn Kruisselbrinkf5268912020-01-15 22:07:1218#include "base/files/file_path.h"
avi5dd91f82015-12-25 22:30:4619#include "base/macros.h"
[email protected]97f9a7952014-03-14 11:50:3320#include "base/memory/weak_ptr.h"
Peter Beverloo988ef962017-09-12 15:49:1721#include "base/optional.h"
22#include "base/strings/string16.h"
danakj89f47082020-09-02 17:53:4323#include "content/web_test/common/web_test.mojom.h"
24#include "content/web_test/common/web_test_bluetooth_fake_adapter_setter.mojom.h"
Hitoshi Yoshida25a31d52020-10-29 08:00:3325#include "content/web_test/common/web_test_constants.h"
danakj89f47082020-09-02 17:53:4326#include "content/web_test/renderer/fake_screen_orientation_impl.h"
27#include "content/web_test/renderer/gamepad_controller.h"
28#include "content/web_test/renderer/layout_dump.h"
29#include "content/web_test/renderer/web_test_content_settings_client.h"
30#include "content/web_test/renderer/web_test_runtime_flags.h"
Blink Reformata30d4232018-04-07 15:31:0631#include "third_party/blink/public/platform/web_effective_connection_type.h"
danakj7c5a96c2020-07-03 15:58:3632#include "third_party/blink/public/platform/web_url.h"
Fredrik Söderquistb2b39eb92019-11-18 16:16:5033#include "third_party/skia/include/core/SkBitmap.h"
[email protected]97f9a7952014-03-14 11:50:3334#include "v8/include/v8.h"
35
danakj754eaff2020-03-31 17:46:5836class SkBitmap;
37
38namespace base {
39class DictionaryValue;
40}
[email protected]eec9e78e2014-06-16 21:38:4841
[email protected]97f9a7952014-03-14 11:50:3342namespace blink {
mlamouri007f9d72015-02-27 16:27:2543class WebContentSettingsClient;
[email protected]97f9a7952014-03-14 11:50:3344class WebFrame;
Dave Tapuska4d524862020-12-01 19:43:4145class WebFrameWidget;
[email protected]97f9a7952014-03-14 11:50:3346class WebString;
47class WebView;
danakjb0092062020-05-04 19:53:0648} // namespace blink
[email protected]97f9a7952014-03-14 11:50:3349
50namespace gin {
51class ArrayBufferView;
52class Arguments;
danakjb0092062020-05-04 19:53:0653} // namespace gin
[email protected]97f9a7952014-03-14 11:50:3354
danakj741848a2020-04-07 22:48:0655namespace content {
danakjb5ae26052020-04-23 17:20:2256class RenderFrame;
danakj552c1cc92020-07-14 22:34:1057class RenderView;
Yuki Shiinoc955c4c2020-07-06 04:38:1558class SpellCheckClient;
danakj552c1cc92020-07-14 22:34:1059class TestRunnerBindings;
danakj4cfe7002020-05-13 23:04:3960class WebFrameTestProxy;
danakj629826b2020-05-13 22:44:5961class WebViewTestProxy;
danakj552c1cc92020-07-14 22:34:1062struct TestPreferences;
[email protected]97f9a7952014-03-14 11:50:3363
lukaszab2ad0502016-04-27 15:51:4264// TestRunner class currently has dual purpose:
danakj2d7921652019-09-11 17:20:1265// 1. It implements TestRunner javascript bindings for "global" / "ambient".
lukaszab2ad0502016-04-27 15:51:4266// Examples:
danakj2d7921652019-09-11 17:20:1267// - TestRunner.DumpAsText (test flag affecting test behavior)
68// - TestRunner.SetAllowRunningOfInsecureContent (test flag affecting product
lukaszab2ad0502016-04-27 15:51:4269// behavior)
danakj2d7921652019-09-11 17:20:1270// - TestRunner.SetTextSubpixelPositioning (directly interacts with product).
lukaszab2ad0502016-04-27 15:51:4271// 2. It manages global test state. Example:
72// - Tracking topLoadingFrame that can finish the test when it loads.
danakj1985c8f2020-07-09 18:28:1673// - WorkQueue holding load requests from web tests.
Kent Tamura21d1de62018-12-10 04:45:2074// - WebTestRuntimeFlags
danakj9f2d3502020-04-07 21:20:2175class TestRunner {
[email protected]97f9a7952014-03-14 11:50:3376 public:
danakj1985c8f2020-07-09 18:28:1677 TestRunner();
[email protected]97f9a7952014-03-14 11:50:3378 virtual ~TestRunner();
79
Yuki Shiinoc955c4c2020-07-06 04:38:1580 void Install(WebFrameTestProxy* frame, SpellCheckClient* spell_check);
[email protected]97f9a7952014-03-14 11:50:3381
danakj12c09b62020-07-11 04:17:0582 // Resets global TestRunner state for the next test.
83 void Reset();
danakjaa87f0092020-07-07 17:13:4384
danakj629826b2020-05-13 22:44:5985 // Resets state on the |web_view_test_proxy| for the next test.
86 void ResetWebView(WebViewTestProxy* web_view_test_proxy);
Dave Tapuska4d524862020-12-01 19:43:4187 // Resets state on the |web_frame_widget| for the next test.
88 void ResetWebFrameWidget(blink::WebFrameWidget* web_frame_widget);
[email protected]97f9a7952014-03-14 11:50:3389
[email protected]97f9a7952014-03-14 11:50:3390 void SetTestIsRunning(bool);
91 bool TestIsRunning() const { return test_is_running_; }
92
danakj3130f122019-07-16 17:49:4793 // Finishes the test if it is ready. This should be called before running
94 // tasks that will change state, so that the test can capture the current
95 // state. Specifically, should run before the BeginMainFrame step which does
96 // layout and animation etc.
97 // This does *not* run as part of loading finishing because that happens in
98 // the middle of blink call stacks that have inconsistent state.
99 void FinishTestIfReady();
danakj4b0ef922020-08-28 14:34:57100 // Notification that another renderer has explicitly asked the test to end.
101 void TestFinishedFromSecondaryRenderer();
danakj3130f122019-07-16 17:49:47102
danakj529c0642020-08-28 18:02:18103 // Performs a reset at the end of a test, in order to prepare for the next
104 // test. This includes a navigation to about:blank, which we hear about
105 // through DidCommitNavigationInMainFrame().
106 void ResetRendererAfterWebTest(base::OnceClosure done_callback);
107 // Listener for navigations in order to hear about the navigation to
108 // about:blank done for ResetRendererAfterWebTest().
109 void DidCommitNavigationInMainFrame(WebFrameTestProxy* main_frame);
110
danakjaa87f0092020-07-07 17:13:43111 // Track the set of all main frames in the process, which is also the set of
112 // windows rooted in this process.
113 void AddMainFrame(WebFrameTestProxy* frame);
114 void RemoveMainFrame(WebFrameTestProxy* frame);
115
danakj1985c8f2020-07-09 18:28:16116 // Track the set of all RenderViews in the process, which includes cross-site
117 // frames/windows accessible from this process but homed in a different
118 // renderer and parts of any windows' frame trees that share the same site.
119 void AddRenderView(WebViewTestProxy* view);
120 void RemoveRenderView(WebViewTestProxy* view);
121
danakj754eaff2020-03-31 17:46:58122 // Returns a mock WebContentSettings that is used for web tests. An
123 // embedder should use this for all WebViews it creates.
danakjaa87f0092020-07-07 17:13:43124 blink::WebContentSettingsClient* GetWebContentSettings();
danakj754eaff2020-03-31 17:46:58125
danakj27e4ebe2020-04-15 18:48:27126 // Returns true if the test output should be an audio file, rather than text
127 // or pixel results.
danakj754eaff2020-03-31 17:46:58128 bool ShouldDumpAsAudio() const;
danakj27e4ebe2020-04-15 18:48:27129 // Gets the audio test output for when audio test results are requested by
130 // the current test.
danakjc50c5e22020-07-09 17:06:14131 const std::vector<uint8_t>& GetAudioData() const;
danakj754eaff2020-03-31 17:46:58132
133 // Reports if tests requested a recursive layout dump of all frames
134 // (i.e. by calling testRunner.dumpChildFramesAsText() from javascript).
135 bool IsRecursiveLayoutDumpRequested();
136
danakj754eaff2020-03-31 17:46:58137 // Returns true if the selection window should be painted onto captured
138 // pixels.
139 bool ShouldDumpSelectionRect() const;
140
141 // Returns false if the browser should capture the pixel output, true if it
danakje9f674512020-07-07 19:23:06142 // can be done locally in the renderer via DumpPixelsInRenderer().
danakj754eaff2020-03-31 17:46:58143 bool CanDumpPixelsFromRenderer() const;
144
145 // Snapshots the content of |render_view| using the mode requested by the
146 // current test and calls |callback| with the result. Caller needs to ensure
147 // that |render_view| stays alive until |callback| is called.
danakje9f674512020-07-07 19:23:06148 SkBitmap DumpPixelsInRenderer(content::RenderView* render_view);
danakj754eaff2020-03-31 17:46:58149
150 // Replicates changes to web test runtime flags (i.e. changes that happened in
danakj529c0642020-08-28 18:02:18151 // another renderer). See also `OnWebTestRuntimeFlagsChanged()`.
Kent Tamura679c7c42018-12-05 03:21:10152 void ReplicateWebTestRuntimeFlagsChanges(
danakj754eaff2020-03-31 17:46:58153 const base::DictionaryValue& changed_values);
154
155 // If custom text dump is present (i.e. if testRunner.setCustomTextOutput has
156 // been called from javascript), then returns |true| and populates the
157 // |custom_text_dump| argument. Otherwise returns |false|.
158 bool HasCustomTextDump(std::string* custom_text_dump) const;
159
160 // Returns true if the history should be included in text results generated at
161 // the end of the test.
162 bool ShouldDumpBackForwardList() const;
163
164 // Returns true if pixel results should be generated at the end of the test.
165 bool ShouldGeneratePixelResults();
166
danakj049cb6a2020-07-11 03:11:34167 TextResultType ShouldGenerateTextResults();
168
danakj674bf1c02020-05-01 18:37:51169 // Activate the window holding the given main frame, and set focus on the
170 // frame's widget.
171 void FocusWindow(RenderFrame* main_frame, bool focus);
[email protected]97f9a7952014-03-14 11:50:33172
lukasza01da2602016-04-05 14:51:26173 // Methods used by WebViewTestClient and WebFrameTestClient.
lukaszaa0b624a2016-04-04 15:00:49174 std::string GetAcceptLanguages() const;
danakj2d7921652019-09-11 17:20:12175 bool ShouldStayOnPageAfterHandlingBeforeUnload() const;
danakj2d7921652019-09-11 17:20:12176 bool ShouldDumpAsCustomText() const;
177 std::string CustomDumpText() const;
abhishek.a21ca9b5602014-09-19 07:33:33178 void ShowDevTools(const std::string& settings,
[email protected]06c253012014-04-16 18:35:33179 const std::string& frontend_url);
danakj2d7921652019-09-11 17:20:12180 void SetShouldDumpAsLayout(bool);
181 void SetCustomTextOutput(const std::string& text);
182 void SetShouldGeneratePixelResults(bool);
183 void SetShouldDumpFrameLoadCallbacks(bool);
danakj2d7921652019-09-11 17:20:12184 bool ShouldDumpEditingCallbacks() const;
185 bool ShouldDumpFrameLoadCallbacks() const;
186 bool ShouldDumpPingLoaderCallbacks() const;
187 bool ShouldDumpUserGestureInFrameLoadCallbacks() const;
188 bool ShouldDumpTitleChanges() const;
189 bool ShouldDumpIconChanges() const;
190 bool ShouldDumpCreateView() const;
191 bool CanOpenWindows() const;
danakj2d7921652019-09-11 17:20:12192 bool ShouldWaitUntilExternalURLLoad() const;
193 const std::set<std::string>* HttpHeadersToClear() const;
Dominic Farolinoaee9c1b82019-12-18 03:20:10194 bool ClearReferrer() const;
danakj29382fc2020-04-20 18:00:09195 bool IsWebPlatformTestsMode() const;
196 void SetIsWebPlatformTestsMode();
Mason Freedb0855622018-10-02 17:49:47197 bool animation_requires_raster() const { return animation_requires_raster_; }
198 void SetAnimationRequiresRaster(bool do_raster);
lukasza10cd8762016-04-27 20:03:02199
arthursonzognid409c252019-03-14 09:22:22200 // Add |frame| to the set of loading frames.
201 //
202 // Note: Only one renderer process is really tracking the loading frames. This
203 // is the first to observe one. Both local and remote frames are tracked
204 // by this process.
205 void AddLoadingFrame(blink::WebFrame* frame);
lukasza10cd8762016-04-27 20:03:02206
arthursonzognid409c252019-03-14 09:22:22207 // Remove |frame| from the set of loading frames.
208 //
209 // When there are no more loading frames, this potentially finishes the test,
danakj2d7921652019-09-11 17:20:12210 // unless TestRunner.WaitUntilDone() was called and/or there are pending load
arthursonzognid409c252019-03-14 09:22:22211 // requests in WorkQueue.
212 void RemoveLoadingFrame(blink::WebFrame* frame);
lukasza10cd8762016-04-27 20:03:02213
Hitoshi Yoshida0d0156c2020-10-29 17:36:15214 // Called when a main frame has been navigated away.
215 void OnFrameDeactivated(WebFrameTestProxy* frame);
216
217 // Called when a main frame has been restored from backward/forward cache.
218 void OnFrameReactivated(WebFrameTestProxy* frame);
219
danakj2d7921652019-09-11 17:20:12220 void PolicyDelegateDone();
221 bool PolicyDelegateEnabled() const;
222 bool PolicyDelegateIsPermissive() const;
223 bool PolicyDelegateShouldNotifyDone() const;
224 void SetToolTipText(const blink::WebString&);
225 void SetDragImage(const SkBitmap& drag_image);
226 bool ShouldDumpNavigationPolicy() const;
[email protected]97f9a7952014-03-14 11:50:33227
caseqcb2227832016-05-24 18:52:04228 bool ShouldDumpConsoleMessages() const;
Yoichi Osatoebf845ac72018-08-30 08:13:50229 // Controls whether console messages produced by the page are dumped
230 // to test output.
231 void SetDumpConsoleMessages(bool value);
232
danakj7c5a96c2020-07-03 15:58:36233 // The following trigger navigations on the main WebView.
234 void GoToOffset(int offset);
235 void Reload();
236 void LoadURLForFrame(const GURL& url, const std::string& frame_name);
237
238 // Add a message to the text dump for the web test.
239 void PrintMessage(const std::string& message);
240 // Add a message to stderr (not saved to expected output files, for debugging
241 // only).
242 void PrintMessageToStderr(const std::string& message);
243
244 // Register a new isolated filesystem with the given files, and return the
245 // new filesystem id.
246 blink::WebString RegisterIsolatedFileSystem(
247 const std::vector<base::FilePath>& file_paths);
248
Hitoshi Yoshida25a31d52020-10-29 08:00:33249 void ProcessWorkItem(mojom::WorkItemPtr work_item);
250 void ReplicateWorkQueueStates(const base::DictionaryValue& changed_values);
251
jkarlin3bddb7d2016-09-21 18:44:16252 blink::WebEffectiveConnectionType effective_connection_type() const {
253 return effective_connection_type_;
254 }
255
[email protected]97f9a7952014-03-14 11:50:33256 private:
[email protected]97f9a7952014-03-14 11:50:33257 friend class TestRunnerBindings;
258 friend class WorkQueue;
[email protected]97f9a7952014-03-14 11:50:33259
danakj2d7921652019-09-11 17:20:12260 // Helper class for managing events queued by methods like QueueLoad or
261 // QueueScript.
[email protected]97f9a7952014-03-14 11:50:33262 class WorkQueue {
Hitoshi Yoshida25a31d52020-10-29 08:00:33263 static constexpr const char* kKeyFrozen = "frozen";
264
[email protected]97f9a7952014-03-14 11:50:33265 public:
266 explicit WorkQueue(TestRunner* controller);
Hitoshi Yoshida25a31d52020-10-29 08:00:33267 ~WorkQueue() = default;
[email protected]97f9a7952014-03-14 11:50:33268
269 // Reset the state of the class between tests.
270 void Reset();
271
Hitoshi Yoshida25a31d52020-10-29 08:00:33272 void AddWork(mojom::WorkItemPtr work_item);
273 void RequestWork();
274 void ProcessWorkItem(mojom::WorkItemPtr work_item);
275 void ReplicateStates(const base::DictionaryValue& values);
[email protected]97f9a7952014-03-14 11:50:33276
Hitoshi Yoshida25a31d52020-10-29 08:00:33277 // Takes care of notifying the browser after a change to the state.
278 void OnStatesChanged();
danakj3130f122019-07-16 17:49:47279
Hitoshi Yoshida25a31d52020-10-29 08:00:33280 void set_loading(bool value) { loading_ = value; }
281
282 void set_frozen(bool value) { states_.SetBoolean(kKeyFrozen, value); }
283 void set_has_items(bool value) {
284 states_.SetBoolean(kDictKeyWorkQueueHasItems, value);
285 }
286 bool has_items() const { return GetStateValue(kDictKeyWorkQueueHasItems); }
[email protected]97f9a7952014-03-14 11:50:33287
288 private:
Hitoshi Yoshida25a31d52020-10-29 08:00:33289 bool ProcessWorkItemInternal(mojom::WorkItemPtr work_item);
[email protected]97f9a7952014-03-14 11:50:33290
Hitoshi Yoshida25a31d52020-10-29 08:00:33291 bool is_frozen() const { return GetStateValue(kKeyFrozen); }
292
293 bool GetStateValue(const char* key) const {
294 base::Optional<bool> value = states_.current_values().FindBoolPath(key);
295 DCHECK(value.has_value());
296 return value.value();
297 }
298
299 bool loading_ = true;
300 // Collection of flags to be synced with the browser process.
301 TrackedDictionary states_;
302
[email protected]97f9a7952014-03-14 11:50:33303 TestRunner* controller_;
[email protected]97f9a7952014-03-14 11:50:33304 };
305
danakje2834422020-07-10 21:18:58306 // If the main test window's main frame is hosted in this renderer process,
307 // then this will return it. Otherwise, it is in another process and this
308 // returns null.
309 WebFrameTestProxy* FindInProcessMainWindowMainFrame();
310
[email protected]97f9a7952014-03-14 11:50:33311 ///////////////////////////////////////////////////////////////////////////
312 // Methods dealing with the test logic
313
314 // By default, tests end when page load is complete. These methods are used
danakj2d7921652019-09-11 17:20:12315 // to delay the completion of the test until NotifyDone is called.
[email protected]97f9a7952014-03-14 11:50:33316 void WaitUntilDone();
danakj654fd752020-07-10 16:52:09317 void NotifyDone();
318
319 // When there are no conditions left to wait for, this is called to cause the
320 // test to end, collect results, and inform the browser.
321 void FinishTest();
[email protected]97f9a7952014-03-14 11:50:33322
323 // Methods for adding actions to the work queue. Used in conjunction with
danakj2d7921652019-09-11 17:20:12324 // WaitUntilDone/NotifyDone above.
[email protected]97f9a7952014-03-14 11:50:33325 void QueueBackNavigation(int how_far_back);
326 void QueueForwardNavigation(int how_far_forward);
327 void QueueReload();
Hitoshi Yoshidaa629c872020-10-22 16:33:33328 void QueueLoadingScript(const std::string& script);
329 void QueueNonLoadingScript(const std::string& script);
danakj12c09b62020-07-11 04:17:05330 void QueueLoad(const GURL& current_url,
331 const std::string& relative_url,
332 const std::string& target);
[email protected]97f9a7952014-03-14 11:50:33333
danakjcdff34e42020-05-04 21:42:48334 // Called from the TestRunnerBindings to inform that the test has modified
335 // the TestPreferences. This will update the WebkitPreferences in the renderer
336 // and the browser.
337 void OnTestPreferencesChanged(const TestPreferences& test_prefs,
338 RenderFrame* frame);
339
[email protected]97f9a7952014-03-14 11:50:33340 // Causes navigation actions just printout the intended navigation instead
341 // of taking you to the page. This is used for cases like mailto, where you
342 // don't actually want to open the mail program.
343 void SetCustomPolicyDelegate(gin::Arguments* args);
344
345 // Delays completion of the test until the policy delegate runs.
346 void WaitForPolicyDelegate();
347
danakjaa87f0092020-07-07 17:13:43348 // This is the count of windows which have their main frame in this renderer
349 // process. A cross-origin window would not appear in this count.
350 int InProcessWindowCount();
[email protected]97f9a7952014-03-14 11:50:33351
Kent Tamura21d1de62018-12-10 04:45:20352 // Allows web tests to manage origins' allow list.
Takashi Toyoshima66e7d0d2018-08-28 09:20:10353 void AddOriginAccessAllowListEntry(const std::string& source_origin,
[email protected]97f9a7952014-03-14 11:50:33354 const std::string& destination_protocol,
355 const std::string& destination_host,
356 bool allow_destination_subdomains);
[email protected]97f9a7952014-03-14 11:50:33357
[email protected]97f9a7952014-03-14 11:50:33358 // Enables or disables subpixel positioning (i.e. fractional X positions for
359 // glyphs) in text rendering on Linux. Since this method changes global
360 // settings, tests that call it must use their own custom font family for
361 // all text that they render. If not, an already-cached style will be used,
362 // resulting in the changed setting being ignored.
363 void SetTextSubpixelPositioning(bool value);
364
[email protected]97f9a7952014-03-14 11:50:33365 // After this function is called, all window-sizing machinery is
366 // short-circuited inside the renderer. This mode is necessary for
367 // some tests that were written before browsers had multi-process architecture
368 // and rely on window resizes to happen synchronously.
369 // The function has "unfortunate" it its name because we must strive to remove
370 // all tests that rely on this... well, unfortunate behavior. See
371 // http://crbug.com/309760 for the plan.
372 void UseUnfortunateSynchronousResizeMode();
373
Dave Tapuska442a74f2020-08-20 15:50:46374 // Set the mock orientation on |view| to |orientation|.
375 void SetMockScreenOrientation(WebViewTestProxy* view,
376 const std::string& orientation);
377 // Disable any mock orientation on |view| that is set.
378 void DisableMockScreenOrientation(WebViewTestProxy* view);
[email protected]e0bc2cb2014-03-20 17:34:24379
Mario Sanchez Prada0bd8b8c2020-10-21 17:49:23380 // Modify accept_languages in blink::RendererPreferences.
[email protected]ebd5ea52014-05-28 14:51:15381 void SetAcceptLanguages(const std::string& accept_languages);
382
[email protected]97f9a7952014-03-14 11:50:33383 ///////////////////////////////////////////////////////////////////////////
384 // Methods that modify the state of TestRunner
385
Xianzhu Wang8d64fc32018-10-15 02:26:53386 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33387 // descriptive text for each editing command. It takes no arguments, and
388 // ignores any that may be present.
389 void DumpEditingCallbacks();
390
Xianzhu Wang6e84f0992018-10-23 23:07:55391 // This function sets a flag that tells the test runner to dump pages as
392 // plain text. The pixel results will not be generated for this test.
393 // It has higher priority than DumpAsMarkup() and DumpAsLayout().
[email protected]97f9a7952014-03-14 11:50:33394 void DumpAsText();
395
Xianzhu Wang8d64fc32018-10-15 02:26:53396 // This function sets a flag that tells the test runner to dump pages as
[email protected]fdc433c02014-06-02 19:27:14397 // the DOM contents, rather than as a text representation of the renderer's
Xianzhu Wang6e84f0992018-10-23 23:07:55398 // state. The pixel results will not be generated for this test. It has
399 // higher priority than DumpAsLayout(), but lower than DumpAsText().
[email protected]fdc433c02014-06-02 19:27:14400 void DumpAsMarkup();
401
Xianzhu Wang6e84f0992018-10-23 23:07:55402 // This function sets a flag that tells the test runner to dump pages as
403 // plain text. It will also generate a pixel dump for the test.
[email protected]97f9a7952014-03-14 11:50:33404 void DumpAsTextWithPixelResults();
405
Xianzhu Wang6e84f0992018-10-23 23:07:55406 // This function sets a flag that tells the test runner to dump pages as
407 // text representation of the layout. The pixel results will not be generated
408 // for this test. It has lower priority than DumpAsText() and DumpAsMarkup().
409 void DumpAsLayout();
410
411 // This function sets a flag that tells the test runner to dump pages as
412 // text representation of the layout. It will also generate a pixel dump for
413 // the test.
414 void DumpAsLayoutWithPixelResults();
415
Xianzhu Wang8d64fc32018-10-15 02:26:53416 // This function sets a flag that tells the test runner to recursively dump
Xianzhu Wang6e84f0992018-10-23 23:07:55417 // all frames as text, markup or layout depending on which of DumpAsText,
418 // DumpAsMarkup and DumpAsLayout is effective.
Xianzhu Wang8d64fc32018-10-15 02:26:53419 void DumpChildFrames();
[email protected]97f9a7952014-03-14 11:50:33420
Xianzhu Wang8d64fc32018-10-15 02:26:53421 // This function sets a flag that tells the test runner to print out the
[email protected]97f9a7952014-03-14 11:50:33422 // information about icon changes notifications from WebKit.
423 void DumpIconChanges();
424
425 // Deals with Web Audio WAV file data.
426 void SetAudioData(const gin::ArrayBufferView& view);
427
Xianzhu Wang8d64fc32018-10-15 02:26:53428 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33429 // descriptive text for each frame load callback. It takes no arguments, and
430 // ignores any that may be present.
431 void DumpFrameLoadCallbacks();
432
Xianzhu Wang8d64fc32018-10-15 02:26:53433 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33434 // descriptive text for each PingLoader dispatch. It takes no arguments, and
435 // ignores any that may be present.
436 void DumpPingLoaderCallbacks();
437
Xianzhu Wang8d64fc32018-10-15 02:26:53438 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33439 // user gesture status text for some frame load callbacks. It takes no
440 // arguments, and ignores any that may be present.
441 void DumpUserGestureInFrameLoadCallbacks();
442
443 void DumpTitleChanges();
444
Xianzhu Wang8d64fc32018-10-15 02:26:53445 // This function sets a flag that tells the test runner to dump all calls to
[email protected]97f9a7952014-03-14 11:50:33446 // WebViewClient::createView().
447 // It takes no arguments, and ignores any that may be present.
448 void DumpCreateView();
449
450 void SetCanOpenWindows();
451
Xianzhu Wang8d64fc32018-10-15 02:26:53452 // This function sets a flag that tells the test runner to dump the MIME type
[email protected]97f9a7952014-03-14 11:50:33453 // for each resource that was loaded. It takes no arguments, and ignores any
454 // that may be present.
455 void DumpResourceResponseMIMETypes();
456
mlamouri007f9d72015-02-27 16:27:25457 // WebContentSettingsClient related.
[email protected]97f9a7952014-03-14 11:50:33458 void SetImagesAllowed(bool allowed);
459 void SetScriptsAllowed(bool allowed);
460 void SetStorageAllowed(bool allowed);
[email protected]97f9a7952014-03-14 11:50:33461 void SetAllowRunningOfInsecureContent(bool allowed);
462 void DumpPermissionClientCallbacks();
463
Xianzhu Wang8d64fc32018-10-15 02:26:53464 // This function sets a flag that tells the test runner to print out a text
[email protected]97f9a7952014-03-14 11:50:33465 // representation of the back/forward list. It ignores all arguments.
466 void DumpBackForwardList();
467
468 void DumpSelectionRect();
[email protected]97f9a7952014-03-14 11:50:33469
470 // Causes layout to happen as if targetted to printed pages.
471 void SetPrinting();
Xianzhu Wangdbb84fc2018-02-03 00:33:35472 void SetPrintingForFrame(const std::string& frame_name);
[email protected]97f9a7952014-03-14 11:50:33473
474 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
475
476 // Causes WillSendRequest to clear certain headers.
Dominic Farolinoaee9c1b82019-12-18 03:20:10477 // Note: This cannot be used to clear the request's `Referer` header, as this
478 // header is computed later given its referrer string member. To clear it, use
479 // SetWillSendRequestClearReferrer() below.
[email protected]97f9a7952014-03-14 11:50:33480 void SetWillSendRequestClearHeader(const std::string& header);
481
Dominic Farolinoaee9c1b82019-12-18 03:20:10482 // Causes WillSendRequest to clear the request's referrer string and set its
483 // referrer policy to the default.
484 void SetWillSendRequestClearReferrer();
485
[email protected]a79cb9912014-04-26 22:07:33486 // Sets a flag that causes the test to be marked as completed when the
danakj2d7921652019-09-11 17:20:12487 // WebLocalFrameClient receives a LoadURLExternally() call.
[email protected]a79cb9912014-04-26 22:07:33488 void WaitUntilExternalURLLoad();
489
lukasza1b546c12016-04-04 16:19:20490 // This function sets a flag to dump the drag image when the next drag&drop is
491 // initiated. It is equivalent to DumpAsTextWithPixelResults but the pixel
492 // results will be the drag image instead of a snapshot of the page.
jackhou656fc852015-02-13 09:04:17493 void DumpDragImage();
494
lfg05e41372016-07-22 15:38:10495 // Sets a flag that tells the WebViewTestProxy to dump the default navigation
danakj2d7921652019-09-11 17:20:12496 // policy passed to the DecidePolicyForNavigation callback.
jochenc3a98da12015-03-10 13:59:58497 void DumpNavigationPolicy();
498
tkent217ff8852016-11-14 04:43:49499 // Controls whether JavaScript dialogs such as alert() are dumped to test
500 // output.
501 void SetDumpJavaScriptDialogs(bool value);
502
jkarlin3bddb7d2016-09-21 18:44:16503 // Overrides the NetworkQualityEstimator's estimated network type. If |type|
504 // is TypeUnknown the NQE's value is used. Be sure to call this with
505 // TypeUnknown at the end of your test if you use this.
506 void SetEffectiveConnectionType(
507 blink::WebEffectiveConnectionType connection_type);
508
danakj7c5a96c2020-07-03 15:58:36509 // Takes care of notifying the browser after a change to web test runtime
lukasza083b4f12016-03-24 16:51:43510 // flags.
Kent Tamura2eab5b12018-12-07 04:31:23511 void OnWebTestRuntimeFlagsChanged();
lukaszac9cbe712016-03-14 14:06:43512
[email protected]97f9a7952014-03-14 11:50:33513 ///////////////////////////////////////////////////////////////////////////
514 // Internal helpers
[email protected]eec9e78e2014-06-16 21:38:48515
danakj7c5a96c2020-07-03 15:58:36516 mojo::AssociatedRemote<mojom::WebTestControlHost>&
517 GetWebTestControlHostRemote();
518 void HandleWebTestControlHostDisconnected();
519 mojo::AssociatedRemote<mojom::WebTestControlHost>
520 web_test_control_host_remote_;
521
danakjaa87f0092020-07-07 17:13:43522 mojom::WebTestBluetoothFakeAdapterSetter& GetBluetoothFakeAdapterSetter();
523 void HandleBluetoothFakeAdapterSetterDisconnected();
524 mojo::Remote<mojom::WebTestBluetoothFakeAdapterSetter>
525 bluetooth_fake_adapter_setter_;
526
danakj3130f122019-07-16 17:49:47527 bool test_is_running_ = false;
[email protected]97f9a7952014-03-14 11:50:33528
[email protected]97f9a7952014-03-14 11:50:33529 WorkQueue work_queue_;
530
[email protected]97f9a7952014-03-14 11:50:33531 // Bound variable to return the name of this platform (chromium).
532 std::string platform_name_;
533
lukasza9b9d70e2016-02-25 23:45:44534 // Flags controlling what content gets dumped as a layout text result.
Kent Tamura2eab5b12018-12-07 04:31:23535 WebTestRuntimeFlags web_test_runtime_flags_;
[email protected]97f9a7952014-03-14 11:50:33536
Xianzhu Wang8d64fc32018-10-15 02:26:53537 // If true, the test runner will output a base64 encoded WAVE file.
[email protected]97f9a7952014-03-14 11:50:33538 bool dump_as_audio_;
539
Xianzhu Wang8d64fc32018-10-15 02:26:53540 // If true, the test runner will produce a dump of the back forward list as
[email protected]97f9a7952014-03-14 11:50:33541 // well.
542 bool dump_back_forward_list_;
543
[email protected]97f9a7952014-03-14 11:50:33544 // If true, pixel dump will be produced as a series of 1px-tall, view-wide
545 // individual paints over the height of the view.
546 bool test_repaint_;
547
548 // If true and test_repaint_ is true as well, pixel dump will be produced as
549 // a series of 1px-wide, view-tall paints across the width of the view.
550 bool sweep_horizontally_;
551
[email protected]97f9a7952014-03-14 11:50:33552 std::set<std::string> http_headers_to_clear_;
Dominic Farolinoaee9c1b82019-12-18 03:20:10553 bool clear_referrer_ = false;
[email protected]97f9a7952014-03-14 11:50:33554
555 // WAV audio data is stored here.
danakjc50c5e22020-07-09 17:06:14556 std::vector<uint8_t> audio_data_;
[email protected]97f9a7952014-03-14 11:50:33557
danakjaa87f0092020-07-07 17:13:43558 base::flat_set<WebFrameTestProxy*> main_frames_;
danakj1985c8f2020-07-09 18:28:16559 // The set of all render views in this renderer process. This may include
560 // cross-site windows accessible from this process, or parts of same-site
561 // windows opened from any renderer process.
562 base::flat_set<WebViewTestProxy*> render_views_;
[email protected]97f9a7952014-03-14 11:50:33563
arthursonzognid409c252019-03-14 09:22:22564 // This is non empty when a load is in progress.
565 std::vector<blink::WebFrame*> loading_frames_;
danakj654fd752020-07-10 16:52:09566 // We do not want the test to end until the main frame finishes loading. This
567 // starts as true at the beginning of the test, and will be set to false once
568 // we run out of frames to load at any time.
569 bool main_frame_loaded_ = false;
danakj3130f122019-07-16 17:49:47570 // When a loading task is started, this bool is set until all loading_frames_
571 // are completed and removed. This bool becomes true earlier than
danakj654fd752020-07-10 16:52:09572 // loading_frames_ becomes non-empty.
573 bool frame_will_start_load_ = true;
danakj3130f122019-07-16 17:49:47574 // When NotifyDone() occurs, if loading is still working, it is delayed, and
575 // this bool tracks that NotifyDone() was called. This differentiates from a
576 // test that was not waiting for NotifyDone() at all.
577 bool did_notify_done_ = false;
[email protected]97f9a7952014-03-14 11:50:33578
danakj1a887ad2020-09-01 22:16:01579 WebTestContentSettingsClient test_content_settings_client_;
580 FakeScreenOrientationImpl fake_screen_orientation_impl_;
danakjaa87f0092020-07-07 17:13:43581 GamepadController gamepad_controller_;
lukaszafd124602016-04-01 16:53:30582
lukasza1b546c12016-04-04 16:19:20583 // Captured drag image.
danakj0c75ad82018-07-10 19:50:12584 SkBitmap drag_image_;
lukasza1b546c12016-04-04 16:19:20585
Mason Freedb0855622018-10-02 17:49:47586 // True if rasterization should be performed during tests that examine
587 // fling-style animations. This includes middle-click auto-scroll behaviors.
588 // This does not include most "ordinary" animations, such as CSS animations.
danakj3130f122019-07-16 17:49:47589 bool animation_requires_raster_ = false;
Mason Freedb0855622018-10-02 17:49:47590
Kent Tamura21d1de62018-12-10 04:45:20591 // An effective connection type settable by web tests.
danakj3130f122019-07-16 17:49:47592 blink::WebEffectiveConnectionType effective_connection_type_ =
593 blink::WebEffectiveConnectionType::kTypeUnknown;
jkarlin3bddb7d2016-09-21 18:44:16594
danakj529c0642020-08-28 18:02:18595 // Set to ack callback when the browser asks the renderer to reset at the end
596 // of a test. Part of reset involves performing a navigation to about:blank
597 // and this tracks that the navigation is in progress, and is called to inform
598 // the browser that the reset is complete.
599 base::OnceClosure waiting_for_reset_navigation_to_about_blank_;
600
Jeremy Roman3bca4bf2019-07-11 03:41:25601 base::WeakPtrFactory<TestRunner> weak_factory_{this};
[email protected]97f9a7952014-03-14 11:50:33602
603 DISALLOW_COPY_AND_ASSIGN(TestRunner);
604};
605
danakj741848a2020-04-07 22:48:06606} // namespace content
[email protected]97f9a7952014-03-14 11:50:33607
danakj89f47082020-09-02 17:53:43608#endif // CONTENT_WEB_TEST_RENDERER_TEST_RUNNER_H_