| 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 | 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 Loading... |
| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; |
| 149 std::string human_readable_name; | 155 std::string human_readable_name; |
| 150 std::vector<uint8_t> edid( | 156 std::vector<uint8_t> edid( |
| 151 kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay)); | 157 kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay)); |
| 152 EXPECT_TRUE(ParseOutputDeviceData( | 158 gfx::Size pixel; |
| 153 edid, &manufacturer_id, &human_readable_name)); | 159 gfx::Size size; |
| 160 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, |
| 161 &human_readable_name, &pixel, &size)); |
| 154 EXPECT_EQ(0x22f0u, manufacturer_id); | 162 EXPECT_EQ(0x22f0u, manufacturer_id); |
| 155 EXPECT_EQ("HP ZR30w", human_readable_name); | 163 EXPECT_EQ("HP ZR30w", human_readable_name); |
| 164 EXPECT_EQ("2560x1600", pixel.ToString()); |
| 165 EXPECT_EQ("641x400", size.ToString()); |
| 156 | 166 |
| 157 manufacturer_id = 0; | 167 manufacturer_id = 0; |
| 158 human_readable_name.clear(); | 168 human_readable_name.clear(); |
| 169 Reset(&pixel, &size); |
| 159 edid.assign(kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay)); | 170 edid.assign(kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay)); |
| 160 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, NULL)); | 171 |
| 172 EXPECT_TRUE( |
| 173 ParseOutputDeviceData(edid, &manufacturer_id, nullptr, &pixel, &size)); |
| 161 EXPECT_EQ(0x4ca3u, manufacturer_id); | 174 EXPECT_EQ(0x4ca3u, manufacturer_id); |
| 162 EXPECT_EQ("", human_readable_name); | 175 EXPECT_EQ("", human_readable_name); |
| 176 EXPECT_EQ("1280x800", pixel.ToString()); |
| 177 EXPECT_EQ("261x163", size.ToString()); |
| 163 | 178 |
| 164 // Internal display doesn't have name. | 179 // Internal display doesn't have name. |
| 165 EXPECT_TRUE(ParseOutputDeviceData(edid, NULL, &human_readable_name)); | 180 EXPECT_TRUE(ParseOutputDeviceData(edid, nullptr, &human_readable_name, &pixel, |
| 181 &size)); |
| 166 EXPECT_TRUE(human_readable_name.empty()); | 182 EXPECT_TRUE(human_readable_name.empty()); |
| 167 | 183 |
| 168 manufacturer_id = 0; | 184 manufacturer_id = 0; |
| 169 human_readable_name.clear(); | 185 human_readable_name.clear(); |
| 186 Reset(&pixel, &size); |
| 170 edid.assign(kOverscanDisplay, kOverscanDisplay + charsize(kOverscanDisplay)); | 187 edid.assign(kOverscanDisplay, kOverscanDisplay + charsize(kOverscanDisplay)); |
| 171 EXPECT_TRUE(ParseOutputDeviceData( | 188 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, |
| 172 edid, &manufacturer_id, &human_readable_name)); | 189 &human_readable_name, &pixel, &size)); |
| 173 EXPECT_EQ(0x4c2du, manufacturer_id); | 190 EXPECT_EQ(0x4c2du, manufacturer_id); |
| 174 EXPECT_EQ("SAMSUNG", human_readable_name); | 191 EXPECT_EQ("SAMSUNG", human_readable_name); |
| 192 EXPECT_EQ("1920x1080", pixel.ToString()); |
| 193 EXPECT_EQ("160x90", size.ToString()); |
| 175 } | 194 } |
| 176 | 195 |
| 177 TEST(EDIDParserTest, ParseBrokenEDID) { | 196 TEST(EDIDParserTest, ParseBrokenEDID) { |
| 178 uint16_t manufacturer_id = 0; | 197 uint16_t manufacturer_id = 0; |
| 179 std::string human_readable_name; | 198 std::string human_readable_name; |
| 180 std::vector<uint8_t> edid; | 199 std::vector<uint8_t> edid; |
| 181 | 200 |
| 201 gfx::Size dummy; |
| 202 |
| 182 // length == 0 | 203 // length == 0 |
| 183 EXPECT_FALSE(ParseOutputDeviceData( | 204 EXPECT_FALSE(ParseOutputDeviceData(edid, &manufacturer_id, |
| 184 edid, &manufacturer_id, &human_readable_name)); | 205 &human_readable_name, &dummy, &dummy)); |
| 185 | 206 |
| 186 // name is broken. Copying kNormalDisplay and substitute its name data by | 207 // name is broken. Copying kNormalDisplay and substitute its name data by |
| 187 // some control code. | 208 // some control code. |
| 188 edid.assign(kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay)); | 209 edid.assign(kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay)); |
| 189 | 210 |
| 190 // display's name data is embedded in byte 95-107 in this specific example. | 211 // 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. | 212 // Fix here too when the contents of kNormalDisplay is altered. |
| 192 edid[97] = '\x1b'; | 213 edid[97] = '\x1b'; |
| 193 EXPECT_FALSE(ParseOutputDeviceData( | 214 EXPECT_FALSE(ParseOutputDeviceData(edid, &manufacturer_id, |
| 194 edid, &manufacturer_id, &human_readable_name)); | 215 &human_readable_name, &dummy, &dummy)); |
| 195 | 216 |
| 196 // If |human_readable_name| isn't specified, it skips parsing the name. | 217 // If |human_readable_name| isn't specified, it skips parsing the name. |
| 197 manufacturer_id = 0; | 218 manufacturer_id = 0; |
| 198 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, NULL)); | 219 EXPECT_TRUE( |
| 220 ParseOutputDeviceData(edid, &manufacturer_id, nullptr, &dummy, &dummy)); |
| 199 EXPECT_EQ(0x22f0u, manufacturer_id); | 221 EXPECT_EQ(0x22f0u, manufacturer_id); |
| 200 } | 222 } |
| 201 | 223 |
| 202 TEST(EDIDParserTest, GetDisplayId) { | 224 TEST(EDIDParserTest, GetDisplayId) { |
| 203 // EDID of kLP2565A and B are slightly different but actually the same device. | 225 // EDID of kLP2565A and B are slightly different but actually the same device. |
| 204 int64_t id1 = -1; | 226 int64_t id1 = -1; |
| 205 int64_t id2 = -1; | 227 int64_t id2 = -1; |
| 206 std::vector<uint8_t> edid(kLP2565A, kLP2565A + charsize(kLP2565A)); | 228 std::vector<uint8_t> edid(kLP2565A, kLP2565A + charsize(kLP2565A)); |
| 207 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id1)); | 229 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id1)); |
| 208 edid.assign(kLP2565B, kLP2565B + charsize(kLP2565B)); | 230 edid.assign(kLP2565B, kLP2565B + charsize(kLP2565B)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 220 } | 242 } |
| 221 | 243 |
| 222 TEST(EDIDParserTest, GetDisplayIdFailure) { | 244 TEST(EDIDParserTest, GetDisplayIdFailure) { |
| 223 int64_t id = -1; | 245 int64_t id = -1; |
| 224 std::vector<uint8_t> edid; | 246 std::vector<uint8_t> edid; |
| 225 EXPECT_FALSE(GetDisplayIdFromEDID(edid, 0, &id)); | 247 EXPECT_FALSE(GetDisplayIdFromEDID(edid, 0, &id)); |
| 226 EXPECT_EQ(-1, id); | 248 EXPECT_EQ(-1, id); |
| 227 } | 249 } |
| 228 | 250 |
| 229 } // namespace ui | 251 } // namespace ui |
| OLD | NEW |