#import <Cocoa/Cocoa.h>
-#include "apps/shell_window_registry.h"
+#include "base/mac/mac_util.h"
+#include "base/mac/sdk_forward_declarations.h"
#include "chrome/browser/apps/app_browsertest_util.h"
-#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/extensions/application_launch.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_utils.h"
+#include "extensions/browser/app_window/app_window_registry.h"
using extensions::PlatformAppBrowserTest;
content::WindowedNotificationObserver app_loaded_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
- OpenApplication(AppLaunchParams(
- profile(), app_, extension_misc::LAUNCH_NONE, NEW_WINDOW));
+ OpenApplication(
+ AppLaunchParams(profile(),
+ app_,
+ extensions::LAUNCH_CONTAINER_NONE,
+ NEW_WINDOW));
app_loaded_observer.Wait();
}
}
// Test interaction of Hide/Show() with Hide/ShowWithApp().
IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, HideShowWithApp) {
SetUpAppWithWindows(2);
- apps::ShellWindowRegistry::ShellWindowList windows =
- apps::ShellWindowRegistry::Get(profile())->shell_windows();
- apps::NativeAppWindow* window = windows.front()->GetBaseWindow();
- NSWindow* ns_window = window->GetNativeWindow();
- apps::NativeAppWindow* other_window = windows.back()->GetBaseWindow();
- NSWindow* other_ns_window = other_window->GetNativeWindow();
+ extensions::AppWindowRegistry::AppWindowList windows =
+ extensions::AppWindowRegistry::Get(profile())->app_windows();
+
+ extensions::AppWindow* app_window = windows.front();
+ extensions::NativeAppWindow* native_window = app_window->GetBaseWindow();
+ NSWindow* ns_window = native_window->GetNativeWindow();
+
+ extensions::AppWindow* other_app_window = windows.back();
+ extensions::NativeAppWindow* other_native_window =
+ other_app_window->GetBaseWindow();
+ NSWindow* other_ns_window = other_native_window->GetNativeWindow();
// Normal Hide/Show.
- window->Hide();
+ app_window->Hide();
EXPECT_FALSE([ns_window isVisible]);
- window->Show();
+ app_window->Show(extensions::AppWindow::SHOW_ACTIVE);
EXPECT_TRUE([ns_window isVisible]);
// Normal Hide/ShowWithApp.
- window->HideWithApp();
+ native_window->HideWithApp();
EXPECT_FALSE([ns_window isVisible]);
- window->ShowWithApp();
+ native_window->ShowWithApp();
EXPECT_TRUE([ns_window isVisible]);
// HideWithApp, Hide, ShowWithApp does not show.
- window->HideWithApp();
- window->Hide();
- window->ShowWithApp();
+ native_window->HideWithApp();
+ app_window->Hide();
+ native_window->ShowWithApp();
EXPECT_FALSE([ns_window isVisible]);
// Hide, HideWithApp, ShowWithApp does not show.
- window->HideWithApp();
- window->ShowWithApp();
+ native_window->HideWithApp();
+ native_window->ShowWithApp();
EXPECT_FALSE([ns_window isVisible]);
// Return to shown state.
- window->Show();
+ app_window->Show(extensions::AppWindow::SHOW_ACTIVE);
EXPECT_TRUE([ns_window isVisible]);
// HideWithApp the other window.
EXPECT_TRUE([other_ns_window isVisible]);
- other_window->HideWithApp();
+ other_native_window->HideWithApp();
EXPECT_FALSE([other_ns_window isVisible]);
// HideWithApp, Show shows all windows for this app.
- window->HideWithApp();
+ native_window->HideWithApp();
EXPECT_FALSE([ns_window isVisible]);
- window->Show();
+ app_window->Show(extensions::AppWindow::SHOW_ACTIVE);
EXPECT_TRUE([ns_window isVisible]);
EXPECT_TRUE([other_ns_window isVisible]);
// Hide the other window.
- other_window->Hide();
+ other_app_window->Hide();
EXPECT_FALSE([other_ns_window isVisible]);
// HideWithApp, ShowWithApp does not show the other window.
- window->HideWithApp();
+ native_window->HideWithApp();
EXPECT_FALSE([ns_window isVisible]);
- window->ShowWithApp();
+ native_window->ShowWithApp();
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
+
+NSString* const NSWindowDidEnterFullScreenNotification =
+ @"NSWindowDidEnterFullScreenNotification";
+NSString* const NSWindowDidExitFullScreenNotification =
+ @"NSWindowDidExitFullScreenNotification";
+
+#endif // MAC_OS_X_VERSION_10_7
+
+@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) {
+ if (!base::mac::IsOSLionOrLater())
+ return;
+
+ SetUpAppWithWindows(1);
+ extensions::AppWindow* app_window = GetFirstAppWindow();
+ extensions::NativeAppWindow* window = app_window->GetBaseWindow();
+ NSWindow* ns_window = app_window->GetNativeWindow();
+ base::scoped_nsobject<ScopedNotificationWatcher> watcher;
+
+ EXPECT_EQ(extensions::AppWindow::FULLSCREEN_TYPE_NONE,
+ app_window->fullscreen_types_for_test());
+ 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(app_window->fullscreen_types_for_test() &
+ extensions::AppWindow::FULLSCREEN_TYPE_OS);
+ EXPECT_TRUE(window->IsFullscreen());
+ EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask);
+
+ watcher.reset([[ScopedNotificationWatcher alloc]
+ initWithNotification:NSWindowDidExitFullScreenNotification
+ andObject:ns_window]);
+ app_window->Restore();
+ EXPECT_FALSE(window->IsFullscreenOrPending());
+ [watcher waitForNotification];
+ EXPECT_EQ(extensions::AppWindow::FULLSCREEN_TYPE_NONE,
+ app_window->fullscreen_types_for_test());
+ EXPECT_FALSE(window->IsFullscreen());
+ EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask);
+
+ watcher.reset([[ScopedNotificationWatcher alloc]
+ initWithNotification:NSWindowDidEnterFullScreenNotification
+ andObject:ns_window]);
+ app_window->Fullscreen();
+ EXPECT_TRUE(window->IsFullscreenOrPending());
+ [watcher waitForNotification];
+ EXPECT_TRUE(app_window->fullscreen_types_for_test() &
+ extensions::AppWindow::FULLSCREEN_TYPE_WINDOW_API);
+ 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];
+ EXPECT_EQ(extensions::AppWindow::FULLSCREEN_TYPE_NONE,
+ app_window->fullscreen_types_for_test());
+ EXPECT_FALSE(window->IsFullscreen());
+ EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask);
+}