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