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