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.
5 #import "ui/base/test/nswindow_fullscreen_notification_waiter.h"
7 #import "base/mac/sdk_forward_declarations.h"
9 @interface NSWindowFullscreenNotificationWaiter ()
10 // Exit the RunLoop if there is one and the counts being tracked match.
11 - (void)maybeQuitForChangedArg:(int*)changedArg;
12 - (void)onEnter:(NSNotification*)notification;
13 - (void)onExit:(NSNotification*)notification;
16 @implementation NSWindowFullscreenNotificationWaiter
18 @synthesize enterCount = enterCount_;
19 @synthesize exitCount = exitCount_;
21 - (id)initWithWindow:(NSWindow*)window {
22 if ((self = [super init])) {
23 window_.reset([window retain]);
24 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
25 [defaultCenter addObserver:self
26 selector:@selector(onEnter:)
27 name:NSWindowDidEnterFullScreenNotification
29 [defaultCenter addObserver:self
30 selector:@selector(onExit:)
31 name:NSWindowDidExitFullScreenNotification
39 [[NSNotificationCenter defaultCenter] removeObserver:self];
43 - (void)waitForEnterCount:(int)enterCount exitCount:(int)exitCount {
44 if (enterCount_ >= enterCount && exitCount_ >= exitCount)
47 targetEnterCount_ = enterCount;
48 targetExitCount_ = exitCount;
49 runLoop_.reset(new base::RunLoop);
54 - (void)maybeQuitForChangedArg:(int*)changedArg {
59 if (enterCount_ >= targetEnterCount_ && exitCount_ >= targetExitCount_)
63 - (void)onEnter:(NSNotification*)notification {
64 [self maybeQuitForChangedArg:&enterCount_];
67 - (void)onExit:(NSNotification*)notification {
68 [self maybeQuitForChangedArg:&exitCount_];