blob: 65936280d7c46f6afb123d91696ab8f0e52cc1c4 [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
Scott Violetfdda96d2018-07-27 20:17:235#ifndef CONTENT_SHELL_TEST_RUNNER_TEST_RUNNER_H_
6#define CONTENT_SHELL_TEST_RUNNER_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
Brett Wilsoncc8623d2017-09-12 03:28:1015#include "base/containers/circular_deque.h"
avi5dd91f82015-12-25 22:30:4616#include "base/macros.h"
[email protected]97f9a7952014-03-14 11:50:3317#include "base/memory/weak_ptr.h"
Peter Beverloo988ef962017-09-12 15:49:1718#include "base/optional.h"
19#include "base/strings/string16.h"
danakj3130f122019-07-16 17:49:4720#include "content/shell/test_runner/mock_screen_orientation_client.h"
Scott Violetfdda96d2018-07-27 20:17:2321#include "content/shell/test_runner/test_runner_export.h"
22#include "content/shell/test_runner/web_test_runner.h"
Kent Tamura2eab5b12018-12-07 04:31:2323#include "content/shell/test_runner/web_test_runtime_flags.h"
Blink Reformata30d4232018-04-07 15:31:0624#include "third_party/blink/public/platform/web_effective_connection_type.h"
Fredrik Söderquistb2b39eb92019-11-18 16:16:5025#include "third_party/skia/include/core/SkBitmap.h"
[email protected]97f9a7952014-03-14 11:50:3326#include "v8/include/v8.h"
27
[email protected]945babb2014-07-30 14:25:3228class GURL;
[email protected]eec9e78e2014-06-16 21:38:4829
[email protected]97f9a7952014-03-14 11:50:3330namespace blink {
mlamouri007f9d72015-02-27 16:27:2531class WebContentSettingsClient;
[email protected]97f9a7952014-03-14 11:50:3332class WebFrame;
lukaszab2ad0502016-04-27 15:51:4233class WebLocalFrame;
[email protected]97f9a7952014-03-14 11:50:3334class WebString;
35class WebView;
Scott Violetfdda96d2018-07-27 20:17:2336}
[email protected]97f9a7952014-03-14 11:50:3337
38namespace gin {
39class ArrayBufferView;
40class Arguments;
Scott Violetfdda96d2018-07-27 20:17:2341}
[email protected]97f9a7952014-03-14 11:50:3342
jochenf5f31752015-06-03 12:06:3443namespace test_runner {
lukasza21353232016-04-12 19:52:1144class MockContentSettingsClient;
lukasza6a113ae12016-03-17 22:41:2045class MockScreenOrientationClient;
lukasza5c2279c2016-04-05 16:44:4746class SpellCheckClient;
[email protected]79ecada2014-05-04 05:16:1647class TestInterfaces;
lukaszab2ad0502016-04-27 15:51:4248class TestRunnerForSpecificView;
[email protected]79ecada2014-05-04 05:16:1649class WebTestDelegate;
[email protected]97f9a7952014-03-14 11:50:3350
lukaszab2ad0502016-04-27 15:51:4251// TestRunner class currently has dual purpose:
danakj2d7921652019-09-11 17:20:1252// 1. It implements TestRunner javascript bindings for "global" / "ambient".
lukaszab2ad0502016-04-27 15:51:4253// Examples:
danakj2d7921652019-09-11 17:20:1254// - TestRunner.DumpAsText (test flag affecting test behavior)
55// - TestRunner.SetAllowRunningOfInsecureContent (test flag affecting product
lukaszab2ad0502016-04-27 15:51:4256// behavior)
danakj2d7921652019-09-11 17:20:1257// - TestRunner.SetTextSubpixelPositioning (directly interacts with product).
lukaszab2ad0502016-04-27 15:51:4258// Note that "per-view" (non-"global") bindings are handled by
59// instances of TestRunnerForSpecificView class.
60// 2. It manages global test state. Example:
61// - Tracking topLoadingFrame that can finish the test when it loads.
62// - WorkQueue holding load requests from the TestInterfaces
Kent Tamura21d1de62018-12-10 04:45:2063// - WebTestRuntimeFlags
lukaszac9358822016-04-07 14:43:4664class TestRunner : public WebTestRunner {
[email protected]97f9a7952014-03-14 11:50:3365 public:
[email protected]79ecada2014-05-04 05:16:1666 explicit TestRunner(TestInterfaces*);
[email protected]97f9a7952014-03-14 11:50:3367 virtual ~TestRunner();
68
lukaszab2ad0502016-04-27 15:51:4269 void Install(blink::WebLocalFrame* frame,
70 base::WeakPtr<TestRunnerForSpecificView> view_test_runner);
[email protected]97f9a7952014-03-14 11:50:3371
[email protected]79ecada2014-05-04 05:16:1672 void SetDelegate(WebTestDelegate*);
lukasza8973c522016-04-27 16:32:2873 void SetMainView(blink::WebView*);
[email protected]97f9a7952014-03-14 11:50:3374
75 void Reset();
76
[email protected]97f9a7952014-03-14 11:50:3377 void SetTestIsRunning(bool);
78 bool TestIsRunning() const { return test_is_running_; }
79
danakj3130f122019-07-16 17:49:4780 // Finishes the test if it is ready. This should be called before running
81 // tasks that will change state, so that the test can capture the current
82 // state. Specifically, should run before the BeginMainFrame step which does
83 // layout and animation etc.
84 // This does *not* run as part of loading finishing because that happens in
85 // the middle of blink call stacks that have inconsistent state.
86 void FinishTestIfReady();
87
[email protected]97f9a7952014-03-14 11:50:3388 // WebTestRunner implementation.
dchenge933b3e2014-10-21 11:44:0989 bool ShouldGeneratePixelResults() override;
90 bool ShouldDumpAsAudio() const override;
91 void GetAudioData(std::vector<unsigned char>* buffer_view) const override;
lukaszaef264fc52016-03-17 22:49:1992 bool IsRecursiveLayoutDumpRequested() override;
93 std::string DumpLayout(blink::WebLocalFrame* frame) override;
Mason Freed75453ec2018-08-27 17:11:2394 bool ShouldDumpSelectionRect() const override;
danakje73c9cd2019-04-16 16:29:3395 bool CanDumpPixelsFromRenderer() const override;
96 void DumpPixelsAsync(
danakjda15621e2019-04-05 20:34:4397 content::RenderView* render_view,
lukasza20971a62017-07-12 01:31:2798 base::OnceCallback<void(const SkBitmap&)> callback) override;
Kent Tamura679c7c42018-12-05 03:21:1099 void ReplicateWebTestRuntimeFlagsChanges(
lukaszac9cbe712016-03-14 14:06:43100 const base::DictionaryValue& changed_values) override;
lukaszaa8960462016-01-27 22:27:33101 bool HasCustomTextDump(std::string* custom_text_dump) const override;
dchenge933b3e2014-10-21 11:44:09102 bool ShouldDumpBackForwardList() const override;
mlamouri007f9d72015-02-27 16:27:25103 blink::WebContentSettingsClient* GetWebContentSettings() const override;
xiaochengh81bfb17412017-04-06 17:54:33104 blink::WebTextCheckClient* GetWebTextCheckClient() const override;
lukasza95416be142016-04-14 15:06:33105 void SetFocus(blink::WebView* web_view, bool focus) override;
[email protected]97f9a7952014-03-14 11:50:33106
lukasza01da2602016-04-05 14:51:26107 // Methods used by WebViewTestClient and WebFrameTestClient.
lukaszaa0b624a2016-04-04 15:00:49108 std::string GetAcceptLanguages() const;
danakj2d7921652019-09-11 17:20:12109 bool ShouldStayOnPageAfterHandlingBeforeUnload() const;
110 MockScreenOrientationClient* GetMockScreenOrientationClient();
111 bool ShouldDumpAsCustomText() const;
112 std::string CustomDumpText() const;
abhishek.a21ca9b5602014-09-19 07:33:33113 void ShowDevTools(const std::string& settings,
[email protected]06c253012014-04-16 18:35:33114 const std::string& frontend_url);
pfeldman4c4133d2016-12-20 02:40:21115 void SetV8CacheDisabled(bool);
danakj2d7921652019-09-11 17:20:12116 void SetShouldDumpAsText(bool);
117 void SetShouldDumpAsMarkup(bool);
118 void SetShouldDumpAsLayout(bool);
119 void SetCustomTextOutput(const std::string& text);
120 void SetShouldGeneratePixelResults(bool);
121 void SetShouldDumpFrameLoadCallbacks(bool);
122 void SetShouldEnableViewSource(bool);
123 bool ShouldDumpEditingCallbacks() const;
124 bool ShouldDumpFrameLoadCallbacks() const;
125 bool ShouldDumpPingLoaderCallbacks() const;
126 bool ShouldDumpUserGestureInFrameLoadCallbacks() const;
127 bool ShouldDumpTitleChanges() const;
128 bool ShouldDumpIconChanges() const;
129 bool ShouldDumpCreateView() const;
130 bool CanOpenWindows() const;
danakj2d7921652019-09-11 17:20:12131 bool ShouldDumpSpellCheckCallbacks() const;
132 bool ShouldWaitUntilExternalURLLoad() const;
133 const std::set<std::string>* HttpHeadersToClear() const;
Dominic Farolinoaee9c1b82019-12-18 03:20:10134 bool ClearReferrer() const;
tkent2edc979d2016-05-27 04:58:25135 bool is_web_platform_tests_mode() const {
136 return is_web_platform_tests_mode_;
137 }
138 void set_is_web_platform_tests_mode() { is_web_platform_tests_mode_ = true; }
Mason Freedb0855622018-10-02 17:49:47139 bool animation_requires_raster() const { return animation_requires_raster_; }
140 void SetAnimationRequiresRaster(bool do_raster);
lukasza10cd8762016-04-27 20:03:02141
arthursonzognid409c252019-03-14 09:22:22142 // Add |frame| to the set of loading frames.
143 //
144 // Note: Only one renderer process is really tracking the loading frames. This
145 // is the first to observe one. Both local and remote frames are tracked
146 // by this process.
147 void AddLoadingFrame(blink::WebFrame* frame);
lukasza10cd8762016-04-27 20:03:02148
arthursonzognid409c252019-03-14 09:22:22149 // Remove |frame| from the set of loading frames.
150 //
151 // When there are no more loading frames, this potentially finishes the test,
danakj2d7921652019-09-11 17:20:12152 // unless TestRunner.WaitUntilDone() was called and/or there are pending load
arthursonzognid409c252019-03-14 09:22:22153 // requests in WorkQueue.
154 void RemoveLoadingFrame(blink::WebFrame* frame);
lukasza10cd8762016-04-27 20:03:02155
danakj3130f122019-07-16 17:49:47156 blink::WebFrame* MainFrame() const;
danakj2d7921652019-09-11 17:20:12157 void PolicyDelegateDone();
158 bool PolicyDelegateEnabled() const;
159 bool PolicyDelegateIsPermissive() const;
160 bool PolicyDelegateShouldNotifyDone() const;
161 void SetToolTipText(const blink::WebString&);
162 void SetDragImage(const SkBitmap& drag_image);
163 bool ShouldDumpNavigationPolicy() const;
[email protected]97f9a7952014-03-14 11:50:33164
caseqcb2227832016-05-24 18:52:04165 bool ShouldDumpConsoleMessages() const;
Yoichi Osatoebf845ac72018-08-30 08:13:50166 // Controls whether console messages produced by the page are dumped
167 // to test output.
168 void SetDumpConsoleMessages(bool value);
169
tkent217ff8852016-11-14 04:43:49170 bool ShouldDumpJavaScriptDialogs() const;
caseqcb2227832016-05-24 18:52:04171
jkarlin3bddb7d2016-09-21 18:44:16172 blink::WebEffectiveConnectionType effective_connection_type() const {
173 return effective_connection_type_;
174 }
175
[email protected]97f9a7952014-03-14 11:50:33176 // A single item in the work queue.
177 class WorkItem {
178 public:
179 virtual ~WorkItem() {}
180
181 // Returns true if this started a load.
[email protected]79ecada2014-05-04 05:16:16182 virtual bool Run(WebTestDelegate*, blink::WebView*) = 0;
[email protected]97f9a7952014-03-14 11:50:33183 };
184
185 private:
[email protected]97f9a7952014-03-14 11:50:33186 friend class TestRunnerBindings;
187 friend class WorkQueue;
188
danakj2d7921652019-09-11 17:20:12189 // Helper class for managing events queued by methods like QueueLoad or
190 // QueueScript.
[email protected]97f9a7952014-03-14 11:50:33191 class WorkQueue {
192 public:
193 explicit WorkQueue(TestRunner* controller);
194 virtual ~WorkQueue();
195 void ProcessWorkSoon();
196
197 // Reset the state of the class between tests.
198 void Reset();
199
200 void AddWork(WorkItem*);
201
202 void set_frozen(bool frozen) { frozen_ = frozen; }
danakj3130f122019-07-16 17:49:47203 bool is_empty() const { return queue_.empty(); }
204
205 void set_finished_loading() { finished_loading_ = true; }
[email protected]97f9a7952014-03-14 11:50:33206
207 private:
208 void ProcessWork();
209
Brett Wilsoncc8623d2017-09-12 03:28:10210 base::circular_deque<WorkItem*> queue_;
danakj3130f122019-07-16 17:49:47211 bool frozen_ = false;
212 bool finished_loading_ = false;
[email protected]97f9a7952014-03-14 11:50:33213 TestRunner* controller_;
lukaszac9358822016-04-07 14:43:46214
Jeremy Roman3bca4bf2019-07-11 03:41:25215 base::WeakPtrFactory<WorkQueue> weak_factory_{this};
[email protected]97f9a7952014-03-14 11:50:33216 };
217
218 ///////////////////////////////////////////////////////////////////////////
219 // Methods dealing with the test logic
220
221 // By default, tests end when page load is complete. These methods are used
danakj2d7921652019-09-11 17:20:12222 // to delay the completion of the test until NotifyDone is called.
[email protected]97f9a7952014-03-14 11:50:33223 void NotifyDone();
224 void WaitUntilDone();
225
226 // Methods for adding actions to the work queue. Used in conjunction with
danakj2d7921652019-09-11 17:20:12227 // WaitUntilDone/NotifyDone above.
[email protected]97f9a7952014-03-14 11:50:33228 void QueueBackNavigation(int how_far_back);
229 void QueueForwardNavigation(int how_far_forward);
230 void QueueReload();
231 void QueueLoadingScript(const std::string& script);
232 void QueueNonLoadingScript(const std::string& script);
233 void QueueLoad(const std::string& url, const std::string& target);
[email protected]97f9a7952014-03-14 11:50:33234
235 // Causes navigation actions just printout the intended navigation instead
236 // of taking you to the page. This is used for cases like mailto, where you
237 // don't actually want to open the mail program.
238 void SetCustomPolicyDelegate(gin::Arguments* args);
239
240 // Delays completion of the test until the policy delegate runs.
241 void WaitForPolicyDelegate();
242
243 // Functions for dealing with windows. By default we block all new windows.
244 int WindowCount();
245 void SetCloseRemainingWindowsWhenComplete(bool close_remaining_windows);
246 void ResetTestHelperControllers();
247
Kent Tamura21d1de62018-12-10 04:45:20248 // Allows web tests to manage origins' allow list.
Takashi Toyoshima66e7d0d2018-08-28 09:20:10249 void AddOriginAccessAllowListEntry(const std::string& source_origin,
[email protected]97f9a7952014-03-14 11:50:33250 const std::string& destination_protocol,
251 const std::string& destination_host,
252 bool allow_destination_subdomains);
[email protected]97f9a7952014-03-14 11:50:33253
dcheng9000dbd2015-04-03 05:39:40254 // Add |source_code| as an injected stylesheet to the active document of the
255 // window of the current V8 context.
256 void InsertStyleSheet(const std::string& source_code);
257
[email protected]97f9a7952014-03-14 11:50:33258 // Enables or disables subpixel positioning (i.e. fractional X positions for
259 // glyphs) in text rendering on Linux. Since this method changes global
260 // settings, tests that call it must use their own custom font family for
261 // all text that they render. If not, an already-cached style will be used,
262 // resulting in the changed setting being ignored.
263 void SetTextSubpixelPositioning(bool value);
264
[email protected]97f9a7952014-03-14 11:50:33265 // After this function is called, all window-sizing machinery is
266 // short-circuited inside the renderer. This mode is necessary for
267 // some tests that were written before browsers had multi-process architecture
268 // and rely on window resizes to happen synchronously.
269 // The function has "unfortunate" it its name because we must strive to remove
270 // all tests that rely on this... well, unfortunate behavior. See
271 // http://crbug.com/309760 for the plan.
272 void UseUnfortunateSynchronousResizeMode();
273
danakj83388a32019-09-11 16:28:31274 void EnableAutoResizeMode(int min_width,
[email protected]97f9a7952014-03-14 11:50:33275 int min_height,
276 int max_width,
277 int max_height);
danakj83388a32019-09-11 16:28:31278 void DisableAutoResizeMode(int new_width, int new_height);
[email protected]97f9a7952014-03-14 11:50:33279
[email protected]e0bc2cb2014-03-20 17:34:24280 void SetMockScreenOrientation(const std::string& orientation);
dgozman3c16f7f2016-02-26 01:21:18281 void DisableMockScreenOrientation();
[email protected]e0bc2cb2014-03-20 17:34:24282
[email protected]97f9a7952014-03-14 11:50:33283 ///////////////////////////////////////////////////////////////////////////
284 // Methods modifying WebPreferences.
285
286 // Set the WebPreference that controls webkit's popup blocking.
287 void SetPopupBlockingEnabled(bool block_popups);
288
289 void SetJavaScriptCanAccessClipboard(bool can_access);
[email protected]97f9a7952014-03-14 11:50:33290 void SetAllowFileAccessFromFileURLs(bool allow);
Dan Elphick382a5962018-07-27 13:34:04291 void OverridePreference(gin::Arguments* arguments);
[email protected]97f9a7952014-03-14 11:50:33292
Leon Hanc819dc62019-01-28 04:30:19293 // Modify accept_languages in blink::mojom::RendererPreferences.
[email protected]ebd5ea52014-05-28 14:51:15294 void SetAcceptLanguages(const std::string& accept_languages);
295
[email protected]97f9a7952014-03-14 11:50:33296 // Enable or disable plugins.
297 void SetPluginsEnabled(bool enabled);
298
299 ///////////////////////////////////////////////////////////////////////////
300 // Methods that modify the state of TestRunner
301
Xianzhu Wang8d64fc32018-10-15 02:26:53302 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33303 // descriptive text for each editing command. It takes no arguments, and
304 // ignores any that may be present.
305 void DumpEditingCallbacks();
306
Xianzhu Wang6e84f0992018-10-23 23:07:55307 // This function sets a flag that tells the test runner to dump pages as
308 // plain text. The pixel results will not be generated for this test.
309 // It has higher priority than DumpAsMarkup() and DumpAsLayout().
[email protected]97f9a7952014-03-14 11:50:33310 void DumpAsText();
311
Xianzhu Wang8d64fc32018-10-15 02:26:53312 // This function sets a flag that tells the test runner to dump pages as
[email protected]fdc433c02014-06-02 19:27:14313 // the DOM contents, rather than as a text representation of the renderer's
Xianzhu Wang6e84f0992018-10-23 23:07:55314 // state. The pixel results will not be generated for this test. It has
315 // higher priority than DumpAsLayout(), but lower than DumpAsText().
[email protected]fdc433c02014-06-02 19:27:14316 void DumpAsMarkup();
317
Xianzhu Wang6e84f0992018-10-23 23:07:55318 // This function sets a flag that tells the test runner to dump pages as
319 // plain text. It will also generate a pixel dump for the test.
[email protected]97f9a7952014-03-14 11:50:33320 void DumpAsTextWithPixelResults();
321
Xianzhu Wang6e84f0992018-10-23 23:07:55322 // This function sets a flag that tells the test runner to dump pages as
323 // text representation of the layout. The pixel results will not be generated
324 // for this test. It has lower priority than DumpAsText() and DumpAsMarkup().
325 void DumpAsLayout();
326
327 // This function sets a flag that tells the test runner to dump pages as
328 // text representation of the layout. It will also generate a pixel dump for
329 // the test.
330 void DumpAsLayoutWithPixelResults();
331
Xianzhu Wang8d64fc32018-10-15 02:26:53332 // This function sets a flag that tells the test runner to recursively dump
Xianzhu Wang6e84f0992018-10-23 23:07:55333 // all frames as text, markup or layout depending on which of DumpAsText,
334 // DumpAsMarkup and DumpAsLayout is effective.
Xianzhu Wang8d64fc32018-10-15 02:26:53335 void DumpChildFrames();
[email protected]97f9a7952014-03-14 11:50:33336
Xianzhu Wang8d64fc32018-10-15 02:26:53337 // This function sets a flag that tells the test runner to print out the
[email protected]97f9a7952014-03-14 11:50:33338 // information about icon changes notifications from WebKit.
339 void DumpIconChanges();
340
341 // Deals with Web Audio WAV file data.
342 void SetAudioData(const gin::ArrayBufferView& view);
343
Xianzhu Wang8d64fc32018-10-15 02:26:53344 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33345 // descriptive text for each frame load callback. It takes no arguments, and
346 // ignores any that may be present.
347 void DumpFrameLoadCallbacks();
348
Xianzhu Wang8d64fc32018-10-15 02:26:53349 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33350 // descriptive text for each PingLoader dispatch. It takes no arguments, and
351 // ignores any that may be present.
352 void DumpPingLoaderCallbacks();
353
Xianzhu Wang8d64fc32018-10-15 02:26:53354 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33355 // user gesture status text for some frame load callbacks. It takes no
356 // arguments, and ignores any that may be present.
357 void DumpUserGestureInFrameLoadCallbacks();
358
359 void DumpTitleChanges();
360
Xianzhu Wang8d64fc32018-10-15 02:26:53361 // This function sets a flag that tells the test runner to dump all calls to
[email protected]97f9a7952014-03-14 11:50:33362 // WebViewClient::createView().
363 // It takes no arguments, and ignores any that may be present.
364 void DumpCreateView();
365
366 void SetCanOpenWindows();
367
Xianzhu Wang8d64fc32018-10-15 02:26:53368 // This function sets a flag that tells the test runner to dump the MIME type
[email protected]97f9a7952014-03-14 11:50:33369 // for each resource that was loaded. It takes no arguments, and ignores any
370 // that may be present.
371 void DumpResourceResponseMIMETypes();
372
mlamouri007f9d72015-02-27 16:27:25373 // WebContentSettingsClient related.
[email protected]97f9a7952014-03-14 11:50:33374 void SetImagesAllowed(bool allowed);
375 void SetScriptsAllowed(bool allowed);
376 void SetStorageAllowed(bool allowed);
377 void SetPluginsAllowed(bool allowed);
[email protected]97f9a7952014-03-14 11:50:33378 void SetAllowRunningOfInsecureContent(bool allowed);
[email protected]97f9a7952014-03-14 11:50:33379 void DumpPermissionClientCallbacks();
380
engedy9ae04242016-06-08 13:31:18381 // Sets up a mock DocumentSubresourceFilter to disallow subsequent subresource
382 // loads within the current document with the given path |suffixes|. The
383 // filter is created and injected even if |suffixes| is empty. If |suffixes|
John Delaney096b7a72019-01-18 18:43:24384 // contains the empty string, all subresource loads will be disallowed. If
385 // |block_subresources| is false, matching resources will not be blocked but
386 // instead marked as matching a disallowed resource.
engedy9ae04242016-06-08 13:31:18387 void SetDisallowedSubresourcePathSuffixes(
John Delaney096b7a72019-01-18 18:43:24388 const std::vector<std::string>& suffixes,
389 bool block_subresources);
engedy9ae04242016-06-08 13:31:18390
Xianzhu Wang8d64fc32018-10-15 02:26:53391 // This function sets a flag that tells the test runner to dump all
[email protected]97f9a7952014-03-14 11:50:33392 // the lines of descriptive text about spellcheck execution.
393 void DumpSpellCheckCallbacks();
394
Xianzhu Wang8d64fc32018-10-15 02:26:53395 // This function sets a flag that tells the test runner to print out a text
[email protected]97f9a7952014-03-14 11:50:33396 // representation of the back/forward list. It ignores all arguments.
397 void DumpBackForwardList();
398
399 void DumpSelectionRect();
[email protected]97f9a7952014-03-14 11:50:33400
401 // Causes layout to happen as if targetted to printed pages.
402 void SetPrinting();
Xianzhu Wangdbb84fc2018-02-03 00:33:35403 void SetPrintingForFrame(const std::string& frame_name);
[email protected]97f9a7952014-03-14 11:50:33404
[email protected]52846102014-06-24 04:26:44405 // Clears the state from SetPrinting().
406 void ClearPrinting();
407
[email protected]97f9a7952014-03-14 11:50:33408 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
409
410 // Causes WillSendRequest to clear certain headers.
Dominic Farolinoaee9c1b82019-12-18 03:20:10411 // Note: This cannot be used to clear the request's `Referer` header, as this
412 // header is computed later given its referrer string member. To clear it, use
413 // SetWillSendRequestClearReferrer() below.
[email protected]97f9a7952014-03-14 11:50:33414 void SetWillSendRequestClearHeader(const std::string& header);
415
Dominic Farolinoaee9c1b82019-12-18 03:20:10416 // Causes WillSendRequest to clear the request's referrer string and set its
417 // referrer policy to the default.
418 void SetWillSendRequestClearReferrer();
419
[email protected]a79cb9912014-04-26 22:07:33420 // Sets a flag that causes the test to be marked as completed when the
danakj2d7921652019-09-11 17:20:12421 // WebLocalFrameClient receives a LoadURLExternally() call.
[email protected]a79cb9912014-04-26 22:07:33422 void WaitUntilExternalURLLoad();
423
lukasza1b546c12016-04-04 16:19:20424 // This function sets a flag to dump the drag image when the next drag&drop is
425 // initiated. It is equivalent to DumpAsTextWithPixelResults but the pixel
426 // results will be the drag image instead of a snapshot of the page.
jackhou656fc852015-02-13 09:04:17427 void DumpDragImage();
428
lfg05e41372016-07-22 15:38:10429 // Sets a flag that tells the WebViewTestProxy to dump the default navigation
danakj2d7921652019-09-11 17:20:12430 // policy passed to the DecidePolicyForNavigation callback.
jochenc3a98da12015-03-10 13:59:58431 void DumpNavigationPolicy();
432
tkent217ff8852016-11-14 04:43:49433 // Controls whether JavaScript dialogs such as alert() are dumped to test
434 // output.
435 void SetDumpJavaScriptDialogs(bool value);
436
jkarlin3bddb7d2016-09-21 18:44:16437 // Overrides the NetworkQualityEstimator's estimated network type. If |type|
438 // is TypeUnknown the NQE's value is used. Be sure to call this with
439 // TypeUnknown at the end of your test if you use this.
440 void SetEffectiveConnectionType(
441 blink::WebEffectiveConnectionType connection_type);
442
xiaochengh2fa3e762016-08-24 11:27:04443 // Controls whether the mock spell checker is enabled.
444 void SetMockSpellCheckerEnabled(bool enabled);
445
[email protected]97f9a7952014-03-14 11:50:33446 ///////////////////////////////////////////////////////////////////////////
lfg05e41372016-07-22 15:38:10447 // Methods interacting with the WebViewTestProxy
[email protected]97f9a7952014-03-14 11:50:33448
449 ///////////////////////////////////////////////////////////////////////////
450 // Methods forwarding to the WebTestDelegate
451
452 // Shows DevTools window.
[email protected]06c253012014-04-16 18:35:33453 void ShowWebInspector(const std::string& str,
454 const std::string& frontend_url);
[email protected]97f9a7952014-03-14 11:50:33455 void CloseWebInspector();
456
Will Chen8bbdf20f2017-12-12 21:09:54457 void NavigateSecondaryWindow(const GURL& url);
458 void InspectSecondaryWindow();
459
[email protected]97f9a7952014-03-14 11:50:33460 // Inspect chooser state
461 bool IsChooserShown();
462
Kent Tamura21d1de62018-12-10 04:45:20463 // Allows web tests to exec scripts at WebInspector side.
[email protected]97f9a7952014-03-14 11:50:33464 void EvaluateInWebInspector(int call_id, const std::string& script);
465
466 // Clears all databases.
467 void ClearAllDatabases();
468 // Sets the default quota for all origins
469 void SetDatabaseQuota(int quota);
470
tyoshinoa6b91462016-07-11 09:15:09471 // Sets the cookie policy to:
472 // - allow all cookies when |block| is false
473 // - block only third-party cookies when |block| is true
474 void SetBlockThirdPartyCookies(bool block);
[email protected]97f9a7952014-03-14 11:50:33475
[email protected]97f9a7952014-03-14 11:50:33476 // Converts a URL starting with file:///tmp/ to the local mapping.
477 std::string PathToLocalResource(const std::string& path);
478
mlamourid5098d02015-04-21 12:17:30479 // Sets the permission's |name| to |value| for a given {origin, embedder}
480 // tuple.
481 void SetPermission(const std::string& name,
482 const std::string& value,
483 const GURL& origin,
484 const GURL& embedding_origin);
485
dominickn09f7b572016-10-28 01:44:15486 // Resolve the in-flight beforeinstallprompt event.
487 void ResolveBeforeInstallPromptPromise(const std::string& platform);
benwells0c0d3f12015-05-25 01:03:17488
[email protected]97f9a7952014-03-14 11:50:33489 // Calls setlocale(LC_ALL, ...) for a specified locale.
490 // Resets between tests.
491 void SetPOSIXLocale(const std::string& locale);
492
peterd98157d2014-11-20 13:15:01493 // Simulates a click on a Web Notification.
Peter Beverloo988ef962017-09-12 15:49:17494 void SimulateWebNotificationClick(
495 const std::string& title,
496 const base::Optional<int>& action_index,
497 const base::Optional<base::string16>& reply);
[email protected]97f9a7952014-03-14 11:50:33498
nsatragno24bd34b2016-02-09 10:30:02499 // Simulates closing a Web Notification.
500 void SimulateWebNotificationClose(const std::string& title, bool by_user);
501
Rayan Kansob7bef392019-07-25 12:32:36502 // Simulates a user deleting a content index entry.
503 void SimulateWebContentIndexDelete(const std::string& id);
504
Kent Tamura2eab5b12018-12-07 04:31:23505 // Takes care of notifying the delegate after a change to web test runtime
lukasza083b4f12016-03-24 16:51:43506 // flags.
Kent Tamura2eab5b12018-12-07 04:31:23507 void OnWebTestRuntimeFlagsChanged();
lukaszac9cbe712016-03-14 14:06:43508
[email protected]97f9a7952014-03-14 11:50:33509 ///////////////////////////////////////////////////////////////////////////
510 // Internal helpers
[email protected]eec9e78e2014-06-16 21:38:48511
lukasza10cd8762016-04-27 20:03:02512 bool IsFramePartOfMainTestWindow(blink::WebFrame*) const;
513
[email protected]97f9a7952014-03-14 11:50:33514 void CheckResponseMimeType();
[email protected]97f9a7952014-03-14 11:50:33515
danakj3130f122019-07-16 17:49:47516 bool test_is_running_ = false;
[email protected]97f9a7952014-03-14 11:50:33517
518 // When reset is called, go through and close all but the main test shell
519 // window. By default, set to true but toggled to false using
danakj2d7921652019-09-11 17:20:12520 // SetCloseRemainingWindowsWhenComplete().
danakj3130f122019-07-16 17:49:47521 bool close_remaining_windows_ = false;
[email protected]97f9a7952014-03-14 11:50:33522
[email protected]97f9a7952014-03-14 11:50:33523 WorkQueue work_queue_;
524
[email protected]97f9a7952014-03-14 11:50:33525 // Bound variable to return the name of this platform (chromium).
526 std::string platform_name_;
527
528 // Bound variable to store the last tooltip text
529 std::string tooltip_text_;
530
[email protected]97f9a7952014-03-14 11:50:33531 // Bound variable counting the number of top URLs visited.
danakj3130f122019-07-16 17:49:47532 int web_history_item_count_ = 0;
[email protected]97f9a7952014-03-14 11:50:33533
lukasza9b9d70e2016-02-25 23:45:44534 // Flags controlling what content gets dumped as a layout text result.
Kent Tamura2eab5b12018-12-07 04:31:23535 WebTestRuntimeFlags web_test_runtime_flags_;
[email protected]97f9a7952014-03-14 11:50:33536
Xianzhu Wang8d64fc32018-10-15 02:26:53537 // If true, the test runner will output a base64 encoded WAVE file.
[email protected]97f9a7952014-03-14 11:50:33538 bool dump_as_audio_;
539
Xianzhu Wang8d64fc32018-10-15 02:26:53540 // If true, the test runner will produce a dump of the back forward list as
[email protected]97f9a7952014-03-14 11:50:33541 // well.
542 bool dump_back_forward_list_;
543
[email protected]97f9a7952014-03-14 11:50:33544 // If true, pixel dump will be produced as a series of 1px-tall, view-wide
545 // individual paints over the height of the view.
546 bool test_repaint_;
547
548 // If true and test_repaint_ is true as well, pixel dump will be produced as
549 // a series of 1px-wide, view-tall paints across the width of the view.
550 bool sweep_horizontally_;
551
[email protected]97f9a7952014-03-14 11:50:33552 std::set<std::string> http_headers_to_clear_;
Dominic Farolinoaee9c1b82019-12-18 03:20:10553 bool clear_referrer_ = false;
[email protected]97f9a7952014-03-14 11:50:33554
555 // WAV audio data is stored here.
556 std::vector<unsigned char> audio_data_;
557
[email protected]79ecada2014-05-04 05:16:16558 TestInterfaces* test_interfaces_;
danakj3130f122019-07-16 17:49:47559 WebTestDelegate* delegate_ = nullptr;
560 blink::WebView* main_view_ = nullptr;
[email protected]97f9a7952014-03-14 11:50:33561
arthursonzognid409c252019-03-14 09:22:22562 // This is non empty when a load is in progress.
563 std::vector<blink::WebFrame*> loading_frames_;
danakj3130f122019-07-16 17:49:47564 // When a loading task is started, this bool is set until all loading_frames_
565 // are completed and removed. This bool becomes true earlier than
566 // loading_frames_ becomes non-empty. Starts as true for the initial load
567 // which does not come from the WorkQueue.
568 bool running_load_ = true;
569 // When NotifyDone() occurs, if loading is still working, it is delayed, and
570 // this bool tracks that NotifyDone() was called. This differentiates from a
571 // test that was not waiting for NotifyDone() at all.
572 bool did_notify_done_ = false;
[email protected]97f9a7952014-03-14 11:50:33573
mlamouri007f9d72015-02-27 16:27:25574 // WebContentSettingsClient mock object.
dcheng82beb4f2016-04-26 00:35:02575 std::unique_ptr<MockContentSettingsClient> mock_content_settings_client_;
[email protected]97f9a7952014-03-14 11:50:33576
danakj3130f122019-07-16 17:49:47577 bool use_mock_theme_ = false;
[email protected]97f9a7952014-03-14 11:50:33578
danakj3130f122019-07-16 17:49:47579 MockScreenOrientationClient mock_screen_orientation_client_;
dcheng82beb4f2016-04-26 00:35:02580 std::unique_ptr<SpellCheckClient> spellcheck_;
lukaszafd124602016-04-01 16:53:30581
582 // Number of currently active color choosers.
danakj3130f122019-07-16 17:49:47583 int chooser_count_ = 0;
lukasza6a113ae12016-03-17 22:41:20584
lukasza1b546c12016-04-04 16:19:20585 // Captured drag image.
danakj0c75ad82018-07-10 19:50:12586 SkBitmap drag_image_;
lukasza1b546c12016-04-04 16:19:20587
lukasza95416be142016-04-14 15:06:33588 // View that was focused by a previous call to TestRunner::SetFocus method.
589 // Note - this can be a dangling pointer to an already destroyed WebView (this
590 // is ok, because this is taken care of in WebTestDelegate::SetFocus).
danakj3130f122019-07-16 17:49:47591 blink::WebView* previously_focused_view_ = nullptr;
lukasza95416be142016-04-14 15:06:33592
Kent Tamurafde0e4e2018-11-26 08:27:00593 // True when running a test in web_tests/external/wpt/.
danakj3130f122019-07-16 17:49:47594 bool is_web_platform_tests_mode_ = false;
tkent003403482016-05-26 08:18:41595
Mason Freedb0855622018-10-02 17:49:47596 // True if rasterization should be performed during tests that examine
597 // fling-style animations. This includes middle-click auto-scroll behaviors.
598 // This does not include most "ordinary" animations, such as CSS animations.
danakj3130f122019-07-16 17:49:47599 bool animation_requires_raster_ = false;
Mason Freedb0855622018-10-02 17:49:47600
Kent Tamura21d1de62018-12-10 04:45:20601 // An effective connection type settable by web tests.
danakj3130f122019-07-16 17:49:47602 blink::WebEffectiveConnectionType effective_connection_type_ =
603 blink::WebEffectiveConnectionType::kTypeUnknown;
jkarlin3bddb7d2016-09-21 18:44:16604
pfeldman4c4133d2016-12-20 02:40:21605 // Forces v8 compilation cache to be disabled (used for inspector tests).
606 bool disable_v8_cache_ = false;
607
Jeremy Roman3bca4bf2019-07-11 03:41:25608 base::WeakPtrFactory<TestRunner> weak_factory_{this};
[email protected]97f9a7952014-03-14 11:50:33609
610 DISALLOW_COPY_AND_ASSIGN(TestRunner);
611};
612
jochenf5f31752015-06-03 12:06:34613} // namespace test_runner
[email protected]97f9a7952014-03-14 11:50:33614
Scott Violetfdda96d2018-07-27 20:17:23615#endif // CONTENT_SHELL_TEST_RUNNER_TEST_RUNNER_H_