blob: dcbb6d99bf15dcf5399ac964af93773ad2368019 [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
dcheng59826e32017-02-22 10:31:365#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
[email protected]97f9a7952014-03-14 11:50:3310#include <deque>
dcheng82beb4f2016-04-26 00:35:0211#include <memory>
[email protected]97f9a7952014-03-14 11:50:3312#include <set>
13#include <string>
benwells0c0d3f12015-05-25 01:03:1714#include <vector>
[email protected]97f9a7952014-03-14 11:50:3315
avi5dd91f82015-12-25 22:30:4616#include "base/macros.h"
[email protected]97f9a7952014-03-14 11:50:3317#include "base/memory/weak_ptr.h"
dcheng59826e32017-02-22 10:31:3618#include "content/shell/test_runner/layout_test_runtime_flags.h"
19#include "content/shell/test_runner/test_runner_export.h"
20#include "content/shell/test_runner/web_test_runner.h"
toyoshim729663f2016-10-17 08:54:1321#include "media/midi/midi_service.mojom.h"
jkarlin3bddb7d2016-09-21 18:44:1622#include "third_party/WebKit/public/platform/WebEffectiveConnectionType.h"
lukasza1b546c12016-04-04 16:19:2023#include "third_party/WebKit/public/platform/WebImage.h"
[email protected]97f9a7952014-03-14 11:50:3324#include "v8/include/v8.h"
25
[email protected]945babb2014-07-30 14:25:3226class GURL;
[email protected]eec9e78e2014-06-16 21:38:4827class SkBitmap;
28
awdff8bdbe82016-10-14 09:42:3229namespace base {
30class NullableString16;
31}
32
[email protected]97f9a7952014-03-14 11:50:3333namespace blink {
mlamouri007f9d72015-02-27 16:27:2534class WebContentSettingsClient;
[email protected]97f9a7952014-03-14 11:50:3335class WebFrame;
lukaszab2ad0502016-04-27 15:51:4236class WebLocalFrame;
[email protected]97f9a7952014-03-14 11:50:3337class WebString;
38class WebView;
39}
40
41namespace gin {
42class ArrayBufferView;
43class Arguments;
44}
45
jochenf5f31752015-06-03 12:06:3446namespace test_runner {
[email protected]97f9a7952014-03-14 11:50:3347
lukasza21353232016-04-12 19:52:1148class MockContentSettingsClient;
lukasza5c2279c2016-04-05 16:44:4749class MockCredentialManagerClient;
lukasza6a113ae12016-03-17 22:41:2050class MockScreenOrientationClient;
lukasza01da2602016-04-05 14:51:2651class MockWebSpeechRecognizer;
lukaszafd124602016-04-01 16:53:3052class MockWebUserMediaClient;
lukasza5c2279c2016-04-05 16:44:4753class SpellCheckClient;
[email protected]79ecada2014-05-04 05:16:1654class TestInterfaces;
lukaszab2ad0502016-04-27 15:51:4255class TestRunnerForSpecificView;
[email protected]79ecada2014-05-04 05:16:1656class WebTestDelegate;
[email protected]97f9a7952014-03-14 11:50:3357
lukaszab2ad0502016-04-27 15:51:4258// TestRunner class currently has dual purpose:
59// 1. It implements |testRunner| javascript bindings for "global" / "ambient".
60// Examples:
61// - testRunner.dumpAsText (test flag affecting test behavior)
carlosk5f1c5172016-09-08 18:59:3162// - testRunner.setAllowRunningOfInsecureContent (test flag affecting product
lukaszab2ad0502016-04-27 15:51:4263// behavior)
64// - testRunner.setTextSubpixelPositioning (directly interacts with product).
65// Note that "per-view" (non-"global") bindings are handled by
66// instances of TestRunnerForSpecificView class.
67// 2. It manages global test state. Example:
68// - Tracking topLoadingFrame that can finish the test when it loads.
69// - WorkQueue holding load requests from the TestInterfaces
70// - LayoutTestRuntimeFlags
lukaszac9358822016-04-07 14:43:4671class TestRunner : public WebTestRunner {
[email protected]97f9a7952014-03-14 11:50:3372 public:
[email protected]79ecada2014-05-04 05:16:1673 explicit TestRunner(TestInterfaces*);
[email protected]97f9a7952014-03-14 11:50:3374 virtual ~TestRunner();
75
lukaszab2ad0502016-04-27 15:51:4276 void Install(blink::WebLocalFrame* frame,
77 base::WeakPtr<TestRunnerForSpecificView> view_test_runner);
[email protected]97f9a7952014-03-14 11:50:3378
[email protected]79ecada2014-05-04 05:16:1679 void SetDelegate(WebTestDelegate*);
lukasza8973c522016-04-27 16:32:2880 void SetMainView(blink::WebView*);
[email protected]97f9a7952014-03-14 11:50:3381
82 void Reset();
83
[email protected]97f9a7952014-03-14 11:50:3384 void SetTestIsRunning(bool);
85 bool TestIsRunning() const { return test_is_running_; }
86
87 bool UseMockTheme() const { return use_mock_theme_; }
88
89 // WebTestRunner implementation.
dchenge933b3e2014-10-21 11:44:0990 bool ShouldGeneratePixelResults() override;
91 bool ShouldDumpAsAudio() const override;
92 void GetAudioData(std::vector<unsigned char>* buffer_view) const override;
lukaszaef264fc52016-03-17 22:49:1993 bool IsRecursiveLayoutDumpRequested() override;
94 std::string DumpLayout(blink::WebLocalFrame* frame) override;
lukasza1b546c12016-04-04 16:19:2095 void DumpPixelsAsync(
96 blink::WebView* web_view,
97 const base::Callback<void(const SkBitmap&)>& callback) override;
lukasza083b4f12016-03-24 16:51:4398 void ReplicateLayoutTestRuntimeFlagsChanges(
lukaszac9cbe712016-03-14 14:06:4399 const base::DictionaryValue& changed_values) override;
lukaszaa8960462016-01-27 22:27:33100 bool HasCustomTextDump(std::string* custom_text_dump) const override;
dchenge933b3e2014-10-21 11:44:09101 bool ShouldDumpBackForwardList() const override;
mlamouri007f9d72015-02-27 16:27:25102 blink::WebContentSettingsClient* GetWebContentSettings() const override;
lukasza5c2279c2016-04-05 16:44:47103 void InitializeWebViewWithMocks(blink::WebView* web_view) override;
lukasza95416be142016-04-14 15:06:33104 void SetFocus(blink::WebView* web_view, bool focus) override;
[email protected]97f9a7952014-03-14 11:50:33105
lukasza01da2602016-04-05 14:51:26106 // Methods used by WebViewTestClient and WebFrameTestClient.
blundell987cb782016-08-17 17:25:37107 void OnNavigationBegin(blink::WebFrame* frame);
108 void OnNavigationEnd() { will_navigate_ = false; }
lukaszaa0b624a2016-04-04 15:00:49109 std::string GetAcceptLanguages() const;
lukaszae26c3d62016-03-14 23:30:59110 bool shouldStayOnPageAfterHandlingBeforeUnload() const;
lukasza6a113ae12016-03-17 22:41:20111 MockScreenOrientationClient* getMockScreenOrientationClient();
lukaszafd124602016-04-01 16:53:30112 MockWebUserMediaClient* getMockWebUserMediaClient();
lukasza01da2602016-04-05 14:51:26113 MockWebSpeechRecognizer* getMockWebSpeechRecognizer();
[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);
abhishek.a21ca9b5602014-09-19 07:33:33119 void ClearDevToolsLocalStorage();
pfeldman4c4133d2016-12-20 02:40:21120 void SetV8CacheDisabled(bool);
[email protected]97f9a7952014-03-14 11:50:33121 void setShouldDumpAsText(bool);
122 void setShouldDumpAsMarkup(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 shouldDumpResourceResponseMIMETypes() const;
137 bool shouldDumpStatusCallbacks() const;
[email protected]97f9a7952014-03-14 11:50:33138 bool shouldDumpSpellCheckCallbacks() const;
[email protected]a79cb9912014-04-26 22:07:33139 bool shouldWaitUntilExternalURLLoad() const;
[email protected]97f9a7952014-03-14 11:50:33140 const std::set<std::string>* httpHeadersToClear() const;
tkent2edc979d2016-05-27 04:58:25141 bool is_web_platform_tests_mode() const {
142 return is_web_platform_tests_mode_;
143 }
144 void set_is_web_platform_tests_mode() { is_web_platform_tests_mode_ = true; }
lukasza10cd8762016-04-27 20:03:02145
146 // To be called when |frame| starts loading - TestRunner will check if
147 // there is currently no top-loading-frame being tracked and if so, then it
148 // will return true and start tracking |frame| as the top-loading-frame.
149 bool tryToSetTopLoadingFrame(blink::WebFrame* frame);
150
151 // To be called when |frame| finishes loading - TestRunner will check if
152 // |frame| is currently tracked as the top-loading-frame, and if yes, then it
153 // will return true, stop top-loading-frame tracking, and potentially finish
154 // the test (unless testRunner.waitUntilDone() was called and/or there are
155 // pending load requests in WorkQueue).
156 bool tryToClearTopLoadingFrame(blink::WebFrame*);
157
xiaochengh5fe2c6a2016-12-20 06:11:56158 blink::WebFrame* mainFrame() const;
[email protected]97f9a7952014-03-14 11:50:33159 blink::WebFrame* topLoadingFrame() const;
160 void policyDelegateDone();
161 bool policyDelegateEnabled() const;
162 bool policyDelegateIsPermissive() const;
163 bool policyDelegateShouldNotifyDone() const;
[email protected]97f9a7952014-03-14 11:50:33164 void setToolTipText(const blink::WebString&);
lukasza1b546c12016-04-04 16:19:20165 void setDragImage(const blink::WebImage& drag_image);
jochenc3a98da12015-03-10 13:59:58166 bool shouldDumpNavigationPolicy() const;
[email protected]97f9a7952014-03-14 11:50:33167
toyoshim729663f2016-10-17 08:54:13168 midi::mojom::Result midiAccessorResult();
[email protected]97f9a7952014-03-14 11:50:33169
lukaszafd124602016-04-01 16:53:30170 // Methods used by MockColorChooser:
171 void DidOpenChooser();
172 void DidCloseChooser();
173
caseqcb2227832016-05-24 18:52:04174 bool ShouldDumpConsoleMessages() const;
tkent217ff8852016-11-14 04:43:49175 bool ShouldDumpJavaScriptDialogs() const;
caseqcb2227832016-05-24 18:52:04176
jkarlin3bddb7d2016-09-21 18:44:16177 blink::WebEffectiveConnectionType effective_connection_type() const {
178 return effective_connection_type_;
179 }
180
[email protected]97f9a7952014-03-14 11:50:33181 // A single item in the work queue.
182 class WorkItem {
183 public:
184 virtual ~WorkItem() {}
185
186 // Returns true if this started a load.
[email protected]79ecada2014-05-04 05:16:16187 virtual bool Run(WebTestDelegate*, blink::WebView*) = 0;
[email protected]97f9a7952014-03-14 11:50:33188 };
189
190 private:
[email protected]97f9a7952014-03-14 11:50:33191 friend class TestRunnerBindings;
192 friend class WorkQueue;
193
194 // Helper class for managing events queued by methods like queueLoad or
195 // queueScript.
196 class WorkQueue {
197 public:
198 explicit WorkQueue(TestRunner* controller);
199 virtual ~WorkQueue();
200 void ProcessWorkSoon();
201
202 // Reset the state of the class between tests.
203 void Reset();
204
205 void AddWork(WorkItem*);
206
207 void set_frozen(bool frozen) { frozen_ = frozen; }
208 bool is_empty() { return queue_.empty(); }
[email protected]97f9a7952014-03-14 11:50:33209
210 private:
211 void ProcessWork();
212
[email protected]97f9a7952014-03-14 11:50:33213 std::deque<WorkItem*> queue_;
214 bool frozen_;
215 TestRunner* controller_;
lukaszac9358822016-04-07 14:43:46216
217 base::WeakPtrFactory<WorkQueue> weak_factory_;
[email protected]97f9a7952014-03-14 11:50:33218 };
219
220 ///////////////////////////////////////////////////////////////////////////
221 // Methods dealing with the test logic
222
223 // By default, tests end when page load is complete. These methods are used
224 // to delay the completion of the test until notifyDone is called.
225 void NotifyDone();
226 void WaitUntilDone();
227
228 // Methods for adding actions to the work queue. Used in conjunction with
229 // waitUntilDone/notifyDone above.
230 void QueueBackNavigation(int how_far_back);
231 void QueueForwardNavigation(int how_far_forward);
232 void QueueReload();
233 void QueueLoadingScript(const std::string& script);
234 void QueueNonLoadingScript(const std::string& script);
235 void QueueLoad(const std::string& url, const std::string& target);
[email protected]97f9a7952014-03-14 11:50:33236
237 // Causes navigation actions just printout the intended navigation instead
238 // of taking you to the page. This is used for cases like mailto, where you
239 // don't actually want to open the mail program.
240 void SetCustomPolicyDelegate(gin::Arguments* args);
241
242 // Delays completion of the test until the policy delegate runs.
243 void WaitForPolicyDelegate();
244
245 // Functions for dealing with windows. By default we block all new windows.
246 int WindowCount();
247 void SetCloseRemainingWindowsWhenComplete(bool close_remaining_windows);
248 void ResetTestHelperControllers();
249
[email protected]97f9a7952014-03-14 11:50:33250 // Allows layout tests to manage origins' whitelisting.
251 void AddOriginAccessWhitelistEntry(const std::string& source_origin,
252 const std::string& destination_protocol,
253 const std::string& destination_host,
254 bool allow_destination_subdomains);
255 void RemoveOriginAccessWhitelistEntry(const std::string& source_origin,
256 const std::string& destination_protocol,
257 const std::string& destination_host,
258 bool allow_destination_subdomains);
259
dcheng9000dbd2015-04-03 05:39:40260 // Add |source_code| as an injected stylesheet to the active document of the
261 // window of the current V8 context.
262 void InsertStyleSheet(const std::string& source_code);
263
[email protected]97f9a7952014-03-14 11:50:33264 // Enables or disables subpixel positioning (i.e. fractional X positions for
265 // glyphs) in text rendering on Linux. Since this method changes global
266 // settings, tests that call it must use their own custom font family for
267 // all text that they render. If not, an already-cached style will be used,
268 // resulting in the changed setting being ignored.
269 void SetTextSubpixelPositioning(bool value);
270
[email protected]97f9a7952014-03-14 11:50:33271 // After this function is called, all window-sizing machinery is
272 // short-circuited inside the renderer. This mode is necessary for
273 // some tests that were written before browsers had multi-process architecture
274 // and rely on window resizes to happen synchronously.
275 // The function has "unfortunate" it its name because we must strive to remove
276 // all tests that rely on this... well, unfortunate behavior. See
277 // http://crbug.com/309760 for the plan.
278 void UseUnfortunateSynchronousResizeMode();
279
280 bool EnableAutoResizeMode(int min_width,
281 int min_height,
282 int max_width,
283 int max_height);
284 bool DisableAutoResizeMode(int new_width, int new_height);
285
[email protected]2ad7e622014-06-30 17:44:21286 void SetMockDeviceLight(double value);
287 void ResetDeviceLight();
[email protected]97f9a7952014-03-14 11:50:33288 // Device Motion / Device Orientation related functions
dcheng59826e32017-02-22 10:31:36289 void SetMockDeviceMotion(bool has_acceleration_x,
290 double acceleration_x,
291 bool has_acceleration_y,
292 double acceleration_y,
293 bool has_acceleration_z,
294 double acceleration_z,
[email protected]97f9a7952014-03-14 11:50:33295 bool has_acceleration_including_gravity_x,
296 double acceleration_including_gravity_x,
297 bool has_acceleration_including_gravity_y,
298 double acceleration_including_gravity_y,
299 bool has_acceleration_including_gravity_z,
300 double acceleration_including_gravity_z,
301 bool has_rotation_rate_alpha,
302 double rotation_rate_alpha,
303 bool has_rotation_rate_beta,
304 double rotation_rate_beta,
305 bool has_rotation_rate_gamma,
306 double rotation_rate_gamma,
307 double interval);
dcheng59826e32017-02-22 10:31:36308 void SetMockDeviceOrientation(bool has_alpha,
309 double alpha,
310 bool has_beta,
311 double beta,
312 bool has_gamma,
313 double gamma,
philipj97906452016-03-02 14:46:22314 bool absolute);
[email protected]97f9a7952014-03-14 11:50:33315
[email protected]e0bc2cb2014-03-20 17:34:24316 void SetMockScreenOrientation(const std::string& orientation);
dgozman3c16f7f2016-02-26 01:21:18317 void DisableMockScreenOrientation();
[email protected]e0bc2cb2014-03-20 17:34:24318
[email protected]97f9a7952014-03-14 11:50:33319 ///////////////////////////////////////////////////////////////////////////
320 // Methods modifying WebPreferences.
321
322 // Set the WebPreference that controls webkit's popup blocking.
323 void SetPopupBlockingEnabled(bool block_popups);
324
325 void SetJavaScriptCanAccessClipboard(bool can_access);
326 void SetXSSAuditorEnabled(bool enabled);
327 void SetAllowUniversalAccessFromFileURLs(bool allow);
328 void SetAllowFileAccessFromFileURLs(bool allow);
ki.stfu939799a42015-09-28 04:41:20329 void OverridePreference(const std::string& key, v8::Local<v8::Value> value);
[email protected]97f9a7952014-03-14 11:50:33330
[email protected]ebd5ea52014-05-28 14:51:15331 // Modify accept_languages in RendererPreferences.
332 void SetAcceptLanguages(const std::string& accept_languages);
333
[email protected]97f9a7952014-03-14 11:50:33334 // Enable or disable plugins.
335 void SetPluginsEnabled(bool enabled);
336
337 ///////////////////////////////////////////////////////////////////////////
338 // Methods that modify the state of TestRunner
339
340 // This function sets a flag that tells the test_shell to print a line of
341 // descriptive text for each editing command. It takes no arguments, and
342 // ignores any that may be present.
343 void DumpEditingCallbacks();
344
345 // This function sets a flag that tells the test_shell to dump pages as
346 // plain text, rather than as a text representation of the renderer's state.
347 // The pixel results will not be generated for this test.
348 void DumpAsText();
349
350 // This function sets a flag that tells the test_shell to dump pages as
[email protected]fdc433c02014-06-02 19:27:14351 // the DOM contents, rather than as a text representation of the renderer's
352 // state. The pixel results will not be generated for this test.
353 void DumpAsMarkup();
354
355 // This function sets a flag that tells the test_shell to dump pages as
[email protected]97f9a7952014-03-14 11:50:33356 // plain text, rather than as a text representation of the renderer's state.
357 // It will also generate a pixel dump for the test.
358 void DumpAsTextWithPixelResults();
359
360 // This function sets a flag that tells the test_shell to print out the
361 // scroll offsets of the child frames. It ignores all.
362 void DumpChildFrameScrollPositions();
363
364 // This function sets a flag that tells the test_shell to recursively
365 // dump all frames as plain text if the DumpAsText flag is set.
366 // It takes no arguments, and ignores any that may be present.
367 void DumpChildFramesAsText();
368
[email protected]fdc433c02014-06-02 19:27:14369 // This function sets a flag that tells the test_shell to recursively
370 // dump all frames as the DOM contents if the DumpAsMarkup flag is set.
371 // It takes no arguments, and ignores any that may be present.
372 void DumpChildFramesAsMarkup();
373
[email protected]97f9a7952014-03-14 11:50:33374 // This function sets a flag that tells the test_shell to print out the
375 // information about icon changes notifications from WebKit.
376 void DumpIconChanges();
377
378 // Deals with Web Audio WAV file data.
379 void SetAudioData(const gin::ArrayBufferView& view);
380
381 // This function sets a flag that tells the test_shell to print a line of
382 // descriptive text for each frame load callback. It takes no arguments, and
383 // ignores any that may be present.
384 void DumpFrameLoadCallbacks();
385
386 // This function sets a flag that tells the test_shell to print a line of
387 // descriptive text for each PingLoader dispatch. It takes no arguments, and
388 // ignores any that may be present.
389 void DumpPingLoaderCallbacks();
390
391 // This function sets a flag that tells the test_shell to print a line of
392 // user gesture status text for some frame load callbacks. It takes no
393 // arguments, and ignores any that may be present.
394 void DumpUserGestureInFrameLoadCallbacks();
395
396 void DumpTitleChanges();
397
398 // This function sets a flag that tells the test_shell to dump all calls to
399 // WebViewClient::createView().
400 // It takes no arguments, and ignores any that may be present.
401 void DumpCreateView();
402
403 void SetCanOpenWindows();
404
405 // This function sets a flag that tells the test_shell to dump a descriptive
406 // line for each resource load callback. It takes no arguments, and ignores
407 // any that may be present.
408 void DumpResourceLoadCallbacks();
409
[email protected]97f9a7952014-03-14 11:50:33410 // This function sets a flag that tells the test_shell to dump the MIME type
411 // for each resource that was loaded. It takes no arguments, and ignores any
412 // that may be present.
413 void DumpResourceResponseMIMETypes();
414
mlamouri007f9d72015-02-27 16:27:25415 // WebContentSettingsClient related.
[email protected]97f9a7952014-03-14 11:50:33416 void SetImagesAllowed(bool allowed);
417 void SetScriptsAllowed(bool allowed);
418 void SetStorageAllowed(bool allowed);
419 void SetPluginsAllowed(bool allowed);
[email protected]97f9a7952014-03-14 11:50:33420 void SetAllowRunningOfInsecureContent(bool allowed);
mlamouri426f2862016-04-29 18:35:01421 void SetAutoplayAllowed(bool allowed);
[email protected]97f9a7952014-03-14 11:50:33422 void DumpPermissionClientCallbacks();
423
engedy9ae04242016-06-08 13:31:18424 // Sets up a mock DocumentSubresourceFilter to disallow subsequent subresource
425 // loads within the current document with the given path |suffixes|. The
426 // filter is created and injected even if |suffixes| is empty. If |suffixes|
427 // contains the empty string, all subresource loads will be disallowed.
428 void SetDisallowedSubresourcePathSuffixes(
429 const std::vector<std::string>& suffixes);
430
[email protected]97f9a7952014-03-14 11:50:33431 // This function sets a flag that tells the test_shell to dump all calls
432 // to window.status().
433 // It takes no arguments, and ignores any that may be present.
434 void DumpWindowStatusChanges();
435
[email protected]97f9a7952014-03-14 11:50:33436 // This function sets a flag that tells the test_shell to dump all
437 // the lines of descriptive text about spellcheck execution.
438 void DumpSpellCheckCallbacks();
439
440 // This function sets a flag that tells the test_shell to print out a text
441 // representation of the back/forward list. It ignores all arguments.
442 void DumpBackForwardList();
443
444 void DumpSelectionRect();
[email protected]97f9a7952014-03-14 11:50:33445
446 // Causes layout to happen as if targetted to printed pages.
447 void SetPrinting();
448
[email protected]52846102014-06-24 04:26:44449 // Clears the state from SetPrinting().
450 void ClearPrinting();
451
[email protected]97f9a7952014-03-14 11:50:33452 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
453
454 // Causes WillSendRequest to clear certain headers.
455 void SetWillSendRequestClearHeader(const std::string& header);
456
[email protected]97f9a7952014-03-14 11:50:33457 // Sets a flag to enable the mock theme.
458 void SetUseMockTheme(bool use);
459
[email protected]a79cb9912014-04-26 22:07:33460 // Sets a flag that causes the test to be marked as completed when the
461 // WebFrameClient receives a loadURLExternally() call.
462 void WaitUntilExternalURLLoad();
463
lukasza1b546c12016-04-04 16:19:20464 // This function sets a flag to dump the drag image when the next drag&drop is
465 // initiated. It is equivalent to DumpAsTextWithPixelResults but the pixel
466 // results will be the drag image instead of a snapshot of the page.
jackhou656fc852015-02-13 09:04:17467 void DumpDragImage();
468
lfg05e41372016-07-22 15:38:10469 // Sets a flag that tells the WebViewTestProxy to dump the default navigation
jochenc3a98da12015-03-10 13:59:58470 // policy passed to the decidePolicyForNavigation callback.
471 void DumpNavigationPolicy();
472
caseqcb2227832016-05-24 18:52:04473 // Controls whether console messages produced by the page are dumped
474 // to test output.
475 void SetDumpConsoleMessages(bool value);
476
tkent217ff8852016-11-14 04:43:49477 // Controls whether JavaScript dialogs such as alert() are dumped to test
478 // output.
479 void SetDumpJavaScriptDialogs(bool value);
480
jkarlin3bddb7d2016-09-21 18:44:16481 // Overrides the NetworkQualityEstimator's estimated network type. If |type|
482 // is TypeUnknown the NQE's value is used. Be sure to call this with
483 // TypeUnknown at the end of your test if you use this.
484 void SetEffectiveConnectionType(
485 blink::WebEffectiveConnectionType connection_type);
486
xiaochengh2fa3e762016-08-24 11:27:04487 // Controls whether the mock spell checker is enabled.
488 void SetMockSpellCheckerEnabled(bool enabled);
489
[email protected]97f9a7952014-03-14 11:50:33490 ///////////////////////////////////////////////////////////////////////////
lfg05e41372016-07-22 15:38:10491 // Methods interacting with the WebViewTestProxy
[email protected]97f9a7952014-03-14 11:50:33492
493 ///////////////////////////////////////////////////////////////////////////
494 // Methods forwarding to the WebTestDelegate
495
496 // Shows DevTools window.
[email protected]06c253012014-04-16 18:35:33497 void ShowWebInspector(const std::string& str,
498 const std::string& frontend_url);
[email protected]97f9a7952014-03-14 11:50:33499 void CloseWebInspector();
500
501 // Inspect chooser state
502 bool IsChooserShown();
503
504 // Allows layout tests to exec scripts at WebInspector side.
505 void EvaluateInWebInspector(int call_id, const std::string& script);
sergeyv0cd842b42015-10-09 16:07:11506 // Allows layout tests to evaluate scripts in InspectorOverlay page.
507 // Script may have an output represented as a string, return values of other
508 // types would be ignored.
509 std::string EvaluateInWebInspectorOverlay(const std::string& script);
[email protected]97f9a7952014-03-14 11:50:33510
511 // Clears all databases.
512 void ClearAllDatabases();
513 // Sets the default quota for all origins
514 void SetDatabaseQuota(int quota);
515
tyoshinoa6b91462016-07-11 09:15:09516 // Sets the cookie policy to:
517 // - allow all cookies when |block| is false
518 // - block only third-party cookies when |block| is true
519 void SetBlockThirdPartyCookies(bool block);
[email protected]97f9a7952014-03-14 11:50:33520
[email protected]97f9a7952014-03-14 11:50:33521 // Converts a URL starting with file:///tmp/ to the local mapping.
522 std::string PathToLocalResource(const std::string& path);
523
mlamourid5098d02015-04-21 12:17:30524 // Sets the permission's |name| to |value| for a given {origin, embedder}
525 // tuple.
526 void SetPermission(const std::string& name,
527 const std::string& value,
528 const GURL& origin,
529 const GURL& embedding_origin);
530
dominickn09f7b572016-10-28 01:44:15531 // Resolve the in-flight beforeinstallprompt event.
532 void ResolveBeforeInstallPromptPromise(const std::string& platform);
benwells0c0d3f12015-05-25 01:03:17533
[email protected]97f9a7952014-03-14 11:50:33534 // Calls setlocale(LC_ALL, ...) for a specified locale.
535 // Resets between tests.
536 void SetPOSIXLocale(const std::string& locale);
537
538 // MIDI function to control permission handling.
toyoshim729663f2016-10-17 08:54:13539 void SetMIDIAccessorResult(midi::mojom::Result result);
[email protected]97f9a7952014-03-14 11:50:33540
peterd98157d2014-11-20 13:15:01541 // Simulates a click on a Web Notification.
awdff8bdbe82016-10-14 09:42:32542 void SimulateWebNotificationClick(const std::string& title,
543 int action_index,
544 const base::NullableString16& reply);
[email protected]97f9a7952014-03-14 11:50:33545
nsatragno24bd34b2016-02-09 10:30:02546 // Simulates closing a Web Notification.
547 void SimulateWebNotificationClose(const std::string& title, bool by_user);
548
[email protected]56e365d42014-05-02 22:18:24549 // Speech recognition related functions.
[email protected]97f9a7952014-03-14 11:50:33550 void AddMockSpeechRecognitionResult(const std::string& transcript,
551 double confidence);
552 void SetMockSpeechRecognitionError(const std::string& error,
553 const std::string& message);
[email protected]97f9a7952014-03-14 11:50:33554
mkwst41667ab2014-09-16 06:52:43555 // Credential Manager mock functions
556 // TODO(mkwst): Support FederatedCredential.
tyoshino5138b3b92016-09-27 09:11:50557 void SetMockCredentialManagerResponse(const std::string& id,
mkwst41667ab2014-09-16 06:52:43558 const std::string& name,
559 const std::string& avatar,
560 const std::string& password);
tyoshino5138b3b92016-09-27 09:11:50561 void ClearMockCredentialManagerResponse();
562 void SetMockCredentialManagerError(const std::string& error);
mkwst41667ab2014-09-16 06:52:43563
lukasza083b4f12016-03-24 16:51:43564 // Takes care of notifying the delegate after a change to layout test runtime
565 // flags.
566 void OnLayoutTestRuntimeFlagsChanged();
lukaszac9cbe712016-03-14 14:06:43567
[email protected]97f9a7952014-03-14 11:50:33568 ///////////////////////////////////////////////////////////////////////////
569 // Internal helpers
[email protected]eec9e78e2014-06-16 21:38:48570
lukasza10cd8762016-04-27 20:03:02571 bool IsFramePartOfMainTestWindow(blink::WebFrame*) const;
572
[email protected]97f9a7952014-03-14 11:50:33573 void CheckResponseMimeType();
[email protected]97f9a7952014-03-14 11:50:33574
[email protected]97f9a7952014-03-14 11:50:33575 // In the Mac code, this is called to trigger the end of a test after the
576 // page has finished loading. From here, we can generate the dump for the
577 // test.
578 void LocationChangeDone();
579
580 bool test_is_running_;
581
582 // When reset is called, go through and close all but the main test shell
583 // window. By default, set to true but toggled to false using
584 // setCloseRemainingWindowsWhenComplete().
585 bool close_remaining_windows_;
586
[email protected]97f9a7952014-03-14 11:50:33587 WorkQueue work_queue_;
588
[email protected]97f9a7952014-03-14 11:50:33589 // Bound variable to return the name of this platform (chromium).
590 std::string platform_name_;
591
592 // Bound variable to store the last tooltip text
593 std::string tooltip_text_;
594
[email protected]97f9a7952014-03-14 11:50:33595 // Bound variable counting the number of top URLs visited.
596 int web_history_item_count_;
597
lukasza9b9d70e2016-02-25 23:45:44598 // Flags controlling what content gets dumped as a layout text result.
lukasza083b4f12016-03-24 16:51:43599 LayoutTestRuntimeFlags layout_test_runtime_flags_;
[email protected]97f9a7952014-03-14 11:50:33600
[email protected]97f9a7952014-03-14 11:50:33601 // If true, the test_shell will output a base64 encoded WAVE file.
602 bool dump_as_audio_;
603
[email protected]97f9a7952014-03-14 11:50:33604 // If true, the test_shell will produce a dump of the back forward list as
605 // well.
606 bool dump_back_forward_list_;
607
[email protected]97f9a7952014-03-14 11:50:33608 // If true, pixel dump will be produced as a series of 1px-tall, view-wide
609 // individual paints over the height of the view.
610 bool test_repaint_;
611
612 // If true and test_repaint_ is true as well, pixel dump will be produced as
613 // a series of 1px-wide, view-tall paints across the width of the view.
614 bool sweep_horizontally_;
615
toyoshim729663f2016-10-17 08:54:13616 // startSession() result of MockWebMIDIAccessor for testing.
617 midi::mojom::Result midi_accessor_result_;
[email protected]97f9a7952014-03-14 11:50:33618
[email protected]97f9a7952014-03-14 11:50:33619 std::set<std::string> http_headers_to_clear_;
620
621 // WAV audio data is stored here.
622 std::vector<unsigned char> audio_data_;
623
[email protected]79ecada2014-05-04 05:16:16624 TestInterfaces* test_interfaces_;
625 WebTestDelegate* delegate_;
lukasza8973c522016-04-27 16:32:28626 blink::WebView* main_view_;
[email protected]97f9a7952014-03-14 11:50:33627
628 // This is non-0 IFF a load is in progress.
629 blink::WebFrame* top_loading_frame_;
630
mlamouri007f9d72015-02-27 16:27:25631 // WebContentSettingsClient mock object.
dcheng82beb4f2016-04-26 00:35:02632 std::unique_ptr<MockContentSettingsClient> mock_content_settings_client_;
[email protected]97f9a7952014-03-14 11:50:33633
[email protected]97f9a7952014-03-14 11:50:33634 bool use_mock_theme_;
635
blundell987cb782016-08-17 17:25:37636 // This is true in the period between the start of a navigation and when the
637 // provisional load for that navigation is started. Note that when
638 // browser-side navigation is enabled there is an arbitrary gap between these
639 // two events.
640 bool will_navigate_;
641
dcheng82beb4f2016-04-26 00:35:02642 std::unique_ptr<MockCredentialManagerClient> credential_manager_client_;
643 std::unique_ptr<MockScreenOrientationClient> mock_screen_orientation_client_;
644 std::unique_ptr<MockWebSpeechRecognizer> speech_recognizer_;
645 std::unique_ptr<MockWebUserMediaClient> user_media_client_;
646 std::unique_ptr<SpellCheckClient> spellcheck_;
lukaszafd124602016-04-01 16:53:30647
648 // Number of currently active color choosers.
649 int chooser_count_;
lukasza6a113ae12016-03-17 22:41:20650
lukasza1b546c12016-04-04 16:19:20651 // Captured drag image.
652 blink::WebImage drag_image_;
653
lukasza95416be142016-04-14 15:06:33654 // View that was focused by a previous call to TestRunner::SetFocus method.
655 // Note - this can be a dangling pointer to an already destroyed WebView (this
656 // is ok, because this is taken care of in WebTestDelegate::SetFocus).
657 blink::WebView* previously_focused_view_;
658
tkent2edc979d2016-05-27 04:58:25659 // True if we run a test in LayoutTests/imported/{csswg-test,wpt}/.
660 bool is_web_platform_tests_mode_;
tkent003403482016-05-26 08:18:41661
jkarlin3bddb7d2016-09-21 18:44:16662 // An effective connection type settable by layout tests.
663 blink::WebEffectiveConnectionType effective_connection_type_;
664
pfeldman4c4133d2016-12-20 02:40:21665 // Forces v8 compilation cache to be disabled (used for inspector tests).
666 bool disable_v8_cache_ = false;
667
[email protected]97f9a7952014-03-14 11:50:33668 base::WeakPtrFactory<TestRunner> weak_factory_;
669
670 DISALLOW_COPY_AND_ASSIGN(TestRunner);
671};
672
jochenf5f31752015-06-03 12:06:34673} // namespace test_runner
[email protected]97f9a7952014-03-14 11:50:33674
dcheng59826e32017-02-22 10:31:36675#endif // CONTENT_SHELL_TEST_RUNNER_TEST_RUNNER_H_