| 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 086d084c2ec9c2eff9da38e89a056d13441d80d9..5e4a62ad485e94bc3d73752694b36ac34822202a 100644
|
| --- a/chrome/test/base/ui_test_utils.h
|
| +++ b/chrome/test/base/ui_test_utils.h
|
| @@ -306,37 +306,58 @@ 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. Quit will only quit the
|
| +// matching call to Run. Nested calls to MessageLoop::Run will not be affected.
|
| +// It is also safe to call Quit after Run has already returned -- in that case
|
| +// Quit will have no effect.
|
| +class MessageLoopRunner {
|
| public:
|
| - // Create new MessageLoopForUI and attach to it.
|
| - TimedMessageLoopRunner();
|
| + MessageLoopRunner() : message_loop_run_id_(0) { }
|
|
|
| - // Attach to an existing message loop.
|
| - explicit TimedMessageLoopRunner(MessageLoop* loop)
|
| - : loop_(loop), owned_(false), quit_loop_invoked_(false) {}
|
| + // Run the current MessageLoop. This can't be called recursively.
|
| + void Run();
|
|
|
| - ~TimedMessageLoopRunner();
|
| + // Quit the matching call to Run (nested MessageLoops are unaffected).
|
| + void QuitNow();
|
|
|
| - // Run the message loop for ms milliseconds.
|
| - void RunFor(int ms);
|
| + private:
|
| + int message_loop_run_id_;
|
| + DISALLOW_COPY_AND_ASSIGN(MessageLoopRunner);
|
| +};
|
|
|
| - // Post Quit task to the message loop.
|
| - void Quit();
|
| +// Variant of MessageLoopRunner that allows a Closure to be used for quiting.
|
| +// This variant is not reusable -- Run can only be called once. Instead, make a
|
| +// new instance for each use.
|
| +class MessageLoopRunnerClosure
|
| + : public base::RefCounted<MessageLoopRunnerClosure> {
|
| + public:
|
| + MessageLoopRunnerClosure();
|
|
|
| - // Post delayed Quit task to the message loop.
|
| - void QuitAfter(int ms);
|
| + // Run the current MessageLoop. This can't be called recursively.
|
| + void Run();
|
|
|
| - bool WasTimedOut() const {
|
| - return !quit_loop_invoked_;
|
| - }
|
| + // Hand this closure off to code that uses callbacks to notify completion.
|
| + // Example:
|
| + // scoped_refptr<MessageLoopRunnerClosure> runner =
|
| + // new MessageLoopRunnerClosure;
|
| + // // 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<MessageLoopRunnerClosure>;
|
| + ~MessageLoopRunnerClosure();
|
| +
|
| + void QuitNow();
|
| +
|
| + MessageLoopRunner message_loop_runner_;
|
| +
|
| + bool run_called_;
|
| + bool quit_received_;
|
| + bool running_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(TimedMessageLoopRunner);
|
| + DISALLOW_COPY_AND_ASSIGN(MessageLoopRunnerClosure);
|
| };
|
|
|
| // This is a utility class for running a python websocket server
|
| @@ -451,6 +472,7 @@ class WindowedNotificationObserver : public content::NotificationObserver {
|
|
|
| content::NotificationSource source_;
|
| content::NotificationDetails details_;
|
| + MessageLoopRunner message_loop_runner_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver);
|
| };
|
| @@ -544,6 +566,7 @@ class TitleWatcher : public content::NotificationObserver {
|
| content::WebContents* web_contents_;
|
| std::vector<string16> expected_titles_;
|
| content::NotificationRegistrar notification_registrar_;
|
| + MessageLoopRunner message_loop_runner_;
|
|
|
| // The most recently observed expected title, if any.
|
| string16 observed_title_;
|
| @@ -643,6 +666,7 @@ class DOMMessageQueue : public content::NotificationObserver {
|
| content::NotificationRegistrar registrar_;
|
| std::queue<std::string> message_queue_;
|
| bool waiting_for_message_;
|
| + MessageLoopRunner message_loop_runner_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(DOMMessageQueue);
|
| };
|
|
|