| 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; |
| 29 | 30 |
| 30 // Watch for an NSNotification on the default notification center from a | 31 // Watch for an NSNotification on the default notification center from a |
| 31 // particular object. | 32 // particular object. |
| 32 - (id)initForNotification:(NSString*)name object:(id)sender; | 33 - (id)initForNotification:(NSString*)name object:(id)sender; |
| 33 | 34 |
| 34 // Watch for an NSNotification on the shared workspace notification center for | 35 // Watch for an NSNotification on the shared workspace notification center for |
| 35 // the | 36 // the given application. |
| 36 // given application. | |
| 37 - (id)initForWorkspaceNotification:(NSString*)name bundleId:(NSString*)bundleId; | 37 - (id)initForWorkspaceNotification:(NSString*)name bundleId:(NSString*)bundleId; |
| 38 | 38 |
| 39 // Returns if the notification has been observed, or spins a RunLoop until it | 39 // Waits for |minimumCount| notifications to be observed and returns YES. |
| 40 // is. Stops observing. | 40 // Returns NO on a timeout. This can be called multiple times. |
| 41 - (void)wait; | 41 - (BOOL)waitForCount:(int)minimumCount; |
| 42 |
| 43 // Returns YES if any notification has been observed, or spins a RunLoop until |
| 44 // it either is observed, or a timeout occurs. Returns NO on a timeout. |
| 45 - (BOOL)wait; |
| 42 @end | 46 @end |
| 43 | 47 |
| 44 #endif // UI_BASE_TEST_WINDOWED_NSNOTIFICATION_OBSERVER_H_ | 48 #endif // UI_BASE_TEST_WINDOWED_NSNOTIFICATION_OBSERVER_H_ |
| OLD | NEW |