blob: 739d6de9c4f4b6e16609d5f17d42caea9ae0e9e8 [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(
lukasza20971a62017-07-12 01:31:2796 blink::WebLocalFrame* frame,
97 base::OnceCallback<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;
xiaochengh81bfb17412017-04-06 17:54:33103 blink::WebTextCheckClient* GetWebTextCheckClient() const override;
lukasza5c2279c2016-04-05 16:44:47104 void InitializeWebViewWithMocks(blink::WebView* web_view) override;
lukasza95416be142016-04-14 15:06:33105 void SetFocus(blink::WebView* web_view, bool focus) override;
[email protected]97f9a7952014-03-14 11:50:33106
lukasza01da2602016-04-05 14:51:26107 // Methods used by WebViewTestClient and WebFrameTestClient.
blundell987cb782016-08-17 17:25:37108 void OnNavigationBegin(blink::WebFrame* frame);
109 void OnNavigationEnd() { will_navigate_ = false; }
lukaszaa0b624a2016-04-04 15:00:49110 std::string GetAcceptLanguages() const;
lukaszae26c3d62016-03-14 23:30:59111 bool shouldStayOnPageAfterHandlingBeforeUnload() const;
lukasza6a113ae12016-03-17 22:41:20112 MockScreenOrientationClient* getMockScreenOrientationClient();
lukaszafd124602016-04-01 16:53:30113 MockWebUserMediaClient* getMockWebUserMediaClient();
lukasza01da2602016-04-05 14:51:26114 MockWebSpeechRecognizer* getMockWebSpeechRecognizer();
[email protected]97f9a7952014-03-14 11:50:33115 bool isPrinting() const;
[email protected]f24836a2014-05-06 01:02:44116 bool shouldDumpAsCustomText() const;
dcheng59826e32017-02-22 10:31:36117 std::string customDumpText() const;
abhishek.a21ca9b5602014-09-19 07:33:33118 void ShowDevTools(const std::string& settings,
[email protected]06c253012014-04-16 18:35:33119 const std::string& frontend_url);
abhishek.a21ca9b5602014-09-19 07:33:33120 void ClearDevToolsLocalStorage();
pfeldman4c4133d2016-12-20 02:40:21121 void SetV8CacheDisabled(bool);
[email protected]97f9a7952014-03-14 11:50:33122 void setShouldDumpAsText(bool);
123 void setShouldDumpAsMarkup(bool);
ki.stfu939799a42015-09-28 04:41:20124 void setCustomTextOutput(const std::string& text);
[email protected]97f9a7952014-03-14 11:50:33125 void setShouldGeneratePixelResults(bool);
126 void setShouldDumpFrameLoadCallbacks(bool);
[email protected]97f9a7952014-03-14 11:50:33127 void setShouldEnableViewSource(bool);
128 bool shouldDumpEditingCallbacks() const;
129 bool shouldDumpFrameLoadCallbacks() const;
130 bool shouldDumpPingLoaderCallbacks() const;
131 bool shouldDumpUserGestureInFrameLoadCallbacks() const;
132 bool shouldDumpTitleChanges() const;
133 bool shouldDumpIconChanges() const;
134 bool shouldDumpCreateView() const;
135 bool canOpenWindows() const;
136 bool shouldDumpResourceLoadCallbacks() const;
[email protected]97f9a7952014-03-14 11:50:33137 bool shouldDumpResourceResponseMIMETypes() 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]97f9a7952014-03-14 11:50:33286 // Device Motion / Device Orientation related functions
dcheng59826e32017-02-22 10:31:36287 void SetMockDeviceMotion(bool has_acceleration_x,
288 double acceleration_x,
289 bool has_acceleration_y,
290 double acceleration_y,
291 bool has_acceleration_z,
292 double acceleration_z,
[email protected]97f9a7952014-03-14 11:50:33293 bool has_acceleration_including_gravity_x,
294 double acceleration_including_gravity_x,
295 bool has_acceleration_including_gravity_y,
296 double acceleration_including_gravity_y,
297 bool has_acceleration_including_gravity_z,
298 double acceleration_including_gravity_z,
299 bool has_rotation_rate_alpha,
300 double rotation_rate_alpha,
301 bool has_rotation_rate_beta,
302 double rotation_rate_beta,
303 bool has_rotation_rate_gamma,
304 double rotation_rate_gamma,
305 double interval);
dcheng59826e32017-02-22 10:31:36306 void SetMockDeviceOrientation(bool has_alpha,
307 double alpha,
308 bool has_beta,
309 double beta,
310 bool has_gamma,
311 double gamma,
philipj97906452016-03-02 14:46:22312 bool absolute);
[email protected]97f9a7952014-03-14 11:50:33313
[email protected]e0bc2cb2014-03-20 17:34:24314 void SetMockScreenOrientation(const std::string& orientation);
dgozman3c16f7f2016-02-26 01:21:18315 void DisableMockScreenOrientation();
[email protected]e0bc2cb2014-03-20 17:34:24316
[email protected]97f9a7952014-03-14 11:50:33317 ///////////////////////////////////////////////////////////////////////////
318 // Methods modifying WebPreferences.
319
320 // Set the WebPreference that controls webkit's popup blocking.
321 void SetPopupBlockingEnabled(bool block_popups);
322
323 void SetJavaScriptCanAccessClipboard(bool can_access);
324 void SetXSSAuditorEnabled(bool enabled);
325 void SetAllowUniversalAccessFromFileURLs(bool allow);
326 void SetAllowFileAccessFromFileURLs(bool allow);
ki.stfu939799a42015-09-28 04:41:20327 void OverridePreference(const std::string& key, v8::Local<v8::Value> value);
[email protected]97f9a7952014-03-14 11:50:33328
[email protected]ebd5ea52014-05-28 14:51:15329 // Modify accept_languages in RendererPreferences.
330 void SetAcceptLanguages(const std::string& accept_languages);
331
[email protected]97f9a7952014-03-14 11:50:33332 // Enable or disable plugins.
333 void SetPluginsEnabled(bool enabled);
334
335 ///////////////////////////////////////////////////////////////////////////
336 // Methods that modify the state of TestRunner
337
338 // This function sets a flag that tells the test_shell to print a line of
339 // descriptive text for each editing command. It takes no arguments, and
340 // ignores any that may be present.
341 void DumpEditingCallbacks();
342
343 // This function sets a flag that tells the test_shell to dump pages as
344 // plain text, rather than as a text representation of the renderer's state.
345 // The pixel results will not be generated for this test.
346 void DumpAsText();
347
348 // This function sets a flag that tells the test_shell to dump pages as
[email protected]fdc433c02014-06-02 19:27:14349 // the DOM contents, rather than as a text representation of the renderer's
350 // state. The pixel results will not be generated for this test.
351 void DumpAsMarkup();
352
353 // This function sets a flag that tells the test_shell to dump pages as
[email protected]97f9a7952014-03-14 11:50:33354 // plain text, rather than as a text representation of the renderer's state.
355 // It will also generate a pixel dump for the test.
356 void DumpAsTextWithPixelResults();
357
358 // This function sets a flag that tells the test_shell to print out the
359 // scroll offsets of the child frames. It ignores all.
360 void DumpChildFrameScrollPositions();
361
362 // This function sets a flag that tells the test_shell to recursively
363 // dump all frames as plain text if the DumpAsText flag is set.
364 // It takes no arguments, and ignores any that may be present.
365 void DumpChildFramesAsText();
366
[email protected]fdc433c02014-06-02 19:27:14367 // This function sets a flag that tells the test_shell to recursively
368 // dump all frames as the DOM contents if the DumpAsMarkup flag is set.
369 // It takes no arguments, and ignores any that may be present.
370 void DumpChildFramesAsMarkup();
371
[email protected]97f9a7952014-03-14 11:50:33372 // This function sets a flag that tells the test_shell to print out the
373 // information about icon changes notifications from WebKit.
374 void DumpIconChanges();
375
376 // Deals with Web Audio WAV file data.
377 void SetAudioData(const gin::ArrayBufferView& view);
378
379 // This function sets a flag that tells the test_shell to print a line of
380 // descriptive text for each frame load callback. It takes no arguments, and
381 // ignores any that may be present.
382 void DumpFrameLoadCallbacks();
383
384 // This function sets a flag that tells the test_shell to print a line of
385 // descriptive text for each PingLoader dispatch. It takes no arguments, and
386 // ignores any that may be present.
387 void DumpPingLoaderCallbacks();
388
389 // This function sets a flag that tells the test_shell to print a line of
390 // user gesture status text for some frame load callbacks. It takes no
391 // arguments, and ignores any that may be present.
392 void DumpUserGestureInFrameLoadCallbacks();
393
394 void DumpTitleChanges();
395
396 // This function sets a flag that tells the test_shell to dump all calls to
397 // WebViewClient::createView().
398 // It takes no arguments, and ignores any that may be present.
399 void DumpCreateView();
400
401 void SetCanOpenWindows();
402
403 // This function sets a flag that tells the test_shell to dump a descriptive
404 // line for each resource load callback. It takes no arguments, and ignores
405 // any that may be present.
406 void DumpResourceLoadCallbacks();
407
[email protected]97f9a7952014-03-14 11:50:33408 // This function sets a flag that tells the test_shell to dump the MIME type
409 // for each resource that was loaded. It takes no arguments, and ignores any
410 // that may be present.
411 void DumpResourceResponseMIMETypes();
412
mlamouri007f9d72015-02-27 16:27:25413 // WebContentSettingsClient related.
[email protected]97f9a7952014-03-14 11:50:33414 void SetImagesAllowed(bool allowed);
415 void SetScriptsAllowed(bool allowed);
416 void SetStorageAllowed(bool allowed);
417 void SetPluginsAllowed(bool allowed);
[email protected]97f9a7952014-03-14 11:50:33418 void SetAllowRunningOfInsecureContent(bool allowed);
mlamouri426f2862016-04-29 18:35:01419 void SetAutoplayAllowed(bool allowed);
[email protected]97f9a7952014-03-14 11:50:33420 void DumpPermissionClientCallbacks();
421
engedy9ae04242016-06-08 13:31:18422 // Sets up a mock DocumentSubresourceFilter to disallow subsequent subresource
423 // loads within the current document with the given path |suffixes|. The
424 // filter is created and injected even if |suffixes| is empty. If |suffixes|
425 // contains the empty string, all subresource loads will be disallowed.
426 void SetDisallowedSubresourcePathSuffixes(
427 const std::vector<std::string>& suffixes);
428
[email protected]97f9a7952014-03-14 11:50:33429 // This function sets a flag that tells the test_shell to dump all
430 // the lines of descriptive text about spellcheck execution.
431 void DumpSpellCheckCallbacks();
432
433 // This function sets a flag that tells the test_shell to print out a text
434 // representation of the back/forward list. It ignores all arguments.
435 void DumpBackForwardList();
436
437 void DumpSelectionRect();
[email protected]97f9a7952014-03-14 11:50:33438
439 // Causes layout to happen as if targetted to printed pages.
440 void SetPrinting();
441
[email protected]52846102014-06-24 04:26:44442 // Clears the state from SetPrinting().
443 void ClearPrinting();
444
[email protected]97f9a7952014-03-14 11:50:33445 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
446
447 // Causes WillSendRequest to clear certain headers.
448 void SetWillSendRequestClearHeader(const std::string& header);
449
[email protected]97f9a7952014-03-14 11:50:33450 // Sets a flag to enable the mock theme.
451 void SetUseMockTheme(bool use);
452
[email protected]a79cb9912014-04-26 22:07:33453 // Sets a flag that causes the test to be marked as completed when the
454 // WebFrameClient receives a loadURLExternally() call.
455 void WaitUntilExternalURLLoad();
456
lukasza1b546c12016-04-04 16:19:20457 // This function sets a flag to dump the drag image when the next drag&drop is
458 // initiated. It is equivalent to DumpAsTextWithPixelResults but the pixel
459 // results will be the drag image instead of a snapshot of the page.
jackhou656fc852015-02-13 09:04:17460 void DumpDragImage();
461
lfg05e41372016-07-22 15:38:10462 // Sets a flag that tells the WebViewTestProxy to dump the default navigation
jochenc3a98da12015-03-10 13:59:58463 // policy passed to the decidePolicyForNavigation callback.
464 void DumpNavigationPolicy();
465
caseqcb2227832016-05-24 18:52:04466 // Controls whether console messages produced by the page are dumped
467 // to test output.
468 void SetDumpConsoleMessages(bool value);
469
tkent217ff8852016-11-14 04:43:49470 // Controls whether JavaScript dialogs such as alert() are dumped to test
471 // output.
472 void SetDumpJavaScriptDialogs(bool value);
473
jkarlin3bddb7d2016-09-21 18:44:16474 // Overrides the NetworkQualityEstimator's estimated network type. If |type|
475 // is TypeUnknown the NQE's value is used. Be sure to call this with
476 // TypeUnknown at the end of your test if you use this.
477 void SetEffectiveConnectionType(
478 blink::WebEffectiveConnectionType connection_type);
479
xiaochengh2fa3e762016-08-24 11:27:04480 // Controls whether the mock spell checker is enabled.
481 void SetMockSpellCheckerEnabled(bool enabled);
482
[email protected]97f9a7952014-03-14 11:50:33483 ///////////////////////////////////////////////////////////////////////////
lfg05e41372016-07-22 15:38:10484 // Methods interacting with the WebViewTestProxy
[email protected]97f9a7952014-03-14 11:50:33485
486 ///////////////////////////////////////////////////////////////////////////
487 // Methods forwarding to the WebTestDelegate
488
489 // Shows DevTools window.
[email protected]06c253012014-04-16 18:35:33490 void ShowWebInspector(const std::string& str,
491 const std::string& frontend_url);
[email protected]97f9a7952014-03-14 11:50:33492 void CloseWebInspector();
493
494 // Inspect chooser state
495 bool IsChooserShown();
496
497 // Allows layout tests to exec scripts at WebInspector side.
498 void EvaluateInWebInspector(int call_id, const std::string& script);
sergeyv0cd842b42015-10-09 16:07:11499 // Allows layout tests to evaluate scripts in InspectorOverlay page.
500 // Script may have an output represented as a string, return values of other
501 // types would be ignored.
502 std::string EvaluateInWebInspectorOverlay(const std::string& script);
[email protected]97f9a7952014-03-14 11:50:33503
504 // Clears all databases.
505 void ClearAllDatabases();
506 // Sets the default quota for all origins
507 void SetDatabaseQuota(int quota);
508
tyoshinoa6b91462016-07-11 09:15:09509 // Sets the cookie policy to:
510 // - allow all cookies when |block| is false
511 // - block only third-party cookies when |block| is true
512 void SetBlockThirdPartyCookies(bool block);
[email protected]97f9a7952014-03-14 11:50:33513
[email protected]97f9a7952014-03-14 11:50:33514 // Converts a URL starting with file:///tmp/ to the local mapping.
515 std::string PathToLocalResource(const std::string& path);
516
mlamourid5098d02015-04-21 12:17:30517 // Sets the permission's |name| to |value| for a given {origin, embedder}
518 // tuple.
519 void SetPermission(const std::string& name,
520 const std::string& value,
521 const GURL& origin,
522 const GURL& embedding_origin);
523
dominickn09f7b572016-10-28 01:44:15524 // Resolve the in-flight beforeinstallprompt event.
525 void ResolveBeforeInstallPromptPromise(const std::string& platform);
benwells0c0d3f12015-05-25 01:03:17526
[email protected]97f9a7952014-03-14 11:50:33527 // Calls setlocale(LC_ALL, ...) for a specified locale.
528 // Resets between tests.
529 void SetPOSIXLocale(const std::string& locale);
530
531 // MIDI function to control permission handling.
toyoshim729663f2016-10-17 08:54:13532 void SetMIDIAccessorResult(midi::mojom::Result result);
[email protected]97f9a7952014-03-14 11:50:33533
peterd98157d2014-11-20 13:15:01534 // Simulates a click on a Web Notification.
awdff8bdbe82016-10-14 09:42:32535 void SimulateWebNotificationClick(const std::string& title,
536 int action_index,
537 const base::NullableString16& reply);
[email protected]97f9a7952014-03-14 11:50:33538
nsatragno24bd34b2016-02-09 10:30:02539 // Simulates closing a Web Notification.
540 void SimulateWebNotificationClose(const std::string& title, bool by_user);
541
[email protected]56e365d42014-05-02 22:18:24542 // Speech recognition related functions.
[email protected]97f9a7952014-03-14 11:50:33543 void AddMockSpeechRecognitionResult(const std::string& transcript,
544 double confidence);
545 void SetMockSpeechRecognitionError(const std::string& error,
546 const std::string& message);
[email protected]97f9a7952014-03-14 11:50:33547
mkwst41667ab2014-09-16 06:52:43548 // Credential Manager mock functions
549 // TODO(mkwst): Support FederatedCredential.
tyoshino5138b3b92016-09-27 09:11:50550 void SetMockCredentialManagerResponse(const std::string& id,
mkwst41667ab2014-09-16 06:52:43551 const std::string& name,
552 const std::string& avatar,
553 const std::string& password);
tyoshino5138b3b92016-09-27 09:11:50554 void ClearMockCredentialManagerResponse();
555 void SetMockCredentialManagerError(const std::string& error);
mkwst41667ab2014-09-16 06:52:43556
lukasza083b4f12016-03-24 16:51:43557 // Takes care of notifying the delegate after a change to layout test runtime
558 // flags.
559 void OnLayoutTestRuntimeFlagsChanged();
lukaszac9cbe712016-03-14 14:06:43560
[email protected]97f9a7952014-03-14 11:50:33561 ///////////////////////////////////////////////////////////////////////////
562 // Internal helpers
[email protected]eec9e78e2014-06-16 21:38:48563
lukasza10cd8762016-04-27 20:03:02564 bool IsFramePartOfMainTestWindow(blink::WebFrame*) const;
565
[email protected]97f9a7952014-03-14 11:50:33566 void CheckResponseMimeType();
[email protected]97f9a7952014-03-14 11:50:33567
[email protected]97f9a7952014-03-14 11:50:33568 // In the Mac code, this is called to trigger the end of a test after the
569 // page has finished loading. From here, we can generate the dump for the
570 // test.
571 void LocationChangeDone();
572
573 bool test_is_running_;
574
575 // When reset is called, go through and close all but the main test shell
576 // window. By default, set to true but toggled to false using
577 // setCloseRemainingWindowsWhenComplete().
578 bool close_remaining_windows_;
579
[email protected]97f9a7952014-03-14 11:50:33580 WorkQueue work_queue_;
581
[email protected]97f9a7952014-03-14 11:50:33582 // Bound variable to return the name of this platform (chromium).
583 std::string platform_name_;
584
585 // Bound variable to store the last tooltip text
586 std::string tooltip_text_;
587
[email protected]97f9a7952014-03-14 11:50:33588 // Bound variable counting the number of top URLs visited.
589 int web_history_item_count_;
590
lukasza9b9d70e2016-02-25 23:45:44591 // Flags controlling what content gets dumped as a layout text result.
lukasza083b4f12016-03-24 16:51:43592 LayoutTestRuntimeFlags layout_test_runtime_flags_;
[email protected]97f9a7952014-03-14 11:50:33593
[email protected]97f9a7952014-03-14 11:50:33594 // If true, the test_shell will output a base64 encoded WAVE file.
595 bool dump_as_audio_;
596
[email protected]97f9a7952014-03-14 11:50:33597 // If true, the test_shell will produce a dump of the back forward list as
598 // well.
599 bool dump_back_forward_list_;
600
[email protected]97f9a7952014-03-14 11:50:33601 // If true, pixel dump will be produced as a series of 1px-tall, view-wide
602 // individual paints over the height of the view.
603 bool test_repaint_;
604
605 // If true and test_repaint_ is true as well, pixel dump will be produced as
606 // a series of 1px-wide, view-tall paints across the width of the view.
607 bool sweep_horizontally_;
608
toyoshim729663f2016-10-17 08:54:13609 // startSession() result of MockWebMIDIAccessor for testing.
610 midi::mojom::Result midi_accessor_result_;
[email protected]97f9a7952014-03-14 11:50:33611
[email protected]97f9a7952014-03-14 11:50:33612 std::set<std::string> http_headers_to_clear_;
613
614 // WAV audio data is stored here.
615 std::vector<unsigned char> audio_data_;
616
[email protected]79ecada2014-05-04 05:16:16617 TestInterfaces* test_interfaces_;
618 WebTestDelegate* delegate_;
lukasza8973c522016-04-27 16:32:28619 blink::WebView* main_view_;
[email protected]97f9a7952014-03-14 11:50:33620
621 // This is non-0 IFF a load is in progress.
622 blink::WebFrame* top_loading_frame_;
623
mlamouri007f9d72015-02-27 16:27:25624 // WebContentSettingsClient mock object.
dcheng82beb4f2016-04-26 00:35:02625 std::unique_ptr<MockContentSettingsClient> mock_content_settings_client_;
[email protected]97f9a7952014-03-14 11:50:33626
[email protected]97f9a7952014-03-14 11:50:33627 bool use_mock_theme_;
628
blundell987cb782016-08-17 17:25:37629 // This is true in the period between the start of a navigation and when the
630 // provisional load for that navigation is started. Note that when
631 // browser-side navigation is enabled there is an arbitrary gap between these
632 // two events.
633 bool will_navigate_;
634
dcheng82beb4f2016-04-26 00:35:02635 std::unique_ptr<MockCredentialManagerClient> credential_manager_client_;
636 std::unique_ptr<MockScreenOrientationClient> mock_screen_orientation_client_;
637 std::unique_ptr<MockWebSpeechRecognizer> speech_recognizer_;
638 std::unique_ptr<MockWebUserMediaClient> user_media_client_;
639 std::unique_ptr<SpellCheckClient> spellcheck_;
lukaszafd124602016-04-01 16:53:30640
641 // Number of currently active color choosers.
642 int chooser_count_;
lukasza6a113ae12016-03-17 22:41:20643
lukasza1b546c12016-04-04 16:19:20644 // Captured drag image.
645 blink::WebImage drag_image_;
646
lukasza95416be142016-04-14 15:06:33647 // View that was focused by a previous call to TestRunner::SetFocus method.
648 // Note - this can be a dangling pointer to an already destroyed WebView (this
649 // is ok, because this is taken care of in WebTestDelegate::SetFocus).
650 blink::WebView* previously_focused_view_;
651
Quinten Yearsley0d7709a2017-03-29 23:10:43652 // True when running a test in LayoutTests/external/wpt/.
tkent2edc979d2016-05-27 04:58:25653 bool is_web_platform_tests_mode_;
tkent003403482016-05-26 08:18:41654
jkarlin3bddb7d2016-09-21 18:44:16655 // An effective connection type settable by layout tests.
656 blink::WebEffectiveConnectionType effective_connection_type_;
657
pfeldman4c4133d2016-12-20 02:40:21658 // Forces v8 compilation cache to be disabled (used for inspector tests).
659 bool disable_v8_cache_ = false;
660
[email protected]97f9a7952014-03-14 11:50:33661 base::WeakPtrFactory<TestRunner> weak_factory_;
662
663 DISALLOW_COPY_AND_ASSIGN(TestRunner);
664};
665
jochenf5f31752015-06-03 12:06:34666} // namespace test_runner
[email protected]97f9a7952014-03-14 11:50:33667
dcheng59826e32017-02-22 10:31:36668#endif // CONTENT_SHELL_TEST_RUNNER_TEST_RUNNER_H_