| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file tests whichever implementation of NativeAppWindow is used. | 5 // This file tests whichever implementation of NativeAppWindow is used. |
| 6 // I.e. it could be NativeAppWindowCocoa or ChromeNativeAppWindowViewsMac. | 6 // I.e. it could be NativeAppWindowCocoa or ChromeNativeAppWindowViewsMac. |
| 7 #include "extensions/browser/app_window/native_app_window.h" | 7 #include "extensions/browser/app_window/native_app_window.h" |
| 8 | 8 |
| 9 #import <Cocoa/Cocoa.h> | 9 #import <Cocoa/Cocoa.h> |
| 10 | 10 |
| 11 #import "base/mac/foundation_util.h" | 11 #import "base/mac/foundation_util.h" |
| 12 #import "base/mac/mac_util.h" | 12 #import "base/mac/mac_util.h" |
| 13 #import "base/mac/scoped_nsobject.h" | 13 #import "base/mac/scoped_nsobject.h" |
| 14 #import "base/mac/sdk_forward_declarations.h" | 14 #import "base/mac/sdk_forward_declarations.h" |
| 15 #include "chrome/browser/apps/app_browsertest_util.h" | 15 #include "chrome/browser/apps/app_browsertest_util.h" |
| 16 #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h" | 16 #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h" |
| 17 #include "chrome/browser/apps/app_shim/test/app_shim_host_manager_test_api_mac.h
" | 17 #include "chrome/browser/apps/app_shim/test/app_shim_host_manager_test_api_mac.h
" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/extensions/app_launch_params.h" | 20 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 21 #include "chrome/browser/ui/extensions/application_launch.h" | 21 #include "chrome/browser/ui/extensions/application_launch.h" |
| 22 #import "chrome/browser/ui/test/scoped_fake_nswindow_main_status.h" | 22 #import "chrome/browser/ui/test/scoped_fake_nswindow_main_status.h" |
| 23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/test/test_utils.h" | 24 #include "content/public/test/test_utils.h" |
| 25 #include "extensions/browser/app_window/app_window_registry.h" | 25 #include "extensions/browser/app_window/app_window_registry.h" |
| 26 #include "extensions/common/constants.h" | 26 #include "extensions/common/constants.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #import "ui/base/test/nswindow_fullscreen_notification_waiter.h" | 28 #import "ui/base/test/nswindow_fullscreen_notification_waiter.h" |
| 29 #import "ui/gfx/mac/nswindow_frame_controls.h" |
| 29 | 30 |
| 30 using extensions::AppWindow; | 31 using extensions::AppWindow; |
| 31 using extensions::PlatformAppBrowserTest; | 32 using extensions::PlatformAppBrowserTest; |
| 32 | 33 |
| 33 using ::testing::_; | 34 using ::testing::_; |
| 34 using ::testing::Invoke; | 35 using ::testing::Invoke; |
| 35 using ::testing::Return; | 36 using ::testing::Return; |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 } | 238 } |
| 238 | 239 |
| 239 @end | 240 @end |
| 240 | 241 |
| 241 // Test that NativeAppWindow and AppWindow fullscreen state is updated when | 242 // Test that NativeAppWindow and AppWindow fullscreen state is updated when |
| 242 // the window is fullscreened natively. | 243 // the window is fullscreened natively. |
| 243 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Fullscreen) { | 244 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Fullscreen) { |
| 244 if (!base::mac::IsOSLionOrLater()) | 245 if (!base::mac::IsOSLionOrLater()) |
| 245 return; | 246 return; |
| 246 | 247 |
| 247 SetUpAppWithWindows(1); | 248 extensions::AppWindow* app_window = |
| 248 AppWindow* app_window = GetFirstAppWindow(); | 249 CreateTestAppWindow("{\"alwaysOnTop\": true }"); |
| 249 extensions::NativeAppWindow* window = app_window->GetBaseWindow(); | 250 extensions::NativeAppWindow* window = app_window->GetBaseWindow(); |
| 250 NSWindow* ns_window = app_window->GetNativeWindow(); | 251 NSWindow* ns_window = app_window->GetNativeWindow(); |
| 251 base::scoped_nsobject<ScopedNotificationWatcher> watcher; | 252 base::scoped_nsobject<ScopedNotificationWatcher> watcher; |
| 252 | 253 |
| 253 EXPECT_EQ(AppWindow::FULLSCREEN_TYPE_NONE, | 254 EXPECT_EQ(AppWindow::FULLSCREEN_TYPE_NONE, |
| 254 app_window->fullscreen_types_for_test()); | 255 app_window->fullscreen_types_for_test()); |
| 255 EXPECT_FALSE(window->IsFullscreen()); | 256 EXPECT_FALSE(window->IsFullscreen()); |
| 256 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); | 257 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); |
| 258 EXPECT_TRUE(gfx::IsNSWindowAlwaysOnTop(ns_window)); |
| 257 | 259 |
| 258 watcher.reset([[ScopedNotificationWatcher alloc] | 260 watcher.reset([[ScopedNotificationWatcher alloc] |
| 259 initWithNotification:NSWindowDidEnterFullScreenNotification | 261 initWithNotification:NSWindowDidEnterFullScreenNotification |
| 260 andObject:ns_window]); | 262 andObject:ns_window]); |
| 261 [ns_window toggleFullScreen:nil]; | 263 [ns_window toggleFullScreen:nil]; |
| 262 [watcher waitForNotification]; | 264 [watcher waitForNotification]; |
| 263 EXPECT_TRUE(app_window->fullscreen_types_for_test() & | 265 EXPECT_TRUE(app_window->fullscreen_types_for_test() & |
| 264 AppWindow::FULLSCREEN_TYPE_OS); | 266 AppWindow::FULLSCREEN_TYPE_OS); |
| 265 EXPECT_TRUE(window->IsFullscreen()); | 267 EXPECT_TRUE(window->IsFullscreen()); |
| 266 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); | 268 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); |
| 269 EXPECT_FALSE(gfx::IsNSWindowAlwaysOnTop(ns_window)); |
| 267 | 270 |
| 268 watcher.reset([[ScopedNotificationWatcher alloc] | 271 watcher.reset([[ScopedNotificationWatcher alloc] |
| 269 initWithNotification:NSWindowDidExitFullScreenNotification | 272 initWithNotification:NSWindowDidExitFullScreenNotification |
| 270 andObject:ns_window]); | 273 andObject:ns_window]); |
| 271 app_window->Restore(); | 274 app_window->Restore(); |
| 272 EXPECT_FALSE(window->IsFullscreenOrPending()); | 275 EXPECT_FALSE(window->IsFullscreenOrPending()); |
| 273 [watcher waitForNotification]; | 276 [watcher waitForNotification]; |
| 274 EXPECT_EQ(AppWindow::FULLSCREEN_TYPE_NONE, | 277 EXPECT_EQ(AppWindow::FULLSCREEN_TYPE_NONE, |
| 275 app_window->fullscreen_types_for_test()); | 278 app_window->fullscreen_types_for_test()); |
| 276 EXPECT_FALSE(window->IsFullscreen()); | 279 EXPECT_FALSE(window->IsFullscreen()); |
| 277 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); | 280 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); |
| 281 EXPECT_TRUE(gfx::IsNSWindowAlwaysOnTop(ns_window)); |
| 278 | 282 |
| 279 watcher.reset([[ScopedNotificationWatcher alloc] | 283 watcher.reset([[ScopedNotificationWatcher alloc] |
| 280 initWithNotification:NSWindowDidEnterFullScreenNotification | 284 initWithNotification:NSWindowDidEnterFullScreenNotification |
| 281 andObject:ns_window]); | 285 andObject:ns_window]); |
| 282 app_window->Fullscreen(); | 286 app_window->Fullscreen(); |
| 283 EXPECT_TRUE(window->IsFullscreenOrPending()); | 287 EXPECT_TRUE(window->IsFullscreenOrPending()); |
| 284 [watcher waitForNotification]; | 288 [watcher waitForNotification]; |
| 285 EXPECT_TRUE(app_window->fullscreen_types_for_test() & | 289 EXPECT_TRUE(app_window->fullscreen_types_for_test() & |
| 286 AppWindow::FULLSCREEN_TYPE_WINDOW_API); | 290 AppWindow::FULLSCREEN_TYPE_WINDOW_API); |
| 287 EXPECT_TRUE(window->IsFullscreen()); | 291 EXPECT_TRUE(window->IsFullscreen()); |
| 288 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); | 292 EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask); |
| 293 EXPECT_FALSE(gfx::IsNSWindowAlwaysOnTop(ns_window)); |
| 289 | 294 |
| 290 watcher.reset([[ScopedNotificationWatcher alloc] | 295 watcher.reset([[ScopedNotificationWatcher alloc] |
| 291 initWithNotification:NSWindowDidExitFullScreenNotification | 296 initWithNotification:NSWindowDidExitFullScreenNotification |
| 292 andObject:ns_window]); | 297 andObject:ns_window]); |
| 293 [ns_window toggleFullScreen:nil]; | 298 [ns_window toggleFullScreen:nil]; |
| 294 [watcher waitForNotification]; | 299 [watcher waitForNotification]; |
| 295 EXPECT_EQ(AppWindow::FULLSCREEN_TYPE_NONE, | 300 EXPECT_EQ(AppWindow::FULLSCREEN_TYPE_NONE, |
| 296 app_window->fullscreen_types_for_test()); | 301 app_window->fullscreen_types_for_test()); |
| 297 EXPECT_FALSE(window->IsFullscreen()); | 302 EXPECT_FALSE(window->IsFullscreen()); |
| 298 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); | 303 EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask); |
| 304 EXPECT_TRUE(gfx::IsNSWindowAlwaysOnTop(ns_window)); |
| 299 } | 305 } |
| 300 | 306 |
| 301 // Test that, in frameless windows, the web contents has the same size as the | 307 // Test that, in frameless windows, the web contents has the same size as the |
| 302 // window. | 308 // window. |
| 303 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Frameless) { | 309 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Frameless) { |
| 304 AppWindow* app_window = CreateTestAppWindow("{\"frame\": \"none\"}"); | 310 AppWindow* app_window = CreateTestAppWindow("{\"frame\": \"none\"}"); |
| 305 NSWindow* ns_window = app_window->GetNativeWindow(); | 311 NSWindow* ns_window = app_window->GetNativeWindow(); |
| 306 NSView* web_contents = app_window->web_contents()->GetNativeView(); | 312 NSView* web_contents = app_window->web_contents()->GetNativeView(); |
| 307 EXPECT_TRUE(NSEqualSizes(NSMakeSize(512, 384), [web_contents frame].size)); | 313 EXPECT_TRUE(NSEqualSizes(NSMakeSize(512, 384), [web_contents frame].size)); |
| 308 // Move and resize the window. | 314 // Move and resize the window. |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 436 |
| 431 ScopedFakeNSWindowMainStatus fake_main(ns_window); | 437 ScopedFakeNSWindowMainStatus fake_main(ns_window); |
| 432 | 438 |
| 433 [frame_view cacheDisplayInRect:bounds toBitmapImageRep:bitmap]; | 439 [frame_view cacheDisplayInRect:bounds toBitmapImageRep:bitmap]; |
| 434 color = [bitmap colorAtX:NSMidX(bounds) y:5]; | 440 color = [bitmap colorAtX:NSMidX(bounds) y:5]; |
| 435 // The window is now active so it should be red (#FF0000). | 441 // The window is now active so it should be red (#FF0000). |
| 436 EXPECT_EQ(1, [color redComponent]); | 442 EXPECT_EQ(1, [color redComponent]); |
| 437 EXPECT_EQ(0, [color greenComponent]); | 443 EXPECT_EQ(0, [color greenComponent]); |
| 438 EXPECT_EQ(0, [color blueComponent]); | 444 EXPECT_EQ(0, [color blueComponent]); |
| 439 } | 445 } |
| OLD | NEW |