OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ios/chrome/browser/callback_counter.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/mac/bind_objc_block.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #import "base/test/ios/wait_util.h" |
| 11 #include "testing/platform_test.h" |
| 12 |
| 13 // Tests that CallbackCounter works with 2 callbacks. |
| 14 TEST(CallbackCounterTest, Basic) { |
| 15 __block BOOL block_was_called = NO; |
| 16 scoped_refptr<CallbackCounter> callback_counter = |
| 17 new CallbackCounter(base::BindBlock(^{ |
| 18 block_was_called = YES; |
| 19 })); |
| 20 |
| 21 // Enqueue the first callback. |
| 22 callback_counter->IncrementCount(); |
| 23 dispatch_async(dispatch_get_main_queue(), ^{ |
| 24 callback_counter->DecrementCount(); |
| 25 }); |
| 26 |
| 27 // Enqueue the second callback. |
| 28 callback_counter->IncrementCount(); |
| 29 dispatch_async(dispatch_get_main_queue(), ^{ |
| 30 callback_counter->DecrementCount(); |
| 31 }); |
| 32 |
| 33 base::test::ios::WaitUntilCondition(^bool() { |
| 34 return block_was_called; |
| 35 }); |
| 36 } |
OLD | NEW |