| OLD | NEW |
| 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 #include "ui/gfx/geometry/size.h" |
| 10 | 10 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 data[126] = '\x01'; | 145 data[126] = '\x01'; |
| 146 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag)); | 146 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag)); |
| 147 | 147 |
| 148 data.assign(150, '\0'); | 148 data.assign(150, '\0'); |
| 149 data[126] = '\x01'; | 149 data[126] = '\x01'; |
| 150 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag)); | 150 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag)); |
| 151 } | 151 } |
| 152 | 152 |
| 153 TEST(EDIDParserTest, ParseEDID) { | 153 TEST(EDIDParserTest, ParseEDID) { |
| 154 uint16_t manufacturer_id = 0; | 154 uint16_t manufacturer_id = 0; |
| 155 uint16_t product_code = 0; |
| 155 std::string human_readable_name; | 156 std::string human_readable_name; |
| 156 std::vector<uint8_t> edid( | 157 std::vector<uint8_t> edid( |
| 157 kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay)); | 158 kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay)); |
| 158 gfx::Size pixel; | 159 gfx::Size pixel; |
| 159 gfx::Size size; | 160 gfx::Size size; |
| 160 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, | 161 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, &product_code, |
| 161 &human_readable_name, &pixel, &size)); | 162 &human_readable_name, &pixel, &size)); |
| 162 EXPECT_EQ(0x22f0u, manufacturer_id); | 163 EXPECT_EQ(0x22f0u, manufacturer_id); |
| 164 EXPECT_EQ(0x286cu, product_code); |
| 163 EXPECT_EQ("HP ZR30w", human_readable_name); | 165 EXPECT_EQ("HP ZR30w", human_readable_name); |
| 164 EXPECT_EQ("2560x1600", pixel.ToString()); | 166 EXPECT_EQ("2560x1600", pixel.ToString()); |
| 165 EXPECT_EQ("641x400", size.ToString()); | 167 EXPECT_EQ("641x400", size.ToString()); |
| 166 | 168 |
| 167 manufacturer_id = 0; | 169 manufacturer_id = 0; |
| 170 product_code = 0; |
| 168 human_readable_name.clear(); | 171 human_readable_name.clear(); |
| 169 Reset(&pixel, &size); | 172 Reset(&pixel, &size); |
| 170 edid.assign(kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay)); | 173 edid.assign(kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay)); |
| 171 | 174 |
| 172 EXPECT_TRUE( | 175 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, &product_code, |
| 173 ParseOutputDeviceData(edid, &manufacturer_id, nullptr, &pixel, &size)); | 176 nullptr, &pixel, &size)); |
| 174 EXPECT_EQ(0x4ca3u, manufacturer_id); | 177 EXPECT_EQ(0x4ca3u, manufacturer_id); |
| 178 EXPECT_EQ(0x3142u, product_code); |
| 175 EXPECT_EQ("", human_readable_name); | 179 EXPECT_EQ("", human_readable_name); |
| 176 EXPECT_EQ("1280x800", pixel.ToString()); | 180 EXPECT_EQ("1280x800", pixel.ToString()); |
| 177 EXPECT_EQ("261x163", size.ToString()); | 181 EXPECT_EQ("261x163", size.ToString()); |
| 178 | 182 |
| 179 // Internal display doesn't have name. | 183 // Internal display doesn't have name. |
| 180 EXPECT_TRUE(ParseOutputDeviceData(edid, nullptr, &human_readable_name, &pixel, | 184 EXPECT_TRUE(ParseOutputDeviceData(edid, nullptr, nullptr, |
| 181 &size)); | 185 &human_readable_name, &pixel, &size)); |
| 182 EXPECT_TRUE(human_readable_name.empty()); | 186 EXPECT_TRUE(human_readable_name.empty()); |
| 183 | 187 |
| 184 manufacturer_id = 0; | 188 manufacturer_id = 0; |
| 189 product_code = 0; |
| 185 human_readable_name.clear(); | 190 human_readable_name.clear(); |
| 186 Reset(&pixel, &size); | 191 Reset(&pixel, &size); |
| 187 edid.assign(kOverscanDisplay, kOverscanDisplay + charsize(kOverscanDisplay)); | 192 edid.assign(kOverscanDisplay, kOverscanDisplay + charsize(kOverscanDisplay)); |
| 188 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, | 193 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, &product_code, |
| 189 &human_readable_name, &pixel, &size)); | 194 &human_readable_name, &pixel, &size)); |
| 190 EXPECT_EQ(0x4c2du, manufacturer_id); | 195 EXPECT_EQ(0x4c2du, manufacturer_id); |
| 196 EXPECT_EQ(0x08feu, product_code); |
| 191 EXPECT_EQ("SAMSUNG", human_readable_name); | 197 EXPECT_EQ("SAMSUNG", human_readable_name); |
| 192 EXPECT_EQ("1920x1080", pixel.ToString()); | 198 EXPECT_EQ("1920x1080", pixel.ToString()); |
| 193 EXPECT_EQ("160x90", size.ToString()); | 199 EXPECT_EQ("160x90", size.ToString()); |
| 194 } | 200 } |
| 195 | 201 |
| 196 TEST(EDIDParserTest, ParseBrokenEDID) { | 202 TEST(EDIDParserTest, ParseBrokenEDID) { |
| 197 uint16_t manufacturer_id = 0; | 203 uint16_t manufacturer_id = 0; |
| 204 uint16_t product_code = 0; |
| 198 std::string human_readable_name; | 205 std::string human_readable_name; |
| 199 std::vector<uint8_t> edid; | 206 std::vector<uint8_t> edid; |
| 200 | 207 |
| 201 gfx::Size dummy; | 208 gfx::Size dummy; |
| 202 | 209 |
| 203 // length == 0 | 210 // length == 0 |
| 204 EXPECT_FALSE(ParseOutputDeviceData(edid, &manufacturer_id, | 211 EXPECT_FALSE(ParseOutputDeviceData(edid, &manufacturer_id, &product_code, |
| 205 &human_readable_name, &dummy, &dummy)); | 212 &human_readable_name, &dummy, &dummy)); |
| 206 | 213 |
| 207 // name is broken. Copying kNormalDisplay and substitute its name data by | 214 // name is broken. Copying kNormalDisplay and substitute its name data by |
| 208 // some control code. | 215 // some control code. |
| 209 edid.assign(kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay)); | 216 edid.assign(kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay)); |
| 210 | 217 |
| 211 // 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. |
| 212 // Fix here too when the contents of kNormalDisplay is altered. | 219 // Fix here too when the contents of kNormalDisplay is altered. |
| 213 edid[97] = '\x1b'; | 220 edid[97] = '\x1b'; |
| 214 EXPECT_FALSE(ParseOutputDeviceData(edid, &manufacturer_id, | 221 EXPECT_FALSE(ParseOutputDeviceData(edid, &manufacturer_id, nullptr, |
| 215 &human_readable_name, &dummy, &dummy)); | 222 &human_readable_name, &dummy, &dummy)); |
| 216 | 223 |
| 217 // 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. |
| 218 manufacturer_id = 0; | 225 manufacturer_id = 0; |
| 219 EXPECT_TRUE( | 226 product_code = 0; |
| 220 ParseOutputDeviceData(edid, &manufacturer_id, nullptr, &dummy, &dummy)); | 227 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, &product_code, |
| 228 nullptr, &dummy, &dummy)); |
| 221 EXPECT_EQ(0x22f0u, manufacturer_id); | 229 EXPECT_EQ(0x22f0u, manufacturer_id); |
| 230 EXPECT_EQ(0x286cu, product_code); |
| 222 } | 231 } |
| 223 | 232 |
| 224 TEST(EDIDParserTest, GetDisplayId) { | 233 TEST(EDIDParserTest, GetDisplayId) { |
| 225 // 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. |
| 226 int64_t id1 = -1; | 235 int64_t id1 = -1; |
| 227 int64_t id2 = -1; | 236 int64_t id2 = -1; |
| 228 int64_t product_id1 = -1; | 237 int64_t product_id1 = -1; |
| 229 int64_t product_id2 = -1; | 238 int64_t product_id2 = -1; |
| 230 std::vector<uint8_t> edid(kLP2565A, kLP2565A + charsize(kLP2565A)); | 239 std::vector<uint8_t> edid(kLP2565A, kLP2565A + charsize(kLP2565A)); |
| 231 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id1, &product_id1)); | 240 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id1, &product_id1)); |
| 232 edid.assign(kLP2565B, kLP2565B + charsize(kLP2565B)); | 241 edid.assign(kLP2565B, kLP2565B + charsize(kLP2565B)); |
| 233 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id2, &product_id2)); | 242 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id2, &product_id2)); |
| 234 EXPECT_EQ(id1, id2); | 243 EXPECT_EQ(id1, id2); |
| 235 EXPECT_EQ(product_id1, product_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); |
| 236 EXPECT_NE(-1, id1); | 248 EXPECT_NE(-1, id1); |
| 237 EXPECT_NE(-1, product_id1); | 249 EXPECT_NE(-1, product_id1); |
| 238 } | 250 } |
| 239 | 251 |
| 240 TEST(EDIDParserTest, GetDisplayIdFromInternal) { | 252 TEST(EDIDParserTest, GetDisplayIdFromInternal) { |
| 241 int64_t id = -1; | 253 int64_t id = -1; |
| 242 int64_t product_id = -1; | 254 int64_t product_id = -1; |
| 243 std::vector<uint8_t> edid( | 255 std::vector<uint8_t> edid( |
| 244 kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay)); | 256 kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay)); |
| 245 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id, &product_id)); | 257 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id, &product_id)); |
| 246 EXPECT_NE(-1, id); | 258 EXPECT_NE(-1, id); |
| 247 EXPECT_NE(-1, product_id); | 259 EXPECT_NE(-1, product_id); |
| 248 } | 260 } |
| 249 | 261 |
| 250 TEST(EDIDParserTest, GetDisplayIdFailure) { | 262 TEST(EDIDParserTest, GetDisplayIdFailure) { |
| 251 int64_t id = -1; | 263 int64_t id = -1; |
| 252 int64_t product_id = -1; | 264 int64_t product_id = -1; |
| 253 std::vector<uint8_t> edid; | 265 std::vector<uint8_t> edid; |
| 254 EXPECT_FALSE(GetDisplayIdFromEDID(edid, 0, &id, &product_id)); | 266 EXPECT_FALSE(GetDisplayIdFromEDID(edid, 0, &id, &product_id)); |
| 255 EXPECT_EQ(-1, id); | 267 EXPECT_EQ(-1, id); |
| 256 EXPECT_EQ(-1, product_id); | 268 EXPECT_EQ(-1, product_id); |
| 257 } | 269 } |
| 258 | 270 |
| 259 } // namespace ui | 271 } // namespace ui |
| OLD | NEW |