1 // Copyright (c) 2011 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.
5 #include "chrome/browser/ui/cocoa/run_loop_testing.h"
7 #import <Foundation/Foundation.h>
9 #include "base/mac/scoped_nsobject.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 @interface TestDelayed : NSObject {
17 @property(readonly, nonatomic) BOOL didWork;
18 @property(assign, nonatomic) TestDelayed* next;
21 @implementation TestDelayed
22 @synthesize didWork = didWork_;
23 @synthesize next = next_;
26 if ((self = [super init])) {
27 [self performSelector:@selector(doWork) withObject:nil afterDelay:0];
34 [next_ performSelector:@selector(doWork) withObject:nil afterDelay:0];
38 TEST(RunLoopTesting, RunAllPending) {
39 base::scoped_nsobject<TestDelayed> tester([[TestDelayed alloc] init]);
40 EXPECT_FALSE([tester didWork]);
42 chrome::testing::NSRunLoopRunAllPending();
44 EXPECT_TRUE([tester didWork]);
47 TEST(RunLoopTesting, NestedWork) {
48 base::scoped_nsobject<TestDelayed> tester([[TestDelayed alloc] init]);
49 base::scoped_nsobject<TestDelayed> nested([[TestDelayed alloc] init]);
50 [tester setNext:nested];
52 EXPECT_FALSE([tester didWork]);
53 EXPECT_FALSE([nested didWork]);
55 chrome::testing::NSRunLoopRunAllPending();
57 EXPECT_TRUE([tester didWork]);
58 EXPECT_TRUE([nested didWork]);