blob: 7cc22be91dac1630d2f0d1b6576ba4f856a4e6ce [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2014 The Chromium Authors
[email protected]97f9a7952014-03-14 11:50:332// 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>
Arthur Sonzognic686e8f2024-01-11 08:36:3711#include <optional>
[email protected]97f9a7952014-03-14 11:50:3312#include <set>
13#include <string>
benwells0c0d3f12015-05-25 01:03:1714#include <vector>
[email protected]97f9a7952014-03-14 11:50:3315
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"
Avi Drissmanadac21992023-01-11 23:46:3919#include "base/functional/callback_forward.h"
Kalvin Leebc3754ae2023-10-01 22:37:3420#include "base/memory/raw_ptr.h"
[email protected]97f9a7952014-03-14 11:50:3321#include "base/memory/weak_ptr.h"
Nan Lin478672f2022-06-29 01:10:2422#include "base/values.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"
Dave Tapuska01437d8e2021-01-29 18:42:1826#include "content/web_test/common/web_test_runtime_flags.h"
danakj89f47082020-09-02 17:53:4327#include "content/web_test/renderer/fake_screen_orientation_impl.h"
28#include "content/web_test/renderer/gamepad_controller.h"
29#include "content/web_test/renderer/layout_dump.h"
30#include "content/web_test/renderer/web_test_content_settings_client.h"
Dave Tapuska1f7929c2023-02-03 18:11:5631#include "printing/buildflags/buildflags.h"
Thorben Troebst2478eed2022-09-07 17:09:0732#include "printing/page_range.h"
Blink Reformata30d4232018-04-07 15:31:0633#include "third_party/blink/public/platform/web_effective_connection_type.h"
danakj7c5a96c2020-07-03 15:58:3634#include "third_party/blink/public/platform/web_url.h"
Fredrik Söderquistb2b39eb92019-11-18 16:16:5035#include "third_party/skia/include/core/SkBitmap.h"
[email protected]97f9a7952014-03-14 11:50:3336#include "v8/include/v8.h"
37
danakj754eaff2020-03-31 17:46:5838class SkBitmap;
39
[email protected]97f9a7952014-03-14 11:50:3340namespace blink {
mlamouri007f9d72015-02-27 16:27:2541class WebContentSettingsClient;
[email protected]97f9a7952014-03-14 11:50:3342class WebFrame;
Dave Tapuska4d524862020-12-01 19:43:4143class WebFrameWidget;
[email protected]97f9a7952014-03-14 11:50:3344class WebString;
45class WebView;
danakjb0092062020-05-04 19:53:0646} // namespace blink
[email protected]97f9a7952014-03-14 11:50:3347
48namespace gin {
49class ArrayBufferView;
50class Arguments;
danakjb0092062020-05-04 19:53:0651} // namespace gin
[email protected]97f9a7952014-03-14 11:50:3352
danakj741848a2020-04-07 22:48:0653namespace content {
danakjb5ae26052020-04-23 17:20:2254class RenderFrame;
Yuki Shiinoc955c4c2020-07-06 04:38:1555class SpellCheckClient;
danakj552c1cc92020-07-14 22:34:1056class TestRunnerBindings;
danakj4cfe7002020-05-13 23:04:3957class WebFrameTestProxy;
danakj552c1cc92020-07-14 22:34:1058struct TestPreferences;
[email protected]97f9a7952014-03-14 11:50:3359
lukaszab2ad0502016-04-27 15:51:4260// TestRunner class currently has dual purpose:
danakj2d7921652019-09-11 17:20:1261// 1. It implements TestRunner javascript bindings for "global" / "ambient".
lukaszab2ad0502016-04-27 15:51:4262// Examples:
danakj2d7921652019-09-11 17:20:1263// - TestRunner.DumpAsText (test flag affecting test behavior)
64// - TestRunner.SetAllowRunningOfInsecureContent (test flag affecting product
lukaszab2ad0502016-04-27 15:51:4265// behavior)
danakj2d7921652019-09-11 17:20:1266// - TestRunner.SetTextSubpixelPositioning (directly interacts with product).
lukaszab2ad0502016-04-27 15:51:4267// 2. It manages global test state. Example:
68// - Tracking topLoadingFrame that can finish the test when it loads.
danakj1985c8f2020-07-09 18:28:1669// - WorkQueue holding load requests from web tests.
Kent Tamura21d1de62018-12-10 04:45:2070// - WebTestRuntimeFlags
danakj9f2d3502020-04-07 21:20:2171class TestRunner {
[email protected]97f9a7952014-03-14 11:50:3372 public:
danakj1985c8f2020-07-09 18:28:1673 TestRunner();
Peter Boström828b9022021-09-21 02:28:4374
75 TestRunner(const TestRunner&) = delete;
76 TestRunner& operator=(const TestRunner&) = delete;
77
[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
Dave Tapuska1b235d82021-02-01 17:40:2585 // Resets state on the |web_view| for the next test.
86 void ResetWebView(blink::WebView* web_view);
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.
Dave Tapuska64faea42024-01-05 21:37:1499 void FinishTestIfReady(blink::WebLocalFrame& source);
100 void FinishTestIfReady(WebFrameTestProxy& source);
danakj4b0ef922020-08-28 14:34:57101 // Notification that another renderer has explicitly asked the test to end.
Dave Tapuska64faea42024-01-05 21:37:14102 void TestFinishedFromSecondaryRenderer(WebFrameTestProxy& source);
danakj3130f122019-07-16 17:49:47103
danakj529c0642020-08-28 18:02:18104 // Performs a reset at the end of a test, in order to prepare for the next
arthursonzogni7ec0feb2021-04-01 18:36:03105 // test.
106 void ResetRendererAfterWebTest();
danakj529c0642020-08-28 18:02:18107
danakjaa87f0092020-07-07 17:13:43108 // Track the set of all main frames in the process, which is also the set of
109 // windows rooted in this process.
Dave Tapuska64faea42024-01-05 21:37:14110 void AddMainFrame(WebFrameTestProxy& frame);
111 void RemoveMainFrame(WebFrameTestProxy& frame);
danakj754eaff2020-03-31 17:46:58112
danakj27e4ebe2020-04-15 18:48:27113 // Returns true if the test output should be an audio file, rather than text
114 // or pixel results.
danakj754eaff2020-03-31 17:46:58115 bool ShouldDumpAsAudio() const;
danakj27e4ebe2020-04-15 18:48:27116 // Gets the audio test output for when audio test results are requested by
117 // the current test.
danakjc50c5e22020-07-09 17:06:14118 const std::vector<uint8_t>& GetAudioData() const;
danakj754eaff2020-03-31 17:46:58119
120 // Reports if tests requested a recursive layout dump of all frames
121 // (i.e. by calling testRunner.dumpChildFramesAsText() from javascript).
122 bool IsRecursiveLayoutDumpRequested();
123
danakj754eaff2020-03-31 17:46:58124 // Returns true if the selection window should be painted onto captured
125 // pixels.
126 bool ShouldDumpSelectionRect() const;
127
128 // Returns false if the browser should capture the pixel output, true if it
danakje9f674512020-07-07 19:23:06129 // can be done locally in the renderer via DumpPixelsInRenderer().
danakj754eaff2020-03-31 17:46:58130 bool CanDumpPixelsFromRenderer() const;
131
Dave Tapuska1f7929c2023-02-03 18:11:56132#if BUILDFLAG(ENABLE_PRINTING)
Morten Stenshorneecd033fe402023-11-30 14:31:33133 // Returns the default page size to be used for printing. This is either the
134 // size that was explicitly set via SetPrintingSize or the size of the frame
135 // if no size was set.
Thorben Troebst7ab80162022-09-07 19:10:15136 gfx::Size GetPrintingPageSize(blink::WebLocalFrame* frame) const;
137
Morten Stenshorneecd033fe402023-11-30 14:31:33138 // Returns the default page margin size to be used for printing. The value
139 // applies to all four sides of the page.
140 int GetPrintingMargin() const;
141
Thorben Troebst2478eed2022-09-07 17:09:07142 // Returns the page ranges to be printed. This is specified in the document
143 // via a tag of the form <meta name=reftest-pages content="1,2-3,5-">. If no
144 // tag is found, print all pages.
145 printing::PageRanges GetPrintingPageRanges(blink::WebLocalFrame* frame) const;
Dave Tapuska1f7929c2023-02-03 18:11:56146#endif
Thorben Troebst2478eed2022-09-07 17:09:07147
Dave Tapuska13da016a2021-02-04 21:51:58148 // Snapshots the content of |main_frame| using the mode requested by the
149 // current test.
150 SkBitmap DumpPixelsInRenderer(blink::WebLocalFrame* main_frame);
danakj754eaff2020-03-31 17:46:58151
152 // Replicates changes to web test runtime flags (i.e. changes that happened in
danakj529c0642020-08-28 18:02:18153 // another renderer). See also `OnWebTestRuntimeFlagsChanged()`.
Kent Tamura679c7c42018-12-05 03:21:10154 void ReplicateWebTestRuntimeFlagsChanges(
Nan Lin478672f2022-06-29 01:10:24155 const base::Value::Dict& changed_values);
danakj754eaff2020-03-31 17:46:58156
157 // If custom text dump is present (i.e. if testRunner.setCustomTextOutput has
158 // been called from javascript), then returns |true| and populates the
159 // |custom_text_dump| argument. Otherwise returns |false|.
160 bool HasCustomTextDump(std::string* custom_text_dump) const;
161
162 // Returns true if the history should be included in text results generated at
163 // the end of the test.
164 bool ShouldDumpBackForwardList() const;
165
166 // Returns true if pixel results should be generated at the end of the test.
167 bool ShouldGeneratePixelResults();
168
danakj049cb6a2020-07-11 03:11:34169 TextResultType ShouldGenerateTextResults();
170
danakj674bf1c02020-05-01 18:37:51171 // Activate the window holding the given main frame, and set focus on the
172 // frame's widget.
173 void FocusWindow(RenderFrame* main_frame, bool focus);
[email protected]97f9a7952014-03-14 11:50:33174
lukasza01da2602016-04-05 14:51:26175 // Methods used by WebViewTestClient and WebFrameTestClient.
danakj2d7921652019-09-11 17:20:12176 bool ShouldStayOnPageAfterHandlingBeforeUnload() const;
danakj2d7921652019-09-11 17:20:12177 bool ShouldDumpAsCustomText() const;
178 std::string CustomDumpText() const;
abhishek.a21ca9b5602014-09-19 07:33:33179 void ShowDevTools(const std::string& settings,
[email protected]06c253012014-04-16 18:35:33180 const std::string& frontend_url);
Dave Tapuska64faea42024-01-05 21:37:14181 void SetShouldDumpAsLayout(bool, WebFrameTestProxy& source);
182 void SetCustomTextOutput(const std::string& text, WebFrameTestProxy& source);
183 void SetShouldGeneratePixelResults(bool, WebFrameTestProxy& source);
184 void SetShouldDumpFrameLoadCallbacks(bool, WebFrameTestProxy& source);
danakj2d7921652019-09-11 17:20:12185 bool ShouldDumpEditingCallbacks() const;
186 bool ShouldDumpFrameLoadCallbacks() const;
187 bool ShouldDumpPingLoaderCallbacks() const;
188 bool ShouldDumpUserGestureInFrameLoadCallbacks() const;
189 bool ShouldDumpTitleChanges() const;
190 bool ShouldDumpIconChanges() const;
danakj2d7921652019-09-11 17:20:12191 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;
Dave Tapuska64faea42024-01-05 21:37:14196 void SetIsWebPlatformTestsMode(WebFrameTestProxy& source);
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.
Dave Tapuska64faea42024-01-05 21:37:14205 void AddLoadingFrame(blink::WebLocalFrame* 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.
Dave Tapuska64faea42024-01-05 21:37:14212 void RemoveLoadingFrame(blink::WebLocalFrame* frame);
lukasza10cd8762016-04-27 20:03:02213
Hitoshi Yoshida0d0156c2020-10-29 17:36:15214 // Called when a main frame has been navigated away.
Dave Tapuska64faea42024-01-05 21:37:14215 void OnFrameDeactivated(WebFrameTestProxy& frame);
Hitoshi Yoshida0d0156c2020-10-29 17:36:15216
217 // Called when a main frame has been restored from backward/forward cache.
Dave Tapuska64faea42024-01-05 21:37:14218 void OnFrameReactivated(WebFrameTestProxy& frame);
Hitoshi Yoshida0d0156c2020-10-29 17:36:15219
Dave Tapuska64faea42024-01-05 21:37:14220 void PolicyDelegateDone(WebFrameTestProxy& source);
danakj2d7921652019-09-11 17:20:12221 bool PolicyDelegateEnabled() const;
222 bool PolicyDelegateIsPermissive() const;
223 bool PolicyDelegateShouldNotifyDone() const;
danakj2d7921652019-09-11 17:20:12224 void SetDragImage(const SkBitmap& drag_image);
225 bool ShouldDumpNavigationPolicy() const;
[email protected]97f9a7952014-03-14 11:50:33226
caseqcb2227832016-05-24 18:52:04227 bool ShouldDumpConsoleMessages() const;
Yoichi Osatoebf845ac72018-08-30 08:13:50228 // Controls whether console messages produced by the page are dumped
229 // to test output.
Dave Tapuska64faea42024-01-05 21:37:14230 void SetDumpConsoleMessages(bool value, WebFrameTestProxy& source);
danakj7c5a96c2020-07-03 15:58:36231
232 // Add a message to the text dump for the web test.
Dave Tapuska64faea42024-01-05 21:37:14233 void PrintMessage(const std::string& message, WebFrameTestProxy& source);
danakj7c5a96c2020-07-03 15:58:36234
235 // Register a new isolated filesystem with the given files, and return the
236 // new filesystem id.
237 blink::WebString RegisterIsolatedFileSystem(
Dave Tapuska64faea42024-01-05 21:37:14238 const std::vector<base::FilePath>& file_paths,
239 WebFrameTestProxy& source);
danakj7c5a96c2020-07-03 15:58:36240
Dave Tapuska64faea42024-01-05 21:37:14241 void ProcessWorkItem(mojom::WorkItemPtr work_item, WebFrameTestProxy& source);
242 void ReplicateWorkQueueStates(const base::Value::Dict& changed_values,
243 WebFrameTestProxy& source);
Hitoshi Yoshida25a31d52020-10-29 08:00:33244
jkarlin3bddb7d2016-09-21 18:44:16245 blink::WebEffectiveConnectionType effective_connection_type() const {
246 return effective_connection_type_;
247 }
248
Dave Tapuska012b5b12021-02-04 21:40:24249 // Determine the the frame is considered in the main window.
250 bool IsFrameInMainWindow(blink::WebLocalFrame* frame);
251
252 // Set the main window and test configuration.
253 void SetMainWindowAndTestConfiguration(
254 blink::WebLocalFrame* initial_local_root,
255 mojom::WebTestRunTestConfigurationPtr config);
256 const mojom::WebTestRunTestConfiguration& TestConfig() const;
257
258 // Returns an asbsolute file path. This depends on the current test
259 // configuration so it should only be called while a test is running.
260 blink::WebString GetAbsoluteWebStringFromUTF8Path(
261 const std::string& utf8_path);
262
Randolf1d3bc062023-03-29 17:37:55263 // Disables automatic drag and drop in web tests' web frame widget
264 // (WebTestWebFrameWidgetImpl).
265 //
266 // In general, drag and drop will automatically be performed because web tests
267 // do not have drag and drop enabled. If you need to control the drag and drop
268 // lifecycle yourself, you can disable it here.
Dave Tapuska64faea42024-01-05 21:37:14269 void DisableAutomaticDragDrop(WebFrameTestProxy& source);
Randolf1d3bc062023-03-29 17:37:55270 bool AutomaticDragDropEnabled();
271
Dave Tapuska64faea42024-01-05 21:37:14272 const WebTestRuntimeFlags& GetFlags();
273
[email protected]97f9a7952014-03-14 11:50:33274 private:
[email protected]97f9a7952014-03-14 11:50:33275 friend class TestRunnerBindings;
276 friend class WorkQueue;
Dave Tapuska012b5b12021-02-04 21:40:24277 class MainWindowTracker;
[email protected]97f9a7952014-03-14 11:50:33278
danakj2d7921652019-09-11 17:20:12279 // Helper class for managing events queued by methods like QueueLoad or
280 // QueueScript.
[email protected]97f9a7952014-03-14 11:50:33281 class WorkQueue {
Hitoshi Yoshida25a31d52020-10-29 08:00:33282 static constexpr const char* kKeyFrozen = "frozen";
283
[email protected]97f9a7952014-03-14 11:50:33284 public:
285 explicit WorkQueue(TestRunner* controller);
Hitoshi Yoshida25a31d52020-10-29 08:00:33286 ~WorkQueue() = default;
[email protected]97f9a7952014-03-14 11:50:33287
288 // Reset the state of the class between tests.
289 void Reset();
290
Dave Tapuska64faea42024-01-05 21:37:14291 void AddWork(mojom::WorkItemPtr work_item, WebFrameTestProxy& source);
292 void RequestWork(WebFrameTestProxy& source);
293 void ProcessWorkItem(mojom::WorkItemPtr work_item,
294 WebFrameTestProxy& source);
295 void ReplicateStates(const base::Value::Dict& values,
296 WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33297
Hitoshi Yoshida25a31d52020-10-29 08:00:33298 // Takes care of notifying the browser after a change to the state.
Dave Tapuska64faea42024-01-05 21:37:14299 void OnStatesChanged(WebFrameTestProxy& source);
danakj3130f122019-07-16 17:49:47300
Hitoshi Yoshida25a31d52020-10-29 08:00:33301 void set_loading(bool value) { loading_ = value; }
302
303 void set_frozen(bool value) { states_.SetBoolean(kKeyFrozen, value); }
304 void set_has_items(bool value) {
305 states_.SetBoolean(kDictKeyWorkQueueHasItems, value);
306 }
307 bool has_items() const { return GetStateValue(kDictKeyWorkQueueHasItems); }
[email protected]97f9a7952014-03-14 11:50:33308
309 private:
Dave Tapuska64faea42024-01-05 21:37:14310 bool ProcessWorkItemInternal(mojom::WorkItemPtr work_item,
311 WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33312
Hitoshi Yoshida25a31d52020-10-29 08:00:33313 bool is_frozen() const { return GetStateValue(kKeyFrozen); }
314
315 bool GetStateValue(const char* key) const {
Arthur Sonzognic686e8f2024-01-11 08:36:37316 std::optional<bool> value =
Nan Lin478672f2022-06-29 01:10:24317 states_.current_values().FindBoolByDottedPath(key);
Hitoshi Yoshida25a31d52020-10-29 08:00:33318 DCHECK(value.has_value());
319 return value.value();
320 }
321
322 bool loading_ = true;
323 // Collection of flags to be synced with the browser process.
324 TrackedDictionary states_;
325
Bartek Nowierskif473c24b2024-02-20 17:51:15326 raw_ptr<TestRunner> controller_;
[email protected]97f9a7952014-03-14 11:50:33327 };
328
danakje2834422020-07-10 21:18:58329 // If the main test window's main frame is hosted in this renderer process,
330 // then this will return it. Otherwise, it is in another process and this
331 // returns null.
332 WebFrameTestProxy* FindInProcessMainWindowMainFrame();
333
[email protected]97f9a7952014-03-14 11:50:33334 ///////////////////////////////////////////////////////////////////////////
335 // Methods dealing with the test logic
336
337 // By default, tests end when page load is complete. These methods are used
danakj2d7921652019-09-11 17:20:12338 // to delay the completion of the test until NotifyDone is called.
Dave Tapuska64faea42024-01-05 21:37:14339 void WaitUntilDone(WebFrameTestProxy& source);
340 void NotifyDone(WebFrameTestProxy& source);
danakj654fd752020-07-10 16:52:09341
342 // When there are no conditions left to wait for, this is called to cause the
343 // test to end, collect results, and inform the browser.
Dave Tapuska64faea42024-01-05 21:37:14344 void FinishTest(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33345
346 // Methods for adding actions to the work queue. Used in conjunction with
danakj2d7921652019-09-11 17:20:12347 // WaitUntilDone/NotifyDone above.
Dave Tapuska64faea42024-01-05 21:37:14348 void QueueBackNavigation(int how_far_back, WebFrameTestProxy& source);
349 void QueueForwardNavigation(int how_far_forward, WebFrameTestProxy& source);
350 void QueueReload(WebFrameTestProxy& source);
351 void QueueLoadingScript(const std::string& script, WebFrameTestProxy& source);
352 void QueueNonLoadingScript(const std::string& script,
353 WebFrameTestProxy& source);
danakj12c09b62020-07-11 04:17:05354 void QueueLoad(const GURL& current_url,
355 const std::string& relative_url,
Dave Tapuska64faea42024-01-05 21:37:14356 const std::string& target,
357 WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33358
danakjcdff34e42020-05-04 21:42:48359 // Called from the TestRunnerBindings to inform that the test has modified
360 // the TestPreferences. This will update the WebkitPreferences in the renderer
361 // and the browser.
362 void OnTestPreferencesChanged(const TestPreferences& test_prefs,
Dave Tapuska64faea42024-01-05 21:37:14363 WebFrameTestProxy& frame);
danakjcdff34e42020-05-04 21:42:48364
[email protected]97f9a7952014-03-14 11:50:33365 // Causes navigation actions just printout the intended navigation instead
366 // of taking you to the page. This is used for cases like mailto, where you
367 // don't actually want to open the mail program.
Dave Tapuska64faea42024-01-05 21:37:14368 void SetCustomPolicyDelegate(gin::Arguments* args, WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33369
370 // Delays completion of the test until the policy delegate runs.
Dave Tapuska64faea42024-01-05 21:37:14371 void WaitForPolicyDelegate(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33372
danakjaa87f0092020-07-07 17:13:43373 // This is the count of windows which have their main frame in this renderer
374 // process. A cross-origin window would not appear in this count.
375 int InProcessWindowCount();
[email protected]97f9a7952014-03-14 11:50:33376
Kent Tamura21d1de62018-12-10 04:45:20377 // Allows web tests to manage origins' allow list.
Takashi Toyoshima66e7d0d2018-08-28 09:20:10378 void AddOriginAccessAllowListEntry(const std::string& source_origin,
[email protected]97f9a7952014-03-14 11:50:33379 const std::string& destination_protocol,
380 const std::string& destination_host,
381 bool allow_destination_subdomains);
[email protected]97f9a7952014-03-14 11:50:33382
[email protected]97f9a7952014-03-14 11:50:33383 // Enables or disables subpixel positioning (i.e. fractional X positions for
384 // glyphs) in text rendering on Linux. Since this method changes global
385 // settings, tests that call it must use their own custom font family for
386 // all text that they render. If not, an already-cached style will be used,
387 // resulting in the changed setting being ignored.
388 void SetTextSubpixelPositioning(bool value);
389
Dave Tapuska442a74f2020-08-20 15:50:46390 // Set the mock orientation on |view| to |orientation|.
Dave Tapuska64faea42024-01-05 21:37:14391 void SetMockScreenOrientation(const std::string& orientation,
392 WebFrameTestProxy& frame);
Dave Tapuska442a74f2020-08-20 15:50:46393 // Disable any mock orientation on |view| that is set.
Dave Tapuska13da016a2021-02-04 21:51:58394 void DisableMockScreenOrientation(blink::WebView* view);
[email protected]e0bc2cb2014-03-20 17:34:24395
[email protected]97f9a7952014-03-14 11:50:33396 ///////////////////////////////////////////////////////////////////////////
397 // Methods that modify the state of TestRunner
398
Xianzhu Wang8d64fc32018-10-15 02:26:53399 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33400 // descriptive text for each editing command. It takes no arguments, and
401 // ignores any that may be present.
Dave Tapuska64faea42024-01-05 21:37:14402 void DumpEditingCallbacks(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33403
Xianzhu Wang6e84f0992018-10-23 23:07:55404 // This function sets a flag that tells the test runner to dump pages as
405 // plain text. The pixel results will not be generated for this test.
406 // It has higher priority than DumpAsMarkup() and DumpAsLayout().
Dave Tapuska64faea42024-01-05 21:37:14407 void DumpAsText(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33408
Xianzhu Wang8d64fc32018-10-15 02:26:53409 // This function sets a flag that tells the test runner to dump pages as
[email protected]fdc433c02014-06-02 19:27:14410 // the DOM contents, rather than as a text representation of the renderer's
Xianzhu Wang6e84f0992018-10-23 23:07:55411 // state. The pixel results will not be generated for this test. It has
412 // higher priority than DumpAsLayout(), but lower than DumpAsText().
Dave Tapuska64faea42024-01-05 21:37:14413 void DumpAsMarkup(WebFrameTestProxy& source);
[email protected]fdc433c02014-06-02 19:27:14414
Xianzhu Wang6e84f0992018-10-23 23:07:55415 // This function sets a flag that tells the test runner to dump pages as
416 // plain text. It will also generate a pixel dump for the test.
Dave Tapuska64faea42024-01-05 21:37:14417 void DumpAsTextWithPixelResults(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33418
Xianzhu Wang6e84f0992018-10-23 23:07:55419 // This function sets a flag that tells the test runner to dump pages as
420 // text representation of the layout. The pixel results will not be generated
421 // for this test. It has lower priority than DumpAsText() and DumpAsMarkup().
Dave Tapuska64faea42024-01-05 21:37:14422 void DumpAsLayout(WebFrameTestProxy& source);
Xianzhu Wang6e84f0992018-10-23 23:07:55423
424 // This function sets a flag that tells the test runner to dump pages as
425 // text representation of the layout. It will also generate a pixel dump for
426 // the test.
Dave Tapuska64faea42024-01-05 21:37:14427 void DumpAsLayoutWithPixelResults(WebFrameTestProxy& source);
Xianzhu Wang6e84f0992018-10-23 23:07:55428
Xianzhu Wang8d64fc32018-10-15 02:26:53429 // This function sets a flag that tells the test runner to recursively dump
Xianzhu Wang6e84f0992018-10-23 23:07:55430 // all frames as text, markup or layout depending on which of DumpAsText,
431 // DumpAsMarkup and DumpAsLayout is effective.
Dave Tapuska64faea42024-01-05 21:37:14432 void DumpChildFrames(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33433
Xianzhu Wang8d64fc32018-10-15 02:26:53434 // This function sets a flag that tells the test runner to print out the
[email protected]97f9a7952014-03-14 11:50:33435 // information about icon changes notifications from WebKit.
Dave Tapuska64faea42024-01-05 21:37:14436 void DumpIconChanges(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33437
438 // Deals with Web Audio WAV file data.
439 void SetAudioData(const gin::ArrayBufferView& view);
440
Xianzhu Wang8d64fc32018-10-15 02:26:53441 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33442 // descriptive text for each frame load callback. It takes no arguments, and
443 // ignores any that may be present.
Dave Tapuska64faea42024-01-05 21:37:14444 void DumpFrameLoadCallbacks(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33445
Xianzhu Wang8d64fc32018-10-15 02:26:53446 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33447 // descriptive text for each PingLoader dispatch. It takes no arguments, and
448 // ignores any that may be present.
Dave Tapuska64faea42024-01-05 21:37:14449 void DumpPingLoaderCallbacks(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33450
Xianzhu Wang8d64fc32018-10-15 02:26:53451 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33452 // user gesture status text for some frame load callbacks. It takes no
453 // arguments, and ignores any that may be present.
Dave Tapuska64faea42024-01-05 21:37:14454 void DumpUserGestureInFrameLoadCallbacks(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33455
Dave Tapuska64faea42024-01-05 21:37:14456 void DumpTitleChanges(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33457
Xianzhu Wang8d64fc32018-10-15 02:26:53458 // This function sets a flag that tells the test runner to dump the MIME type
[email protected]97f9a7952014-03-14 11:50:33459 // for each resource that was loaded. It takes no arguments, and ignores any
460 // that may be present.
461 void DumpResourceResponseMIMETypes();
462
mlamouri007f9d72015-02-27 16:27:25463 // WebContentSettingsClient related.
Dave Tapuska64faea42024-01-05 21:37:14464 void SetImagesAllowed(bool allowed, WebFrameTestProxy& source);
465 void SetStorageAllowed(bool allowed, WebFrameTestProxy& source);
466 void SetAllowRunningOfInsecureContent(bool allowed,
467 WebFrameTestProxy& source);
468 void DumpPermissionClientCallbacks(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33469
Xianzhu Wang8d64fc32018-10-15 02:26:53470 // This function sets a flag that tells the test runner to print out a text
[email protected]97f9a7952014-03-14 11:50:33471 // representation of the back/forward list. It ignores all arguments.
472 void DumpBackForwardList();
473
Dave Tapuska64faea42024-01-05 21:37:14474 void DumpSelectionRect(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33475
Dave Tapuska64faea42024-01-05 21:37:14476 // Causes layout to happen as if targeted to printed pages.
477 void SetPrinting(WebFrameTestProxy& source);
478 void SetPrintingForFrame(const std::string& frame_name,
479 WebFrameTestProxy& source);
480 void SetPrintingSize(int width, int height, WebFrameTestProxy& source);
481 void SetPrintingMargin(int size, WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33482
Dave Tapuska64faea42024-01-05 21:37:14483 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value,
484 WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33485
486 // Causes WillSendRequest to clear certain headers.
Dominic Farolinoaee9c1b82019-12-18 03:20:10487 // Note: This cannot be used to clear the request's `Referer` header, as this
488 // header is computed later given its referrer string member. To clear it, use
489 // SetWillSendRequestClearReferrer() below.
[email protected]97f9a7952014-03-14 11:50:33490 void SetWillSendRequestClearHeader(const std::string& header);
491
Dominic Farolinoaee9c1b82019-12-18 03:20:10492 // Causes WillSendRequest to clear the request's referrer string and set its
493 // referrer policy to the default.
494 void SetWillSendRequestClearReferrer();
495
[email protected]a79cb9912014-04-26 22:07:33496 // Sets a flag that causes the test to be marked as completed when the
danakj2d7921652019-09-11 17:20:12497 // WebLocalFrameClient receives a LoadURLExternally() call.
Dave Tapuska64faea42024-01-05 21:37:14498 void WaitUntilExternalURLLoad(WebFrameTestProxy& source);
[email protected]a79cb9912014-04-26 22:07:33499
lukasza1b546c12016-04-04 16:19:20500 // This function sets a flag to dump the drag image when the next drag&drop is
501 // initiated. It is equivalent to DumpAsTextWithPixelResults but the pixel
502 // results will be the drag image instead of a snapshot of the page.
Dave Tapuska64faea42024-01-05 21:37:14503 void DumpDragImage(WebFrameTestProxy& source);
jackhou656fc852015-02-13 09:04:17504
Dave Tapuska13da016a2021-02-04 21:51:58505 // Sets a flag that sets a flag to dump the default navigation policy passed
506 // to the DecidePolicyForNavigation callback.
Dave Tapuska64faea42024-01-05 21:37:14507 void DumpNavigationPolicy(WebFrameTestProxy& source);
jochenc3a98da12015-03-10 13:59:58508
tkent217ff8852016-11-14 04:43:49509 // Controls whether JavaScript dialogs such as alert() are dumped to test
510 // output.
Dave Tapuska64faea42024-01-05 21:37:14511 void SetDumpJavaScriptDialogs(bool value, WebFrameTestProxy& source);
tkent217ff8852016-11-14 04:43:49512
jkarlin3bddb7d2016-09-21 18:44:16513 // Overrides the NetworkQualityEstimator's estimated network type. If |type|
514 // is TypeUnknown the NQE's value is used. Be sure to call this with
515 // TypeUnknown at the end of your test if you use this.
516 void SetEffectiveConnectionType(
517 blink::WebEffectiveConnectionType connection_type);
518
danakj7c5a96c2020-07-03 15:58:36519 // Takes care of notifying the browser after a change to web test runtime
lukasza083b4f12016-03-24 16:51:43520 // flags.
Dave Tapuska64faea42024-01-05 21:37:14521 void OnWebTestRuntimeFlagsChanged(WebFrameTestProxy& source);
lukaszac9cbe712016-03-14 14:06:43522
[email protected]97f9a7952014-03-14 11:50:33523 ///////////////////////////////////////////////////////////////////////////
524 // Internal helpers
[email protected]eec9e78e2014-06-16 21:38:48525
danakjaa87f0092020-07-07 17:13:43526 mojom::WebTestBluetoothFakeAdapterSetter& GetBluetoothFakeAdapterSetter();
527 void HandleBluetoothFakeAdapterSetterDisconnected();
528 mojo::Remote<mojom::WebTestBluetoothFakeAdapterSetter>
529 bluetooth_fake_adapter_setter_;
530
danakj3130f122019-07-16 17:49:47531 bool test_is_running_ = false;
[email protected]97f9a7952014-03-14 11:50:33532
[email protected]97f9a7952014-03-14 11:50:33533 WorkQueue work_queue_;
534
[email protected]97f9a7952014-03-14 11:50:33535 // Bound variable to return the name of this platform (chromium).
536 std::string platform_name_;
537
lukasza9b9d70e2016-02-25 23:45:44538 // Flags controlling what content gets dumped as a layout text result.
Kent Tamura2eab5b12018-12-07 04:31:23539 WebTestRuntimeFlags web_test_runtime_flags_;
[email protected]97f9a7952014-03-14 11:50:33540
Xianzhu Wang8d64fc32018-10-15 02:26:53541 // If true, the test runner will output a base64 encoded WAVE file.
[email protected]97f9a7952014-03-14 11:50:33542 bool dump_as_audio_;
543
Xianzhu Wang8d64fc32018-10-15 02:26:53544 // If true, the test runner will produce a dump of the back forward list as
[email protected]97f9a7952014-03-14 11:50:33545 // well.
546 bool dump_back_forward_list_;
547
[email protected]97f9a7952014-03-14 11:50:33548 // If true, pixel dump will be produced as a series of 1px-tall, view-wide
549 // individual paints over the height of the view.
550 bool test_repaint_;
551
552 // If true and test_repaint_ is true as well, pixel dump will be produced as
553 // a series of 1px-wide, view-tall paints across the width of the view.
554 bool sweep_horizontally_;
555
[email protected]97f9a7952014-03-14 11:50:33556 std::set<std::string> http_headers_to_clear_;
Dominic Farolinoaee9c1b82019-12-18 03:20:10557 bool clear_referrer_ = false;
[email protected]97f9a7952014-03-14 11:50:33558
559 // WAV audio data is stored here.
danakjc50c5e22020-07-09 17:06:14560 std::vector<uint8_t> audio_data_;
[email protected]97f9a7952014-03-14 11:50:33561
danakjaa87f0092020-07-07 17:13:43562 base::flat_set<WebFrameTestProxy*> main_frames_;
[email protected]97f9a7952014-03-14 11:50:33563
Dave Tapuska012b5b12021-02-04 21:40:24564 // Keeps track of which WebViews that are main windows.
565 std::vector<std::unique_ptr<MainWindowTracker>> main_windows_;
566
arthursonzognid409c252019-03-14 09:22:22567 // This is non empty when a load is in progress.
Ali Hijazie63cbaf62023-12-20 19:29:35568 std::vector<raw_ptr<blink::WebFrame, VectorExperimental>> loading_frames_;
danakj654fd752020-07-10 16:52:09569 // We do not want the test to end until the main frame finishes loading. This
570 // starts as true at the beginning of the test, and will be set to false once
571 // we run out of frames to load at any time.
572 bool main_frame_loaded_ = false;
danakj3130f122019-07-16 17:49:47573 // When a loading task is started, this bool is set until all loading_frames_
574 // are completed and removed. This bool becomes true earlier than
danakj654fd752020-07-10 16:52:09575 // loading_frames_ becomes non-empty.
576 bool frame_will_start_load_ = true;
danakj3130f122019-07-16 17:49:47577 // When NotifyDone() occurs, if loading is still working, it is delayed, and
578 // this bool tracks that NotifyDone() was called. This differentiates from a
579 // test that was not waiting for NotifyDone() at all.
580 bool did_notify_done_ = false;
[email protected]97f9a7952014-03-14 11:50:33581
danakj1a887ad2020-09-01 22:16:01582 FakeScreenOrientationImpl fake_screen_orientation_impl_;
danakjaa87f0092020-07-07 17:13:43583 GamepadController gamepad_controller_;
lukaszafd124602016-04-01 16:53:30584
lukasza1b546c12016-04-04 16:19:20585 // Captured drag image.
danakj0c75ad82018-07-10 19:50:12586 SkBitmap drag_image_;
lukasza1b546c12016-04-04 16:19:20587
Mason Freedb0855622018-10-02 17:49:47588 // True if rasterization should be performed during tests that examine
589 // fling-style animations. This includes middle-click auto-scroll behaviors.
590 // This does not include most "ordinary" animations, such as CSS animations.
danakj3130f122019-07-16 17:49:47591 bool animation_requires_raster_ = false;
Mason Freedb0855622018-10-02 17:49:47592
Kent Tamura21d1de62018-12-10 04:45:20593 // An effective connection type settable by web tests.
danakj3130f122019-07-16 17:49:47594 blink::WebEffectiveConnectionType effective_connection_type_ =
595 blink::WebEffectiveConnectionType::kTypeUnknown;
jkarlin3bddb7d2016-09-21 18:44:16596
Dave Tapuska012b5b12021-02-04 21:40:24597 mojom::WebTestRunTestConfiguration test_config_;
598
Jeremy Roman3bca4bf2019-07-11 03:41:25599 base::WeakPtrFactory<TestRunner> weak_factory_{this};
[email protected]97f9a7952014-03-14 11:50:33600};
601
danakj741848a2020-04-07 22:48:06602} // namespace content
[email protected]97f9a7952014-03-14 11:50:33603
danakj89f47082020-09-02 17:53:43604#endif // CONTENT_WEB_TEST_RENDERER_TEST_RUNNER_H_