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 #include "base/mac/mac_util.h" | 11 #import "base/mac/foundation_util.h" |
12 #include "base/mac/scoped_nsobject.h" | 12 #import "base/mac/mac_util.h" |
13 #include "base/mac/sdk_forward_declarations.h" | 13 #import "base/mac/scoped_nsobject.h" |
| 14 #import "base/mac/sdk_forward_declarations.h" |
14 #include "chrome/browser/apps/app_browsertest_util.h" | 15 #include "chrome/browser/apps/app_browsertest_util.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/extensions/app_launch_params.h" | 17 #include "chrome/browser/ui/extensions/app_launch_params.h" |
17 #include "chrome/browser/ui/extensions/application_launch.h" | 18 #include "chrome/browser/ui/extensions/application_launch.h" |
| 19 #import "chrome/browser/ui/test/scoped_fake_nswindow_main_status.h" |
18 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
19 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
20 #include "extensions/browser/app_window/app_window_registry.h" | 22 #include "extensions/browser/app_window/app_window_registry.h" |
21 #include "extensions/common/constants.h" | 23 #include "extensions/common/constants.h" |
22 | 24 |
23 using extensions::PlatformAppBrowserTest; | 25 using extensions::PlatformAppBrowserTest; |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 class NativeAppWindowCocoaBrowserTest : public PlatformAppBrowserTest { | 29 class NativeAppWindowCocoaBrowserTest : public PlatformAppBrowserTest { |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 299 |
298 } // namespace | 300 } // namespace |
299 | 301 |
300 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Controls) { | 302 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Controls) { |
301 TestControls(CreateTestAppWindow("{}")); | 303 TestControls(CreateTestAppWindow("{}")); |
302 } | 304 } |
303 | 305 |
304 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, ControlsFrameless) { | 306 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, ControlsFrameless) { |
305 TestControls(CreateTestAppWindow("{\"frame\": \"none\"}")); | 307 TestControls(CreateTestAppWindow("{\"frame\": \"none\"}")); |
306 } | 308 } |
| 309 |
| 310 // Test that the colored frames have the correct color when active and inactive. |
| 311 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, FrameColor) { |
| 312 // The hex values indicate an RGB color. When we get the NSColor later, the |
| 313 // components are CGFloats in the range [0, 1]. |
| 314 extensions::AppWindow* app_window = CreateTestAppWindow( |
| 315 "{\"frame\": {\"color\": \"#FF0000\", \"inactiveColor\": \"#0000FF\"}}"); |
| 316 NSWindow* ns_window = app_window->GetNativeWindow(); |
| 317 // Disable color correction so we can read unmodified values from the bitmap. |
| 318 [ns_window setColorSpace:[NSColorSpace sRGBColorSpace]]; |
| 319 |
| 320 NSView* frame_view = [[ns_window contentView] superview]; |
| 321 NSRect bounds = [frame_view bounds]; |
| 322 NSBitmapImageRep* bitmap = |
| 323 [frame_view bitmapImageRepForCachingDisplayInRect:bounds]; |
| 324 |
| 325 [frame_view cacheDisplayInRect:bounds toBitmapImageRep:bitmap]; |
| 326 NSColor* color = [bitmap colorAtX:NSMidX(bounds) y:5]; |
| 327 // The window is currently inactive so it should be blue (#0000FF). |
| 328 EXPECT_EQ(0, [color redComponent]); |
| 329 EXPECT_EQ(0, [color greenComponent]); |
| 330 EXPECT_EQ(1, [color blueComponent]); |
| 331 |
| 332 ScopedFakeNSWindowMainStatus fake_main(ns_window); |
| 333 |
| 334 [frame_view cacheDisplayInRect:bounds toBitmapImageRep:bitmap]; |
| 335 color = [bitmap colorAtX:NSMidX(bounds) y:5]; |
| 336 // The window is now active so it should be red (#FF0000). |
| 337 EXPECT_EQ(1, [color redComponent]); |
| 338 EXPECT_EQ(0, [color greenComponent]); |
| 339 EXPECT_EQ(0, [color blueComponent]); |
| 340 } |
OLD | NEW |