blob: 23c13bb57509d18817adf5b2feaaa7ec36c3181a [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
danakjaa87f0092020-07-07 17:13:43104 // Track the set of all main frames in the process, which is also the set of
105 // windows rooted in this process.
Dave Tapuska64faea42024-01-05 21:37:14106 void AddMainFrame(WebFrameTestProxy& frame);
107 void RemoveMainFrame(WebFrameTestProxy& frame);
danakj754eaff2020-03-31 17:46:58108
danakj27e4ebe2020-04-15 18:48:27109 // Returns true if the test output should be an audio file, rather than text
110 // or pixel results.
danakj754eaff2020-03-31 17:46:58111 bool ShouldDumpAsAudio() const;
danakj27e4ebe2020-04-15 18:48:27112 // Gets the audio test output for when audio test results are requested by
113 // the current test.
danakjc50c5e22020-07-09 17:06:14114 const std::vector<uint8_t>& GetAudioData() const;
danakj754eaff2020-03-31 17:46:58115
116 // Reports if tests requested a recursive layout dump of all frames
117 // (i.e. by calling testRunner.dumpChildFramesAsText() from javascript).
118 bool IsRecursiveLayoutDumpRequested();
119
danakj754eaff2020-03-31 17:46:58120 // Returns true if the selection window should be painted onto captured
121 // pixels.
122 bool ShouldDumpSelectionRect() const;
123
124 // Returns false if the browser should capture the pixel output, true if it
danakje9f674512020-07-07 19:23:06125 // can be done locally in the renderer via DumpPixelsInRenderer().
danakj754eaff2020-03-31 17:46:58126 bool CanDumpPixelsFromRenderer() const;
127
Traian Captan37faa272024-05-20 22:33:56128 bool IsPrinting() const;
129
Dave Tapuska1f7929c2023-02-03 18:11:56130#if BUILDFLAG(ENABLE_PRINTING)
Morten Stenshorneecd033fe402023-11-30 14:31:33131 // Returns the default page size to be used for printing. This is either the
132 // size that was explicitly set via SetPrintingSize or the size of the frame
133 // if no size was set.
Thorben Troebst7ab80162022-09-07 19:10:15134 gfx::Size GetPrintingPageSize(blink::WebLocalFrame* frame) const;
135
Morten Stenshorneecd033fe402023-11-30 14:31:33136 // Returns the default page margin size to be used for printing. The value
137 // applies to all four sides of the page.
138 int GetPrintingMargin() const;
139
Thorben Troebst2478eed2022-09-07 17:09:07140 // Returns the page ranges to be printed. This is specified in the document
141 // via a tag of the form <meta name=reftest-pages content="1,2-3,5-">. If no
142 // tag is found, print all pages.
143 printing::PageRanges GetPrintingPageRanges(blink::WebLocalFrame* frame) const;
Morten Stenshorne8ae65182024-05-14 10:57:27144
145 // Go through a test-only path to dump the frame's pixel output as if it was
146 // printed.
147 SkBitmap PrintFrameToBitmap(blink::WebLocalFrame* frame);
Dave Tapuska1f7929c2023-02-03 18:11:56148#endif
Thorben Troebst2478eed2022-09-07 17:09:07149
Dave Tapuska13da016a2021-02-04 21:51:58150 // Snapshots the content of |main_frame| using the mode requested by the
151 // current test.
152 SkBitmap DumpPixelsInRenderer(blink::WebLocalFrame* main_frame);
danakj754eaff2020-03-31 17:46:58153
154 // Replicates changes to web test runtime flags (i.e. changes that happened in
danakj529c0642020-08-28 18:02:18155 // another renderer). See also `OnWebTestRuntimeFlagsChanged()`.
Kent Tamura679c7c42018-12-05 03:21:10156 void ReplicateWebTestRuntimeFlagsChanges(
Nan Lin478672f2022-06-29 01:10:24157 const base::Value::Dict& changed_values);
danakj754eaff2020-03-31 17:46:58158
159 // If custom text dump is present (i.e. if testRunner.setCustomTextOutput has
160 // been called from javascript), then returns |true| and populates the
161 // |custom_text_dump| argument. Otherwise returns |false|.
162 bool HasCustomTextDump(std::string* custom_text_dump) const;
163
164 // Returns true if the history should be included in text results generated at
165 // the end of the test.
166 bool ShouldDumpBackForwardList() const;
167
168 // Returns true if pixel results should be generated at the end of the test.
169 bool ShouldGeneratePixelResults();
170
danakj049cb6a2020-07-11 03:11:34171 TextResultType ShouldGenerateTextResults();
172
danakj674bf1c02020-05-01 18:37:51173 // Activate the window holding the given main frame, and set focus on the
174 // frame's widget.
175 void FocusWindow(RenderFrame* main_frame, bool focus);
[email protected]97f9a7952014-03-14 11:50:33176
lukasza01da2602016-04-05 14:51:26177 // Methods used by WebViewTestClient and WebFrameTestClient.
danakj2d7921652019-09-11 17:20:12178 bool ShouldStayOnPageAfterHandlingBeforeUnload() const;
danakj2d7921652019-09-11 17:20:12179 bool ShouldDumpAsCustomText() const;
180 std::string CustomDumpText() const;
abhishek.a21ca9b5602014-09-19 07:33:33181 void ShowDevTools(const std::string& settings,
[email protected]06c253012014-04-16 18:35:33182 const std::string& frontend_url);
Dave Tapuska64faea42024-01-05 21:37:14183 void SetShouldDumpAsLayout(bool, WebFrameTestProxy& source);
184 void SetCustomTextOutput(const std::string& text, WebFrameTestProxy& source);
185 void SetShouldGeneratePixelResults(bool, WebFrameTestProxy& source);
186 void SetShouldDumpFrameLoadCallbacks(bool, WebFrameTestProxy& source);
danakj2d7921652019-09-11 17:20:12187 bool ShouldDumpEditingCallbacks() const;
188 bool ShouldDumpFrameLoadCallbacks() const;
189 bool ShouldDumpPingLoaderCallbacks() const;
190 bool ShouldDumpUserGestureInFrameLoadCallbacks() const;
191 bool ShouldDumpTitleChanges() const;
192 bool ShouldDumpIconChanges() const;
danakj2d7921652019-09-11 17:20:12193 bool CanOpenWindows() const;
danakj2d7921652019-09-11 17:20:12194 bool ShouldWaitUntilExternalURLLoad() const;
195 const std::set<std::string>* HttpHeadersToClear() const;
Dominic Farolinoaee9c1b82019-12-18 03:20:10196 bool ClearReferrer() const;
danakj29382fc2020-04-20 18:00:09197 bool IsWebPlatformTestsMode() const;
Dave Tapuska64faea42024-01-05 21:37:14198 void SetIsWebPlatformTestsMode(WebFrameTestProxy& source);
Mason Freedb0855622018-10-02 17:49:47199 bool animation_requires_raster() const { return animation_requires_raster_; }
200 void SetAnimationRequiresRaster(bool do_raster);
lukasza10cd8762016-04-27 20:03:02201
arthursonzognid409c252019-03-14 09:22:22202 // Add |frame| to the set of loading frames.
203 //
204 // Note: Only one renderer process is really tracking the loading frames. This
205 // is the first to observe one. Both local and remote frames are tracked
206 // by this process.
Dave Tapuska64faea42024-01-05 21:37:14207 void AddLoadingFrame(blink::WebLocalFrame* frame);
lukasza10cd8762016-04-27 20:03:02208
arthursonzognid409c252019-03-14 09:22:22209 // Remove |frame| from the set of loading frames.
210 //
211 // When there are no more loading frames, this potentially finishes the test,
danakj2d7921652019-09-11 17:20:12212 // unless TestRunner.WaitUntilDone() was called and/or there are pending load
arthursonzognid409c252019-03-14 09:22:22213 // requests in WorkQueue.
Dave Tapuska64faea42024-01-05 21:37:14214 void RemoveLoadingFrame(blink::WebLocalFrame* frame);
lukasza10cd8762016-04-27 20:03:02215
Hitoshi Yoshida0d0156c2020-10-29 17:36:15216 // Called when a main frame has been navigated away.
Dave Tapuska64faea42024-01-05 21:37:14217 void OnFrameDeactivated(WebFrameTestProxy& frame);
Hitoshi Yoshida0d0156c2020-10-29 17:36:15218
219 // Called when a main frame has been restored from backward/forward cache.
Dave Tapuska64faea42024-01-05 21:37:14220 void OnFrameReactivated(WebFrameTestProxy& frame);
Hitoshi Yoshida0d0156c2020-10-29 17:36:15221
Dave Tapuska64faea42024-01-05 21:37:14222 void PolicyDelegateDone(WebFrameTestProxy& source);
danakj2d7921652019-09-11 17:20:12223 bool PolicyDelegateEnabled() const;
224 bool PolicyDelegateIsPermissive() const;
225 bool PolicyDelegateShouldNotifyDone() const;
danakj2d7921652019-09-11 17:20:12226 void SetDragImage(const SkBitmap& drag_image);
227 bool ShouldDumpNavigationPolicy() const;
[email protected]97f9a7952014-03-14 11:50:33228
caseqcb2227832016-05-24 18:52:04229 bool ShouldDumpConsoleMessages() const;
Yoichi Osatoebf845ac72018-08-30 08:13:50230 // Controls whether console messages produced by the page are dumped
231 // to test output.
Dave Tapuska64faea42024-01-05 21:37:14232 void SetDumpConsoleMessages(bool value, WebFrameTestProxy& source);
danakj7c5a96c2020-07-03 15:58:36233
234 // Add a message to the text dump for the web test.
Dave Tapuska64faea42024-01-05 21:37:14235 void PrintMessage(const std::string& message, WebFrameTestProxy& source);
danakj7c5a96c2020-07-03 15:58:36236
237 // Register a new isolated filesystem with the given files, and return the
238 // new filesystem id.
239 blink::WebString RegisterIsolatedFileSystem(
Dave Tapuska64faea42024-01-05 21:37:14240 const std::vector<base::FilePath>& file_paths,
241 WebFrameTestProxy& source);
danakj7c5a96c2020-07-03 15:58:36242
Dave Tapuska64faea42024-01-05 21:37:14243 void ProcessWorkItem(mojom::WorkItemPtr work_item, WebFrameTestProxy& source);
244 void ReplicateWorkQueueStates(const base::Value::Dict& changed_values,
245 WebFrameTestProxy& source);
Hitoshi Yoshida25a31d52020-10-29 08:00:33246
jkarlin3bddb7d2016-09-21 18:44:16247 blink::WebEffectiveConnectionType effective_connection_type() const {
248 return effective_connection_type_;
249 }
250
Dave Tapuska012b5b12021-02-04 21:40:24251 // Determine the the frame is considered in the main window.
252 bool IsFrameInMainWindow(blink::WebLocalFrame* frame);
253
254 // Set the main window and test configuration.
255 void SetMainWindowAndTestConfiguration(
256 blink::WebLocalFrame* initial_local_root,
257 mojom::WebTestRunTestConfigurationPtr config);
258 const mojom::WebTestRunTestConfiguration& TestConfig() const;
259
260 // Returns an asbsolute file path. This depends on the current test
261 // configuration so it should only be called while a test is running.
262 blink::WebString GetAbsoluteWebStringFromUTF8Path(
263 const std::string& utf8_path);
264
Randolf1d3bc062023-03-29 17:37:55265 // Disables automatic drag and drop in web tests' web frame widget
266 // (WebTestWebFrameWidgetImpl).
267 //
268 // In general, drag and drop will automatically be performed because web tests
269 // do not have drag and drop enabled. If you need to control the drag and drop
270 // lifecycle yourself, you can disable it here.
Dave Tapuska64faea42024-01-05 21:37:14271 void DisableAutomaticDragDrop(WebFrameTestProxy& source);
Randolf1d3bc062023-03-29 17:37:55272 bool AutomaticDragDropEnabled();
273
Dave Tapuska64faea42024-01-05 21:37:14274 const WebTestRuntimeFlags& GetFlags();
275
[email protected]97f9a7952014-03-14 11:50:33276 private:
[email protected]97f9a7952014-03-14 11:50:33277 friend class TestRunnerBindings;
278 friend class WorkQueue;
Dave Tapuska012b5b12021-02-04 21:40:24279 class MainWindowTracker;
[email protected]97f9a7952014-03-14 11:50:33280
danakj2d7921652019-09-11 17:20:12281 // Helper class for managing events queued by methods like QueueLoad or
282 // QueueScript.
[email protected]97f9a7952014-03-14 11:50:33283 class WorkQueue {
Hitoshi Yoshida25a31d52020-10-29 08:00:33284 static constexpr const char* kKeyFrozen = "frozen";
285
[email protected]97f9a7952014-03-14 11:50:33286 public:
287 explicit WorkQueue(TestRunner* controller);
Hitoshi Yoshida25a31d52020-10-29 08:00:33288 ~WorkQueue() = default;
[email protected]97f9a7952014-03-14 11:50:33289
290 // Reset the state of the class between tests.
291 void Reset();
292
Dave Tapuska64faea42024-01-05 21:37:14293 void AddWork(mojom::WorkItemPtr work_item, WebFrameTestProxy& source);
294 void RequestWork(WebFrameTestProxy& source);
295 void ProcessWorkItem(mojom::WorkItemPtr work_item,
296 WebFrameTestProxy& source);
297 void ReplicateStates(const base::Value::Dict& values,
298 WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33299
Hitoshi Yoshida25a31d52020-10-29 08:00:33300 // Takes care of notifying the browser after a change to the state.
Dave Tapuska64faea42024-01-05 21:37:14301 void OnStatesChanged(WebFrameTestProxy& source);
danakj3130f122019-07-16 17:49:47302
Hitoshi Yoshida25a31d52020-10-29 08:00:33303 void set_loading(bool value) { loading_ = value; }
304
305 void set_frozen(bool value) { states_.SetBoolean(kKeyFrozen, value); }
306 void set_has_items(bool value) {
307 states_.SetBoolean(kDictKeyWorkQueueHasItems, value);
308 }
309 bool has_items() const { return GetStateValue(kDictKeyWorkQueueHasItems); }
[email protected]97f9a7952014-03-14 11:50:33310
311 private:
Dave Tapuska64faea42024-01-05 21:37:14312 bool ProcessWorkItemInternal(mojom::WorkItemPtr work_item,
313 WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33314
Hitoshi Yoshida25a31d52020-10-29 08:00:33315 bool is_frozen() const { return GetStateValue(kKeyFrozen); }
316
317 bool GetStateValue(const char* key) const {
Arthur Sonzognic686e8f2024-01-11 08:36:37318 std::optional<bool> value =
Nan Lin478672f2022-06-29 01:10:24319 states_.current_values().FindBoolByDottedPath(key);
Hitoshi Yoshida25a31d52020-10-29 08:00:33320 DCHECK(value.has_value());
321 return value.value();
322 }
323
324 bool loading_ = true;
325 // Collection of flags to be synced with the browser process.
326 TrackedDictionary states_;
327
Bartek Nowierskif473c24b2024-02-20 17:51:15328 raw_ptr<TestRunner> controller_;
[email protected]97f9a7952014-03-14 11:50:33329 };
330
danakje2834422020-07-10 21:18:58331 // If the main test window's main frame is hosted in this renderer process,
332 // then this will return it. Otherwise, it is in another process and this
333 // returns null.
334 WebFrameTestProxy* FindInProcessMainWindowMainFrame();
335
[email protected]97f9a7952014-03-14 11:50:33336 ///////////////////////////////////////////////////////////////////////////
337 // Methods dealing with the test logic
338
339 // By default, tests end when page load is complete. These methods are used
danakj2d7921652019-09-11 17:20:12340 // to delay the completion of the test until NotifyDone is called.
Dave Tapuska64faea42024-01-05 21:37:14341 void WaitUntilDone(WebFrameTestProxy& source);
342 void NotifyDone(WebFrameTestProxy& source);
danakj654fd752020-07-10 16:52:09343
344 // When there are no conditions left to wait for, this is called to cause the
345 // test to end, collect results, and inform the browser.
Dave Tapuska64faea42024-01-05 21:37:14346 void FinishTest(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33347
348 // Methods for adding actions to the work queue. Used in conjunction with
danakj2d7921652019-09-11 17:20:12349 // WaitUntilDone/NotifyDone above.
Dave Tapuska64faea42024-01-05 21:37:14350 void QueueBackNavigation(int how_far_back, WebFrameTestProxy& source);
351 void QueueForwardNavigation(int how_far_forward, WebFrameTestProxy& source);
352 void QueueReload(WebFrameTestProxy& source);
353 void QueueLoadingScript(const std::string& script, WebFrameTestProxy& source);
354 void QueueNonLoadingScript(const std::string& script,
355 WebFrameTestProxy& source);
danakj12c09b62020-07-11 04:17:05356 void QueueLoad(const GURL& current_url,
357 const std::string& relative_url,
Dave Tapuska64faea42024-01-05 21:37:14358 const std::string& target,
359 WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33360
danakjcdff34e42020-05-04 21:42:48361 // Called from the TestRunnerBindings to inform that the test has modified
362 // the TestPreferences. This will update the WebkitPreferences in the renderer
363 // and the browser.
364 void OnTestPreferencesChanged(const TestPreferences& test_prefs,
Dave Tapuska64faea42024-01-05 21:37:14365 WebFrameTestProxy& frame);
danakjcdff34e42020-05-04 21:42:48366
[email protected]97f9a7952014-03-14 11:50:33367 // Causes navigation actions just printout the intended navigation instead
368 // of taking you to the page. This is used for cases like mailto, where you
369 // don't actually want to open the mail program.
Dave Tapuska64faea42024-01-05 21:37:14370 void SetCustomPolicyDelegate(gin::Arguments* args, WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33371
372 // Delays completion of the test until the policy delegate runs.
Dave Tapuska64faea42024-01-05 21:37:14373 void WaitForPolicyDelegate(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33374
danakjaa87f0092020-07-07 17:13:43375 // This is the count of windows which have their main frame in this renderer
376 // process. A cross-origin window would not appear in this count.
377 int InProcessWindowCount();
[email protected]97f9a7952014-03-14 11:50:33378
Kent Tamura21d1de62018-12-10 04:45:20379 // Allows web tests to manage origins' allow list.
Takashi Toyoshima66e7d0d2018-08-28 09:20:10380 void AddOriginAccessAllowListEntry(const std::string& source_origin,
[email protected]97f9a7952014-03-14 11:50:33381 const std::string& destination_protocol,
382 const std::string& destination_host,
383 bool allow_destination_subdomains);
[email protected]97f9a7952014-03-14 11:50:33384
[email protected]97f9a7952014-03-14 11:50:33385 // Enables or disables subpixel positioning (i.e. fractional X positions for
386 // glyphs) in text rendering on Linux. Since this method changes global
387 // settings, tests that call it must use their own custom font family for
388 // all text that they render. If not, an already-cached style will be used,
389 // resulting in the changed setting being ignored.
390 void SetTextSubpixelPositioning(bool value);
391
Dave Tapuska442a74f2020-08-20 15:50:46392 // Set the mock orientation on |view| to |orientation|.
Dave Tapuska64faea42024-01-05 21:37:14393 void SetMockScreenOrientation(const std::string& orientation,
394 WebFrameTestProxy& frame);
Dave Tapuska442a74f2020-08-20 15:50:46395 // Disable any mock orientation on |view| that is set.
Dave Tapuska13da016a2021-02-04 21:51:58396 void DisableMockScreenOrientation(blink::WebView* view);
[email protected]e0bc2cb2014-03-20 17:34:24397
[email protected]97f9a7952014-03-14 11:50:33398 ///////////////////////////////////////////////////////////////////////////
399 // Methods that modify the state of TestRunner
400
Xianzhu Wang8d64fc32018-10-15 02:26:53401 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33402 // descriptive text for each editing command. It takes no arguments, and
403 // ignores any that may be present.
Dave Tapuska64faea42024-01-05 21:37:14404 void DumpEditingCallbacks(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33405
Xianzhu Wang6e84f0992018-10-23 23:07:55406 // This function sets a flag that tells the test runner to dump pages as
407 // plain text. The pixel results will not be generated for this test.
408 // It has higher priority than DumpAsMarkup() and DumpAsLayout().
Dave Tapuska64faea42024-01-05 21:37:14409 void DumpAsText(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33410
Xianzhu Wang8d64fc32018-10-15 02:26:53411 // This function sets a flag that tells the test runner to dump pages as
[email protected]fdc433c02014-06-02 19:27:14412 // the DOM contents, rather than as a text representation of the renderer's
Xianzhu Wang6e84f0992018-10-23 23:07:55413 // state. The pixel results will not be generated for this test. It has
414 // higher priority than DumpAsLayout(), but lower than DumpAsText().
Dave Tapuska64faea42024-01-05 21:37:14415 void DumpAsMarkup(WebFrameTestProxy& source);
[email protected]fdc433c02014-06-02 19:27:14416
Xianzhu Wang6e84f0992018-10-23 23:07:55417 // This function sets a flag that tells the test runner to dump pages as
418 // plain text. It will also generate a pixel dump for the test.
Dave Tapuska64faea42024-01-05 21:37:14419 void DumpAsTextWithPixelResults(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33420
Xianzhu Wang6e84f0992018-10-23 23:07:55421 // This function sets a flag that tells the test runner to dump pages as
422 // text representation of the layout. The pixel results will not be generated
423 // for this test. It has lower priority than DumpAsText() and DumpAsMarkup().
Dave Tapuska64faea42024-01-05 21:37:14424 void DumpAsLayout(WebFrameTestProxy& source);
Xianzhu Wang6e84f0992018-10-23 23:07:55425
426 // This function sets a flag that tells the test runner to dump pages as
427 // text representation of the layout. It will also generate a pixel dump for
428 // the test.
Dave Tapuska64faea42024-01-05 21:37:14429 void DumpAsLayoutWithPixelResults(WebFrameTestProxy& source);
Xianzhu Wang6e84f0992018-10-23 23:07:55430
Xianzhu Wang8d64fc32018-10-15 02:26:53431 // This function sets a flag that tells the test runner to recursively dump
Xianzhu Wang6e84f0992018-10-23 23:07:55432 // all frames as text, markup or layout depending on which of DumpAsText,
433 // DumpAsMarkup and DumpAsLayout is effective.
Dave Tapuska64faea42024-01-05 21:37:14434 void DumpChildFrames(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33435
Xianzhu Wang8d64fc32018-10-15 02:26:53436 // This function sets a flag that tells the test runner to print out the
[email protected]97f9a7952014-03-14 11:50:33437 // information about icon changes notifications from WebKit.
Dave Tapuska64faea42024-01-05 21:37:14438 void DumpIconChanges(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33439
440 // Deals with Web Audio WAV file data.
441 void SetAudioData(const gin::ArrayBufferView& view);
442
Xianzhu Wang8d64fc32018-10-15 02:26:53443 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33444 // descriptive text for each frame load callback. It takes no arguments, and
445 // ignores any that may be present.
Dave Tapuska64faea42024-01-05 21:37:14446 void DumpFrameLoadCallbacks(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33447
Xianzhu Wang8d64fc32018-10-15 02:26:53448 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33449 // descriptive text for each PingLoader dispatch. It takes no arguments, and
450 // ignores any that may be present.
Dave Tapuska64faea42024-01-05 21:37:14451 void DumpPingLoaderCallbacks(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33452
Xianzhu Wang8d64fc32018-10-15 02:26:53453 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33454 // user gesture status text for some frame load callbacks. It takes no
455 // arguments, and ignores any that may be present.
Dave Tapuska64faea42024-01-05 21:37:14456 void DumpUserGestureInFrameLoadCallbacks(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33457
Dave Tapuska64faea42024-01-05 21:37:14458 void DumpTitleChanges(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33459
Xianzhu Wang8d64fc32018-10-15 02:26:53460 // This function sets a flag that tells the test runner to dump the MIME type
[email protected]97f9a7952014-03-14 11:50:33461 // for each resource that was loaded. It takes no arguments, and ignores any
462 // that may be present.
463 void DumpResourceResponseMIMETypes();
464
mlamouri007f9d72015-02-27 16:27:25465 // WebContentSettingsClient related.
Dave Tapuska64faea42024-01-05 21:37:14466 void SetStorageAllowed(bool allowed, WebFrameTestProxy& source);
467 void SetAllowRunningOfInsecureContent(bool allowed,
468 WebFrameTestProxy& source);
469 void DumpPermissionClientCallbacks(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33470
Xianzhu Wang8d64fc32018-10-15 02:26:53471 // This function sets a flag that tells the test runner to print out a text
[email protected]97f9a7952014-03-14 11:50:33472 // representation of the back/forward list. It ignores all arguments.
473 void DumpBackForwardList();
474
Dave Tapuska64faea42024-01-05 21:37:14475 void DumpSelectionRect(WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33476
Dave Tapuska64faea42024-01-05 21:37:14477 // Causes layout to happen as if targeted to printed pages.
478 void SetPrinting(WebFrameTestProxy& source);
479 void SetPrintingForFrame(const std::string& frame_name,
480 WebFrameTestProxy& source);
481 void SetPrintingSize(int width, int height, WebFrameTestProxy& source);
482 void SetPrintingMargin(int size, WebFrameTestProxy& source);
Morten Stenshorne8ae65182024-05-14 10:57:27483 void SetShouldCenterAndShrinkToFitPaper(bool b) {
484 should_center_and_shrink_to_fit_paper_ = b;
485 }
486 void SetPrintingScaleFactor(float factor) { printing_scale_factor_ = factor; }
[email protected]97f9a7952014-03-14 11:50:33487
Dave Tapuska64faea42024-01-05 21:37:14488 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value,
489 WebFrameTestProxy& source);
[email protected]97f9a7952014-03-14 11:50:33490
491 // Causes WillSendRequest to clear certain headers.
Dominic Farolinoaee9c1b82019-12-18 03:20:10492 // Note: This cannot be used to clear the request's `Referer` header, as this
493 // header is computed later given its referrer string member. To clear it, use
494 // SetWillSendRequestClearReferrer() below.
[email protected]97f9a7952014-03-14 11:50:33495 void SetWillSendRequestClearHeader(const std::string& header);
496
Dominic Farolinoaee9c1b82019-12-18 03:20:10497 // Causes WillSendRequest to clear the request's referrer string and set its
498 // referrer policy to the default.
499 void SetWillSendRequestClearReferrer();
500
[email protected]a79cb9912014-04-26 22:07:33501 // Sets a flag that causes the test to be marked as completed when the
danakj2d7921652019-09-11 17:20:12502 // WebLocalFrameClient receives a LoadURLExternally() call.
Dave Tapuska64faea42024-01-05 21:37:14503 void WaitUntilExternalURLLoad(WebFrameTestProxy& source);
[email protected]a79cb9912014-04-26 22:07:33504
lukasza1b546c12016-04-04 16:19:20505 // This function sets a flag to dump the drag image when the next drag&drop is
506 // initiated. It is equivalent to DumpAsTextWithPixelResults but the pixel
507 // results will be the drag image instead of a snapshot of the page.
Dave Tapuska64faea42024-01-05 21:37:14508 void DumpDragImage(WebFrameTestProxy& source);
jackhou656fc852015-02-13 09:04:17509
Dave Tapuska13da016a2021-02-04 21:51:58510 // Sets a flag that sets a flag to dump the default navigation policy passed
511 // to the DecidePolicyForNavigation callback.
Dave Tapuska64faea42024-01-05 21:37:14512 void DumpNavigationPolicy(WebFrameTestProxy& source);
jochenc3a98da12015-03-10 13:59:58513
tkent217ff8852016-11-14 04:43:49514 // Controls whether JavaScript dialogs such as alert() are dumped to test
515 // output.
Dave Tapuska64faea42024-01-05 21:37:14516 void SetDumpJavaScriptDialogs(bool value, WebFrameTestProxy& source);
tkent217ff8852016-11-14 04:43:49517
jkarlin3bddb7d2016-09-21 18:44:16518 // Overrides the NetworkQualityEstimator's estimated network type. If |type|
519 // is TypeUnknown the NQE's value is used. Be sure to call this with
520 // TypeUnknown at the end of your test if you use this.
521 void SetEffectiveConnectionType(
522 blink::WebEffectiveConnectionType connection_type);
523
danakj7c5a96c2020-07-03 15:58:36524 // Takes care of notifying the browser after a change to web test runtime
lukasza083b4f12016-03-24 16:51:43525 // flags.
Dave Tapuska64faea42024-01-05 21:37:14526 void OnWebTestRuntimeFlagsChanged(WebFrameTestProxy& source);
lukaszac9cbe712016-03-14 14:06:43527
[email protected]97f9a7952014-03-14 11:50:33528 ///////////////////////////////////////////////////////////////////////////
529 // Internal helpers
[email protected]eec9e78e2014-06-16 21:38:48530
danakjaa87f0092020-07-07 17:13:43531 mojom::WebTestBluetoothFakeAdapterSetter& GetBluetoothFakeAdapterSetter();
532 void HandleBluetoothFakeAdapterSetterDisconnected();
533 mojo::Remote<mojom::WebTestBluetoothFakeAdapterSetter>
534 bluetooth_fake_adapter_setter_;
535
danakj3130f122019-07-16 17:49:47536 bool test_is_running_ = false;
[email protected]97f9a7952014-03-14 11:50:33537
[email protected]97f9a7952014-03-14 11:50:33538 WorkQueue work_queue_;
539
[email protected]97f9a7952014-03-14 11:50:33540 // Bound variable to return the name of this platform (chromium).
541 std::string platform_name_;
542
lukasza9b9d70e2016-02-25 23:45:44543 // Flags controlling what content gets dumped as a layout text result.
Kent Tamura2eab5b12018-12-07 04:31:23544 WebTestRuntimeFlags web_test_runtime_flags_;
[email protected]97f9a7952014-03-14 11:50:33545
Xianzhu Wang8d64fc32018-10-15 02:26:53546 // If true, the test runner will output a base64 encoded WAVE file.
[email protected]97f9a7952014-03-14 11:50:33547 bool dump_as_audio_;
548
Xianzhu Wang8d64fc32018-10-15 02:26:53549 // If true, the test runner will produce a dump of the back forward list as
[email protected]97f9a7952014-03-14 11:50:33550 // well.
551 bool dump_back_forward_list_;
552
[email protected]97f9a7952014-03-14 11:50:33553 // If true, pixel dump will be produced as a series of 1px-tall, view-wide
554 // individual paints over the height of the view.
555 bool test_repaint_;
556
557 // If true and test_repaint_ is true as well, pixel dump will be produced as
558 // a series of 1px-wide, view-tall paints across the width of the view.
559 bool sweep_horizontally_;
560
Morten Stenshorne8ae65182024-05-14 10:57:27561 // If set, pretend that the specified default page size when printing (see
562 // `SetPrintingSize()`) is also the size of the imaginary paper, so that any
563 // CSS @page size that overrides the default page size will be centered on
564 // paper, and scaled down to fit if required. This is the default behavior
565 // when printing to an actual printer (as opposed to generating a PDF) in
566 // Chrome.
567 bool should_center_and_shrink_to_fit_paper_ = false;
568
569 // The scale factor to apply to printed content.
570 float printing_scale_factor_ = 1.0;
571
[email protected]97f9a7952014-03-14 11:50:33572 std::set<std::string> http_headers_to_clear_;
Dominic Farolinoaee9c1b82019-12-18 03:20:10573 bool clear_referrer_ = false;
[email protected]97f9a7952014-03-14 11:50:33574
575 // WAV audio data is stored here.
danakjc50c5e22020-07-09 17:06:14576 std::vector<uint8_t> audio_data_;
[email protected]97f9a7952014-03-14 11:50:33577
Ali Hijazia56154d2024-02-26 10:21:17578 base::flat_set<raw_ptr<WebFrameTestProxy, CtnExperimental>> main_frames_;
[email protected]97f9a7952014-03-14 11:50:33579
Dave Tapuska012b5b12021-02-04 21:40:24580 // Keeps track of which WebViews that are main windows.
581 std::vector<std::unique_ptr<MainWindowTracker>> main_windows_;
582
arthursonzognid409c252019-03-14 09:22:22583 // This is non empty when a load is in progress.
Ali Hijazie63cbaf62023-12-20 19:29:35584 std::vector<raw_ptr<blink::WebFrame, VectorExperimental>> loading_frames_;
danakj654fd752020-07-10 16:52:09585 // We do not want the test to end until the main frame finishes loading. This
586 // starts as true at the beginning of the test, and will be set to false once
587 // we run out of frames to load at any time.
588 bool main_frame_loaded_ = false;
danakj3130f122019-07-16 17:49:47589 // When a loading task is started, this bool is set until all loading_frames_
590 // are completed and removed. This bool becomes true earlier than
danakj654fd752020-07-10 16:52:09591 // loading_frames_ becomes non-empty.
592 bool frame_will_start_load_ = true;
danakj3130f122019-07-16 17:49:47593 // When NotifyDone() occurs, if loading is still working, it is delayed, and
594 // this bool tracks that NotifyDone() was called. This differentiates from a
595 // test that was not waiting for NotifyDone() at all.
596 bool did_notify_done_ = false;
[email protected]97f9a7952014-03-14 11:50:33597
danakj1a887ad2020-09-01 22:16:01598 FakeScreenOrientationImpl fake_screen_orientation_impl_;
danakjaa87f0092020-07-07 17:13:43599 GamepadController gamepad_controller_;
lukaszafd124602016-04-01 16:53:30600
lukasza1b546c12016-04-04 16:19:20601 // Captured drag image.
danakj0c75ad82018-07-10 19:50:12602 SkBitmap drag_image_;
lukasza1b546c12016-04-04 16:19:20603
Mason Freedb0855622018-10-02 17:49:47604 // True if rasterization should be performed during tests that examine
605 // fling-style animations. This includes middle-click auto-scroll behaviors.
606 // This does not include most "ordinary" animations, such as CSS animations.
danakj3130f122019-07-16 17:49:47607 bool animation_requires_raster_ = false;
Mason Freedb0855622018-10-02 17:49:47608
Kent Tamura21d1de62018-12-10 04:45:20609 // An effective connection type settable by web tests.
danakj3130f122019-07-16 17:49:47610 blink::WebEffectiveConnectionType effective_connection_type_ =
611 blink::WebEffectiveConnectionType::kTypeUnknown;
jkarlin3bddb7d2016-09-21 18:44:16612
Dave Tapuska012b5b12021-02-04 21:40:24613 mojom::WebTestRunTestConfiguration test_config_;
614
Jeremy Roman3bca4bf2019-07-11 03:41:25615 base::WeakPtrFactory<TestRunner> weak_factory_{this};
[email protected]97f9a7952014-03-14 11:50:33616};
617
danakj741848a2020-04-07 22:48:06618} // namespace content
[email protected]97f9a7952014-03-14 11:50:33619
danakj89f47082020-09-02 17:53:43620#endif // CONTENT_WEB_TEST_RENDERER_TEST_RUNNER_H_