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

Unified Diff: content/test/test_utils.cc

Issue 10825085: Move RunAllPendingInMessageLoop from ui_test_utils.h to test_utils.h, so that it can be reused by c… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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
« no previous file with comments | « 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/test/test_utils.cc
===================================================================
--- content/test/test_utils.cc (revision 149002)
+++ content/test/test_utils.cc (working copy)
@@ -11,6 +11,8 @@
#include "content/public/test/test_launcher.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace content {
+
namespace {
// Number of times to repost a Quit task so that the MessageLoop finishes up
@@ -34,9 +36,13 @@
}
}
+void RunAllPendingMessageAndSendQuit(BrowserThread::ID thread_id,
+ const base::Closure& quit_task) {
+ RunAllPendingInMessageLoop();
+ BrowserThread::PostTask(thread_id, FROM_HERE, quit_task);
}
-namespace content {
+} // namespace
void RunMessageLoop() {
base::RunLoop run_loop;
@@ -57,6 +63,30 @@
delegate->PostRunMessageLoop();
}
+void RunAllPendingInMessageLoop() {
+ MessageLoop::current()->PostTask(FROM_HERE,
+ MessageLoop::QuitWhenIdleClosure());
+ RunMessageLoop();
+}
+
+void RunAllPendingInMessageLoop(BrowserThread::ID thread_id) {
+ if (BrowserThread::CurrentlyOn(thread_id)) {
+ RunAllPendingInMessageLoop();
+ return;
+ }
+ BrowserThread::ID current_thread_id;
+ if (!BrowserThread::GetCurrentThreadIdentifier(&current_thread_id)) {
+ NOTREACHED();
+ return;
+ }
+
+ base::RunLoop run_loop;
+ BrowserThread::PostTask(thread_id, FROM_HERE,
+ base::Bind(&RunAllPendingMessageAndSendQuit, current_thread_id,
+ run_loop.QuitClosure()));
+ RunThisRunLoop(&run_loop);
+}
+
base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop) {
return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(),
kNumQuitDeferrals);
« no previous file with comments | « content/public/test/test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698