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