| 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 "platform/ThreadSafeFunctional.h" | 7 #include "platform/ThreadSafeFunctional.h" |
| 8 #include "platform/WaitableEvent.h" | 8 #include "platform/WaitableEvent.h" |
| 9 #include "public/platform/WebTraceLocation.h" | 9 #include "public/platform/WebTraceLocation.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "wtf/PtrUtil.h" | 11 #include "wtf/PtrUtil.h" |
| 12 #include <memory> | 12 #include <memory> |
| 13 | 13 |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 using namespace blink; | 17 using namespace blink; |
| 18 | 18 |
| 19 void PingPongTask(WaitableEvent* doneEvent) | 19 void PingPongTask(WaitableEvent* doneEvent) |
| 20 { | 20 { |
| 21 doneEvent->signal(); | 21 doneEvent->signal(); |
| 22 } | 22 } |
| 23 | 23 |
| 24 class BackgroundTaskRunnerTest : public testing::Test { | 24 class BackgroundTaskRunnerTest : public testing::Test { |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 TEST_F(BackgroundTaskRunnerTest, RunShortTaskOnBackgroundThread) | 27 TEST_F(BackgroundTaskRunnerTest, RunShortTaskOnBackgroundThread) |
| 28 { | 28 { |
| 29 std::unique_ptr<WaitableEvent> doneEvent = wrapUnique(new WaitableEvent()); | 29 std::unique_ptr<WaitableEvent> doneEvent = wrapUnique(new WaitableEvent()); |
| 30 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, threadSafeBind
(&PingPongTask, AllowCrossThreadAccess(doneEvent.get())), BackgroundTaskRunner::
TaskSizeShortRunningTask); | 30 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, threadSafeBind
(&PingPongTask, crossThreadUnretained(doneEvent.get())), BackgroundTaskRunner::T
askSizeShortRunningTask); |
| 31 // Test passes by not hanging on the following wait(). | 31 // Test passes by not hanging on the following wait(). |
| 32 doneEvent->wait(); | 32 doneEvent->wait(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 TEST_F(BackgroundTaskRunnerTest, RunLongTaskOnBackgroundThread) | 35 TEST_F(BackgroundTaskRunnerTest, RunLongTaskOnBackgroundThread) |
| 36 { | 36 { |
| 37 std::unique_ptr<WaitableEvent> doneEvent = wrapUnique(new WaitableEvent()); | 37 std::unique_ptr<WaitableEvent> doneEvent = wrapUnique(new WaitableEvent()); |
| 38 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, threadSafeBind
(&PingPongTask, AllowCrossThreadAccess(doneEvent.get())), BackgroundTaskRunner::
TaskSizeLongRunningTask); | 38 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, threadSafeBind
(&PingPongTask, crossThreadUnretained(doneEvent.get())), BackgroundTaskRunner::T
askSizeLongRunningTask); |
| 39 // Test passes by not hanging on the following wait(). | 39 // Test passes by not hanging on the following wait(). |
| 40 doneEvent->wait(); | 40 doneEvent->wait(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // unnamed namespace | 43 } // unnamed namespace |
| OLD | NEW |