1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import <Cocoa/Cocoa.h>
7 #include "base/mac/scoped_nsobject.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/color_profile.h"
10 #include "ui/gfx/mac/coordinate_conversion.h"
11 #import "ui/gfx/test/ui_cocoa_test_helper.h"
15 class ColorProfileTest : public ui::CocoaTest {
17 virtual void SetUp() override {
18 ui::CocoaTest::SetUp();
20 // Verify the primary screen origin.
21 NSRect primary_screen_frame = PrimaryScreenFrame();
22 EXPECT_EQ(0, primary_screen_frame.origin.x);
23 EXPECT_EQ(0, primary_screen_frame.origin.y);
25 // Move the test window onto the screen.
26 MoveTestWindowTo(gfx::Rect(0, 0, 200, 200));
28 // Verify it is contained by the screen.
29 BOOL screen_contains_test_window = NSContainsRect(
30 primary_screen_frame, [test_window() frame]);
31 EXPECT_TRUE(screen_contains_test_window);
34 void MoveTestWindowTo(gfx::Rect bounds) {
35 [test_window() setFrame:gfx::ScreenRectToNSRect(bounds) display:NO];
36 EXPECT_EQ(bounds.ToString(), TestWindowBounds().ToString());
39 gfx::Rect TestWindowBounds() {
40 return gfx::ScreenRectFromNSRect([test_window() frame]);
43 BOOL TestWindowOnScreen() {
44 return NSIntersectsRect(PrimaryScreenFrame(), [test_window() frame]);
47 BOOL TestWindowContainedOnScreen() {
48 return NSContainsRect(PrimaryScreenFrame(), [test_window() frame]);
51 NSRect PrimaryScreenFrame() {
52 return [[[NSScreen screens] objectAtIndex:0] frame];
56 bool TestColorProfileForBounds(const gfx::Rect& bounds) {
57 std::vector<char> color_profile;
58 return gfx::GetDisplayColorProfile(bounds, &color_profile);
61 TEST_F(ColorProfileTest, GetDisplayColorProfileForOnScreenBounds) {
62 MoveTestWindowTo(gfx::Rect(10, 10, 100, 100));
63 EXPECT_FALSE(TestWindowBounds().IsEmpty());
64 EXPECT_TRUE(TestWindowContainedOnScreen());
65 EXPECT_TRUE(TestColorProfileForBounds(TestWindowBounds()));
68 TEST_F(ColorProfileTest, GetDisplayColorProfileForPartiallyOnScreenBounds) {
69 MoveTestWindowTo(gfx::Rect(-50, -50, 80, 80));
70 EXPECT_FALSE(TestWindowBounds().IsEmpty());
71 EXPECT_TRUE(TestWindowOnScreen());
72 EXPECT_TRUE(TestColorProfileForBounds(TestWindowBounds()));
75 TEST_F(ColorProfileTest, GetDisplayColorProfileForOffScreenBounds) {
76 MoveTestWindowTo(gfx::Rect(-100, -100, 10, 10));
77 EXPECT_FALSE(TestWindowBounds().IsEmpty());
78 EXPECT_FALSE(TestWindowOnScreen());
79 EXPECT_FALSE(TestColorProfileForBounds(TestWindowBounds()));
82 TEST_F(ColorProfileTest, GetDisplayColorProfileForEmptyOnScreenBounds) {
83 MoveTestWindowTo(gfx::Rect(10, 10, 0, 0));
84 EXPECT_TRUE(TestWindowBounds().IsEmpty());
85 EXPECT_FALSE(TestWindowOnScreen());
86 EXPECT_FALSE(TestColorProfileForBounds(TestWindowBounds()));
89 TEST_F(ColorProfileTest, GetDisplayColorProfileForEmptyOffScreenBounds) {
90 MoveTestWindowTo(gfx::Rect(-100, -100, 0, 0));
91 EXPECT_TRUE(TestWindowBounds().IsEmpty());
92 EXPECT_FALSE(TestWindowOnScreen());
93 EXPECT_FALSE(TestColorProfileForBounds(TestWindowBounds()));