Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Side by Side Diff: chrome/browser/ui/cocoa/run_loop_testing.mm

Issue 2565813002: Create c/b/ui/cocoa/test and move test files to there (Closed)
Patch Set: Rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/ui/cocoa/run_loop_testing.h"
6
7 #import <Foundation/Foundation.h>
8
9 #include <memory>
10
11 #include "base/mac/scoped_nsobject.h"
12 #include "base/message_loop/message_pump_mac.h"
13
14 // This class is scheduled with a delayed selector to quit the message pump.
15 @interface CocoaQuitTask : NSObject {
16 @private
17 base::MessagePumpNSRunLoop* pump_;
18 }
19 - (id)initWithMessagePump:(base::MessagePumpNSRunLoop*)pump;
20 - (void)doQuit;
21 @end
22
23 @implementation CocoaQuitTask
24 - (id)initWithMessagePump:(base::MessagePumpNSRunLoop*)pump {
25 if ((self = [super init])) {
26 pump_ = pump;
27 }
28 return self;
29 }
30
31 - (void)doQuit {
32 pump_->Quit();
33 }
34 @end
35
36 ////////////////////////////////////////////////////////////////////////////////
37
38 namespace chrome {
39 namespace testing {
40
41 void NSRunLoopRunAllPending() {
42 std::unique_ptr<base::MessagePumpNSRunLoop> message_pump(
43 new base::MessagePumpNSRunLoop);
44
45 // Put a delayed selector on the queue. All other pending delayed selectors
46 // will run before this, after which the internal loop can end.
47 base::scoped_nsobject<CocoaQuitTask> quit_task(
48 [[CocoaQuitTask alloc] initWithMessagePump:message_pump.get()]);
49
50 [quit_task performSelector:@selector(doQuit)
51 withObject:nil
52 afterDelay:0];
53
54 // Spin the internal loop, running it until the quit task is pumped. Pass NULL
55 // because there is no delegate MessageLoop; only the Cocoa work queues will
56 // be pumped.
57 message_pump->Run(NULL);
58 }
59
60 } // namespace testing
61 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/run_loop_testing.h ('k') | chrome/browser/ui/cocoa/run_loop_testing_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698