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