[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 1 | // 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 | |
jochen | 73e711c | 2015-06-03 10:01:46 | [diff] [blame] | 5 | #ifndef COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_ |
| 6 | #define COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_ |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 7 | |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 10 | #include <deque> |
dcheng | 82beb4f | 2016-04-26 00:35:02 | [diff] [blame] | 11 | #include <memory> |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 12 | #include <set> |
| 13 | #include <string> |
benwells | 0c0d3f1 | 2015-05-25 01:03:17 | [diff] [blame] | 14 | #include <vector> |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 15 | |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 16 | #include "base/macros.h" |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 17 | #include "base/memory/weak_ptr.h" |
lukasza | 083b4f1 | 2016-03-24 16:51:43 | [diff] [blame] | 18 | #include "components/test_runner/layout_test_runtime_flags.h" |
jochen | 746754c5 | 2015-06-05 16:40:41 | [diff] [blame] | 19 | #include "components/test_runner/test_runner_export.h" |
jochen | 73e711c | 2015-06-03 10:01:46 | [diff] [blame] | 20 | #include "components/test_runner/web_test_runner.h" |
lukasza | 1b546c1 | 2016-04-04 16:19:20 | [diff] [blame] | 21 | #include "third_party/WebKit/public/platform/WebImage.h" |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 22 | #include "v8/include/v8.h" |
| 23 | |
[email protected] | 945babb | 2014-07-30 14:25:32 | [diff] [blame] | 24 | class GURL; |
[email protected] | eec9e78e | 2014-06-16 21:38:48 | [diff] [blame] | 25 | class SkBitmap; |
| 26 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 27 | namespace blink { |
mlamouri | 007f9d7 | 2015-02-27 16:27:25 | [diff] [blame] | 28 | class WebContentSettingsClient; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 29 | class WebFrame; |
lukasza | b2ad050 | 2016-04-27 15:51:42 | [diff] [blame] | 30 | class WebLocalFrame; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 31 | class WebString; |
| 32 | class WebView; |
lukasza | df92022f | 2016-05-03 16:42:31 | [diff] [blame] | 33 | class WebWidget; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | namespace gin { |
| 37 | class ArrayBufferView; |
| 38 | class Arguments; |
| 39 | } |
| 40 | |
jochen | f5f3175 | 2015-06-03 12:06:34 | [diff] [blame] | 41 | namespace test_runner { |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 42 | |
lukasza | 2135323 | 2016-04-12 19:52:11 | [diff] [blame] | 43 | class MockContentSettingsClient; |
lukasza | 5c2279c | 2016-04-05 16:44:47 | [diff] [blame] | 44 | class MockCredentialManagerClient; |
lukasza | 6a113ae1 | 2016-03-17 22:41:20 | [diff] [blame] | 45 | class MockScreenOrientationClient; |
lukasza | 01da260 | 2016-04-05 14:51:26 | [diff] [blame] | 46 | class MockWebSpeechRecognizer; |
lukasza | fd12460 | 2016-04-01 16:53:30 | [diff] [blame] | 47 | class MockWebUserMediaClient; |
lukasza | 5c2279c | 2016-04-05 16:44:47 | [diff] [blame] | 48 | class SpellCheckClient; |
[email protected] | 79ecada | 2014-05-04 05:16:16 | [diff] [blame] | 49 | class TestInterfaces; |
lukasza | b2ad050 | 2016-04-27 15:51:42 | [diff] [blame] | 50 | class TestRunnerForSpecificView; |
[email protected] | 79ecada | 2014-05-04 05:16:16 | [diff] [blame] | 51 | class WebTestDelegate; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 52 | |
lukasza | b2ad050 | 2016-04-27 15:51:42 | [diff] [blame] | 53 | // TestRunner class currently has dual purpose: |
| 54 | // 1. It implements |testRunner| javascript bindings for "global" / "ambient". |
| 55 | // Examples: |
| 56 | // - testRunner.dumpAsText (test flag affecting test behavior) |
| 57 | // - testRunner.setAllowDisplayOfInsecureContent (test flag affecting product |
| 58 | // behavior) |
| 59 | // - testRunner.setTextSubpixelPositioning (directly interacts with product). |
| 60 | // Note that "per-view" (non-"global") bindings are handled by |
| 61 | // instances of TestRunnerForSpecificView class. |
| 62 | // 2. It manages global test state. Example: |
| 63 | // - Tracking topLoadingFrame that can finish the test when it loads. |
| 64 | // - WorkQueue holding load requests from the TestInterfaces |
| 65 | // - LayoutTestRuntimeFlags |
lukasza | c935882 | 2016-04-07 14:43:46 | [diff] [blame] | 66 | class TestRunner : public WebTestRunner { |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 67 | public: |
[email protected] | 79ecada | 2014-05-04 05:16:16 | [diff] [blame] | 68 | explicit TestRunner(TestInterfaces*); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 69 | virtual ~TestRunner(); |
| 70 | |
lukasza | b2ad050 | 2016-04-27 15:51:42 | [diff] [blame] | 71 | void Install(blink::WebLocalFrame* frame, |
| 72 | base::WeakPtr<TestRunnerForSpecificView> view_test_runner); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 73 | |
[email protected] | 79ecada | 2014-05-04 05:16:16 | [diff] [blame] | 74 | void SetDelegate(WebTestDelegate*); |
lukasza | 8973c52 | 2016-04-27 16:32:28 | [diff] [blame] | 75 | void SetMainView(blink::WebView*); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 76 | |
| 77 | void Reset(); |
| 78 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 79 | void SetTestIsRunning(bool); |
| 80 | bool TestIsRunning() const { return test_is_running_; } |
| 81 | |
| 82 | bool UseMockTheme() const { return use_mock_theme_; } |
| 83 | |
| 84 | // WebTestRunner implementation. |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 85 | bool ShouldGeneratePixelResults() override; |
| 86 | bool ShouldDumpAsAudio() const override; |
| 87 | void GetAudioData(std::vector<unsigned char>* buffer_view) const override; |
lukasza | ef264fc5 | 2016-03-17 22:49:19 | [diff] [blame] | 88 | bool IsRecursiveLayoutDumpRequested() override; |
| 89 | std::string DumpLayout(blink::WebLocalFrame* frame) override; |
lukasza | 1b546c1 | 2016-04-04 16:19:20 | [diff] [blame] | 90 | void DumpPixelsAsync( |
| 91 | blink::WebView* web_view, |
| 92 | const base::Callback<void(const SkBitmap&)>& callback) override; |
lukasza | 083b4f1 | 2016-03-24 16:51:43 | [diff] [blame] | 93 | void ReplicateLayoutTestRuntimeFlagsChanges( |
lukasza | c9cbe71 | 2016-03-14 14:06:43 | [diff] [blame] | 94 | const base::DictionaryValue& changed_values) override; |
lukasza | a896046 | 2016-01-27 22:27:33 | [diff] [blame] | 95 | bool HasCustomTextDump(std::string* custom_text_dump) const override; |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 96 | bool ShouldDumpBackForwardList() const override; |
mlamouri | 007f9d7 | 2015-02-27 16:27:25 | [diff] [blame] | 97 | blink::WebContentSettingsClient* GetWebContentSettings() const override; |
lukasza | 5c2279c | 2016-04-05 16:44:47 | [diff] [blame] | 98 | void InitializeWebViewWithMocks(blink::WebView* web_view) override; |
lukasza | 95416be14 | 2016-04-14 15:06:33 | [diff] [blame] | 99 | void SetFocus(blink::WebView* web_view, bool focus) override; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 100 | |
lukasza | 01da260 | 2016-04-05 14:51:26 | [diff] [blame] | 101 | // Methods used by WebViewTestClient and WebFrameTestClient. |
lukasza | df92022f | 2016-05-03 16:42:31 | [diff] [blame] | 102 | void OnAnimationScheduled(blink::WebWidget* widget); |
| 103 | void OnAnimationBegun(blink::WebWidget* widget); |
lukasza | a0b624a | 2016-04-04 15:00:49 | [diff] [blame] | 104 | std::string GetAcceptLanguages() const; |
lukasza | e26c3d6 | 2016-03-14 23:30:59 | [diff] [blame] | 105 | bool shouldStayOnPageAfterHandlingBeforeUnload() const; |
lukasza | 6a113ae1 | 2016-03-17 22:41:20 | [diff] [blame] | 106 | MockScreenOrientationClient* getMockScreenOrientationClient(); |
lukasza | fd12460 | 2016-04-01 16:53:30 | [diff] [blame] | 107 | MockWebUserMediaClient* getMockWebUserMediaClient(); |
lukasza | 01da260 | 2016-04-05 14:51:26 | [diff] [blame] | 108 | MockWebSpeechRecognizer* getMockWebSpeechRecognizer(); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 109 | bool isPrinting() const; |
[email protected] | f24836a | 2014-05-06 01:02:44 | [diff] [blame] | 110 | bool shouldDumpAsCustomText() const; |
| 111 | std:: string customDumpText() const; |
abhishek.a21 | ca9b560 | 2014-09-19 07:33:33 | [diff] [blame] | 112 | void ShowDevTools(const std::string& settings, |
[email protected] | 06c25301 | 2014-04-16 18:35:33 | [diff] [blame] | 113 | const std::string& frontend_url); |
abhishek.a21 | ca9b560 | 2014-09-19 07:33:33 | [diff] [blame] | 114 | void ClearDevToolsLocalStorage(); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 115 | void setShouldDumpAsText(bool); |
| 116 | void setShouldDumpAsMarkup(bool); |
ki.stfu | 939799a4 | 2015-09-28 04:41:20 | [diff] [blame] | 117 | void setCustomTextOutput(const std::string& text); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 118 | void setShouldGeneratePixelResults(bool); |
| 119 | void setShouldDumpFrameLoadCallbacks(bool); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 120 | void setShouldEnableViewSource(bool); |
| 121 | bool shouldDumpEditingCallbacks() const; |
| 122 | bool shouldDumpFrameLoadCallbacks() const; |
| 123 | bool shouldDumpPingLoaderCallbacks() const; |
| 124 | bool shouldDumpUserGestureInFrameLoadCallbacks() const; |
| 125 | bool shouldDumpTitleChanges() const; |
| 126 | bool shouldDumpIconChanges() const; |
| 127 | bool shouldDumpCreateView() const; |
| 128 | bool canOpenWindows() const; |
| 129 | bool shouldDumpResourceLoadCallbacks() const; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 130 | bool shouldDumpResourceResponseMIMETypes() const; |
| 131 | bool shouldDumpStatusCallbacks() const; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 132 | bool shouldDumpSpellCheckCallbacks() const; |
[email protected] | a79cb991 | 2014-04-26 22:07:33 | [diff] [blame] | 133 | bool shouldWaitUntilExternalURLLoad() const; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 134 | const std::set<std::string>* httpHeadersToClear() const; |
lukasza | 10cd876 | 2016-04-27 20:03:02 | [diff] [blame] | 135 | |
| 136 | // To be called when |frame| starts loading - TestRunner will check if |
| 137 | // there is currently no top-loading-frame being tracked and if so, then it |
| 138 | // will return true and start tracking |frame| as the top-loading-frame. |
| 139 | bool tryToSetTopLoadingFrame(blink::WebFrame* frame); |
| 140 | |
| 141 | // To be called when |frame| finishes loading - TestRunner will check if |
| 142 | // |frame| is currently tracked as the top-loading-frame, and if yes, then it |
| 143 | // will return true, stop top-loading-frame tracking, and potentially finish |
| 144 | // the test (unless testRunner.waitUntilDone() was called and/or there are |
| 145 | // pending load requests in WorkQueue). |
| 146 | bool tryToClearTopLoadingFrame(blink::WebFrame*); |
| 147 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 148 | blink::WebFrame* topLoadingFrame() const; |
| 149 | void policyDelegateDone(); |
| 150 | bool policyDelegateEnabled() const; |
| 151 | bool policyDelegateIsPermissive() const; |
| 152 | bool policyDelegateShouldNotifyDone() const; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 153 | bool shouldDumpResourcePriorities() const; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 154 | void setToolTipText(const blink::WebString&); |
lukasza | 1b546c1 | 2016-04-04 16:19:20 | [diff] [blame] | 155 | void setDragImage(const blink::WebImage& drag_image); |
jochen | c3a98da1 | 2015-03-10 13:59:58 | [diff] [blame] | 156 | bool shouldDumpNavigationPolicy() const; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 157 | |
| 158 | bool midiAccessorResult(); |
| 159 | |
lukasza | fd12460 | 2016-04-01 16:53:30 | [diff] [blame] | 160 | // Methods used by MockColorChooser: |
| 161 | void DidOpenChooser(); |
| 162 | void DidCloseChooser(); |
| 163 | |
caseq | cb222783 | 2016-05-24 18:52:04 | [diff] [blame^] | 164 | bool ShouldDumpConsoleMessages() const; |
| 165 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 166 | // A single item in the work queue. |
| 167 | class WorkItem { |
| 168 | public: |
| 169 | virtual ~WorkItem() {} |
| 170 | |
| 171 | // Returns true if this started a load. |
[email protected] | 79ecada | 2014-05-04 05:16:16 | [diff] [blame] | 172 | virtual bool Run(WebTestDelegate*, blink::WebView*) = 0; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | private: |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 176 | friend class TestRunnerBindings; |
| 177 | friend class WorkQueue; |
| 178 | |
| 179 | // Helper class for managing events queued by methods like queueLoad or |
| 180 | // queueScript. |
| 181 | class WorkQueue { |
| 182 | public: |
| 183 | explicit WorkQueue(TestRunner* controller); |
| 184 | virtual ~WorkQueue(); |
| 185 | void ProcessWorkSoon(); |
| 186 | |
| 187 | // Reset the state of the class between tests. |
| 188 | void Reset(); |
| 189 | |
| 190 | void AddWork(WorkItem*); |
| 191 | |
| 192 | void set_frozen(bool frozen) { frozen_ = frozen; } |
| 193 | bool is_empty() { return queue_.empty(); } |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 194 | |
| 195 | private: |
| 196 | void ProcessWork(); |
| 197 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 198 | std::deque<WorkItem*> queue_; |
| 199 | bool frozen_; |
| 200 | TestRunner* controller_; |
lukasza | c935882 | 2016-04-07 14:43:46 | [diff] [blame] | 201 | |
| 202 | base::WeakPtrFactory<WorkQueue> weak_factory_; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | /////////////////////////////////////////////////////////////////////////// |
| 206 | // Methods dealing with the test logic |
| 207 | |
| 208 | // By default, tests end when page load is complete. These methods are used |
| 209 | // to delay the completion of the test until notifyDone is called. |
| 210 | void NotifyDone(); |
| 211 | void WaitUntilDone(); |
| 212 | |
| 213 | // Methods for adding actions to the work queue. Used in conjunction with |
| 214 | // waitUntilDone/notifyDone above. |
| 215 | void QueueBackNavigation(int how_far_back); |
| 216 | void QueueForwardNavigation(int how_far_forward); |
| 217 | void QueueReload(); |
| 218 | void QueueLoadingScript(const std::string& script); |
| 219 | void QueueNonLoadingScript(const std::string& script); |
| 220 | void QueueLoad(const std::string& url, const std::string& target); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 221 | |
| 222 | // Causes navigation actions just printout the intended navigation instead |
| 223 | // of taking you to the page. This is used for cases like mailto, where you |
| 224 | // don't actually want to open the mail program. |
| 225 | void SetCustomPolicyDelegate(gin::Arguments* args); |
| 226 | |
| 227 | // Delays completion of the test until the policy delegate runs. |
| 228 | void WaitForPolicyDelegate(); |
| 229 | |
| 230 | // Functions for dealing with windows. By default we block all new windows. |
| 231 | int WindowCount(); |
| 232 | void SetCloseRemainingWindowsWhenComplete(bool close_remaining_windows); |
| 233 | void ResetTestHelperControllers(); |
| 234 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 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 | |
dcheng | 9000dbd | 2015-04-03 05:39:40 | [diff] [blame] | 245 | // Add |source_code| as an injected stylesheet to the active document of the |
| 246 | // window of the current V8 context. |
| 247 | void InsertStyleSheet(const std::string& source_code); |
| 248 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 249 | // Enables or disables subpixel positioning (i.e. fractional X positions for |
| 250 | // glyphs) in text rendering on Linux. Since this method changes global |
| 251 | // settings, tests that call it must use their own custom font family for |
| 252 | // all text that they render. If not, an already-cached style will be used, |
| 253 | // resulting in the changed setting being ignored. |
| 254 | void SetTextSubpixelPositioning(bool value); |
| 255 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 256 | // After this function is called, all window-sizing machinery is |
| 257 | // short-circuited inside the renderer. This mode is necessary for |
| 258 | // some tests that were written before browsers had multi-process architecture |
| 259 | // and rely on window resizes to happen synchronously. |
| 260 | // The function has "unfortunate" it its name because we must strive to remove |
| 261 | // all tests that rely on this... well, unfortunate behavior. See |
| 262 | // http://crbug.com/309760 for the plan. |
| 263 | void UseUnfortunateSynchronousResizeMode(); |
| 264 | |
| 265 | bool EnableAutoResizeMode(int min_width, |
| 266 | int min_height, |
| 267 | int max_width, |
| 268 | int max_height); |
| 269 | bool DisableAutoResizeMode(int new_width, int new_height); |
| 270 | |
[email protected] | 2ad7e62 | 2014-06-30 17:44:21 | [diff] [blame] | 271 | void SetMockDeviceLight(double value); |
| 272 | void ResetDeviceLight(); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 273 | // Device Motion / Device Orientation related functions |
| 274 | void SetMockDeviceMotion(bool has_acceleration_x, double acceleration_x, |
| 275 | bool has_acceleration_y, double acceleration_y, |
| 276 | bool has_acceleration_z, double acceleration_z, |
| 277 | bool has_acceleration_including_gravity_x, |
| 278 | double acceleration_including_gravity_x, |
| 279 | bool has_acceleration_including_gravity_y, |
| 280 | double acceleration_including_gravity_y, |
| 281 | bool has_acceleration_including_gravity_z, |
| 282 | double acceleration_including_gravity_z, |
| 283 | bool has_rotation_rate_alpha, |
| 284 | double rotation_rate_alpha, |
| 285 | bool has_rotation_rate_beta, |
| 286 | double rotation_rate_beta, |
| 287 | bool has_rotation_rate_gamma, |
| 288 | double rotation_rate_gamma, |
| 289 | double interval); |
| 290 | void SetMockDeviceOrientation(bool has_alpha, double alpha, |
| 291 | bool has_beta, double beta, |
| 292 | bool has_gamma, double gamma, |
philipj | 9790645 | 2016-03-02 14:46:22 | [diff] [blame] | 293 | bool absolute); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 294 | |
[email protected] | e0bc2cb | 2014-03-20 17:34:24 | [diff] [blame] | 295 | void SetMockScreenOrientation(const std::string& orientation); |
dgozman | 3c16f7f | 2016-02-26 01:21:18 | [diff] [blame] | 296 | void DisableMockScreenOrientation(); |
[email protected] | e0bc2cb | 2014-03-20 17:34:24 | [diff] [blame] | 297 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 298 | /////////////////////////////////////////////////////////////////////////// |
| 299 | // Methods modifying WebPreferences. |
| 300 | |
| 301 | // Set the WebPreference that controls webkit's popup blocking. |
| 302 | void SetPopupBlockingEnabled(bool block_popups); |
| 303 | |
| 304 | void SetJavaScriptCanAccessClipboard(bool can_access); |
| 305 | void SetXSSAuditorEnabled(bool enabled); |
| 306 | void SetAllowUniversalAccessFromFileURLs(bool allow); |
| 307 | void SetAllowFileAccessFromFileURLs(bool allow); |
ki.stfu | 939799a4 | 2015-09-28 04:41:20 | [diff] [blame] | 308 | void OverridePreference(const std::string& key, v8::Local<v8::Value> value); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 309 | |
[email protected] | ebd5ea5 | 2014-05-28 14:51:15 | [diff] [blame] | 310 | // Modify accept_languages in RendererPreferences. |
| 311 | void SetAcceptLanguages(const std::string& accept_languages); |
| 312 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 313 | // Enable or disable plugins. |
| 314 | void SetPluginsEnabled(bool enabled); |
| 315 | |
lukasza | 01da260 | 2016-04-05 14:51:26 | [diff] [blame] | 316 | // Returns |true| if an animation has been scheduled in one or more WebViews |
| 317 | // participating in the layout test. |
| 318 | bool GetAnimationScheduled() const; |
chrishtr | aea6066d | 2016-02-19 04:49:12 | [diff] [blame] | 319 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 320 | /////////////////////////////////////////////////////////////////////////// |
| 321 | // Methods that modify the state of TestRunner |
| 322 | |
| 323 | // This function sets a flag that tells the test_shell to print a line of |
| 324 | // descriptive text for each editing command. It takes no arguments, and |
| 325 | // ignores any that may be present. |
| 326 | void DumpEditingCallbacks(); |
| 327 | |
| 328 | // This function sets a flag that tells the test_shell to dump pages as |
| 329 | // plain text, rather than as a text representation of the renderer's state. |
| 330 | // The pixel results will not be generated for this test. |
| 331 | void DumpAsText(); |
| 332 | |
| 333 | // This function sets a flag that tells the test_shell to dump pages as |
[email protected] | fdc433c0 | 2014-06-02 19:27:14 | [diff] [blame] | 334 | // the DOM contents, rather than as a text representation of the renderer's |
| 335 | // state. The pixel results will not be generated for this test. |
| 336 | void DumpAsMarkup(); |
| 337 | |
| 338 | // This function sets a flag that tells the test_shell to dump pages as |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 339 | // plain text, rather than as a text representation of the renderer's state. |
| 340 | // It will also generate a pixel dump for the test. |
| 341 | void DumpAsTextWithPixelResults(); |
| 342 | |
| 343 | // This function sets a flag that tells the test_shell to print out the |
| 344 | // scroll offsets of the child frames. It ignores all. |
| 345 | void DumpChildFrameScrollPositions(); |
| 346 | |
| 347 | // This function sets a flag that tells the test_shell to recursively |
| 348 | // dump all frames as plain text if the DumpAsText flag is set. |
| 349 | // It takes no arguments, and ignores any that may be present. |
| 350 | void DumpChildFramesAsText(); |
| 351 | |
[email protected] | fdc433c0 | 2014-06-02 19:27:14 | [diff] [blame] | 352 | // This function sets a flag that tells the test_shell to recursively |
| 353 | // dump all frames as the DOM contents if the DumpAsMarkup flag is set. |
| 354 | // It takes no arguments, and ignores any that may be present. |
| 355 | void DumpChildFramesAsMarkup(); |
| 356 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 357 | // This function sets a flag that tells the test_shell to print out the |
| 358 | // information about icon changes notifications from WebKit. |
| 359 | void DumpIconChanges(); |
| 360 | |
| 361 | // Deals with Web Audio WAV file data. |
| 362 | void SetAudioData(const gin::ArrayBufferView& view); |
| 363 | |
| 364 | // This function sets a flag that tells the test_shell to print a line of |
| 365 | // descriptive text for each frame load callback. It takes no arguments, and |
| 366 | // ignores any that may be present. |
| 367 | void DumpFrameLoadCallbacks(); |
| 368 | |
| 369 | // This function sets a flag that tells the test_shell to print a line of |
| 370 | // descriptive text for each PingLoader dispatch. It takes no arguments, and |
| 371 | // ignores any that may be present. |
| 372 | void DumpPingLoaderCallbacks(); |
| 373 | |
| 374 | // This function sets a flag that tells the test_shell to print a line of |
| 375 | // user gesture status text for some frame load callbacks. It takes no |
| 376 | // arguments, and ignores any that may be present. |
| 377 | void DumpUserGestureInFrameLoadCallbacks(); |
| 378 | |
| 379 | void DumpTitleChanges(); |
| 380 | |
| 381 | // This function sets a flag that tells the test_shell to dump all calls to |
| 382 | // WebViewClient::createView(). |
| 383 | // It takes no arguments, and ignores any that may be present. |
| 384 | void DumpCreateView(); |
| 385 | |
| 386 | void SetCanOpenWindows(); |
| 387 | |
| 388 | // This function sets a flag that tells the test_shell to dump a descriptive |
| 389 | // line for each resource load callback. It takes no arguments, and ignores |
| 390 | // any that may be present. |
| 391 | void DumpResourceLoadCallbacks(); |
| 392 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 393 | // This function sets a flag that tells the test_shell to dump the MIME type |
| 394 | // for each resource that was loaded. It takes no arguments, and ignores any |
| 395 | // that may be present. |
| 396 | void DumpResourceResponseMIMETypes(); |
| 397 | |
mlamouri | 007f9d7 | 2015-02-27 16:27:25 | [diff] [blame] | 398 | // WebContentSettingsClient related. |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 399 | void SetImagesAllowed(bool allowed); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 400 | void SetScriptsAllowed(bool allowed); |
| 401 | void SetStorageAllowed(bool allowed); |
| 402 | void SetPluginsAllowed(bool allowed); |
| 403 | void SetAllowDisplayOfInsecureContent(bool allowed); |
| 404 | void SetAllowRunningOfInsecureContent(bool allowed); |
mlamouri | 426f286 | 2016-04-29 18:35:01 | [diff] [blame] | 405 | void SetAutoplayAllowed(bool allowed); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 406 | void DumpPermissionClientCallbacks(); |
| 407 | |
| 408 | // This function sets a flag that tells the test_shell to dump all calls |
| 409 | // to window.status(). |
| 410 | // It takes no arguments, and ignores any that may be present. |
| 411 | void DumpWindowStatusChanges(); |
| 412 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 413 | // This function sets a flag that tells the test_shell to dump all |
| 414 | // the lines of descriptive text about spellcheck execution. |
| 415 | void DumpSpellCheckCallbacks(); |
| 416 | |
| 417 | // This function sets a flag that tells the test_shell to print out a text |
| 418 | // representation of the back/forward list. It ignores all arguments. |
| 419 | void DumpBackForwardList(); |
| 420 | |
| 421 | void DumpSelectionRect(); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 422 | |
| 423 | // Causes layout to happen as if targetted to printed pages. |
| 424 | void SetPrinting(); |
| 425 | |
[email protected] | 5284610 | 2014-06-24 04:26:44 | [diff] [blame] | 426 | // Clears the state from SetPrinting(). |
| 427 | void ClearPrinting(); |
| 428 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 429 | void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value); |
| 430 | |
| 431 | // Causes WillSendRequest to clear certain headers. |
| 432 | void SetWillSendRequestClearHeader(const std::string& header); |
| 433 | |
| 434 | // This function sets a flag that tells the test_shell to dump a descriptive |
| 435 | // line for each resource load's priority and any time that priority |
| 436 | // changes. It takes no arguments, and ignores any that may be present. |
| 437 | void DumpResourceRequestPriorities(); |
| 438 | |
| 439 | // Sets a flag to enable the mock theme. |
| 440 | void SetUseMockTheme(bool use); |
| 441 | |
[email protected] | a79cb991 | 2014-04-26 22:07:33 | [diff] [blame] | 442 | // Sets a flag that causes the test to be marked as completed when the |
| 443 | // WebFrameClient receives a loadURLExternally() call. |
| 444 | void WaitUntilExternalURLLoad(); |
| 445 | |
lukasza | 1b546c1 | 2016-04-04 16:19:20 | [diff] [blame] | 446 | // This function sets a flag to dump the drag image when the next drag&drop is |
| 447 | // initiated. It is equivalent to DumpAsTextWithPixelResults but the pixel |
| 448 | // results will be the drag image instead of a snapshot of the page. |
jackhou | 656fc85 | 2015-02-13 09:04:17 | [diff] [blame] | 449 | void DumpDragImage(); |
| 450 | |
jochen | c3a98da1 | 2015-03-10 13:59:58 | [diff] [blame] | 451 | // Sets a flag that tells the WebTestProxy to dump the default navigation |
| 452 | // policy passed to the decidePolicyForNavigation callback. |
| 453 | void DumpNavigationPolicy(); |
| 454 | |
caseq | cb222783 | 2016-05-24 18:52:04 | [diff] [blame^] | 455 | // Controls whether console messages produced by the page are dumped |
| 456 | // to test output. |
| 457 | void SetDumpConsoleMessages(bool value); |
| 458 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 459 | /////////////////////////////////////////////////////////////////////////// |
| 460 | // Methods interacting with the WebTestProxy |
| 461 | |
| 462 | /////////////////////////////////////////////////////////////////////////// |
| 463 | // Methods forwarding to the WebTestDelegate |
| 464 | |
| 465 | // Shows DevTools window. |
[email protected] | 06c25301 | 2014-04-16 18:35:33 | [diff] [blame] | 466 | void ShowWebInspector(const std::string& str, |
| 467 | const std::string& frontend_url); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 468 | void CloseWebInspector(); |
| 469 | |
| 470 | // Inspect chooser state |
| 471 | bool IsChooserShown(); |
| 472 | |
| 473 | // Allows layout tests to exec scripts at WebInspector side. |
| 474 | void EvaluateInWebInspector(int call_id, const std::string& script); |
sergeyv | 0cd842b4 | 2015-10-09 16:07:11 | [diff] [blame] | 475 | // Allows layout tests to evaluate scripts in InspectorOverlay page. |
| 476 | // Script may have an output represented as a string, return values of other |
| 477 | // types would be ignored. |
| 478 | std::string EvaluateInWebInspectorOverlay(const std::string& script); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 479 | |
| 480 | // Clears all databases. |
| 481 | void ClearAllDatabases(); |
| 482 | // Sets the default quota for all origins |
| 483 | void SetDatabaseQuota(int quota); |
| 484 | |
| 485 | // Changes the cookie policy from the default to allow all cookies. |
| 486 | void SetAlwaysAcceptCookies(bool accept); |
| 487 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 488 | // Converts a URL starting with file:///tmp/ to the local mapping. |
| 489 | std::string PathToLocalResource(const std::string& path); |
| 490 | |
mlamouri | d5098d0 | 2015-04-21 12:17:30 | [diff] [blame] | 491 | // Sets the permission's |name| to |value| for a given {origin, embedder} |
| 492 | // tuple. |
| 493 | void SetPermission(const std::string& name, |
| 494 | const std::string& value, |
| 495 | const GURL& origin, |
| 496 | const GURL& embedding_origin); |
| 497 | |
benwells | 0c0d3f1 | 2015-05-25 01:03:17 | [diff] [blame] | 498 | // Resolve the beforeinstallprompt event with the matching request id. |
| 499 | void ResolveBeforeInstallPromptPromise(int request_id, |
| 500 | const std::string& platform); |
| 501 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 502 | // Calls setlocale(LC_ALL, ...) for a specified locale. |
| 503 | // Resets between tests. |
| 504 | void SetPOSIXLocale(const std::string& locale); |
| 505 | |
| 506 | // MIDI function to control permission handling. |
| 507 | void SetMIDIAccessorResult(bool result); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 508 | |
peter | d98157d | 2014-11-20 13:15:01 | [diff] [blame] | 509 | // Simulates a click on a Web Notification. |
johnme | 96d5012 | 2015-08-07 15:33:21 | [diff] [blame] | 510 | void SimulateWebNotificationClick(const std::string& title, int action_index); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 511 | |
nsatragno | 24bd34b | 2016-02-09 10:30:02 | [diff] [blame] | 512 | // Simulates closing a Web Notification. |
| 513 | void SimulateWebNotificationClose(const std::string& title, bool by_user); |
| 514 | |
[email protected] | 56e365d4 | 2014-05-02 22:18:24 | [diff] [blame] | 515 | // Speech recognition related functions. |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 516 | void AddMockSpeechRecognitionResult(const std::string& transcript, |
| 517 | double confidence); |
| 518 | void SetMockSpeechRecognitionError(const std::string& error, |
| 519 | const std::string& message); |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 520 | |
mkwst | 41667ab | 2014-09-16 06:52:43 | [diff] [blame] | 521 | // Credential Manager mock functions |
| 522 | // TODO(mkwst): Support FederatedCredential. |
| 523 | void AddMockCredentialManagerResponse(const std::string& id, |
| 524 | const std::string& name, |
| 525 | const std::string& avatar, |
| 526 | const std::string& password); |
mkwst | 008acce6 | 2016-03-11 13:02:01 | [diff] [blame] | 527 | void AddMockCredentialManagerError(const std::string& error); |
mkwst | 41667ab | 2014-09-16 06:52:43 | [diff] [blame] | 528 | |
lukasza | 083b4f1 | 2016-03-24 16:51:43 | [diff] [blame] | 529 | // Takes care of notifying the delegate after a change to layout test runtime |
| 530 | // flags. |
| 531 | void OnLayoutTestRuntimeFlagsChanged(); |
lukasza | c9cbe71 | 2016-03-14 14:06:43 | [diff] [blame] | 532 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 533 | /////////////////////////////////////////////////////////////////////////// |
| 534 | // Internal helpers |
[email protected] | eec9e78e | 2014-06-16 21:38:48 | [diff] [blame] | 535 | |
lukasza | 10cd876 | 2016-04-27 20:03:02 | [diff] [blame] | 536 | bool IsFramePartOfMainTestWindow(blink::WebFrame*) const; |
| 537 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 538 | void CheckResponseMimeType(); |
| 539 | void CompleteNotifyDone(); |
| 540 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 541 | // In the Mac code, this is called to trigger the end of a test after the |
| 542 | // page has finished loading. From here, we can generate the dump for the |
| 543 | // test. |
| 544 | void LocationChangeDone(); |
| 545 | |
| 546 | bool test_is_running_; |
| 547 | |
| 548 | // When reset is called, go through and close all but the main test shell |
| 549 | // window. By default, set to true but toggled to false using |
| 550 | // setCloseRemainingWindowsWhenComplete(). |
| 551 | bool close_remaining_windows_; |
| 552 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 553 | WorkQueue work_queue_; |
| 554 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 555 | // Bound variable to return the name of this platform (chromium). |
| 556 | std::string platform_name_; |
| 557 | |
| 558 | // Bound variable to store the last tooltip text |
| 559 | std::string tooltip_text_; |
| 560 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 561 | // Bound variable counting the number of top URLs visited. |
| 562 | int web_history_item_count_; |
| 563 | |
lukasza | 9b9d70e | 2016-02-25 23:45:44 | [diff] [blame] | 564 | // Flags controlling what content gets dumped as a layout text result. |
lukasza | 083b4f1 | 2016-03-24 16:51:43 | [diff] [blame] | 565 | LayoutTestRuntimeFlags layout_test_runtime_flags_; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 566 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 567 | // If true, the test_shell will output a base64 encoded WAVE file. |
| 568 | bool dump_as_audio_; |
| 569 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 570 | // If true, output a descriptive line each time WebViewClient::createView |
| 571 | // is invoked. |
| 572 | bool dump_create_view_; |
| 573 | |
| 574 | // If true, new windows can be opened via javascript or by plugins. By |
| 575 | // default, set to false and can be toggled to true using |
| 576 | // setCanOpenWindows(). |
| 577 | bool can_open_windows_; |
| 578 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 579 | // If true, the test_shell will dump all changes to window.status. |
| 580 | bool dump_window_status_changes_; |
| 581 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 582 | // If true, the test_shell will output descriptive test for spellcheck |
| 583 | // execution. |
| 584 | bool dump_spell_check_callbacks_; |
| 585 | |
| 586 | // If true, the test_shell will produce a dump of the back forward list as |
| 587 | // well. |
| 588 | bool dump_back_forward_list_; |
| 589 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 590 | // If true, pixel dump will be produced as a series of 1px-tall, view-wide |
| 591 | // individual paints over the height of the view. |
| 592 | bool test_repaint_; |
| 593 | |
| 594 | // If true and test_repaint_ is true as well, pixel dump will be produced as |
| 595 | // a series of 1px-wide, view-tall paints across the width of the view. |
| 596 | bool sweep_horizontally_; |
| 597 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 598 | // If false, MockWebMIDIAccessor fails on startSession() for testing. |
| 599 | bool midi_accessor_result_; |
| 600 | |
[email protected] | f24836a | 2014-05-06 01:02:44 | [diff] [blame] | 601 | bool has_custom_text_output_; |
| 602 | std::string custom_text_output_; |
| 603 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 604 | std::set<std::string> http_headers_to_clear_; |
| 605 | |
| 606 | // WAV audio data is stored here. |
| 607 | std::vector<unsigned char> audio_data_; |
| 608 | |
[email protected] | 79ecada | 2014-05-04 05:16:16 | [diff] [blame] | 609 | TestInterfaces* test_interfaces_; |
| 610 | WebTestDelegate* delegate_; |
lukasza | 8973c52 | 2016-04-27 16:32:28 | [diff] [blame] | 611 | blink::WebView* main_view_; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 612 | |
| 613 | // This is non-0 IFF a load is in progress. |
| 614 | blink::WebFrame* top_loading_frame_; |
| 615 | |
mlamouri | 007f9d7 | 2015-02-27 16:27:25 | [diff] [blame] | 616 | // WebContentSettingsClient mock object. |
dcheng | 82beb4f | 2016-04-26 00:35:02 | [diff] [blame] | 617 | std::unique_ptr<MockContentSettingsClient> mock_content_settings_client_; |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 618 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 619 | bool use_mock_theme_; |
| 620 | |
dcheng | 82beb4f | 2016-04-26 00:35:02 | [diff] [blame] | 621 | std::unique_ptr<MockCredentialManagerClient> credential_manager_client_; |
| 622 | std::unique_ptr<MockScreenOrientationClient> mock_screen_orientation_client_; |
| 623 | std::unique_ptr<MockWebSpeechRecognizer> speech_recognizer_; |
| 624 | std::unique_ptr<MockWebUserMediaClient> user_media_client_; |
| 625 | std::unique_ptr<SpellCheckClient> spellcheck_; |
lukasza | fd12460 | 2016-04-01 16:53:30 | [diff] [blame] | 626 | |
| 627 | // Number of currently active color choosers. |
| 628 | int chooser_count_; |
lukasza | 6a113ae1 | 2016-03-17 22:41:20 | [diff] [blame] | 629 | |
lukasza | 1b546c1 | 2016-04-04 16:19:20 | [diff] [blame] | 630 | // Captured drag image. |
| 631 | blink::WebImage drag_image_; |
| 632 | |
lukasza | 95416be14 | 2016-04-14 15:06:33 | [diff] [blame] | 633 | // View that was focused by a previous call to TestRunner::SetFocus method. |
| 634 | // Note - this can be a dangling pointer to an already destroyed WebView (this |
| 635 | // is ok, because this is taken care of in WebTestDelegate::SetFocus). |
| 636 | blink::WebView* previously_focused_view_; |
| 637 | |
lukasza | df92022f | 2016-05-03 16:42:31 | [diff] [blame] | 638 | std::set<blink::WebWidget*> widgets_with_scheduled_animations_; |
lukasza | 01da260 | 2016-04-05 14:51:26 | [diff] [blame] | 639 | |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 640 | base::WeakPtrFactory<TestRunner> weak_factory_; |
| 641 | |
| 642 | DISALLOW_COPY_AND_ASSIGN(TestRunner); |
| 643 | }; |
| 644 | |
jochen | f5f3175 | 2015-06-03 12:06:34 | [diff] [blame] | 645 | } // namespace test_runner |
[email protected] | 97f9a795 | 2014-03-14 11:50:33 | [diff] [blame] | 646 | |
jochen | 73e711c | 2015-06-03 10:01:46 | [diff] [blame] | 647 | #endif // COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_ |