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

Side by Side Diff: device/usb/webusb_descriptors_unittest.cc

Issue 1256113006: Add utilities to parse WebUSB device descriptors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "device/usb/webusb_descriptors.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7
8 namespace device {
9
10 namespace {
11
12 const uint8_t kExampleBosDescriptor[] = {
13 // BOS descriptor.
14 0x05, 0x0F, 0x4C, 0x00, 0x03,
15
16 // Container ID descriptor.
17 0x14, 0x10, 0x04, 0x00, 0x2A, 0xF9, 0xF6, 0xC2, 0x98, 0x10, 0x2B, 0x49,
18 0x8E, 0x64, 0xFF, 0x01, 0x0C, 0x7F, 0x94, 0xE1,
19
20 // WebUSB Platform Capability descriptor.
21 0x17, 0x10, 0x05, 0x00, 0x38, 0xB6, 0x08, 0x34, 0xA9, 0x09, 0xA0, 0x47,
22 0x8B, 0xFD, 0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65, 0x00, 0x01, 0x42,
23
24 // Microsoft OS 2.0 Platform Capability descriptor.
25 0x1C, 0x10, 0x05, 0x00, 0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C,
26 0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F, 0x00, 0x00, 0x03, 0x06,
27 0x00, 0x00, 0x01, 0x00};
28
29 const uint8_t kExampleDescriptorSet[] = {
30 // Descriptor set header.
31 0x04, 0x00, 0x9E, 0x00,
32
33 // URL descriptor: https://example.com:80
34 0x18, 0x03, 'h', 't', 't', 'p', 's', ':', '/', '/', 'e', 'x', 'a', 'm', 'p',
35 'l', 'e', '.', 'c', 'o', 'm', ':', '8', '0',
36
37 // Configuration subset header. {
38 0x05, 0x01, 0x01, 0x6A, 0x00,
39
40 // URL descriptor: https://example.com:81
41 0x18, 0x03, 'h', 't', 't', 'p', 's', ':', '/', '/', 'e', 'x', 'a', 'm', 'p',
42 'l', 'e', '.', 'c', 'o', 'm', ':', '8', '1',
43
44 // Function subset header. {
45 0x05, 0x02, 0x01, 0x35, 0x00,
46
47 // URL descriptor: https://example.com:82
48 0x18, 0x03, 'h', 't', 't', 'p', 's', ':', '/', '/', 'e', 'x', 'a', 'm', 'p',
49 'l', 'e', '.', 'c', 'o', 'm', ':', '8', '2',
50
51 // URL descriptor: https://example.com:83
52 0x18, 0x03, 'h', 't', 't', 'p', 's', ':', '/', '/', 'e', 'x', 'a', 'm', 'p',
53 'l', 'e', '.', 'c', 'o', 'm', ':', '8', '3',
54
55 // }
56 // URL descriptor: https://example.com:84
57 0x18, 0x03, 'h', 't', 't', 'p', 's', ':', '/', '/', 'e', 'x', 'a', 'm', 'p',
58 'l', 'e', '.', 'c', 'o', 'm', ':', '8', '4',
59
60 // }
61 // URL descriptor: https://example.com:85
62 0x18, 0x03, 'h', 't', 't', 'p', 's', ':', '/', '/', 'e', 'x', 'a', 'm', 'p',
63 'l', 'e', '.', 'c', 'o', 'm', ':', '8', '5',
64 };
65
66 const uint8_t kExampleUrlDescriptor[] = {
67 0x18, 0x03, 'h', 't', 't', 'p', 's', ':', '/', '/', 'e', 'x',
68 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', ':', '8', '0'};
69
70 class WebUsbDescriptorsTest : public ::testing::Test {};
71
72 TEST_F(WebUsbDescriptorsTest, PlatformCapabilityDescriptor) {
73 WebUsbPlatformCapabilityDescriptor descriptor;
74
75 ASSERT_TRUE(descriptor.ParseFromBosDescriptor(std::vector<uint8_t>(
76 kExampleBosDescriptor,
77 kExampleBosDescriptor + sizeof(kExampleBosDescriptor))));
78 EXPECT_EQ(0x0100, descriptor.version);
79 EXPECT_EQ(0x42, descriptor.vendor_code);
80 }
81
82 TEST_F(WebUsbDescriptorsTest, ShortBosDescriptorHeader) {
83 // This BOS descriptor is just too short.
84 static const uint8_t kBuffer[] = {0x03, 0x0F, 0x03};
85
86 WebUsbPlatformCapabilityDescriptor descriptor;
87 ASSERT_FALSE(descriptor.ParseFromBosDescriptor(
88 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
89 }
90
91 TEST_F(WebUsbDescriptorsTest, LongBosDescriptorHeader) {
92 // BOS descriptor's bLength is too large.
93 static const uint8_t kBuffer[] = {0x06, 0x0F, 0x05, 0x00, 0x01};
94
95 WebUsbPlatformCapabilityDescriptor descriptor;
96 ASSERT_FALSE(descriptor.ParseFromBosDescriptor(
97 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
98 }
99
100 TEST_F(WebUsbDescriptorsTest, InvalidBosDescriptor) {
101 WebUsbPlatformCapabilityDescriptor descriptor;
102 ASSERT_FALSE(descriptor.ParseFromBosDescriptor(std::vector<uint8_t>(
103 kExampleUrlDescriptor,
104 kExampleUrlDescriptor + sizeof(kExampleUrlDescriptor))));
105 }
106
107 TEST_F(WebUsbDescriptorsTest, ShortBosDescriptor) {
108 // wTotalLength is less than bLength. bNumDeviceCaps == 1 to expose buffer
109 // length checking bugs.
110 static const uint8_t kBuffer[] = {0x05, 0x0F, 0x04, 0x00, 0x01};
111
112 WebUsbPlatformCapabilityDescriptor descriptor;
113 ASSERT_FALSE(descriptor.ParseFromBosDescriptor(
114 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
115 }
116
117 TEST_F(WebUsbDescriptorsTest, LongBosDescriptor) {
118 // wTotalLength is too large. bNumDeviceCaps == 1 to expose buffer
119 // length checking bugs.
120 static const uint8_t kBuffer[] = {0x05, 0x0F, 0x06, 0x00, 0x01};
121
122 WebUsbPlatformCapabilityDescriptor descriptor;
123 ASSERT_FALSE(descriptor.ParseFromBosDescriptor(
124 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
125 }
126
127 TEST_F(WebUsbDescriptorsTest, UnexpectedlyEmptyBosDescriptor) {
128 // bNumDeviceCaps == 1 but there are no actual descriptors.
129 static const uint8_t kBuffer[] = {0x05, 0x0F, 0x05, 0x00, 0x01};
130 WebUsbPlatformCapabilityDescriptor descriptor;
131 ASSERT_FALSE(descriptor.ParseFromBosDescriptor(
132 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
133 }
134
135 TEST_F(WebUsbDescriptorsTest, ShortCapabilityDescriptor) {
136 // The single capability descriptor in the BOS descriptor is too short.
137 static const uint8_t kBuffer[] = {0x05, 0x0F, 0x06, 0x00, 0x01, 0x02, 0x10};
138 WebUsbPlatformCapabilityDescriptor descriptor;
139 ASSERT_FALSE(descriptor.ParseFromBosDescriptor(
140 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
141 }
142
143 TEST_F(WebUsbDescriptorsTest, LongCapabilityDescriptor) {
144 // The bLength on a capability descriptor in the BOS descriptor is longer than
145 // the remaining space defined by wTotalLength.
146 static const uint8_t kBuffer[] = {0x05, 0x0F, 0x08, 0x00,
147 0x01, 0x04, 0x10, 0x05};
148 WebUsbPlatformCapabilityDescriptor descriptor;
149 ASSERT_FALSE(descriptor.ParseFromBosDescriptor(
150 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
151 }
152
153 TEST_F(WebUsbDescriptorsTest, NotACapabilityDescriptor) {
154 // There is something other than a device capability descriptor in the BOS
155 // descriptor.
156 static const uint8_t kBuffer[] = {0x05, 0x0F, 0x08, 0x00,
157 0x01, 0x03, 0x0F, 0x05};
158 WebUsbPlatformCapabilityDescriptor descriptor;
159 ASSERT_FALSE(descriptor.ParseFromBosDescriptor(
160 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
161 }
162
163 TEST_F(WebUsbDescriptorsTest, NoPlatformCapabilityDescriptor) {
164 // The BOS descriptor only contains a Container ID descriptor.
165 static const uint8_t kBuffer[] = {0x05, 0x0F, 0x19, 0x00, 0x01, 0x14, 0x10,
166 0x04, 0x00, 0x2A, 0xF9, 0xF6, 0xC2, 0x98,
167 0x10, 0x2B, 0x49, 0x8E, 0x64, 0xFF, 0x01,
168 0x0C, 0x7F, 0x94, 0xE1};
169 WebUsbPlatformCapabilityDescriptor descriptor;
170 ASSERT_FALSE(descriptor.ParseFromBosDescriptor(
171 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
172 }
173
174 TEST_F(WebUsbDescriptorsTest, ShortPlatformCapabilityDescriptor) {
175 // The platform capability descriptor is too short to contain a UUID.
176 static const uint8_t kBuffer[] = {
177 0x05, 0x0F, 0x18, 0x00, 0x01, 0x13, 0x10, 0x05, 0x00, 0x2A, 0xF9, 0xF6,
178 0xC2, 0x98, 0x10, 0x2B, 0x49, 0x8E, 0x64, 0xFF, 0x01, 0x0C, 0x7F, 0x94};
179 WebUsbPlatformCapabilityDescriptor descriptor;
180 ASSERT_FALSE(descriptor.ParseFromBosDescriptor(
181 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
182 }
183
184 TEST_F(WebUsbDescriptorsTest, NoWebUsbCapabilityDescriptor) {
185 // The BOS descriptor only contains another kind of platform capability
186 // descriptor.
187 static const uint8_t kBuffer[] = {0x05, 0x0F, 0x19, 0x00, 0x01, 0x14, 0x10,
188 0x05, 0x00, 0x2A, 0xF9, 0xF6, 0xC2, 0x98,
189 0x10, 0x2B, 0x49, 0x8E, 0x64, 0xFF, 0x01,
190 0x0C, 0x7F, 0x94, 0xE1};
191 WebUsbPlatformCapabilityDescriptor descriptor;
192 ASSERT_FALSE(descriptor.ParseFromBosDescriptor(
193 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
194 }
195
196 TEST_F(WebUsbDescriptorsTest, ShortWebUsbPlatformCapabilityDescriptor) {
197 // The WebUSB Platform Capability Descriptor is too short.
198 static const uint8_t kBuffer[] = {0x05, 0x0F, 0x19, 0x00, 0x01, 0x14, 0x10,
199 0x05, 0x00, 0x38, 0xB6, 0x08, 0x34, 0xA9,
200 0x09, 0xA0, 0x47, 0x8B, 0xFD, 0xA0, 0x76,
201 0x88, 0x15, 0xB6, 0x65};
202 WebUsbPlatformCapabilityDescriptor descriptor;
203 ASSERT_FALSE(descriptor.ParseFromBosDescriptor(
204 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
205 }
206
207 TEST_F(WebUsbDescriptorsTest, WebUsbPlatformCapabilityDescriptorOutOfDate) {
208 // The WebUSB Platform Capability Descriptor is version 0.9 (too old).
209 static const uint8_t kBuffer[] = {0x05, 0x0F, 0x1C, 0x00, 0x01, 0x17, 0x10,
210 0x05, 0x00, 0x38, 0xB6, 0x08, 0x34, 0xA9,
211 0x09, 0xA0, 0x47, 0x8B, 0xFD, 0xA0, 0x76,
212 0x88, 0x15, 0xB6, 0x65, 0x90, 0x00, 0x01};
213 WebUsbPlatformCapabilityDescriptor descriptor;
214 ASSERT_FALSE(descriptor.ParseFromBosDescriptor(
215 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
216 }
217
218 TEST_F(WebUsbDescriptorsTest, DescriptorSet) {
219 WebUsbDescriptorSet descriptor;
220
221 ASSERT_TRUE(descriptor.Parse(std::vector<uint8_t>(
222 kExampleDescriptorSet,
223 kExampleDescriptorSet + sizeof(kExampleDescriptorSet))));
224 EXPECT_EQ(2u, descriptor.origins.size());
225 EXPECT_EQ(GURL("https://example.com:80"), descriptor.origins[0]);
226 EXPECT_EQ(GURL("https://example.com:85"), descriptor.origins[1]);
227 EXPECT_EQ(1u, descriptor.configurations.size());
228
229 const WebUsbConfigurationSubset& config1 = descriptor.configurations[0];
230 EXPECT_EQ(2u, config1.origins.size());
231 EXPECT_EQ(GURL("https://example.com:81"), config1.origins[0]);
232 EXPECT_EQ(GURL("https://example.com:84"), config1.origins[1]);
233 EXPECT_EQ(1u, config1.functions.size());
234
235 const WebUsbFunctionSubset& function1 = config1.functions[0];
236 EXPECT_EQ(2u, function1.origins.size());
237 EXPECT_EQ(GURL("https://example.com:82"), function1.origins[0]);
238 EXPECT_EQ(GURL("https://example.com:83"), function1.origins[1]);
239 }
240
241 TEST_F(WebUsbDescriptorsTest, ShortDescriptorSetHeader) {
242 // bLength is too short for a WebUSB Descriptor Set Header.
243 static const uint8_t kBuffer[] = {0x03, 0x00, 0x03};
244 WebUsbDescriptorSet descriptor;
245 ASSERT_FALSE(descriptor.Parse(
246 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
247 }
248
249 TEST_F(WebUsbDescriptorsTest, LongDescriptorSetHeader) {
250 // bLength is too long for a WebUSB DescriptorSet Header.
251 static const uint8_t kBuffer[] = {0x05, 0x00, 0x04, 0x00};
252 WebUsbDescriptorSet descriptor;
253 ASSERT_FALSE(descriptor.Parse(
254 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
255 }
256
257 TEST_F(WebUsbDescriptorsTest, UrlNotDescriptorSet) {
258 WebUsbDescriptorSet descriptor;
259 ASSERT_FALSE(descriptor.Parse(std::vector<uint8_t>(
260 kExampleUrlDescriptor,
261 kExampleUrlDescriptor + sizeof(kExampleUrlDescriptor))));
262 }
263
264 TEST_F(WebUsbDescriptorsTest, ShortDescriptorSet) {
265 // wTotalLength is shorter than bLength, making the WebUSB Descriptor Set
266 // Header inconsistent.
267 static const uint8_t kBuffer[] = {0x04, 0x00, 0x03, 0x00};
268 WebUsbDescriptorSet descriptor;
269 ASSERT_FALSE(descriptor.Parse(
270 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
271 }
272
273 TEST_F(WebUsbDescriptorsTest, LongDescriptorSet) {
274 // The WebUSB Descriptor Set Header's wTotalLength is longer than the buffer.
275 static const uint8_t kBuffer[] = {0x04, 0x00, 0x05, 0x00};
276 WebUsbDescriptorSet descriptor;
277 ASSERT_FALSE(descriptor.Parse(
278 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
279 }
280
281 TEST_F(WebUsbDescriptorsTest, ShortDescriptorInDescriptorSet) {
282 // bLength for the descriptor within the descriptor set is too short.
283 static const uint8_t kBuffer[] = {0x04, 0x00, 0x05, 0x00, 0x01};
284 WebUsbDescriptorSet descriptor;
285 ASSERT_FALSE(descriptor.Parse(
286 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
287 }
288
289 TEST_F(WebUsbDescriptorsTest, LongDescriptorInDescriptorSet) {
290 // bLength for the descriptor within the descriptor set is longer than the
291 // remaining portion of the buffer and the wTotalLength of the descriptor set.
292 static const uint8_t kBuffer[] = {0x04, 0x00, 0x06, 0x00, 0x03, 0x03};
293 WebUsbDescriptorSet descriptor;
294 ASSERT_FALSE(descriptor.Parse(
295 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
296 }
297
298 TEST_F(WebUsbDescriptorsTest, InvalidDescriptorInDescriptorSet) {
299 // A descriptor set cannot contain a descriptor with this bDescriptorType.
300 static const uint8_t kBuffer[] = {0x04, 0x00, 0x06, 0x00, 0x02, 0x04};
301 WebUsbDescriptorSet descriptor;
302 ASSERT_FALSE(descriptor.Parse(
303 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
304 }
305
306 TEST_F(WebUsbDescriptorsTest, InvalidUrlInDescriptorSet) {
307 // The URL in this descriptor set is not a valid URL: "This is not a URL."
308 static const uint8_t kBuffer[] = {
309 0x04, 0x00, 0x18, 0x00, 0x14, 0x03, 'T', 'h', 'i', 's', ' ', 'i',
310 's', ' ', 'n', 'o', 't', ' ', 'a', ' ', 'U', 'R', 'L', '.'};
311 WebUsbDescriptorSet descriptor;
312 ASSERT_FALSE(descriptor.Parse(
313 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
314 }
315
316 TEST_F(WebUsbDescriptorsTest, ShortConfigurationSubsetHeader) {
317 // bLength is too short for a WebUSB Configuration Subset Header.
318 static const uint8_t kBuffer[] = {0x04, 0x00, 0x05, 0x00, 0x02, 0x01};
319 WebUsbDescriptorSet descriptor;
320 ASSERT_FALSE(descriptor.Parse(
321 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
322 }
323
324 TEST_F(WebUsbDescriptorsTest, ShortConfigurationSubset) {
325 // The configuration subset header's wTotalLength is shorter than its bLength,
326 // making it inconsistent.
327 static const uint8_t kBuffer[] = {0x04, 0x00, 0x09, 0x00, 0x05,
328 0x01, 0x01, 0x04, 0x00};
329 WebUsbDescriptorSet descriptor;
330 ASSERT_FALSE(descriptor.Parse(
331 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
332 }
333
334 TEST_F(WebUsbDescriptorsTest, LongConfigurationSubset) {
335 // wTotalLength of the configuration subset header extends beyond wTotalLength
336 // for the descriptor set and the length of the buffer.
337 static const uint8_t kBuffer[] = {0x04, 0x00, 0x09, 0x00, 0x05,
338 0x01, 0x01, 0x06, 0x00};
339 WebUsbDescriptorSet descriptor;
340 ASSERT_FALSE(descriptor.Parse(
341 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
342 }
343
344 TEST_F(WebUsbDescriptorsTest, ShortDescriptorInConfigurationSubset) {
345 // bLength for the descriptor within the configuration subset is too short.
346 static const uint8_t kBuffer[] = {0x04, 0x00, 0x0A, 0x00, 0x05,
347 0x01, 0x01, 0x06, 0x00, 0x01};
348 WebUsbDescriptorSet descriptor;
349 ASSERT_FALSE(descriptor.Parse(
350 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
351 }
352
353 TEST_F(WebUsbDescriptorsTest, LongDescriptorInConfigurationSubset) {
354 // bLength for the descriptor within the configuration subset is longer than
355 // the remaining portion of the buffer and the wTotalLength of the
356 // configuration subset.
357 static const uint8_t kBuffer[] = {0x04, 0x00, 0x0B, 0x00, 0x05, 0x01,
358 0x01, 0x07, 0x00, 0x03, 0x03};
359 WebUsbDescriptorSet descriptor;
360 ASSERT_FALSE(descriptor.Parse(
361 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
362 }
363
364 TEST_F(WebUsbDescriptorsTest, InvalidDescriptorInConfigurationSubset) {
365 // A configuration subset cannot contain a descriptor with this
366 // bDescriptorType.
367 static const uint8_t kBuffer[] = {0x04, 0x00, 0x0B, 0x00, 0x05, 0x01,
368 0x01, 0x07, 0x00, 0x02, 0x01};
369 WebUsbDescriptorSet descriptor;
370 ASSERT_FALSE(descriptor.Parse(
371 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
372 }
373
374 TEST_F(WebUsbDescriptorsTest, ShortFunctionSubsetHeader) {
375 // bLength is too short for a WebUSB Function Subset Header.
376 static const uint8_t kBuffer[] = {0x04, 0x00, 0x0B, 0x00, 0x05, 0x01,
377 0x01, 0x07, 0x00, 0x02, 0x02};
378 WebUsbDescriptorSet descriptor;
379 ASSERT_FALSE(descriptor.Parse(
380 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
381 }
382
383 TEST_F(WebUsbDescriptorsTest, ShortFunctionSubset) {
384 // The function subset header's wTotalLength is shorter than its bLength,
385 // making it inconsistent.
386 static const uint8_t kBuffer[] = {0x04, 0x00, 0x0E, 0x00, 0x05, 0x01, 0x01,
387 0x0A, 0x00, 0x05, 0x02, 0x01, 0x04, 0x00};
388 WebUsbDescriptorSet descriptor;
389 ASSERT_FALSE(descriptor.Parse(
390 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
391 }
392
393 TEST_F(WebUsbDescriptorsTest, LongFunctionSubset) {
394 // wTotalLength of the function subset header extends beyond wTotalLength for
395 // for the configuration subset and the length of the buffer.
396 static const uint8_t kBuffer[] = {0x04, 0x00, 0x0E, 0x00, 0x05, 0x01, 0x01,
397 0x0A, 0x00, 0x05, 0x02, 0x01, 0x06, 0x00};
398 WebUsbDescriptorSet descriptor;
399 ASSERT_FALSE(descriptor.Parse(
400 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
401 }
402
403 TEST_F(WebUsbDescriptorsTest, ShortDescriptorInFunctionSubset) {
404 // bLength for the descriptor within the function subset is too short.
405 static const uint8_t kBuffer[] = {0x04, 0x00, 0x0F, 0x00, 0x05,
406 0x01, 0x01, 0x0B, 0x00, 0x05,
407 0x02, 0x01, 0x06, 0x00, 0x01};
408 WebUsbDescriptorSet descriptor;
409 ASSERT_FALSE(descriptor.Parse(
410 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
411 }
412
413 TEST_F(WebUsbDescriptorsTest, LongDescriptorInFunctionSubset) {
414 // bLength for the descriptor within the function subset is longer than the
415 // remaining portion of the buffer and the wTotalLength of the function
416 // subset.
417 static const uint8_t kBuffer[] = {0x04, 0x00, 0x10, 0x00, 0x05, 0x01,
418 0x01, 0x0C, 0x00, 0x05, 0x02, 0x01,
419 0x07, 0x00, 0x03, 0x03};
420 WebUsbDescriptorSet descriptor;
421 ASSERT_FALSE(descriptor.Parse(
422 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
423 }
424
425 TEST_F(WebUsbDescriptorsTest, InvalidDescriptorInFunctionSubset) {
426 // A function subset cannot contain a descriptor with this bDescriptorType.
427 static const uint8_t kBuffer[] = {0x04, 0x00, 0x10, 0x00, 0x05, 0x01,
428 0x01, 0x0C, 0x00, 0x05, 0x02, 0x01,
429 0x07, 0x00, 0x02, 0x02};
430 WebUsbDescriptorSet descriptor;
431 ASSERT_FALSE(descriptor.Parse(
432 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer))));
433 }
434
435 } // namespace
436
437 } // namespace device
OLDNEW
« device/usb/webusb_descriptors.cc ('K') | « device/usb/webusb_descriptors.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698