Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Unified Diff: content/public/test/test_utils.cc

Issue 380993002: Upstream RunBlockingPoolTask(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« content/public/test/test_utils.h ('K') | « content/public/test/test_utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..890e97a83728106b73510573b95d8c7521fd2da1 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 posted to a message loop.
+class TaskObserver : public base::MessageLoop::TaskObserver {
+ public:
+ TaskObserver() : posted_(false) {}
+ virtual ~TaskObserver() {}
+
+ // MessageLoop::TaskObserver overrides.
+ virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE {
+ }
+ virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE {
+ posted_ = true;
+ }
+
+ // Returns true if any task was posted.
+ bool posted() const { return posted_; }
+
+ private:
+ bool posted_;
+ 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) {
+ content::BrowserThread::GetBlockingPool()->FlushForTesting();
+
+ TaskObserver task_observer;
sky 2014/07/11 16:37:54 It seems like you want to know if any tasks are ad
mtomasz 2014/07/14 07:33:57 Done.
hashimoto 2014/07/15 05:17:41 No need to start observing the message loop while
mtomasz 2014/07/15 05:45:29 Done.
+ base::MessageLoop::current()->AddTaskObserver(&task_observer);
+ base::RunLoop().RunUntilIdle();
+ base::MessageLoop::current()->RemoveTaskObserver(&task_observer);
+
+ if (!task_observer.posted())
+ break;
+ }
+}
+
base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop) {
return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(),
kNumQuitDeferrals);
« content/public/test/test_utils.h ('K') | « content/public/test/test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698