[iOS] Cleanup ios/chrome/ios_chrome.gyp
[chromium-blink-merge.git] / ui / gfx / color_profile_mac_unittest.mm
blob95680c35ce61258ce80c02f8baec2c2b8a8f08c2
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"
13 namespace {
15 class ColorProfileTest : public ui::CocoaTest {
16  public:
17   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);
32   }
34   void MoveTestWindowTo(gfx::Rect bounds) {
35     [test_window() setFrame:gfx::ScreenRectToNSRect(bounds) display:NO];
36     EXPECT_EQ(bounds.ToString(), TestWindowBounds().ToString());
37   }
39   gfx::Rect TestWindowBounds() {
40     return gfx::ScreenRectFromNSRect([test_window() frame]);
41   }
43   BOOL TestWindowOnScreen() {
44     return NSIntersectsRect(PrimaryScreenFrame(), [test_window() frame]);
45   }
47   BOOL TestWindowContainedOnScreen() {
48     return NSContainsRect(PrimaryScreenFrame(), [test_window() frame]);
49   }
51   NSRect PrimaryScreenFrame() {
52     return [[[NSScreen screens] objectAtIndex:0] frame];
53   }
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()));
96 bool TestColorProfileForWindow(NSWindow* window) {
97   std::vector<char> color_profile;
98   return gfx::GetDisplayColorProfile(window, &color_profile);
101 TEST_F(ColorProfileTest, GetDisplayColorProfileForOnScreenWindow) {
102   MoveTestWindowTo(gfx::Rect(10, 10, 100, 100));
103   EXPECT_FALSE(TestWindowBounds().IsEmpty());
104   EXPECT_TRUE(TestWindowContainedOnScreen());
105   EXPECT_TRUE(TestColorProfileForWindow(test_window()));
108 TEST_F(ColorProfileTest, GetDisplayColorProfileForPartiallyOnScreenWindow) {
109   MoveTestWindowTo(gfx::Rect(-50, -50, 80, 80));
110   EXPECT_FALSE(TestWindowBounds().IsEmpty());
111   EXPECT_TRUE(TestWindowOnScreen());
112   EXPECT_TRUE(TestColorProfileForWindow(test_window()));
115 TEST_F(ColorProfileTest, GetDisplayColorProfileForOffScreenWindow) {
116   MoveTestWindowTo(gfx::Rect(-100, -100, 10, 10));
117   EXPECT_FALSE(TestWindowBounds().IsEmpty());
118   EXPECT_FALSE(TestWindowOnScreen());
119   EXPECT_TRUE(TestColorProfileForWindow(test_window()));
122 TEST_F(ColorProfileTest, GetDisplayColorProfileForEmptyOnScreenWindow) {
123   MoveTestWindowTo(gfx::Rect(10, 10, 0, 0));
124   EXPECT_TRUE(TestWindowBounds().IsEmpty());
125   EXPECT_FALSE(TestWindowOnScreen());
126   EXPECT_FALSE(TestColorProfileForWindow(test_window()));
129 TEST_F(ColorProfileTest, GetDisplayColorProfileForEmptyOffScreenWindow) {
130   MoveTestWindowTo(gfx::Rect(-100, -100, 0, 0));
131   EXPECT_TRUE(TestWindowBounds().IsEmpty());
132   EXPECT_FALSE(TestWindowOnScreen());
133   EXPECT_FALSE(TestColorProfileForWindow(test_window()));
136 TEST_F(ColorProfileTest, GetDisplayColorProfileForNullWindow) {
137   EXPECT_FALSE(TestColorProfileForWindow(nullptr));
138   EXPECT_FALSE(TestColorProfileForWindow(nil));
141 }  // namespace