blob: a538972a1f615bdfb5cf14a2f021cb11fcccb842 [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"
[email protected]97f9a7952014-03-14 11:50:3319#include "base/memory/weak_ptr.h"
Nan Lin478672f2022-06-29 01:10:2420#include "base/values.h"
danakj89f47082020-09-02 17:53:4321#include "content/web_test/common/web_test.mojom.h"
22#include "content/web_test/common/web_test_bluetooth_fake_adapter_setter.mojom.h"
Hitoshi Yoshida25a31d52020-10-29 08:00:3323#include "content/web_test/common/web_test_constants.h"
Dave Tapuska01437d8e2021-01-29 18:42:1824#include "content/web_test/common/web_test_runtime_flags.h"
danakj89f47082020-09-02 17:53:4325#include "content/web_test/renderer/fake_screen_orientation_impl.h"
26#include "content/web_test/renderer/gamepad_controller.h"
27#include "content/web_test/renderer/layout_dump.h"
28#include "content/web_test/renderer/web_test_content_settings_client.h"
Thorben Troebst2478eed2022-09-07 17:09:0729#include "printing/page_range.h"
Anton Bikineevf62d1bf2021-05-15 17:56:0730#include "third_party/abseil-cpp/absl/types/optional.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
[email protected]97f9a7952014-03-14 11:50:3338namespace blink {
mlamouri007f9d72015-02-27 16:27:2539class WebContentSettingsClient;
[email protected]97f9a7952014-03-14 11:50:3340class WebFrame;
Dave Tapuska4d524862020-12-01 19:43:4141class WebFrameWidget;
[email protected]97f9a7952014-03-14 11:50:3342class WebString;
43class WebView;
danakjb0092062020-05-04 19:53:0644} // namespace blink
[email protected]97f9a7952014-03-14 11:50:3345
46namespace gin {
47class ArrayBufferView;
48class Arguments;
danakjb0092062020-05-04 19:53:0649} // namespace gin
[email protected]97f9a7952014-03-14 11:50:3350
danakj741848a2020-04-07 22:48:0651namespace content {
danakjb5ae26052020-04-23 17:20:2252class RenderFrame;
Yuki Shiinoc955c4c2020-07-06 04:38:1553class SpellCheckClient;
danakj552c1cc92020-07-14 22:34:1054class TestRunnerBindings;
danakj4cfe7002020-05-13 23:04:3955class WebFrameTestProxy;
danakj552c1cc92020-07-14 22:34:1056struct TestPreferences;
[email protected]97f9a7952014-03-14 11:50:3357
lukaszab2ad0502016-04-27 15:51:4258// TestRunner class currently has dual purpose:
danakj2d7921652019-09-11 17:20:1259// 1. It implements TestRunner javascript bindings for "global" / "ambient".
lukaszab2ad0502016-04-27 15:51:4260// Examples:
danakj2d7921652019-09-11 17:20:1261// - TestRunner.DumpAsText (test flag affecting test behavior)
62// - TestRunner.SetAllowRunningOfInsecureContent (test flag affecting product
lukaszab2ad0502016-04-27 15:51:4263// behavior)
danakj2d7921652019-09-11 17:20:1264// - TestRunner.SetTextSubpixelPositioning (directly interacts with product).
lukaszab2ad0502016-04-27 15:51:4265// 2. It manages global test state. Example:
66// - Tracking topLoadingFrame that can finish the test when it loads.
danakj1985c8f2020-07-09 18:28:1667// - WorkQueue holding load requests from web tests.
Kent Tamura21d1de62018-12-10 04:45:2068// - WebTestRuntimeFlags
danakj9f2d3502020-04-07 21:20:2169class TestRunner {
[email protected]97f9a7952014-03-14 11:50:3370 public:
danakj1985c8f2020-07-09 18:28:1671 TestRunner();
Peter Boström828b9022021-09-21 02:28:4372
73 TestRunner(const TestRunner&) = delete;
74 TestRunner& operator=(const TestRunner&) = delete;
75
[email protected]97f9a7952014-03-14 11:50:3376 virtual ~TestRunner();
77
Yuki Shiinoc955c4c2020-07-06 04:38:1578 void Install(WebFrameTestProxy* frame, SpellCheckClient* spell_check);
[email protected]97f9a7952014-03-14 11:50:3379
danakj12c09b62020-07-11 04:17:0580 // Resets global TestRunner state for the next test.
81 void Reset();
danakjaa87f0092020-07-07 17:13:4382
Dave Tapuska1b235d82021-02-01 17:40:2583 // Resets state on the |web_view| for the next test.
84 void ResetWebView(blink::WebView* web_view);
Dave Tapuska4d524862020-12-01 19:43:4185 // Resets state on the |web_frame_widget| for the next test.
86 void ResetWebFrameWidget(blink::WebFrameWidget* web_frame_widget);
[email protected]97f9a7952014-03-14 11:50:3387
[email protected]97f9a7952014-03-14 11:50:3388 void SetTestIsRunning(bool);
89 bool TestIsRunning() const { return test_is_running_; }
90
danakj3130f122019-07-16 17:49:4791 // Finishes the test if it is ready. This should be called before running
92 // tasks that will change state, so that the test can capture the current
93 // state. Specifically, should run before the BeginMainFrame step which does
94 // layout and animation etc.
95 // This does *not* run as part of loading finishing because that happens in
96 // the middle of blink call stacks that have inconsistent state.
97 void FinishTestIfReady();
danakj4b0ef922020-08-28 14:34:5798 // Notification that another renderer has explicitly asked the test to end.
99 void TestFinishedFromSecondaryRenderer();
danakj3130f122019-07-16 17:49:47100
danakj529c0642020-08-28 18:02:18101 // Performs a reset at the end of a test, in order to prepare for the next
arthursonzogni7ec0feb2021-04-01 18:36:03102 // test.
103 void ResetRendererAfterWebTest();
danakj529c0642020-08-28 18:02:18104
danakjaa87f0092020-07-07 17:13:43105 // Track the set of all main frames in the process, which is also the set of
106 // windows rooted in this process.
107 void AddMainFrame(WebFrameTestProxy* frame);
108 void RemoveMainFrame(WebFrameTestProxy* frame);
109
danakj754eaff2020-03-31 17:46:58110 // Returns a mock WebContentSettings that is used for web tests. An
111 // embedder should use this for all WebViews it creates.
danakjaa87f0092020-07-07 17:13:43112 blink::WebContentSettingsClient* GetWebContentSettings();
danakj754eaff2020-03-31 17:46:58113
danakj27e4ebe2020-04-15 18:48:27114 // Returns true if the test output should be an audio file, rather than text
115 // or pixel results.
danakj754eaff2020-03-31 17:46:58116 bool ShouldDumpAsAudio() const;
danakj27e4ebe2020-04-15 18:48:27117 // Gets the audio test output for when audio test results are requested by
118 // the current test.
danakjc50c5e22020-07-09 17:06:14119 const std::vector<uint8_t>& GetAudioData() const;
danakj754eaff2020-03-31 17:46:58120
121 // Reports if tests requested a recursive layout dump of all frames
122 // (i.e. by calling testRunner.dumpChildFramesAsText() from javascript).
123 bool IsRecursiveLayoutDumpRequested();
124
danakj754eaff2020-03-31 17:46:58125 // Returns true if the selection window should be painted onto captured
126 // pixels.
127 bool ShouldDumpSelectionRect() const;
128
129 // Returns false if the browser should capture the pixel output, true if it
danakje9f674512020-07-07 19:23:06130 // can be done locally in the renderer via DumpPixelsInRenderer().
danakj754eaff2020-03-31 17:46:58131 bool CanDumpPixelsFromRenderer() const;
132
Thorben Troebst2478eed2022-09-07 17:09:07133 // Returns the page ranges to be printed. This is specified in the document
134 // via a tag of the form <meta name=reftest-pages content="1,2-3,5-">. If no
135 // tag is found, print all pages.
136 printing::PageRanges GetPrintingPageRanges(blink::WebLocalFrame* frame) const;
137
Dave Tapuska13da016a2021-02-04 21:51:58138 // Snapshots the content of |main_frame| using the mode requested by the
139 // current test.
140 SkBitmap DumpPixelsInRenderer(blink::WebLocalFrame* main_frame);
danakj754eaff2020-03-31 17:46:58141
142 // Replicates changes to web test runtime flags (i.e. changes that happened in
danakj529c0642020-08-28 18:02:18143 // another renderer). See also `OnWebTestRuntimeFlagsChanged()`.
Kent Tamura679c7c42018-12-05 03:21:10144 void ReplicateWebTestRuntimeFlagsChanges(
Nan Lin478672f2022-06-29 01:10:24145 const base::Value::Dict& changed_values);
danakj754eaff2020-03-31 17:46:58146
147 // If custom text dump is present (i.e. if testRunner.setCustomTextOutput has
148 // been called from javascript), then returns |true| and populates the
149 // |custom_text_dump| argument. Otherwise returns |false|.
150 bool HasCustomTextDump(std::string* custom_text_dump) const;
151
152 // Returns true if the history should be included in text results generated at
153 // the end of the test.
154 bool ShouldDumpBackForwardList() const;
155
156 // Returns true if pixel results should be generated at the end of the test.
157 bool ShouldGeneratePixelResults();
158
danakj049cb6a2020-07-11 03:11:34159 TextResultType ShouldGenerateTextResults();
160
danakj674bf1c02020-05-01 18:37:51161 // Activate the window holding the given main frame, and set focus on the
162 // frame's widget.
163 void FocusWindow(RenderFrame* main_frame, bool focus);
[email protected]97f9a7952014-03-14 11:50:33164
lukasza01da2602016-04-05 14:51:26165 // Methods used by WebViewTestClient and WebFrameTestClient.
danakj2d7921652019-09-11 17:20:12166 bool ShouldStayOnPageAfterHandlingBeforeUnload() const;
danakj2d7921652019-09-11 17:20:12167 bool ShouldDumpAsCustomText() const;
168 std::string CustomDumpText() const;
abhishek.a21ca9b5602014-09-19 07:33:33169 void ShowDevTools(const std::string& settings,
[email protected]06c253012014-04-16 18:35:33170 const std::string& frontend_url);
danakj2d7921652019-09-11 17:20:12171 void SetShouldDumpAsLayout(bool);
172 void SetCustomTextOutput(const std::string& text);
173 void SetShouldGeneratePixelResults(bool);
174 void SetShouldDumpFrameLoadCallbacks(bool);
danakj2d7921652019-09-11 17:20:12175 bool ShouldDumpEditingCallbacks() const;
176 bool ShouldDumpFrameLoadCallbacks() const;
177 bool ShouldDumpPingLoaderCallbacks() const;
178 bool ShouldDumpUserGestureInFrameLoadCallbacks() const;
179 bool ShouldDumpTitleChanges() const;
180 bool ShouldDumpIconChanges() const;
danakj2d7921652019-09-11 17:20:12181 bool CanOpenWindows() const;
danakj2d7921652019-09-11 17:20:12182 bool ShouldWaitUntilExternalURLLoad() const;
183 const std::set<std::string>* HttpHeadersToClear() const;
Dominic Farolinoaee9c1b82019-12-18 03:20:10184 bool ClearReferrer() const;
danakj29382fc2020-04-20 18:00:09185 bool IsWebPlatformTestsMode() const;
186 void SetIsWebPlatformTestsMode();
Mason Freedb0855622018-10-02 17:49:47187 bool animation_requires_raster() const { return animation_requires_raster_; }
188 void SetAnimationRequiresRaster(bool do_raster);
lukasza10cd8762016-04-27 20:03:02189
arthursonzognid409c252019-03-14 09:22:22190 // Add |frame| to the set of loading frames.
191 //
192 // Note: Only one renderer process is really tracking the loading frames. This
193 // is the first to observe one. Both local and remote frames are tracked
194 // by this process.
195 void AddLoadingFrame(blink::WebFrame* frame);
lukasza10cd8762016-04-27 20:03:02196
arthursonzognid409c252019-03-14 09:22:22197 // Remove |frame| from the set of loading frames.
198 //
199 // When there are no more loading frames, this potentially finishes the test,
danakj2d7921652019-09-11 17:20:12200 // unless TestRunner.WaitUntilDone() was called and/or there are pending load
arthursonzognid409c252019-03-14 09:22:22201 // requests in WorkQueue.
202 void RemoveLoadingFrame(blink::WebFrame* frame);
lukasza10cd8762016-04-27 20:03:02203
Hitoshi Yoshida0d0156c2020-10-29 17:36:15204 // Called when a main frame has been navigated away.
205 void OnFrameDeactivated(WebFrameTestProxy* frame);
206
207 // Called when a main frame has been restored from backward/forward cache.
208 void OnFrameReactivated(WebFrameTestProxy* frame);
209
danakj2d7921652019-09-11 17:20:12210 void PolicyDelegateDone();
211 bool PolicyDelegateEnabled() const;
212 bool PolicyDelegateIsPermissive() const;
213 bool PolicyDelegateShouldNotifyDone() const;
danakj2d7921652019-09-11 17:20:12214 void SetDragImage(const SkBitmap& drag_image);
215 bool ShouldDumpNavigationPolicy() const;
[email protected]97f9a7952014-03-14 11:50:33216
caseqcb2227832016-05-24 18:52:04217 bool ShouldDumpConsoleMessages() const;
Yoichi Osatoebf845ac72018-08-30 08:13:50218 // Controls whether console messages produced by the page are dumped
219 // to test output.
220 void SetDumpConsoleMessages(bool value);
221
danakj7c5a96c2020-07-03 15:58:36222 // The following trigger navigations on the main WebView.
223 void GoToOffset(int offset);
224 void Reload();
225 void LoadURLForFrame(const GURL& url, const std::string& frame_name);
226
227 // Add a message to the text dump for the web test.
228 void PrintMessage(const std::string& message);
229 // Add a message to stderr (not saved to expected output files, for debugging
230 // only).
231 void PrintMessageToStderr(const std::string& message);
232
233 // Register a new isolated filesystem with the given files, and return the
234 // new filesystem id.
235 blink::WebString RegisterIsolatedFileSystem(
236 const std::vector<base::FilePath>& file_paths);
237
Hitoshi Yoshida25a31d52020-10-29 08:00:33238 void ProcessWorkItem(mojom::WorkItemPtr work_item);
Nan Lin478672f2022-06-29 01:10:24239 void ReplicateWorkQueueStates(const base::Value::Dict& changed_values);
Hitoshi Yoshida25a31d52020-10-29 08:00:33240
jkarlin3bddb7d2016-09-21 18:44:16241 blink::WebEffectiveConnectionType effective_connection_type() const {
242 return effective_connection_type_;
243 }
244
Dave Tapuska012b5b12021-02-04 21:40:24245 // Determine the the frame is considered in the main window.
246 bool IsFrameInMainWindow(blink::WebLocalFrame* frame);
247
248 // Set the main window and test configuration.
249 void SetMainWindowAndTestConfiguration(
250 blink::WebLocalFrame* initial_local_root,
251 mojom::WebTestRunTestConfigurationPtr config);
252 const mojom::WebTestRunTestConfiguration& TestConfig() const;
253
254 // Returns an asbsolute file path. This depends on the current test
255 // configuration so it should only be called while a test is running.
256 blink::WebString GetAbsoluteWebStringFromUTF8Path(
257 const std::string& utf8_path);
258
[email protected]97f9a7952014-03-14 11:50:33259 private:
[email protected]97f9a7952014-03-14 11:50:33260 friend class TestRunnerBindings;
261 friend class WorkQueue;
Dave Tapuska012b5b12021-02-04 21:40:24262 class MainWindowTracker;
[email protected]97f9a7952014-03-14 11:50:33263
danakj2d7921652019-09-11 17:20:12264 // Helper class for managing events queued by methods like QueueLoad or
265 // QueueScript.
[email protected]97f9a7952014-03-14 11:50:33266 class WorkQueue {
Hitoshi Yoshida25a31d52020-10-29 08:00:33267 static constexpr const char* kKeyFrozen = "frozen";
268
[email protected]97f9a7952014-03-14 11:50:33269 public:
270 explicit WorkQueue(TestRunner* controller);
Hitoshi Yoshida25a31d52020-10-29 08:00:33271 ~WorkQueue() = default;
[email protected]97f9a7952014-03-14 11:50:33272
273 // Reset the state of the class between tests.
274 void Reset();
275
Hitoshi Yoshida25a31d52020-10-29 08:00:33276 void AddWork(mojom::WorkItemPtr work_item);
277 void RequestWork();
278 void ProcessWorkItem(mojom::WorkItemPtr work_item);
Nan Lin478672f2022-06-29 01:10:24279 void ReplicateStates(const base::Value::Dict& values);
[email protected]97f9a7952014-03-14 11:50:33280
Hitoshi Yoshida25a31d52020-10-29 08:00:33281 // Takes care of notifying the browser after a change to the state.
282 void OnStatesChanged();
danakj3130f122019-07-16 17:49:47283
Hitoshi Yoshida25a31d52020-10-29 08:00:33284 void set_loading(bool value) { loading_ = value; }
285
286 void set_frozen(bool value) { states_.SetBoolean(kKeyFrozen, value); }
287 void set_has_items(bool value) {
288 states_.SetBoolean(kDictKeyWorkQueueHasItems, value);
289 }
290 bool has_items() const { return GetStateValue(kDictKeyWorkQueueHasItems); }
[email protected]97f9a7952014-03-14 11:50:33291
292 private:
Hitoshi Yoshida25a31d52020-10-29 08:00:33293 bool ProcessWorkItemInternal(mojom::WorkItemPtr work_item);
[email protected]97f9a7952014-03-14 11:50:33294
Hitoshi Yoshida25a31d52020-10-29 08:00:33295 bool is_frozen() const { return GetStateValue(kKeyFrozen); }
296
297 bool GetStateValue(const char* key) const {
Nan Lin478672f2022-06-29 01:10:24298 absl::optional<bool> value =
299 states_.current_values().FindBoolByDottedPath(key);
Hitoshi Yoshida25a31d52020-10-29 08:00:33300 DCHECK(value.has_value());
301 return value.value();
302 }
303
304 bool loading_ = true;
305 // Collection of flags to be synced with the browser process.
306 TrackedDictionary states_;
307
[email protected]97f9a7952014-03-14 11:50:33308 TestRunner* controller_;
309 };
310
danakje2834422020-07-10 21:18:58311 // If the main test window's main frame is hosted in this renderer process,
312 // then this will return it. Otherwise, it is in another process and this
313 // returns null.
314 WebFrameTestProxy* FindInProcessMainWindowMainFrame();
315
[email protected]97f9a7952014-03-14 11:50:33316 ///////////////////////////////////////////////////////////////////////////
317 // Methods dealing with the test logic
318
319 // By default, tests end when page load is complete. These methods are used
danakj2d7921652019-09-11 17:20:12320 // to delay the completion of the test until NotifyDone is called.
[email protected]97f9a7952014-03-14 11:50:33321 void WaitUntilDone();
danakj654fd752020-07-10 16:52:09322 void NotifyDone();
323
324 // When there are no conditions left to wait for, this is called to cause the
325 // test to end, collect results, and inform the browser.
326 void FinishTest();
[email protected]97f9a7952014-03-14 11:50:33327
328 // Methods for adding actions to the work queue. Used in conjunction with
danakj2d7921652019-09-11 17:20:12329 // WaitUntilDone/NotifyDone above.
[email protected]97f9a7952014-03-14 11:50:33330 void QueueBackNavigation(int how_far_back);
331 void QueueForwardNavigation(int how_far_forward);
332 void QueueReload();
Hitoshi Yoshidaa629c872020-10-22 16:33:33333 void QueueLoadingScript(const std::string& script);
334 void QueueNonLoadingScript(const std::string& script);
danakj12c09b62020-07-11 04:17:05335 void QueueLoad(const GURL& current_url,
336 const std::string& relative_url,
337 const std::string& target);
[email protected]97f9a7952014-03-14 11:50:33338
danakjcdff34e42020-05-04 21:42:48339 // Called from the TestRunnerBindings to inform that the test has modified
340 // the TestPreferences. This will update the WebkitPreferences in the renderer
341 // and the browser.
342 void OnTestPreferencesChanged(const TestPreferences& test_prefs,
343 RenderFrame* frame);
344
[email protected]97f9a7952014-03-14 11:50:33345 // Causes navigation actions just printout the intended navigation instead
346 // of taking you to the page. This is used for cases like mailto, where you
347 // don't actually want to open the mail program.
348 void SetCustomPolicyDelegate(gin::Arguments* args);
349
350 // Delays completion of the test until the policy delegate runs.
351 void WaitForPolicyDelegate();
352
danakjaa87f0092020-07-07 17:13:43353 // This is the count of windows which have their main frame in this renderer
354 // process. A cross-origin window would not appear in this count.
355 int InProcessWindowCount();
[email protected]97f9a7952014-03-14 11:50:33356
Kent Tamura21d1de62018-12-10 04:45:20357 // Allows web tests to manage origins' allow list.
Takashi Toyoshima66e7d0d2018-08-28 09:20:10358 void AddOriginAccessAllowListEntry(const std::string& source_origin,
[email protected]97f9a7952014-03-14 11:50:33359 const std::string& destination_protocol,
360 const std::string& destination_host,
361 bool allow_destination_subdomains);
[email protected]97f9a7952014-03-14 11:50:33362
[email protected]97f9a7952014-03-14 11:50:33363 // Enables or disables subpixel positioning (i.e. fractional X positions for
364 // glyphs) in text rendering on Linux. Since this method changes global
365 // settings, tests that call it must use their own custom font family for
366 // all text that they render. If not, an already-cached style will be used,
367 // resulting in the changed setting being ignored.
368 void SetTextSubpixelPositioning(bool value);
369
Dave Tapuska442a74f2020-08-20 15:50:46370 // Set the mock orientation on |view| to |orientation|.
Dave Tapuska13da016a2021-02-04 21:51:58371 void SetMockScreenOrientation(blink::WebView* view,
Dave Tapuska442a74f2020-08-20 15:50:46372 const std::string& orientation);
373 // Disable any mock orientation on |view| that is set.
Dave Tapuska13da016a2021-02-04 21:51:58374 void DisableMockScreenOrientation(blink::WebView* view);
[email protected]e0bc2cb2014-03-20 17:34:24375
Mario Sanchez Prada0bd8b8c2020-10-21 17:49:23376 // Modify accept_languages in blink::RendererPreferences.
[email protected]ebd5ea52014-05-28 14:51:15377 void SetAcceptLanguages(const std::string& accept_languages);
378
[email protected]97f9a7952014-03-14 11:50:33379 ///////////////////////////////////////////////////////////////////////////
380 // Methods that modify the state of TestRunner
381
Xianzhu Wang8d64fc32018-10-15 02:26:53382 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33383 // descriptive text for each editing command. It takes no arguments, and
384 // ignores any that may be present.
385 void DumpEditingCallbacks();
386
Xianzhu Wang6e84f0992018-10-23 23:07:55387 // This function sets a flag that tells the test runner to dump pages as
388 // plain text. The pixel results will not be generated for this test.
389 // It has higher priority than DumpAsMarkup() and DumpAsLayout().
[email protected]97f9a7952014-03-14 11:50:33390 void DumpAsText();
391
Xianzhu Wang8d64fc32018-10-15 02:26:53392 // This function sets a flag that tells the test runner to dump pages as
[email protected]fdc433c02014-06-02 19:27:14393 // the DOM contents, rather than as a text representation of the renderer's
Xianzhu Wang6e84f0992018-10-23 23:07:55394 // state. The pixel results will not be generated for this test. It has
395 // higher priority than DumpAsLayout(), but lower than DumpAsText().
[email protected]fdc433c02014-06-02 19:27:14396 void DumpAsMarkup();
397
Xianzhu Wang6e84f0992018-10-23 23:07:55398 // This function sets a flag that tells the test runner to dump pages as
399 // plain text. It will also generate a pixel dump for the test.
[email protected]97f9a7952014-03-14 11:50:33400 void DumpAsTextWithPixelResults();
401
Xianzhu Wang6e84f0992018-10-23 23:07:55402 // This function sets a flag that tells the test runner to dump pages as
403 // text representation of the layout. The pixel results will not be generated
404 // for this test. It has lower priority than DumpAsText() and DumpAsMarkup().
405 void DumpAsLayout();
406
407 // This function sets a flag that tells the test runner to dump pages as
408 // text representation of the layout. It will also generate a pixel dump for
409 // the test.
410 void DumpAsLayoutWithPixelResults();
411
Xianzhu Wang8d64fc32018-10-15 02:26:53412 // This function sets a flag that tells the test runner to recursively dump
Xianzhu Wang6e84f0992018-10-23 23:07:55413 // all frames as text, markup or layout depending on which of DumpAsText,
414 // DumpAsMarkup and DumpAsLayout is effective.
Xianzhu Wang8d64fc32018-10-15 02:26:53415 void DumpChildFrames();
[email protected]97f9a7952014-03-14 11:50:33416
Xianzhu Wang8d64fc32018-10-15 02:26:53417 // This function sets a flag that tells the test runner to print out the
[email protected]97f9a7952014-03-14 11:50:33418 // information about icon changes notifications from WebKit.
419 void DumpIconChanges();
420
421 // Deals with Web Audio WAV file data.
422 void SetAudioData(const gin::ArrayBufferView& view);
423
Xianzhu Wang8d64fc32018-10-15 02:26:53424 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33425 // descriptive text for each frame load callback. It takes no arguments, and
426 // ignores any that may be present.
427 void DumpFrameLoadCallbacks();
428
Xianzhu Wang8d64fc32018-10-15 02:26:53429 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33430 // descriptive text for each PingLoader dispatch. It takes no arguments, and
431 // ignores any that may be present.
432 void DumpPingLoaderCallbacks();
433
Xianzhu Wang8d64fc32018-10-15 02:26:53434 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33435 // user gesture status text for some frame load callbacks. It takes no
436 // arguments, and ignores any that may be present.
437 void DumpUserGestureInFrameLoadCallbacks();
438
439 void DumpTitleChanges();
440
Xianzhu Wang8d64fc32018-10-15 02:26:53441 // This function sets a flag that tells the test runner to dump the MIME type
[email protected]97f9a7952014-03-14 11:50:33442 // for each resource that was loaded. It takes no arguments, and ignores any
443 // that may be present.
444 void DumpResourceResponseMIMETypes();
445
mlamouri007f9d72015-02-27 16:27:25446 // WebContentSettingsClient related.
[email protected]97f9a7952014-03-14 11:50:33447 void SetImagesAllowed(bool allowed);
448 void SetScriptsAllowed(bool allowed);
449 void SetStorageAllowed(bool allowed);
[email protected]97f9a7952014-03-14 11:50:33450 void SetAllowRunningOfInsecureContent(bool allowed);
451 void DumpPermissionClientCallbacks();
452
Xianzhu Wang8d64fc32018-10-15 02:26:53453 // This function sets a flag that tells the test runner to print out a text
[email protected]97f9a7952014-03-14 11:50:33454 // representation of the back/forward list. It ignores all arguments.
455 void DumpBackForwardList();
456
457 void DumpSelectionRect();
[email protected]97f9a7952014-03-14 11:50:33458
459 // Causes layout to happen as if targetted to printed pages.
460 void SetPrinting();
Xianzhu Wangdbb84fc2018-02-03 00:33:35461 void SetPrintingForFrame(const std::string& frame_name);
[email protected]97f9a7952014-03-14 11:50:33462
463 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
464
465 // Causes WillSendRequest to clear certain headers.
Dominic Farolinoaee9c1b82019-12-18 03:20:10466 // Note: This cannot be used to clear the request's `Referer` header, as this
467 // header is computed later given its referrer string member. To clear it, use
468 // SetWillSendRequestClearReferrer() below.
[email protected]97f9a7952014-03-14 11:50:33469 void SetWillSendRequestClearHeader(const std::string& header);
470
Dominic Farolinoaee9c1b82019-12-18 03:20:10471 // Causes WillSendRequest to clear the request's referrer string and set its
472 // referrer policy to the default.
473 void SetWillSendRequestClearReferrer();
474
[email protected]a79cb9912014-04-26 22:07:33475 // Sets a flag that causes the test to be marked as completed when the
danakj2d7921652019-09-11 17:20:12476 // WebLocalFrameClient receives a LoadURLExternally() call.
[email protected]a79cb9912014-04-26 22:07:33477 void WaitUntilExternalURLLoad();
478
lukasza1b546c12016-04-04 16:19:20479 // This function sets a flag to dump the drag image when the next drag&drop is
480 // initiated. It is equivalent to DumpAsTextWithPixelResults but the pixel
481 // results will be the drag image instead of a snapshot of the page.
jackhou656fc852015-02-13 09:04:17482 void DumpDragImage();
483
Dave Tapuska13da016a2021-02-04 21:51:58484 // Sets a flag that sets a flag to dump the default navigation policy passed
485 // to the DecidePolicyForNavigation callback.
jochenc3a98da12015-03-10 13:59:58486 void DumpNavigationPolicy();
487
tkent217ff8852016-11-14 04:43:49488 // Controls whether JavaScript dialogs such as alert() are dumped to test
489 // output.
490 void SetDumpJavaScriptDialogs(bool value);
491
jkarlin3bddb7d2016-09-21 18:44:16492 // Overrides the NetworkQualityEstimator's estimated network type. If |type|
493 // is TypeUnknown the NQE's value is used. Be sure to call this with
494 // TypeUnknown at the end of your test if you use this.
495 void SetEffectiveConnectionType(
496 blink::WebEffectiveConnectionType connection_type);
497
danakj7c5a96c2020-07-03 15:58:36498 // Takes care of notifying the browser after a change to web test runtime
lukasza083b4f12016-03-24 16:51:43499 // flags.
Kent Tamura2eab5b12018-12-07 04:31:23500 void OnWebTestRuntimeFlagsChanged();
lukaszac9cbe712016-03-14 14:06:43501
[email protected]97f9a7952014-03-14 11:50:33502 ///////////////////////////////////////////////////////////////////////////
503 // Internal helpers
[email protected]eec9e78e2014-06-16 21:38:48504
danakj7c5a96c2020-07-03 15:58:36505 mojo::AssociatedRemote<mojom::WebTestControlHost>&
506 GetWebTestControlHostRemote();
507 void HandleWebTestControlHostDisconnected();
508 mojo::AssociatedRemote<mojom::WebTestControlHost>
509 web_test_control_host_remote_;
510
danakjaa87f0092020-07-07 17:13:43511 mojom::WebTestBluetoothFakeAdapterSetter& GetBluetoothFakeAdapterSetter();
512 void HandleBluetoothFakeAdapterSetterDisconnected();
513 mojo::Remote<mojom::WebTestBluetoothFakeAdapterSetter>
514 bluetooth_fake_adapter_setter_;
515
danakj3130f122019-07-16 17:49:47516 bool test_is_running_ = false;
[email protected]97f9a7952014-03-14 11:50:33517
[email protected]97f9a7952014-03-14 11:50:33518 WorkQueue work_queue_;
519
[email protected]97f9a7952014-03-14 11:50:33520 // Bound variable to return the name of this platform (chromium).
521 std::string platform_name_;
522
lukasza9b9d70e2016-02-25 23:45:44523 // Flags controlling what content gets dumped as a layout text result.
Kent Tamura2eab5b12018-12-07 04:31:23524 WebTestRuntimeFlags web_test_runtime_flags_;
[email protected]97f9a7952014-03-14 11:50:33525
Xianzhu Wang8d64fc32018-10-15 02:26:53526 // If true, the test runner will output a base64 encoded WAVE file.
[email protected]97f9a7952014-03-14 11:50:33527 bool dump_as_audio_;
528
Xianzhu Wang8d64fc32018-10-15 02:26:53529 // If true, the test runner will produce a dump of the back forward list as
[email protected]97f9a7952014-03-14 11:50:33530 // well.
531 bool dump_back_forward_list_;
532
[email protected]97f9a7952014-03-14 11:50:33533 // If true, pixel dump will be produced as a series of 1px-tall, view-wide
534 // individual paints over the height of the view.
535 bool test_repaint_;
536
537 // If true and test_repaint_ is true as well, pixel dump will be produced as
538 // a series of 1px-wide, view-tall paints across the width of the view.
539 bool sweep_horizontally_;
540
[email protected]97f9a7952014-03-14 11:50:33541 std::set<std::string> http_headers_to_clear_;
Dominic Farolinoaee9c1b82019-12-18 03:20:10542 bool clear_referrer_ = false;
[email protected]97f9a7952014-03-14 11:50:33543
544 // WAV audio data is stored here.
danakjc50c5e22020-07-09 17:06:14545 std::vector<uint8_t> audio_data_;
[email protected]97f9a7952014-03-14 11:50:33546
danakjaa87f0092020-07-07 17:13:43547 base::flat_set<WebFrameTestProxy*> main_frames_;
[email protected]97f9a7952014-03-14 11:50:33548
Dave Tapuska012b5b12021-02-04 21:40:24549 // Keeps track of which WebViews that are main windows.
550 std::vector<std::unique_ptr<MainWindowTracker>> main_windows_;
551
arthursonzognid409c252019-03-14 09:22:22552 // This is non empty when a load is in progress.
553 std::vector<blink::WebFrame*> loading_frames_;
danakj654fd752020-07-10 16:52:09554 // We do not want the test to end until the main frame finishes loading. This
555 // starts as true at the beginning of the test, and will be set to false once
556 // we run out of frames to load at any time.
557 bool main_frame_loaded_ = false;
danakj3130f122019-07-16 17:49:47558 // When a loading task is started, this bool is set until all loading_frames_
559 // are completed and removed. This bool becomes true earlier than
danakj654fd752020-07-10 16:52:09560 // loading_frames_ becomes non-empty.
561 bool frame_will_start_load_ = true;
danakj3130f122019-07-16 17:49:47562 // When NotifyDone() occurs, if loading is still working, it is delayed, and
563 // this bool tracks that NotifyDone() was called. This differentiates from a
564 // test that was not waiting for NotifyDone() at all.
565 bool did_notify_done_ = false;
[email protected]97f9a7952014-03-14 11:50:33566
danakj1a887ad2020-09-01 22:16:01567 WebTestContentSettingsClient test_content_settings_client_;
568 FakeScreenOrientationImpl fake_screen_orientation_impl_;
danakjaa87f0092020-07-07 17:13:43569 GamepadController gamepad_controller_;
lukaszafd124602016-04-01 16:53:30570
lukasza1b546c12016-04-04 16:19:20571 // Captured drag image.
danakj0c75ad82018-07-10 19:50:12572 SkBitmap drag_image_;
lukasza1b546c12016-04-04 16:19:20573
Mason Freedb0855622018-10-02 17:49:47574 // True if rasterization should be performed during tests that examine
575 // fling-style animations. This includes middle-click auto-scroll behaviors.
576 // This does not include most "ordinary" animations, such as CSS animations.
danakj3130f122019-07-16 17:49:47577 bool animation_requires_raster_ = false;
Mason Freedb0855622018-10-02 17:49:47578
Kent Tamura21d1de62018-12-10 04:45:20579 // An effective connection type settable by web tests.
danakj3130f122019-07-16 17:49:47580 blink::WebEffectiveConnectionType effective_connection_type_ =
581 blink::WebEffectiveConnectionType::kTypeUnknown;
jkarlin3bddb7d2016-09-21 18:44:16582
Dave Tapuska012b5b12021-02-04 21:40:24583 mojom::WebTestRunTestConfiguration test_config_;
584
Jeremy Roman3bca4bf2019-07-11 03:41:25585 base::WeakPtrFactory<TestRunner> weak_factory_{this};
[email protected]97f9a7952014-03-14 11:50:33586};
587
danakj741848a2020-04-07 22:48:06588} // namespace content
[email protected]97f9a7952014-03-14 11:50:33589
danakj89f47082020-09-02 17:53:43590#endif // CONTENT_WEB_TEST_RENDERER_TEST_RUNNER_H_