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

Unified Diff: ui/base/test/windowed_nsnotification_observer.mm

Issue 1186803003: Mac: Give packaged app windows their own window cycle list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase (overlap with r335812 and I want a fresh CQ run) Created 5 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/test/windowed_nsnotification_observer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ae8d2f4de7b79c645c27f36fa51b943dca4f3670..bb0b9c7d8edb78cfa4b8dca8e18198e6205f947e 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;
@@ -41,31 +42,46 @@
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 {
+ while (notificationCount_ < minimumCount) {
+ const int oldCount = notificationCount_;
+ base::RunLoop runLoop;
+ base::MessageLoop::current()->task_runner()->PostDelayedTask(
+ FROM_HERE, runLoop.QuitClosure(), TestTimeouts::action_timeout());
+ runLoop_ = &runLoop;
+ runLoop.Run();
+ runLoop_ = nullptr;
+
+ // If there was no new notification, it must have been a timeout.
+ if (notificationCount_ == oldCount)
+ break;
+ }
+ return notificationCount_ >= minimumCount;
+}
- base::RunLoop runLoop;
- runLoop_ = &runLoop;
- runLoop.Run();
- runLoop_ = nullptr;
+- (BOOL)wait {
+ return [self waitForCount:1];
}
@end
« no previous file with comments | « ui/base/test/windowed_nsnotification_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698