blob: 767d61ac90cf048d78b2c0333e38d0fab3c4a7c9 [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/layout_test_runtime_flags.h"
21#include "content/shell/test_runner/test_runner_export.h"
22#include "content/shell/test_runner/web_test_runner.h"
toyoshim729663f2016-10-17 08:54:1323#include "media/midi/midi_service.mojom.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 {
[email protected]97f9a7952014-03-14 11:50:3345
lukasza21353232016-04-12 19:52:1146class MockContentSettingsClient;
lukasza6a113ae12016-03-17 22:41:2047class MockScreenOrientationClient;
lukasza5c2279c2016-04-05 16:44:4748class SpellCheckClient;
[email protected]79ecada2014-05-04 05:16:1649class TestInterfaces;
lukaszab2ad0502016-04-27 15:51:4250class TestRunnerForSpecificView;
[email protected]79ecada2014-05-04 05:16:1651class WebTestDelegate;
[email protected]97f9a7952014-03-14 11:50:3352
lukaszab2ad0502016-04-27 15:51:4253// TestRunner class currently has dual purpose:
54// 1. It implements |testRunner| javascript bindings for "global" / "ambient".
55// Examples:
56// - testRunner.dumpAsText (test flag affecting test behavior)
carlosk5f1c5172016-09-08 18:59:3157// - testRunner.setAllowRunningOfInsecureContent (test flag affecting product
lukaszab2ad0502016-04-27 15:51:4258// behavior)
59// - testRunner.setTextSubpixelPositioning (directly interacts with product).
60// Note that "per-view" (non-"global") bindings are handled by
61// instances of TestRunnerForSpecificView class.
62// 2. It manages global test state. Example:
63// - Tracking topLoadingFrame that can finish the test when it loads.
64// - WorkQueue holding load requests from the TestInterfaces
65// - LayoutTestRuntimeFlags
lukaszac9358822016-04-07 14:43:4666class TestRunner : public WebTestRunner {
[email protected]97f9a7952014-03-14 11:50:3367 public:
[email protected]79ecada2014-05-04 05:16:1668 explicit TestRunner(TestInterfaces*);
[email protected]97f9a7952014-03-14 11:50:3369 virtual ~TestRunner();
70
lukaszab2ad0502016-04-27 15:51:4271 void Install(blink::WebLocalFrame* frame,
72 base::WeakPtr<TestRunnerForSpecificView> view_test_runner);
[email protected]97f9a7952014-03-14 11:50:3373
[email protected]79ecada2014-05-04 05:16:1674 void SetDelegate(WebTestDelegate*);
lukasza8973c522016-04-27 16:32:2875 void SetMainView(blink::WebView*);
[email protected]97f9a7952014-03-14 11:50:3376
77 void Reset();
78
[email protected]97f9a7952014-03-14 11:50:3379 void SetTestIsRunning(bool);
80 bool TestIsRunning() const { return test_is_running_; }
81
82 bool UseMockTheme() const { return use_mock_theme_; }
83
84 // WebTestRunner implementation.
dchenge933b3e2014-10-21 11:44:0985 bool ShouldGeneratePixelResults() override;
86 bool ShouldDumpAsAudio() const override;
87 void GetAudioData(std::vector<unsigned char>* buffer_view) const override;
lukaszaef264fc52016-03-17 22:49:1988 bool IsRecursiveLayoutDumpRequested() override;
89 std::string DumpLayout(blink::WebLocalFrame* frame) 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;
lukasza083b4f12016-03-24 16:51:4394 void ReplicateLayoutTestRuntimeFlagsChanges(
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);
ki.stfu939799a42015-09-28 04:41:20114 void setCustomTextOutput(const std::string& text);
[email protected]97f9a7952014-03-14 11:50:33115 void setShouldGeneratePixelResults(bool);
116 void setShouldDumpFrameLoadCallbacks(bool);
[email protected]97f9a7952014-03-14 11:50:33117 void setShouldEnableViewSource(bool);
118 bool shouldDumpEditingCallbacks() const;
119 bool shouldDumpFrameLoadCallbacks() const;
120 bool shouldDumpPingLoaderCallbacks() const;
121 bool shouldDumpUserGestureInFrameLoadCallbacks() const;
122 bool shouldDumpTitleChanges() const;
123 bool shouldDumpIconChanges() const;
124 bool shouldDumpCreateView() const;
125 bool canOpenWindows() const;
126 bool shouldDumpResourceLoadCallbacks() const;
[email protected]97f9a7952014-03-14 11:50:33127 bool shouldDumpResourceResponseMIMETypes() const;
[email protected]97f9a7952014-03-14 11:50:33128 bool shouldDumpSpellCheckCallbacks() const;
[email protected]a79cb9912014-04-26 22:07:33129 bool shouldWaitUntilExternalURLLoad() const;
[email protected]97f9a7952014-03-14 11:50:33130 const std::set<std::string>* httpHeadersToClear() const;
tkent2edc979d2016-05-27 04:58:25131 bool is_web_platform_tests_mode() const {
132 return is_web_platform_tests_mode_;
133 }
134 void set_is_web_platform_tests_mode() { is_web_platform_tests_mode_ = true; }
Kent Tamura98e6b1382018-07-02 03:31:19135 const base::Optional<std::vector<std::string>>& file_chooser_paths() const {
Kent Tamura428b9a512018-06-27 09:32:00136 return file_chooser_paths_;
137 }
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
toyoshim729663f2016-10-17 08:54:13161 midi::mojom::Result midiAccessorResult();
[email protected]97f9a7952014-03-14 11:50:33162
caseqcb2227832016-05-24 18:52:04163 bool ShouldDumpConsoleMessages() const;
tkent217ff8852016-11-14 04:43:49164 bool ShouldDumpJavaScriptDialogs() const;
caseqcb2227832016-05-24 18:52:04165
jkarlin3bddb7d2016-09-21 18:44:16166 blink::WebEffectiveConnectionType effective_connection_type() const {
167 return effective_connection_type_;
168 }
169
[email protected]97f9a7952014-03-14 11:50:33170 // A single item in the work queue.
171 class WorkItem {
172 public:
173 virtual ~WorkItem() {}
174
175 // Returns true if this started a load.
[email protected]79ecada2014-05-04 05:16:16176 virtual bool Run(WebTestDelegate*, blink::WebView*) = 0;
[email protected]97f9a7952014-03-14 11:50:33177 };
178
179 private:
[email protected]97f9a7952014-03-14 11:50:33180 friend class TestRunnerBindings;
181 friend class WorkQueue;
182
183 // Helper class for managing events queued by methods like queueLoad or
184 // queueScript.
185 class WorkQueue {
186 public:
187 explicit WorkQueue(TestRunner* controller);
188 virtual ~WorkQueue();
189 void ProcessWorkSoon();
190
191 // Reset the state of the class between tests.
192 void Reset();
193
194 void AddWork(WorkItem*);
195
196 void set_frozen(bool frozen) { frozen_ = frozen; }
197 bool is_empty() { return queue_.empty(); }
[email protected]97f9a7952014-03-14 11:50:33198
199 private:
200 void ProcessWork();
201
Brett Wilsoncc8623d2017-09-12 03:28:10202 base::circular_deque<WorkItem*> queue_;
[email protected]97f9a7952014-03-14 11:50:33203 bool frozen_;
204 TestRunner* controller_;
lukaszac9358822016-04-07 14:43:46205
206 base::WeakPtrFactory<WorkQueue> weak_factory_;
[email protected]97f9a7952014-03-14 11:50:33207 };
208
209 ///////////////////////////////////////////////////////////////////////////
210 // Methods dealing with the test logic
211
212 // By default, tests end when page load is complete. These methods are used
213 // to delay the completion of the test until notifyDone is called.
214 void NotifyDone();
215 void WaitUntilDone();
216
217 // Methods for adding actions to the work queue. Used in conjunction with
218 // waitUntilDone/notifyDone above.
219 void QueueBackNavigation(int how_far_back);
220 void QueueForwardNavigation(int how_far_forward);
221 void QueueReload();
222 void QueueLoadingScript(const std::string& script);
223 void QueueNonLoadingScript(const std::string& script);
224 void QueueLoad(const std::string& url, const std::string& target);
[email protected]97f9a7952014-03-14 11:50:33225
226 // Causes navigation actions just printout the intended navigation instead
227 // of taking you to the page. This is used for cases like mailto, where you
228 // don't actually want to open the mail program.
229 void SetCustomPolicyDelegate(gin::Arguments* args);
230
231 // Delays completion of the test until the policy delegate runs.
232 void WaitForPolicyDelegate();
233
234 // Functions for dealing with windows. By default we block all new windows.
235 int WindowCount();
236 void SetCloseRemainingWindowsWhenComplete(bool close_remaining_windows);
237 void ResetTestHelperControllers();
238
[email protected]97f9a7952014-03-14 11:50:33239 // Allows layout tests to manage origins' whitelisting.
240 void AddOriginAccessWhitelistEntry(const std::string& source_origin,
241 const std::string& destination_protocol,
242 const std::string& destination_host,
243 bool allow_destination_subdomains);
244 void RemoveOriginAccessWhitelistEntry(const std::string& source_origin,
245 const std::string& destination_protocol,
246 const std::string& destination_host,
247 bool allow_destination_subdomains);
248
dcheng9000dbd2015-04-03 05:39:40249 // Add |source_code| as an injected stylesheet to the active document of the
250 // window of the current V8 context.
251 void InsertStyleSheet(const std::string& source_code);
252
[email protected]97f9a7952014-03-14 11:50:33253 // Enables or disables subpixel positioning (i.e. fractional X positions for
254 // glyphs) in text rendering on Linux. Since this method changes global
255 // settings, tests that call it must use their own custom font family for
256 // all text that they render. If not, an already-cached style will be used,
257 // resulting in the changed setting being ignored.
258 void SetTextSubpixelPositioning(bool value);
259
[email protected]97f9a7952014-03-14 11:50:33260 // After this function is called, all window-sizing machinery is
261 // short-circuited inside the renderer. This mode is necessary for
262 // some tests that were written before browsers had multi-process architecture
263 // and rely on window resizes to happen synchronously.
264 // The function has "unfortunate" it its name because we must strive to remove
265 // all tests that rely on this... well, unfortunate behavior. See
266 // http://crbug.com/309760 for the plan.
267 void UseUnfortunateSynchronousResizeMode();
268
269 bool EnableAutoResizeMode(int min_width,
270 int min_height,
271 int max_width,
272 int max_height);
273 bool DisableAutoResizeMode(int new_width, int new_height);
274
[email protected]e0bc2cb2014-03-20 17:34:24275 void SetMockScreenOrientation(const std::string& orientation);
dgozman3c16f7f2016-02-26 01:21:18276 void DisableMockScreenOrientation();
[email protected]e0bc2cb2014-03-20 17:34:24277
[email protected]97f9a7952014-03-14 11:50:33278 ///////////////////////////////////////////////////////////////////////////
279 // Methods modifying WebPreferences.
280
281 // Set the WebPreference that controls webkit's popup blocking.
282 void SetPopupBlockingEnabled(bool block_popups);
283
284 void SetJavaScriptCanAccessClipboard(bool can_access);
285 void SetXSSAuditorEnabled(bool enabled);
286 void SetAllowUniversalAccessFromFileURLs(bool allow);
287 void SetAllowFileAccessFromFileURLs(bool allow);
Dan Elphick382a5962018-07-27 13:34:04288 void OverridePreference(gin::Arguments* arguments);
[email protected]97f9a7952014-03-14 11:50:33289
[email protected]ebd5ea52014-05-28 14:51:15290 // Modify accept_languages in RendererPreferences.
291 void SetAcceptLanguages(const std::string& accept_languages);
292
[email protected]97f9a7952014-03-14 11:50:33293 // Enable or disable plugins.
294 void SetPluginsEnabled(bool enabled);
295
296 ///////////////////////////////////////////////////////////////////////////
297 // Methods that modify the state of TestRunner
298
299 // This function sets a flag that tells the test_shell to print a line of
300 // descriptive text for each editing command. It takes no arguments, and
301 // ignores any that may be present.
302 void DumpEditingCallbacks();
303
304 // This function sets a flag that tells the test_shell to dump pages as
305 // plain text, rather than as a text representation of the renderer's state.
306 // The pixel results will not be generated for this test.
307 void DumpAsText();
308
309 // This function sets a flag that tells the test_shell to dump pages as
[email protected]fdc433c02014-06-02 19:27:14310 // the DOM contents, rather than as a text representation of the renderer's
311 // state. The pixel results will not be generated for this test.
312 void DumpAsMarkup();
313
314 // This function sets a flag that tells the test_shell to dump pages as
[email protected]97f9a7952014-03-14 11:50:33315 // plain text, rather than as a text representation of the renderer's state.
316 // It will also generate a pixel dump for the test.
317 void DumpAsTextWithPixelResults();
318
319 // This function sets a flag that tells the test_shell to print out the
320 // scroll offsets of the child frames. It ignores all.
321 void DumpChildFrameScrollPositions();
322
323 // This function sets a flag that tells the test_shell to recursively
324 // dump all frames as plain text if the DumpAsText flag is set.
325 // It takes no arguments, and ignores any that may be present.
326 void DumpChildFramesAsText();
327
[email protected]fdc433c02014-06-02 19:27:14328 // This function sets a flag that tells the test_shell to recursively
329 // dump all frames as the DOM contents if the DumpAsMarkup flag is set.
330 // It takes no arguments, and ignores any that may be present.
331 void DumpChildFramesAsMarkup();
332
[email protected]97f9a7952014-03-14 11:50:33333 // This function sets a flag that tells the test_shell to print out the
334 // information about icon changes notifications from WebKit.
335 void DumpIconChanges();
336
337 // Deals with Web Audio WAV file data.
338 void SetAudioData(const gin::ArrayBufferView& view);
339
340 // This function sets a flag that tells the test_shell to print a line of
341 // descriptive text for each frame load callback. It takes no arguments, and
342 // ignores any that may be present.
343 void DumpFrameLoadCallbacks();
344
345 // This function sets a flag that tells the test_shell to print a line of
346 // descriptive text for each PingLoader dispatch. It takes no arguments, and
347 // ignores any that may be present.
348 void DumpPingLoaderCallbacks();
349
350 // This function sets a flag that tells the test_shell to print a line of
351 // user gesture status text for some frame load callbacks. It takes no
352 // arguments, and ignores any that may be present.
353 void DumpUserGestureInFrameLoadCallbacks();
354
355 void DumpTitleChanges();
356
357 // This function sets a flag that tells the test_shell to dump all calls to
358 // WebViewClient::createView().
359 // It takes no arguments, and ignores any that may be present.
360 void DumpCreateView();
361
362 void SetCanOpenWindows();
363
364 // This function sets a flag that tells the test_shell to dump a descriptive
365 // line for each resource load callback. It takes no arguments, and ignores
366 // any that may be present.
367 void DumpResourceLoadCallbacks();
368
[email protected]97f9a7952014-03-14 11:50:33369 // This function sets a flag that tells the test_shell to dump the MIME type
370 // for each resource that was loaded. It takes no arguments, and ignores any
371 // that may be present.
372 void DumpResourceResponseMIMETypes();
373
mlamouri007f9d72015-02-27 16:27:25374 // WebContentSettingsClient related.
[email protected]97f9a7952014-03-14 11:50:33375 void SetImagesAllowed(bool allowed);
376 void SetScriptsAllowed(bool allowed);
377 void SetStorageAllowed(bool allowed);
378 void SetPluginsAllowed(bool allowed);
[email protected]97f9a7952014-03-14 11:50:33379 void SetAllowRunningOfInsecureContent(bool allowed);
mlamouri426f2862016-04-29 18:35:01380 void SetAutoplayAllowed(bool allowed);
[email protected]97f9a7952014-03-14 11:50:33381 void DumpPermissionClientCallbacks();
382
engedy9ae04242016-06-08 13:31:18383 // Sets up a mock DocumentSubresourceFilter to disallow subsequent subresource
384 // loads within the current document with the given path |suffixes|. The
385 // filter is created and injected even if |suffixes| is empty. If |suffixes|
386 // contains the empty string, all subresource loads will be disallowed.
387 void SetDisallowedSubresourcePathSuffixes(
388 const std::vector<std::string>& suffixes);
389
[email protected]97f9a7952014-03-14 11:50:33390 // This function sets a flag that tells the test_shell to dump all
391 // the lines of descriptive text about spellcheck execution.
392 void DumpSpellCheckCallbacks();
393
394 // This function sets a flag that tells the test_shell to print out a text
395 // representation of the back/forward list. It ignores all arguments.
396 void DumpBackForwardList();
397
398 void DumpSelectionRect();
[email protected]97f9a7952014-03-14 11:50:33399
400 // Causes layout to happen as if targetted to printed pages.
401 void SetPrinting();
Xianzhu Wangdbb84fc2018-02-03 00:33:35402 void SetPrintingForFrame(const std::string& frame_name);
[email protected]97f9a7952014-03-14 11:50:33403
[email protected]52846102014-06-24 04:26:44404 // Clears the state from SetPrinting().
405 void ClearPrinting();
406
[email protected]97f9a7952014-03-14 11:50:33407 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
408
409 // Causes WillSendRequest to clear certain headers.
410 void SetWillSendRequestClearHeader(const std::string& header);
411
[email protected]97f9a7952014-03-14 11:50:33412 // Sets a flag to enable the mock theme.
413 void SetUseMockTheme(bool use);
414
[email protected]a79cb9912014-04-26 22:07:33415 // Sets a flag that causes the test to be marked as completed when the
Mustaq Ahmed55944cb2018-05-25 20:44:27416 // WebLocalFrameClient receives a loadURLExternally() call.
[email protected]a79cb9912014-04-26 22:07:33417 void WaitUntilExternalURLLoad();
418
lukasza1b546c12016-04-04 16:19:20419 // This function sets a flag to dump the drag image when the next drag&drop is
420 // initiated. It is equivalent to DumpAsTextWithPixelResults but the pixel
421 // results will be the drag image instead of a snapshot of the page.
jackhou656fc852015-02-13 09:04:17422 void DumpDragImage();
423
lfg05e41372016-07-22 15:38:10424 // Sets a flag that tells the WebViewTestProxy to dump the default navigation
jochenc3a98da12015-03-10 13:59:58425 // policy passed to the decidePolicyForNavigation callback.
426 void DumpNavigationPolicy();
427
caseqcb2227832016-05-24 18:52:04428 // Controls whether console messages produced by the page are dumped
429 // to test output.
430 void SetDumpConsoleMessages(bool value);
431
tkent217ff8852016-11-14 04:43:49432 // Controls whether JavaScript dialogs such as alert() are dumped to test
433 // output.
434 void SetDumpJavaScriptDialogs(bool value);
435
jkarlin3bddb7d2016-09-21 18:44:16436 // Overrides the NetworkQualityEstimator's estimated network type. If |type|
437 // is TypeUnknown the NQE's value is used. Be sure to call this with
438 // TypeUnknown at the end of your test if you use this.
439 void SetEffectiveConnectionType(
440 blink::WebEffectiveConnectionType connection_type);
441
xiaochengh2fa3e762016-08-24 11:27:04442 // Controls whether the mock spell checker is enabled.
443 void SetMockSpellCheckerEnabled(bool enabled);
444
[email protected]97f9a7952014-03-14 11:50:33445 ///////////////////////////////////////////////////////////////////////////
lfg05e41372016-07-22 15:38:10446 // Methods interacting with the WebViewTestProxy
[email protected]97f9a7952014-03-14 11:50:33447
448 ///////////////////////////////////////////////////////////////////////////
449 // Methods forwarding to the WebTestDelegate
450
451 // Shows DevTools window.
[email protected]06c253012014-04-16 18:35:33452 void ShowWebInspector(const std::string& str,
453 const std::string& frontend_url);
[email protected]97f9a7952014-03-14 11:50:33454 void CloseWebInspector();
455
Will Chen8bbdf20f2017-12-12 21:09:54456 void NavigateSecondaryWindow(const GURL& url);
457 void InspectSecondaryWindow();
458
[email protected]97f9a7952014-03-14 11:50:33459 // Inspect chooser state
460 bool IsChooserShown();
461
462 // Allows layout tests to exec scripts at WebInspector side.
463 void EvaluateInWebInspector(int call_id, const std::string& script);
464
465 // Clears all databases.
466 void ClearAllDatabases();
467 // Sets the default quota for all origins
468 void SetDatabaseQuota(int quota);
469
tyoshinoa6b91462016-07-11 09:15:09470 // Sets the cookie policy to:
471 // - allow all cookies when |block| is false
472 // - block only third-party cookies when |block| is true
473 void SetBlockThirdPartyCookies(bool block);
[email protected]97f9a7952014-03-14 11:50:33474
[email protected]97f9a7952014-03-14 11:50:33475 // Converts a URL starting with file:///tmp/ to the local mapping.
476 std::string PathToLocalResource(const std::string& path);
477
mlamourid5098d02015-04-21 12:17:30478 // Sets the permission's |name| to |value| for a given {origin, embedder}
479 // tuple.
480 void SetPermission(const std::string& name,
481 const std::string& value,
482 const GURL& origin,
483 const GURL& embedding_origin);
484
dominickn09f7b572016-10-28 01:44:15485 // Resolve the in-flight beforeinstallprompt event.
486 void ResolveBeforeInstallPromptPromise(const std::string& platform);
benwells0c0d3f12015-05-25 01:03:17487
[email protected]97f9a7952014-03-14 11:50:33488 // Calls setlocale(LC_ALL, ...) for a specified locale.
489 // Resets between tests.
490 void SetPOSIXLocale(const std::string& locale);
491
492 // MIDI function to control permission handling.
toyoshim729663f2016-10-17 08:54:13493 void SetMIDIAccessorResult(midi::mojom::Result result);
[email protected]97f9a7952014-03-14 11:50:33494
peterd98157d2014-11-20 13:15:01495 // Simulates a click on a Web Notification.
Peter Beverloo988ef962017-09-12 15:49:17496 void SimulateWebNotificationClick(
497 const std::string& title,
498 const base::Optional<int>& action_index,
499 const base::Optional<base::string16>& reply);
[email protected]97f9a7952014-03-14 11:50:33500
nsatragno24bd34b2016-02-09 10:30:02501 // Simulates closing a Web Notification.
502 void SimulateWebNotificationClose(const std::string& title, bool by_user);
503
lukasza083b4f12016-03-24 16:51:43504 // Takes care of notifying the delegate after a change to layout test runtime
505 // flags.
506 void OnLayoutTestRuntimeFlagsChanged();
lukaszac9cbe712016-03-14 14:06:43507
Kent Tamura428b9a512018-06-27 09:32:00508 // Sets a list of file paths to be selected in the next file chooser session.
509 // If an empty list is specified, the next file chooser will be canceled.
510 void SetFileChooserPaths(const std::vector<std::string>& paths);
511
[email protected]97f9a7952014-03-14 11:50:33512 ///////////////////////////////////////////////////////////////////////////
513 // Internal helpers
[email protected]eec9e78e2014-06-16 21:38:48514
lukasza10cd8762016-04-27 20:03:02515 bool IsFramePartOfMainTestWindow(blink::WebFrame*) const;
516
[email protected]97f9a7952014-03-14 11:50:33517 void CheckResponseMimeType();
[email protected]97f9a7952014-03-14 11:50:33518
[email protected]97f9a7952014-03-14 11:50:33519 // In the Mac code, this is called to trigger the end of a test after the
520 // page has finished loading. From here, we can generate the dump for the
521 // test.
522 void LocationChangeDone();
523
524 bool test_is_running_;
525
526 // When reset is called, go through and close all but the main test shell
527 // window. By default, set to true but toggled to false using
528 // setCloseRemainingWindowsWhenComplete().
529 bool close_remaining_windows_;
530
[email protected]97f9a7952014-03-14 11:50:33531 WorkQueue work_queue_;
532
[email protected]97f9a7952014-03-14 11:50:33533 // Bound variable to return the name of this platform (chromium).
534 std::string platform_name_;
535
536 // Bound variable to store the last tooltip text
537 std::string tooltip_text_;
538
[email protected]97f9a7952014-03-14 11:50:33539 // Bound variable counting the number of top URLs visited.
540 int web_history_item_count_;
541
lukasza9b9d70e2016-02-25 23:45:44542 // Flags controlling what content gets dumped as a layout text result.
lukasza083b4f12016-03-24 16:51:43543 LayoutTestRuntimeFlags layout_test_runtime_flags_;
[email protected]97f9a7952014-03-14 11:50:33544
[email protected]97f9a7952014-03-14 11:50:33545 // If true, the test_shell will output a base64 encoded WAVE file.
546 bool dump_as_audio_;
547
[email protected]97f9a7952014-03-14 11:50:33548 // If true, the test_shell will produce a dump of the back forward list as
549 // well.
550 bool dump_back_forward_list_;
551
[email protected]97f9a7952014-03-14 11:50:33552 // If true, pixel dump will be produced as a series of 1px-tall, view-wide
553 // individual paints over the height of the view.
554 bool test_repaint_;
555
556 // If true and test_repaint_ is true as well, pixel dump will be produced as
557 // a series of 1px-wide, view-tall paints across the width of the view.
558 bool sweep_horizontally_;
559
toyoshim729663f2016-10-17 08:54:13560 // startSession() result of MockWebMIDIAccessor for testing.
561 midi::mojom::Result midi_accessor_result_;
[email protected]97f9a7952014-03-14 11:50:33562
[email protected]97f9a7952014-03-14 11:50:33563 std::set<std::string> http_headers_to_clear_;
564
565 // WAV audio data is stored here.
566 std::vector<unsigned char> audio_data_;
567
[email protected]79ecada2014-05-04 05:16:16568 TestInterfaces* test_interfaces_;
569 WebTestDelegate* delegate_;
lukasza8973c522016-04-27 16:32:28570 blink::WebView* main_view_;
[email protected]97f9a7952014-03-14 11:50:33571
572 // This is non-0 IFF a load is in progress.
573 blink::WebFrame* top_loading_frame_;
574
mlamouri007f9d72015-02-27 16:27:25575 // WebContentSettingsClient mock object.
dcheng82beb4f2016-04-26 00:35:02576 std::unique_ptr<MockContentSettingsClient> mock_content_settings_client_;
[email protected]97f9a7952014-03-14 11:50:33577
[email protected]97f9a7952014-03-14 11:50:33578 bool use_mock_theme_;
579
dcheng82beb4f2016-04-26 00:35:02580 std::unique_ptr<MockScreenOrientationClient> mock_screen_orientation_client_;
dcheng82beb4f2016-04-26 00:35:02581 std::unique_ptr<SpellCheckClient> spellcheck_;
lukaszafd124602016-04-01 16:53:30582
583 // Number of currently active color choosers.
584 int chooser_count_;
lukasza6a113ae12016-03-17 22:41:20585
lukasza1b546c12016-04-04 16:19:20586 // Captured drag image.
danakj0c75ad82018-07-10 19:50:12587 SkBitmap drag_image_;
lukasza1b546c12016-04-04 16:19:20588
lukasza95416be142016-04-14 15:06:33589 // View that was focused by a previous call to TestRunner::SetFocus method.
590 // Note - this can be a dangling pointer to an already destroyed WebView (this
591 // is ok, because this is taken care of in WebTestDelegate::SetFocus).
592 blink::WebView* previously_focused_view_;
593
Quinten Yearsley0d7709a2017-03-29 23:10:43594 // True when running a test in LayoutTests/external/wpt/.
tkent2edc979d2016-05-27 04:58:25595 bool is_web_platform_tests_mode_;
tkent003403482016-05-26 08:18:41596
jkarlin3bddb7d2016-09-21 18:44:16597 // An effective connection type settable by layout tests.
598 blink::WebEffectiveConnectionType effective_connection_type_;
599
pfeldman4c4133d2016-12-20 02:40:21600 // Forces v8 compilation cache to be disabled (used for inspector tests).
601 bool disable_v8_cache_ = false;
602
Kent Tamura98e6b1382018-07-02 03:31:19603 base::Optional<std::vector<std::string>> file_chooser_paths_;
Kent Tamura428b9a512018-06-27 09:32:00604
[email protected]97f9a7952014-03-14 11:50:33605 base::WeakPtrFactory<TestRunner> weak_factory_;
606
607 DISALLOW_COPY_AND_ASSIGN(TestRunner);
608};
609
jochenf5f31752015-06-03 12:06:34610} // namespace test_runner
[email protected]97f9a7952014-03-14 11:50:33611
Scott Violetfdda96d2018-07-27 20:17:23612#endif // CONTENT_SHELL_TEST_RUNNER_TEST_RUNNER_H_