Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: ui/display/util/edid_parser_unittest.cc

Issue 1285183008: Ozone integration. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add missing license header Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/display/util/edid_parser.cc ('k') | ui/events/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/util/edid_parser.h" 5 #include "ui/display/util/edid_parser.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/geometry/size.h"
9 10
10 namespace ui { 11 namespace ui {
11 12
12 namespace { 13 namespace {
13 14
14 // Returns the number of characters in the string literal but doesn't count its 15 // Returns the number of characters in the string literal but doesn't count its
15 // terminator NULL byte. 16 // terminator NULL byte.
16 #define charsize(str) (arraysize(str) - 1) 17 #define charsize(str) (arraysize(str) - 1)
17 18
18 // Sample EDID data extracted from real devices. 19 // Sample EDID data extracted from real devices.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 const unsigned char kLP2565B[] = 87 const unsigned char kLP2565B[] =
87 "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x22\xF0\x75\x26\x01\x01\x01\x01" 88 "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x22\xF0\x75\x26\x01\x01\x01\x01"
88 "\x02\x12\x01\x03\x6E\x34\x21\x78\xEE\xEF\x95\xA3\x54\x4C\x9B\x26" 89 "\x02\x12\x01\x03\x6E\x34\x21\x78\xEE\xEF\x95\xA3\x54\x4C\x9B\x26"
89 "\x0F\x50\x54\xA5\x6B\x80\x81\x40\x71\x00\xA9\x00\xA9\x40\xA9\x4F" 90 "\x0F\x50\x54\xA5\x6B\x80\x81\x40\x71\x00\xA9\x00\xA9\x40\xA9\x4F"
90 "\xB3\x00\xD1\xC0\xD1\x00\x28\x3C\x80\xA0\x70\xB0\x23\x40\x30\x20" 91 "\xB3\x00\xD1\xC0\xD1\x00\x28\x3C\x80\xA0\x70\xB0\x23\x40\x30\x20"
91 "\x36\x00\x07\x44\x21\x00\x00\x1A\x00\x00\x00\xFD\x00\x30\x55\x1E" 92 "\x36\x00\x07\x44\x21\x00\x00\x1A\x00\x00\x00\xFD\x00\x30\x55\x1E"
92 "\x5E\x15\x00\x0A\x20\x20\x20\x20\x20\x20\x00\x00\x00\xFC\x00\x48" 93 "\x5E\x15\x00\x0A\x20\x20\x20\x20\x20\x20\x00\x00\x00\xFC\x00\x48"
93 "\x50\x20\x4C\x50\x32\x34\x36\x35\x0A\x20\x20\x20\x00\x00\x00\xFF" 94 "\x50\x20\x4C\x50\x32\x34\x36\x35\x0A\x20\x20\x20\x00\x00\x00\xFF"
94 "\x00\x43\x4E\x4B\x38\x30\x32\x30\x34\x48\x4D\x0A\x20\x20\x00\x45"; 95 "\x00\x43\x4E\x4B\x38\x30\x32\x30\x34\x48\x4D\x0A\x20\x20\x00\x45";
95 96
97 void Reset(gfx::Size* pixel, gfx::Size* size) {
98 pixel->SetSize(0, 0);
99 size->SetSize(0, 0);
100 }
101
96 } // namespace 102 } // namespace
97 103
98 TEST(EDIDParserTest, ParseOverscanFlag) { 104 TEST(EDIDParserTest, ParseOverscanFlag) {
99 bool flag = false; 105 bool flag = false;
100 std::vector<uint8_t> edid( 106 std::vector<uint8_t> edid(
101 kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay)); 107 kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay));
102 EXPECT_FALSE(ParseOutputOverscanFlag(edid, &flag)); 108 EXPECT_FALSE(ParseOutputOverscanFlag(edid, &flag));
103 109
104 flag = false; 110 flag = false;
105 edid.assign(kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay)); 111 edid.assign(kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 data[126] = '\x01'; 145 data[126] = '\x01';
140 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag)); 146 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag));
141 147
142 data.assign(150, '\0'); 148 data.assign(150, '\0');
143 data[126] = '\x01'; 149 data[126] = '\x01';
144 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag)); 150 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag));
145 } 151 }
146 152
147 TEST(EDIDParserTest, ParseEDID) { 153 TEST(EDIDParserTest, ParseEDID) {
148 uint16_t manufacturer_id = 0; 154 uint16_t manufacturer_id = 0;
155 uint16_t product_code = 0;
149 std::string human_readable_name; 156 std::string human_readable_name;
150 std::vector<uint8_t> edid( 157 std::vector<uint8_t> edid(
151 kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay)); 158 kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay));
152 EXPECT_TRUE(ParseOutputDeviceData( 159 gfx::Size pixel;
153 edid, &manufacturer_id, &human_readable_name)); 160 gfx::Size size;
161 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, &product_code,
162 &human_readable_name, &pixel, &size));
154 EXPECT_EQ(0x22f0u, manufacturer_id); 163 EXPECT_EQ(0x22f0u, manufacturer_id);
164 EXPECT_EQ(0x286cu, product_code);
155 EXPECT_EQ("HP ZR30w", human_readable_name); 165 EXPECT_EQ("HP ZR30w", human_readable_name);
166 EXPECT_EQ("2560x1600", pixel.ToString());
167 EXPECT_EQ("641x400", size.ToString());
156 168
157 manufacturer_id = 0; 169 manufacturer_id = 0;
170 product_code = 0;
158 human_readable_name.clear(); 171 human_readable_name.clear();
172 Reset(&pixel, &size);
159 edid.assign(kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay)); 173 edid.assign(kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay));
160 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, NULL)); 174
175 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, &product_code,
176 nullptr, &pixel, &size));
161 EXPECT_EQ(0x4ca3u, manufacturer_id); 177 EXPECT_EQ(0x4ca3u, manufacturer_id);
178 EXPECT_EQ(0x3142u, product_code);
162 EXPECT_EQ("", human_readable_name); 179 EXPECT_EQ("", human_readable_name);
180 EXPECT_EQ("1280x800", pixel.ToString());
181 EXPECT_EQ("261x163", size.ToString());
163 182
164 // Internal display doesn't have name. 183 // Internal display doesn't have name.
165 EXPECT_TRUE(ParseOutputDeviceData(edid, NULL, &human_readable_name)); 184 EXPECT_TRUE(ParseOutputDeviceData(edid, nullptr, nullptr,
185 &human_readable_name, &pixel, &size));
166 EXPECT_TRUE(human_readable_name.empty()); 186 EXPECT_TRUE(human_readable_name.empty());
167 187
168 manufacturer_id = 0; 188 manufacturer_id = 0;
189 product_code = 0;
169 human_readable_name.clear(); 190 human_readable_name.clear();
191 Reset(&pixel, &size);
170 edid.assign(kOverscanDisplay, kOverscanDisplay + charsize(kOverscanDisplay)); 192 edid.assign(kOverscanDisplay, kOverscanDisplay + charsize(kOverscanDisplay));
171 EXPECT_TRUE(ParseOutputDeviceData( 193 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, &product_code,
172 edid, &manufacturer_id, &human_readable_name)); 194 &human_readable_name, &pixel, &size));
173 EXPECT_EQ(0x4c2du, manufacturer_id); 195 EXPECT_EQ(0x4c2du, manufacturer_id);
196 EXPECT_EQ(0x08feu, product_code);
174 EXPECT_EQ("SAMSUNG", human_readable_name); 197 EXPECT_EQ("SAMSUNG", human_readable_name);
198 EXPECT_EQ("1920x1080", pixel.ToString());
199 EXPECT_EQ("160x90", size.ToString());
175 } 200 }
176 201
177 TEST(EDIDParserTest, ParseBrokenEDID) { 202 TEST(EDIDParserTest, ParseBrokenEDID) {
178 uint16_t manufacturer_id = 0; 203 uint16_t manufacturer_id = 0;
204 uint16_t product_code = 0;
179 std::string human_readable_name; 205 std::string human_readable_name;
180 std::vector<uint8_t> edid; 206 std::vector<uint8_t> edid;
181 207
208 gfx::Size dummy;
209
182 // length == 0 210 // length == 0
183 EXPECT_FALSE(ParseOutputDeviceData( 211 EXPECT_FALSE(ParseOutputDeviceData(edid, &manufacturer_id, &product_code,
184 edid, &manufacturer_id, &human_readable_name)); 212 &human_readable_name, &dummy, &dummy));
185 213
186 // name is broken. Copying kNormalDisplay and substitute its name data by 214 // name is broken. Copying kNormalDisplay and substitute its name data by
187 // some control code. 215 // some control code.
188 edid.assign(kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay)); 216 edid.assign(kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay));
189 217
190 // display's name data is embedded in byte 95-107 in this specific example. 218 // display's name data is embedded in byte 95-107 in this specific example.
191 // Fix here too when the contents of kNormalDisplay is altered. 219 // Fix here too when the contents of kNormalDisplay is altered.
192 edid[97] = '\x1b'; 220 edid[97] = '\x1b';
193 EXPECT_FALSE(ParseOutputDeviceData( 221 EXPECT_FALSE(ParseOutputDeviceData(edid, &manufacturer_id, nullptr,
194 edid, &manufacturer_id, &human_readable_name)); 222 &human_readable_name, &dummy, &dummy));
195 223
196 // If |human_readable_name| isn't specified, it skips parsing the name. 224 // If |human_readable_name| isn't specified, it skips parsing the name.
197 manufacturer_id = 0; 225 manufacturer_id = 0;
198 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, NULL)); 226 product_code = 0;
227 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, &product_code,
228 nullptr, &dummy, &dummy));
199 EXPECT_EQ(0x22f0u, manufacturer_id); 229 EXPECT_EQ(0x22f0u, manufacturer_id);
230 EXPECT_EQ(0x286cu, product_code);
200 } 231 }
201 232
202 TEST(EDIDParserTest, GetDisplayId) { 233 TEST(EDIDParserTest, GetDisplayId) {
203 // EDID of kLP2565A and B are slightly different but actually the same device. 234 // EDID of kLP2565A and B are slightly different but actually the same device.
204 int64_t id1 = -1; 235 int64_t id1 = -1;
205 int64_t id2 = -1; 236 int64_t id2 = -1;
237 int64_t product_id1 = -1;
238 int64_t product_id2 = -1;
206 std::vector<uint8_t> edid(kLP2565A, kLP2565A + charsize(kLP2565A)); 239 std::vector<uint8_t> edid(kLP2565A, kLP2565A + charsize(kLP2565A));
207 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id1)); 240 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id1, &product_id1));
208 edid.assign(kLP2565B, kLP2565B + charsize(kLP2565B)); 241 edid.assign(kLP2565B, kLP2565B + charsize(kLP2565B));
209 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id2)); 242 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id2, &product_id2));
210 EXPECT_EQ(id1, id2); 243 EXPECT_EQ(id1, id2);
244 // The product code in the two EDIDs varies.
245 EXPECT_NE(product_id1, product_id2);
246 EXPECT_EQ(0x22f02676, product_id1);
247 EXPECT_EQ(0x22f02675, product_id2);
211 EXPECT_NE(-1, id1); 248 EXPECT_NE(-1, id1);
249 EXPECT_NE(-1, product_id1);
212 } 250 }
213 251
214 TEST(EDIDParserTest, GetDisplayIdFromInternal) { 252 TEST(EDIDParserTest, GetDisplayIdFromInternal) {
215 int64_t id = -1; 253 int64_t id = -1;
254 int64_t product_id = -1;
216 std::vector<uint8_t> edid( 255 std::vector<uint8_t> edid(
217 kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay)); 256 kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay));
218 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id)); 257 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id, &product_id));
219 EXPECT_NE(-1, id); 258 EXPECT_NE(-1, id);
259 EXPECT_NE(-1, product_id);
220 } 260 }
221 261
222 TEST(EDIDParserTest, GetDisplayIdFailure) { 262 TEST(EDIDParserTest, GetDisplayIdFailure) {
223 int64_t id = -1; 263 int64_t id = -1;
264 int64_t product_id = -1;
224 std::vector<uint8_t> edid; 265 std::vector<uint8_t> edid;
225 EXPECT_FALSE(GetDisplayIdFromEDID(edid, 0, &id)); 266 EXPECT_FALSE(GetDisplayIdFromEDID(edid, 0, &id, &product_id));
226 EXPECT_EQ(-1, id); 267 EXPECT_EQ(-1, id);
268 EXPECT_EQ(-1, product_id);
227 } 269 }
228 270
229 } // namespace ui 271 } // namespace ui
OLDNEW
« no previous file with comments | « ui/display/util/edid_parser.cc ('k') | ui/events/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698