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

Side by Side Diff: third_party/WebKit/Source/platform/threading/BackgroundTaskRunnerTest.cpp

Issue 2685673005: Use TaskScheduler instead of WorkerPool in BackgroundTaskRunner.cpp (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
OLDNEW
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>
8 #include "base/test/scoped_async_task_scheduler.h"
7 #include "platform/CrossThreadFunctional.h" 9 #include "platform/CrossThreadFunctional.h"
8 #include "platform/WaitableEvent.h" 10 #include "platform/WaitableEvent.h"
9 #include "public/platform/WebTraceLocation.h" 11 #include "public/platform/WebTraceLocation.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 #include "wtf/PtrUtil.h" 13 #include "wtf/PtrUtil.h"
12 #include <memory>
13 14
14 namespace blink { 15 namespace blink {
15 16
16 namespace { 17 namespace {
17 18
18 void PingPongTask(WaitableEvent* doneEvent) { 19 void PingPongTask(WaitableEvent* doneEvent) {
19 doneEvent->signal(); 20 doneEvent->signal();
20 } 21 }
21 22
22 class BackgroundTaskRunnerTest : public testing::Test {};
23
24 } // namespace 23 } // namespace
25 24
26 TEST_F(BackgroundTaskRunnerTest, RunShortTaskOnBackgroundThread) { 25 TEST(BackgroundTaskRunnerTest, RunOnBackgroundThread) {
26 base::test::ScopedAsyncTaskScheduler scopedAsyncTaskScheduler;
27 std::unique_ptr<WaitableEvent> doneEvent = WTF::makeUnique<WaitableEvent>(); 27 std::unique_ptr<WaitableEvent> doneEvent = WTF::makeUnique<WaitableEvent>();
28 BackgroundTaskRunner::postOnBackgroundThread( 28 BackgroundTaskRunner::postOnBackgroundThread(
29 BLINK_FROM_HERE, 29 BLINK_FROM_HERE,
30 crossThreadBind(&PingPongTask, crossThreadUnretained(doneEvent.get())), 30 crossThreadBind(&PingPongTask, crossThreadUnretained(doneEvent.get())));
31 BackgroundTaskRunner::TaskSizeShortRunningTask);
32 // Test passes by not hanging on the following wait(). 31 // Test passes by not hanging on the following wait().
33 doneEvent->wait(); 32 doneEvent->wait();
34 } 33 }
35
36 TEST_F(BackgroundTaskRunnerTest, RunLongTaskOnBackgroundThread) {
37 std::unique_ptr<WaitableEvent> doneEvent = WTF::makeUnique<WaitableEvent>();
38 BackgroundTaskRunner::postOnBackgroundThread(
39 BLINK_FROM_HERE,
40 crossThreadBind(&PingPongTask, crossThreadUnretained(doneEvent.get())),
41 BackgroundTaskRunner::TaskSizeLongRunningTask);
42 // Test passes by not hanging on the following wait().
43 doneEvent->wait();
44 }
45 34
46 } // namespace blink 35 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698