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

Side by Side Diff: base/threading/sequenced_task_runner_handle_unittest.cc

Issue 2032603002: Migrate WaitableEvent to enum-based constructor in base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@WEvent_enums
Patch Set: undo incorrect template change Created 4 years, 6 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 "base/threading/sequenced_task_runner_handle.h" 5 #include "base/threading/sequenced_task_runner_handle.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 TEST_F(SequencedTaskRunnerHandleTest, FromMessageLoop) { 56 TEST_F(SequencedTaskRunnerHandleTest, FromMessageLoop) {
57 RunLoop run_loop; 57 RunLoop run_loop;
58 VerifyCurrentSequencedTaskRunner(run_loop.QuitClosure()); 58 VerifyCurrentSequencedTaskRunner(run_loop.QuitClosure());
59 run_loop.Run(); 59 run_loop.Run();
60 } 60 }
61 61
62 TEST_F(SequencedTaskRunnerHandleTest, FromSequencedWorkerPoolTask) { 62 TEST_F(SequencedTaskRunnerHandleTest, FromSequencedWorkerPoolTask) {
63 // Wrap the SequencedWorkerPool to avoid leaks due to its asynchronous 63 // Wrap the SequencedWorkerPool to avoid leaks due to its asynchronous
64 // destruction. 64 // destruction.
65 SequencedWorkerPoolOwner owner(3, "Test"); 65 SequencedWorkerPoolOwner owner(3, "Test");
66 WaitableEvent event(false, false); 66 WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC,
67 WaitableEvent::InitialState::NOT_SIGNALED);
67 owner.pool()->PostSequencedWorkerTask( 68 owner.pool()->PostSequencedWorkerTask(
68 owner.pool()->GetSequenceToken(), FROM_HERE, 69 owner.pool()->GetSequenceToken(), FROM_HERE,
69 base::Bind( 70 base::Bind(
70 &SequencedTaskRunnerHandleTest::VerifyCurrentSequencedTaskRunner, 71 &SequencedTaskRunnerHandleTest::VerifyCurrentSequencedTaskRunner,
71 base::Bind(&WaitableEvent::Signal, base::Unretained(&event)))); 72 base::Bind(&WaitableEvent::Signal, base::Unretained(&event))));
72 event.Wait(); 73 event.Wait();
73 owner.pool()->Shutdown(); 74 owner.pool()->Shutdown();
74 } 75 }
75 76
76 TEST_F(SequencedTaskRunnerHandleTest, FromUnsequencedTask) { 77 TEST_F(SequencedTaskRunnerHandleTest, FromUnsequencedTask) {
77 // Wrap the SequencedWorkerPool to avoid leaks due to its asynchronous 78 // Wrap the SequencedWorkerPool to avoid leaks due to its asynchronous
78 // destruction. 79 // destruction.
79 SequencedWorkerPoolOwner owner(3, "Test"); 80 SequencedWorkerPoolOwner owner(3, "Test");
80 WaitableEvent event(false, false); 81 WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC,
82 WaitableEvent::InitialState::NOT_SIGNALED);
81 owner.pool()->PostWorkerTask( 83 owner.pool()->PostWorkerTask(
82 FROM_HERE, 84 FROM_HERE,
83 base::Bind( 85 base::Bind(
84 &SequencedTaskRunnerHandleTest::VerifyCurrentSequencedTaskRunner, 86 &SequencedTaskRunnerHandleTest::VerifyCurrentSequencedTaskRunner,
85 base::Bind(&WaitableEvent::Signal, base::Unretained(&event)))); 87 base::Bind(&WaitableEvent::Signal, base::Unretained(&event))));
86 event.Wait(); 88 event.Wait();
87 } 89 }
88 90
89 TEST(SequencedTaskRunnerHandleTestWithoutMessageLoop, FromHandleInScope) { 91 TEST(SequencedTaskRunnerHandleTestWithoutMessageLoop, FromHandleInScope) {
90 scoped_refptr<SequencedTaskRunner> test_task_runner(new TestSimpleTaskRunner); 92 scoped_refptr<SequencedTaskRunner> test_task_runner(new TestSimpleTaskRunner);
91 EXPECT_FALSE(SequencedTaskRunnerHandle::IsSet()); 93 EXPECT_FALSE(SequencedTaskRunnerHandle::IsSet());
92 EXPECT_FALSE(ThreadTaskRunnerHandle::IsSet()); 94 EXPECT_FALSE(ThreadTaskRunnerHandle::IsSet());
93 { 95 {
94 SequencedTaskRunnerHandle handle(test_task_runner); 96 SequencedTaskRunnerHandle handle(test_task_runner);
95 EXPECT_TRUE(SequencedTaskRunnerHandle::IsSet()); 97 EXPECT_TRUE(SequencedTaskRunnerHandle::IsSet());
96 EXPECT_FALSE(ThreadTaskRunnerHandle::IsSet()); 98 EXPECT_FALSE(ThreadTaskRunnerHandle::IsSet());
97 EXPECT_EQ(test_task_runner, SequencedTaskRunnerHandle::Get()); 99 EXPECT_EQ(test_task_runner, SequencedTaskRunnerHandle::Get());
98 } 100 }
99 EXPECT_FALSE(SequencedTaskRunnerHandle::IsSet()); 101 EXPECT_FALSE(SequencedTaskRunnerHandle::IsSet());
100 EXPECT_FALSE(ThreadTaskRunnerHandle::IsSet()); 102 EXPECT_FALSE(ThreadTaskRunnerHandle::IsSet());
101 } 103 }
102 104
103 } // namespace 105 } // namespace
104 } // namespace base 106 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/platform_thread_unittest.cc ('k') | base/threading/sequenced_worker_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698