| Index: chrome/test/base/ui_test_utils.cc
|
| diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc
|
| index efb8a8dbdb8844216b7aa01078abcc029d0b446f..7075d45c95feca7d7ebc6023b8454323dbeda0fd 100644
|
| --- a/chrome/test/base/ui_test_utils.cc
|
| +++ b/chrome/test/base/ui_test_utils.cc
|
| @@ -95,6 +95,21 @@ namespace ui_test_utils {
|
|
|
| namespace {
|
|
|
| +// Helper class to Quit the message loop only once. Subsequent calls to Quit
|
| +// are ignored.
|
| +class MessageLoopQuitter {
|
| + public:
|
| + MessageLoopQuitter() : did_quit_(false) { }
|
| + void Quit() {
|
| + if (did_quit_)
|
| + return;
|
| + did_quit_ = true;
|
| + MessageLoopForUI::current()->QuitAfterPending();
|
| + }
|
| + private:
|
| + bool did_quit_;
|
| +};
|
| +
|
| class DOMOperationObserver : public content::NotificationObserver,
|
| public content::WebContentsObserver {
|
| public:
|
| @@ -114,12 +129,12 @@ class DOMOperationObserver : public content::NotificationObserver,
|
| content::Details<DomOperationNotificationDetails> dom_op_details(details);
|
| response_ = dom_op_details->json;
|
| did_respond_ = true;
|
| - MessageLoopForUI::current()->Quit();
|
| + message_loop_quitter_.Quit();
|
| }
|
|
|
| // Overridden from content::WebContentsObserver:
|
| virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE {
|
| - MessageLoopForUI::current()->Quit();
|
| + message_loop_quitter_.Quit();
|
| }
|
|
|
| bool GetResponse(std::string* response) WARN_UNUSED_RESULT {
|
| @@ -131,6 +146,7 @@ class DOMOperationObserver : public content::NotificationObserver,
|
| content::NotificationRegistrar registrar_;
|
| std::string response_;
|
| bool did_respond_;
|
| + MessageLoopQuitter message_loop_quitter_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(DOMOperationObserver);
|
| };
|
| @@ -163,7 +179,7 @@ class FindInPageNotificationObserver : public content::NotificationObserver {
|
| active_match_ordinal_ = find_details->active_match_ordinal();
|
| if (find_details->final_update()) {
|
| number_of_matches_ = find_details->number_of_matches();
|
| - MessageLoopForUI::current()->Quit();
|
| + message_loop_quitter_.Quit();
|
| } else {
|
| DVLOG(1) << "Ignoring, since we only care about the final message";
|
| }
|
| @@ -183,6 +199,7 @@ class FindInPageNotificationObserver : public content::NotificationObserver {
|
| // The id of the current find request, obtained from WebContents. Allows us
|
| // to monitor when the search completes.
|
| int current_find_request_id_;
|
| + MessageLoopQuitter message_loop_quitter_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver);
|
| };
|
| @@ -262,10 +279,11 @@ bool ExecuteJavaScriptHelper(RenderViewHost* render_view_host,
|
| }
|
|
|
| void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id) {
|
| - MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
|
| + MessageLoop::current()->PostTask(FROM_HERE,
|
| + MessageLoop::QuitWhenIdleClosure());
|
| RunMessageLoop();
|
| content::BrowserThread::PostTask(thread_id, FROM_HERE,
|
| - MessageLoop::QuitClosure());
|
| + MessageLoop::QuitAfterPendingClosure());
|
| }
|
|
|
| } // namespace
|
| @@ -293,7 +311,8 @@ void RunMessageLoop() {
|
| }
|
|
|
| void RunAllPendingInMessageLoop() {
|
| - MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
|
| + MessageLoop::current()->PostTask(FROM_HERE,
|
| + MessageLoop::QuitWhenIdleClosure());
|
| ui_test_utils::RunMessageLoop();
|
| }
|
|
|
| @@ -331,8 +350,7 @@ void WaitForNavigations(NavigationController* controller,
|
| number_of_navigations);
|
| observer.WaitForObservation(
|
| base::Bind(&ui_test_utils::RunMessageLoop),
|
| - base::Bind(&MessageLoop::Quit,
|
| - base::Unretained(MessageLoopForUI::current())));
|
| + MessageLoop::QuitAfterPendingClosure());
|
| }
|
|
|
| void WaitForNewTab(Browser* browser) {
|
| @@ -391,8 +409,7 @@ void NavigateToURL(browser::NavigateParams* params) {
|
| browser::Navigate(params);
|
| observer.WaitForObservation(
|
| base::Bind(&ui_test_utils::RunMessageLoop),
|
| - base::Bind(&MessageLoop::Quit,
|
| - base::Unretained(MessageLoopForUI::current())));
|
| + MessageLoop::QuitAfterPendingClosure());
|
|
|
| }
|
|
|
| @@ -465,8 +482,7 @@ static void NavigateToURLWithDispositionBlockUntilNavigationsComplete(
|
| if (disposition == CURRENT_TAB) {
|
| same_tab_observer.WaitForObservation(
|
| base::Bind(&ui_test_utils::RunMessageLoop),
|
| - base::Bind(&MessageLoop::Quit,
|
| - base::Unretained(MessageLoopForUI::current())));
|
| + MessageLoop::QuitAfterPendingClosure());
|
| return;
|
| } else if (web_contents) {
|
| NavigationController* controller = &web_contents->GetController();
|
| @@ -773,11 +789,13 @@ bool SendKeyPressSync(const Browser* browser,
|
|
|
| bool result;
|
| result = ui_controls::SendKeyPressNotifyWhenDone(
|
| - window, key, control, shift, alt, command, MessageLoop::QuitClosure());
|
| + window, key, control, shift, alt, command,
|
| + MessageLoop::QuitAfterPendingClosure());
|
| #if defined(OS_WIN)
|
| if (!result && BringBrowserWindowToFront(browser)) {
|
| result = ui_controls::SendKeyPressNotifyWhenDone(
|
| - window, key, control, shift, alt, command, MessageLoop::QuitClosure());
|
| + window, key, control, shift, alt, command,
|
| + MessageLoop::QuitAfterPendingClosure());
|
| }
|
| #endif
|
| if (!result) {
|
| @@ -810,8 +828,8 @@ bool SendKeyPressAndWait(const Browser* browser,
|
| }
|
|
|
| bool SendMouseMoveSync(const gfx::Point& location) {
|
| - if (!ui_controls::SendMouseMoveNotifyWhenDone(location.x(), location.y(),
|
| - MessageLoop::QuitClosure())) {
|
| + if (!ui_controls::SendMouseMoveNotifyWhenDone(
|
| + location.x(), location.y(), MessageLoop::QuitAfterPendingClosure())) {
|
| return false;
|
| }
|
| RunMessageLoop();
|
| @@ -820,7 +838,7 @@ bool SendMouseMoveSync(const gfx::Point& location) {
|
|
|
| bool SendMouseEventsSync(ui_controls::MouseButton type, int state) {
|
| if (!ui_controls::SendMouseEventsNotifyWhenDone(
|
| - type, state, MessageLoop::QuitClosure())) {
|
| + type, state, MessageLoop::QuitAfterPendingClosure())) {
|
| return false;
|
| }
|
| RunMessageLoop();
|
| @@ -829,8 +847,7 @@ bool SendMouseEventsSync(ui_controls::MouseButton type, int state) {
|
|
|
| TimedMessageLoopRunner::TimedMessageLoopRunner()
|
| : loop_(new MessageLoopForUI()),
|
| - owned_(true),
|
| - quit_loop_invoked_(false) {
|
| + owned_(true) {
|
| }
|
|
|
| TimedMessageLoopRunner::~TimedMessageLoopRunner() {
|
| @@ -839,22 +856,11 @@ TimedMessageLoopRunner::~TimedMessageLoopRunner() {
|
| }
|
|
|
| void TimedMessageLoopRunner::RunFor(int ms) {
|
| - QuitAfter(ms);
|
| - quit_loop_invoked_ = false;
|
| - loop_->Run();
|
| -}
|
| -
|
| -void TimedMessageLoopRunner::Quit() {
|
| - quit_loop_invoked_ = true;
|
| - loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure());
|
| -}
|
| -
|
| -void TimedMessageLoopRunner::QuitAfter(int ms) {
|
| - quit_loop_invoked_ = true;
|
| loop_->PostDelayedTask(
|
| FROM_HERE,
|
| - MessageLoop::QuitClosure(),
|
| + MessageLoop::QuitAfterPendingClosure(),
|
| base::TimeDelta::FromMilliseconds(ms));
|
| + loop_->Run();
|
| }
|
|
|
| TestWebSocketServer::TestWebSocketServer()
|
| @@ -1033,7 +1039,7 @@ void WindowedNotificationObserver::Observe(
|
| if (!running_)
|
| return;
|
|
|
| - MessageLoopForUI::current()->Quit();
|
| + MessageLoopForUI::current()->QuitAfterPending();
|
| running_ = false;
|
| }
|
|
|
| @@ -1110,8 +1116,11 @@ void TitleWatcher::Observe(int type,
|
| return;
|
| observed_title_ = *it;
|
| expected_title_observed_ = true;
|
| - if (quit_loop_on_observation_)
|
| - MessageLoopForUI::current()->Quit();
|
| + if (quit_loop_on_observation_) {
|
| + // Only call Quit once, on first Observe:
|
| + quit_loop_on_observation_ = false;
|
| + MessageLoopForUI::current()->QuitAfterPending();
|
| + }
|
| }
|
|
|
| BrowserAddedObserver::BrowserAddedObserver()
|
| @@ -1146,7 +1155,7 @@ void DOMMessageQueue::Observe(int type,
|
| message_queue_.push(dom_op_details->json);
|
| if (waiting_for_message_) {
|
| waiting_for_message_ = false;
|
| - MessageLoopForUI::current()->Quit();
|
| + MessageLoopForUI::current()->QuitAfterPending();
|
| }
|
| }
|
|
|
| @@ -1221,7 +1230,7 @@ class SnapshotTaker {
|
| void OnSnapshotTaken(const SkBitmap& bitmap) {
|
| *bitmap_ = bitmap;
|
| snapshot_taken_ = true;
|
| - MessageLoop::current()->Quit();
|
| + MessageLoop::current()->QuitNow();
|
| }
|
|
|
| SkBitmap* bitmap_;
|
| @@ -1254,7 +1263,7 @@ void OverrideGeolocation(double latitude, double longitude) {
|
| position.accuracy = 0.;
|
| position.timestamp = base::Time::Now();
|
| content::OverrideLocationForTesting(position,
|
| - base::Bind(MessageLoop::QuitClosure()));
|
| + MessageLoop::QuitAfterPendingClosure());
|
| RunMessageLoop();
|
| }
|
|
|
|
|