summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/run_loop_testing.mm
diff options
context:
space:
mode:
authorrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-20 22:10:08 +0000
committerrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-20 22:10:08 +0000
commit149b62c5e7f27b9b5f22d69a24a02825adb3238e (patch)
tree09d5a8669750ad6f47419c3975da18f91cfed7af /chrome/browser/ui/cocoa/run_loop_testing.mm
parent4ba8b62ce0766d328b67e3e93bf0f7a6d211ee90 (diff)
downloadchromium_src-149b62c5e7f27b9b5f22d69a24a02825adb3238e.zip
chromium_src-149b62c5e7f27b9b5f22d69a24a02825adb3238e.tar.gz
chromium_src-149b62c5e7f27b9b5f22d69a24a02825adb3238e.tar.bz2
[Mac] Add a function to make it easy to test around the infamous Chromium delayed selector hack.
BUG=none TEST=RunLoopTesting.RunAllPending unittest Review URL: http://codereview.chromium.org/7692014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97585 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/cocoa/run_loop_testing.mm')
-rw-r--r--chrome/browser/ui/cocoa/run_loop_testing.mm59
1 files changed, 59 insertions, 0 deletions
diff --git a/chrome/browser/ui/cocoa/run_loop_testing.mm b/chrome/browser/ui/cocoa/run_loop_testing.mm
new file mode 100644
index 0000000..d20d3ce
--- /dev/null
+++ b/chrome/browser/ui/cocoa/run_loop_testing.mm
@@ -0,0 +1,59 @@
+// Copyright (c) 2011 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.
+
+#include "chrome/browser/ui/cocoa/run_loop_testing.h"
+
+#import <Foundation/Foundation.h>
+
+#include "base/memory/scoped_nsobject.h"
+#include "base/message_pump_mac.h"
+
+// This class is scheduled with a delayed selector to quit the message pump.
+@interface CocoaQuitTask : NSObject {
+ @private
+ base::MessagePumpNSRunLoop* pump_;
+}
+- (id)initWithMessagePump:(base::MessagePumpNSRunLoop*)pump;
+- (void)doQuit;
+@end
+
+@implementation CocoaQuitTask
+- (id)initWithMessagePump:(base::MessagePumpNSRunLoop*)pump {
+ if ((self = [super init])) {
+ pump_ = pump;
+ }
+ return self;
+}
+
+- (void)doQuit {
+ pump_->Quit();
+}
+@end
+
+////////////////////////////////////////////////////////////////////////////////
+
+namespace chrome {
+namespace testing {
+
+void NSRunLoopRunAllPending() {
+ scoped_refptr<base::MessagePumpNSRunLoop> message_pump(
+ new base::MessagePumpNSRunLoop);
+
+ // Put a delayed selector on the queue. All other pending delayed selectors
+ // will run before this, after which the internal loop can end.
+ scoped_nsobject<CocoaQuitTask> quit_task(
+ [[CocoaQuitTask alloc] initWithMessagePump:message_pump]);
+
+ [quit_task performSelector:@selector(doQuit)
+ withObject:nil
+ afterDelay:0];
+
+ // Spin the internal loop, running it until the quit task is pumped. Pass NULL
+ // because there is no delegate MessageLoop; only the Cocoa work queues will
+ // be pumped.
+ message_pump->Run(NULL);
+}
+
+} // namespace testing
+} // namespace chrome