| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 BROWSER_TEST_MASK = BROWSER_TEST_WAIT_FOR_BROWSER | | 89 BROWSER_TEST_MASK = BROWSER_TEST_WAIT_FOR_BROWSER | |
| 90 BROWSER_TEST_WAIT_FOR_TAB | | 90 BROWSER_TEST_WAIT_FOR_TAB | |
| 91 BROWSER_TEST_WAIT_FOR_NAVIGATION | 91 BROWSER_TEST_WAIT_FOR_NAVIGATION |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 // Turns on nestable tasks, runs the message loop, then resets nestable tasks | 94 // Turns on nestable tasks, runs the message loop, then resets nestable tasks |
| 95 // to what they were originally. Prefer this over MessageLoop::Run for in | 95 // to what they were originally. Prefer this over MessageLoop::Run for in |
| 96 // process browser tests that need to block until a condition is met. | 96 // process browser tests that need to block until a condition is met. |
| 97 void RunMessageLoop(); | 97 void RunMessageLoop(); |
| 98 | 98 |
| 99 // Variant of RunMessageLoop that takes RunLoop. |
| 100 void RunRunLoop(const base::WeakPtr<MessageLoop::RunLoop>& run_loop); |
| 101 |
| 102 // Quit the given RunLoop. Allows a few generations of pending tasks to run. |
| 103 void QuitRunLoop(const base::WeakPtr<MessageLoop::RunLoop>& run_loop); |
| 104 |
| 99 // Turns on nestable tasks, runs all pending tasks in the message loop, | 105 // Turns on nestable tasks, runs all pending tasks in the message loop, |
| 100 // then resets nestable tasks to what they were originally. Prefer this | 106 // then resets nestable tasks to what they were originally. Prefer this |
| 101 // over MessageLoop::RunAllPending for in process browser tests to run | 107 // over MessageLoop::RunAllPending for in process browser tests to run |
| 102 // all pending tasks. | 108 // all pending tasks. |
| 103 void RunAllPendingInMessageLoop(); | 109 void RunAllPendingInMessageLoop(); |
| 104 | 110 |
| 105 // Blocks the current thread until all the pending messages in the loop of the | 111 // Blocks the current thread until all the pending messages in the loop of the |
| 106 // thread |thread_id| have been processed. | 112 // thread |thread_id| have been processed. |
| 107 void RunAllPendingInMessageLoop(content::BrowserThread::ID thread_id); | 113 void RunAllPendingInMessageLoop(content::BrowserThread::ID thread_id); |
| 108 | 114 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 const content::NotificationSource& source) | 300 const content::NotificationSource& source) |
| 295 WARN_UNUSED_RESULT; | 301 WARN_UNUSED_RESULT; |
| 296 | 302 |
| 297 // Sends a move event blocking until received. Returns true if the event was | 303 // Sends a move event blocking until received. Returns true if the event was |
| 298 // successfully received. This uses ui_controls::SendMouse***NotifyWhenDone, | 304 // successfully received. This uses ui_controls::SendMouse***NotifyWhenDone, |
| 299 // see it for details. | 305 // see it for details. |
| 300 bool SendMouseMoveSync(const gfx::Point& location) WARN_UNUSED_RESULT; | 306 bool SendMouseMoveSync(const gfx::Point& location) WARN_UNUSED_RESULT; |
| 301 bool SendMouseEventsSync(ui_controls::MouseButton type, | 307 bool SendMouseEventsSync(ui_controls::MouseButton type, |
| 302 int state) WARN_UNUSED_RESULT; | 308 int state) WARN_UNUSED_RESULT; |
| 303 | 309 |
| 304 // Run a message loop only for the specified amount of time. | 310 // Helper class to Run and Quit the message loop. Run and Quit can only happen |
| 305 class TimedMessageLoopRunner { | 311 // once per instance. Make a new instance for each use. Calling Quit after Run |
| 312 // has returned is safe and has no effect. |
| 313 class MessageLoopRunner |
| 314 : public base::RefCounted<MessageLoopRunner> { |
| 306 public: | 315 public: |
| 307 // Create new MessageLoopForUI and attach to it. | 316 MessageLoopRunner(); |
| 308 TimedMessageLoopRunner(); | |
| 309 | 317 |
| 310 // Attach to an existing message loop. | 318 // Run the current MessageLoop. This can't be called recursively. |
| 311 explicit TimedMessageLoopRunner(MessageLoop* loop) | 319 void Run(); |
| 312 : loop_(loop), owned_(false), quit_loop_invoked_(false) {} | |
| 313 | 320 |
| 314 ~TimedMessageLoopRunner(); | 321 // Quit the matching call to Run (nested MessageLoops are unaffected). |
| 322 void QuitNow(); |
| 315 | 323 |
| 316 // Run the message loop for ms milliseconds. | 324 // Hand this closure off to code that uses callbacks to notify completion. |
| 317 void RunFor(int ms); | 325 // Example: |
| 318 | 326 // scoped_refptr<MessageLoopRunner> runner = |
| 319 // Post Quit task to the message loop. | 327 // new MessageLoopRunner; |
| 320 void Quit(); | 328 // // Must be no nested MessageLoop::Run calls during kick_off_some_api: |
| 321 | 329 // kick_off_some_api(runner.QuitNowClosure()); |
| 322 // Post delayed Quit task to the message loop. | 330 // runner.Run(); |
| 323 void QuitAfter(int ms); | 331 base::Closure QuitNowClosure(); |
| 324 | |
| 325 bool WasTimedOut() const { | |
| 326 return !quit_loop_invoked_; | |
| 327 } | |
| 328 | 332 |
| 329 private: | 333 private: |
| 330 MessageLoop* loop_; | 334 friend class base::RefCounted<MessageLoopRunner>; |
| 331 bool owned_; | 335 ~MessageLoopRunner(); |
| 332 bool quit_loop_invoked_; | |
| 333 | 336 |
| 334 DISALLOW_COPY_AND_ASSIGN(TimedMessageLoopRunner); | 337 MessageLoop::RunLoop run_loop_; |
| 338 |
| 339 DISALLOW_COPY_AND_ASSIGN(MessageLoopRunner); |
| 335 }; | 340 }; |
| 336 | 341 |
| 337 // This is a utility class for running a python websocket server | 342 // This is a utility class for running a python websocket server |
| 338 // during tests. The server is started during the construction of the | 343 // during tests. The server is started during the construction of the |
| 339 // object, and is stopped when the destructor is called. Note that | 344 // object, and is stopped when the destructor is called. Note that |
| 340 // because of the underlying script that is used: | 345 // because of the underlying script that is used: |
| 341 // | 346 // |
| 342 // third_paty/WebKit/Tools/Scripts/new-run-webkit-websocketserver | 347 // third_paty/WebKit/Tools/Scripts/new-run-webkit-websocketserver |
| 343 // | 348 // |
| 344 // Only *_wsh.py handlers found under "http/tests/websocket/tests" from the | 349 // 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... |
| 439 const content::NotificationSource& source, | 444 const content::NotificationSource& source, |
| 440 const content::NotificationDetails& details) OVERRIDE; | 445 const content::NotificationDetails& details) OVERRIDE; |
| 441 | 446 |
| 442 private: | 447 private: |
| 443 bool seen_; | 448 bool seen_; |
| 444 bool running_; | 449 bool running_; |
| 445 content::NotificationRegistrar registrar_; | 450 content::NotificationRegistrar registrar_; |
| 446 | 451 |
| 447 content::NotificationSource source_; | 452 content::NotificationSource source_; |
| 448 content::NotificationDetails details_; | 453 content::NotificationDetails details_; |
| 454 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 449 | 455 |
| 450 DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver); | 456 DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver); |
| 451 }; | 457 }; |
| 452 | 458 |
| 453 // A WindowedNotificationObserver hard-wired to observe | 459 // A WindowedNotificationObserver hard-wired to observe |
| 454 // chrome::NOTIFICATION_TAB_ADDED. | 460 // chrome::NOTIFICATION_TAB_ADDED. |
| 455 class WindowedTabAddedNotificationObserver | 461 class WindowedTabAddedNotificationObserver |
| 456 : public WindowedNotificationObserver { | 462 : public WindowedNotificationObserver { |
| 457 public: | 463 public: |
| 458 // Register to listen for notifications of NOTIFICATION_TAB_ADDED from either | 464 // Register to listen for notifications of NOTIFICATION_TAB_ADDED from either |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 | 538 |
| 533 private: | 539 private: |
| 534 // content::NotificationObserver | 540 // content::NotificationObserver |
| 535 virtual void Observe(int type, | 541 virtual void Observe(int type, |
| 536 const content::NotificationSource& source, | 542 const content::NotificationSource& source, |
| 537 const content::NotificationDetails& details) OVERRIDE; | 543 const content::NotificationDetails& details) OVERRIDE; |
| 538 | 544 |
| 539 content::WebContents* web_contents_; | 545 content::WebContents* web_contents_; |
| 540 std::vector<string16> expected_titles_; | 546 std::vector<string16> expected_titles_; |
| 541 content::NotificationRegistrar notification_registrar_; | 547 content::NotificationRegistrar notification_registrar_; |
| 548 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 542 | 549 |
| 543 // The most recently observed expected title, if any. | 550 // The most recently observed expected title, if any. |
| 544 string16 observed_title_; | 551 string16 observed_title_; |
| 545 | 552 |
| 546 bool expected_title_observed_; | 553 bool expected_title_observed_; |
| 547 bool quit_loop_on_observation_; | 554 bool quit_loop_on_observation_; |
| 548 | 555 |
| 549 DISALLOW_COPY_AND_ASSIGN(TitleWatcher); | 556 DISALLOW_COPY_AND_ASSIGN(TitleWatcher); |
| 550 }; | 557 }; |
| 551 | 558 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 | 638 |
| 632 // Overridden content::NotificationObserver methods. | 639 // Overridden content::NotificationObserver methods. |
| 633 virtual void Observe(int type, | 640 virtual void Observe(int type, |
| 634 const content::NotificationSource& source, | 641 const content::NotificationSource& source, |
| 635 const content::NotificationDetails& details) OVERRIDE; | 642 const content::NotificationDetails& details) OVERRIDE; |
| 636 | 643 |
| 637 private: | 644 private: |
| 638 content::NotificationRegistrar registrar_; | 645 content::NotificationRegistrar registrar_; |
| 639 std::queue<std::string> message_queue_; | 646 std::queue<std::string> message_queue_; |
| 640 bool waiting_for_message_; | 647 bool waiting_for_message_; |
| 648 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 641 | 649 |
| 642 DISALLOW_COPY_AND_ASSIGN(DOMMessageQueue); | 650 DISALLOW_COPY_AND_ASSIGN(DOMMessageQueue); |
| 643 }; | 651 }; |
| 644 | 652 |
| 645 // Takes a snapshot of the given render widget, rendered at |page_size|. The | 653 // Takes a snapshot of the given render widget, rendered at |page_size|. The |
| 646 // snapshot is set to |bitmap|. Returns true on success. | 654 // snapshot is set to |bitmap|. Returns true on success. |
| 647 bool TakeRenderWidgetSnapshot(content::RenderWidgetHost* rwh, | 655 bool TakeRenderWidgetSnapshot(content::RenderWidgetHost* rwh, |
| 648 const gfx::Size& page_size, | 656 const gfx::Size& page_size, |
| 649 SkBitmap* bitmap) WARN_UNUSED_RESULT; | 657 SkBitmap* bitmap) WARN_UNUSED_RESULT; |
| 650 | 658 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 // ui_controls_linux.cc and ui_controls_mac.cc | 697 // ui_controls_linux.cc and ui_controls_mac.cc |
| 690 void ClickTask(ui_controls::MouseButton button, | 698 void ClickTask(ui_controls::MouseButton button, |
| 691 int state, | 699 int state, |
| 692 const base::Closure& followup); | 700 const base::Closure& followup); |
| 693 | 701 |
| 694 } // namespace internal | 702 } // namespace internal |
| 695 | 703 |
| 696 } // namespace ui_test_utils | 704 } // namespace ui_test_utils |
| 697 | 705 |
| 698 #endif // CHROME_TEST_BASE_UI_TEST_UTILS_H_ | 706 #endif // CHROME_TEST_BASE_UI_TEST_UTILS_H_ |
| OLD | NEW |