| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_TEST_BASE_UI_TEST_UTILS_H_ | 5 #ifndef CHROME_TEST_BASE_UI_TEST_UTILS_H_ |
| 6 #define CHROME_TEST_BASE_UI_TEST_UTILS_H_ | 6 #define CHROME_TEST_BASE_UI_TEST_UTILS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 const content::NotificationSource& source) | 299 const content::NotificationSource& source) |
| 300 WARN_UNUSED_RESULT; | 300 WARN_UNUSED_RESULT; |
| 301 | 301 |
| 302 // Sends a move event blocking until received. Returns true if the event was | 302 // Sends a move event blocking until received. Returns true if the event was |
| 303 // successfully received. This uses ui_controls::SendMouse***NotifyWhenDone, | 303 // successfully received. This uses ui_controls::SendMouse***NotifyWhenDone, |
| 304 // see it for details. | 304 // see it for details. |
| 305 bool SendMouseMoveSync(const gfx::Point& location) WARN_UNUSED_RESULT; | 305 bool SendMouseMoveSync(const gfx::Point& location) WARN_UNUSED_RESULT; |
| 306 bool SendMouseEventsSync(ui_controls::MouseButton type, | 306 bool SendMouseEventsSync(ui_controls::MouseButton type, |
| 307 int state) WARN_UNUSED_RESULT; | 307 int state) WARN_UNUSED_RESULT; |
| 308 | 308 |
| 309 // Run a message loop only for the specified amount of time. | 309 // Helper class to Run and Quit the message loop. Quit will only quit the |
| 310 class TimedMessageLoopRunner { | 310 // matching call to Run. Nested calls to MessageLoop::Run will not be affected. |
| 311 // It is also safe to call Quit after Run has already returned -- in that case |
| 312 // Quit will have no effect. |
| 313 class MessageLoopRunner { |
| 311 public: | 314 public: |
| 312 // Create new MessageLoopForUI and attach to it. | 315 MessageLoopRunner() : message_loop_run_id_(0) { } |
| 313 TimedMessageLoopRunner(); | |
| 314 | 316 |
| 315 // Attach to an existing message loop. | 317 // Run the current MessageLoop. This can't be called recursively. |
| 316 explicit TimedMessageLoopRunner(MessageLoop* loop) | 318 void Run(); |
| 317 : loop_(loop), owned_(false), quit_loop_invoked_(false) {} | |
| 318 | 319 |
| 319 ~TimedMessageLoopRunner(); | 320 // Quit the matching call to Run (nested MessageLoops are unaffected). |
| 320 | 321 void QuitNow(); |
| 321 // Run the message loop for ms milliseconds. | |
| 322 void RunFor(int ms); | |
| 323 | |
| 324 // Post Quit task to the message loop. | |
| 325 void Quit(); | |
| 326 | |
| 327 // Post delayed Quit task to the message loop. | |
| 328 void QuitAfter(int ms); | |
| 329 | |
| 330 bool WasTimedOut() const { | |
| 331 return !quit_loop_invoked_; | |
| 332 } | |
| 333 | 322 |
| 334 private: | 323 private: |
| 335 MessageLoop* loop_; | 324 int message_loop_run_id_; |
| 336 bool owned_; | 325 DISALLOW_COPY_AND_ASSIGN(MessageLoopRunner); |
| 337 bool quit_loop_invoked_; | 326 }; |
| 338 | 327 |
| 339 DISALLOW_COPY_AND_ASSIGN(TimedMessageLoopRunner); | 328 // Variant of MessageLoopRunner that allows a Closure to be used for quiting. |
| 329 // This variant is not reusable -- Run can only be called once. Instead, make a |
| 330 // new instance for each use. |
| 331 class MessageLoopRunnerClosure |
| 332 : public base::RefCounted<MessageLoopRunnerClosure> { |
| 333 public: |
| 334 MessageLoopRunnerClosure(); |
| 335 |
| 336 // Run the current MessageLoop. This can't be called recursively. |
| 337 void Run(); |
| 338 |
| 339 // Hand this closure off to code that uses callbacks to notify completion. |
| 340 // Example: |
| 341 // scoped_refptr<MessageLoopRunnerClosure> runner = |
| 342 // new MessageLoopRunnerClosure; |
| 343 // // Must be no nested MessageLoop::Run calls during kick_off_some_api: |
| 344 // kick_off_some_api(runner.QuitNowClosure()); |
| 345 // runner.Run(); |
| 346 base::Closure QuitNowClosure(); |
| 347 |
| 348 private: |
| 349 friend class base::RefCounted<MessageLoopRunnerClosure>; |
| 350 ~MessageLoopRunnerClosure(); |
| 351 |
| 352 void QuitNow(); |
| 353 |
| 354 MessageLoopRunner message_loop_runner_; |
| 355 |
| 356 bool run_called_; |
| 357 bool quit_received_; |
| 358 bool running_; |
| 359 |
| 360 DISALLOW_COPY_AND_ASSIGN(MessageLoopRunnerClosure); |
| 340 }; | 361 }; |
| 341 | 362 |
| 342 // This is a utility class for running a python websocket server | 363 // This is a utility class for running a python websocket server |
| 343 // during tests. The server is started during the construction of the | 364 // during tests. The server is started during the construction of the |
| 344 // object, and is stopped when the destructor is called. Note that | 365 // object, and is stopped when the destructor is called. Note that |
| 345 // because of the underlying script that is used: | 366 // because of the underlying script that is used: |
| 346 // | 367 // |
| 347 // third_paty/WebKit/Tools/Scripts/new-run-webkit-websocketserver | 368 // third_paty/WebKit/Tools/Scripts/new-run-webkit-websocketserver |
| 348 // | 369 // |
| 349 // Only *_wsh.py handlers found under "http/tests/websocket/tests" from the | 370 // Only *_wsh.py handlers found under "http/tests/websocket/tests" from the |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 const content::NotificationSource& source, | 465 const content::NotificationSource& source, |
| 445 const content::NotificationDetails& details) OVERRIDE; | 466 const content::NotificationDetails& details) OVERRIDE; |
| 446 | 467 |
| 447 private: | 468 private: |
| 448 bool seen_; | 469 bool seen_; |
| 449 bool running_; | 470 bool running_; |
| 450 content::NotificationRegistrar registrar_; | 471 content::NotificationRegistrar registrar_; |
| 451 | 472 |
| 452 content::NotificationSource source_; | 473 content::NotificationSource source_; |
| 453 content::NotificationDetails details_; | 474 content::NotificationDetails details_; |
| 475 MessageLoopRunner message_loop_runner_; |
| 454 | 476 |
| 455 DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver); | 477 DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver); |
| 456 }; | 478 }; |
| 457 | 479 |
| 458 // A WindowedNotificationObserver hard-wired to observe | 480 // A WindowedNotificationObserver hard-wired to observe |
| 459 // chrome::NOTIFICATION_TAB_ADDED. | 481 // chrome::NOTIFICATION_TAB_ADDED. |
| 460 class WindowedTabAddedNotificationObserver | 482 class WindowedTabAddedNotificationObserver |
| 461 : public WindowedNotificationObserver { | 483 : public WindowedNotificationObserver { |
| 462 public: | 484 public: |
| 463 // Register to listen for notifications of NOTIFICATION_TAB_ADDED from either | 485 // Register to listen for notifications of NOTIFICATION_TAB_ADDED from either |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 | 559 |
| 538 private: | 560 private: |
| 539 // content::NotificationObserver | 561 // content::NotificationObserver |
| 540 virtual void Observe(int type, | 562 virtual void Observe(int type, |
| 541 const content::NotificationSource& source, | 563 const content::NotificationSource& source, |
| 542 const content::NotificationDetails& details) OVERRIDE; | 564 const content::NotificationDetails& details) OVERRIDE; |
| 543 | 565 |
| 544 content::WebContents* web_contents_; | 566 content::WebContents* web_contents_; |
| 545 std::vector<string16> expected_titles_; | 567 std::vector<string16> expected_titles_; |
| 546 content::NotificationRegistrar notification_registrar_; | 568 content::NotificationRegistrar notification_registrar_; |
| 569 MessageLoopRunner message_loop_runner_; |
| 547 | 570 |
| 548 // The most recently observed expected title, if any. | 571 // The most recently observed expected title, if any. |
| 549 string16 observed_title_; | 572 string16 observed_title_; |
| 550 | 573 |
| 551 bool expected_title_observed_; | 574 bool expected_title_observed_; |
| 552 bool quit_loop_on_observation_; | 575 bool quit_loop_on_observation_; |
| 553 | 576 |
| 554 DISALLOW_COPY_AND_ASSIGN(TitleWatcher); | 577 DISALLOW_COPY_AND_ASSIGN(TitleWatcher); |
| 555 }; | 578 }; |
| 556 | 579 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 | 659 |
| 637 // Overridden content::NotificationObserver methods. | 660 // Overridden content::NotificationObserver methods. |
| 638 virtual void Observe(int type, | 661 virtual void Observe(int type, |
| 639 const content::NotificationSource& source, | 662 const content::NotificationSource& source, |
| 640 const content::NotificationDetails& details) OVERRIDE; | 663 const content::NotificationDetails& details) OVERRIDE; |
| 641 | 664 |
| 642 private: | 665 private: |
| 643 content::NotificationRegistrar registrar_; | 666 content::NotificationRegistrar registrar_; |
| 644 std::queue<std::string> message_queue_; | 667 std::queue<std::string> message_queue_; |
| 645 bool waiting_for_message_; | 668 bool waiting_for_message_; |
| 669 MessageLoopRunner message_loop_runner_; |
| 646 | 670 |
| 647 DISALLOW_COPY_AND_ASSIGN(DOMMessageQueue); | 671 DISALLOW_COPY_AND_ASSIGN(DOMMessageQueue); |
| 648 }; | 672 }; |
| 649 | 673 |
| 650 // Takes a snapshot of the given render widget, rendered at |page_size|. The | 674 // Takes a snapshot of the given render widget, rendered at |page_size|. The |
| 651 // snapshot is set to |bitmap|. Returns true on success. | 675 // snapshot is set to |bitmap|. Returns true on success. |
| 652 bool TakeRenderWidgetSnapshot(content::RenderWidgetHost* rwh, | 676 bool TakeRenderWidgetSnapshot(content::RenderWidgetHost* rwh, |
| 653 const gfx::Size& page_size, | 677 const gfx::Size& page_size, |
| 654 SkBitmap* bitmap) WARN_UNUSED_RESULT; | 678 SkBitmap* bitmap) WARN_UNUSED_RESULT; |
| 655 | 679 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 // ui_controls_linux.cc and ui_controls_mac.cc | 718 // ui_controls_linux.cc and ui_controls_mac.cc |
| 695 void ClickTask(ui_controls::MouseButton button, | 719 void ClickTask(ui_controls::MouseButton button, |
| 696 int state, | 720 int state, |
| 697 const base::Closure& followup); | 721 const base::Closure& followup); |
| 698 | 722 |
| 699 } // namespace internal | 723 } // namespace internal |
| 700 | 724 |
| 701 } // namespace ui_test_utils | 725 } // namespace ui_test_utils |
| 702 | 726 |
| 703 #endif // CHROME_TEST_BASE_UI_TEST_UTILS_H_ | 727 #endif // CHROME_TEST_BASE_UI_TEST_UTILS_H_ |
| OLD | NEW |