OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "media/base/bind_to_current_loop.h" | 5 #include "media/base/bind_to_current_loop.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/memory/free_deleter.h" | 10 #include "base/memory/free_deleter.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 // Various tests that check that the bound function is only actually executed | 44 // Various tests that check that the bound function is only actually executed |
45 // on the message loop, not during the original Run. | 45 // on the message loop, not during the original Run. |
46 class BindToCurrentLoopTest : public ::testing::Test { | 46 class BindToCurrentLoopTest : public ::testing::Test { |
47 protected: | 47 protected: |
48 base::MessageLoop loop_; | 48 base::MessageLoop loop_; |
49 }; | 49 }; |
50 | 50 |
51 TEST_F(BindToCurrentLoopTest, Closure) { | 51 TEST_F(BindToCurrentLoopTest, Closure) { |
52 // Test the closure is run inside the loop, not outside it. | 52 // Test the closure is run inside the loop, not outside it. |
53 base::WaitableEvent waiter(false, false); | 53 base::WaitableEvent waiter(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 54 base::WaitableEvent::InitialState::NOT_SIGNALED); |
54 base::Closure cb = BindToCurrentLoop(base::Bind( | 55 base::Closure cb = BindToCurrentLoop(base::Bind( |
55 &base::WaitableEvent::Signal, base::Unretained(&waiter))); | 56 &base::WaitableEvent::Signal, base::Unretained(&waiter))); |
56 cb.Run(); | 57 cb.Run(); |
57 EXPECT_FALSE(waiter.IsSignaled()); | 58 EXPECT_FALSE(waiter.IsSignaled()); |
58 loop_.RunUntilIdle(); | 59 loop_.RunUntilIdle(); |
59 EXPECT_TRUE(waiter.IsSignaled()); | 60 EXPECT_TRUE(waiter.IsSignaled()); |
60 } | 61 } |
61 | 62 |
62 TEST_F(BindToCurrentLoopTest, Bool) { | 63 TEST_F(BindToCurrentLoopTest, Bool) { |
63 bool bool_var = false; | 64 bool bool_var = false; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 &BoundIntegersSet, &a, &b)); | 164 &BoundIntegersSet, &a, &b)); |
164 cb.Run(1, -1); | 165 cb.Run(1, -1); |
165 EXPECT_EQ(a, 0); | 166 EXPECT_EQ(a, 0); |
166 EXPECT_EQ(b, 0); | 167 EXPECT_EQ(b, 0); |
167 loop_.RunUntilIdle(); | 168 loop_.RunUntilIdle(); |
168 EXPECT_EQ(a, 1); | 169 EXPECT_EQ(a, 1); |
169 EXPECT_EQ(b, -1); | 170 EXPECT_EQ(b, -1); |
170 } | 171 } |
171 | 172 |
172 } // namespace media | 173 } // namespace media |
OLD | NEW |