OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/display/display_util_x11.h" | 5 #include "ash/display/display_change_observer_chromeos.h" |
6 | 6 |
7 #include <X11/extensions/Xrandr.h> | 7 #include "ash/display/display_info.h" |
8 | 8 #include "chromeos/display/output_configurator.h" |
9 // Undefine X's macros used in gtest. | |
10 #undef Bool | |
11 #undef None | |
12 | |
13 #include "chromeos/display/output_util.h" | 9 #include "chromeos/display/output_util.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
15 | 11 |
16 typedef testing::Test DisplayUtilX11Test; | 12 using chromeos::OutputConfigurator; |
| 13 |
| 14 typedef testing::Test DisplayChangeObserverTest; |
17 | 15 |
18 namespace ash { | 16 namespace ash { |
19 namespace internal { | 17 namespace internal { |
20 | 18 |
21 TEST_F(DisplayUtilX11Test, TestBlackListedDisplay) { | 19 TEST_F(DisplayChangeObserverTest, TestBlackListedDisplay) { |
22 EXPECT_TRUE(ShouldIgnoreSize(10, 10)); | 20 EXPECT_TRUE(DisplayChangeObserver::ShouldIgnoreSize(10, 10)); |
23 EXPECT_TRUE(ShouldIgnoreSize(40, 30)); | 21 EXPECT_TRUE(DisplayChangeObserver::ShouldIgnoreSize(40, 30)); |
24 EXPECT_TRUE(ShouldIgnoreSize(50, 40)); | 22 EXPECT_TRUE(DisplayChangeObserver::ShouldIgnoreSize(50, 40)); |
25 EXPECT_TRUE(ShouldIgnoreSize(160, 90)); | 23 EXPECT_TRUE(DisplayChangeObserver::ShouldIgnoreSize(160, 90)); |
26 EXPECT_TRUE(ShouldIgnoreSize(160, 100)); | 24 EXPECT_TRUE(DisplayChangeObserver::ShouldIgnoreSize(160, 100)); |
27 | 25 |
28 EXPECT_FALSE(ShouldIgnoreSize(50, 60)); | 26 EXPECT_FALSE(DisplayChangeObserver::ShouldIgnoreSize(50, 60)); |
29 EXPECT_FALSE(ShouldIgnoreSize(100, 70)); | 27 EXPECT_FALSE(DisplayChangeObserver::ShouldIgnoreSize(100, 70)); |
30 EXPECT_FALSE(ShouldIgnoreSize(272, 181)); | 28 EXPECT_FALSE(DisplayChangeObserver::ShouldIgnoreSize(272, 181)); |
31 } | 29 } |
32 | 30 |
33 TEST_F(DisplayUtilX11Test, GetResolutionList) { | 31 TEST_F(DisplayChangeObserverTest, GetResolutionList) { |
34 XRRScreenResources resources = {0}; | 32 OutputConfigurator::OutputSnapshot output; |
35 RROutput outputs[] = {1}; | 33 output.mode_infos[11] = OutputConfigurator::ModeInfo(1920, 1200, false); |
36 resources.noutput = arraysize(outputs); | |
37 resources.outputs = outputs; | |
38 XRRModeInfo modes[] = { | |
39 // id, width, height, interlaced, refresh rate | |
40 chromeos::test::CreateModeInfo(11, 1920, 1200, false, 60.0f), | |
41 | 34 |
42 // different rates | 35 // All non-interlaced (as would be seen with different refresh rates). |
43 chromeos::test::CreateModeInfo(12, 1920, 1080, false, 30.0f), | 36 output.mode_infos[12] = OutputConfigurator::ModeInfo(1920, 1080, false); |
44 chromeos::test::CreateModeInfo(13, 1920, 1080, false, 50.0f), | 37 output.mode_infos[13] = OutputConfigurator::ModeInfo(1920, 1080, false); |
45 chromeos::test::CreateModeInfo(14, 1920, 1080, false, 40.0f), | 38 output.mode_infos[14] = OutputConfigurator::ModeInfo(1920, 1080, false); |
46 | 39 |
47 // interlace vs non interlace | 40 // Interlaced vs non-interlaced. |
48 chromeos::test::CreateModeInfo(15, 1280, 720, true, 60.0f), | 41 output.mode_infos[15] = OutputConfigurator::ModeInfo(1280, 720, true); |
49 chromeos::test::CreateModeInfo(16, 1280, 720, false, 40.0f), | 42 output.mode_infos[16] = OutputConfigurator::ModeInfo(1280, 720, false); |
50 | 43 |
51 // interlace only | 44 // Interlaced only. |
52 chromeos::test::CreateModeInfo(17, 1024, 768, true, 40.0f), | 45 output.mode_infos[17] = OutputConfigurator::ModeInfo(1024, 768, true); |
53 chromeos::test::CreateModeInfo(18, 1024, 768, true, 60.0f), | 46 output.mode_infos[18] = OutputConfigurator::ModeInfo(1024, 768, true); |
54 | 47 |
55 // mixed | 48 // Mixed. |
56 chromeos::test::CreateModeInfo(19, 1024, 600, true, 60.0f), | 49 output.mode_infos[19] = OutputConfigurator::ModeInfo(1024, 600, true); |
57 chromeos::test::CreateModeInfo(20, 1024, 600, false, 40.0f), | 50 output.mode_infos[20] = OutputConfigurator::ModeInfo(1024, 600, false); |
58 chromeos::test::CreateModeInfo(21, 1024, 600, false, 50.0f), | 51 output.mode_infos[21] = OutputConfigurator::ModeInfo(1024, 600, false); |
59 | 52 |
60 // just one interlaced mode | 53 // Just one interlaced mode. |
61 chromeos::test::CreateModeInfo(22, 640, 480, true, 60.0f), | 54 output.mode_infos[22] = OutputConfigurator::ModeInfo(640, 480, true); |
62 }; | |
63 resources.nmode = arraysize(modes); | |
64 resources.modes = modes; | |
65 | |
66 XRROutputInfo output_info = {0}; | |
67 RRMode output_modes[] = { | |
68 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 | |
69 }; | |
70 output_info.nmode = arraysize(output_modes); | |
71 output_info.modes = output_modes; | |
72 | 55 |
73 std::vector<Resolution> resolutions = | 56 std::vector<Resolution> resolutions = |
74 GetResolutionList(&resources, &output_info); | 57 DisplayChangeObserver::GetResolutionList(output); |
75 EXPECT_EQ(6u, resolutions.size()); | 58 ASSERT_EQ(6u, resolutions.size()); |
76 EXPECT_EQ("1920x1200", resolutions[0].size.ToString()); | 59 EXPECT_EQ("1920x1200", resolutions[0].size.ToString()); |
77 EXPECT_FALSE(resolutions[0].interlaced); | 60 EXPECT_FALSE(resolutions[0].interlaced); |
78 | 61 |
79 EXPECT_EQ("1920x1080", resolutions[1].size.ToString()); | 62 EXPECT_EQ("1920x1080", resolutions[1].size.ToString()); |
80 EXPECT_FALSE(resolutions[1].interlaced); | 63 EXPECT_FALSE(resolutions[1].interlaced); |
81 | 64 |
82 EXPECT_EQ("1280x720", resolutions[2].size.ToString()); | 65 EXPECT_EQ("1280x720", resolutions[2].size.ToString()); |
83 EXPECT_FALSE(resolutions[2].interlaced); | 66 EXPECT_FALSE(resolutions[2].interlaced); |
84 | 67 |
85 EXPECT_EQ("1024x768", resolutions[3].size.ToString()); | 68 EXPECT_EQ("1024x768", resolutions[3].size.ToString()); |
86 EXPECT_TRUE(resolutions[3].interlaced); | 69 EXPECT_TRUE(resolutions[3].interlaced); |
87 | 70 |
88 EXPECT_EQ("1024x600", resolutions[4].size.ToString()); | 71 EXPECT_EQ("1024x600", resolutions[4].size.ToString()); |
89 EXPECT_FALSE(resolutions[4].interlaced); | 72 EXPECT_FALSE(resolutions[4].interlaced); |
90 | 73 |
91 EXPECT_EQ("640x480", resolutions[5].size.ToString()); | 74 EXPECT_EQ("640x480", resolutions[5].size.ToString()); |
92 EXPECT_TRUE(resolutions[5].interlaced); | 75 EXPECT_TRUE(resolutions[5].interlaced); |
93 | 76 |
94 // Empty output shouldn't crash. | 77 // Outputs without any modes shouldn't cause a crash. |
95 RRMode empty_output_modes[] = {}; | 78 output.mode_infos.clear(); |
96 output_info.nmode = 0; | 79 resolutions = DisplayChangeObserver::GetResolutionList(output); |
97 output_info.modes = empty_output_modes; | |
98 | |
99 resolutions = GetResolutionList(&resources, &output_info); | |
100 EXPECT_EQ(0u, resolutions.size()); | 80 EXPECT_EQ(0u, resolutions.size()); |
101 } | 81 } |
102 | 82 |
103 } // namespace internal | 83 } // namespace internal |
104 } // namespace ash | 84 } // namespace ash |
OLD | NEW |