Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: ui/gfx/color_profile_mac_unittest.mm

Issue 2092533002: Clean up gfx::ColorProfile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl try Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/color_profile_mac.mm ('k') | ui/gfx/color_profile_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #import <Cocoa/Cocoa.h>
6
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"
12
13 namespace {
14
15 class ColorProfileTest : public ui::CocoaTest {
16 public:
17 void SetUp() override {
18 ui::CocoaTest::SetUp();
19
20 [test_window() setUseDefaultConstraints:NO];
21
22 // Verify the primary screen origin.
23 NSRect primary_screen_frame = PrimaryScreenFrame();
24 EXPECT_EQ(0, primary_screen_frame.origin.x);
25 EXPECT_EQ(0, primary_screen_frame.origin.y);
26
27 // Move the test window onto the screen.
28 MoveTestWindowTo(gfx::Rect(0, 0, 200, 200));
29
30 // Verify it is contained by the screen.
31 BOOL screen_contains_test_window = NSContainsRect(
32 primary_screen_frame, [test_window() frame]);
33 EXPECT_TRUE(screen_contains_test_window);
34 }
35
36 void MoveTestWindowTo(gfx::Rect bounds) {
37 [test_window() setFrame:gfx::ScreenRectToNSRect(bounds) display:NO];
38 EXPECT_EQ(bounds.ToString(), TestWindowBounds().ToString());
39 }
40
41 gfx::Rect TestWindowBounds() {
42 return gfx::ScreenRectFromNSRect([test_window() frame]);
43 }
44
45 BOOL TestWindowOnScreen() {
46 return NSIntersectsRect(PrimaryScreenFrame(), [test_window() frame]);
47 }
48
49 BOOL TestWindowContainedOnScreen() {
50 return NSContainsRect(PrimaryScreenFrame(), [test_window() frame]);
51 }
52
53 NSRect PrimaryScreenFrame() {
54 return [[[NSScreen screens] firstObject] frame];
55 }
56 };
57
58 bool TestColorProfileForBounds(const gfx::Rect& bounds) {
59 std::vector<char> color_profile;
60 return gfx::GetDisplayColorProfile(bounds, &color_profile);
61 }
62
63 TEST_F(ColorProfileTest, GetDisplayColorProfileForOnScreenBounds) {
64 MoveTestWindowTo(gfx::Rect(10, 10, 100, 100));
65 EXPECT_FALSE(TestWindowBounds().IsEmpty());
66 EXPECT_TRUE(TestWindowContainedOnScreen());
67 EXPECT_TRUE(TestColorProfileForBounds(TestWindowBounds()));
68 }
69
70 TEST_F(ColorProfileTest, GetDisplayColorProfileForPartiallyOnScreenBounds) {
71 MoveTestWindowTo(gfx::Rect(-50, -50, 80, 80));
72 EXPECT_FALSE(TestWindowBounds().IsEmpty());
73 EXPECT_TRUE(TestWindowOnScreen());
74 EXPECT_TRUE(TestColorProfileForBounds(TestWindowBounds()));
75 }
76
77 TEST_F(ColorProfileTest, GetDisplayColorProfileForOffScreenBounds) {
78 MoveTestWindowTo(gfx::Rect(-100, -100, 10, 10));
79 EXPECT_FALSE(TestWindowBounds().IsEmpty());
80 EXPECT_FALSE(TestWindowOnScreen());
81 EXPECT_FALSE(TestColorProfileForBounds(TestWindowBounds()));
82 }
83
84 TEST_F(ColorProfileTest, GetDisplayColorProfileForEmptyOnScreenBounds) {
85 MoveTestWindowTo(gfx::Rect(10, 10, 0, 0));
86 EXPECT_TRUE(TestWindowBounds().IsEmpty());
87 EXPECT_FALSE(TestWindowOnScreen());
88 EXPECT_FALSE(TestColorProfileForBounds(TestWindowBounds()));
89 }
90
91 TEST_F(ColorProfileTest, GetDisplayColorProfileForEmptyOffScreenBounds) {
92 MoveTestWindowTo(gfx::Rect(-100, -100, 0, 0));
93 EXPECT_TRUE(TestWindowBounds().IsEmpty());
94 EXPECT_FALSE(TestWindowOnScreen());
95 EXPECT_FALSE(TestColorProfileForBounds(TestWindowBounds()));
96 }
97
98 bool TestColorProfileForWindow(NSWindow* window) {
99 std::vector<char> color_profile;
100 return gfx::GetDisplayColorProfile(window, &color_profile);
101 }
102
103 TEST_F(ColorProfileTest, GetDisplayColorProfileForOnScreenWindow) {
104 MoveTestWindowTo(gfx::Rect(10, 10, 100, 100));
105 EXPECT_FALSE(TestWindowBounds().IsEmpty());
106 EXPECT_TRUE(TestWindowContainedOnScreen());
107 EXPECT_TRUE(TestColorProfileForWindow(test_window()));
108 }
109
110 TEST_F(ColorProfileTest, GetDisplayColorProfileForPartiallyOnScreenWindow) {
111 MoveTestWindowTo(gfx::Rect(-50, -50, 80, 80));
112 EXPECT_FALSE(TestWindowBounds().IsEmpty());
113 EXPECT_TRUE(TestWindowOnScreen());
114 EXPECT_TRUE(TestColorProfileForWindow(test_window()));
115 }
116
117 TEST_F(ColorProfileTest, GetDisplayColorProfileForOffScreenWindow) {
118 MoveTestWindowTo(gfx::Rect(-100, -100, 10, 10));
119 EXPECT_FALSE(TestWindowBounds().IsEmpty());
120 EXPECT_FALSE(TestWindowOnScreen());
121 EXPECT_TRUE(TestColorProfileForWindow(test_window()));
122 }
123
124 TEST_F(ColorProfileTest, GetDisplayColorProfileForEmptyOnScreenWindow) {
125 MoveTestWindowTo(gfx::Rect(10, 10, 0, 0));
126 EXPECT_TRUE(TestWindowBounds().IsEmpty());
127 EXPECT_FALSE(TestWindowOnScreen());
128 EXPECT_FALSE(TestColorProfileForWindow(test_window()));
129 }
130
131 TEST_F(ColorProfileTest, GetDisplayColorProfileForEmptyOffScreenWindow) {
132 MoveTestWindowTo(gfx::Rect(-100, -100, 0, 0));
133 EXPECT_TRUE(TestWindowBounds().IsEmpty());
134 EXPECT_FALSE(TestWindowOnScreen());
135 EXPECT_FALSE(TestColorProfileForWindow(test_window()));
136 }
137
138 TEST_F(ColorProfileTest, GetDisplayColorProfileForNullWindow) {
139 EXPECT_FALSE(TestColorProfileForWindow(nullptr));
140 EXPECT_FALSE(TestColorProfileForWindow(nil));
141 }
142
143 } // namespace
OLDNEW
« no previous file with comments | « ui/gfx/color_profile_mac.mm ('k') | ui/gfx/color_profile_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698