OLD | NEW |
(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 virtual void SetUp() override { |
| 18 ui::CocoaTest::SetUp(); |
| 19 |
| 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); |
| 24 |
| 25 // Move the test window onto the screen. |
| 26 MoveTestWindowTo(gfx::Rect(0, 0, 200, 200)); |
| 27 |
| 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 } |
| 33 |
| 34 void MoveTestWindowTo(gfx::Rect bounds) { |
| 35 [test_window() setFrame:gfx::ScreenRectToNSRect(bounds) display:NO]; |
| 36 EXPECT_EQ(bounds.ToString(), TestWindowBounds().ToString()); |
| 37 } |
| 38 |
| 39 gfx::Rect TestWindowBounds() { |
| 40 return gfx::ScreenRectFromNSRect([test_window() frame]); |
| 41 } |
| 42 |
| 43 BOOL TestWindowOnScreen() { |
| 44 return NSIntersectsRect(PrimaryScreenFrame(), [test_window() frame]); |
| 45 } |
| 46 |
| 47 BOOL TestWindowContainedOnScreen() { |
| 48 return NSContainsRect(PrimaryScreenFrame(), [test_window() frame]); |
| 49 } |
| 50 |
| 51 NSRect PrimaryScreenFrame() { |
| 52 return [[[NSScreen screens] objectAtIndex:0] frame]; |
| 53 } |
| 54 }; |
| 55 |
| 56 bool TestColorProfileForBounds(const gfx::Rect& bounds) { |
| 57 std::vector<char> color_profile; |
| 58 return gfx::GetDisplayColorProfile(bounds, &color_profile); |
| 59 } |
| 60 |
| 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())); |
| 66 } |
| 67 |
| 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())); |
| 73 } |
| 74 |
| 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())); |
| 80 } |
| 81 |
| 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())); |
| 87 } |
| 88 |
| 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())); |
| 94 } |
| 95 |
| 96 } // namespace |
OLD | NEW |