Index: third_party/WebKit/Source/platform/testing/UnitTestHelpers.cpp |
diff --git a/third_party/WebKit/Source/platform/testing/UnitTestHelpers.cpp b/third_party/WebKit/Source/platform/testing/UnitTestHelpers.cpp |
index 814a7f7150012d4cd85c2493031e8d990bbe3768..36f6123b3b247bff4921fbc551fef7fe91781b9f 100644 |
--- a/third_party/WebKit/Source/platform/testing/UnitTestHelpers.cpp |
+++ b/third_party/WebKit/Source/platform/testing/UnitTestHelpers.cpp |
@@ -30,6 +30,7 @@ |
#include "base/message_loop/message_loop.h" |
#include "base/path_service.h" |
#include "platform/SharedBuffer.h" |
+#include "platform/Timer.h" |
#include "public/platform/FilePathConversion.h" |
#include "public/platform/Platform.h" |
#include "public/platform/WebString.h" |
@@ -48,6 +49,22 @@ void runPendingTasks() |
enterRunLoop(); |
} |
+struct QuitTask { |
+ void timerFired(Timer<QuitTask>*) |
+ { |
+ // We cannot just exit loop here, because we may be halfway through the task queue. |
+ Platform::current()->currentThread()->getWebTaskRunner()->postTask(BLINK_FROM_HERE, bind(&exitRunLoop)); |
+ } |
+}; |
+ |
+void waitForDeferredTasks(double seconds) |
+{ |
+ // Pending tasks include Timers that have been scheduled. |
+ Timer<QuitTask> quitOnTimeout(new QuitTask, &QuitTask::timerFired); |
+ quitOnTimeout.startOneShot(seconds, BLINK_FROM_HERE); |
+ testing::enterRunLoop(); |
+} |
+ |
String blinkRootDir() |
{ |
base::FilePath path; |