Chromium Code Reviews| Index: content/public/test/test_utils.cc |
| diff --git a/content/public/test/test_utils.cc b/content/public/test/test_utils.cc |
| index ae45762dab52550be6d1c7008b24dc8b224f5bf0..c90a6c0a3da5ce1f9d9be38cefe002d5f1a1a6ea 100644 |
| --- a/content/public/test/test_utils.cc |
| +++ b/content/public/test/test_utils.cc |
| @@ -49,7 +49,7 @@ void RunAllPendingMessageAndSendQuit(BrowserThread::ID thread_id, |
| BrowserThread::PostTask(thread_id, FROM_HERE, quit_task); |
| } |
| -// Class used handle result callbacks for ExecuteScriptAndGetValue. |
| +// Class used to handle result callbacks for ExecuteScriptAndGetValue. |
| class ScriptCallback { |
| public: |
| ScriptCallback() { } |
| @@ -70,6 +70,27 @@ void ScriptCallback::ResultCallback(const base::Value* result) { |
| base::MessageLoop::current()->Quit(); |
| } |
| +// Monitors if any task is processed by the message loop. |
| +class TaskObserver : public base::MessageLoop::TaskObserver { |
| + public: |
| + TaskObserver() : processed_(false) {} |
| + virtual ~TaskObserver() {} |
| + |
| + // MessageLoop::TaskObserver overrides. |
| + virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
| + } |
| + virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
| + processed_ = true; |
| + } |
| + |
| + // Returns true if any task was processed. |
| + bool processed() const { return processed_; } |
| + |
| + private: |
| + bool processed_; |
| + DISALLOW_COPY_AND_ASSIGN(TaskObserver); |
| +}; |
| + |
| // Adapter that makes a WindowedNotificationObserver::ConditionTestCallback from |
| // a WindowedNotificationObserver::ConditionTestCallbackWithoutSourceAndDetails |
| // by ignoring the notification source and details. |
| @@ -129,6 +150,20 @@ void RunAllPendingInMessageLoop(BrowserThread::ID thread_id) { |
| RunThisRunLoop(&run_loop); |
| } |
| +void RunAllBlockingPoolTasksUntilIdle() { |
| + while (true) { |
| + TaskObserver task_observer; |
|
hashimoto
2014/07/15 05:49:40
nit: task_observer should be declared and initiali
mtomasz
2014/07/15 05:59:16
Done.
|
| + content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| + |
| + base::MessageLoop::current()->AddTaskObserver(&task_observer); |
| + base::RunLoop().RunUntilIdle(); |
| + base::MessageLoop::current()->RemoveTaskObserver(&task_observer); |
| + |
| + if (!task_observer.processed()) |
| + break; |
| + } |
| +} |
| + |
| base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop) { |
| return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(), |
| kNumQuitDeferrals); |