blob: d3188717fa10220228e482135b53aed9c6b0390d [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"
Scott Violetfdda96d2018-07-27 20:17:2320#include "content/shell/test_runner/test_runner_export.h"
21#include "content/shell/test_runner/web_test_runner.h"
Kent Tamura2eab5b12018-12-07 04:31:2322#include "content/shell/test_runner/web_test_runtime_flags.h"
Blink Reformata30d4232018-04-07 15:31:0623#include "third_party/blink/public/platform/web_effective_connection_type.h"
24#include "third_party/blink/public/platform/web_image.h"
[email protected]97f9a7952014-03-14 11:50:3325#include "v8/include/v8.h"
26
[email protected]945babb2014-07-30 14:25:3227class GURL;
[email protected]eec9e78e2014-06-16 21:38:4828class SkBitmap;
29
[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 {
[email protected]97f9a7952014-03-14 11:50:3344
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
81 bool UseMockTheme() const { return use_mock_theme_; }
82
83 // WebTestRunner implementation.
dchenge933b3e2014-10-21 11:44:0984 bool ShouldGeneratePixelResults() override;
85 bool ShouldDumpAsAudio() const override;
86 void GetAudioData(std::vector<unsigned char>* buffer_view) const override;
lukaszaef264fc52016-03-17 22:49:1987 bool IsRecursiveLayoutDumpRequested() override;
88 std::string DumpLayout(blink::WebLocalFrame* frame) override;
Mason Freed75453ec2018-08-27 17:11:2389 bool ShouldDumpSelectionRect() const override;
Vladimir Levind29618c2018-04-17 21:49:0190 // Returns true if the browser should capture the pixels instead.
91 bool DumpPixelsAsync(
lukasza20971a62017-07-12 01:31:2792 blink::WebLocalFrame* frame,
93 base::OnceCallback<void(const SkBitmap&)> callback) override;
Kent Tamura679c7c42018-12-05 03:21:1094 void ReplicateWebTestRuntimeFlagsChanges(
lukaszac9cbe712016-03-14 14:06:4395 const base::DictionaryValue& changed_values) override;
lukaszaa8960462016-01-27 22:27:3396 bool HasCustomTextDump(std::string* custom_text_dump) const override;
dchenge933b3e2014-10-21 11:44:0997 bool ShouldDumpBackForwardList() const override;
mlamouri007f9d72015-02-27 16:27:2598 blink::WebContentSettingsClient* GetWebContentSettings() const override;
xiaochengh81bfb17412017-04-06 17:54:3399 blink::WebTextCheckClient* GetWebTextCheckClient() const override;
lukasza95416be142016-04-14 15:06:33100 void SetFocus(blink::WebView* web_view, bool focus) override;
[email protected]97f9a7952014-03-14 11:50:33101
lukasza01da2602016-04-05 14:51:26102 // Methods used by WebViewTestClient and WebFrameTestClient.
lukaszaa0b624a2016-04-04 15:00:49103 std::string GetAcceptLanguages() const;
lukaszae26c3d62016-03-14 23:30:59104 bool shouldStayOnPageAfterHandlingBeforeUnload() const;
lukasza6a113ae12016-03-17 22:41:20105 MockScreenOrientationClient* getMockScreenOrientationClient();
[email protected]97f9a7952014-03-14 11:50:33106 bool isPrinting() const;
[email protected]f24836a2014-05-06 01:02:44107 bool shouldDumpAsCustomText() const;
dcheng59826e32017-02-22 10:31:36108 std::string customDumpText() const;
abhishek.a21ca9b5602014-09-19 07:33:33109 void ShowDevTools(const std::string& settings,
[email protected]06c253012014-04-16 18:35:33110 const std::string& frontend_url);
pfeldman4c4133d2016-12-20 02:40:21111 void SetV8CacheDisabled(bool);
[email protected]97f9a7952014-03-14 11:50:33112 void setShouldDumpAsText(bool);
113 void setShouldDumpAsMarkup(bool);
Xianzhu Wang6e84f0992018-10-23 23:07:55114 void setShouldDumpAsLayout(bool);
ki.stfu939799a42015-09-28 04:41:20115 void setCustomTextOutput(const std::string& text);
[email protected]97f9a7952014-03-14 11:50:33116 void setShouldGeneratePixelResults(bool);
117 void setShouldDumpFrameLoadCallbacks(bool);
[email protected]97f9a7952014-03-14 11:50:33118 void setShouldEnableViewSource(bool);
119 bool shouldDumpEditingCallbacks() const;
120 bool shouldDumpFrameLoadCallbacks() const;
121 bool shouldDumpPingLoaderCallbacks() const;
122 bool shouldDumpUserGestureInFrameLoadCallbacks() const;
123 bool shouldDumpTitleChanges() const;
124 bool shouldDumpIconChanges() const;
125 bool shouldDumpCreateView() const;
126 bool canOpenWindows() const;
127 bool shouldDumpResourceLoadCallbacks() const;
[email protected]97f9a7952014-03-14 11:50:33128 bool shouldDumpResourceResponseMIMETypes() const;
[email protected]97f9a7952014-03-14 11:50:33129 bool shouldDumpSpellCheckCallbacks() const;
[email protected]a79cb9912014-04-26 22:07:33130 bool shouldWaitUntilExternalURLLoad() const;
[email protected]97f9a7952014-03-14 11:50:33131 const std::set<std::string>* httpHeadersToClear() const;
tkent2edc979d2016-05-27 04:58:25132 bool is_web_platform_tests_mode() const {
133 return is_web_platform_tests_mode_;
134 }
135 void set_is_web_platform_tests_mode() { is_web_platform_tests_mode_ = true; }
Mason Freedb0855622018-10-02 17:49:47136 bool animation_requires_raster() const { return animation_requires_raster_; }
137 void SetAnimationRequiresRaster(bool do_raster);
lukasza10cd8762016-04-27 20:03:02138
139 // To be called when |frame| starts loading - TestRunner will check if
140 // there is currently no top-loading-frame being tracked and if so, then it
141 // will return true and start tracking |frame| as the top-loading-frame.
142 bool tryToSetTopLoadingFrame(blink::WebFrame* frame);
143
144 // To be called when |frame| finishes loading - TestRunner will check if
145 // |frame| is currently tracked as the top-loading-frame, and if yes, then it
146 // will return true, stop top-loading-frame tracking, and potentially finish
147 // the test (unless testRunner.waitUntilDone() was called and/or there are
148 // pending load requests in WorkQueue).
149 bool tryToClearTopLoadingFrame(blink::WebFrame*);
150
xiaochengh5fe2c6a2016-12-20 06:11:56151 blink::WebFrame* mainFrame() const;
[email protected]97f9a7952014-03-14 11:50:33152 blink::WebFrame* topLoadingFrame() const;
153 void policyDelegateDone();
154 bool policyDelegateEnabled() const;
155 bool policyDelegateIsPermissive() const;
156 bool policyDelegateShouldNotifyDone() const;
[email protected]97f9a7952014-03-14 11:50:33157 void setToolTipText(const blink::WebString&);
danakj0c75ad82018-07-10 19:50:12158 void setDragImage(const SkBitmap& drag_image);
jochenc3a98da12015-03-10 13:59:58159 bool shouldDumpNavigationPolicy() const;
[email protected]97f9a7952014-03-14 11:50:33160
caseqcb2227832016-05-24 18:52:04161 bool ShouldDumpConsoleMessages() const;
Yoichi Osatoebf845ac72018-08-30 08:13:50162 // Controls whether console messages produced by the page are dumped
163 // to test output.
164 void SetDumpConsoleMessages(bool value);
165
tkent217ff8852016-11-14 04:43:49166 bool ShouldDumpJavaScriptDialogs() const;
caseqcb2227832016-05-24 18:52:04167
jkarlin3bddb7d2016-09-21 18:44:16168 blink::WebEffectiveConnectionType effective_connection_type() const {
169 return effective_connection_type_;
170 }
171
[email protected]97f9a7952014-03-14 11:50:33172 // A single item in the work queue.
173 class WorkItem {
174 public:
175 virtual ~WorkItem() {}
176
177 // Returns true if this started a load.
[email protected]79ecada2014-05-04 05:16:16178 virtual bool Run(WebTestDelegate*, blink::WebView*) = 0;
[email protected]97f9a7952014-03-14 11:50:33179 };
180
181 private:
[email protected]97f9a7952014-03-14 11:50:33182 friend class TestRunnerBindings;
183 friend class WorkQueue;
184
185 // Helper class for managing events queued by methods like queueLoad or
186 // queueScript.
187 class WorkQueue {
188 public:
189 explicit WorkQueue(TestRunner* controller);
190 virtual ~WorkQueue();
191 void ProcessWorkSoon();
192
193 // Reset the state of the class between tests.
194 void Reset();
195
196 void AddWork(WorkItem*);
197
198 void set_frozen(bool frozen) { frozen_ = frozen; }
199 bool is_empty() { return queue_.empty(); }
[email protected]97f9a7952014-03-14 11:50:33200
201 private:
202 void ProcessWork();
203
Brett Wilsoncc8623d2017-09-12 03:28:10204 base::circular_deque<WorkItem*> queue_;
[email protected]97f9a7952014-03-14 11:50:33205 bool frozen_;
206 TestRunner* controller_;
lukaszac9358822016-04-07 14:43:46207
208 base::WeakPtrFactory<WorkQueue> weak_factory_;
[email protected]97f9a7952014-03-14 11:50:33209 };
210
211 ///////////////////////////////////////////////////////////////////////////
212 // Methods dealing with the test logic
213
214 // By default, tests end when page load is complete. These methods are used
215 // to delay the completion of the test until notifyDone is called.
216 void NotifyDone();
217 void WaitUntilDone();
218
219 // Methods for adding actions to the work queue. Used in conjunction with
220 // waitUntilDone/notifyDone above.
221 void QueueBackNavigation(int how_far_back);
222 void QueueForwardNavigation(int how_far_forward);
223 void QueueReload();
224 void QueueLoadingScript(const std::string& script);
225 void QueueNonLoadingScript(const std::string& script);
226 void QueueLoad(const std::string& url, const std::string& target);
[email protected]97f9a7952014-03-14 11:50:33227
228 // Causes navigation actions just printout the intended navigation instead
229 // of taking you to the page. This is used for cases like mailto, where you
230 // don't actually want to open the mail program.
231 void SetCustomPolicyDelegate(gin::Arguments* args);
232
233 // Delays completion of the test until the policy delegate runs.
234 void WaitForPolicyDelegate();
235
236 // Functions for dealing with windows. By default we block all new windows.
237 int WindowCount();
238 void SetCloseRemainingWindowsWhenComplete(bool close_remaining_windows);
239 void ResetTestHelperControllers();
240
Kent Tamura21d1de62018-12-10 04:45:20241 // Allows web tests to manage origins' allow list.
Takashi Toyoshima66e7d0d2018-08-28 09:20:10242 void AddOriginAccessAllowListEntry(const std::string& source_origin,
[email protected]97f9a7952014-03-14 11:50:33243 const std::string& destination_protocol,
244 const std::string& destination_host,
245 bool allow_destination_subdomains);
[email protected]97f9a7952014-03-14 11:50:33246
dcheng9000dbd2015-04-03 05:39:40247 // Add |source_code| as an injected stylesheet to the active document of the
248 // window of the current V8 context.
249 void InsertStyleSheet(const std::string& source_code);
250
[email protected]97f9a7952014-03-14 11:50:33251 // Enables or disables subpixel positioning (i.e. fractional X positions for
252 // glyphs) in text rendering on Linux. Since this method changes global
253 // settings, tests that call it must use their own custom font family for
254 // all text that they render. If not, an already-cached style will be used,
255 // resulting in the changed setting being ignored.
256 void SetTextSubpixelPositioning(bool value);
257
[email protected]97f9a7952014-03-14 11:50:33258 // After this function is called, all window-sizing machinery is
259 // short-circuited inside the renderer. This mode is necessary for
260 // some tests that were written before browsers had multi-process architecture
261 // and rely on window resizes to happen synchronously.
262 // The function has "unfortunate" it its name because we must strive to remove
263 // all tests that rely on this... well, unfortunate behavior. See
264 // http://crbug.com/309760 for the plan.
265 void UseUnfortunateSynchronousResizeMode();
266
267 bool EnableAutoResizeMode(int min_width,
268 int min_height,
269 int max_width,
270 int max_height);
271 bool DisableAutoResizeMode(int new_width, int new_height);
272
[email protected]e0bc2cb2014-03-20 17:34:24273 void SetMockScreenOrientation(const std::string& orientation);
dgozman3c16f7f2016-02-26 01:21:18274 void DisableMockScreenOrientation();
[email protected]e0bc2cb2014-03-20 17:34:24275
[email protected]97f9a7952014-03-14 11:50:33276 ///////////////////////////////////////////////////////////////////////////
277 // Methods modifying WebPreferences.
278
279 // Set the WebPreference that controls webkit's popup blocking.
280 void SetPopupBlockingEnabled(bool block_popups);
281
282 void SetJavaScriptCanAccessClipboard(bool can_access);
283 void SetXSSAuditorEnabled(bool enabled);
284 void SetAllowUniversalAccessFromFileURLs(bool allow);
285 void SetAllowFileAccessFromFileURLs(bool allow);
Dan Elphick382a5962018-07-27 13:34:04286 void OverridePreference(gin::Arguments* arguments);
[email protected]97f9a7952014-03-14 11:50:33287
Leon Hanc819dc62019-01-28 04:30:19288 // Modify accept_languages in blink::mojom::RendererPreferences.
[email protected]ebd5ea52014-05-28 14:51:15289 void SetAcceptLanguages(const std::string& accept_languages);
290
[email protected]97f9a7952014-03-14 11:50:33291 // Enable or disable plugins.
292 void SetPluginsEnabled(bool enabled);
293
294 ///////////////////////////////////////////////////////////////////////////
295 // Methods that modify the state of TestRunner
296
Xianzhu Wang8d64fc32018-10-15 02:26:53297 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33298 // descriptive text for each editing command. It takes no arguments, and
299 // ignores any that may be present.
300 void DumpEditingCallbacks();
301
Xianzhu Wang6e84f0992018-10-23 23:07:55302 // This function sets a flag that tells the test runner to dump pages as
303 // plain text. The pixel results will not be generated for this test.
304 // It has higher priority than DumpAsMarkup() and DumpAsLayout().
[email protected]97f9a7952014-03-14 11:50:33305 void DumpAsText();
306
Xianzhu Wang8d64fc32018-10-15 02:26:53307 // This function sets a flag that tells the test runner to dump pages as
[email protected]fdc433c02014-06-02 19:27:14308 // the DOM contents, rather than as a text representation of the renderer's
Xianzhu Wang6e84f0992018-10-23 23:07:55309 // state. The pixel results will not be generated for this test. It has
310 // higher priority than DumpAsLayout(), but lower than DumpAsText().
[email protected]fdc433c02014-06-02 19:27:14311 void DumpAsMarkup();
312
Xianzhu Wang6e84f0992018-10-23 23:07:55313 // This function sets a flag that tells the test runner to dump pages as
314 // plain text. It will also generate a pixel dump for the test.
[email protected]97f9a7952014-03-14 11:50:33315 void DumpAsTextWithPixelResults();
316
Xianzhu Wang6e84f0992018-10-23 23:07:55317 // This function sets a flag that tells the test runner to dump pages as
318 // text representation of the layout. The pixel results will not be generated
319 // for this test. It has lower priority than DumpAsText() and DumpAsMarkup().
320 void DumpAsLayout();
321
322 // This function sets a flag that tells the test runner to dump pages as
323 // text representation of the layout. It will also generate a pixel dump for
324 // the test.
325 void DumpAsLayoutWithPixelResults();
326
Xianzhu Wang8d64fc32018-10-15 02:26:53327 // This function sets a flag that tells the test runner to recursively dump
Xianzhu Wang6e84f0992018-10-23 23:07:55328 // all frames as text, markup or layout depending on which of DumpAsText,
329 // DumpAsMarkup and DumpAsLayout is effective.
Xianzhu Wang8d64fc32018-10-15 02:26:53330 void DumpChildFrames();
[email protected]97f9a7952014-03-14 11:50:33331
Xianzhu Wang8d64fc32018-10-15 02:26:53332 // This function sets a flag that tells the test runner to print out the
[email protected]97f9a7952014-03-14 11:50:33333 // information about icon changes notifications from WebKit.
334 void DumpIconChanges();
335
336 // Deals with Web Audio WAV file data.
337 void SetAudioData(const gin::ArrayBufferView& view);
338
Xianzhu Wang8d64fc32018-10-15 02:26:53339 // This function sets a flag that tells the test runner to print a line of
[email protected]97f9a7952014-03-14 11:50:33340 // descriptive text for each frame load callback. It takes no arguments, and
341 // ignores any that may be present.
342 void DumpFrameLoadCallbacks();
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 PingLoader dispatch. It takes no arguments, and
346 // ignores any that may be present.
347 void DumpPingLoaderCallbacks();
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 // user gesture status text for some frame load callbacks. It takes no
351 // arguments, and ignores any that may be present.
352 void DumpUserGestureInFrameLoadCallbacks();
353
354 void DumpTitleChanges();
355
Xianzhu Wang8d64fc32018-10-15 02:26:53356 // This function sets a flag that tells the test runner to dump all calls to
[email protected]97f9a7952014-03-14 11:50:33357 // WebViewClient::createView().
358 // It takes no arguments, and ignores any that may be present.
359 void DumpCreateView();
360
361 void SetCanOpenWindows();
362
Xianzhu Wang8d64fc32018-10-15 02:26:53363 // This function sets a flag that tells the test runner to dump a descriptive
[email protected]97f9a7952014-03-14 11:50:33364 // line for each resource load callback. It takes no arguments, and ignores
365 // any that may be present.
366 void DumpResourceLoadCallbacks();
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);
mlamouri426f2862016-04-29 18:35:01379 void SetAutoplayAllowed(bool allowed);
[email protected]97f9a7952014-03-14 11:50:33380 void DumpPermissionClientCallbacks();
381
engedy9ae04242016-06-08 13:31:18382 // Sets up a mock DocumentSubresourceFilter to disallow subsequent subresource
383 // loads within the current document with the given path |suffixes|. The
384 // filter is created and injected even if |suffixes| is empty. If |suffixes|
John Delaney096b7a72019-01-18 18:43:24385 // contains the empty string, all subresource loads will be disallowed. If
386 // |block_subresources| is false, matching resources will not be blocked but
387 // instead marked as matching a disallowed resource.
engedy9ae04242016-06-08 13:31:18388 void SetDisallowedSubresourcePathSuffixes(
John Delaney096b7a72019-01-18 18:43:24389 const std::vector<std::string>& suffixes,
390 bool block_subresources);
engedy9ae04242016-06-08 13:31:18391
Xianzhu Wang8d64fc32018-10-15 02:26:53392 // This function sets a flag that tells the test runner to dump all
[email protected]97f9a7952014-03-14 11:50:33393 // the lines of descriptive text about spellcheck execution.
394 void DumpSpellCheckCallbacks();
395
Xianzhu Wang8d64fc32018-10-15 02:26:53396 // This function sets a flag that tells the test runner to print out a text
[email protected]97f9a7952014-03-14 11:50:33397 // representation of the back/forward list. It ignores all arguments.
398 void DumpBackForwardList();
399
400 void DumpSelectionRect();
[email protected]97f9a7952014-03-14 11:50:33401
402 // Causes layout to happen as if targetted to printed pages.
403 void SetPrinting();
Xianzhu Wangdbb84fc2018-02-03 00:33:35404 void SetPrintingForFrame(const std::string& frame_name);
[email protected]97f9a7952014-03-14 11:50:33405
[email protected]52846102014-06-24 04:26:44406 // Clears the state from SetPrinting().
407 void ClearPrinting();
408
[email protected]97f9a7952014-03-14 11:50:33409 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
410
411 // Causes WillSendRequest to clear certain headers.
412 void SetWillSendRequestClearHeader(const std::string& header);
413
[email protected]97f9a7952014-03-14 11:50:33414 // Sets a flag to enable the mock theme.
415 void SetUseMockTheme(bool use);
416
[email protected]a79cb9912014-04-26 22:07:33417 // Sets a flag that causes the test to be marked as completed when the
Mustaq Ahmed55944cb2018-05-25 20:44:27418 // WebLocalFrameClient receives a loadURLExternally() call.
[email protected]a79cb9912014-04-26 22:07:33419 void WaitUntilExternalURLLoad();
420
lukasza1b546c12016-04-04 16:19:20421 // This function sets a flag to dump the drag image when the next drag&drop is
422 // initiated. It is equivalent to DumpAsTextWithPixelResults but the pixel
423 // results will be the drag image instead of a snapshot of the page.
jackhou656fc852015-02-13 09:04:17424 void DumpDragImage();
425
lfg05e41372016-07-22 15:38:10426 // Sets a flag that tells the WebViewTestProxy to dump the default navigation
jochenc3a98da12015-03-10 13:59:58427 // policy passed to the decidePolicyForNavigation callback.
428 void DumpNavigationPolicy();
429
tkent217ff8852016-11-14 04:43:49430 // Controls whether JavaScript dialogs such as alert() are dumped to test
431 // output.
432 void SetDumpJavaScriptDialogs(bool value);
433
jkarlin3bddb7d2016-09-21 18:44:16434 // Overrides the NetworkQualityEstimator's estimated network type. If |type|
435 // is TypeUnknown the NQE's value is used. Be sure to call this with
436 // TypeUnknown at the end of your test if you use this.
437 void SetEffectiveConnectionType(
438 blink::WebEffectiveConnectionType connection_type);
439
xiaochengh2fa3e762016-08-24 11:27:04440 // Controls whether the mock spell checker is enabled.
441 void SetMockSpellCheckerEnabled(bool enabled);
442
[email protected]97f9a7952014-03-14 11:50:33443 ///////////////////////////////////////////////////////////////////////////
lfg05e41372016-07-22 15:38:10444 // Methods interacting with the WebViewTestProxy
[email protected]97f9a7952014-03-14 11:50:33445
446 ///////////////////////////////////////////////////////////////////////////
447 // Methods forwarding to the WebTestDelegate
448
449 // Shows DevTools window.
[email protected]06c253012014-04-16 18:35:33450 void ShowWebInspector(const std::string& str,
451 const std::string& frontend_url);
[email protected]97f9a7952014-03-14 11:50:33452 void CloseWebInspector();
453
Will Chen8bbdf20f2017-12-12 21:09:54454 void NavigateSecondaryWindow(const GURL& url);
455 void InspectSecondaryWindow();
456
[email protected]97f9a7952014-03-14 11:50:33457 // Inspect chooser state
458 bool IsChooserShown();
459
Kent Tamura21d1de62018-12-10 04:45:20460 // Allows web tests to exec scripts at WebInspector side.
[email protected]97f9a7952014-03-14 11:50:33461 void EvaluateInWebInspector(int call_id, const std::string& script);
462
463 // Clears all databases.
464 void ClearAllDatabases();
465 // Sets the default quota for all origins
466 void SetDatabaseQuota(int quota);
467
tyoshinoa6b91462016-07-11 09:15:09468 // Sets the cookie policy to:
469 // - allow all cookies when |block| is false
470 // - block only third-party cookies when |block| is true
471 void SetBlockThirdPartyCookies(bool block);
[email protected]97f9a7952014-03-14 11:50:33472
[email protected]97f9a7952014-03-14 11:50:33473 // Converts a URL starting with file:///tmp/ to the local mapping.
474 std::string PathToLocalResource(const std::string& path);
475
mlamourid5098d02015-04-21 12:17:30476 // Sets the permission's |name| to |value| for a given {origin, embedder}
477 // tuple.
478 void SetPermission(const std::string& name,
479 const std::string& value,
480 const GURL& origin,
481 const GURL& embedding_origin);
482
dominickn09f7b572016-10-28 01:44:15483 // Resolve the in-flight beforeinstallprompt event.
484 void ResolveBeforeInstallPromptPromise(const std::string& platform);
benwells0c0d3f12015-05-25 01:03:17485
[email protected]97f9a7952014-03-14 11:50:33486 // Calls setlocale(LC_ALL, ...) for a specified locale.
487 // Resets between tests.
488 void SetPOSIXLocale(const std::string& locale);
489
peterd98157d2014-11-20 13:15:01490 // Simulates a click on a Web Notification.
Peter Beverloo988ef962017-09-12 15:49:17491 void SimulateWebNotificationClick(
492 const std::string& title,
493 const base::Optional<int>& action_index,
494 const base::Optional<base::string16>& reply);
[email protected]97f9a7952014-03-14 11:50:33495
nsatragno24bd34b2016-02-09 10:30:02496 // Simulates closing a Web Notification.
497 void SimulateWebNotificationClose(const std::string& title, bool by_user);
498
Kent Tamura2eab5b12018-12-07 04:31:23499 // Takes care of notifying the delegate after a change to web test runtime
lukasza083b4f12016-03-24 16:51:43500 // flags.
Kent Tamura2eab5b12018-12-07 04:31:23501 void OnWebTestRuntimeFlagsChanged();
lukaszac9cbe712016-03-14 14:06:43502
[email protected]97f9a7952014-03-14 11:50:33503 ///////////////////////////////////////////////////////////////////////////
504 // Internal helpers
[email protected]eec9e78e2014-06-16 21:38:48505
lukasza10cd8762016-04-27 20:03:02506 bool IsFramePartOfMainTestWindow(blink::WebFrame*) const;
507
[email protected]97f9a7952014-03-14 11:50:33508 void CheckResponseMimeType();
[email protected]97f9a7952014-03-14 11:50:33509
[email protected]97f9a7952014-03-14 11:50:33510 // In the Mac code, this is called to trigger the end of a test after the
511 // page has finished loading. From here, we can generate the dump for the
512 // test.
513 void LocationChangeDone();
514
515 bool test_is_running_;
516
517 // When reset is called, go through and close all but the main test shell
518 // window. By default, set to true but toggled to false using
519 // setCloseRemainingWindowsWhenComplete().
520 bool close_remaining_windows_;
521
[email protected]97f9a7952014-03-14 11:50:33522 WorkQueue work_queue_;
523
[email protected]97f9a7952014-03-14 11:50:33524 // Bound variable to return the name of this platform (chromium).
525 std::string platform_name_;
526
527 // Bound variable to store the last tooltip text
528 std::string tooltip_text_;
529
[email protected]97f9a7952014-03-14 11:50:33530 // Bound variable counting the number of top URLs visited.
531 int web_history_item_count_;
532
lukasza9b9d70e2016-02-25 23:45:44533 // Flags controlling what content gets dumped as a layout text result.
Kent Tamura2eab5b12018-12-07 04:31:23534 WebTestRuntimeFlags web_test_runtime_flags_;
[email protected]97f9a7952014-03-14 11:50:33535
Xianzhu Wang8d64fc32018-10-15 02:26:53536 // If true, the test runner will output a base64 encoded WAVE file.
[email protected]97f9a7952014-03-14 11:50:33537 bool dump_as_audio_;
538
Xianzhu Wang8d64fc32018-10-15 02:26:53539 // If true, the test runner will produce a dump of the back forward list as
[email protected]97f9a7952014-03-14 11:50:33540 // well.
541 bool dump_back_forward_list_;
542
[email protected]97f9a7952014-03-14 11:50:33543 // If true, pixel dump will be produced as a series of 1px-tall, view-wide
544 // individual paints over the height of the view.
545 bool test_repaint_;
546
547 // If true and test_repaint_ is true as well, pixel dump will be produced as
548 // a series of 1px-wide, view-tall paints across the width of the view.
549 bool sweep_horizontally_;
550
[email protected]97f9a7952014-03-14 11:50:33551 std::set<std::string> http_headers_to_clear_;
552
553 // WAV audio data is stored here.
554 std::vector<unsigned char> audio_data_;
555
[email protected]79ecada2014-05-04 05:16:16556 TestInterfaces* test_interfaces_;
557 WebTestDelegate* delegate_;
lukasza8973c522016-04-27 16:32:28558 blink::WebView* main_view_;
[email protected]97f9a7952014-03-14 11:50:33559
560 // This is non-0 IFF a load is in progress.
561 blink::WebFrame* top_loading_frame_;
562
mlamouri007f9d72015-02-27 16:27:25563 // WebContentSettingsClient mock object.
dcheng82beb4f2016-04-26 00:35:02564 std::unique_ptr<MockContentSettingsClient> mock_content_settings_client_;
[email protected]97f9a7952014-03-14 11:50:33565
[email protected]97f9a7952014-03-14 11:50:33566 bool use_mock_theme_;
567
dcheng82beb4f2016-04-26 00:35:02568 std::unique_ptr<MockScreenOrientationClient> mock_screen_orientation_client_;
dcheng82beb4f2016-04-26 00:35:02569 std::unique_ptr<SpellCheckClient> spellcheck_;
lukaszafd124602016-04-01 16:53:30570
571 // Number of currently active color choosers.
572 int chooser_count_;
lukasza6a113ae12016-03-17 22:41:20573
lukasza1b546c12016-04-04 16:19:20574 // Captured drag image.
danakj0c75ad82018-07-10 19:50:12575 SkBitmap drag_image_;
lukasza1b546c12016-04-04 16:19:20576
lukasza95416be142016-04-14 15:06:33577 // View that was focused by a previous call to TestRunner::SetFocus method.
578 // Note - this can be a dangling pointer to an already destroyed WebView (this
579 // is ok, because this is taken care of in WebTestDelegate::SetFocus).
580 blink::WebView* previously_focused_view_;
581
Kent Tamurafde0e4e2018-11-26 08:27:00582 // True when running a test in web_tests/external/wpt/.
tkent2edc979d2016-05-27 04:58:25583 bool is_web_platform_tests_mode_;
tkent003403482016-05-26 08:18:41584
Mason Freedb0855622018-10-02 17:49:47585 // True if rasterization should be performed during tests that examine
586 // fling-style animations. This includes middle-click auto-scroll behaviors.
587 // This does not include most "ordinary" animations, such as CSS animations.
588 bool animation_requires_raster_;
589
Kent Tamura21d1de62018-12-10 04:45:20590 // An effective connection type settable by web tests.
jkarlin3bddb7d2016-09-21 18:44:16591 blink::WebEffectiveConnectionType effective_connection_type_;
592
pfeldman4c4133d2016-12-20 02:40:21593 // Forces v8 compilation cache to be disabled (used for inspector tests).
594 bool disable_v8_cache_ = false;
595
[email protected]97f9a7952014-03-14 11:50:33596 base::WeakPtrFactory<TestRunner> weak_factory_;
597
598 DISALLOW_COPY_AND_ASSIGN(TestRunner);
599};
600
jochenf5f31752015-06-03 12:06:34601} // namespace test_runner
[email protected]97f9a7952014-03-14 11:50:33602
Scott Violetfdda96d2018-07-27 20:17:23603#endif // CONTENT_SHELL_TEST_RUNNER_TEST_RUNNER_H_