| Index: chrome/test/base/ui_test_utils.h
|
| diff --git a/chrome/test/base/ui_test_utils.h b/chrome/test/base/ui_test_utils.h
|
| index d21875cc1db0d7fe1a88ee86ad442f037dfe71a9..03ef615b6c522ec0dc79de6d8445179684820d33 100644
|
| --- a/chrome/test/base/ui_test_utils.h
|
| +++ b/chrome/test/base/ui_test_utils.h
|
| @@ -100,6 +100,18 @@ enum BrowserTestWaitFlags {
|
| // process browser tests that need to block until a condition is met.
|
| void RunMessageLoop();
|
|
|
| +// Variant of RunMessageLoop that takes a |run_id| (from
|
| +// MessageLoop::current()->GetRunID()).
|
| +void RunMessageLoopWithID(const MessageLoop::RunID& run_id);
|
| +
|
| +// Quit the MessageLoop Run of the specified |run_id|.
|
| +void QuitMessageLoopWithID(const MessageLoop::RunID& run_id);
|
| +
|
| +// Get a MessageLoop::QuitNowWithID task that will repost itself a few times to
|
| +// allow the MessageLoop to finish pending tasks (and tasks posted by those
|
| +// pending tasks...).
|
| +base::Closure QuitMessageLoopWithIDClosure(const MessageLoop::RunID& run_id);
|
| +
|
| // Turns on nestable tasks, runs all pending tasks in the message loop,
|
| // then resets nestable tasks to what they were originally. Prefer this
|
| // over MessageLoop::RunAllPending for in process browser tests to run
|
| @@ -313,37 +325,39 @@ bool SendMouseMoveSync(const gfx::Point& location) WARN_UNUSED_RESULT;
|
| bool SendMouseEventsSync(ui_controls::MouseButton type,
|
| int state) WARN_UNUSED_RESULT;
|
|
|
| -// Run a message loop only for the specified amount of time.
|
| -class TimedMessageLoopRunner {
|
| +// Helper class to Run and Quit the message loop. Run and Quit can only happen
|
| +// once per instance. Make a new instance for each use. Calling Quit after Run
|
| +// has returned is safe and has no effect.
|
| +class MessageLoopRunner
|
| + : public base::RefCounted<MessageLoopRunner> {
|
| public:
|
| - // Create new MessageLoopForUI and attach to it.
|
| - TimedMessageLoopRunner();
|
| -
|
| - // Attach to an existing message loop.
|
| - explicit TimedMessageLoopRunner(MessageLoop* loop)
|
| - : loop_(loop), owned_(false), quit_loop_invoked_(false) {}
|
| -
|
| - ~TimedMessageLoopRunner();
|
| + MessageLoopRunner();
|
|
|
| - // Run the message loop for ms milliseconds.
|
| - void RunFor(int ms);
|
| + // Run the current MessageLoop. This can't be called recursively.
|
| + void Run();
|
|
|
| - // Post Quit task to the message loop.
|
| - void Quit();
|
| + // Quit the matching call to Run (nested MessageLoops are unaffected).
|
| + void QuitNow();
|
|
|
| - // Post delayed Quit task to the message loop.
|
| - void QuitAfter(int ms);
|
| -
|
| - bool WasTimedOut() const {
|
| - return !quit_loop_invoked_;
|
| - }
|
| + // Hand this closure off to code that uses callbacks to notify completion.
|
| + // Example:
|
| + // scoped_refptr<MessageLoopRunner> runner =
|
| + // new MessageLoopRunner;
|
| + // // Must be no nested MessageLoop::Run calls during kick_off_some_api:
|
| + // kick_off_some_api(runner.QuitNowClosure());
|
| + // runner.Run();
|
| + base::Closure QuitNowClosure();
|
|
|
| private:
|
| - MessageLoop* loop_;
|
| - bool owned_;
|
| - bool quit_loop_invoked_;
|
| + friend class base::RefCounted<MessageLoopRunner>;
|
| + ~MessageLoopRunner();
|
| +
|
| + MessageLoop::RunID message_loop_run_id_;
|
| + bool run_called_;
|
| + bool quit_received_;
|
| + bool running_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(TimedMessageLoopRunner);
|
| + DISALLOW_COPY_AND_ASSIGN(MessageLoopRunner);
|
| };
|
|
|
| // This is a utility class for running a python websocket server
|
| @@ -458,6 +472,7 @@ class WindowedNotificationObserver : public content::NotificationObserver {
|
|
|
| content::NotificationSource source_;
|
| content::NotificationDetails details_;
|
| + scoped_refptr<MessageLoopRunner> message_loop_runner_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver);
|
| };
|
| @@ -551,6 +566,7 @@ class TitleWatcher : public content::NotificationObserver {
|
| content::WebContents* web_contents_;
|
| std::vector<string16> expected_titles_;
|
| content::NotificationRegistrar notification_registrar_;
|
| + scoped_refptr<MessageLoopRunner> message_loop_runner_;
|
|
|
| // The most recently observed expected title, if any.
|
| string16 observed_title_;
|
| @@ -650,6 +666,7 @@ class DOMMessageQueue : public content::NotificationObserver {
|
| content::NotificationRegistrar registrar_;
|
| std::queue<std::string> message_queue_;
|
| bool waiting_for_message_;
|
| + scoped_refptr<MessageLoopRunner> message_loop_runner_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(DOMMessageQueue);
|
| };
|
|
|