blob: d9b08a18804b9e401a086659ae8453250848bfaf [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>
11#include <set>
12#include <string>
benwells0c0d3f12015-05-25 01:03:1713#include <vector>
[email protected]97f9a7952014-03-14 11:50:3314
avi5dd91f82015-12-25 22:30:4615#include "base/macros.h"
[email protected]97f9a7952014-03-14 11:50:3316#include "base/memory/scoped_ptr.h"
17#include "base/memory/weak_ptr.h"
jochen746754c52015-06-05 16:40:4118#include "components/test_runner/test_runner_export.h"
jochen73e711c2015-06-03 10:01:4619#include "components/test_runner/web_task.h"
20#include "components/test_runner/web_test_runner.h"
[email protected]97f9a7952014-03-14 11:50:3321#include "v8/include/v8.h"
22
[email protected]945babb2014-07-30 14:25:3223class GURL;
[email protected]eec9e78e2014-06-16 21:38:4824class SkBitmap;
25
[email protected]97f9a7952014-03-14 11:50:3326namespace blink {
mlamouri007f9d72015-02-27 16:27:2527class WebContentSettingsClient;
[email protected]97f9a7952014-03-14 11:50:3328class WebFrame;
mcasas43ff56ff2015-10-08 05:24:3729class WebMediaStream;
[email protected]97f9a7952014-03-14 11:50:3330class WebString;
31class WebView;
kenneth.r.christiansen1a4946d2014-09-25 16:11:0632class WebURLResponse;
[email protected]97f9a7952014-03-14 11:50:3333}
34
35namespace gin {
36class ArrayBufferView;
37class Arguments;
38}
39
jochenf5f31752015-06-03 12:06:3440namespace test_runner {
[email protected]97f9a7952014-03-14 11:50:3341
[email protected]97d3fe82014-04-05 02:40:0042class InvokeCallbackTask;
[email protected]79ecada2014-05-04 05:16:1643class TestInterfaces;
mlamouri007f9d72015-02-27 16:27:2544class WebContentSettings;
[email protected]79ecada2014-05-04 05:16:1645class WebTestDelegate;
[email protected]a2ec0bc2014-04-23 08:18:2746class WebTestProxyBase;
[email protected]97f9a7952014-03-14 11:50:3347
[email protected]79ecada2014-05-04 05:16:1648class TestRunner : public WebTestRunner,
[email protected]97f9a7952014-03-14 11:50:3349 public base::SupportsWeakPtr<TestRunner> {
50 public:
[email protected]79ecada2014-05-04 05:16:1651 explicit TestRunner(TestInterfaces*);
[email protected]97f9a7952014-03-14 11:50:3352 virtual ~TestRunner();
53
54 void Install(blink::WebFrame* frame);
55
[email protected]79ecada2014-05-04 05:16:1656 void SetDelegate(WebTestDelegate*);
[email protected]a2ec0bc2014-04-23 08:18:2757 void SetWebView(blink::WebView*, WebTestProxyBase*);
[email protected]97f9a7952014-03-14 11:50:3358
59 void Reset();
60
[email protected]a1640e42014-05-14 13:43:3261 WebTaskList* mutable_task_list() { return &task_list_; }
[email protected]97f9a7952014-03-14 11:50:3362
63 void SetTestIsRunning(bool);
64 bool TestIsRunning() const { return test_is_running_; }
65
66 bool UseMockTheme() const { return use_mock_theme_; }
67
[email protected]97d3fe82014-04-05 02:40:0068 void InvokeCallback(scoped_ptr<InvokeCallbackTask> callback);
69
[email protected]97f9a7952014-03-14 11:50:3370 // WebTestRunner implementation.
dchenge933b3e2014-10-21 11:44:0971 bool ShouldGeneratePixelResults() override;
jochen746754c52015-06-05 16:40:4172 bool ShouldStayOnPageAfterHandlingBeforeUnload() const override;
dchenge933b3e2014-10-21 11:44:0973 bool ShouldDumpAsAudio() const override;
74 void GetAudioData(std::vector<unsigned char>* buffer_view) const override;
lukaszaa8960462016-01-27 22:27:3375 LayoutDumpFlags GetLayoutDumpFlags() override;
76 bool HasCustomTextDump(std::string* custom_text_dump) const override;
dchenge933b3e2014-10-21 11:44:0977 bool ShouldDumpBackForwardList() const override;
mlamouri007f9d72015-02-27 16:27:2578 blink::WebContentSettingsClient* GetWebContentSettings() const override;
[email protected]97f9a7952014-03-14 11:50:3379
80 // Methods used by WebTestProxyBase.
81 bool shouldDumpSelectionRect() const;
[email protected]97f9a7952014-03-14 11:50:3382 bool isPrinting() const;
83 bool shouldDumpAsText();
84 bool shouldDumpAsTextWithPixelResults();
[email protected]f24836a2014-05-06 01:02:4485 bool shouldDumpAsCustomText() const;
86 std:: string customDumpText() const;
[email protected]97f9a7952014-03-14 11:50:3387 bool shouldDumpAsMarkup();
88 bool shouldDumpChildFrameScrollPositions() const;
[email protected]fdc433c02014-06-02 19:27:1489 bool shouldDumpChildFramesAsMarkup() const;
[email protected]97f9a7952014-03-14 11:50:3390 bool shouldDumpChildFramesAsText() const;
abhishek.a21ca9b5602014-09-19 07:33:3391 void ShowDevTools(const std::string& settings,
[email protected]06c253012014-04-16 18:35:3392 const std::string& frontend_url);
abhishek.a21ca9b5602014-09-19 07:33:3393 void ClearDevToolsLocalStorage();
[email protected]97f9a7952014-03-14 11:50:3394 void setShouldDumpAsText(bool);
95 void setShouldDumpAsMarkup(bool);
ki.stfu939799a42015-09-28 04:41:2096 void setCustomTextOutput(const std::string& text);
[email protected]97f9a7952014-03-14 11:50:3397 void setShouldGeneratePixelResults(bool);
98 void setShouldDumpFrameLoadCallbacks(bool);
99 void setShouldDumpPingLoaderCallbacks(bool);
100 void setShouldEnableViewSource(bool);
101 bool shouldDumpEditingCallbacks() const;
102 bool shouldDumpFrameLoadCallbacks() const;
103 bool shouldDumpPingLoaderCallbacks() const;
104 bool shouldDumpUserGestureInFrameLoadCallbacks() const;
105 bool shouldDumpTitleChanges() const;
106 bool shouldDumpIconChanges() const;
107 bool shouldDumpCreateView() const;
108 bool canOpenWindows() const;
109 bool shouldDumpResourceLoadCallbacks() const;
110 bool shouldDumpResourceRequestCallbacks() const;
111 bool shouldDumpResourceResponseMIMETypes() const;
112 bool shouldDumpStatusCallbacks() const;
[email protected]97f9a7952014-03-14 11:50:33113 bool shouldDumpSpellCheckCallbacks() const;
[email protected]a79cb9912014-04-26 22:07:33114 bool shouldWaitUntilExternalURLLoad() const;
[email protected]97f9a7952014-03-14 11:50:33115 const std::set<std::string>* httpHeadersToClear() const;
116 void setTopLoadingFrame(blink::WebFrame*, bool);
117 blink::WebFrame* topLoadingFrame() const;
118 void policyDelegateDone();
119 bool policyDelegateEnabled() const;
120 bool policyDelegateIsPermissive() const;
121 bool policyDelegateShouldNotifyDone() const;
122 bool shouldInterceptPostMessage() const;
123 bool shouldDumpResourcePriorities() const;
[email protected]97f9a7952014-03-14 11:50:33124 bool RequestPointerLock();
125 void RequestPointerUnlock();
126 bool isPointerLocked();
127 void setToolTipText(const blink::WebString&);
jackhou656fc852015-02-13 09:04:17128 bool shouldDumpDragImage();
jochenc3a98da12015-03-10 13:59:58129 bool shouldDumpNavigationPolicy() const;
[email protected]97f9a7952014-03-14 11:50:33130
131 bool midiAccessorResult();
132
133 // A single item in the work queue.
134 class WorkItem {
135 public:
136 virtual ~WorkItem() {}
137
138 // Returns true if this started a load.
[email protected]79ecada2014-05-04 05:16:16139 virtual bool Run(WebTestDelegate*, blink::WebView*) = 0;
[email protected]97f9a7952014-03-14 11:50:33140 };
141
142 private:
143 friend class InvokeCallbackTask;
144 friend class TestRunnerBindings;
145 friend class WorkQueue;
146
147 // Helper class for managing events queued by methods like queueLoad or
148 // queueScript.
149 class WorkQueue {
150 public:
151 explicit WorkQueue(TestRunner* controller);
152 virtual ~WorkQueue();
153 void ProcessWorkSoon();
154
155 // Reset the state of the class between tests.
156 void Reset();
157
158 void AddWork(WorkItem*);
159
160 void set_frozen(bool frozen) { frozen_ = frozen; }
161 bool is_empty() { return queue_.empty(); }
[email protected]a1640e42014-05-14 13:43:32162 WebTaskList* mutable_task_list() { return &task_list_; }
[email protected]97f9a7952014-03-14 11:50:33163
164 private:
165 void ProcessWork();
166
[email protected]79ecada2014-05-04 05:16:16167 class WorkQueueTask : public WebMethodTask<WorkQueue> {
[email protected]97f9a7952014-03-14 11:50:33168 public:
[email protected]79ecada2014-05-04 05:16:16169 WorkQueueTask(WorkQueue* object) : WebMethodTask<WorkQueue>(object) {}
[email protected]97f9a7952014-03-14 11:50:33170
dchenge933b3e2014-10-21 11:44:09171 void RunIfValid() override;
[email protected]97f9a7952014-03-14 11:50:33172 };
173
[email protected]79ecada2014-05-04 05:16:16174 WebTaskList task_list_;
[email protected]97f9a7952014-03-14 11:50:33175 std::deque<WorkItem*> queue_;
176 bool frozen_;
177 TestRunner* controller_;
178 };
179
180 ///////////////////////////////////////////////////////////////////////////
181 // Methods dealing with the test logic
182
183 // By default, tests end when page load is complete. These methods are used
184 // to delay the completion of the test until notifyDone is called.
185 void NotifyDone();
186 void WaitUntilDone();
187
188 // Methods for adding actions to the work queue. Used in conjunction with
189 // waitUntilDone/notifyDone above.
190 void QueueBackNavigation(int how_far_back);
191 void QueueForwardNavigation(int how_far_forward);
192 void QueueReload();
193 void QueueLoadingScript(const std::string& script);
194 void QueueNonLoadingScript(const std::string& script);
195 void QueueLoad(const std::string& url, const std::string& target);
196 void QueueLoadHTMLString(gin::Arguments* args);
197
198 // Causes navigation actions just printout the intended navigation instead
199 // of taking you to the page. This is used for cases like mailto, where you
200 // don't actually want to open the mail program.
201 void SetCustomPolicyDelegate(gin::Arguments* args);
202
203 // Delays completion of the test until the policy delegate runs.
204 void WaitForPolicyDelegate();
205
206 // Functions for dealing with windows. By default we block all new windows.
207 int WindowCount();
208 void SetCloseRemainingWindowsWhenComplete(bool close_remaining_windows);
209 void ResetTestHelperControllers();
210
211 ///////////////////////////////////////////////////////////////////////////
212 // Methods implemented entirely in terms of chromium's public WebKit API
213
214 // Method that controls whether pressing Tab key cycles through page elements
215 // or inserts a '\t' char in text area
216 void SetTabKeyCyclesThroughElements(bool tab_key_cycles_through_elements);
217
218 // Executes an internal command (superset of document.execCommand() commands).
219 void ExecCommand(gin::Arguments* args);
220
221 // Checks if an internal command is currently available.
222 bool IsCommandEnabled(const std::string& command);
223
224 bool CallShouldCloseOnWebView();
225 void SetDomainRelaxationForbiddenForURLScheme(bool forbidden,
226 const std::string& scheme);
deepak.s750d68f2015-04-30 07:32:41227 v8::Local<v8::Value> EvaluateScriptInIsolatedWorldAndReturnValue(
[email protected]97f9a7952014-03-14 11:50:33228 int world_id, const std::string& script);
229 void EvaluateScriptInIsolatedWorld(int world_id, const std::string& script);
230 void SetIsolatedWorldSecurityOrigin(int world_id,
deepak.s750d68f2015-04-30 07:32:41231 v8::Local<v8::Value> origin);
[email protected]97f9a7952014-03-14 11:50:33232 void SetIsolatedWorldContentSecurityPolicy(int world_id,
233 const std::string& policy);
234
235 // Allows layout tests to manage origins' whitelisting.
236 void AddOriginAccessWhitelistEntry(const std::string& source_origin,
237 const std::string& destination_protocol,
238 const std::string& destination_host,
239 bool allow_destination_subdomains);
240 void RemoveOriginAccessWhitelistEntry(const std::string& source_origin,
241 const std::string& destination_protocol,
242 const std::string& destination_host,
243 bool allow_destination_subdomains);
244
245 // Returns true if the current page box has custom page size style for
246 // printing.
247 bool HasCustomPageSizeStyle(int page_index);
248
249 // Forces the selection colors for testing under Linux.
250 void ForceRedSelectionColors();
251
dcheng9000dbd2015-04-03 05:39:40252 // Add |source_code| as an injected stylesheet to the active document of the
253 // window of the current V8 context.
254 void InsertStyleSheet(const std::string& source_code);
255
[email protected]97f9a7952014-03-14 11:50:33256 bool FindString(const std::string& search_text,
257 const std::vector<std::string>& options_array);
258
259 std::string SelectionAsMarkup();
260
261 // Enables or disables subpixel positioning (i.e. fractional X positions for
262 // glyphs) in text rendering on Linux. Since this method changes global
263 // settings, tests that call it must use their own custom font family for
264 // all text that they render. If not, an already-cached style will be used,
265 // resulting in the changed setting being ignored.
266 void SetTextSubpixelPositioning(bool value);
267
268 // Switch the visibility of the page.
269 void SetPageVisibility(const std::string& new_visibility);
270
271 // Changes the direction of the focused element.
272 void SetTextDirection(const std::string& direction_name);
273
274 // After this function is called, all window-sizing machinery is
275 // short-circuited inside the renderer. This mode is necessary for
276 // some tests that were written before browsers had multi-process architecture
277 // and rely on window resizes to happen synchronously.
278 // The function has "unfortunate" it its name because we must strive to remove
279 // all tests that rely on this... well, unfortunate behavior. See
280 // http://crbug.com/309760 for the plan.
281 void UseUnfortunateSynchronousResizeMode();
282
283 bool EnableAutoResizeMode(int min_width,
284 int min_height,
285 int max_width,
286 int max_height);
287 bool DisableAutoResizeMode(int new_width, int new_height);
288
[email protected]2ad7e622014-06-30 17:44:21289 void SetMockDeviceLight(double value);
290 void ResetDeviceLight();
[email protected]97f9a7952014-03-14 11:50:33291 // Device Motion / Device Orientation related functions
292 void SetMockDeviceMotion(bool has_acceleration_x, double acceleration_x,
293 bool has_acceleration_y, double acceleration_y,
294 bool has_acceleration_z, double acceleration_z,
295 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);
308 void SetMockDeviceOrientation(bool has_alpha, double alpha,
309 bool has_beta, double beta,
310 bool has_gamma, double gamma,
311 bool has_absolute, bool absolute);
312
[email protected]e0bc2cb2014-03-20 17:34:24313 void SetMockScreenOrientation(const std::string& orientation);
314
[email protected]de7c9e72014-06-03 22:30:26315 void DidChangeBatteryStatus(bool charging,
316 double chargingTime,
317 double dischargingTime,
318 double level);
319 void ResetBatteryStatus();
320
[email protected]97f9a7952014-03-14 11:50:33321 void DidAcquirePointerLock();
322 void DidNotAcquirePointerLock();
323 void DidLosePointerLock();
324 void SetPointerLockWillFailSynchronously();
325 void SetPointerLockWillRespondAsynchronously();
326
327 ///////////////////////////////////////////////////////////////////////////
328 // Methods modifying WebPreferences.
329
330 // Set the WebPreference that controls webkit's popup blocking.
331 void SetPopupBlockingEnabled(bool block_popups);
332
333 void SetJavaScriptCanAccessClipboard(bool can_access);
334 void SetXSSAuditorEnabled(bool enabled);
335 void SetAllowUniversalAccessFromFileURLs(bool allow);
336 void SetAllowFileAccessFromFileURLs(bool allow);
ki.stfu939799a42015-09-28 04:41:20337 void OverridePreference(const std::string& key, v8::Local<v8::Value> value);
[email protected]97f9a7952014-03-14 11:50:33338
[email protected]ebd5ea52014-05-28 14:51:15339 // Modify accept_languages in RendererPreferences.
340 void SetAcceptLanguages(const std::string& accept_languages);
341
[email protected]97f9a7952014-03-14 11:50:33342 // Enable or disable plugins.
343 void SetPluginsEnabled(bool enabled);
344
345 ///////////////////////////////////////////////////////////////////////////
346 // Methods that modify the state of TestRunner
347
348 // This function sets a flag that tells the test_shell to print a line of
349 // descriptive text for each editing command. It takes no arguments, and
350 // ignores any that may be present.
351 void DumpEditingCallbacks();
352
353 // This function sets a flag that tells the test_shell to dump pages as
354 // plain text, rather than as a text representation of the renderer's state.
355 // The pixel results will not be generated for this test.
356 void DumpAsText();
357
358 // This function sets a flag that tells the test_shell to dump pages as
[email protected]fdc433c02014-06-02 19:27:14359 // the DOM contents, rather than as a text representation of the renderer's
360 // state. The pixel results will not be generated for this test.
361 void DumpAsMarkup();
362
363 // This function sets a flag that tells the test_shell to dump pages as
[email protected]97f9a7952014-03-14 11:50:33364 // plain text, rather than as a text representation of the renderer's state.
365 // It will also generate a pixel dump for the test.
366 void DumpAsTextWithPixelResults();
367
368 // This function sets a flag that tells the test_shell to print out the
369 // scroll offsets of the child frames. It ignores all.
370 void DumpChildFrameScrollPositions();
371
372 // This function sets a flag that tells the test_shell to recursively
373 // dump all frames as plain text if the DumpAsText flag is set.
374 // It takes no arguments, and ignores any that may be present.
375 void DumpChildFramesAsText();
376
[email protected]fdc433c02014-06-02 19:27:14377 // This function sets a flag that tells the test_shell to recursively
378 // dump all frames as the DOM contents if the DumpAsMarkup flag is set.
379 // It takes no arguments, and ignores any that may be present.
380 void DumpChildFramesAsMarkup();
381
[email protected]97f9a7952014-03-14 11:50:33382 // This function sets a flag that tells the test_shell to print out the
383 // information about icon changes notifications from WebKit.
384 void DumpIconChanges();
385
386 // Deals with Web Audio WAV file data.
387 void SetAudioData(const gin::ArrayBufferView& view);
388
389 // This function sets a flag that tells the test_shell to print a line of
390 // descriptive text for each frame load callback. It takes no arguments, and
391 // ignores any that may be present.
392 void DumpFrameLoadCallbacks();
393
394 // This function sets a flag that tells the test_shell to print a line of
395 // descriptive text for each PingLoader dispatch. It takes no arguments, and
396 // ignores any that may be present.
397 void DumpPingLoaderCallbacks();
398
399 // This function sets a flag that tells the test_shell to print a line of
400 // user gesture status text for some frame load callbacks. It takes no
401 // arguments, and ignores any that may be present.
402 void DumpUserGestureInFrameLoadCallbacks();
403
404 void DumpTitleChanges();
405
406 // This function sets a flag that tells the test_shell to dump all calls to
407 // WebViewClient::createView().
408 // It takes no arguments, and ignores any that may be present.
409 void DumpCreateView();
410
411 void SetCanOpenWindows();
412
413 // This function sets a flag that tells the test_shell to dump a descriptive
414 // line for each resource load callback. It takes no arguments, and ignores
415 // any that may be present.
416 void DumpResourceLoadCallbacks();
417
418 // This function sets a flag that tells the test_shell to print a line of
419 // descriptive text for each element that requested a resource. It takes no
420 // arguments, and ignores any that may be present.
421 void DumpResourceRequestCallbacks();
422
423 // This function sets a flag that tells the test_shell to dump the MIME type
424 // for each resource that was loaded. It takes no arguments, and ignores any
425 // that may be present.
426 void DumpResourceResponseMIMETypes();
427
mlamouri007f9d72015-02-27 16:27:25428 // WebContentSettingsClient related.
[email protected]97f9a7952014-03-14 11:50:33429 void SetImagesAllowed(bool allowed);
[email protected]e19024b92014-06-10 11:10:37430 void SetMediaAllowed(bool allowed);
[email protected]97f9a7952014-03-14 11:50:33431 void SetScriptsAllowed(bool allowed);
432 void SetStorageAllowed(bool allowed);
433 void SetPluginsAllowed(bool allowed);
434 void SetAllowDisplayOfInsecureContent(bool allowed);
435 void SetAllowRunningOfInsecureContent(bool allowed);
436 void DumpPermissionClientCallbacks();
437
438 // This function sets a flag that tells the test_shell to dump all calls
439 // to window.status().
440 // It takes no arguments, and ignores any that may be present.
441 void DumpWindowStatusChanges();
442
[email protected]97f9a7952014-03-14 11:50:33443 // This function sets a flag that tells the test_shell to dump all
444 // the lines of descriptive text about spellcheck execution.
445 void DumpSpellCheckCallbacks();
446
447 // This function sets a flag that tells the test_shell to print out a text
448 // representation of the back/forward list. It ignores all arguments.
449 void DumpBackForwardList();
450
451 void DumpSelectionRect();
[email protected]97f9a7952014-03-14 11:50:33452
453 // Causes layout to happen as if targetted to printed pages.
454 void SetPrinting();
455
[email protected]52846102014-06-24 04:26:44456 // Clears the state from SetPrinting().
457 void ClearPrinting();
458
[email protected]97f9a7952014-03-14 11:50:33459 void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
460
461 // Causes WillSendRequest to clear certain headers.
462 void SetWillSendRequestClearHeader(const std::string& header);
463
464 // This function sets a flag that tells the test_shell to dump a descriptive
465 // line for each resource load's priority and any time that priority
466 // changes. It takes no arguments, and ignores any that may be present.
467 void DumpResourceRequestPriorities();
468
469 // Sets a flag to enable the mock theme.
470 void SetUseMockTheme(bool use);
471
[email protected]a79cb9912014-04-26 22:07:33472 // Sets a flag that causes the test to be marked as completed when the
473 // WebFrameClient receives a loadURLExternally() call.
474 void WaitUntilExternalURLLoad();
475
jackhou656fc852015-02-13 09:04:17476 // This function sets a flag which tells the WebTestProxy to dump the drag
477 // image when the next drag-and-drop is initiated. It is equivalent to
478 // DumpAsTextWithPixelResults but the pixel results will be the drag image
479 // instead of a snapshot of the page.
480 void DumpDragImage();
481
jochenc3a98da12015-03-10 13:59:58482 // Sets a flag that tells the WebTestProxy to dump the default navigation
483 // policy passed to the decidePolicyForNavigation callback.
484 void DumpNavigationPolicy();
485
kouhei503bf4e2015-11-05 04:59:04486 // Dump current PageImportanceSignals for the page.
487 void DumpPageImportanceSignals();
488
[email protected]97f9a7952014-03-14 11:50:33489 ///////////////////////////////////////////////////////////////////////////
490 // Methods interacting with the WebTestProxy
491
492 ///////////////////////////////////////////////////////////////////////////
493 // Methods forwarding to the WebTestDelegate
494
495 // Shows DevTools window.
[email protected]06c253012014-04-16 18:35:33496 void ShowWebInspector(const std::string& str,
497 const std::string& frontend_url);
[email protected]97f9a7952014-03-14 11:50:33498 void CloseWebInspector();
499
500 // Inspect chooser state
501 bool IsChooserShown();
502
503 // Allows layout tests to exec scripts at WebInspector side.
504 void EvaluateInWebInspector(int call_id, const std::string& script);
sergeyv0cd842b42015-10-09 16:07:11505 // Allows layout tests to evaluate scripts in InspectorOverlay page.
506 // Script may have an output represented as a string, return values of other
507 // types would be ignored.
508 std::string EvaluateInWebInspectorOverlay(const std::string& script);
[email protected]97f9a7952014-03-14 11:50:33509
510 // Clears all databases.
511 void ClearAllDatabases();
512 // Sets the default quota for all origins
513 void SetDatabaseQuota(int quota);
514
515 // Changes the cookie policy from the default to allow all cookies.
516 void SetAlwaysAcceptCookies(bool accept);
517
518 // Gives focus to the window.
519 void SetWindowIsKey(bool value);
520
521 // Converts a URL starting with file:///tmp/ to the local mapping.
522 std::string PathToLocalResource(const std::string& path);
523
524 // Used to set the device scale factor.
deepak.s750d68f2015-04-30 07:32:41525 void SetBackingScaleFactor(double value, v8::Local<v8::Function> callback);
[email protected]97f9a7952014-03-14 11:50:33526
oshima841bbae2015-12-18 08:14:29527 // Enable zoom-for-dsf option.
528 // TODO(oshima): Remove this once all platforms migrated.
529 void EnableUseZoomForDSF(v8::Local<v8::Function> callback);
530
[email protected]71e652302014-05-09 14:20:13531 // Change the device color profile while running a layout test.
532 void SetColorProfile(const std::string& name,
deepak.s750d68f2015-04-30 07:32:41533 v8::Local<v8::Function> callback);
[email protected]71e652302014-05-09 14:20:13534
jyasskin8057c002015-09-10 19:09:53535 // Change the bluetooth test data while running a layout test and resets the
536 // chooser to accept the first device.
scheib834f26902014-11-05 23:57:26537 void SetBluetoothMockDataSet(const std::string& name);
538
jyasskin8057c002015-09-10 19:09:53539 // Makes the Bluetooth chooser record its input and wait for instructions from
540 // the test program on how to proceed.
541 void SetBluetoothManualChooser();
542
jyasskina5cef8f2015-09-22 16:20:26543 // Calls |callback| with a DOMString[] representing the events recorded since
544 // the last call to this function.
545 void GetBluetoothManualChooserEvents(v8::Local<v8::Function> callback);
jyasskin8057c002015-09-10 19:09:53546
547 // Calls the BluetoothChooser::EventHandler with the arguments here. Valid
548 // event strings are:
549 // * "cancel" - simulates the user canceling the chooser.
550 // * "select" - simulates the user selecting a device whose device ID is in
551 // |argument|.
552 void SendBluetoothManualChooserEvent(const std::string& event,
553 const std::string& argument);
554
mek340dd9d2014-12-11 02:10:46555 // Enables mock geofencing service while running a layout test.
556 // |service_available| indicates if the mock service should mock geofencing
557 // being available or not.
558 void SetGeofencingMockProvider(bool service_available);
559
560 // Disables mock geofencing service while running a layout test.
561 void ClearGeofencingMockProvider();
562
563 // Set the mock geofencing position while running a layout test.
564 void SetGeofencingMockPosition(double latitude, double longitude);
565
mlamourid5098d02015-04-21 12:17:30566 // Sets the permission's |name| to |value| for a given {origin, embedder}
567 // tuple.
568 void SetPermission(const std::string& name,
569 const std::string& value,
570 const GURL& origin,
571 const GURL& embedding_origin);
572
benwells0c0d3f12015-05-25 01:03:17573 // Causes the beforeinstallprompt event to be sent to the renderer.
574 void DispatchBeforeInstallPromptEvent(
575 int request_id,
576 const std::vector<std::string>& event_platforms,
577 v8::Local<v8::Function> callback);
578
579 // Resolve the beforeinstallprompt event with the matching request id.
580 void ResolveBeforeInstallPromptPromise(int request_id,
581 const std::string& platform);
582
[email protected]97f9a7952014-03-14 11:50:33583 // Calls setlocale(LC_ALL, ...) for a specified locale.
584 // Resets between tests.
585 void SetPOSIXLocale(const std::string& locale);
586
587 // MIDI function to control permission handling.
588 void SetMIDIAccessorResult(bool result);
[email protected]97f9a7952014-03-14 11:50:33589
peterd98157d2014-11-20 13:15:01590 // Simulates a click on a Web Notification.
johnme96d50122015-08-07 15:33:21591 void SimulateWebNotificationClick(const std::string& title, int action_index);
[email protected]97f9a7952014-03-14 11:50:33592
nsatragno24bd34b2016-02-09 10:30:02593 // Simulates closing a Web Notification.
594 void SimulateWebNotificationClose(const std::string& title, bool by_user);
595
[email protected]56e365d42014-05-02 22:18:24596 // Speech recognition related functions.
[email protected]97f9a7952014-03-14 11:50:33597 void AddMockSpeechRecognitionResult(const std::string& transcript,
598 double confidence);
599 void SetMockSpeechRecognitionError(const std::string& error,
600 const std::string& message);
601 bool WasMockSpeechRecognitionAborted();
602
mkwst41667ab2014-09-16 06:52:43603 // Credential Manager mock functions
604 // TODO(mkwst): Support FederatedCredential.
605 void AddMockCredentialManagerResponse(const std::string& id,
606 const std::string& name,
607 const std::string& avatar,
608 const std::string& password);
609
[email protected]97f9a7952014-03-14 11:50:33610 // WebPageOverlay related functions. Permits the adding and removing of only
611 // one opaque overlay.
612 void AddWebPageOverlay();
613 void RemoveWebPageOverlay();
614
wangxianzhu372112e2015-05-06 23:01:57615 void LayoutAndPaintAsync();
616 void LayoutAndPaintAsyncThen(v8::Local<v8::Function> callback);
[email protected]97f9a7952014-03-14 11:50:33617
wangxianzhu372112e2015-05-06 23:01:57618 // Similar to LayoutAndPaintAsyncThen(), but pass parameters of the captured
[email protected]52846102014-06-24 04:26:44619 // snapshot (width, height, snapshot) to the callback. The snapshot is in
avi5dd91f82015-12-25 22:30:46620 // uint8_t RGBA format.
deepak.s750d68f2015-04-30 07:32:41621 void CapturePixelsAsyncThen(v8::Local<v8::Function> callback);
[email protected]9285cdc2014-07-18 15:42:25622 // Similar to CapturePixelsAsyncThen(). Copies to the clipboard the image
623 // located at a particular point in the WebView (if there is such an image),
624 // reads back its pixels, and provides the snapshot to the callback. If there
625 // is no image at that point, calls the callback with (0, 0, empty_snapshot).
626 void CopyImageAtAndCapturePixelsAsyncThen(
deepak.s750d68f2015-04-30 07:32:41627 int x, int y, const v8::Local<v8::Function> callback);
[email protected]eec9e78e2014-06-16 21:38:48628
deepak.s750d68f2015-04-30 07:32:41629 void GetManifestThen(v8::Local<v8::Function> callback);
kenneth.r.christiansen1a4946d2014-09-25 16:11:06630
[email protected]97f9a7952014-03-14 11:50:33631 ///////////////////////////////////////////////////////////////////////////
632 // Internal helpers
[email protected]eec9e78e2014-06-16 21:38:48633
kenneth.r.christiansen1a4946d2014-09-25 16:11:06634 void GetManifestCallback(scoped_ptr<InvokeCallbackTask> task,
635 const blink::WebURLResponse& response,
636 const std::string& data);
[email protected]eec9e78e2014-06-16 21:38:48637 void CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task,
638 const SkBitmap& snapshot);
benwells0c0d3f12015-05-25 01:03:17639 void DispatchBeforeInstallPromptCallback(scoped_ptr<InvokeCallbackTask> task,
640 bool canceled);
jyasskina5cef8f2015-09-22 16:20:26641 void GetBluetoothManualChooserEventsCallback(
642 scoped_ptr<InvokeCallbackTask> task,
643 const std::vector<std::string>& events);
[email protected]eec9e78e2014-06-16 21:38:48644
[email protected]97f9a7952014-03-14 11:50:33645 void CheckResponseMimeType();
646 void CompleteNotifyDone();
647
648 void DidAcquirePointerLockInternal();
649 void DidNotAcquirePointerLockInternal();
650 void DidLosePointerLockInternal();
651
652 // In the Mac code, this is called to trigger the end of a test after the
653 // page has finished loading. From here, we can generate the dump for the
654 // test.
655 void LocationChangeDone();
656
siva.gunturi3ccb61442014-11-14 01:55:13657 // Sets a flag causing the next call to WebGLRenderingContext::create to fail.
658 void ForceNextWebGLContextCreationToFail();
659
bajonesf6f00b002015-05-28 00:01:43660 // Sets a flag causing the next call to DrawingBuffer::create to fail.
661 void ForceNextDrawingBufferCreationToFail();
662
[email protected]97f9a7952014-03-14 11:50:33663 bool test_is_running_;
664
665 // When reset is called, go through and close all but the main test shell
666 // window. By default, set to true but toggled to false using
667 // setCloseRemainingWindowsWhenComplete().
668 bool close_remaining_windows_;
669
670 // If true, don't dump output until notifyDone is called.
671 bool wait_until_done_;
672
[email protected]a79cb9912014-04-26 22:07:33673 // If true, ends the test when a URL is loaded externally via
674 // WebFrameClient::loadURLExternally().
675 bool wait_until_external_url_load_;
676
[email protected]97f9a7952014-03-14 11:50:33677 // Causes navigation actions just printout the intended navigation instead
678 // of taking you to the page. This is used for cases like mailto, where you
679 // don't actually want to open the mail program.
680 bool policy_delegate_enabled_;
681
682 // Toggles the behavior of the policy delegate. If true, then navigations
683 // will be allowed. Otherwise, they will be ignored (dropped).
684 bool policy_delegate_is_permissive_;
685
686 // If true, the policy delegate will signal layout test completion.
687 bool policy_delegate_should_notify_done_;
688
689 WorkQueue work_queue_;
690
[email protected]97f9a7952014-03-14 11:50:33691 // Bound variable to return the name of this platform (chromium).
692 std::string platform_name_;
693
694 // Bound variable to store the last tooltip text
695 std::string tooltip_text_;
696
697 // Bound variable to disable notifyDone calls. This is used in GC leak
698 // tests, where existing LayoutTests are loaded within an iframe. The GC
699 // test harness will set this flag to ignore the notifyDone calls from the
700 // target LayoutTest.
701 bool disable_notify_done_;
702
703 // Bound variable counting the number of top URLs visited.
704 int web_history_item_count_;
705
706 // Bound variable to set whether postMessages should be intercepted or not
707 bool intercept_post_message_;
708
709 // If true, the test_shell will write a descriptive line for each editing
710 // command.
711 bool dump_editting_callbacks_;
712
713 // If true, the test_shell will generate pixel results in DumpAsText mode
714 bool generate_pixel_results_;
715
716 // If true, the test_shell will produce a plain text dump rather than a
717 // text representation of the renderer.
718 bool dump_as_text_;
719
720 // If true and if dump_as_text_ is true, the test_shell will recursively
721 // dump all frames as plain text.
722 bool dump_child_frames_as_text_;
723
724 // If true, the test_shell will produce a dump of the DOM rather than a text
725 // representation of the renderer.
726 bool dump_as_markup_;
727
[email protected]fdc433c02014-06-02 19:27:14728 // If true and if dump_as_markup_ is true, the test_shell will recursively
729 // produce a dump of the DOM rather than a text representation of the
730 // renderer.
731 bool dump_child_frames_as_markup_;
732
[email protected]97f9a7952014-03-14 11:50:33733 // If true, the test_shell will print out the child frame scroll offsets as
734 // well.
735 bool dump_child_frame_scroll_positions_;
736
737 // If true, the test_shell will print out the icon change notifications.
738 bool dump_icon_changes_;
739
740 // If true, the test_shell will output a base64 encoded WAVE file.
741 bool dump_as_audio_;
742
743 // If true, the test_shell will output a descriptive line for each frame
744 // load callback.
745 bool dump_frame_load_callbacks_;
746
747 // If true, the test_shell will output a descriptive line for each
748 // PingLoader dispatched.
749 bool dump_ping_loader_callbacks_;
750
751 // If true, the test_shell will output a line of the user gesture status
752 // text for some frame load callbacks.
753 bool dump_user_gesture_in_frame_load_callbacks_;
754
755 // If true, output a message when the page title is changed.
756 bool dump_title_changes_;
757
758 // If true, output a descriptive line each time WebViewClient::createView
759 // is invoked.
760 bool dump_create_view_;
761
762 // If true, new windows can be opened via javascript or by plugins. By
763 // default, set to false and can be toggled to true using
764 // setCanOpenWindows().
765 bool can_open_windows_;
766
767 // If true, the test_shell will output a descriptive line for each resource
768 // load callback.
769 bool dump_resource_load_callbacks_;
770
771 // If true, the test_shell will output a descriptive line for each resource
772 // request callback.
773 bool dump_resource_request_callbacks_;
774
775 // If true, the test_shell will output the MIME type for each resource that
776 // was loaded.
jbroman37b021e2015-05-08 17:30:25777 bool dump_resource_response_mime_types_;
[email protected]97f9a7952014-03-14 11:50:33778
779 // If true, the test_shell will dump all changes to window.status.
780 bool dump_window_status_changes_;
781
[email protected]97f9a7952014-03-14 11:50:33782 // If true, the test_shell will output descriptive test for spellcheck
783 // execution.
784 bool dump_spell_check_callbacks_;
785
786 // If true, the test_shell will produce a dump of the back forward list as
787 // well.
788 bool dump_back_forward_list_;
789
790 // If true, the test_shell will draw the bounds of the current selection rect
791 // taking possible transforms of the selection rect into account.
792 bool dump_selection_rect_;
793
jackhou656fc852015-02-13 09:04:17794 // If true, the test_shell will dump the drag image as pixel results.
795 bool dump_drag_image_;
796
jochenc3a98da12015-03-10 13:59:58797 // If true, content_shell will dump the default navigation policy passed to
798 // WebFrameClient::decidePolicyForNavigation.
799 bool dump_navigation_policy_;
800
[email protected]97f9a7952014-03-14 11:50:33801 // If true, pixel dump will be produced as a series of 1px-tall, view-wide
802 // individual paints over the height of the view.
803 bool test_repaint_;
804
805 // If true and test_repaint_ is true as well, pixel dump will be produced as
806 // a series of 1px-wide, view-tall paints across the width of the view.
807 bool sweep_horizontally_;
808
809 // If true, layout is to target printed pages.
810 bool is_printing_;
811
812 // If false, MockWebMIDIAccessor fails on startSession() for testing.
813 bool midi_accessor_result_;
814
815 bool should_stay_on_page_after_handling_before_unload_;
816
817 bool should_dump_resource_priorities_;
818
[email protected]f24836a2014-05-06 01:02:44819 bool has_custom_text_output_;
820 std::string custom_text_output_;
821
[email protected]97f9a7952014-03-14 11:50:33822 std::set<std::string> http_headers_to_clear_;
823
824 // WAV audio data is stored here.
825 std::vector<unsigned char> audio_data_;
826
827 // Used for test timeouts.
[email protected]79ecada2014-05-04 05:16:16828 WebTaskList task_list_;
[email protected]97f9a7952014-03-14 11:50:33829
[email protected]79ecada2014-05-04 05:16:16830 TestInterfaces* test_interfaces_;
831 WebTestDelegate* delegate_;
[email protected]97f9a7952014-03-14 11:50:33832 blink::WebView* web_view_;
[email protected]a2ec0bc2014-04-23 08:18:27833 WebTestProxyBase* proxy_;
[email protected]97f9a7952014-03-14 11:50:33834
835 // This is non-0 IFF a load is in progress.
836 blink::WebFrame* top_loading_frame_;
837
mlamouri007f9d72015-02-27 16:27:25838 // WebContentSettingsClient mock object.
839 scoped_ptr<WebContentSettings> web_content_settings_;
[email protected]97f9a7952014-03-14 11:50:33840
[email protected]97f9a7952014-03-14 11:50:33841 bool pointer_locked_;
842 enum {
843 PointerLockWillSucceed,
844 PointerLockWillRespondAsync,
845 PointerLockWillFailSync,
846 } pointer_lock_planned_result_;
847 bool use_mock_theme_;
848
849 base::WeakPtrFactory<TestRunner> weak_factory_;
850
851 DISALLOW_COPY_AND_ASSIGN(TestRunner);
852};
853
jochenf5f31752015-06-03 12:06:34854} // namespace test_runner
[email protected]97f9a7952014-03-14 11:50:33855
jochen73e711c2015-06-03 10:01:46856#endif // COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_