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