OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ui/display/screen.h" | 5 #include "ui/display/screen.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/display/display.h" | 8 #include "ui/display/display.h" |
| 9 #include "ui/display/test/test_screen.h" |
9 | 10 |
10 namespace display { | 11 namespace display { |
11 | 12 |
12 TEST(ScreenTest, GetPrimaryDisplaySize) { | 13 namespace { |
13 // We aren't actually testing that it's correct, just that it's sane. | 14 |
| 15 const int DEFAULT_DISPLAY_ID = 0x1337; |
| 16 const int DEFAULT_DISPLAY_WIDTH = 2560; |
| 17 const int DEFAULT_DISPLAY_HEIGHT = 1440; |
| 18 |
| 19 } // namespace |
| 20 |
| 21 class ScreenTest : public testing::Test { |
| 22 protected: |
| 23 ScreenTest() { |
| 24 const display::Display test_display = test_screen_.GetPrimaryDisplay(); |
| 25 display::Display display(test_display); |
| 26 display.set_id(DEFAULT_DISPLAY_ID); |
| 27 display.set_bounds( |
| 28 gfx::Rect(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT)); |
| 29 test_screen_.display_list().RemoveDisplay(test_display.id()); |
| 30 test_screen_.display_list().AddDisplay(display, |
| 31 display::DisplayList::Type::PRIMARY); |
| 32 Screen::SetScreenInstance(&test_screen_); |
| 33 } |
| 34 |
| 35 ~ScreenTest() override { Screen::SetScreenInstance(nullptr); } |
| 36 |
| 37 private: |
| 38 display::test::TestScreen test_screen_; |
| 39 |
| 40 DISALLOW_COPY_AND_ASSIGN(ScreenTest); |
| 41 }; |
| 42 |
| 43 TEST_F(ScreenTest, GetPrimaryDisplaySize) { |
14 const gfx::Size size = Screen::GetScreen()->GetPrimaryDisplay().size(); | 44 const gfx::Size size = Screen::GetScreen()->GetPrimaryDisplay().size(); |
15 EXPECT_GE(size.width(), 1); | 45 EXPECT_EQ(DEFAULT_DISPLAY_WIDTH, size.width()); |
16 EXPECT_GE(size.height(), 1); | 46 EXPECT_EQ(DEFAULT_DISPLAY_HEIGHT, size.height()); |
17 } | 47 } |
18 | 48 |
19 TEST(ScreenTest, GetNumDisplays) { | 49 TEST_F(ScreenTest, GetNumDisplays) { |
20 // We aren't actually testing that it's correct, just that it's sane. | 50 EXPECT_EQ(Screen::GetScreen()->GetNumDisplays(), 1); |
21 EXPECT_GE(Screen::GetScreen()->GetNumDisplays(), 1); | 51 } |
| 52 |
| 53 TEST_F(ScreenTest, GetDisplayWithDisplayId) { |
| 54 Display display; |
| 55 EXPECT_TRUE(Screen::GetScreen()->GetDisplayWithDisplayId(DEFAULT_DISPLAY_ID, |
| 56 &display)); |
| 57 EXPECT_EQ(DEFAULT_DISPLAY_ID, display.id()); |
| 58 EXPECT_EQ(DEFAULT_DISPLAY_WIDTH, display.size().width()); |
| 59 EXPECT_EQ(DEFAULT_DISPLAY_HEIGHT, display.size().height()); |
22 } | 60 } |
23 | 61 |
24 } // namespace | 62 } // namespace |
OLD | NEW |