blob: 4f5127502e7391f43f40e4423494eb3d204c8bf5 [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
jochen73e711c2015-06-03 10:01:465#ifndef COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_
6#define COMPONENTS_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"
lukasza083b4f12016-03-24 16:51:4318#include "components/test_runner/layout_test_runtime_flags.h"
jochen746754c52015-06-05 16:40:4119#include "components/test_runner/test_runner_export.h"
jochen73e711c2015-06-03 10:01:4620#include "components/test_runner/web_test_runner.h"
lukasza1b546c12016-04-04 16:19:2021#include "third_party/WebKit/public/platform/WebImage.h"
[email protected]97f9a7952014-03-14 11:50:3322#include "v8/include/v8.h"
23
[email protected]945babb2014-07-30 14:25:3224class GURL;
[email protected]eec9e78e2014-06-16 21:38:4825class SkBitmap;
26
[email protected]97f9a7952014-03-14 11:50:3327namespace blink {
mlamouri007f9d72015-02-27 16:27:2528class WebContentSettingsClient;
[email protected]97f9a7952014-03-14 11:50:3329class WebFrame;
lukaszab2ad0502016-04-27 15:51:4230class WebLocalFrame;
mcasas43ff56ff2015-10-08 05:24:3731class WebMediaStream;
[email protected]97f9a7952014-03-14 11:50:3332class WebString;
33class WebView;
kenneth.r.christiansen1a4946d2014-09-25 16:11:0634class WebURLResponse;
[email protected]97f9a7952014-03-14 11:50:3335}
36
37namespace gin {
38class ArrayBufferView;
39class Arguments;
40}
41
jochenf5f31752015-06-03 12:06:3442namespace test_runner {
[email protected]97f9a7952014-03-14 11:50:3343
[email protected]97d3fe8b2014-04-05 02:40:0044class InvokeCallbackTask;
lukasza21353232016-04-12 19:52:1145class MockContentSettingsClient;
lukasza5c2279c2016-04-05 16:44:4746class MockCredentialManagerClient;
lukasza6a113ae12016-03-17 22:41:2047class MockScreenOrientationClient;
lukasza01da2602016-04-05 14:51:2648class MockWebSpeechRecognizer;
lukaszafd124602016-04-01 16:53:3049class MockWebUserMediaClient;
lukasza5c2279c2016-04-05 16:44:4750class SpellCheckClient;
[email protected]79ecada2014-05-04 05:16:1651class TestInterfaces;
lukaszab2ad0502016-04-27 15:51:4252class TestRunnerForSpecificView;
[email protected]79ecada2014-05-04 05:16:1653class WebTestDelegate;
[email protected]a2ec0bc2014-04-23 08:18:2754class WebTestProxyBase;
[email protected]97f9a7952014-03-14 11:50:3355
lukaszab2ad0502016-04-27 15:51:4256// TestRunner class currently has dual purpose:
57// 1. It implements |testRunner| javascript bindings for "global" / "ambient".
58// Examples:
59// - testRunner.dumpAsText (test flag affecting test behavior)
60// - testRunner.setAllowDisplayOfInsecureContent (test flag affecting product
61// behavior)
62// - testRunner.setTextSubpixelPositioning (directly interacts with product).
63// Note that "per-view" (non-"global") bindings are handled by
64// instances of TestRunnerForSpecificView class.
65// 2. It manages global test state. Example:
66// - Tracking topLoadingFrame that can finish the test when it loads.
67// - WorkQueue holding load requests from the TestInterfaces
68// - LayoutTestRuntimeFlags
lukaszac9358822016-04-07 14:43:4669class TestRunner : public WebTestRunner {
[email protected]97f9a7952014-03-14 11:50:3370 public:
[email protected]79ecada2014-05-04 05:16:1671 explicit TestRunner(TestInterfaces*);
[email protected]97f9a7952014-03-14 11:50:3372 virtual ~TestRunner();
73
lukaszab2ad0502016-04-27 15:51:4274 void Install(blink::WebLocalFrame* frame,
75 base::WeakPtr<TestRunnerForSpecificView> view_test_runner);
[email protected]97f9a7952014-03-14 11:50:3376
[email protected]79ecada2014-05-04 05:16:1677 void SetDelegate(WebTestDelegate*);
lukaszaf41da4b2016-04-14 22:33:2078 void SetWebView(blink::WebView*);
[email protected]97f9a7952014-03-14 11:50:3379
80 void Reset();
81
[email protected]97f9a7952014-03-14 11:50:3382 void SetTestIsRunning(bool);
83 bool TestIsRunning() const { return test_is_running_; }
84
85 bool UseMockTheme() const { return use_mock_theme_; }
86
87 // WebTestRunner implementation.
dchenge933b3e2014-10-21 11:44:0988 bool ShouldGeneratePixelResults() override;
89 bool ShouldDumpAsAudio() const override;
90 void GetAudioData(std::vector<unsigned char>* buffer_view) const override;
lukaszaef264fc52016-03-17 22:49:1991 bool IsRecursiveLayoutDumpRequested() override;
92 std::string DumpLayout(blink::WebLocalFrame* frame) override;
lukasza1b546c12016-04-04 16:19:2093 void DumpPixelsAsync(
94 blink::WebView* web_view,
95 const base::Callback<void(const SkBitmap&)>& callback) override;
lukasza083b4f12016-03-24 16:51:4396 void ReplicateLayoutTestRuntimeFlagsChanges(
lukaszac9cbe712016-03-14 14:06:4397 const base::DictionaryValue& changed_values) override;
lukaszaa8960462016-01-27 22:27:3398 bool HasCustomTextDump(std::string* custom_text_dump) const override;
dchenge933b3e2014-10-21 11:44:0999 bool ShouldDumpBackForwardList() const override;
mlamouri007f9d72015-02-27 16:27:25100 blink::WebContentSettingsClient* GetWebContentSettings() const override;
lukasza5c2279c2016-04-05 16:44:47101 void InitializeWebViewWithMocks(blink::WebView* web_view) override;
lukasza95416be142016-04-14 15:06:33102 void SetFocus(blink::WebView* web_view, bool focus) override;
[email protected]97f9a7952014-03-14 11:50:33103
lukasza01da2602016-04-05 14:51:26104 // Methods used by WebViewTestClient and WebFrameTestClient.
105 void OnAnimationScheduled(blink::WebView* view);
106 void OnAnimationBegun(blink::WebView* view);
lukaszaa0b624a2016-04-04 15:00:49107 std::string GetAcceptLanguages() const;
lukaszae26c3d62016-03-14 23:30:59108 bool shouldStayOnPageAfterHandlingBeforeUnload() const;
lukasza6a113ae12016-03-17 22:41:20109 MockScreenOrientationClient* getMockScreenOrientationClient();
lukaszafd124602016-04-01 16:53:30110 MockWebUserMediaClient* getMockWebUserMediaClient();
lukasza01da2602016-04-05 14:51:26111 MockWebSpeechRecognizer* getMockWebSpeechRecognizer();
[email protected]97f9a7952014-03-14 11:50:33112 bool isPrinting() const;
[email protected]f24836a2014-05-06 01:02:44113 bool shouldDumpAsCustomText() const;
114 std:: string customDumpText() const;
abhishek.a21ca9b5602014-09-19 07:33:33115 void ShowDevTools(const std::string& settings,
[email protected]06c253012014-04-16 18:35:33116 const std::string& frontend_url);
abhishek.a21ca9b5602014-09-19 07:33:33117 void ClearDevToolsLocalStorage();
[email protected]97f9a7952014-03-14 11:50:33118 void setShouldDumpAsText(bool);
119 void setShouldDumpAsMarkup(bool);
ki.stfu939799a42015-09-28 04:41:20120 void setCustomTextOutput(const std::string& text);
[email protected]97f9a7952014-03-14 11:50:33121 void setShouldGeneratePixelResults(bool);
122 void setShouldDumpFrameLoadCallbacks(bool);
[email protected]97f9a7952014-03-14 11:50:33123 void setShouldEnableViewSource(bool);
124 bool shouldDumpEditingCallbacks() const;
125 bool shouldDumpFrameLoadCallbacks() const;
126 bool shouldDumpPingLoaderCallbacks() const;
127 bool shouldDumpUserGestureInFrameLoadCallbacks() const;
128 bool shouldDumpTitleChanges() const;
129 bool shouldDumpIconChanges() const;
130 bool shouldDumpCreateView() const;
131 bool canOpenWindows() const;
132 bool shouldDumpResourceLoadCallbacks() const;
[email protected]97f9a7952014-03-14 11:50:33133 bool shouldDumpResourceResponseMIMETypes() const;
134 bool shouldDumpStatusCallbacks() const;
[email protected]97f9a7952014-03-14 11:50:33135 bool shouldDumpSpellCheckCallbacks() const;
[email protected]a79cb9912014-04-26 22:07:33136 bool shouldWaitUntilExternalURLLoad() const;
[email protected]97f9a7952014-03-14 11:50:33137 const std::set<std::string>* httpHeadersToClear() const;
138 void setTopLoadingFrame(blink::WebFrame*, bool);
139 blink::WebFrame* topLoadingFrame() const;
140 void policyDelegateDone();
141 bool policyDelegateEnabled() const;
142 bool policyDelegateIsPermissive() const;
143 bool policyDelegateShouldNotifyDone() const;
144 bool shouldInterceptPostMessage() const;
145 bool shouldDumpResourcePriorities() const;
[email protected]97f9a7952014-03-14 11:50:33146 void setToolTipText(const blink::WebString&);
lukasza1b546c12016-04-04 16:19:20147 void setDragImage(const blink::WebImage& drag_image);
jochenc3a98da12015-03-10 13:59:58148 bool shouldDumpNavigationPolicy() const;
[email protected]97f9a7952014-03-14 11:50:33149
150 bool midiAccessorResult();
151
lukaszafd124602016-04-01 16:53:30152 // Methods used by MockColorChooser:
153 void DidOpenChooser();
154 void DidCloseChooser();
155
[email protected]97f9a7952014-03-14 11:50:33156 // A single item in the work queue.
157 class WorkItem {
158 public:
159 virtual ~WorkItem() {}
160
161 // Returns true if this started a load.
[email protected]79ecada2014-05-04 05:16:16162 virtual bool Run(WebTestDelegate*, blink::WebView*) = 0;
[email protected]97f9a7952014-03-14 11:50:33163 };
164
165 private:
[email protected]97f9a7952014-03-14 11:50:33166 friend class TestRunnerBindings;
167 friend class WorkQueue;
168
169 // Helper class for managing events queued by methods like queueLoad or
170 // queueScript.
171 class WorkQueue {
172 public:
173 explicit WorkQueue(TestRunner* controller);
174 virtual ~WorkQueue();
175 void ProcessWorkSoon();
176
177 // Reset the state of the class between tests.
178 void Reset();
179
180 void AddWork(WorkItem*);
181
182 void set_frozen(bool frozen) { frozen_ = frozen; }
183 bool is_empty() { return queue_.empty(); }
[email protected]97f9a7952014-03-14 11:50:33184
185 private:
186 void ProcessWork();
187
[email protected]97f9a7952014-03-14 11:50:33188 std::deque<WorkItem*> queue_;
189 bool frozen_;
190 TestRunner* controller_;
lukaszac9358822016-04-07 14:43:46191
192 base::WeakPtrFactory<WorkQueue> weak_factory_;
[email protected]97f9a7952014-03-14 11:50:33193 };
194
195 ///////////////////////////////////////////////////////////////////////////
196 // Methods dealing with the test logic
197
198 // By default, tests end when page load is complete. These methods are used
199 // to delay the completion of the test until notifyDone is called.
200 void NotifyDone();
201 void WaitUntilDone();
202
203 // Methods for adding actions to the work queue. Used in conjunction with
204 // waitUntilDone/notifyDone above.
205 void QueueBackNavigation(int how_far_back);
206 void QueueForwardNavigation(int how_far_forward);
207 void QueueReload();
208 void QueueLoadingScript(const std::string& script);
209 void QueueNonLoadingScript(const std::string& script);
210 void QueueLoad(const std::string& url, const std::string& target);
[email protected]97f9a7952014-03-14 11:50:33211
212 // Causes navigation actions just printout the intended navigation instead
213 // of taking you to the page. This is used for cases like mailto, where you
214 // don't actually want to open the mail program.
215 void SetCustomPolicyDelegate(gin::Arguments* args);
216
217 // Delays completion of the test until the policy delegate runs.
218 void WaitForPolicyDelegate();
219
220 // Functions for dealing with windows. By default we block all new windows.
221 int WindowCount();
222 void SetCloseRemainingWindowsWhenComplete(bool close_remaining_windows);
223 void ResetTestHelperControllers();
224
[email protected]97f9a7952014-03-14 11:50:33225 // Allows layout tests to manage origins' whitelisting.
226 void AddOriginAccessWhitelistEntry(const std::string& source_origin,
227 const std::string& destination_protocol,
228 const std::string& destination_host,
229 bool allow_destination_subdomains);
230 void RemoveOriginAccessWhitelistEntry(const std::string& source_origin,
231 const std::string& destination_protocol,
232 const std::string& destination_host,
233 bool allow_destination_subdomains);
234
dcheng9000dbd2015-04-03 05:39:40235 // Add |source_code| as an injected stylesheet to the active document of the
236 // window of the current V8 context.
237 void InsertStyleSheet(const std::string& source_code);
238
[email protected]97f9a7952014-03-14 11:50:33239 // Enables or disables subpixel positioning (i.e. fractional X positions for
240 // glyphs) in text rendering on Linux. Since this method changes global
241 // settings, tests that call it must use their own custom font family for
242 // all text that they render. If not, an already-cached style will be used,
243 // resulting in the changed setting being ignored.
244 void SetTextSubpixelPositioning(bool value);
245
[email protected]97f9a7952014-03-14 11:50:33246 // After this function is called, all window-sizing machinery is
247 // short-circuited inside the renderer. This mode is necessary for
248 // some tests that were written before browsers had multi-process architecture
249 // and rely on window resizes to happen synchronously.
250 // The function has "unfortunate" it its name because we must strive to remove
251 // all tests that rely on this... well, unfortunate behavior. See
252 // http://crbug.com/309760 for the plan.
253 void UseUnfortunateSynchronousResizeMode();
254
255 bool EnableAutoResizeMode(int min_width,
256 int min_height,
257 int max_width,
258 int max_height);
259 bool DisableAutoResizeMode(int new_width, int new_height);
260
[email protected]2ad7e622014-06-30 17:44:21261 void SetMockDeviceLight(double value);
262 void ResetDeviceLight();
[email protected]97f9a7952014-03-14 11:50:33263 // Device Motion / Device Orientation related functions
264 void SetMockDeviceMotion(bool has_acceleration_x, double acceleration_x,
265 bool has_acceleration_y, double acceleration_y,
266 bool has_acceleration_z, double acceleration_z,
267 bool has_acceleration_including_gravity_x,
268 double acceleration_including_gravity_x,
269 bool has_acceleration_including_gravity_y,
270 double acceleration_including_gravity_y,
271 bool has_acceleration_including_gravity_z,
272 double acceleration_including_gravity_z,
273 bool has_rotation_rate_alpha,
274 double rotation_rate_alpha,
275 bool has_rotation_rate_beta,
276 double rotation_rate_beta,
277 bool has_rotation_rate_gamma,
278 double rotation_rate_gamma,
279 double interval);
280 void SetMockDeviceOrientation(bool has_alpha, double alpha,
281 bool has_beta, double beta,
282 bool has_gamma, double gamma,
philipj97906452016-03-02 14:46:22283 bool absolute);
[email protected]97f9a7952014-03-14 11:50:33284
[email protected]e0bc2cb2014-03-20 17:34:24285 void SetMockScreenOrientation(const std::string& orientation);
dgozman3c16f7f2016-02-26 01:21:18286 void DisableMockScreenOrientation();
[email protected]e0bc2cb2014-03-20 17:34:24287
[email protected]97f9a7952014-03-14 11:50:33288 ///////////////////////////////////////////////////////////////////////////
289 // Methods modifying WebPreferences.
290
291 // Set the WebPreference that controls webkit's popup blocking.
292 void SetPopupBlockingEnabled(bool block_popups);
293
294 void SetJavaScriptCanAccessClipboard(bool can_access);
295 void SetXSSAuditorEnabled(bool enabled);
296 void SetAllowUniversalAccessFromFileURLs(bool allow);
297 void SetAllowFileAccessFromFileURLs(bool allow);
ki.stfu939799a42015-09-28 04:41:20298 void OverridePreference(const std::string& key, v8::Local<v8::Value> value);
[email protected]97f9a7952014-03-14 11:50:33299
[email protected]ebd5ea52014-05-28 14:51:15300 // Modify accept_languages in RendererPreferences.
301 void SetAcceptLanguages(const std::string& accept_languages);
302
[email protected]97f9a7952014-03-14 11:50:33303 // Enable or disable plugins.
304 void SetPluginsEnabled(bool enabled);
305
lukasza01da2602016-04-05 14:51:26306 // Returns |true| if an animation has been scheduled in one or more WebViews
307 // participating in the layout test.
308 bool GetAnimationScheduled() const;
chrishtraea6066d2016-02-19 04:49:12309
[email protected]97f9a7952014-03-14 11:50:33310 ///////////////////////////////////////////////////////////////////////////
311 // Methods that modify the state of TestRunner
312
313 // This function sets a flag that tells the test_shell to print a line of
314 // descriptive text for each editing command. It takes no arguments, and
315 // ignores any that may be present.
316 void DumpEditingCallbacks();
317
318 // This function sets a flag that tells the test_shell to dump pages as
319 // plain text, rather than as a text representation of the renderer's state.
320 // The pixel results will not be generated for this test.
321 void DumpAsText();
322
323 // This function sets a flag that tells the test_shell to dump pages as
[email protected]fdc433c02014-06-02 19:27:14324 // the DOM contents, rather than as a text representation of the renderer's
325 // state. The pixel results will not be generated for this test.
326 void DumpAsMarkup();
327
328 // This function sets a flag that tells the test_shell to dump pages as
[email protected]97f9a7952014-03-14 11:50:33329 // plain text, rather than as a text representation of the renderer's state.
330 // It will also generate a pixel dump for the test.
331 void DumpAsTextWithPixelResults();
332
333 // This function sets a flag that tells the test_shell to print out the
334 // scroll offsets of the child frames. It ignores all.
335 void DumpChildFrameScrollPositions();
336
337 // This function sets a flag that tells the test_shell to recursively
338 // dump all frames as plain text if the DumpAsText flag is set.
339 // It takes no arguments, and ignores any that may be present.
340 void DumpChildFramesAsText();
341
[email protected]fdc433c02014-06-02 19:27:14342 // This function sets a flag that tells the test_shell to recursively
343 // dump all frames as the DOM contents if the DumpAsMarkup flag is set.
344 // It takes no arguments, and ignores any that may be present.
345 void DumpChildFramesAsMarkup();
346
[email protected]97f9a7952014-03-14 11:50:33347 // This function sets a flag that tells the test_shell to print out the
348 // information about icon changes notifications from WebKit.
349 void DumpIconChanges();
350
351 // Deals with Web Audio WAV file data.
352 void SetAudioData(const gin::ArrayBufferView& view);
353
354 // This function sets a flag that tells the test_shell to print a line of
355 // descriptive text for each frame load callback. It takes no arguments, and
356 // ignores any that may be present.
357 void DumpFrameLoadCallbacks();
358
359 // This function sets a flag that tells the test_shell to print a line of
360 // descriptive text for each PingLoader dispatch. It takes no arguments, and
361 // ignores any that may be present.
362 void DumpPingLoaderCallbacks();
363
364 // This function sets a flag that tells the test_shell to print a line of
365 // user gesture status text for some frame load callbacks. It takes no
366 // arguments, and ignores any that may be present.
367 void DumpUserGestureInFrameLoadCallbacks();
368
369 void DumpTitleChanges();
370
371 // This function sets a flag that tells the test_shell to dump all calls to
372 // WebViewClient::createView().
373 // It takes no arguments, and ignores any that may be present.
374 void DumpCreateView();
375
376 void SetCanOpenWindows();
377
378 // This function sets a flag that tells the test_shell to dump a descriptive
379 // line for each resource load callback. It takes no arguments, and ignores
380 // any that may be present.
381 void DumpResourceLoadCallbacks();
382
[email protected]97f9a7952014-03-14 11:50:33383 // This function sets a flag that tells the test_shell to dump the MIME type
384 // for each resource that was loaded. It takes no arguments, and ignores any
385 // that may be present.
386 void DumpResourceResponseMIMETypes();
387
mlamouri007f9d72015-02-27 16:27:25388 // WebContentSettingsClient related.
[email protected]97f9a7952014-03-14 11:50:33389 void SetImagesAllowed(bool allowed);
[email protected]e19024b92014-06-10 11:10:37390 void SetMediaAllowed(bool allowed);
[email protected]97f9a7952014-03-14 11:50:33391 void SetScriptsAllowed(bool allowed);
392 void SetStorageAllowed(bool allowed);
393 void SetPluginsAllowed(bool allowed);
394 void SetAllowDisplayOfInsecureContent(bool allowed);
395 void SetAllowRunningOfInsecureContent(bool allowed);
396 void DumpPermissionClientCallbacks();
397
398 // This function sets a flag that tells the test_shell to dump all calls
399 // to window.status().
400 // It takes no arguments, and ignores any that may be present.
401 void DumpWindowStatusChanges();
402
[email protected]97f9a7952014-03-14 11:50:33403 // This function sets a flag that tells the test_shell to dump all
404 // the lines of descriptive text about spellcheck execution.
405 void DumpSpellCheckCallbacks();
406
407 // This function sets a flag that tells the test_shell to print out a text
408 // representation of the back/forward list. It ignores all arguments.
409 void DumpBackForwardList();
410
411 void DumpSelectionRect();
[email protected]97f9a7952014-03-14 11:50:33412
413 // Causes layout to happen as if targetted to printed pages.
414 void SetPrinting();
415
[email protected]52846102014-06-24 04:26:44416 // Clears the state from SetPrinting().
417 void ClearPrinting();
418
[email protected]97f9a7952014-03-14 11:50:33419 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
420
421 // Causes WillSendRequest to clear certain headers.
422 void SetWillSendRequestClearHeader(const std::string& header);
423
424 // This function sets a flag that tells the test_shell to dump a descriptive
425 // line for each resource load's priority and any time that priority
426 // changes. It takes no arguments, and ignores any that may be present.
427 void DumpResourceRequestPriorities();
428
429 // Sets a flag to enable the mock theme.
430 void SetUseMockTheme(bool use);
431
[email protected]a79cb9912014-04-26 22:07:33432 // Sets a flag that causes the test to be marked as completed when the
433 // WebFrameClient receives a loadURLExternally() call.
434 void WaitUntilExternalURLLoad();
435
lukasza1b546c12016-04-04 16:19:20436 // This function sets a flag to dump the drag image when the next drag&drop is
437 // initiated. It is equivalent to DumpAsTextWithPixelResults but the pixel
438 // results will be the drag image instead of a snapshot of the page.
jackhou656fc852015-02-13 09:04:17439 void DumpDragImage();
440
jochenc3a98da12015-03-10 13:59:58441 // Sets a flag that tells the WebTestProxy to dump the default navigation
442 // policy passed to the decidePolicyForNavigation callback.
443 void DumpNavigationPolicy();
444
[email protected]97f9a7952014-03-14 11:50:33445 ///////////////////////////////////////////////////////////////////////////
446 // Methods interacting with the WebTestProxy
447
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
456 // Inspect chooser state
457 bool IsChooserShown();
458
459 // Allows layout tests to exec scripts at WebInspector side.
460 void EvaluateInWebInspector(int call_id, const std::string& script);
sergeyv0cd842b42015-10-09 16:07:11461 // Allows layout tests to evaluate scripts in InspectorOverlay page.
462 // Script may have an output represented as a string, return values of other
463 // types would be ignored.
464 std::string EvaluateInWebInspectorOverlay(const std::string& script);
[email protected]97f9a7952014-03-14 11:50:33465
466 // Clears all databases.
467 void ClearAllDatabases();
468 // Sets the default quota for all origins
469 void SetDatabaseQuota(int quota);
470
471 // Changes the cookie policy from the default to allow all cookies.
472 void SetAlwaysAcceptCookies(bool accept);
473
[email protected]97f9a7952014-03-14 11:50:33474 // Converts a URL starting with file:///tmp/ to the local mapping.
475 std::string PathToLocalResource(const std::string& path);
476
mek340dd9d2014-12-11 02:10:46477 // Enables mock geofencing service while running a layout test.
478 // |service_available| indicates if the mock service should mock geofencing
479 // being available or not.
480 void SetGeofencingMockProvider(bool service_available);
481
482 // Disables mock geofencing service while running a layout test.
483 void ClearGeofencingMockProvider();
484
485 // Set the mock geofencing position while running a layout test.
486 void SetGeofencingMockPosition(double latitude, double longitude);
487
mlamourid5098d02015-04-21 12:17:30488 // Sets the permission's |name| to |value| for a given {origin, embedder}
489 // tuple.
490 void SetPermission(const std::string& name,
491 const std::string& value,
492 const GURL& origin,
493 const GURL& embedding_origin);
494
benwells0c0d3f12015-05-25 01:03:17495 // Resolve the beforeinstallprompt event with the matching request id.
496 void ResolveBeforeInstallPromptPromise(int request_id,
497 const std::string& platform);
498
[email protected]97f9a7952014-03-14 11:50:33499 // Calls setlocale(LC_ALL, ...) for a specified locale.
500 // Resets between tests.
501 void SetPOSIXLocale(const std::string& locale);
502
503 // MIDI function to control permission handling.
504 void SetMIDIAccessorResult(bool result);
[email protected]97f9a7952014-03-14 11:50:33505
peterd98157d2014-11-20 13:15:01506 // Simulates a click on a Web Notification.
johnme96d50122015-08-07 15:33:21507 void SimulateWebNotificationClick(const std::string& title, int action_index);
[email protected]97f9a7952014-03-14 11:50:33508
nsatragno24bd34b2016-02-09 10:30:02509 // Simulates closing a Web Notification.
510 void SimulateWebNotificationClose(const std::string& title, bool by_user);
511
[email protected]56e365d42014-05-02 22:18:24512 // Speech recognition related functions.
[email protected]97f9a7952014-03-14 11:50:33513 void AddMockSpeechRecognitionResult(const std::string& transcript,
514 double confidence);
515 void SetMockSpeechRecognitionError(const std::string& error,
516 const std::string& message);
[email protected]97f9a7952014-03-14 11:50:33517
mkwst41667ab2014-09-16 06:52:43518 // Credential Manager mock functions
519 // TODO(mkwst): Support FederatedCredential.
520 void AddMockCredentialManagerResponse(const std::string& id,
521 const std::string& name,
522 const std::string& avatar,
523 const std::string& password);
mkwst008acce62016-03-11 13:02:01524 void AddMockCredentialManagerError(const std::string& error);
mkwst41667ab2014-09-16 06:52:43525
lukasza083b4f12016-03-24 16:51:43526 // Takes care of notifying the delegate after a change to layout test runtime
527 // flags.
528 void OnLayoutTestRuntimeFlagsChanged();
lukaszac9cbe712016-03-14 14:06:43529
[email protected]97f9a7952014-03-14 11:50:33530 ///////////////////////////////////////////////////////////////////////////
531 // Internal helpers
[email protected]eec9e78e2014-06-16 21:38:48532
[email protected]97f9a7952014-03-14 11:50:33533 void CheckResponseMimeType();
534 void CompleteNotifyDone();
535
[email protected]97f9a7952014-03-14 11:50:33536 // In the Mac code, this is called to trigger the end of a test after the
537 // page has finished loading. From here, we can generate the dump for the
538 // test.
539 void LocationChangeDone();
540
541 bool test_is_running_;
542
543 // When reset is called, go through and close all but the main test shell
544 // window. By default, set to true but toggled to false using
545 // setCloseRemainingWindowsWhenComplete().
546 bool close_remaining_windows_;
547
[email protected]97f9a7952014-03-14 11:50:33548 WorkQueue work_queue_;
549
[email protected]97f9a7952014-03-14 11:50:33550 // Bound variable to return the name of this platform (chromium).
551 std::string platform_name_;
552
553 // Bound variable to store the last tooltip text
554 std::string tooltip_text_;
555
[email protected]97f9a7952014-03-14 11:50:33556 // Bound variable counting the number of top URLs visited.
557 int web_history_item_count_;
558
lukasza9b9d70e2016-02-25 23:45:44559 // Flags controlling what content gets dumped as a layout text result.
lukasza083b4f12016-03-24 16:51:43560 LayoutTestRuntimeFlags layout_test_runtime_flags_;
[email protected]97f9a7952014-03-14 11:50:33561
[email protected]97f9a7952014-03-14 11:50:33562 // If true, the test_shell will output a base64 encoded WAVE file.
563 bool dump_as_audio_;
564
[email protected]97f9a7952014-03-14 11:50:33565 // If true, output a descriptive line each time WebViewClient::createView
566 // is invoked.
567 bool dump_create_view_;
568
569 // If true, new windows can be opened via javascript or by plugins. By
570 // default, set to false and can be toggled to true using
571 // setCanOpenWindows().
572 bool can_open_windows_;
573
[email protected]97f9a7952014-03-14 11:50:33574 // If true, the test_shell will dump all changes to window.status.
575 bool dump_window_status_changes_;
576
[email protected]97f9a7952014-03-14 11:50:33577 // If true, the test_shell will output descriptive test for spellcheck
578 // execution.
579 bool dump_spell_check_callbacks_;
580
581 // If true, the test_shell will produce a dump of the back forward list as
582 // well.
583 bool dump_back_forward_list_;
584
[email protected]97f9a7952014-03-14 11:50:33585 // If true, pixel dump will be produced as a series of 1px-tall, view-wide
586 // individual paints over the height of the view.
587 bool test_repaint_;
588
589 // If true and test_repaint_ is true as well, pixel dump will be produced as
590 // a series of 1px-wide, view-tall paints across the width of the view.
591 bool sweep_horizontally_;
592
[email protected]97f9a7952014-03-14 11:50:33593 // If false, MockWebMIDIAccessor fails on startSession() for testing.
594 bool midi_accessor_result_;
595
[email protected]f24836a2014-05-06 01:02:44596 bool has_custom_text_output_;
597 std::string custom_text_output_;
598
[email protected]97f9a7952014-03-14 11:50:33599 std::set<std::string> http_headers_to_clear_;
600
601 // WAV audio data is stored here.
602 std::vector<unsigned char> audio_data_;
603
[email protected]79ecada2014-05-04 05:16:16604 TestInterfaces* test_interfaces_;
605 WebTestDelegate* delegate_;
[email protected]97f9a7952014-03-14 11:50:33606 blink::WebView* web_view_;
[email protected]97f9a7952014-03-14 11:50:33607
608 // This is non-0 IFF a load is in progress.
609 blink::WebFrame* top_loading_frame_;
610
mlamouri007f9d72015-02-27 16:27:25611 // WebContentSettingsClient mock object.
dcheng82beb4f2016-04-26 00:35:02612 std::unique_ptr<MockContentSettingsClient> mock_content_settings_client_;
[email protected]97f9a7952014-03-14 11:50:33613
[email protected]97f9a7952014-03-14 11:50:33614 bool use_mock_theme_;
615
dcheng82beb4f2016-04-26 00:35:02616 std::unique_ptr<MockCredentialManagerClient> credential_manager_client_;
617 std::unique_ptr<MockScreenOrientationClient> mock_screen_orientation_client_;
618 std::unique_ptr<MockWebSpeechRecognizer> speech_recognizer_;
619 std::unique_ptr<MockWebUserMediaClient> user_media_client_;
620 std::unique_ptr<SpellCheckClient> spellcheck_;
lukaszafd124602016-04-01 16:53:30621
622 // Number of currently active color choosers.
623 int chooser_count_;
lukasza6a113ae12016-03-17 22:41:20624
lukasza1b546c12016-04-04 16:19:20625 // Captured drag image.
626 blink::WebImage drag_image_;
627
lukasza95416be142016-04-14 15:06:33628 // View that was focused by a previous call to TestRunner::SetFocus method.
629 // Note - this can be a dangling pointer to an already destroyed WebView (this
630 // is ok, because this is taken care of in WebTestDelegate::SetFocus).
631 blink::WebView* previously_focused_view_;
632
lukasza01da2602016-04-05 14:51:26633 std::set<blink::WebView*> views_with_scheduled_animations_;
634
[email protected]97f9a7952014-03-14 11:50:33635 base::WeakPtrFactory<TestRunner> weak_factory_;
636
637 DISALLOW_COPY_AND_ASSIGN(TestRunner);
638};
639
lukaszab2ad0502016-04-27 15:51:42640// TestRunnerForSpecificView implements part of |testRunner| javascript bindings
641// that work with a view where the javascript call originated from. Examples:
642// - testRunner.capturePixelsAsyncThen
643// - testRunner.setPageVisibility
644// Note that "global" bindings are handled by TestRunner class.
645// TODO(lukasza): Move this class to a separate compilation unit.
646class TestRunnerForSpecificView {
647 public:
648 explicit TestRunnerForSpecificView(WebTestProxyBase* web_test_proxy_base);
649 ~TestRunnerForSpecificView();
650
651 // Installs view-specific bindings (handled by |this|) and *also* global
652 // TestRunner bindings (both kinds of bindings are exposed via a single
653 // |testRunner| object in javascript).
654 void Install(blink::WebLocalFrame* frame);
655
656 void Reset();
657
658 // Pointer lock methods used by WebViewTestClient.
659 bool RequestPointerLock();
660 void RequestPointerUnlock();
661 bool isPointerLocked();
662
663 private:
664 friend class TestRunnerBindings;
665
666 // Helpers for working with base and V8 callbacks.
667 void PostTask(const base::Closure& callback);
668 void PostDelayedTask(long long delay, const base::Closure& callback);
669 void PostV8Callback(const v8::Local<v8::Function>& callback);
670 void PostV8CallbackWithArgs(v8::UniquePersistent<v8::Function> callback,
671 int argc,
672 v8::Local<v8::Value> argv[]);
673 void InvokeV8Callback(const v8::UniquePersistent<v8::Function>& callback);
674 void InvokeV8CallbackWithArgs(
675 const v8::UniquePersistent<v8::Function>& callback,
676 const std::vector<v8::UniquePersistent<v8::Value>>& args);
677 base::Closure CreateClosureThatPostsV8Callback(
678 const v8::Local<v8::Function>& callback);
679
680 void LayoutAndPaintAsync();
681 void LayoutAndPaintAsyncThen(v8::Local<v8::Function> callback);
682
683 // Similar to LayoutAndPaintAsyncThen(), but pass parameters of the captured
684 // snapshot (width, height, snapshot) to the callback. The snapshot is in
685 // uint8_t RGBA format.
686 void CapturePixelsAsyncThen(v8::Local<v8::Function> callback);
687 void CapturePixelsCallback(v8::UniquePersistent<v8::Function> callback,
688 const SkBitmap& snapshot);
689
690 // Similar to CapturePixelsAsyncThen(). Copies to the clipboard the image
691 // located at a particular point in the WebView (if there is such an image),
692 // reads back its pixels, and provides the snapshot to the callback. If there
693 // is no image at that point, calls the callback with (0, 0, empty_snapshot).
694 void CopyImageAtAndCapturePixelsAsyncThen(
695 int x,
696 int y,
697 const v8::Local<v8::Function> callback);
698
699 void GetManifestThen(v8::Local<v8::Function> callback);
700 void GetManifestCallback(v8::UniquePersistent<v8::Function> callback,
701 const blink::WebURLResponse& response,
702 const std::string& data);
703
704 // Calls |callback| with a DOMString[] representing the events recorded since
705 // the last call to this function.
706 void GetBluetoothManualChooserEvents(v8::Local<v8::Function> callback);
707 void GetBluetoothManualChooserEventsCallback(
708 v8::UniquePersistent<v8::Function> callback,
709 const std::vector<std::string>& events);
710
711 // Change the bluetooth test data while running a layout test.
712 void SetBluetoothFakeAdapter(const std::string& adapter_name,
713 v8::Local<v8::Function> callback);
714
715 // If |enable| is true, makes the Bluetooth chooser record its input and wait
716 // for instructions from the test program on how to proceed. Otherwise falls
717 // back to the browser's default chooser.
718 void SetBluetoothManualChooser(bool enable);
719
720 // Calls the BluetoothChooser::EventHandler with the arguments here. Valid
721 // event strings are:
722 // * "cancel" - simulates the user canceling the chooser.
723 // * "select" - simulates the user selecting a device whose device ID is in
724 // |argument|.
725 void SendBluetoothManualChooserEvent(const std::string& event,
726 const std::string& argument);
727
728 // Used to set the device scale factor.
729 void SetBackingScaleFactor(double value, v8::Local<v8::Function> callback);
730
731 // Enable zoom-for-dsf option.
732 // TODO(oshima): Remove this once all platforms migrated.
733 void EnableUseZoomForDSF(v8::Local<v8::Function> callback);
734
735 // Change the device color profile while running a layout test.
736 void SetColorProfile(const std::string& name,
737 v8::Local<v8::Function> callback);
738
739 // Causes the beforeinstallprompt event to be sent to the renderer.
740 void DispatchBeforeInstallPromptEvent(
741 int request_id,
742 const std::vector<std::string>& event_platforms,
743 v8::Local<v8::Function> callback);
744 void DispatchBeforeInstallPromptCallback(
745 v8::UniquePersistent<v8::Function> callback,
746 bool canceled);
747
748 // Immediately run all pending idle tasks, including all pending
749 // requestIdleCallback calls. Invoke the callback when all
750 // idle tasks are complete.
751 void RunIdleTasks(v8::Local<v8::Function> callback);
752
753 // Method that controls whether pressing Tab key cycles through page elements
754 // or inserts a '\t' char in text area
755 void SetTabKeyCyclesThroughElements(bool tab_key_cycles_through_elements);
756
757 // Executes an internal command (superset of document.execCommand() commands).
758 void ExecCommand(gin::Arguments* args);
759
760 // Checks if an internal command is currently available.
761 bool IsCommandEnabled(const std::string& command);
762
763 // Returns true if the current page box has custom page size style for
764 // printing.
765 bool HasCustomPageSizeStyle(int page_index);
766
767 // Forces the selection colors for testing under Linux.
768 void ForceRedSelectionColors();
769
770 // Switch the visibility of the page.
771 void SetPageVisibility(const std::string& new_visibility);
772
773 // Changes the direction of the focused element.
774 void SetTextDirection(const std::string& direction_name);
775
776 // Dump current PageImportanceSignals for the page.
777 void DumpPageImportanceSignals();
778
779 // WebPageOverlay related functions. Permits the adding and removing of only
780 // one opaque overlay.
781 void AddWebPageOverlay();
782 void RemoveWebPageOverlay();
783
784 // Sets a flag causing the next call to WebGLRenderingContext::create to fail.
785 void ForceNextWebGLContextCreationToFail();
786
787 // Sets a flag causing the next call to DrawingBuffer::create to fail.
788 void ForceNextDrawingBufferCreationToFail();
789
790 // Gives focus to the view associated with TestRunnerForSpecificView.
791 void SetWindowIsKey(bool value);
792
793 // Pointer lock handling.
794 void DidAcquirePointerLock();
795 void DidNotAcquirePointerLock();
796 void DidLosePointerLock();
797 void SetPointerLockWillFailSynchronously();
798 void SetPointerLockWillRespondAsynchronously();
799 void DidAcquirePointerLockInternal();
800 void DidNotAcquirePointerLockInternal();
801 void DidLosePointerLockInternal();
802 bool pointer_locked_;
803 enum {
804 PointerLockWillSucceed,
805 PointerLockWillRespondAsync,
806 PointerLockWillFailSync,
807 } pointer_lock_planned_result_;
808
809 bool CallShouldCloseOnWebView();
810 void SetDomainRelaxationForbiddenForURLScheme(bool forbidden,
811 const std::string& scheme);
812 v8::Local<v8::Value> EvaluateScriptInIsolatedWorldAndReturnValue(
813 int world_id,
814 const std::string& script);
815 void EvaluateScriptInIsolatedWorld(int world_id, const std::string& script);
816 void SetIsolatedWorldSecurityOrigin(int world_id,
817 v8::Local<v8::Value> origin);
818 void SetIsolatedWorldContentSecurityPolicy(int world_id,
819 const std::string& policy);
820 bool FindString(const std::string& search_text,
821 const std::vector<std::string>& options_array);
822 std::string SelectionAsMarkup();
823 void SetViewSourceForFrame(const std::string& name, bool enabled);
824
825 // Helpers for accessing pointers exposed by |web_test_proxy_base_|.
826 blink::WebView* web_view();
827 WebTestDelegate* delegate();
828 WebTestProxyBase* web_test_proxy_base_;
829
830 base::WeakPtrFactory<TestRunnerForSpecificView> weak_factory_;
831
832 DISALLOW_COPY_AND_ASSIGN(TestRunnerForSpecificView);
833};
834
jochenf5f31752015-06-03 12:06:34835} // namespace test_runner
[email protected]97f9a7952014-03-14 11:50:33836
jochen73e711c2015-06-03 10:01:46837#endif // COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_