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 "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_pump_mac.h"
13 // This class is scheduled with a delayed selector to quit the message pump.
14 @interface CocoaQuitTask : NSObject {
16 base::MessagePumpNSRunLoop* pump_;
18 - (id)initWithMessagePump:(base::MessagePumpNSRunLoop*)pump;
22 @implementation CocoaQuitTask
23 - (id)initWithMessagePump:(base::MessagePumpNSRunLoop*)pump {
24 if ((self = [super init])) {
35 ////////////////////////////////////////////////////////////////////////////////
40 void NSRunLoopRunAllPending() {
41 scoped_ptr<base::MessagePumpNSRunLoop> message_pump(
42 new base::MessagePumpNSRunLoop);
44 // Put a delayed selector on the queue. All other pending delayed selectors
45 // will run before this, after which the internal loop can end.
46 base::scoped_nsobject<CocoaQuitTask> quit_task(
47 [[CocoaQuitTask alloc] initWithMessagePump:message_pump.get()]);
49 [quit_task performSelector:@selector(doQuit)
53 // Spin the internal loop, running it until the quit task is pumped. Pass NULL
54 // because there is no delegate MessageLoop; only the Cocoa work queues will
56 message_pump->Run(NULL);
59 } // namespace testing