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 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 233 |
234 // Since the window has no constraints, it should have all of the following | 234 // Since the window has no constraints, it should have all of the following |
235 // style mask bits. | 235 // style mask bits. |
236 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | | 236 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | |
237 NSMiniaturizableWindowMask | NSResizableWindowMask | | 237 NSMiniaturizableWindowMask | NSResizableWindowMask | |
238 NSTexturedBackgroundWindowMask; | 238 NSTexturedBackgroundWindowMask; |
239 EXPECT_EQ(style_mask, [ns_window styleMask]); | 239 EXPECT_EQ(style_mask, [ns_window styleMask]); |
240 | 240 |
241 CloseAppWindow(app_window); | 241 CloseAppWindow(app_window); |
242 } | 242 } |
| 243 |
| 244 namespace { |
| 245 |
| 246 // Test that resize and fullscreen controls are correctly enabled/disabled. |
| 247 void TestControls(extensions::AppWindow* app_window) { |
| 248 NSWindow* ns_window = app_window->GetNativeWindow(); |
| 249 |
| 250 // The window is resizable. |
| 251 EXPECT_TRUE([ns_window styleMask] & NSResizableWindowMask); |
| 252 if (base::mac::IsOSSnowLeopard()) |
| 253 EXPECT_TRUE([ns_window showsResizeIndicator]); |
| 254 |
| 255 // Due to this bug: http://crbug.com/362039, which manifests on the Cocoa |
| 256 // implementation but not the views one, frameless windows should have |
| 257 // fullscreen controls disabled. |
| 258 BOOL can_fullscreen = |
| 259 ![NSStringFromClass([ns_window class]) isEqualTo:@"AppFramelessNSWindow"]; |
| 260 // The window can fullscreen and maximize. |
| 261 if (base::mac::IsOSLionOrLater()) |
| 262 EXPECT_EQ(can_fullscreen, !!([ns_window collectionBehavior] & |
| 263 NSWindowCollectionBehaviorFullScreenPrimary)); |
| 264 EXPECT_EQ(can_fullscreen, |
| 265 [[ns_window standardWindowButton:NSWindowZoomButton] isEnabled]); |
| 266 |
| 267 // Set a maximum size. |
| 268 app_window->SetContentSizeConstraints(gfx::Size(), gfx::Size(200, 201)); |
| 269 EXPECT_EQ(200, [ns_window contentMaxSize].width); |
| 270 EXPECT_EQ(201, [ns_window contentMaxSize].height); |
| 271 NSView* web_contents = app_window->web_contents()->GetNativeView(); |
| 272 EXPECT_EQ(200, [web_contents frame].size.width); |
| 273 EXPECT_EQ(201, [web_contents frame].size.height); |
| 274 |
| 275 // Still resizable. |
| 276 EXPECT_TRUE([ns_window styleMask] & NSResizableWindowMask); |
| 277 if (base::mac::IsOSSnowLeopard()) |
| 278 EXPECT_TRUE([ns_window showsResizeIndicator]); |
| 279 |
| 280 // Fullscreen and maximize are disabled. |
| 281 if (base::mac::IsOSLionOrLater()) |
| 282 EXPECT_FALSE([ns_window collectionBehavior] & |
| 283 NSWindowCollectionBehaviorFullScreenPrimary); |
| 284 EXPECT_FALSE([[ns_window standardWindowButton:NSWindowZoomButton] isEnabled]); |
| 285 |
| 286 // Set a minimum size equal to the maximum size. |
| 287 app_window->SetContentSizeConstraints(gfx::Size(200, 201), |
| 288 gfx::Size(200, 201)); |
| 289 EXPECT_EQ(200, [ns_window contentMinSize].width); |
| 290 EXPECT_EQ(201, [ns_window contentMinSize].height); |
| 291 |
| 292 // No longer resizable. |
| 293 EXPECT_FALSE([ns_window styleMask] & NSResizableWindowMask); |
| 294 if (base::mac::IsOSSnowLeopard()) |
| 295 EXPECT_FALSE([ns_window showsResizeIndicator]); |
| 296 } |
| 297 |
| 298 } // namespace |
| 299 |
| 300 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Controls) { |
| 301 TestControls(CreateTestAppWindow("{}")); |
| 302 } |
| 303 |
| 304 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, ControlsFrameless) { |
| 305 TestControls(CreateTestAppWindow("{\"frame\": \"none\"}")); |
| 306 } |
OLD | NEW |