windowed_nsnotification_observer.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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
  3. // found in the LICENSE file.
  4. #ifndef UI_BASE_TEST_WINDOWED_NSNOTIFICATION_OBSERVER_H_
  5. #define UI_BASE_TEST_WINDOWED_NSNOTIFICATION_OBSERVER_H_
  6. #include "base/memory/raw_ptr.h"
  7. #import <Foundation/Foundation.h>
  8. #import "base/mac/scoped_nsobject.h"
  9. namespace base {
  10. class RunLoop;
  11. }
  12. // Like WindowedNotificationObserver in content/public/test/test_utils.h, this
  13. // starts watching for a notification upon construction and can wait until the
  14. // notification is observed. This guarantees that notifications fired between
  15. // calls to init and wait will be caught.
  16. @interface WindowedNSNotificationObserver : NSObject {
  17. @private
  18. base::scoped_nsobject<NSString> _bundleId;
  19. int _notificationCount;
  20. raw_ptr<base::RunLoop> _runLoop;
  21. }
  22. @property(readonly, nonatomic) int notificationCount;
  23. // Watch for an NSNotification on the default notification center for the given
  24. // |notificationSender|, or a nil object if omitted.
  25. - (instancetype)initForNotification:(NSString*)name;
  26. // Watch for an NSNotification on the default notification center from a
  27. // particular object.
  28. - (instancetype)initForNotification:(NSString*)name object:(id)sender;
  29. // Watch for an NSNotification on the shared workspace notification center for
  30. // the given application.
  31. - (instancetype)initForWorkspaceNotification:(NSString*)name
  32. bundleId:(NSString*)bundleId;
  33. // Waits for |minimumCount| notifications to be observed and returns YES.
  34. // Returns NO on a timeout. This can be called multiple times.
  35. - (BOOL)waitForCount:(int)minimumCount;
  36. // Returns YES if any notification has been observed, or spins a RunLoop until
  37. // it either is observed, or a timeout occurs. Returns NO on a timeout.
  38. - (BOOL)wait;
  39. @end
  40. #endif // UI_BASE_TEST_WINDOWED_NSNOTIFICATION_OBSERVER_H_