OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
| 4 <script src="../resources/mojo-helpers.js"></script> |
4 <script src="resources/fake-devices.js"></script> | 5 <script src="resources/fake-devices.js"></script> |
5 <script src="resources/usb-helpers.js"></script> | 6 <script src="resources/usb-helpers.js"></script> |
6 <script src="resources/webusb-test.js"></script> | |
7 <script> | 7 <script> |
8 'use strict'; | 8 'use strict'; |
9 | 9 |
10 function assertRejectsWithNotFoundError(promise) { | 10 function assertRejectsWithNotFoundError(promise) { |
11 return assertRejectsWithError(promise, 'NotFoundError'); | 11 return assertRejectsWithError(promise, 'NotFoundError'); |
12 } | 12 } |
13 | 13 |
14 function assertRejectsWithNotOpenError(promise) { | 14 function assertRejectsWithNotOpenError(promise) { |
15 return assertRejectsWithError( | 15 return assertRejectsWithError( |
16 promise, 'InvalidStateError', 'The device must be opened first.') | 16 promise, 'InvalidStateError', 'The device must be opened first.') |
17 } | 17 } |
18 | 18 |
19 function assertRejectsWithNotConfiguredError(promise) { | 19 function assertRejectsWithNotConfiguredError(promise) { |
20 return assertRejectsWithError( | 20 return assertRejectsWithError( |
21 promise, 'InvalidStateError', | 21 promise, 'InvalidStateError', |
22 'The device must have a configuration selected.'); | 22 'The device must have a configuration selected.'); |
23 } | 23 } |
24 | 24 |
25 usb_test(() => { | 25 usb_test(usb => { |
26 let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); | 26 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
27 | |
28 return navigator.usb.getDevices().then(devices => { | 27 return navigator.usb.getDevices().then(devices => { |
29 assert_equals(1, devices.length); | 28 assert_equals(1, devices.length); |
30 navigator.usb.test.removeFakeDevice(guid); | 29 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
31 return assertRejectsWithNotFoundError(devices[0].open()); | 30 return assertRejectsWithNotFoundError(devices[0].open()); |
32 }); | 31 }); |
33 }, 'open rejects when called on a disconnected device'); | 32 }, 'open rejects when called on a disconnected device'); |
34 | 33 |
35 usb_test(() => { | 34 usb_test(usb => { |
36 let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); | 35 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
37 | |
38 return navigator.usb.getDevices().then(devices => { | 36 return navigator.usb.getDevices().then(devices => { |
39 assert_equals(1, devices.length); | 37 assert_equals(1, devices.length); |
40 let promise = devices[0].open(); | 38 let promise = devices[0].open(); |
41 navigator.usb.test.removeFakeDevice(guid); | 39 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
42 return assertRejectsWithNotFoundError(promise) | 40 return assertRejectsWithNotFoundError(promise) |
43 .then(() => runGarbageCollection()); | 41 .then(() => runGarbageCollection()); |
44 }); | 42 }); |
45 }, 'open rejects when device disconnected during call'); | 43 }, 'open rejects when device disconnected during call'); |
46 | 44 |
47 usb_test(() => { | 45 usb_test(usb => { |
48 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 46 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
49 | |
50 return navigator.usb.getDevices().then(devices => { | 47 return navigator.usb.getDevices().then(devices => { |
51 assert_equals(1, devices.length); | 48 assert_equals(1, devices.length); |
52 let device = devices[0]; | 49 let device = devices[0]; |
53 assert_false(device.opened); | 50 assert_false(device.opened); |
54 return device.open().then(() => { | 51 return device.open().then(() => { |
55 assert_true(device.opened); | 52 assert_true(device.opened); |
56 return device.close().then(() => { | 53 return device.close().then(() => { |
57 assert_false(device.opened); | 54 assert_false(device.opened); |
58 }); | 55 }); |
59 }); | 56 }); |
60 }).then(() => runGarbageCollection()); | 57 }).then(() => runGarbageCollection()); |
61 }, 'a device can be opened and closed'); | 58 }, 'a device can be opened and closed'); |
62 | 59 |
63 usb_test(() => { | 60 usb_test(usb => { |
64 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 61 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
65 | |
66 return navigator.usb.getDevices().then(devices => { | 62 return navigator.usb.getDevices().then(devices => { |
67 assert_equals(1, devices.length); | 63 assert_equals(1, devices.length); |
68 let device = devices[0]; | 64 let device = devices[0]; |
69 return device.open() | 65 return device.open() |
70 .then(() => device.open()) | 66 .then(() => device.open()) |
71 .then(() => device.open()) | 67 .then(() => device.open()) |
72 .then(() => device.open()) | 68 .then(() => device.open()) |
73 .then(() => device.close()) | 69 .then(() => device.close()) |
74 .then(() => device.close()) | 70 .then(() => device.close()) |
75 .then(() => device.close()) | 71 .then(() => device.close()) |
76 .then(() => device.close()); | 72 .then(() => device.close()); |
77 }); | 73 }); |
78 }, 'open and close can be called multiple times'); | 74 }, 'open and close can be called multiple times'); |
79 | 75 |
80 usb_test(() => { | 76 usb_test(usb => { |
81 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 77 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
82 | |
83 return navigator.usb.getDevices().then(devices => { | 78 return navigator.usb.getDevices().then(devices => { |
84 assert_equals(1, devices.length); | 79 assert_equals(1, devices.length); |
85 let device = devices[0]; | 80 let device = devices[0]; |
86 const message = | 81 const message = |
87 'An operation that changes the device state is in progress.'; | 82 'An operation that changes the device state is in progress.'; |
88 return Promise.all([ | 83 return Promise.all([ |
89 device.open(), | 84 device.open(), |
90 assertRejectsWithError(device.open(), 'InvalidStateError', message), | 85 assertRejectsWithError(device.open(), 'InvalidStateError', message), |
91 assertRejectsWithError(device.close(), 'InvalidStateError', message), | 86 assertRejectsWithError(device.close(), 'InvalidStateError', message), |
92 ]).then(() => Promise.all([ | 87 ]).then(() => Promise.all([ |
93 device.close(), | 88 device.close(), |
94 assertRejectsWithError(device.open(), 'InvalidStateError', message), | 89 assertRejectsWithError(device.open(), 'InvalidStateError', message), |
95 assertRejectsWithError(device.close(), 'InvalidStateError', message), | 90 assertRejectsWithError(device.close(), 'InvalidStateError', message), |
96 ])); | 91 ])); |
97 }); | 92 }); |
98 }, 'open and close cannot be called again while open or close are in progress'); | 93 }, 'open and close cannot be called again while open or close are in progress'); |
99 | 94 |
100 usb_test(() => { | 95 usb_test(usb => { |
101 let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); | 96 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
102 | |
103 return navigator.usb.getDevices().then(devices => { | 97 return navigator.usb.getDevices().then(devices => { |
104 assert_equals(1, devices.length); | 98 assert_equals(1, devices.length); |
105 let device = devices[0]; | 99 let device = devices[0]; |
106 return device.open().then(() => { | 100 return device.open().then(() => { |
107 navigator.usb.test.removeFakeDevice(guid); | 101 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
108 return assertRejectsWithNotFoundError(device.close()); | 102 return assertRejectsWithNotFoundError(device.close()); |
109 }); | 103 }); |
110 }); | 104 }); |
111 }, 'close rejects when called on a disconnected device'); | 105 }, 'close rejects when called on a disconnected device'); |
112 | 106 |
113 usb_test(() => { | 107 usb_test(usb => { |
114 let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); | 108 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
115 | |
116 return navigator.usb.getDevices().then(devices => { | 109 return navigator.usb.getDevices().then(devices => { |
117 assert_equals(1, devices.length); | 110 assert_equals(1, devices.length); |
118 let device = devices[0]; | 111 var device = devices[0]; |
119 return device.open() | 112 return device.open() |
120 .then(() => { | 113 .then(() => { |
121 navigator.usb.test.removeFakeDevice(guid); | 114 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
122 return assertRejectsWithNotFoundError(device.selectConfiguration(1)); | 115 return assertRejectsWithNotFoundError(device.selectConfiguration(1)); |
123 }); | 116 }); |
124 }); | 117 }); |
125 }, 'selectConfiguration rejects when called on a disconnected device'); | 118 }, 'selectConfiguration rejects when called on a disconnected device'); |
126 | 119 |
127 usb_test(() => { | 120 usb_test(usb => { |
128 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 121 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
129 | |
130 return navigator.usb.getDevices().then(devices => { | 122 return navigator.usb.getDevices().then(devices => { |
131 assert_equals(1, devices.length); | 123 assert_equals(1, devices.length); |
132 let device = devices[0]; | 124 var device = devices[0]; |
133 return Promise.all([ | 125 return Promise.all([ |
134 assertRejectsWithNotOpenError(device.selectConfiguration(1)), | 126 assertRejectsWithNotOpenError(device.selectConfiguration(1)), |
135 assertRejectsWithNotOpenError(device.claimInterface(0)), | 127 assertRejectsWithNotOpenError(device.claimInterface(0)), |
136 assertRejectsWithNotOpenError(device.releaseInterface(0)), | 128 assertRejectsWithNotOpenError(device.releaseInterface(0)), |
137 assertRejectsWithNotOpenError(device.selectAlternateInterface(0, 1)), | 129 assertRejectsWithNotOpenError(device.selectAlternateInterface(0, 1)), |
138 assertRejectsWithNotOpenError(device.controlTransferIn({ | 130 assertRejectsWithNotOpenError(device.controlTransferIn({ |
139 requestType: 'vendor', | 131 requestType: 'vendor', |
140 recipient: 'device', | 132 recipient: 'device', |
141 request: 0x42, | 133 request: 0x42, |
142 value: 0x1234, | 134 value: 0x1234, |
(...skipping 11 matching lines...) Expand all Loading... |
154 assertRejectsWithNotOpenError( | 146 assertRejectsWithNotOpenError( |
155 device.transferOut(1, new ArrayBuffer(8))), | 147 device.transferOut(1, new ArrayBuffer(8))), |
156 assertRejectsWithNotOpenError(device.isochronousTransferIn(1, [8])), | 148 assertRejectsWithNotOpenError(device.isochronousTransferIn(1, [8])), |
157 assertRejectsWithNotOpenError( | 149 assertRejectsWithNotOpenError( |
158 device.isochronousTransferOut(1, new ArrayBuffer(8), [8])), | 150 device.isochronousTransferOut(1, new ArrayBuffer(8), [8])), |
159 assertRejectsWithNotOpenError(device.reset()) | 151 assertRejectsWithNotOpenError(device.reset()) |
160 ]); | 152 ]); |
161 }); | 153 }); |
162 }, 'methods requiring it reject when the device is not open'); | 154 }, 'methods requiring it reject when the device is not open'); |
163 | 155 |
164 usb_test(() => { | 156 usb_test(usb => { |
165 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 157 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
166 | |
167 return navigator.usb.getDevices().then(devices => { | 158 return navigator.usb.getDevices().then(devices => { |
168 assert_equals(1, devices.length); | 159 assert_equals(1, devices.length); |
169 let device = devices[0]; | 160 let device = devices[0]; |
170 assert_equals(device.configuration, null); | 161 assert_equals(device.configuration, null); |
171 return device.open() | 162 return device.open() |
172 .then(() => { | 163 .then(() => { |
173 assert_equals(device.configuration, null); | 164 assert_equals(device.configuration, null); |
174 return device.selectConfiguration(1); | 165 return device.selectConfiguration(1); |
175 }) | 166 }) |
176 .then(() => { | 167 .then(() => { |
177 assertDeviceInfoEquals( | 168 usb.assertConfigurationInfoEquals( |
178 device.configuration, fakeDeviceInit.configurations[0]); | 169 device.configuration, usb.fakeDevices[0].configurations[0]); |
179 }) | 170 }) |
180 .then(() => device.close()); | 171 .then(() => device.close()); |
181 }); | 172 }); |
182 }, 'device configuration can be set and queried'); | 173 }, 'device configuration can be set and queried'); |
183 | 174 |
184 usb_test(() => { | 175 usb_test(usb => { |
185 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 176 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
186 | |
187 return navigator.usb.getDevices().then(devices => { | 177 return navigator.usb.getDevices().then(devices => { |
188 assert_equals(1, devices.length); | 178 assert_equals(1, devices.length); |
189 let device = devices[0]; | 179 let device = devices[0]; |
190 assert_equals(device.configuration, null); | 180 assert_equals(device.configuration, null); |
191 return device.open() | 181 return device.open() |
192 .then(() => assertRejectsWithError( | 182 .then(() => assertRejectsWithError( |
193 device.selectConfiguration(3), 'NotFoundError', | 183 device.selectConfiguration(3), 'NotFoundError', |
194 'The configuration value provided is not supported by the device.')) | 184 'The configuration value provided is not supported by the device.')) |
195 .then(() => device.close()); | 185 .then(() => device.close()); |
196 }); | 186 }); |
197 }, 'selectConfiguration rejects on invalid configurations'); | 187 }, 'selectConfiguration rejects on invalid configurations'); |
198 | 188 |
199 usb_test(() => { | |
200 navigator.usb.test.addFakeDevice(fakeDeviceInit); | |
201 | 189 |
| 190 usb_test(usb => { |
| 191 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
202 return navigator.usb.getDevices().then(devices => { | 192 return navigator.usb.getDevices().then(devices => { |
203 assert_equals(1, devices.length); | 193 assert_equals(1, devices.length); |
204 let device = devices[0]; | 194 let device = devices[0]; |
205 assert_equals(device.configuration, null); | 195 assert_equals(device.configuration, null); |
206 return device.open().then(() => Promise.all([ | 196 return device.open().then(() => Promise.all([ |
207 assertRejectsWithNotConfiguredError(device.claimInterface(0)), | 197 assertRejectsWithNotConfiguredError(device.claimInterface(0)), |
208 assertRejectsWithNotConfiguredError(device.releaseInterface(0)), | 198 assertRejectsWithNotConfiguredError(device.releaseInterface(0)), |
209 assertRejectsWithNotConfiguredError(device.selectAlternateInterface(0, 1
)), | 199 assertRejectsWithNotConfiguredError(device.selectAlternateInterface(0, 1
)), |
210 assertRejectsWithNotConfiguredError(device.controlTransferIn({ | 200 assertRejectsWithNotConfiguredError(device.controlTransferIn({ |
211 requestType: 'vendor', | 201 requestType: 'vendor', |
(...skipping 14 matching lines...) Expand all Loading... |
226 assertRejectsWithNotConfiguredError( | 216 assertRejectsWithNotConfiguredError( |
227 device.transferOut(1, new ArrayBuffer(8))), | 217 device.transferOut(1, new ArrayBuffer(8))), |
228 assertRejectsWithNotConfiguredError( | 218 assertRejectsWithNotConfiguredError( |
229 device.isochronousTransferIn(1, [8])), | 219 device.isochronousTransferIn(1, [8])), |
230 assertRejectsWithNotConfiguredError( | 220 assertRejectsWithNotConfiguredError( |
231 device.isochronousTransferOut(1, new ArrayBuffer(8), [8])), | 221 device.isochronousTransferOut(1, new ArrayBuffer(8), [8])), |
232 ])).then(() => device.close()); | 222 ])).then(() => device.close()); |
233 }); | 223 }); |
234 }, 'methods requiring it reject when the device is unconfigured'); | 224 }, 'methods requiring it reject when the device is unconfigured'); |
235 | 225 |
236 usb_test(() => { | 226 usb_test(usb => { |
237 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 227 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
238 | |
239 return navigator.usb.getDevices().then(devices => { | 228 return navigator.usb.getDevices().then(devices => { |
240 assert_equals(1, devices.length); | 229 assert_equals(1, devices.length); |
241 let device = devices[0]; | 230 let device = devices[0]; |
242 return device.open() | 231 return device.open() |
243 .then(() => device.selectConfiguration(1)) | 232 .then(() => device.selectConfiguration(1)) |
244 .then(() => device.claimInterface(0)) | 233 .then(() => device.claimInterface(0)) |
245 .then(() => { | 234 .then(() => { |
246 assert_true(device.configuration.interfaces[0].claimed); | 235 assert_true(device.configuration.interfaces[0].claimed); |
247 return device.releaseInterface(0); | 236 return device.releaseInterface(0); |
248 }) | 237 }) |
249 .then(() => { | 238 .then(() => { |
250 assert_false(device.configuration.interfaces[0].claimed); | 239 assert_false(device.configuration.interfaces[0].claimed); |
251 return device.close(); | 240 return device.close(); |
252 }); | 241 }); |
253 }); | 242 }); |
254 }, 'an interface can be claimed and released'); | 243 }, 'an interface can be claimed and released'); |
255 | 244 |
256 usb_test(() => { | 245 usb_test(usb => { |
257 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 246 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
258 | |
259 return navigator.usb.getDevices().then(devices => { | 247 return navigator.usb.getDevices().then(devices => { |
260 assert_equals(1, devices.length); | 248 assert_equals(1, devices.length); |
261 let device = devices[0]; | 249 let device = devices[0]; |
262 return device.open() | 250 return device.open() |
263 .then(() => device.selectConfiguration(1)) | 251 .then(() => device.selectConfiguration(1)) |
264 .then(() => device.claimInterface(0)) | 252 .then(() => device.claimInterface(0)) |
265 .then(() => { | 253 .then(() => { |
266 assert_true(device.configuration.interfaces[0].claimed); | 254 assert_true(device.configuration.interfaces[0].claimed); |
267 return device.close(0); | 255 return device.close(0); |
268 }) | 256 }) |
269 .then(() => { | 257 .then(() => { |
270 assert_false(device.configuration.interfaces[0].claimed); | 258 assert_false(device.configuration.interfaces[0].claimed); |
271 }); | 259 }); |
272 }); | 260 }); |
273 }, 'interfaces are released on close'); | 261 }, 'interfaces are released on close'); |
274 | 262 |
275 usb_test(() => { | 263 usb_test(usb => { |
276 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 264 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
277 | |
278 return navigator.usb.getDevices().then(devices => { | 265 return navigator.usb.getDevices().then(devices => { |
279 assert_equals(1, devices.length); | 266 assert_equals(1, devices.length); |
280 let device = devices[0]; | 267 let device = devices[0]; |
281 const message = 'The interface number provided is not supported by the ' + | 268 const message = 'The interface number provided is not supported by the ' + |
282 'device in its current configuration.'; | 269 'device in its current configuration.'; |
283 return device.open() | 270 return device.open() |
284 .then(() => device.selectConfiguration(1)) | 271 .then(() => device.selectConfiguration(1)) |
285 .then(() => Promise.all([ | 272 .then(() => Promise.all([ |
286 assertRejectsWithError( | 273 assertRejectsWithError( |
287 device.claimInterface(2), 'NotFoundError', message), | 274 device.claimInterface(2), 'NotFoundError', message), |
288 assertRejectsWithError( | 275 assertRejectsWithError( |
289 device.releaseInterface(2), 'NotFoundError', message), | 276 device.releaseInterface(2), 'NotFoundError', message), |
290 ])) | 277 ])) |
291 .then(() => device.close()); | 278 .then(() => device.close()); |
292 }); | 279 }); |
293 }, 'a non-existent interface cannot be claimed or released'); | 280 }, 'a non-existent interface cannot be claimed or released'); |
294 | 281 |
295 usb_test(() => { | 282 usb_test(usb => { |
296 let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); | 283 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
297 | |
298 return navigator.usb.getDevices().then(devices => { | 284 return navigator.usb.getDevices().then(devices => { |
299 assert_equals(1, devices.length); | 285 assert_equals(1, devices.length); |
300 var device = devices[0]; | 286 var device = devices[0]; |
301 return device.open() | 287 return device.open() |
302 .then(() => device.selectConfiguration(1)) | 288 .then(() => device.selectConfiguration(1)) |
303 .then(() => { | 289 .then(() => { |
304 navigator.usb.test.removeFakeDevice(guid); | 290 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
305 return assertRejectsWithNotFoundError(device.claimInterface(0)); | 291 return assertRejectsWithNotFoundError(device.claimInterface(0)); |
306 }); | 292 }); |
307 }); | 293 }); |
308 }, 'claimInterface rejects when called on a disconnected device'); | 294 }, 'claimInterface rejects when called on a disconnected device'); |
309 | 295 |
310 usb_test(() => { | 296 usb_test(usb => { |
311 let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); | 297 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
312 | |
313 return navigator.usb.getDevices().then(devices => { | 298 return navigator.usb.getDevices().then(devices => { |
314 assert_equals(1, devices.length); | 299 assert_equals(1, devices.length); |
315 var device = devices[0]; | 300 var device = devices[0]; |
316 return device.open() | 301 return device.open() |
317 .then(() => device.selectConfiguration(1)) | 302 .then(() => device.selectConfiguration(1)) |
318 .then(() => device.claimInterface(0)) | 303 .then(() => device.claimInterface(0)) |
319 .then(() => { | 304 .then(() => { |
320 navigator.usb.test.removeFakeDevice(guid); | 305 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
321 return assertRejectsWithNotFoundError(device.releaseInterface(0)); | 306 return assertRejectsWithNotFoundError(device.releaseInterface(0)); |
322 }); | 307 }); |
323 }); | 308 }); |
324 }, 'releaseInterface rejects when called on a disconnected device'); | 309 }, 'releaseInterface rejects when called on a disconnected device'); |
325 | 310 |
326 usb_test(() => { | 311 usb_test(usb => { |
327 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 312 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
328 | |
329 return navigator.usb.getDevices().then(devices => { | 313 return navigator.usb.getDevices().then(devices => { |
330 assert_equals(1, devices.length); | 314 assert_equals(1, devices.length); |
331 let device = devices[0]; | 315 let device = devices[0]; |
332 return device.open() | 316 return device.open() |
333 .then(() => device.selectConfiguration(2)) | 317 .then(() => device.selectConfiguration(2)) |
334 .then(() => device.claimInterface(0)) | 318 .then(() => device.claimInterface(0)) |
335 .then(() => device.selectAlternateInterface(0, 1)) | 319 .then(() => device.selectAlternateInterface(0, 1)) |
336 .then(() => device.close()); | 320 .then(() => device.close()); |
337 }); | 321 }); |
338 }, 'can select an alternate interface'); | 322 }, 'can select an alternate interface'); |
339 | 323 |
340 usb_test(() => { | 324 usb_test(usb => { |
341 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 325 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
342 | |
343 return navigator.usb.getDevices().then(devices => { | 326 return navigator.usb.getDevices().then(devices => { |
344 assert_equals(1, devices.length); | 327 assert_equals(1, devices.length); |
345 let device = devices[0]; | 328 let device = devices[0]; |
346 return device.open() | 329 return device.open() |
347 .then(() => device.selectConfiguration(2)) | 330 .then(() => device.selectConfiguration(2)) |
348 .then(() => device.claimInterface(0)) | 331 .then(() => device.claimInterface(0)) |
349 .then(() => assertRejectsWithError( | 332 .then(() => assertRejectsWithError( |
350 device.selectAlternateInterface(0, 2), 'NotFoundError', | 333 device.selectAlternateInterface(0, 2), 'NotFoundError', |
351 'The alternate setting provided is not supported by the device in ' + | 334 'The alternate setting provided is not supported by the device in ' + |
352 'its current configuration.')) | 335 'its current configuration.')) |
353 .then(() => device.close()); | 336 .then(() => device.close()); |
354 }); | 337 }); |
355 }, 'cannot select a non-existent alternate interface'); | 338 }, 'cannot select a non-existent alternate interface'); |
356 | 339 |
357 usb_test(() => { | 340 usb_test(usb => { |
358 let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); | 341 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
359 | |
360 return navigator.usb.getDevices().then(devices => { | 342 return navigator.usb.getDevices().then(devices => { |
361 assert_equals(1, devices.length); | 343 assert_equals(1, devices.length); |
362 var device = devices[0]; | 344 var device = devices[0]; |
363 return device.open() | 345 return device.open() |
364 .then(() => device.selectConfiguration(2)) | 346 .then(() => device.selectConfiguration(2)) |
365 .then(() => device.claimInterface(0)) | 347 .then(() => device.claimInterface(0)) |
366 .then(() => { | 348 .then(() => { |
367 navigator.usb.test.removeFakeDevice(guid); | 349 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
368 return assertRejectsWithNotFoundError(device.selectAlternateInterface(0,
1)); | 350 return assertRejectsWithNotFoundError(device.selectAlternateInterface(0,
1)); |
369 }); | 351 }); |
370 }); | 352 }); |
371 }, 'selectAlternateInterface rejects when called on a disconnected device'); | 353 }, 'selectAlternateInterface rejects when called on a disconnected device'); |
372 | 354 |
373 usb_test(() => { | 355 usb_test(usb => { |
374 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 356 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
375 | |
376 return navigator.usb.getDevices().then(devices => { | 357 return navigator.usb.getDevices().then(devices => { |
377 assert_equals(1, devices.length); | 358 assert_equals(1, devices.length); |
378 let device = devices[0]; | 359 let device = devices[0]; |
379 return device.open() | 360 return device.open() |
380 .then(() => device.selectConfiguration(1)) | 361 .then(() => device.selectConfiguration(1)) |
381 .then(() => device.controlTransferIn({ | 362 .then(() => device.controlTransferIn({ |
382 requestType: 'vendor', | 363 requestType: 'vendor', |
383 recipient: 'device', | 364 recipient: 'device', |
384 request: 0x42, | 365 request: 0x42, |
385 value: 0x1234, | 366 value: 0x1234, |
386 index: 0x5678 | 367 index: 0x5678 |
387 }, 7)) | 368 }, 7)) |
388 .then(result => { | 369 .then(result => { |
389 assert_true(result instanceof USBInTransferResult); | 370 assert_true(result instanceof USBInTransferResult); |
390 assert_equals(result.status, 'ok'); | 371 assert_equals(result.status, 'ok'); |
391 assert_equals(result.data.byteLength, 7); | 372 assert_equals(result.data.byteLength, 7); |
392 assert_equals(result.data.getUint16(0), 0x07); | 373 assert_equals(result.data.getUint16(0), 0x07); |
393 assert_equals(result.data.getUint8(2), 0x42); | 374 assert_equals(result.data.getUint8(2), 0x42); |
394 assert_equals(result.data.getUint16(3), 0x1234); | 375 assert_equals(result.data.getUint16(3), 0x1234); |
395 assert_equals(result.data.getUint16(5), 0x5678); | 376 assert_equals(result.data.getUint16(5), 0x5678); |
396 return device.close(); | 377 return device.close(); |
397 }); | 378 }); |
398 }); | 379 }); |
399 }, 'can issue IN control transfer'); | 380 }, 'can issue IN control transfer'); |
400 | 381 |
401 usb_test(() => { | 382 usb_test(usb => { |
402 let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); | 383 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
403 | |
404 return navigator.usb.getDevices().then(devices => { | 384 return navigator.usb.getDevices().then(devices => { |
405 assert_equals(1, devices.length); | 385 assert_equals(1, devices.length); |
406 let device = devices[0]; | 386 let device = devices[0]; |
407 return device.open() | 387 return device.open() |
408 .then(() => device.selectConfiguration(1)) | 388 .then(() => device.selectConfiguration(1)) |
409 .then(() => { | 389 .then(() => { |
410 navigator.usb.test.removeFakeDevice(guid); | 390 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
411 return assertRejectsWithNotFoundError(device.controlTransferIn({ | 391 return assertRejectsWithNotFoundError(device.controlTransferIn({ |
412 requestType: 'vendor', | 392 requestType: 'vendor', |
413 recipient: 'device', | 393 recipient: 'device', |
414 request: 0x42, | 394 request: 0x42, |
415 value: 0x1234, | 395 value: 0x1234, |
416 index: 0x5678 | 396 index: 0x5678 |
417 }, 7)); | 397 }, 7)); |
418 }); | 398 }); |
419 }); | 399 }); |
420 }, 'controlTransferIn rejects when called on a disconnected device'); | 400 }, 'controlTransferIn rejects when called on a disconnected device'); |
421 | 401 |
422 usb_test(() => { | 402 usb_test(usb => { |
423 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 403 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
424 | |
425 return navigator.usb.getDevices().then(devices => { | 404 return navigator.usb.getDevices().then(devices => { |
426 assert_equals(1, devices.length); | 405 assert_equals(1, devices.length); |
427 let device = devices[0]; | 406 let device = devices[0]; |
428 return device.open() | 407 return device.open() |
429 .then(() => device.selectConfiguration(1)) | 408 .then(() => device.selectConfiguration(1)) |
430 .then(() => device.controlTransferOut({ | 409 .then(() => device.controlTransferOut({ |
431 requestType: 'vendor', | 410 requestType: 'vendor', |
432 recipient: 'device', | 411 recipient: 'device', |
433 request: 0x42, | 412 request: 0x42, |
434 value: 0x1234, | 413 value: 0x1234, |
435 index: 0x5678 | 414 index: 0x5678 |
436 }, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]))) | 415 }, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]))) |
437 .then(result => { | 416 .then(result => { |
438 assert_true(result instanceof USBOutTransferResult); | 417 assert_true(result instanceof USBOutTransferResult); |
439 assert_equals(result.status, 'ok'); | 418 assert_equals(result.status, 'ok'); |
440 assert_equals(result.bytesWritten, 8); | 419 assert_equals(result.bytesWritten, 8); |
441 return device.close(); | 420 return device.close(); |
442 }) | 421 }) |
443 }); | 422 }); |
444 }, 'can issue OUT control transfer'); | 423 }, 'can issue OUT control transfer'); |
445 | 424 |
446 usb_test(() => { | 425 usb_test(usb => { |
447 let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); | 426 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
448 | |
449 return navigator.usb.getDevices().then(devices => { | 427 return navigator.usb.getDevices().then(devices => { |
450 assert_equals(1, devices.length); | 428 assert_equals(1, devices.length); |
451 let device = devices[0]; | 429 let device = devices[0]; |
452 return device.open() | 430 return device.open() |
453 .then(() => device.selectConfiguration(1)) | 431 .then(() => device.selectConfiguration(1)) |
454 .then(() => { | 432 .then(() => { |
455 navigator.usb.test.removeFakeDevice(guid); | 433 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
456 return assertRejectsWithNotFoundError(device.controlTransferOut({ | 434 return assertRejectsWithNotFoundError(device.controlTransferOut({ |
457 requestType: 'vendor', | 435 requestType: 'vendor', |
458 recipient: 'device', | 436 recipient: 'device', |
459 request: 0x42, | 437 request: 0x42, |
460 value: 0x1234, | 438 value: 0x1234, |
461 index: 0x5678 | 439 index: 0x5678 |
462 }, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]))); | 440 }, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]))); |
463 }); | 441 }); |
464 }); | 442 }); |
465 }, 'controlTransferOut rejects when called on a disconnected device'); | 443 }, 'controlTransferOut rejects when called on a disconnected device'); |
466 | 444 |
467 usb_test(() => { | 445 usb_test(usb => { |
468 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 446 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
469 | |
470 return navigator.usb.getDevices().then(devices => { | 447 return navigator.usb.getDevices().then(devices => { |
471 assert_equals(1, devices.length); | 448 assert_equals(1, devices.length); |
472 let device = devices[0]; | 449 let device = devices[0]; |
473 let interfaceRequest = { | 450 let interfaceRequest = { |
474 requestType: 'vendor', | 451 requestType: 'vendor', |
475 recipient: 'interface', | 452 recipient: 'interface', |
476 request: 0x42, | 453 request: 0x42, |
477 value: 0x1234, | 454 value: 0x1234, |
478 index: 0x5600 // Last byte of index is interface number. | 455 index: 0x5600 // Last byte of index is interface number. |
479 }; | 456 }; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 assert_equals(result.data.getUint16(3), 0x1234); | 498 assert_equals(result.data.getUint16(3), 0x1234); |
522 assert_equals(result.data.getUint16(5), 0x5681); | 499 assert_equals(result.data.getUint16(5), 0x5681); |
523 }), | 500 }), |
524 device.controlTransferOut(interfaceRequest, data), | 501 device.controlTransferOut(interfaceRequest, data), |
525 device.controlTransferOut(endpointRequest, data), | 502 device.controlTransferOut(endpointRequest, data), |
526 ])) | 503 ])) |
527 .then(() => device.close()); | 504 .then(() => device.close()); |
528 }); | 505 }); |
529 }, 'requests to interfaces and endpoint require an interface claim'); | 506 }, 'requests to interfaces and endpoint require an interface claim'); |
530 | 507 |
531 usb_test(() => { | 508 usb_test(usb => { |
532 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 509 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
533 | |
534 return navigator.usb.getDevices().then(devices => { | 510 return navigator.usb.getDevices().then(devices => { |
535 assert_equals(devices.length, 1); | 511 assert_equals(devices.length, 1); |
536 let device = devices[0]; | 512 let device = devices[0]; |
537 return device.open() | 513 return device.open() |
538 .then(() => device.selectConfiguration(1)) | 514 .then(() => device.selectConfiguration(1)) |
539 .then(() => device.claimInterface(0)) | 515 .then(() => device.claimInterface(0)) |
540 .then(() => device.clearHalt('in', 1)) | 516 .then(() => device.clearHalt('in', 1)) |
541 .then(() => device.close()); | 517 .then(() => device.close()); |
542 }); | 518 }); |
543 }, 'can clear a halt condition'); | 519 }, 'can clear a halt condition'); |
544 | 520 |
545 usb_test(() => { | 521 usb_test(usb => { |
546 let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); | 522 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
547 | |
548 return navigator.usb.getDevices().then(devices => { | 523 return navigator.usb.getDevices().then(devices => { |
549 assert_equals(devices.length, 1); | 524 assert_equals(devices.length, 1); |
550 let device = devices[0]; | 525 let device = devices[0]; |
551 return device.open() | 526 return device.open() |
552 .then(() => device.selectConfiguration(1)) | 527 .then(() => device.selectConfiguration(1)) |
553 .then(() => device.claimInterface(0)) | 528 .then(() => device.claimInterface(0)) |
554 .then(() => { | 529 .then(() => { |
555 navigator.usb.test.removeFakeDevice(guid); | 530 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
556 return assertRejectsWithNotFoundError(device.clearHalt('in', 1)); | 531 return assertRejectsWithNotFoundError(device.clearHalt('in', 1)); |
557 }); | 532 }); |
558 }); | 533 }); |
559 }, 'clearHalt rejects when called on a disconnected device'); | 534 }, 'clearHalt rejects when called on a disconnected device'); |
560 | 535 |
561 usb_test(() => { | 536 usb_test(usb => { |
562 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 537 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
563 | |
564 return navigator.usb.getDevices().then(devices => { | 538 return navigator.usb.getDevices().then(devices => { |
565 assert_equals(devices.length, 1); | 539 assert_equals(devices.length, 1); |
566 let device = devices[0]; | 540 let device = devices[0]; |
567 let data = new DataView(new ArrayBuffer(1024)); | 541 let data = new DataView(new ArrayBuffer(1024)); |
568 for (let i = 0; i < 1024; ++i) | 542 for (let i = 0; i < 1024; ++i) |
569 data.setUint8(i, i & 0xff); | 543 data.setUint8(i, i & 0xff); |
570 const notFoundMessage = 'The specified endpoint is not part of a claimed ' + | 544 const notFoundMessage = 'The specified endpoint is not part of a claimed ' + |
571 'and selected alternate interface.'; | 545 'and selected alternate interface.'; |
572 const rangeError = 'The specified endpoint number is out of range.'; | 546 const rangeError = 'The specified endpoint number is out of range.'; |
573 return device.open() | 547 return device.open() |
574 .then(() => device.selectConfiguration(1)) | 548 .then(() => device.selectConfiguration(1)) |
575 .then(() => device.claimInterface(0)) | 549 .then(() => device.claimInterface(0)) |
576 .then(() => Promise.all([ | 550 .then(() => Promise.all([ |
577 assertRejectsWithError(device.transferIn(2, 8), | 551 assertRejectsWithError(device.transferIn(2, 8), |
578 'NotFoundError', notFoundMessage), // Unclaimed | 552 'NotFoundError', notFoundMessage), // Unclaimed |
579 assertRejectsWithError(device.transferIn(3, 8), 'NotFoundError', | 553 assertRejectsWithError(device.transferIn(3, 8), 'NotFoundError', |
580 notFoundMessage), // Non-existent | 554 notFoundMessage), // Non-existent |
581 assertRejectsWithError( | 555 assertRejectsWithError( |
582 device.transferIn(16, 8), 'IndexSizeError', rangeError), | 556 device.transferIn(16, 8), 'IndexSizeError', rangeError), |
583 assertRejectsWithError(device.transferOut(2, data), | 557 assertRejectsWithError(device.transferOut(2, data), |
584 'NotFoundError', notFoundMessage), // Unclaimed | 558 'NotFoundError', notFoundMessage), // Unclaimed |
585 assertRejectsWithError(device.transferOut(3, data), 'NotFoundError', | 559 assertRejectsWithError(device.transferOut(3, data), 'NotFoundError', |
586 notFoundMessage), // Non-existent | 560 notFoundMessage), // Non-existent |
587 assertRejectsWithError( | 561 assertRejectsWithError( |
588 device.transferOut(16, data), 'IndexSizeError', rangeError), | 562 device.transferOut(16, data), 'IndexSizeError', rangeError), |
589 ])); | 563 ])); |
590 }); | 564 }); |
591 }, 'transfers to unavailable endpoints are rejected'); | 565 }, 'transfers to unavailable endpoints are rejected'); |
592 | 566 |
593 usb_test(() => { | 567 usb_test(usb => { |
594 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 568 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
595 | |
596 return navigator.usb.getDevices().then(devices => { | 569 return navigator.usb.getDevices().then(devices => { |
597 assert_equals(devices.length, 1); | 570 assert_equals(devices.length, 1); |
598 let device = devices[0]; | 571 let device = devices[0]; |
599 return device.open() | 572 return device.open() |
600 .then(() => device.selectConfiguration(1)) | 573 .then(() => device.selectConfiguration(1)) |
601 .then(() => device.claimInterface(0)) | 574 .then(() => device.claimInterface(0)) |
602 .then(() => device.transferIn(1, 8)) | 575 .then(() => device.transferIn(1, 8)) |
603 .then(result => { | 576 .then(result => { |
604 assert_true(result instanceof USBInTransferResult); | 577 assert_true(result instanceof USBInTransferResult); |
605 assert_equals(result.status, 'ok'); | 578 assert_equals(result.status, 'ok'); |
606 assert_equals(result.data.byteLength, 8); | 579 assert_equals(result.data.byteLength, 8); |
607 for (let i = 0; i < 8; ++i) | 580 for (let i = 0; i < 8; ++i) |
608 assert_equals(result.data.getUint8(i), i, 'mismatch at byte ' + i); | 581 assert_equals(result.data.getUint8(i), i, 'mismatch at byte ' + i); |
609 return device.close(); | 582 return device.close(); |
610 }); | 583 }); |
611 }); | 584 }); |
612 }, 'can issue IN interrupt transfer'); | 585 }, 'can issue IN interrupt transfer'); |
613 | 586 |
614 usb_test(() => { | 587 usb_test(usb => { |
615 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 588 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
616 | |
617 return navigator.usb.getDevices().then(devices => { | 589 return navigator.usb.getDevices().then(devices => { |
618 assert_equals(devices.length, 1); | 590 assert_equals(devices.length, 1); |
619 let device = devices[0]; | 591 let device = devices[0]; |
620 return device.open() | 592 return device.open() |
621 .then(() => device.selectConfiguration(1)) | 593 .then(() => device.selectConfiguration(1)) |
622 .then(() => device.claimInterface(1)) | 594 .then(() => device.claimInterface(1)) |
623 .then(() => device.transferIn(2, 1024)) | 595 .then(() => device.transferIn(2, 1024)) |
624 .then(result => { | 596 .then(result => { |
625 assert_true(result instanceof USBInTransferResult); | 597 assert_true(result instanceof USBInTransferResult); |
626 assert_equals(result.status, 'ok'); | 598 assert_equals(result.status, 'ok'); |
627 assert_equals(result.data.byteLength, 1024); | 599 assert_equals(result.data.byteLength, 1024); |
628 for (let i = 0; i < 1024; ++i) | 600 for (let i = 0; i < 1024; ++i) |
629 assert_equals(result.data.getUint8(i), i & 0xff, | 601 assert_equals(result.data.getUint8(i), i & 0xff, |
630 'mismatch at byte ' + i); | 602 'mismatch at byte ' + i); |
631 return device.close(); | 603 return device.close(); |
632 }); | 604 }); |
633 }); | 605 }); |
634 }, 'can issue IN bulk transfer'); | 606 }, 'can issue IN bulk transfer'); |
635 | 607 |
636 usb_test(() => { | 608 usb_test(usb => { |
637 let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); | 609 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
638 | |
639 return navigator.usb.getDevices().then(devices => { | 610 return navigator.usb.getDevices().then(devices => { |
640 assert_equals(devices.length, 1); | 611 assert_equals(devices.length, 1); |
641 let device = devices[0]; | 612 let device = devices[0]; |
642 return device.open() | 613 return device.open() |
643 .then(() => device.selectConfiguration(1)) | 614 .then(() => device.selectConfiguration(1)) |
644 .then(() => device.claimInterface(1)) | 615 .then(() => device.claimInterface(1)) |
645 .then(() => { | 616 .then(() => { |
646 navigator.usb.test.removeFakeDevice(guid); | 617 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
647 return assertRejectsWithNotFoundError(device.transferIn(2, 1024)); | 618 return assertRejectsWithNotFoundError(device.transferIn(2, 1024)); |
648 }); | 619 }); |
649 }); | 620 }); |
650 }, 'transferIn rejects if called on a disconnected device'); | 621 }, 'transferIn rejects if called on a disconnected device'); |
651 | 622 |
652 usb_test(() => { | 623 usb_test(usb => { |
653 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 624 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
654 | |
655 return navigator.usb.getDevices().then(devices => { | 625 return navigator.usb.getDevices().then(devices => { |
656 assert_equals(devices.length, 1); | 626 assert_equals(devices.length, 1); |
657 let device = devices[0]; | 627 let device = devices[0]; |
658 return device.open() | 628 return device.open() |
659 .then(() => device.selectConfiguration(1)) | 629 .then(() => device.selectConfiguration(1)) |
660 .then(() => device.claimInterface(1)) | 630 .then(() => device.claimInterface(1)) |
661 .then(() => { | 631 .then(() => { |
662 let data = new DataView(new ArrayBuffer(1024)); | 632 let data = new DataView(new ArrayBuffer(1024)); |
663 for (let i = 0; i < 1024; ++i) | 633 for (let i = 0; i < 1024; ++i) |
664 data.setUint8(i, i & 0xff); | 634 data.setUint8(i, i & 0xff); |
665 return device.transferOut(2, data); | 635 return device.transferOut(2, data); |
666 }) | 636 }) |
667 .then(result => { | 637 .then(result => { |
668 assert_true(result instanceof USBOutTransferResult); | 638 assert_true(result instanceof USBOutTransferResult); |
669 assert_equals(result.status, 'ok'); | 639 assert_equals(result.status, 'ok'); |
670 assert_equals(result.bytesWritten, 1024); | 640 assert_equals(result.bytesWritten, 1024); |
671 return device.close(); | 641 return device.close(); |
672 }); | 642 }); |
673 }); | 643 }); |
674 }, 'can issue OUT bulk transfer'); | 644 }, 'can issue OUT bulk transfer'); |
675 | 645 |
676 usb_test(() => { | 646 usb_test(usb => { |
677 let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); | 647 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
678 | |
679 return navigator.usb.getDevices().then(devices => { | 648 return navigator.usb.getDevices().then(devices => { |
680 assert_equals(devices.length, 1); | 649 assert_equals(devices.length, 1); |
681 let device = devices[0]; | 650 let device = devices[0]; |
682 return device.open() | 651 return device.open() |
683 .then(() => device.selectConfiguration(1)) | 652 .then(() => device.selectConfiguration(1)) |
684 .then(() => device.claimInterface(1)) | 653 .then(() => device.claimInterface(1)) |
685 .then(() => { | 654 .then(() => { |
686 let data = new DataView(new ArrayBuffer(1024)); | 655 let data = new DataView(new ArrayBuffer(1024)); |
687 for (let i = 0; i < 1024; ++i) | 656 for (let i = 0; i < 1024; ++i) |
688 data.setUint8(i, i & 0xff); | 657 data.setUint8(i, i & 0xff); |
689 navigator.usb.test.removeFakeDevice(guid); | 658 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
690 return assertRejectsWithNotFoundError(device.transferOut(2, data)); | 659 return assertRejectsWithNotFoundError(device.transferOut(2, data)); |
691 }); | 660 }); |
692 }); | 661 }); |
693 }, 'transferOut rejects if called on a disconnected device'); | 662 }, 'transferOut rejects if called on a disconnected device'); |
694 | 663 |
695 usb_test(() => { | 664 usb_test(usb => { |
696 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 665 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
697 | |
698 return navigator.usb.getDevices().then(devices => { | 666 return navigator.usb.getDevices().then(devices => { |
699 assert_equals(devices.length, 1); | 667 assert_equals(devices.length, 1); |
700 let device = devices[0]; | 668 let device = devices[0]; |
701 return device.open() | 669 return device.open() |
702 .then(() => device.selectConfiguration(2)) | 670 .then(() => device.selectConfiguration(2)) |
703 .then(() => device.claimInterface(0)) | 671 .then(() => device.claimInterface(0)) |
704 .then(() => device.selectAlternateInterface(0, 1)) | 672 .then(() => device.selectAlternateInterface(0, 1)) |
705 .then(() => device.isochronousTransferIn( | 673 .then(() => device.isochronousTransferIn( |
706 1, [64, 64, 64, 64, 64, 64, 64, 64])) | 674 1, [64, 64, 64, 64, 64, 64, 64, 64])) |
707 .then(result => { | 675 .then(result => { |
(...skipping 11 matching lines...) Expand all Loading... |
719 for (let j = 0; j < 64; ++j) | 687 for (let j = 0; j < 64; ++j) |
720 assert_equals(result.packets[i].data.getUint8(j), j & 0xff, | 688 assert_equals(result.packets[i].data.getUint8(j), j & 0xff, |
721 'mismatch at byte ' + j + ' of packet ' + i); | 689 'mismatch at byte ' + j + ' of packet ' + i); |
722 byteOffset += result.packets[i].data.byteLength; | 690 byteOffset += result.packets[i].data.byteLength; |
723 } | 691 } |
724 return device.close(); | 692 return device.close(); |
725 }); | 693 }); |
726 }); | 694 }); |
727 }, 'can issue IN isochronous transfer'); | 695 }, 'can issue IN isochronous transfer'); |
728 | 696 |
729 usb_test(() => { | 697 usb_test(usb => { |
730 let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); | 698 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
731 | |
732 return navigator.usb.getDevices().then(devices => { | 699 return navigator.usb.getDevices().then(devices => { |
733 assert_equals(devices.length, 1); | 700 assert_equals(devices.length, 1); |
734 let device = devices[0]; | 701 let device = devices[0]; |
735 return device.open() | 702 return device.open() |
736 .then(() => device.selectConfiguration(2)) | 703 .then(() => device.selectConfiguration(2)) |
737 .then(() => device.claimInterface(0)) | 704 .then(() => device.claimInterface(0)) |
738 .then(() => device.selectAlternateInterface(0, 1)) | 705 .then(() => device.selectAlternateInterface(0, 1)) |
739 .then(() => { | 706 .then(() => { |
740 navigator.usb.test.removeFakeDevice(guid); | 707 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
741 return assertRejectsWithNotFoundError(device.isochronousTransferIn( | 708 return assertRejectsWithNotFoundError(device.isochronousTransferIn( |
742 1, [64, 64, 64, 64, 64, 64, 64, 64])); | 709 1, [64, 64, 64, 64, 64, 64, 64, 64])); |
743 }); | 710 }); |
744 }); | 711 }); |
745 }, 'isochronousTransferIn rejects when called on a disconnected device'); | 712 }, 'isochronousTransferIn rejects when called on a disconnected device'); |
746 | 713 |
747 usb_test(() => { | 714 usb_test(usb => { |
748 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 715 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
749 | |
750 return navigator.usb.getDevices().then(devices => { | 716 return navigator.usb.getDevices().then(devices => { |
751 assert_equals(devices.length, 1); | 717 assert_equals(devices.length, 1); |
752 let device = devices[0]; | 718 let device = devices[0]; |
753 return device.open() | 719 return device.open() |
754 .then(() => device.selectConfiguration(2)) | 720 .then(() => device.selectConfiguration(2)) |
755 .then(() => device.claimInterface(0)) | 721 .then(() => device.claimInterface(0)) |
756 .then(() => device.selectAlternateInterface(0, 1)) | 722 .then(() => device.selectAlternateInterface(0, 1)) |
757 .then(() => { | 723 .then(() => { |
758 let data = new DataView(new ArrayBuffer(64 * 8)); | 724 let data = new DataView(new ArrayBuffer(64 * 8)); |
759 for (let i = 0; i < 8; ++i) { | 725 for (let i = 0; i < 8; ++i) { |
(...skipping 11 matching lines...) Expand all Loading... |
771 assert_true( | 737 assert_true( |
772 result.packets[i] instanceof USBIsochronousOutTransferPacket); | 738 result.packets[i] instanceof USBIsochronousOutTransferPacket); |
773 assert_equals(result.packets[i].status, 'ok'); | 739 assert_equals(result.packets[i].status, 'ok'); |
774 assert_equals(result.packets[i].bytesWritten, 64); | 740 assert_equals(result.packets[i].bytesWritten, 64); |
775 } | 741 } |
776 return device.close(); | 742 return device.close(); |
777 }); | 743 }); |
778 }); | 744 }); |
779 }, 'can issue OUT isochronous transfer'); | 745 }, 'can issue OUT isochronous transfer'); |
780 | 746 |
781 usb_test(() => { | 747 usb_test(usb => { |
782 let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); | 748 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
783 | |
784 return navigator.usb.getDevices().then(devices => { | 749 return navigator.usb.getDevices().then(devices => { |
785 assert_equals(devices.length, 1); | 750 assert_equals(devices.length, 1); |
786 let device = devices[0]; | 751 let device = devices[0]; |
787 return device.open() | 752 return device.open() |
788 .then(() => device.selectConfiguration(2)) | 753 .then(() => device.selectConfiguration(2)) |
789 .then(() => device.claimInterface(0)) | 754 .then(() => device.claimInterface(0)) |
790 .then(() => device.selectAlternateInterface(0, 1)) | 755 .then(() => device.selectAlternateInterface(0, 1)) |
791 .then(() => { | 756 .then(() => { |
792 let data = new DataView(new ArrayBuffer(64 * 8)); | 757 let data = new DataView(new ArrayBuffer(64 * 8)); |
793 for (let i = 0; i < 8; ++i) { | 758 for (let i = 0; i < 8; ++i) { |
794 for (let j = 0; j < 64; ++j) | 759 for (let j = 0; j < 64; ++j) |
795 data.setUint8(i * j, j & 0xff); | 760 data.setUint8(i * j, j & 0xff); |
796 } | 761 } |
797 navigator.usb.test.removeFakeDevice(guid); | 762 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
798 return assertRejectsWithNotFoundError(device.isochronousTransferOut( | 763 return assertRejectsWithNotFoundError(device.isochronousTransferOut( |
799 1, data, [64, 64, 64, 64, 64, 64, 64, 64])); | 764 1, data, [64, 64, 64, 64, 64, 64, 64, 64])); |
800 }); | 765 }); |
801 }); | 766 }); |
802 }, 'isochronousTransferOut rejects when called on a disconnected device'); | 767 }, 'isochronousTransferOut rejects when called on a disconnected device'); |
803 | 768 |
804 usb_test(() => { | 769 usb_test(usb => { |
805 navigator.usb.test.addFakeDevice(fakeDeviceInit); | 770 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
806 | |
807 return navigator.usb.getDevices().then(devices => { | 771 return navigator.usb.getDevices().then(devices => { |
808 assert_equals(1, devices.length); | 772 assert_equals(1, devices.length); |
809 let device = devices[0]; | 773 let device = devices[0]; |
810 return device.open().then(() => device.reset()).then(() => device.close()); | 774 return device.open().then(() => device.reset()).then(() => device.close()); |
811 }); | 775 }); |
812 }, 'can reset the device'); | 776 }, 'can reset the device'); |
813 | 777 |
814 usb_test(() => { | 778 usb_test(usb => { |
815 let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); | 779 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
816 | |
817 return navigator.usb.getDevices().then(devices => { | 780 return navigator.usb.getDevices().then(devices => { |
818 assert_equals(1, devices.length); | 781 assert_equals(1, devices.length); |
819 let device = devices[0]; | 782 let device = devices[0]; |
820 return device.open().then(() => { | 783 return device.open().then(() => { |
821 navigator.usb.test.removeFakeDevice(guid); | 784 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
822 return assertRejectsWithNotFoundError(device.reset()); | 785 return assertRejectsWithNotFoundError(device.reset()); |
823 }); | 786 }); |
824 }); | 787 }); |
825 }, 'resetDevice rejects when called on a disconnected device'); | 788 }, 'resetDevice rejects when called on a disconnected device'); |
826 </script> | 789 </script> |
OLD | NEW |