OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/threading/BackgroundTaskRunner.h" | 5 #include "platform/threading/BackgroundTaskRunner.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include "base/test/scoped_async_task_scheduler.h" | 8 #include "base/test/scoped_async_task_scheduler.h" |
9 #include "platform/CrossThreadFunctional.h" | 9 #include "platform/CrossThreadFunctional.h" |
10 #include "platform/WaitableEvent.h" | 10 #include "platform/WaitableEvent.h" |
| 11 #include "platform/wtf/PtrUtil.h" |
11 #include "public/platform/WebTraceLocation.h" | 12 #include "public/platform/WebTraceLocation.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "wtf/PtrUtil.h" | |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 void PingPongTask(WaitableEvent* done_event) { | 19 void PingPongTask(WaitableEvent* done_event) { |
20 done_event->Signal(); | 20 done_event->Signal(); |
21 } | 21 } |
22 | 22 |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 TEST(BackgroundTaskRunnerTest, RunOnBackgroundThread) { | 25 TEST(BackgroundTaskRunnerTest, RunOnBackgroundThread) { |
26 base::test::ScopedAsyncTaskScheduler scoped_async_task_scheduler; | 26 base::test::ScopedAsyncTaskScheduler scoped_async_task_scheduler; |
27 std::unique_ptr<WaitableEvent> done_event = WTF::MakeUnique<WaitableEvent>(); | 27 std::unique_ptr<WaitableEvent> done_event = WTF::MakeUnique<WaitableEvent>(); |
28 BackgroundTaskRunner::PostOnBackgroundThread( | 28 BackgroundTaskRunner::PostOnBackgroundThread( |
29 BLINK_FROM_HERE, | 29 BLINK_FROM_HERE, |
30 CrossThreadBind(&PingPongTask, CrossThreadUnretained(done_event.get()))); | 30 CrossThreadBind(&PingPongTask, CrossThreadUnretained(done_event.get()))); |
31 // Test passes by not hanging on the following wait(). | 31 // Test passes by not hanging on the following wait(). |
32 done_event->Wait(); | 32 done_event->Wait(); |
33 } | 33 } |
34 | 34 |
35 } // namespace blink | 35 } // namespace blink |
OLD | NEW |