blob: dbe4c0b19f72259cd5897f60002d73f322b0739c [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Foundation/Foundation.h>
#include "ios/chrome/test/block_cleanup_test.h"
#include "base/logging.h"
#include "base/mac/scoped_nsobject.h"
void BlockCleanupTest::SetUp() {
block_cleanup_pool_ = [[NSAutoreleasePool alloc] init];
void BlockCleanupTest::TearDown() {
// Block-copied items are released asynchronously; spin the loop to give them
// a chance to be cleaned up.
const NSTimeInterval kCleanupTime = 0.1;
// Drain the autorelease pool to finish cleaning up after blocks.
// TODO(rohitrao): Can this be an EXPECT, so as to not crash the whole suite?
[block_cleanup_pool_ release];
block_cleanup_pool_ = nil;
void BlockCleanupTest::SpinRunLoop(NSTimeInterval cleanup_time) {
NSDate* cleanup_start = [NSDate date];
while (fabs([cleanup_start timeIntervalSinceNow]) < cleanup_time) {
base::scoped_nsobject<NSDate> beforeDate(
[[NSDate alloc] initWithTimeIntervalSinceNow:cleanup_time]);
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode