OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/basictypes.h" | |
6 #include "base/memory/scoped_ptr.h" | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 #include "ui/base/x/x11_util.h" | |
9 | |
10 namespace ui { | |
11 | |
12 namespace { | |
13 | |
14 // Returns the number of characters in the string literal but doesn't count its | |
15 // terminator NULL byte. | |
16 #define charsize(str) (arraysize(str) - 1) | |
17 | |
18 // Sample EDID data extracted from real devices. | |
19 const unsigned char kNormalDisplay[] = | |
20 "\x00\xff\xff\xff\xff\xff\xff\x00\x22\xf0\x6c\x28\x01\x01\x01\x01" | |
21 "\x02\x16\x01\x04\xb5\x40\x28\x78\xe2\x8d\x85\xad\x4f\x35\xb1\x25" | |
22 "\x0e\x50\x54\x00\x00\x00\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" | |
23 "\x01\x01\x01\x01\x01\x01\xe2\x68\x00\xa0\xa0\x40\x2e\x60\x30\x20" | |
24 "\x36\x00\x81\x90\x21\x00\x00\x1a\xbc\x1b\x00\xa0\x50\x20\x17\x30" | |
25 "\x30\x20\x36\x00\x81\x90\x21\x00\x00\x1a\x00\x00\x00\xfc\x00\x48" | |
26 "\x50\x20\x5a\x52\x33\x30\x77\x0a\x20\x20\x20\x20\x00\x00\x00\xff" | |
27 "\x00\x43\x4e\x34\x32\x30\x32\x31\x33\x37\x51\x0a\x20\x20\x00\x71"; | |
28 | |
29 const unsigned char kInternalDisplay[] = | |
30 "\x00\xff\xff\xff\xff\xff\xff\x00\x4c\xa3\x42\x31\x00\x00\x00\x00" | |
31 "\x00\x15\x01\x03\x80\x1a\x10\x78\x0a\xd3\xe5\x95\x5c\x60\x90\x27" | |
32 "\x19\x50\x54\x00\x00\x00\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" | |
33 "\x01\x01\x01\x01\x01\x01\x9e\x1b\x00\xa0\x50\x20\x12\x30\x10\x30" | |
34 "\x13\x00\x05\xa3\x10\x00\x00\x19\x00\x00\x00\x0f\x00\x00\x00\x00" | |
35 "\x00\x00\x00\x00\x00\x23\x87\x02\x64\x00\x00\x00\x00\xfe\x00\x53" | |
36 "\x41\x4d\x53\x55\x4e\x47\x0a\x20\x20\x20\x20\x20\x00\x00\x00\xfe" | |
37 "\x00\x31\x32\x31\x41\x54\x31\x31\x2d\x38\x30\x31\x0a\x20\x00\x45"; | |
38 | |
39 const unsigned char kOverscanDisplay[] = | |
40 "\x00\xff\xff\xff\xff\xff\xff\x00\x4c\x2d\xfe\x08\x00\x00\x00\x00" | |
41 "\x29\x15\x01\x03\x80\x10\x09\x78\x0a\xee\x91\xa3\x54\x4c\x99\x26" | |
42 "\x0f\x50\x54\xbd\xef\x80\x71\x4f\x81\xc0\x81\x00\x81\x80\x95\x00" | |
43 "\xa9\xc0\xb3\x00\x01\x01\x02\x3a\x80\x18\x71\x38\x2d\x40\x58\x2c" | |
44 "\x45\x00\xa0\x5a\x00\x00\x00\x1e\x66\x21\x56\xaa\x51\x00\x1e\x30" | |
45 "\x46\x8f\x33\x00\xa0\x5a\x00\x00\x00\x1e\x00\x00\x00\xfd\x00\x18" | |
46 "\x4b\x0f\x51\x17\x00\x0a\x20\x20\x20\x20\x20\x20\x00\x00\x00\xfc" | |
47 "\x00\x53\x41\x4d\x53\x55\x4e\x47\x0a\x20\x20\x20\x20\x20\x01\x1d" | |
48 "\x02\x03\x1f\xf1\x47\x90\x04\x05\x03\x20\x22\x07\x23\x09\x07\x07" | |
49 "\x83\x01\x00\x00\xe2\x00\x0f\x67\x03\x0c\x00\x20\x00\xb8\x2d\x01" | |
50 "\x1d\x80\x18\x71\x1c\x16\x20\x58\x2c\x25\x00\xa0\x5a\x00\x00\x00" | |
51 "\x9e\x01\x1d\x00\x72\x51\xd0\x1e\x20\x6e\x28\x55\x00\xa0\x5a\x00" | |
52 "\x00\x00\x1e\x8c\x0a\xd0\x8a\x20\xe0\x2d\x10\x10\x3e\x96\x00\xa0" | |
53 "\x5a\x00\x00\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" | |
54 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" | |
55 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc6"; | |
56 | |
57 // The EDID info misdetecting overscan once. see crbug.com/226318 | |
58 const unsigned char kMisdetecedDisplay[] = | |
59 "\x00\xff\xff\xff\xff\xff\xff\x00\x10\xac\x64\x40\x4c\x30\x30\x32" | |
60 "\x0c\x15\x01\x03\x80\x40\x28\x78\xea\x8d\x85\xad\x4f\x35\xb1\x25" | |
61 "\x0e\x50\x54\xa5\x4b\x00\x71\x4f\x81\x00\x81\x80\xd1\x00\xa9\x40" | |
62 "\x01\x01\x01\x01\x01\x01\x28\x3c\x80\xa0\x70\xb0\x23\x40\x30\x20" | |
63 "\x36\x00\x81\x91\x21\x00\x00\x1a\x00\x00\x00\xff\x00\x50\x48\x35" | |
64 "\x4e\x59\x31\x33\x4e\x32\x30\x30\x4c\x0a\x00\x00\x00\xfc\x00\x44" | |
65 "\x45\x4c\x4c\x20\x55\x33\x30\x31\x31\x0a\x20\x20\x00\x00\x00\xfd" | |
66 "\x00\x31\x56\x1d\x5e\x12\x00\x0a\x20\x20\x20\x20\x20\x20\x01\x38" | |
67 "\x02\x03\x29\xf1\x50\x90\x05\x04\x03\x02\x07\x16\x01\x06\x11\x12" | |
68 "\x15\x13\x14\x1f\x20\x23\x0d\x7f\x07\x83\x0f\x00\x00\x67\x03\x0c" | |
69 "\x00\x10\x00\x38\x2d\xe3\x05\x03\x01\x02\x3a\x80\x18\x71\x38\x2d" | |
70 "\x40\x58\x2c\x45\x00\x81\x91\x21\x00\x00\x1e\x01\x1d\x80\x18\x71" | |
71 "\x1c\x16\x20\x58\x2c\x25\x00\x81\x91\x21\x00\x00\x9e\x01\x1d\x00" | |
72 "\x72\x51\xd0\x1e\x20\x6e\x28\x55\x00\x81\x91\x21\x00\x00\x1e\x8c" | |
73 "\x0a\xd0\x8a\x20\xe0\x2d\x10\x10\x3e\x96\x00\x81\x91\x21\x00\x00" | |
74 "\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x94"; | |
75 | |
76 } | |
77 | |
78 TEST(X11UtilTest, ParseEDID) { | |
79 uint16 manufacturer_id = 0; | |
80 uint16 product_code = 0; | |
81 std::string human_readable_name; | |
82 EXPECT_TRUE(ParseOutputDeviceData( | |
83 kNormalDisplay, charsize(kNormalDisplay), | |
84 &manufacturer_id, &product_code, &human_readable_name)); | |
85 EXPECT_EQ(0x22f0u, manufacturer_id); | |
86 EXPECT_EQ(0x286cu, product_code); | |
87 EXPECT_EQ("HP ZR30w", human_readable_name); | |
88 | |
89 manufacturer_id = 0; | |
90 product_code = 0; | |
91 human_readable_name.clear(); | |
92 EXPECT_TRUE(ParseOutputDeviceData( | |
93 kInternalDisplay, charsize(kInternalDisplay), | |
94 &manufacturer_id, &product_code, NULL)); | |
95 EXPECT_EQ(0x4ca3u, manufacturer_id); | |
96 EXPECT_EQ(0x3142u, product_code); | |
97 EXPECT_EQ("", human_readable_name); | |
98 | |
99 // Internal display doesn't have name. | |
100 EXPECT_FALSE(ParseOutputDeviceData( | |
101 kInternalDisplay, charsize(kInternalDisplay), | |
102 NULL, NULL, &human_readable_name)); | |
103 | |
104 manufacturer_id = 0; | |
105 product_code = 0; | |
106 human_readable_name.clear(); | |
107 EXPECT_TRUE(ParseOutputDeviceData( | |
108 kOverscanDisplay, charsize(kOverscanDisplay), | |
109 &manufacturer_id, &product_code, &human_readable_name)); | |
110 EXPECT_EQ(0x4c2du, manufacturer_id); | |
111 EXPECT_EQ(0x08feu, product_code); | |
112 EXPECT_EQ("SAMSUNG", human_readable_name); | |
113 } | |
114 | |
115 TEST(X11UtilTest, ParseBrokenEDID) { | |
116 uint16 manufacturer_id = 0; | |
117 uint16 product_code = 0; | |
118 std::string human_readable_name; | |
119 | |
120 // length == 0 | |
121 EXPECT_FALSE(ParseOutputDeviceData( | |
122 kNormalDisplay, 0, | |
123 &manufacturer_id, &product_code, &human_readable_name)); | |
124 | |
125 // name is broken. Copying kNormalDisplay and substitute its name data by | |
126 // some control code. | |
127 std::string display_data( | |
128 reinterpret_cast<const char*>(kNormalDisplay), charsize(kNormalDisplay)); | |
129 | |
130 // display's name data is embedded in byte 95-107 in this specific example. | |
131 // Fix here too when the contents of kNormalDisplay is altered. | |
132 display_data[97] = '\x1b'; | |
133 EXPECT_FALSE(ParseOutputDeviceData( | |
134 reinterpret_cast<const unsigned char*>(display_data.data()), | |
135 display_data.size(), | |
136 &manufacturer_id, &product_code, &human_readable_name)); | |
137 | |
138 // If |human_readable_name| isn't specified, it skips parsing the name. | |
139 manufacturer_id = 0; | |
140 product_code = 0; | |
141 EXPECT_TRUE(ParseOutputDeviceData( | |
142 reinterpret_cast<const unsigned char*>(display_data.data()), | |
143 display_data.size(), | |
144 &manufacturer_id, &product_code, NULL)); | |
145 EXPECT_EQ(0x22f0u, manufacturer_id); | |
146 EXPECT_EQ(0x286cu, product_code); | |
147 } | |
148 | |
149 TEST(X11UtilTest, ParseOverscanFlag) { | |
150 bool flag = false; | |
151 EXPECT_FALSE(ParseOutputOverscanFlag( | |
152 kNormalDisplay, charsize(kNormalDisplay), &flag)); | |
153 | |
154 flag = false; | |
155 EXPECT_FALSE(ParseOutputOverscanFlag( | |
156 kInternalDisplay, charsize(kInternalDisplay), &flag)); | |
157 | |
158 flag = false; | |
159 EXPECT_TRUE(ParseOutputOverscanFlag( | |
160 kOverscanDisplay, charsize(kOverscanDisplay), &flag)); | |
161 EXPECT_TRUE(flag); | |
162 | |
163 flag = false; | |
164 EXPECT_FALSE(ParseOutputOverscanFlag( | |
165 kMisdetecedDisplay, charsize(kMisdetecedDisplay), &flag)); | |
166 | |
167 flag = false; | |
168 // Copy |kOverscanDisplay| and set flags to false in it. The overscan flags | |
169 // are embedded at byte 150 in this specific example. Fix here too when the | |
170 // contents of kOverscanDisplay is altered. | |
171 std::string display_data(reinterpret_cast<const char*>(kOverscanDisplay), | |
172 charsize(kOverscanDisplay)); | |
173 display_data[150] = '\0'; | |
174 EXPECT_TRUE(ParseOutputOverscanFlag( | |
175 reinterpret_cast<const unsigned char*>(display_data.data()), | |
176 display_data.size(), &flag)); | |
177 EXPECT_FALSE(flag); | |
178 } | |
179 | |
180 TEST(X11UtilTest, ParseBrokenOverscanData) { | |
181 // Do not fill valid data here because it anyway fails to parse the data. | |
182 scoped_ptr<unsigned char[]> data(new unsigned char[126]); | |
183 bool flag = false; | |
184 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 0, &flag)); | |
185 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 126, &flag)); | |
186 | |
187 // extending data because ParseOutputOverscanFlag() will access the data. | |
188 data.reset(new unsigned char[150]); | |
189 // The number of CEA extensions is stored at byte 126. | |
190 data[126] = '\x01'; | |
191 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 128, &flag)); | |
192 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 150, &flag)); | |
193 } | |
194 | |
195 } | |
OLD | NEW |