Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_BASE_TEST_WINDOWED_NSNOTIFICATION_OBSERVER_H_ | 5 #ifndef UI_BASE_TEST_WINDOWED_NSNOTIFICATION_OBSERVER_H_ |
| 6 #define UI_BASE_TEST_WINDOWED_NSNOTIFICATION_OBSERVER_H_ | 6 #define UI_BASE_TEST_WINDOWED_NSNOTIFICATION_OBSERVER_H_ |
| 7 | 7 |
| 8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
| 9 | 9 |
| 10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
| 11 | 11 |
| 12 namespace base { | 12 namespace base { |
| 13 class RunLoop; | 13 class RunLoop; |
| 14 } | 14 } |
| 15 | 15 |
| 16 // Like WindowedNotificationObserver in content/public/test/test_utils.h, this | 16 // Like WindowedNotificationObserver in content/public/test/test_utils.h, this |
| 17 // starts watching for a notification upon construction and can wait until the | 17 // starts watching for a notification upon construction and can wait until the |
| 18 // notification is observed. This guarantees that a notification fired between | 18 // notification is observed. This guarantees that notifications fired between |
| 19 // calls to init and wait will be caught. | 19 // calls to init and wait will be caught. |
| 20 @interface WindowedNSNotificationObserver : NSObject { | 20 @interface WindowedNSNotificationObserver : NSObject { |
| 21 @private | 21 @private |
| 22 base::scoped_nsobject<NSString> bundleId_; | 22 base::scoped_nsobject<NSString> bundleId_; |
| 23 BOOL notificationReceived_; | 23 int notificationCount_; |
| 24 base::RunLoop* runLoop_; | 24 base::RunLoop* runLoop_; |
| 25 } | 25 } |
| 26 | 26 |
| 27 // Watch for an NSNotification on the default notification center. | 27 // Watch for an NSNotification on the default notification center for the given |
| 28 // |notificationSender|, or a nil object if omitted. | |
| 28 - (id)initForNotification:(NSString*)name; | 29 - (id)initForNotification:(NSString*)name; |
| 30 - (id)initForNotification:(NSString*)name object:(id)notificationSender; | |
| 29 | 31 |
| 30 // Watch for an NSNotification on the shared workspace notification center for | 32 // Watch for an NSNotification on the shared workspace notification center for |
| 31 // the | 33 // the given application. |
| 32 // given application. | |
| 33 - (id)initForWorkspaceNotification:(NSString*)name bundleId:(NSString*)bundleId; | 34 - (id)initForWorkspaceNotification:(NSString*)name bundleId:(NSString*)bundleId; |
| 34 | 35 |
| 35 // Returns if the notification has been observed, or spins a RunLoop until it | 36 // Waits for |minimumCount| notifications to be observed and returns YES. |
|
jackhou1
2015/06/22 01:34:26
This quits the run loop as soon as a notification
tapted
2015/06/22 01:57:08
ooh! good catch. That wasn't intentional - I think
| |
| 36 // is. Stops observing. | 37 // Returns NO on a timeout. This can be called multiple times. |
| 37 - (void)wait; | 38 - (BOOL)waitForCount:(int)minimumCount; |
| 39 | |
| 40 // Returns YES if any notification has been observed, or spins a RunLoop until | |
| 41 // it either is observed, or a timeout occurs. Returns NO on a timeout. | |
| 42 - (BOOL)wait; | |
| 38 @end | 43 @end |
| 39 | 44 |
| 40 #endif // UI_BASE_TEST_WINDOWED_NSNOTIFICATION_OBSERVER_H_ | 45 #endif // UI_BASE_TEST_WINDOWED_NSNOTIFICATION_OBSERVER_H_ |
| OLD | NEW |