OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/callback_list.h" | 5 #include "base/callback_list.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <utility> | 8 #include <utility> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 namespace { | 16 namespace { |
17 | 17 |
18 class Listener { | 18 class Listener { |
19 public: | 19 public: |
20 Listener() : total_(0), scaler_(1) {} | 20 Listener() : total_(0), scaler_(1) {} |
21 explicit Listener(int scaler) : total_(0), scaler_(scaler) {} | 21 explicit Listener(int scaler) : total_(0), scaler_(scaler) {} |
22 void IncrementTotal() { total_++; } | 22 void IncrementTotal() { total_++; } |
23 void IncrementByMultipleOfScaler(int x) { total_ += x * scaler_; } | 23 void IncrementByMultipleOfScaler(int x) { total_ += x * scaler_; } |
24 | 24 |
25 int total() const { return total_; } | 25 int total() const { return total_; } |
26 | 26 |
27 private: | 27 private: |
28 int total_; | 28 int total_; |
29 int scaler_; | 29 int scaler_; |
30 DISALLOW_COPY_AND_ASSIGN(Listener); | 30 DISALLOW_COPY_AND_ASSIGN(Listener); |
31 }; | 31 }; |
32 | 32 |
33 class Remover { | 33 class Remover { |
34 public: | 34 public: |
35 Remover() : total_(0) {} | 35 Remover() : total_(0) {} |
36 void IncrementTotalAndRemove() { | 36 void IncrementTotalAndRemove() { |
37 total_++; | 37 total_++; |
38 removal_subscription_.reset(); | 38 removal_subscription_.reset(); |
39 } | 39 } |
40 void SetSubscriptionToRemove( | 40 void SetSubscriptionToRemove( |
41 scoped_ptr<CallbackList<void(void)>::Subscription> sub) { | 41 std::unique_ptr<CallbackList<void(void)>::Subscription> sub) { |
42 removal_subscription_ = std::move(sub); | 42 removal_subscription_ = std::move(sub); |
43 } | 43 } |
44 | 44 |
45 int total() const { return total_; } | 45 int total() const { return total_; } |
46 | 46 |
47 private: | 47 private: |
48 int total_; | 48 int total_; |
49 scoped_ptr<CallbackList<void(void)>::Subscription> removal_subscription_; | 49 std::unique_ptr<CallbackList<void(void)>::Subscription> removal_subscription_; |
50 DISALLOW_COPY_AND_ASSIGN(Remover); | 50 DISALLOW_COPY_AND_ASSIGN(Remover); |
51 }; | 51 }; |
52 | 52 |
53 class Adder { | 53 class Adder { |
54 public: | 54 public: |
55 explicit Adder(CallbackList<void(void)>* cb_reg) | 55 explicit Adder(CallbackList<void(void)>* cb_reg) |
56 : added_(false), | 56 : added_(false), |
57 total_(0), | 57 total_(0), |
58 cb_reg_(cb_reg) { | 58 cb_reg_(cb_reg) { |
59 } | 59 } |
60 void AddCallback() { | 60 void AddCallback() { |
61 if (!added_) { | 61 if (!added_) { |
62 added_ = true; | 62 added_ = true; |
63 subscription_ = | 63 subscription_ = |
64 cb_reg_->Add(Bind(&Adder::IncrementTotal, Unretained(this))); | 64 cb_reg_->Add(Bind(&Adder::IncrementTotal, Unretained(this))); |
65 } | 65 } |
66 } | 66 } |
67 void IncrementTotal() { total_++; } | 67 void IncrementTotal() { total_++; } |
68 | 68 |
69 bool added() const { return added_; } | 69 bool added() const { return added_; } |
70 | 70 |
71 int total() const { return total_; } | 71 int total() const { return total_; } |
72 | 72 |
73 private: | 73 private: |
74 bool added_; | 74 bool added_; |
75 int total_; | 75 int total_; |
76 CallbackList<void(void)>* cb_reg_; | 76 CallbackList<void(void)>* cb_reg_; |
77 scoped_ptr<CallbackList<void(void)>::Subscription> subscription_; | 77 std::unique_ptr<CallbackList<void(void)>::Subscription> subscription_; |
78 DISALLOW_COPY_AND_ASSIGN(Adder); | 78 DISALLOW_COPY_AND_ASSIGN(Adder); |
79 }; | 79 }; |
80 | 80 |
81 class Summer { | 81 class Summer { |
82 public: | 82 public: |
83 Summer() : value_(0) {} | 83 Summer() : value_(0) {} |
84 | 84 |
85 void AddOneParam(int a) { value_ = a; } | 85 void AddOneParam(int a) { value_ = a; } |
86 void AddTwoParam(int a, int b) { value_ = a + b; } | 86 void AddTwoParam(int a, int b) { value_ = a + b; } |
87 void AddThreeParam(int a, int b, int c) { value_ = a + b + c; } | 87 void AddThreeParam(int a, int b, int c) { value_ = a + b + c; } |
(...skipping 23 matching lines...) Expand all Loading... |
111 private: | 111 private: |
112 int value_; | 112 int value_; |
113 DISALLOW_COPY_AND_ASSIGN(Counter); | 113 DISALLOW_COPY_AND_ASSIGN(Counter); |
114 }; | 114 }; |
115 | 115 |
116 // Sanity check that we can instantiate a CallbackList for each arity. | 116 // Sanity check that we can instantiate a CallbackList for each arity. |
117 TEST(CallbackListTest, ArityTest) { | 117 TEST(CallbackListTest, ArityTest) { |
118 Summer s; | 118 Summer s; |
119 | 119 |
120 CallbackList<void(int)> c1; | 120 CallbackList<void(int)> c1; |
121 scoped_ptr<CallbackList<void(int)>::Subscription> subscription1 = | 121 std::unique_ptr<CallbackList<void(int)>::Subscription> subscription1 = |
122 c1.Add(Bind(&Summer::AddOneParam, Unretained(&s))); | 122 c1.Add(Bind(&Summer::AddOneParam, Unretained(&s))); |
123 | 123 |
124 c1.Notify(1); | 124 c1.Notify(1); |
125 EXPECT_EQ(1, s.value()); | 125 EXPECT_EQ(1, s.value()); |
126 | 126 |
127 CallbackList<void(int, int)> c2; | 127 CallbackList<void(int, int)> c2; |
128 scoped_ptr<CallbackList<void(int, int)>::Subscription> subscription2 = | 128 std::unique_ptr<CallbackList<void(int, int)>::Subscription> subscription2 = |
129 c2.Add(Bind(&Summer::AddTwoParam, Unretained(&s))); | 129 c2.Add(Bind(&Summer::AddTwoParam, Unretained(&s))); |
130 | 130 |
131 c2.Notify(1, 2); | 131 c2.Notify(1, 2); |
132 EXPECT_EQ(3, s.value()); | 132 EXPECT_EQ(3, s.value()); |
133 | 133 |
134 CallbackList<void(int, int, int)> c3; | 134 CallbackList<void(int, int, int)> c3; |
135 scoped_ptr<CallbackList<void(int, int, int)>::Subscription> | 135 std::unique_ptr<CallbackList<void(int, int, int)>::Subscription> |
136 subscription3 = c3.Add(Bind(&Summer::AddThreeParam, Unretained(&s))); | 136 subscription3 = c3.Add(Bind(&Summer::AddThreeParam, Unretained(&s))); |
137 | 137 |
138 c3.Notify(1, 2, 3); | 138 c3.Notify(1, 2, 3); |
139 EXPECT_EQ(6, s.value()); | 139 EXPECT_EQ(6, s.value()); |
140 | 140 |
141 CallbackList<void(int, int, int, int)> c4; | 141 CallbackList<void(int, int, int, int)> c4; |
142 scoped_ptr<CallbackList<void(int, int, int, int)>::Subscription> | 142 std::unique_ptr<CallbackList<void(int, int, int, int)>::Subscription> |
143 subscription4 = c4.Add(Bind(&Summer::AddFourParam, Unretained(&s))); | 143 subscription4 = c4.Add(Bind(&Summer::AddFourParam, Unretained(&s))); |
144 | 144 |
145 c4.Notify(1, 2, 3, 4); | 145 c4.Notify(1, 2, 3, 4); |
146 EXPECT_EQ(10, s.value()); | 146 EXPECT_EQ(10, s.value()); |
147 | 147 |
148 CallbackList<void(int, int, int, int, int)> c5; | 148 CallbackList<void(int, int, int, int, int)> c5; |
149 scoped_ptr<CallbackList<void(int, int, int, int, int)>::Subscription> | 149 std::unique_ptr<CallbackList<void(int, int, int, int, int)>::Subscription> |
150 subscription5 = c5.Add(Bind(&Summer::AddFiveParam, Unretained(&s))); | 150 subscription5 = c5.Add(Bind(&Summer::AddFiveParam, Unretained(&s))); |
151 | 151 |
152 c5.Notify(1, 2, 3, 4, 5); | 152 c5.Notify(1, 2, 3, 4, 5); |
153 EXPECT_EQ(15, s.value()); | 153 EXPECT_EQ(15, s.value()); |
154 | 154 |
155 CallbackList<void(int, int, int, int, int, int)> c6; | 155 CallbackList<void(int, int, int, int, int, int)> c6; |
156 scoped_ptr<CallbackList<void(int, int, int, int, int, int)>::Subscription> | 156 std::unique_ptr< |
| 157 CallbackList<void(int, int, int, int, int, int)>::Subscription> |
157 subscription6 = c6.Add(Bind(&Summer::AddSixParam, Unretained(&s))); | 158 subscription6 = c6.Add(Bind(&Summer::AddSixParam, Unretained(&s))); |
158 | 159 |
159 c6.Notify(1, 2, 3, 4, 5, 6); | 160 c6.Notify(1, 2, 3, 4, 5, 6); |
160 EXPECT_EQ(21, s.value()); | 161 EXPECT_EQ(21, s.value()); |
161 } | 162 } |
162 | 163 |
163 // Sanity check that closures added to the list will be run, and those removed | 164 // Sanity check that closures added to the list will be run, and those removed |
164 // from the list will not be run. | 165 // from the list will not be run. |
165 TEST(CallbackListTest, BasicTest) { | 166 TEST(CallbackListTest, BasicTest) { |
166 CallbackList<void(void)> cb_reg; | 167 CallbackList<void(void)> cb_reg; |
167 Listener a, b, c; | 168 Listener a, b, c; |
168 | 169 |
169 scoped_ptr<CallbackList<void(void)>::Subscription> a_subscription = | 170 std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription = |
170 cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&a))); | 171 cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&a))); |
171 scoped_ptr<CallbackList<void(void)>::Subscription> b_subscription = | 172 std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription = |
172 cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b))); | 173 cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b))); |
173 | 174 |
174 EXPECT_TRUE(a_subscription.get()); | 175 EXPECT_TRUE(a_subscription.get()); |
175 EXPECT_TRUE(b_subscription.get()); | 176 EXPECT_TRUE(b_subscription.get()); |
176 | 177 |
177 cb_reg.Notify(); | 178 cb_reg.Notify(); |
178 | 179 |
179 EXPECT_EQ(1, a.total()); | 180 EXPECT_EQ(1, a.total()); |
180 EXPECT_EQ(1, b.total()); | 181 EXPECT_EQ(1, b.total()); |
181 | 182 |
182 b_subscription.reset(); | 183 b_subscription.reset(); |
183 | 184 |
184 scoped_ptr<CallbackList<void(void)>::Subscription> c_subscription = | 185 std::unique_ptr<CallbackList<void(void)>::Subscription> c_subscription = |
185 cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&c))); | 186 cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&c))); |
186 | 187 |
187 cb_reg.Notify(); | 188 cb_reg.Notify(); |
188 | 189 |
189 EXPECT_EQ(2, a.total()); | 190 EXPECT_EQ(2, a.total()); |
190 EXPECT_EQ(1, b.total()); | 191 EXPECT_EQ(1, b.total()); |
191 EXPECT_EQ(1, c.total()); | 192 EXPECT_EQ(1, c.total()); |
192 | 193 |
193 a_subscription.reset(); | 194 a_subscription.reset(); |
194 b_subscription.reset(); | 195 b_subscription.reset(); |
195 c_subscription.reset(); | 196 c_subscription.reset(); |
196 } | 197 } |
197 | 198 |
198 // Sanity check that callbacks with details added to the list will be run, with | 199 // Sanity check that callbacks with details added to the list will be run, with |
199 // the correct details, and those removed from the list will not be run. | 200 // the correct details, and those removed from the list will not be run. |
200 TEST(CallbackListTest, BasicTestWithParams) { | 201 TEST(CallbackListTest, BasicTestWithParams) { |
201 CallbackList<void(int)> cb_reg; | 202 CallbackList<void(int)> cb_reg; |
202 Listener a(1), b(-1), c(1); | 203 Listener a(1), b(-1), c(1); |
203 | 204 |
204 scoped_ptr<CallbackList<void(int)>::Subscription> a_subscription = | 205 std::unique_ptr<CallbackList<void(int)>::Subscription> a_subscription = |
205 cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&a))); | 206 cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&a))); |
206 scoped_ptr<CallbackList<void(int)>::Subscription> b_subscription = | 207 std::unique_ptr<CallbackList<void(int)>::Subscription> b_subscription = |
207 cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&b))); | 208 cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&b))); |
208 | 209 |
209 EXPECT_TRUE(a_subscription.get()); | 210 EXPECT_TRUE(a_subscription.get()); |
210 EXPECT_TRUE(b_subscription.get()); | 211 EXPECT_TRUE(b_subscription.get()); |
211 | 212 |
212 cb_reg.Notify(10); | 213 cb_reg.Notify(10); |
213 | 214 |
214 EXPECT_EQ(10, a.total()); | 215 EXPECT_EQ(10, a.total()); |
215 EXPECT_EQ(-10, b.total()); | 216 EXPECT_EQ(-10, b.total()); |
216 | 217 |
217 b_subscription.reset(); | 218 b_subscription.reset(); |
218 | 219 |
219 scoped_ptr<CallbackList<void(int)>::Subscription> c_subscription = | 220 std::unique_ptr<CallbackList<void(int)>::Subscription> c_subscription = |
220 cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&c))); | 221 cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&c))); |
221 | 222 |
222 cb_reg.Notify(10); | 223 cb_reg.Notify(10); |
223 | 224 |
224 EXPECT_EQ(20, a.total()); | 225 EXPECT_EQ(20, a.total()); |
225 EXPECT_EQ(-10, b.total()); | 226 EXPECT_EQ(-10, b.total()); |
226 EXPECT_EQ(10, c.total()); | 227 EXPECT_EQ(10, c.total()); |
227 | 228 |
228 a_subscription.reset(); | 229 a_subscription.reset(); |
229 b_subscription.reset(); | 230 b_subscription.reset(); |
230 c_subscription.reset(); | 231 c_subscription.reset(); |
231 } | 232 } |
232 | 233 |
233 // Test the a callback can remove itself or a different callback from the list | 234 // Test the a callback can remove itself or a different callback from the list |
234 // during iteration without invalidating the iterator. | 235 // during iteration without invalidating the iterator. |
235 TEST(CallbackListTest, RemoveCallbacksDuringIteration) { | 236 TEST(CallbackListTest, RemoveCallbacksDuringIteration) { |
236 CallbackList<void(void)> cb_reg; | 237 CallbackList<void(void)> cb_reg; |
237 Listener a, b; | 238 Listener a, b; |
238 Remover remover_1, remover_2; | 239 Remover remover_1, remover_2; |
239 | 240 |
240 scoped_ptr<CallbackList<void(void)>::Subscription> remover_1_sub = | 241 std::unique_ptr<CallbackList<void(void)>::Subscription> remover_1_sub = |
241 cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove, | 242 cb_reg.Add( |
242 Unretained(&remover_1))); | 243 Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_1))); |
243 scoped_ptr<CallbackList<void(void)>::Subscription> remover_2_sub = | 244 std::unique_ptr<CallbackList<void(void)>::Subscription> remover_2_sub = |
244 cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove, | 245 cb_reg.Add( |
245 Unretained(&remover_2))); | 246 Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_2))); |
246 scoped_ptr<CallbackList<void(void)>::Subscription> a_subscription = | 247 std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription = |
247 cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&a))); | 248 cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&a))); |
248 scoped_ptr<CallbackList<void(void)>::Subscription> b_subscription = | 249 std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription = |
249 cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b))); | 250 cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b))); |
250 | 251 |
251 // |remover_1| will remove itself. | 252 // |remover_1| will remove itself. |
252 remover_1.SetSubscriptionToRemove(std::move(remover_1_sub)); | 253 remover_1.SetSubscriptionToRemove(std::move(remover_1_sub)); |
253 // |remover_2| will remove a. | 254 // |remover_2| will remove a. |
254 remover_2.SetSubscriptionToRemove(std::move(a_subscription)); | 255 remover_2.SetSubscriptionToRemove(std::move(a_subscription)); |
255 | 256 |
256 cb_reg.Notify(); | 257 cb_reg.Notify(); |
257 | 258 |
258 // |remover_1| runs once (and removes itself), |remover_2| runs once (and | 259 // |remover_1| runs once (and removes itself), |remover_2| runs once (and |
(...skipping 12 matching lines...) Expand all Loading... |
271 EXPECT_EQ(2, b.total()); | 272 EXPECT_EQ(2, b.total()); |
272 } | 273 } |
273 | 274 |
274 // Test that a callback can add another callback to the list durning iteration | 275 // Test that a callback can add another callback to the list durning iteration |
275 // without invalidating the iterator. The newly added callback should be run on | 276 // without invalidating the iterator. The newly added callback should be run on |
276 // the current iteration as will all other callbacks in the list. | 277 // the current iteration as will all other callbacks in the list. |
277 TEST(CallbackListTest, AddCallbacksDuringIteration) { | 278 TEST(CallbackListTest, AddCallbacksDuringIteration) { |
278 CallbackList<void(void)> cb_reg; | 279 CallbackList<void(void)> cb_reg; |
279 Adder a(&cb_reg); | 280 Adder a(&cb_reg); |
280 Listener b; | 281 Listener b; |
281 scoped_ptr<CallbackList<void(void)>::Subscription> a_subscription = | 282 std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription = |
282 cb_reg.Add(Bind(&Adder::AddCallback, Unretained(&a))); | 283 cb_reg.Add(Bind(&Adder::AddCallback, Unretained(&a))); |
283 scoped_ptr<CallbackList<void(void)>::Subscription> b_subscription = | 284 std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription = |
284 cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b))); | 285 cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b))); |
285 | 286 |
286 cb_reg.Notify(); | 287 cb_reg.Notify(); |
287 | 288 |
288 EXPECT_EQ(1, a.total()); | 289 EXPECT_EQ(1, a.total()); |
289 EXPECT_EQ(1, b.total()); | 290 EXPECT_EQ(1, b.total()); |
290 EXPECT_TRUE(a.added()); | 291 EXPECT_TRUE(a.added()); |
291 | 292 |
292 cb_reg.Notify(); | 293 cb_reg.Notify(); |
293 | 294 |
294 EXPECT_EQ(2, a.total()); | 295 EXPECT_EQ(2, a.total()); |
295 EXPECT_EQ(2, b.total()); | 296 EXPECT_EQ(2, b.total()); |
296 } | 297 } |
297 | 298 |
298 // Sanity check: notifying an empty list is a no-op. | 299 // Sanity check: notifying an empty list is a no-op. |
299 TEST(CallbackListTest, EmptyList) { | 300 TEST(CallbackListTest, EmptyList) { |
300 CallbackList<void(void)> cb_reg; | 301 CallbackList<void(void)> cb_reg; |
301 | 302 |
302 cb_reg.Notify(); | 303 cb_reg.Notify(); |
303 } | 304 } |
304 | 305 |
305 TEST(CallbackList, RemovalCallback) { | 306 TEST(CallbackList, RemovalCallback) { |
306 Counter remove_count; | 307 Counter remove_count; |
307 CallbackList<void(void)> cb_reg; | 308 CallbackList<void(void)> cb_reg; |
308 cb_reg.set_removal_callback( | 309 cb_reg.set_removal_callback( |
309 Bind(&Counter::Increment, Unretained(&remove_count))); | 310 Bind(&Counter::Increment, Unretained(&remove_count))); |
310 | 311 |
311 scoped_ptr<CallbackList<void(void)>::Subscription> subscription = | 312 std::unique_ptr<CallbackList<void(void)>::Subscription> subscription = |
312 cb_reg.Add(Bind(&DoNothing)); | 313 cb_reg.Add(Bind(&DoNothing)); |
313 | 314 |
314 // Removing a subscription outside of iteration signals the callback. | 315 // Removing a subscription outside of iteration signals the callback. |
315 EXPECT_EQ(0, remove_count.value()); | 316 EXPECT_EQ(0, remove_count.value()); |
316 subscription.reset(); | 317 subscription.reset(); |
317 EXPECT_EQ(1, remove_count.value()); | 318 EXPECT_EQ(1, remove_count.value()); |
318 | 319 |
319 // Configure two subscriptions to remove themselves. | 320 // Configure two subscriptions to remove themselves. |
320 Remover remover_1, remover_2; | 321 Remover remover_1, remover_2; |
321 scoped_ptr<CallbackList<void(void)>::Subscription> remover_1_sub = | 322 std::unique_ptr<CallbackList<void(void)>::Subscription> remover_1_sub = |
322 cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove, | 323 cb_reg.Add( |
323 Unretained(&remover_1))); | 324 Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_1))); |
324 scoped_ptr<CallbackList<void(void)>::Subscription> remover_2_sub = | 325 std::unique_ptr<CallbackList<void(void)>::Subscription> remover_2_sub = |
325 cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove, | 326 cb_reg.Add( |
326 Unretained(&remover_2))); | 327 Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_2))); |
327 remover_1.SetSubscriptionToRemove(std::move(remover_1_sub)); | 328 remover_1.SetSubscriptionToRemove(std::move(remover_1_sub)); |
328 remover_2.SetSubscriptionToRemove(std::move(remover_2_sub)); | 329 remover_2.SetSubscriptionToRemove(std::move(remover_2_sub)); |
329 | 330 |
330 // The callback should be signaled exactly once. | 331 // The callback should be signaled exactly once. |
331 EXPECT_EQ(1, remove_count.value()); | 332 EXPECT_EQ(1, remove_count.value()); |
332 cb_reg.Notify(); | 333 cb_reg.Notify(); |
333 EXPECT_EQ(2, remove_count.value()); | 334 EXPECT_EQ(2, remove_count.value()); |
334 EXPECT_TRUE(cb_reg.empty()); | 335 EXPECT_TRUE(cb_reg.empty()); |
335 } | 336 } |
336 | 337 |
337 } // namespace | 338 } // namespace |
338 } // namespace base | 339 } // namespace base |
OLD | NEW |