| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
| 3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
| 4 <script src="../resources/mojo-helpers.js"></script> | 4 <script src="../resources/mojo-helpers.js"></script> |
| 5 <script src="resources/fake-devices.js"></script> | 5 <script src="resources/fake-devices.js"></script> |
| 6 <script src="resources/usb-helpers.js"></script> | 6 <script src="resources/usb-helpers.js"></script> |
| 7 <script> | 7 <script> |
| 8 'use strict'; | 8 'use strict'; |
| 9 | 9 |
| 10 function assertRejectsWithError(promise, name, message) { | 10 function assertRejectsWithError(promise, name, message) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 value: 0x1234, | 133 value: 0x1234, |
| 134 index: 0x5678 | 134 index: 0x5678 |
| 135 }, 7)), | 135 }, 7)), |
| 136 assertRejectsWithNotOpenError(device.controlTransferOut({ | 136 assertRejectsWithNotOpenError(device.controlTransferOut({ |
| 137 requestType: 'vendor', | 137 requestType: 'vendor', |
| 138 recipient: 'device', | 138 recipient: 'device', |
| 139 request: 0x42, | 139 request: 0x42, |
| 140 value: 0x1234, | 140 value: 0x1234, |
| 141 index: 0x5678 | 141 index: 0x5678 |
| 142 }, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]))), | 142 }, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]))), |
| 143 assertRejectsWithNotOpenError(device.clearHalt(1)), | 143 assertRejectsWithNotOpenError(device.clearHalt('in', 1)), |
| 144 assertRejectsWithNotOpenError(device.transferIn(1, 8)), | 144 assertRejectsWithNotOpenError(device.transferIn(1, 8)), |
| 145 assertRejectsWithNotOpenError( | 145 assertRejectsWithNotOpenError( |
| 146 device.transferOut(1, new ArrayBuffer(8))), | 146 device.transferOut(1, new ArrayBuffer(8))), |
| 147 assertRejectsWithNotOpenError(device.isochronousTransferIn(1, [8])), | 147 assertRejectsWithNotOpenError(device.isochronousTransferIn(1, [8])), |
| 148 assertRejectsWithNotOpenError( | 148 assertRejectsWithNotOpenError( |
| 149 device.isochronousTransferOut(1, new ArrayBuffer(8), [8])), | 149 device.isochronousTransferOut(1, new ArrayBuffer(8), [8])), |
| 150 assertRejectsWithNotOpenError(device.reset()) | 150 assertRejectsWithNotOpenError(device.reset()) |
| 151 ]); | 151 ]); |
| 152 }); | 152 }); |
| 153 }, 'methods requiring it reject when the device is not open'); | 153 }, 'methods requiring it reject when the device is not open'); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 value: 0x1234, | 203 value: 0x1234, |
| 204 index: 0x5678 | 204 index: 0x5678 |
| 205 }, 7)), | 205 }, 7)), |
| 206 assertRejectsWithNotConfiguredError(device.controlTransferOut({ | 206 assertRejectsWithNotConfiguredError(device.controlTransferOut({ |
| 207 requestType: 'vendor', | 207 requestType: 'vendor', |
| 208 recipient: 'device', | 208 recipient: 'device', |
| 209 request: 0x42, | 209 request: 0x42, |
| 210 value: 0x1234, | 210 value: 0x1234, |
| 211 index: 0x5678 | 211 index: 0x5678 |
| 212 }, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]))), | 212 }, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]))), |
| 213 assertRejectsWithNotConfiguredError(device.clearHalt(1)), | 213 assertRejectsWithNotConfiguredError(device.clearHalt('in', 1)), |
| 214 assertRejectsWithNotConfiguredError(device.transferIn(1, 8)), | 214 assertRejectsWithNotConfiguredError(device.transferIn(1, 8)), |
| 215 assertRejectsWithNotConfiguredError( | 215 assertRejectsWithNotConfiguredError( |
| 216 device.transferOut(1, new ArrayBuffer(8))), | 216 device.transferOut(1, new ArrayBuffer(8))), |
| 217 assertRejectsWithNotConfiguredError( | 217 assertRejectsWithNotConfiguredError( |
| 218 device.isochronousTransferIn(1, [8])), | 218 device.isochronousTransferIn(1, [8])), |
| 219 assertRejectsWithNotConfiguredError( | 219 assertRejectsWithNotConfiguredError( |
| 220 device.isochronousTransferOut(1, new ArrayBuffer(8), [8])), | 220 device.isochronousTransferOut(1, new ArrayBuffer(8), [8])), |
| 221 ])).then(() => device.close()); | 221 ])).then(() => device.close()); |
| 222 }); | 222 }); |
| 223 }, 'methods requiring it reject when the device is unconfigured'); | 223 }, 'methods requiring it reject when the device is unconfigured'); |
| 224 | 224 |
| 225 usb_test(usb => { | 225 usb_test(usb => { |
| 226 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); | 226 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
| 227 return navigator.usb.getDevices().then(devices => { | 227 return navigator.usb.getDevices().then(devices => { |
| 228 assert_equals(1, devices.length); | 228 assert_equals(1, devices.length); |
| 229 let device = devices[0]; | 229 let device = devices[0]; |
| 230 return device.open() | 230 return device.open() |
| 231 .then(() => device.selectConfiguration(1)) | 231 .then(() => device.selectConfiguration(1)) |
| 232 .then(() => device.claimInterface(0)) | 232 .then(() => device.claimInterface(0)) |
| 233 .then(() => device.releaseInterface(0)) | 233 .then(() => device.releaseInterface(0)) |
| 234 .then(() => device.close()); | 234 .then(() => device.close()); |
| 235 }); | 235 }); |
| 236 }, 'an interface can be claimed and released'); | 236 }, 'an interface can be claimed and released'); |
| 237 | 237 |
| 238 usb_test(usb => { | 238 usb_test(usb => { |
| 239 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); | 239 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
| 240 return navigator.usb.getDevices().then(devices => { | 240 return navigator.usb.getDevices().then(devices => { |
| 241 assert_equals(1, devices.length); | 241 assert_equals(1, devices.length); |
| 242 let device = devices[0]; |
| 243 const message = 'The interface number provided is not supported by the ' + |
| 244 'device in its current configuration.'; |
| 245 return device.open() |
| 246 .then(() => device.selectConfiguration(1)) |
| 247 .then(() => Promise.all([ |
| 248 assertRejectsWithError( |
| 249 device.claimInterface(2), 'NotFoundError', message), |
| 250 assertRejectsWithError( |
| 251 device.releaseInterface(2), 'NotFoundError', message), |
| 252 ])) |
| 253 .then(() => device.close()); |
| 254 }); |
| 255 }, 'a non-existent interface cannot be claimed or released'); |
| 256 |
| 257 |
| 258 usb_test(usb => { |
| 259 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
| 260 return navigator.usb.getDevices().then(devices => { |
| 261 assert_equals(1, devices.length); |
| 242 var device = devices[0]; | 262 var device = devices[0]; |
| 243 return device.open() | 263 return device.open() |
| 244 .then(() => device.selectConfiguration(1)) | 264 .then(() => device.selectConfiguration(1)) |
| 245 .then(() => { | 265 .then(() => { |
| 246 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); | 266 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
| 247 return assertRejectsWithNotFoundError(device.claimInterface(0)); | 267 return assertRejectsWithNotFoundError(device.claimInterface(0)); |
| 248 }); | 268 }); |
| 249 }); | 269 }); |
| 250 }, 'claimInterface rejects when called on a disconnected device'); | 270 }, 'claimInterface rejects when called on a disconnected device'); |
| 251 | 271 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 }, 'controlTransferOut rejects when called on a disconnected device'); | 403 }, 'controlTransferOut rejects when called on a disconnected device'); |
| 384 | 404 |
| 385 usb_test(usb => { | 405 usb_test(usb => { |
| 386 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); | 406 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
| 387 return navigator.usb.getDevices().then(devices => { | 407 return navigator.usb.getDevices().then(devices => { |
| 388 assert_equals(devices.length, 1); | 408 assert_equals(devices.length, 1); |
| 389 let device = devices[0]; | 409 let device = devices[0]; |
| 390 return device.open() | 410 return device.open() |
| 391 .then(() => device.selectConfiguration(1)) | 411 .then(() => device.selectConfiguration(1)) |
| 392 .then(() => device.claimInterface(0)) | 412 .then(() => device.claimInterface(0)) |
| 393 .then(() => device.clearHalt(1)) | 413 .then(() => device.clearHalt('in', 1)) |
| 394 .then(() => device.close()); | 414 .then(() => device.close()); |
| 395 }); | 415 }); |
| 396 }, 'can clear a halt condition'); | 416 }, 'can clear a halt condition'); |
| 397 | 417 |
| 398 usb_test(usb => { | 418 usb_test(usb => { |
| 399 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); | 419 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
| 400 return navigator.usb.getDevices().then(devices => { | 420 return navigator.usb.getDevices().then(devices => { |
| 401 assert_equals(devices.length, 1); | 421 assert_equals(devices.length, 1); |
| 402 let device = devices[0]; | 422 let device = devices[0]; |
| 403 return device.open() | 423 return device.open() |
| 404 .then(() => device.selectConfiguration(1)) | 424 .then(() => device.selectConfiguration(1)) |
| 405 .then(() => device.claimInterface(0)) | 425 .then(() => device.claimInterface(0)) |
| 406 .then(() => { | 426 .then(() => { |
| 407 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); | 427 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
| 408 return assertRejectsWithNotFoundError(device.clearHalt(1)); | 428 return assertRejectsWithNotFoundError(device.clearHalt('in', 1)); |
| 409 }); | 429 }); |
| 410 }); | 430 }); |
| 411 }, 'clearHalt rejects when called on a disconnected device'); | 431 }, 'clearHalt rejects when called on a disconnected device'); |
| 412 | 432 |
| 413 usb_test(usb => { | 433 usb_test(usb => { |
| 414 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); | 434 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
| 415 return navigator.usb.getDevices().then(devices => { | 435 return navigator.usb.getDevices().then(devices => { |
| 416 assert_equals(devices.length, 1); | 436 assert_equals(devices.length, 1); |
| 417 let device = devices[0]; | 437 let device = devices[0]; |
| 418 return device.open() | 438 return device.open() |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 return navigator.usb.getDevices().then(devices => { | 646 return navigator.usb.getDevices().then(devices => { |
| 627 assert_equals(1, devices.length); | 647 assert_equals(1, devices.length); |
| 628 let device = devices[0]; | 648 let device = devices[0]; |
| 629 return device.open().then(() => { | 649 return device.open().then(() => { |
| 630 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); | 650 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
| 631 return assertRejectsWithNotFoundError(device.reset()); | 651 return assertRejectsWithNotFoundError(device.reset()); |
| 632 }); | 652 }); |
| 633 }); | 653 }); |
| 634 }, 'resetDevice rejects when called on a disconnected device'); | 654 }, 'resetDevice rejects when called on a disconnected device'); |
| 635 </script> | 655 </script> |
| OLD | NEW |