Chromium Code Reviews| Index: chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm |
| diff --git a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm |
| index 197680667bdea8348b77082c9b71668968a77908..410b8285d5d0d2a19e2a0ff7ae857327bf45e000 100644 |
| --- a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm |
| +++ b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm |
| @@ -107,3 +107,105 @@ IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, HideShowWithApp) { |
| EXPECT_TRUE([ns_window isVisible]); |
| EXPECT_FALSE([other_ns_window isVisible]); |
| } |
| + |
| +// Only test fullscreen for 10.7 and above. |
| +// Replicate specific 10.7 SDK declarations for building with prior SDKs. |
| +#if !defined(MAC_OS_X_VERSION_10_7) || \ |
| + MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
| + |
| +@interface NSWindow (LionSDKDeclarations) |
| +- (void)toggleFullScreen:(id)sender; |
| +@end |
| + |
| +enum { |
| + NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7, |
| + NSFullScreenWindowMask = 1 << 14 |
| +}; |
| + |
| +NSString* const NSWindowDidEnterFullScreenNotification = |
| + @"NSWindowDidEnterFullScreenNotification"; |
| +NSString* const NSWindowDidExitFullScreenNotification = |
| + @"NSWindowDidExitFullScreenNotification"; |
| + |
|
tapted
2014/05/15 06:39:20
#endif here
jackhou1
2014/05/15 07:15:29
Done.
|
| +@interface ScopedNotificationWatcher : NSObject { |
| + @private |
| + BOOL received_; |
| +} |
| +- (id)initWithNotification:(NSString*)notification |
| + andObject:(NSObject*)object; |
| +- (void)onNotification:(NSString*)notification; |
| +- (void)waitForNotification; |
| +@end |
| + |
| +@implementation ScopedNotificationWatcher |
| + |
| +- (id)initWithNotification:(NSString*)notification |
| + andObject:(NSObject*)object { |
| + if ((self = [super init])) { |
| + [[NSNotificationCenter defaultCenter] |
| + addObserver:self |
| + selector:@selector(onNotification:) |
| + name:notification |
| + object:object]; |
| + } |
| + return self; |
| +} |
| + |
| +- (void)onNotification:(NSString*)notification { |
| + received_ = YES; |
| + [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| +} |
| + |
| +- (void)waitForNotification { |
| + while (!received_) |
| + content::RunAllPendingInMessageLoop(); |
| +} |
| + |
| +@end |
| + |
| +// Test that NativeAppWindow and AppWindow fullscreen state is updated when |
| +// the window is fullscreened natively. |
| +IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Fullscreen) { |
| + SetUpAppWithWindows(1); |
|
tapted
2014/05/15 06:39:20
here do
// Only test fullscreen for 10.7 and abov
jackhou1
2014/05/15 07:15:29
Done.
|
| + apps::AppWindow* app_window = GetFirstAppWindow(); |
| + apps::NativeAppWindow* window = app_window->GetBaseWindow(); |
| + NSWindow* ns_window = app_window->GetNativeWindow(); |
| + base::scoped_nsobject<ScopedNotificationWatcher> watcher; |
| + |
| + EXPECT_FALSE(window->IsFullscreen()); |
| + EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); |
| + |
| + watcher.reset([[ScopedNotificationWatcher alloc] |
| + initWithNotification:NSWindowDidEnterFullScreenNotification |
| + andObject:ns_window]); |
| + [ns_window toggleFullScreen:nil]; |
| + [watcher waitForNotification]; |
| + EXPECT_TRUE(window->IsFullscreen()); |
| + EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); |
|
tapted
2014/05/15 06:39:20
I think it's worth moving `IsFullscreen` out of th
jackhou1
2014/05/15 07:15:29
Added AppWindow::fullscreen_types_for_test like ap
|
| + |
| + watcher.reset([[ScopedNotificationWatcher alloc] |
| + initWithNotification:NSWindowDidExitFullScreenNotification |
| + andObject:ns_window]); |
| + app_window->Restore(); |
|
tapted
2014/05/15 06:39:20
does window->IsFullscreenOrPending() change immedi
jackhou1
2014/05/15 07:15:29
Done.
|
| + [watcher waitForNotification]; |
| + EXPECT_FALSE(window->IsFullscreen()); |
| + EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); |
| + |
| + watcher.reset([[ScopedNotificationWatcher alloc] |
| + initWithNotification:NSWindowDidEnterFullScreenNotification |
| + andObject:ns_window]); |
| + app_window->Fullscreen(); |
| + [watcher waitForNotification]; |
|
tapted
2014/05/15 06:39:20
likewise window->IsFullscreenOrPending() should be
jackhou1
2014/05/15 07:15:29
I take it you mean true? The comment on IsFullscre
tapted
2014/05/15 07:44:40
oops - yep.
|
| + EXPECT_TRUE(window->IsFullscreen()); |
| + EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); |
| + |
| + watcher.reset([[ScopedNotificationWatcher alloc] |
| + initWithNotification:NSWindowDidExitFullScreenNotification |
| + andObject:ns_window]); |
| + [ns_window toggleFullScreen:nil]; |
| + [watcher waitForNotification]; |
|
tapted
2014/05/15 06:39:20
(but this one is native, so window->IsFullscreenOr
|
| + EXPECT_FALSE(window->IsFullscreen()); |
| + EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); |
| +} |
| + |
| +#endif // MAC_OS_X_VERSION_10_7 |