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