| Index: ui/base/test/windowed_nsnotification_observer.mm
|
| diff --git a/ui/base/test/windowed_nsnotification_observer.mm b/ui/base/test/windowed_nsnotification_observer.mm
|
| index 02f45179e9b25e1f75ca215c704a5d93d528a40c..1a3ce4ada21de89f34e6e5d5f5cc649e840ea346 100644
|
| --- a/ui/base/test/windowed_nsnotification_observer.mm
|
| +++ b/ui/base/test/windowed_nsnotification_observer.mm
|
| @@ -7,6 +7,7 @@
|
| #import <Cocoa/Cocoa.h>
|
|
|
| #include "base/run_loop.h"
|
| +#include "base/test/test_timeouts.h"
|
|
|
| @interface WindowedNSNotificationObserver ()
|
| - (void)onNotification:(NSNotification*)notification;
|
| @@ -14,16 +15,20 @@
|
|
|
| @implementation WindowedNSNotificationObserver
|
|
|
| -- (id)initForNotification:(NSString*)name {
|
| +- (id)initForNotification:(NSString*)name object:(id)notificationSender {
|
| if ((self = [super init])) {
|
| [[NSNotificationCenter defaultCenter] addObserver:self
|
| selector:@selector(onNotification:)
|
| name:name
|
| - object:nil];
|
| + object:notificationSender];
|
| }
|
| return self;
|
| }
|
|
|
| +- (id)initForNotification:(NSString*)name {
|
| + return [self initForNotification:name object:nil];
|
| +}
|
| +
|
| - (id)initForWorkspaceNotification:(NSString*)name
|
| bundleId:(NSString*)bundleId {
|
| if ((self = [super init])) {
|
| @@ -37,31 +42,42 @@
|
| return self;
|
| }
|
|
|
| +- (void)dealloc {
|
| + if (bundleId_)
|
| + [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
|
| + else
|
| + [[NSNotificationCenter defaultCenter] removeObserver:self];
|
| + [super dealloc];
|
| +}
|
| +
|
| - (void)onNotification:(NSNotification*)notification {
|
| if (bundleId_) {
|
| NSRunningApplication* application =
|
| [[notification userInfo] objectForKey:NSWorkspaceApplicationKey];
|
| if (![[application bundleIdentifier] isEqualToString:bundleId_])
|
| return;
|
| -
|
| - [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
|
| - } else {
|
| - [[NSNotificationCenter defaultCenter] removeObserver:self];
|
| }
|
|
|
| - notificationReceived_ = YES;
|
| + ++notificationCount_;
|
| if (runLoop_)
|
| runLoop_->Quit();
|
| }
|
|
|
| -- (void)wait {
|
| - if (notificationReceived_)
|
| - return;
|
| +- (BOOL)waitForCount:(int)minimumCount {
|
| + if (notificationCount_ >= minimumCount)
|
| + return YES;
|
|
|
| base::RunLoop runLoop;
|
| + base::MessageLoop::current()->task_runner()->PostDelayedTask(
|
| + FROM_HERE, runLoop.QuitClosure(), TestTimeouts::action_timeout());
|
| runLoop_ = &runLoop;
|
| runLoop.Run();
|
| runLoop_ = nullptr;
|
| + return notificationCount_ >= minimumCount;
|
| +}
|
| +
|
| +- (BOOL)wait {
|
| + return [self waitForCount:1];
|
| }
|
|
|
| @end
|
|
|