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