blob: cbdce2116131d41312a1c186f85a6e96c21c5172 [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"
25#include "third_party/blink/public/platform/web_image.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:4829class SkBitmap;
30
[email protected]97f9a7952014-03-14 11:50:3331namespace blink {
mlamouri007f9d72015-02-27 16:27:2532class WebContentSettingsClient;
[email protected]97f9a7952014-03-14 11:50:3333class WebFrame;
lukaszab2ad0502016-04-27 15:51:4234class WebLocalFrame;
[email protected]97f9a7952014-03-14 11:50:3335class WebString;
36class WebView;
Scott Violetfdda96d2018-07-27 20:17:2337}
[email protected]97f9a7952014-03-14 11:50:3338
39namespace gin {
40class ArrayBufferView;
41class Arguments;
Scott Violetfdda96d2018-07-27 20:17:2342}
[email protected]97f9a7952014-03-14 11:50:3343
jochenf5f31752015-06-03 12:06:3444namespace test_runner {
lukasza21353232016-04-12 19:52:1145class MockContentSettingsClient;
lukasza6a113ae12016-03-17 22:41:2046class MockScreenOrientationClient;
lukasza5c2279c2016-04-05 16:44:4747class SpellCheckClient;
[email protected]79ecada2014-05-04 05:16:1648class TestInterfaces;
lukaszab2ad0502016-04-27 15:51:4249class TestRunnerForSpecificView;
[email protected]79ecada2014-05-04 05:16:1650class WebTestDelegate;
[email protected]97f9a7952014-03-14 11:50:3351
lukaszab2ad0502016-04-27 15:51:4252// TestRunner class currently has dual purpose:
53// 1. It implements |testRunner| javascript bindings for "global" / "ambient".
54// Examples:
55// - testRunner.dumpAsText (test flag affecting test behavior)
carlosk5f1c5172016-09-08 18:59:3156// - testRunner.setAllowRunningOfInsecureContent (test flag affecting product
lukaszab2ad0502016-04-27 15:51:4257// behavior)
58// - testRunner.setTextSubpixelPositioning (directly interacts with product).
59// Note that "per-view" (non-"global") bindings are handled by
60// instances of TestRunnerForSpecificView class.
61// 2. It manages global test state. Example:
62// - Tracking topLoadingFrame that can finish the test when it loads.
63// - WorkQueue holding load requests from the TestInterfaces
Kent Tamura21d1de62018-12-10 04:45:2064// - WebTestRuntimeFlags
lukaszac9358822016-04-07 14:43:4665class TestRunner : public WebTestRunner {
[email protected]97f9a7952014-03-14 11:50:3366 public:
[email protected]79ecada2014-05-04 05:16:1667 explicit TestRunner(TestInterfaces*);
[email protected]97f9a7952014-03-14 11:50:3368 virtual ~TestRunner();
69
lukaszab2ad0502016-04-27 15:51:4270 void Install(blink::WebLocalFrame* frame,
71 base::WeakPtr<TestRunnerForSpecificView> view_test_runner);
[email protected]97f9a7952014-03-14 11:50:3372
[email protected]79ecada2014-05-04 05:16:1673 void SetDelegate(WebTestDelegate*);
lukasza8973c522016-04-27 16:32:2874 void SetMainView(blink::WebView*);
[email protected]97f9a7952014-03-14 11:50:3375
76 void Reset();
77
[email protected]97f9a7952014-03-14 11:50:3378 void SetTestIsRunning(bool);
79 bool TestIsRunning() const { return test_is_running_; }
80
danakj3130f122019-07-16 17:49:4781 // Finishes the test if it is ready. This should be called before running
82 // tasks that will change state, so that the test can capture the current
83 // state. Specifically, should run before the BeginMainFrame step which does
84 // layout and animation etc.
85 // This does *not* run as part of loading finishing because that happens in
86 // the middle of blink call stacks that have inconsistent state.
87 void FinishTestIfReady();
88
[email protected]97f9a7952014-03-14 11:50:3389 bool UseMockTheme() const { return use_mock_theme_; }
90
91 // WebTestRunner implementation.
dchenge933b3e2014-10-21 11:44:0992 bool ShouldGeneratePixelResults() override;
93 bool ShouldDumpAsAudio() const override;
94 void GetAudioData(std::vector<unsigned char>* buffer_view) const override;
lukaszaef264fc52016-03-17 22:49:1995 bool IsRecursiveLayoutDumpRequested() override;
96 std::string DumpLayout(blink::WebLocalFrame* frame) override;
Mason Freed75453ec2018-08-27 17:11:2397 bool ShouldDumpSelectionRect() const override;
danakje73c9cd2019-04-16 16:29:3398 bool CanDumpPixelsFromRenderer() const override;
99 void DumpPixelsAsync(
danakjda15621e2019-04-05 20:34:43100 content::RenderView* render_view,
lukasza20971a62017-07-12 01:31:27101 base::OnceCallback<void(const SkBitmap&)> callback) override;
Kent Tamura679c7c42018-12-05 03:21:10102 void ReplicateWebTestRuntimeFlagsChanges(
lukaszac9cbe712016-03-14 14:06:43103 const base::DictionaryValue& changed_values) override;
lukaszaa8960462016-01-27 22:27:33104 bool HasCustomTextDump(std::string* custom_text_dump) const override;
dchenge933b3e2014-10-21 11:44:09105 bool ShouldDumpBackForwardList() const override;
mlamouri007f9d72015-02-27 16:27:25106 blink::WebContentSettingsClient* GetWebContentSettings() const override;
xiaochengh81bfb17412017-04-06 17:54:33107 blink::WebTextCheckClient* GetWebTextCheckClient() const override;
lukasza95416be142016-04-14 15:06:33108 void SetFocus(blink::WebView* web_view, bool focus) override;
[email protected]97f9a7952014-03-14 11:50:33109
lukasza01da2602016-04-05 14:51:26110 // Methods used by WebViewTestClient and WebFrameTestClient.
lukaszaa0b624a2016-04-04 15:00:49111 std::string GetAcceptLanguages() const;
lukaszae26c3d62016-03-14 23:30:59112 bool shouldStayOnPageAfterHandlingBeforeUnload() const;
lukasza6a113ae12016-03-17 22:41:20113 MockScreenOrientationClient* getMockScreenOrientationClient();
[email protected]97f9a7952014-03-14 11:50:33114 bool isPrinting() const;
[email protected]f24836a2014-05-06 01:02:44115 bool shouldDumpAsCustomText() const;
dcheng59826e32017-02-22 10:31:36116 std::string customDumpText() const;
abhishek.a21ca9b5602014-09-19 07:33:33117 void ShowDevTools(const std::string& settings,
[email protected]06c253012014-04-16 18:35:33118 const std::string& frontend_url);
pfeldman4c4133d2016-12-20 02:40:21119 void SetV8CacheDisabled(bool);
[email protected]97f9a7952014-03-14 11:50:33120 void setShouldDumpAsText(bool);
121 void setShouldDumpAsMarkup(bool);
Xianzhu Wang6e84f0992018-10-23 23:07:55122 void setShouldDumpAsLayout(bool);
ki.stfu939799a42015-09-28 04:41:20123 void setCustomTextOutput(const std::string& text);
[email protected]97f9a7952014-03-14 11:50:33124 void setShouldGeneratePixelResults(bool);
125 void setShouldDumpFrameLoadCallbacks(bool);
[email protected]97f9a7952014-03-14 11:50:33126 void setShouldEnableViewSource(bool);
127 bool shouldDumpEditingCallbacks() const;
128 bool shouldDumpFrameLoadCallbacks() const;
129 bool shouldDumpPingLoaderCallbacks() const;
130 bool shouldDumpUserGestureInFrameLoadCallbacks() const;
131 bool shouldDumpTitleChanges() const;
132 bool shouldDumpIconChanges() const;
133 bool shouldDumpCreateView() const;
134 bool canOpenWindows() const;
135 bool shouldDumpResourceLoadCallbacks() const;
[email protected]97f9a7952014-03-14 11:50:33136 bool shouldDumpSpellCheckCallbacks() const;
[email protected]a79cb9912014-04-26 22:07:33137 bool shouldWaitUntilExternalURLLoad() const;
[email protected]97f9a7952014-03-14 11:50:33138 const std::set<std::string>* httpHeadersToClear() const;
tkent2edc979d2016-05-27 04:58:25139 bool is_web_platform_tests_mode() const {
140 return is_web_platform_tests_mode_;
141 }
142 void set_is_web_platform_tests_mode() { is_web_platform_tests_mode_ = true; }
Mason Freedb0855622018-10-02 17:49:47143 bool animation_requires_raster() const { return animation_requires_raster_; }
144 void SetAnimationRequiresRaster(bool do_raster);
lukasza10cd8762016-04-27 20:03:02145
arthursonzognid409c252019-03-14 09:22:22146 // Add |frame| to the set of loading frames.
147 //
148 // Note: Only one renderer process is really tracking the loading frames. This
149 // is the first to observe one. Both local and remote frames are tracked
150 // by this process.
151 void AddLoadingFrame(blink::WebFrame* frame);
lukasza10cd8762016-04-27 20:03:02152
arthursonzognid409c252019-03-14 09:22:22153 // Remove |frame| from the set of loading frames.
154 //
155 // When there are no more loading frames, this potentially finishes the test,
156 // unless testRunner.waitUntilDone() was called and/or there are pending load
157 // requests in WorkQueue.
158 void RemoveLoadingFrame(blink::WebFrame* frame);
lukasza10cd8762016-04-27 20:03:02159
danakj3130f122019-07-16 17:49:47160 blink::WebFrame* MainFrame() const;
[email protected]97f9a7952014-03-14 11:50:33161 void policyDelegateDone();
162 bool policyDelegateEnabled() const;
163 bool policyDelegateIsPermissive() const;
164 bool policyDelegateShouldNotifyDone() const;
[email protected]97f9a7952014-03-14 11:50:33165 void setToolTipText(const blink::WebString&);
danakj0c75ad82018-07-10 19:50:12166 void setDragImage(const SkBitmap& drag_image);
jochenc3a98da12015-03-10 13:59:58167 bool shouldDumpNavigationPolicy() const;
[email protected]97f9a7952014-03-14 11:50:33168
caseqcb2227832016-05-24 18:52:04169 bool ShouldDumpConsoleMessages() const;
Yoichi Osatoebf845ac72018-08-30 08:13:50170 // Controls whether console messages produced by the page are dumped
171 // to test output.
172 void SetDumpConsoleMessages(bool value);
173
tkent217ff8852016-11-14 04:43:49174 bool ShouldDumpJavaScriptDialogs() const;
caseqcb2227832016-05-24 18:52:04175
jkarlin3bddb7d2016-09-21 18:44:16176 blink::WebEffectiveConnectionType effective_connection_type() const {
177 return effective_connection_type_;
178 }
179
[email protected]97f9a7952014-03-14 11:50:33180 // A single item in the work queue.
181 class WorkItem {
182 public:
183 virtual ~WorkItem() {}
184
185 // Returns true if this started a load.
[email protected]79ecada2014-05-04 05:16:16186 virtual bool Run(WebTestDelegate*, blink::WebView*) = 0;
[email protected]97f9a7952014-03-14 11:50:33187 };
188
189 private:
[email protected]97f9a7952014-03-14 11:50:33190 friend class TestRunnerBindings;
191 friend class WorkQueue;
192
193 // Helper class for managing events queued by methods like queueLoad or
194 // queueScript.
195 class WorkQueue {
196 public:
197 explicit WorkQueue(TestRunner* controller);
198 virtual ~WorkQueue();
199 void ProcessWorkSoon();
200
201 // Reset the state of the class between tests.
202 void Reset();
203
204 void AddWork(WorkItem*);
205
206 void set_frozen(bool frozen) { frozen_ = frozen; }
danakj3130f122019-07-16 17:49:47207 bool is_empty() const { return queue_.empty(); }
208
209 void set_finished_loading() { finished_loading_ = true; }
[email protected]97f9a7952014-03-14 11:50:33210
211 private:
212 void ProcessWork();
213
Brett Wilsoncc8623d2017-09-12 03:28:10214 base::circular_deque<WorkItem*> queue_;
danakj3130f122019-07-16 17:49:47215 bool frozen_ = false;
216 bool finished_loading_ = false;
[email protected]97f9a7952014-03-14 11:50:33217 TestRunner* controller_;
lukaszac9358822016-04-07 14:43:46218
Jeremy Roman3bca4bf2019-07-11 03:41:25219 base::WeakPtrFactory<WorkQueue> weak_factory_{this};
[email protected]97f9a7952014-03-14 11:50:33220 };
221
222 ///////////////////////////////////////////////////////////////////////////
223 // Methods dealing with the test logic
224
225 // By default, tests end when page load is complete. These methods are used
226 // to delay the completion of the test until notifyDone is called.
227 void NotifyDone();
228 void WaitUntilDone();
229
230 // Methods for adding actions to the work queue. Used in conjunction with
231 // waitUntilDone/notifyDone above.
232 void QueueBackNavigation(int how_far_back);
233 void QueueForwardNavigation(int how_far_forward);
234 void QueueReload();
235 void QueueLoadingScript(const std::string& script);
236 void QueueNonLoadingScript(const std::string& script);
237 void QueueLoad(const std::string& url, const std::string& target);
[email protected]97f9a7952014-03-14 11:50:33238
239 // Causes navigation actions just printout the intended navigation instead
240 // of taking you to the page. This is used for cases like mailto, where you
241 // don't actually want to open the mail program.
242 void SetCustomPolicyDelegate(gin::Arguments* args);
243
244 // Delays completion of the test until the policy delegate runs.
245 void WaitForPolicyDelegate();
246
247 // Functions for dealing with windows. By default we block all new windows.
248 int WindowCount();
249 void SetCloseRemainingWindowsWhenComplete(bool close_remaining_windows);
250 void ResetTestHelperControllers();
251
Kent Tamura21d1de62018-12-10 04:45:20252 // Allows web tests to manage origins' allow list.
Takashi Toyoshima66e7d0d2018-08-28 09:20:10253 void AddOriginAccessAllowListEntry(const std::string& source_origin,
[email protected]97f9a7952014-03-14 11:50:33254 const std::string& destination_protocol,
255 const std::string& destination_host,
256 bool allow_destination_subdomains);
[email protected]97f9a7952014-03-14 11:50:33257
dcheng9000dbd2015-04-03 05:39:40258 // Add |source_code| as an injected stylesheet to the active document of the
259 // window of the current V8 context.
260 void InsertStyleSheet(const std::string& source_code);
261
[email protected]97f9a7952014-03-14 11:50:33262 // Enables or disables subpixel positioning (i.e. fractional X positions for
263 // glyphs) in text rendering on Linux. Since this method changes global
264 // settings, tests that call it must use their own custom font family for
265 // all text that they render. If not, an already-cached style will be used,
266 // resulting in the changed setting being ignored.
267 void SetTextSubpixelPositioning(bool value);
268
[email protected]97f9a7952014-03-14 11:50:33269 // After this function is called, all window-sizing machinery is
270 // short-circuited inside the renderer. This mode is necessary for
271 // some tests that were written before browsers had multi-process architecture
272 // and rely on window resizes to happen synchronously.
273 // The function has "unfortunate" it its name because we must strive to remove
274 // all tests that rely on this... well, unfortunate behavior. See
275 // http://crbug.com/309760 for the plan.
276 void UseUnfortunateSynchronousResizeMode();
277
278 bool EnableAutoResizeMode(int min_width,
279 int min_height,
280 int max_width,
281 int max_height);
282 bool DisableAutoResizeMode(int new_width, int new_height);
283
[email protected]e0bc2cb2014-03-20 17:34:24284 void SetMockScreenOrientation(const std::string& orientation);
dgozman3c16f7f2016-02-26 01:21:18285 void DisableMockScreenOrientation();
[email protected]e0bc2cb2014-03-20 17:34:24286
[email protected]97f9a7952014-03-14 11:50:33287 ///////////////////////////////////////////////////////////////////////////
288 // Methods modifying WebPreferences.
289
290 // Set the WebPreference that controls webkit's popup blocking.
291 void SetPopupBlockingEnabled(bool block_popups);
292
293 void SetJavaScriptCanAccessClipboard(bool can_access);
294 void SetXSSAuditorEnabled(bool enabled);
[email protected]97f9a7952014-03-14 11:50:33295 void SetAllowFileAccessFromFileURLs(bool allow);
Dan Elphick382a5962018-07-27 13:34:04296 void OverridePreference(gin::Arguments* arguments);
[email protected]97f9a7952014-03-14 11:50:33297
Leon Hanc819dc62019-01-28 04:30:19298 // Modify accept_languages in blink::mojom::RendererPreferences.
[email protected]ebd5ea52014-05-28 14:51:15299 void SetAcceptLanguages(const std::string& accept_languages);
300
[email protected]97f9a7952014-03-14 11:50:33301 // Enable or disable plugins.
302 void SetPluginsEnabled(bool enabled);
303
304 ///////////////////////////////////////////////////////////////////////////
305 // Methods that modify the state of TestRunner
306
Xianzhu Wang8d64fc32018-10-15 02:26:53307 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33308 // descriptive text for each editing command. It takes no arguments, and
309 // ignores any that may be present.
310 void DumpEditingCallbacks();
311
Xianzhu Wang6e84f0992018-10-23 23:07:55312 // This function sets a flag that tells the test runner to dump pages as
313 // plain text. The pixel results will not be generated for this test.
314 // It has higher priority than DumpAsMarkup() and DumpAsLayout().
[email protected]97f9a7952014-03-14 11:50:33315 void DumpAsText();
316
Xianzhu Wang8d64fc32018-10-15 02:26:53317 // This function sets a flag that tells the test runner to dump pages as
[email protected]fdc433c02014-06-02 19:27:14318 // the DOM contents, rather than as a text representation of the renderer's
Xianzhu Wang6e84f0992018-10-23 23:07:55319 // state. The pixel results will not be generated for this test. It has
320 // higher priority than DumpAsLayout(), but lower than DumpAsText().
[email protected]fdc433c02014-06-02 19:27:14321 void DumpAsMarkup();
322
Xianzhu Wang6e84f0992018-10-23 23:07:55323 // This function sets a flag that tells the test runner to dump pages as
324 // plain text. It will also generate a pixel dump for the test.
[email protected]97f9a7952014-03-14 11:50:33325 void DumpAsTextWithPixelResults();
326
Xianzhu Wang6e84f0992018-10-23 23:07:55327 // This function sets a flag that tells the test runner to dump pages as
328 // text representation of the layout. The pixel results will not be generated
329 // for this test. It has lower priority than DumpAsText() and DumpAsMarkup().
330 void DumpAsLayout();
331
332 // This function sets a flag that tells the test runner to dump pages as
333 // text representation of the layout. It will also generate a pixel dump for
334 // the test.
335 void DumpAsLayoutWithPixelResults();
336
Xianzhu Wang8d64fc32018-10-15 02:26:53337 // This function sets a flag that tells the test runner to recursively dump
Xianzhu Wang6e84f0992018-10-23 23:07:55338 // all frames as text, markup or layout depending on which of DumpAsText,
339 // DumpAsMarkup and DumpAsLayout is effective.
Xianzhu Wang8d64fc32018-10-15 02:26:53340 void DumpChildFrames();
[email protected]97f9a7952014-03-14 11:50:33341
Xianzhu Wang8d64fc32018-10-15 02:26:53342 // This function sets a flag that tells the test runner to print out the
[email protected]97f9a7952014-03-14 11:50:33343 // information about icon changes notifications from WebKit.
344 void DumpIconChanges();
345
346 // Deals with Web Audio WAV file data.
347 void SetAudioData(const gin::ArrayBufferView& view);
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 frame load callback. It takes no arguments, and
351 // ignores any that may be present.
352 void DumpFrameLoadCallbacks();
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 // descriptive text for each PingLoader dispatch. It takes no arguments, and
356 // ignores any that may be present.
357 void DumpPingLoaderCallbacks();
358
Xianzhu Wang8d64fc32018-10-15 02:26:53359 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33360 // user gesture status text for some frame load callbacks. It takes no
361 // arguments, and ignores any that may be present.
362 void DumpUserGestureInFrameLoadCallbacks();
363
364 void DumpTitleChanges();
365
Xianzhu Wang8d64fc32018-10-15 02:26:53366 // This function sets a flag that tells the test runner to dump all calls to
[email protected]97f9a7952014-03-14 11:50:33367 // WebViewClient::createView().
368 // It takes no arguments, and ignores any that may be present.
369 void DumpCreateView();
370
371 void SetCanOpenWindows();
372
Xianzhu Wang8d64fc32018-10-15 02:26:53373 // This function sets a flag that tells the test runner to dump a descriptive
[email protected]97f9a7952014-03-14 11:50:33374 // line for each resource load callback. It takes no arguments, and ignores
375 // any that may be present.
376 void DumpResourceLoadCallbacks();
377
Xianzhu Wang8d64fc32018-10-15 02:26:53378 // This function sets a flag that tells the test runner to dump the MIME type
[email protected]97f9a7952014-03-14 11:50:33379 // for each resource that was loaded. It takes no arguments, and ignores any
380 // that may be present.
381 void DumpResourceResponseMIMETypes();
382
mlamouri007f9d72015-02-27 16:27:25383 // WebContentSettingsClient related.
[email protected]97f9a7952014-03-14 11:50:33384 void SetImagesAllowed(bool allowed);
385 void SetScriptsAllowed(bool allowed);
386 void SetStorageAllowed(bool allowed);
387 void SetPluginsAllowed(bool allowed);
[email protected]97f9a7952014-03-14 11:50:33388 void SetAllowRunningOfInsecureContent(bool allowed);
mlamouri426f2862016-04-29 18:35:01389 void SetAutoplayAllowed(bool allowed);
[email protected]97f9a7952014-03-14 11:50:33390 void DumpPermissionClientCallbacks();
391
engedy9ae04242016-06-08 13:31:18392 // Sets up a mock DocumentSubresourceFilter to disallow subsequent subresource
393 // loads within the current document with the given path |suffixes|. The
394 // filter is created and injected even if |suffixes| is empty. If |suffixes|
John Delaney096b7a72019-01-18 18:43:24395 // contains the empty string, all subresource loads will be disallowed. If
396 // |block_subresources| is false, matching resources will not be blocked but
397 // instead marked as matching a disallowed resource.
engedy9ae04242016-06-08 13:31:18398 void SetDisallowedSubresourcePathSuffixes(
John Delaney096b7a72019-01-18 18:43:24399 const std::vector<std::string>& suffixes,
400 bool block_subresources);
engedy9ae04242016-06-08 13:31:18401
Xianzhu Wang8d64fc32018-10-15 02:26:53402 // This function sets a flag that tells the test runner to dump all
[email protected]97f9a7952014-03-14 11:50:33403 // the lines of descriptive text about spellcheck execution.
404 void DumpSpellCheckCallbacks();
405
Xianzhu Wang8d64fc32018-10-15 02:26:53406 // This function sets a flag that tells the test runner to print out a text
[email protected]97f9a7952014-03-14 11:50:33407 // representation of the back/forward list. It ignores all arguments.
408 void DumpBackForwardList();
409
410 void DumpSelectionRect();
[email protected]97f9a7952014-03-14 11:50:33411
412 // Causes layout to happen as if targetted to printed pages.
413 void SetPrinting();
Xianzhu Wangdbb84fc2018-02-03 00:33:35414 void SetPrintingForFrame(const std::string& frame_name);
[email protected]97f9a7952014-03-14 11:50:33415
[email protected]52846102014-06-24 04:26:44416 // Clears the state from SetPrinting().
417 void ClearPrinting();
418
[email protected]97f9a7952014-03-14 11:50:33419 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
420
421 // Causes WillSendRequest to clear certain headers.
422 void SetWillSendRequestClearHeader(const std::string& header);
423
[email protected]97f9a7952014-03-14 11:50:33424 // Sets a flag to enable the mock theme.
425 void SetUseMockTheme(bool use);
426
[email protected]a79cb9912014-04-26 22:07:33427 // Sets a flag that causes the test to be marked as completed when the
Mustaq Ahmed55944cb2018-05-25 20:44:27428 // WebLocalFrameClient receives a loadURLExternally() call.
[email protected]a79cb9912014-04-26 22:07:33429 void WaitUntilExternalURLLoad();
430
lukasza1b546c12016-04-04 16:19:20431 // This function sets a flag to dump the drag image when the next drag&drop is
432 // initiated. It is equivalent to DumpAsTextWithPixelResults but the pixel
433 // results will be the drag image instead of a snapshot of the page.
jackhou656fc852015-02-13 09:04:17434 void DumpDragImage();
435
lfg05e41372016-07-22 15:38:10436 // Sets a flag that tells the WebViewTestProxy to dump the default navigation
jochenc3a98da12015-03-10 13:59:58437 // policy passed to the decidePolicyForNavigation callback.
438 void DumpNavigationPolicy();
439
tkent217ff8852016-11-14 04:43:49440 // Controls whether JavaScript dialogs such as alert() are dumped to test
441 // output.
442 void SetDumpJavaScriptDialogs(bool value);
443
jkarlin3bddb7d2016-09-21 18:44:16444 // Overrides the NetworkQualityEstimator's estimated network type. If |type|
445 // is TypeUnknown the NQE's value is used. Be sure to call this with
446 // TypeUnknown at the end of your test if you use this.
447 void SetEffectiveConnectionType(
448 blink::WebEffectiveConnectionType connection_type);
449
xiaochengh2fa3e762016-08-24 11:27:04450 // Controls whether the mock spell checker is enabled.
451 void SetMockSpellCheckerEnabled(bool enabled);
452
[email protected]97f9a7952014-03-14 11:50:33453 ///////////////////////////////////////////////////////////////////////////
lfg05e41372016-07-22 15:38:10454 // Methods interacting with the WebViewTestProxy
[email protected]97f9a7952014-03-14 11:50:33455
456 ///////////////////////////////////////////////////////////////////////////
457 // Methods forwarding to the WebTestDelegate
458
459 // Shows DevTools window.
[email protected]06c253012014-04-16 18:35:33460 void ShowWebInspector(const std::string& str,
461 const std::string& frontend_url);
[email protected]97f9a7952014-03-14 11:50:33462 void CloseWebInspector();
463
Will Chen8bbdf20f2017-12-12 21:09:54464 void NavigateSecondaryWindow(const GURL& url);
465 void InspectSecondaryWindow();
466
[email protected]97f9a7952014-03-14 11:50:33467 // Inspect chooser state
468 bool IsChooserShown();
469
Kent Tamura21d1de62018-12-10 04:45:20470 // Allows web tests to exec scripts at WebInspector side.
[email protected]97f9a7952014-03-14 11:50:33471 void EvaluateInWebInspector(int call_id, const std::string& script);
472
473 // Clears all databases.
474 void ClearAllDatabases();
475 // Sets the default quota for all origins
476 void SetDatabaseQuota(int quota);
477
tyoshinoa6b91462016-07-11 09:15:09478 // Sets the cookie policy to:
479 // - allow all cookies when |block| is false
480 // - block only third-party cookies when |block| is true
481 void SetBlockThirdPartyCookies(bool block);
[email protected]97f9a7952014-03-14 11:50:33482
[email protected]97f9a7952014-03-14 11:50:33483 // Converts a URL starting with file:///tmp/ to the local mapping.
484 std::string PathToLocalResource(const std::string& path);
485
mlamourid5098d02015-04-21 12:17:30486 // Sets the permission's |name| to |value| for a given {origin, embedder}
487 // tuple.
488 void SetPermission(const std::string& name,
489 const std::string& value,
490 const GURL& origin,
491 const GURL& embedding_origin);
492
dominickn09f7b572016-10-28 01:44:15493 // Resolve the in-flight beforeinstallprompt event.
494 void ResolveBeforeInstallPromptPromise(const std::string& platform);
benwells0c0d3f12015-05-25 01:03:17495
[email protected]97f9a7952014-03-14 11:50:33496 // Calls setlocale(LC_ALL, ...) for a specified locale.
497 // Resets between tests.
498 void SetPOSIXLocale(const std::string& locale);
499
peterd98157d2014-11-20 13:15:01500 // Simulates a click on a Web Notification.
Peter Beverloo988ef962017-09-12 15:49:17501 void SimulateWebNotificationClick(
502 const std::string& title,
503 const base::Optional<int>& action_index,
504 const base::Optional<base::string16>& reply);
[email protected]97f9a7952014-03-14 11:50:33505
nsatragno24bd34b2016-02-09 10:30:02506 // Simulates closing a Web Notification.
507 void SimulateWebNotificationClose(const std::string& title, bool by_user);
508
Rayan Kansob7bef392019-07-25 12:32:36509 // Simulates a user deleting a content index entry.
510 void SimulateWebContentIndexDelete(const std::string& id);
511
Kent Tamura2eab5b12018-12-07 04:31:23512 // Takes care of notifying the delegate after a change to web test runtime
lukasza083b4f12016-03-24 16:51:43513 // flags.
Kent Tamura2eab5b12018-12-07 04:31:23514 void OnWebTestRuntimeFlagsChanged();
lukaszac9cbe712016-03-14 14:06:43515
[email protected]97f9a7952014-03-14 11:50:33516 ///////////////////////////////////////////////////////////////////////////
517 // Internal helpers
[email protected]eec9e78e2014-06-16 21:38:48518
lukasza10cd8762016-04-27 20:03:02519 bool IsFramePartOfMainTestWindow(blink::WebFrame*) const;
520
[email protected]97f9a7952014-03-14 11:50:33521 void CheckResponseMimeType();
[email protected]97f9a7952014-03-14 11:50:33522
danakj3130f122019-07-16 17:49:47523 bool test_is_running_ = false;
[email protected]97f9a7952014-03-14 11:50:33524
525 // When reset is called, go through and close all but the main test shell
526 // window. By default, set to true but toggled to false using
527 // setCloseRemainingWindowsWhenComplete().
danakj3130f122019-07-16 17:49:47528 bool close_remaining_windows_ = false;
[email protected]97f9a7952014-03-14 11:50:33529
[email protected]97f9a7952014-03-14 11:50:33530 WorkQueue work_queue_;
531
[email protected]97f9a7952014-03-14 11:50:33532 // Bound variable to return the name of this platform (chromium).
533 std::string platform_name_;
534
535 // Bound variable to store the last tooltip text
536 std::string tooltip_text_;
537
[email protected]97f9a7952014-03-14 11:50:33538 // Bound variable counting the number of top URLs visited.
danakj3130f122019-07-16 17:49:47539 int web_history_item_count_ = 0;
[email protected]97f9a7952014-03-14 11:50:33540
lukasza9b9d70e2016-02-25 23:45:44541 // Flags controlling what content gets dumped as a layout text result.
Kent Tamura2eab5b12018-12-07 04:31:23542 WebTestRuntimeFlags web_test_runtime_flags_;
[email protected]97f9a7952014-03-14 11:50:33543
Xianzhu Wang8d64fc32018-10-15 02:26:53544 // If true, the test runner will output a base64 encoded WAVE file.
[email protected]97f9a7952014-03-14 11:50:33545 bool dump_as_audio_;
546
Xianzhu Wang8d64fc32018-10-15 02:26:53547 // If true, the test runner will produce a dump of the back forward list as
[email protected]97f9a7952014-03-14 11:50:33548 // well.
549 bool dump_back_forward_list_;
550
[email protected]97f9a7952014-03-14 11:50:33551 // If true, pixel dump will be produced as a series of 1px-tall, view-wide
552 // individual paints over the height of the view.
553 bool test_repaint_;
554
555 // If true and test_repaint_ is true as well, pixel dump will be produced as
556 // a series of 1px-wide, view-tall paints across the width of the view.
557 bool sweep_horizontally_;
558
[email protected]97f9a7952014-03-14 11:50:33559 std::set<std::string> http_headers_to_clear_;
560
561 // WAV audio data is stored here.
562 std::vector<unsigned char> audio_data_;
563
[email protected]79ecada2014-05-04 05:16:16564 TestInterfaces* test_interfaces_;
danakj3130f122019-07-16 17:49:47565 WebTestDelegate* delegate_ = nullptr;
566 blink::WebView* main_view_ = nullptr;
[email protected]97f9a7952014-03-14 11:50:33567
arthursonzognid409c252019-03-14 09:22:22568 // This is non empty when a load is in progress.
569 std::vector<blink::WebFrame*> loading_frames_;
danakj3130f122019-07-16 17:49:47570 // When a loading task is started, this bool is set until all loading_frames_
571 // are completed and removed. This bool becomes true earlier than
572 // loading_frames_ becomes non-empty. Starts as true for the initial load
573 // which does not come from the WorkQueue.
574 bool running_load_ = true;
575 // When NotifyDone() occurs, if loading is still working, it is delayed, and
576 // this bool tracks that NotifyDone() was called. This differentiates from a
577 // test that was not waiting for NotifyDone() at all.
578 bool did_notify_done_ = false;
[email protected]97f9a7952014-03-14 11:50:33579
mlamouri007f9d72015-02-27 16:27:25580 // WebContentSettingsClient mock object.
dcheng82beb4f2016-04-26 00:35:02581 std::unique_ptr<MockContentSettingsClient> mock_content_settings_client_;
[email protected]97f9a7952014-03-14 11:50:33582
danakj3130f122019-07-16 17:49:47583 bool use_mock_theme_ = false;
[email protected]97f9a7952014-03-14 11:50:33584
danakj3130f122019-07-16 17:49:47585 MockScreenOrientationClient mock_screen_orientation_client_;
dcheng82beb4f2016-04-26 00:35:02586 std::unique_ptr<SpellCheckClient> spellcheck_;
lukaszafd124602016-04-01 16:53:30587
588 // Number of currently active color choosers.
danakj3130f122019-07-16 17:49:47589 int chooser_count_ = 0;
lukasza6a113ae12016-03-17 22:41:20590
lukasza1b546c12016-04-04 16:19:20591 // Captured drag image.
danakj0c75ad82018-07-10 19:50:12592 SkBitmap drag_image_;
lukasza1b546c12016-04-04 16:19:20593
lukasza95416be142016-04-14 15:06:33594 // View that was focused by a previous call to TestRunner::SetFocus method.
595 // Note - this can be a dangling pointer to an already destroyed WebView (this
596 // is ok, because this is taken care of in WebTestDelegate::SetFocus).
danakj3130f122019-07-16 17:49:47597 blink::WebView* previously_focused_view_ = nullptr;
lukasza95416be142016-04-14 15:06:33598
Kent Tamurafde0e4e2018-11-26 08:27:00599 // True when running a test in web_tests/external/wpt/.
danakj3130f122019-07-16 17:49:47600 bool is_web_platform_tests_mode_ = false;
tkent003403482016-05-26 08:18:41601
Mason Freedb0855622018-10-02 17:49:47602 // True if rasterization should be performed during tests that examine
603 // fling-style animations. This includes middle-click auto-scroll behaviors.
604 // This does not include most "ordinary" animations, such as CSS animations.
danakj3130f122019-07-16 17:49:47605 bool animation_requires_raster_ = false;
Mason Freedb0855622018-10-02 17:49:47606
Kent Tamura21d1de62018-12-10 04:45:20607 // An effective connection type settable by web tests.
danakj3130f122019-07-16 17:49:47608 blink::WebEffectiveConnectionType effective_connection_type_ =
609 blink::WebEffectiveConnectionType::kTypeUnknown;
jkarlin3bddb7d2016-09-21 18:44:16610
pfeldman4c4133d2016-12-20 02:40:21611 // Forces v8 compilation cache to be disabled (used for inspector tests).
612 bool disable_v8_cache_ = false;
613
Jeremy Roman3bca4bf2019-07-11 03:41:25614 base::WeakPtrFactory<TestRunner> weak_factory_{this};
[email protected]97f9a7952014-03-14 11:50:33615
616 DISALLOW_COPY_AND_ASSIGN(TestRunner);
617};
618
jochenf5f31752015-06-03 12:06:34619} // namespace test_runner
[email protected]97f9a7952014-03-14 11:50:33620
Scott Violetfdda96d2018-07-27 20:17:23621#endif // CONTENT_SHELL_TEST_RUNNER_TEST_RUNNER_H_