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 #import <Foundation/Foundation.h> | 5 #import <Foundation/Foundation.h> |
6 | 6 |
7 #include "ios/chrome/test/block_cleanup_test.h" | 7 #import "ios/chrome/test/block_cleanup_test.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
11 | 11 |
12 void BlockCleanupTest::SetUp() { | 12 void BlockCleanupTest::SetUp() { |
13 block_cleanup_pool_ = [[NSAutoreleasePool alloc] init]; | 13 block_cleanup_pool_ = [[NSAutoreleasePool alloc] init]; |
14 } | 14 } |
15 | 15 |
16 void BlockCleanupTest::TearDown() { | 16 void BlockCleanupTest::TearDown() { |
17 // Block-copied items are released asynchronously; spin the loop to give them | 17 // Block-copied items are released asynchronously; spin the loop to give them |
18 // a chance to be cleaned up. | 18 // a chance to be cleaned up. |
19 const NSTimeInterval kCleanupTime = 0.1; | 19 const NSTimeInterval kCleanupTime = 0.1; |
20 SpinRunLoop(kCleanupTime); | 20 SpinRunLoop(kCleanupTime); |
21 | 21 |
22 // Drain the autorelease pool to finish cleaning up after blocks. | 22 // Drain the autorelease pool to finish cleaning up after blocks. |
23 // TODO(rohitrao): Can this be an EXPECT, so as to not crash the whole suite? | 23 // TODO(rohitrao): Can this be an EXPECT, so as to not crash the whole suite? |
24 DCHECK(block_cleanup_pool_); | 24 DCHECK(block_cleanup_pool_); |
25 [block_cleanup_pool_ release]; | 25 [block_cleanup_pool_ release]; |
26 block_cleanup_pool_ = nil; | 26 block_cleanup_pool_ = nil; |
27 | 27 |
28 PlatformTest::TearDown(); | 28 PlatformTest::TearDown(); |
29 } | 29 } |
30 | 30 |
31 void BlockCleanupTest::SpinRunLoop(NSTimeInterval cleanup_time) { | 31 void BlockCleanupTest::SpinRunLoop(NSTimeInterval cleanup_time) { |
32 NSDate* cleanup_start = [NSDate date]; | 32 NSDate* cleanup_start = [NSDate date]; |
33 while (fabs([cleanup_start timeIntervalSinceNow]) < cleanup_time) { | 33 while (fabs([cleanup_start timeIntervalSinceNow]) < cleanup_time) { |
34 base::scoped_nsobject<NSDate> beforeDate( | 34 base::scoped_nsobject<NSDate> beforeDate( |
35 [[NSDate alloc] initWithTimeIntervalSinceNow:cleanup_time]); | 35 [[NSDate alloc] initWithTimeIntervalSinceNow:cleanup_time]); |
36 [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode | 36 [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode |
37 beforeDate:beforeDate]; | 37 beforeDate:beforeDate]; |
38 } | 38 } |
39 } | 39 } |
OLD | NEW |