Index: third_party/WebKit/Source/platform/BackgroundTaskTest.cpp |
diff --git a/third_party/WebKit/Source/platform/BackgroundTaskTest.cpp b/third_party/WebKit/Source/platform/BackgroundTaskTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..554e5bec1dcb626bdb632593019f34cee09ce31c |
--- /dev/null |
+++ b/third_party/WebKit/Source/platform/BackgroundTaskTest.cpp |
@@ -0,0 +1,50 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+#include "platform/BackgroundTask.h" |
+ |
+#include "public/platform/Platform.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+ |
+namespace { |
+ |
+using namespace blink; |
+ |
+class PingTask : public BackgroundTask { |
+public: |
+ PingTask(WebWaitableEvent* doneEvent) |
+ : m_doneEvent(doneEvent) |
+ { } |
+ |
+ void run() |
+ { |
+ m_doneEvent->signal(); |
+ } |
+ |
+private: |
+ WebWaitableEvent* m_doneEvent; |
+}; |
+ |
+class BackgroundTaskTest : public testing::Test { |
+}; |
+ |
+TEST_F(BackgroundTaskTest, RunShortTaskOnBackgroundThread) |
+{ |
+ OwnPtr<WebWaitableEvent> doneEvent = adoptPtr(Platform::current()->createWaitableEvent()); |
+ BackgroundTask::postOnBackgroundThread(new PingTask(doneEvent.get()), BackgroundTask::TaskSizeShortRunningTask); |
+ // Test passes by not hanging on the following wait(). |
+ doneEvent->wait(); |
+} |
+ |
+TEST_F(BackgroundTaskTest, RunLongTaskOnBackgroundThread) |
+{ |
+ OwnPtr<WebWaitableEvent> doneEvent = adoptPtr(Platform::current()->createWaitableEvent()); |
+ BackgroundTask::postOnBackgroundThread(new PingTask(doneEvent.get()), BackgroundTask::TaskSizeLongRunningTask); |
+ // Test passes by not hanging on the following wait(). |
+ doneEvent->wait(); |
+} |
+ |
+} // unnamed namespace |