| 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 assertRejectsWithNotFoundError(promise) { | 10 function assertRejectsWithNotFoundError(promise) { |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 value: 0x1234, | 404 value: 0x1234, |
| 405 index: 0x5678 | 405 index: 0x5678 |
| 406 }, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]))); | 406 }, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]))); |
| 407 }); | 407 }); |
| 408 }); | 408 }); |
| 409 }, 'controlTransferOut rejects when called on a disconnected device'); | 409 }, 'controlTransferOut rejects when called on a disconnected device'); |
| 410 | 410 |
| 411 usb_test(usb => { | 411 usb_test(usb => { |
| 412 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); | 412 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
| 413 return navigator.usb.getDevices().then(devices => { | 413 return navigator.usb.getDevices().then(devices => { |
| 414 assert_equals(1, devices.length); |
| 415 let device = devices[0]; |
| 416 let interfaceRequest = { |
| 417 requestType: 'vendor', |
| 418 recipient: 'interface', |
| 419 request: 0x42, |
| 420 value: 0x1234, |
| 421 index: 0x5600 // Last byte of index is interface number. |
| 422 }; |
| 423 let endpointRequest = { |
| 424 requestType: 'vendor', |
| 425 recipient: 'endpoint', |
| 426 request: 0x42, |
| 427 value: 0x1234, |
| 428 index: 0x5681 // Last byte of index is endpoint address. |
| 429 }; |
| 430 let data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); |
| 431 return device.open() |
| 432 .then(() => device.selectConfiguration(1)) |
| 433 .then(() => Promise.all([ |
| 434 assertRejectsWithError( |
| 435 device.controlTransferIn(interfaceRequest, 7), |
| 436 'InvalidStateError'), |
| 437 assertRejectsWithError( |
| 438 device.controlTransferIn(endpointRequest, 7), |
| 439 'NotFoundError'), |
| 440 assertRejectsWithError( |
| 441 device.controlTransferOut(interfaceRequest, data), |
| 442 'InvalidStateError'), |
| 443 assertRejectsWithError( |
| 444 device.controlTransferOut(endpointRequest, data), |
| 445 'NotFoundError'), |
| 446 ])) |
| 447 .then(() => device.claimInterface(0)) |
| 448 .then(() => Promise.all([ |
| 449 device.controlTransferIn(interfaceRequest, 7).then(result => { |
| 450 assert_true(result instanceof USBInTransferResult); |
| 451 assert_equals(result.status, 'ok'); |
| 452 assert_equals(result.data.byteLength, 7); |
| 453 assert_equals(result.data.getUint16(0), 0x07); |
| 454 assert_equals(result.data.getUint8(2), 0x42); |
| 455 assert_equals(result.data.getUint16(3), 0x1234); |
| 456 assert_equals(result.data.getUint16(5), 0x5600); |
| 457 }), |
| 458 device.controlTransferIn(endpointRequest, 7).then(result => { |
| 459 assert_true(result instanceof USBInTransferResult); |
| 460 assert_equals(result.status, 'ok'); |
| 461 assert_equals(result.data.byteLength, 7); |
| 462 assert_equals(result.data.getUint16(0), 0x07); |
| 463 assert_equals(result.data.getUint8(2), 0x42); |
| 464 assert_equals(result.data.getUint16(3), 0x1234); |
| 465 assert_equals(result.data.getUint16(5), 0x5681); |
| 466 }), |
| 467 device.controlTransferOut(interfaceRequest, data), |
| 468 device.controlTransferOut(endpointRequest, data), |
| 469 ])) |
| 470 .then(() => device.close()); |
| 471 }); |
| 472 }, 'requests to interfaces and endpoint require an interface claim'); |
| 473 |
| 474 usb_test(usb => { |
| 475 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
| 476 return navigator.usb.getDevices().then(devices => { |
| 414 assert_equals(devices.length, 1); | 477 assert_equals(devices.length, 1); |
| 415 let device = devices[0]; | 478 let device = devices[0]; |
| 416 return device.open() | 479 return device.open() |
| 417 .then(() => device.selectConfiguration(1)) | 480 .then(() => device.selectConfiguration(1)) |
| 418 .then(() => device.claimInterface(0)) | 481 .then(() => device.claimInterface(0)) |
| 419 .then(() => device.clearHalt('in', 1)) | 482 .then(() => device.clearHalt('in', 1)) |
| 420 .then(() => device.close()); | 483 .then(() => device.close()); |
| 421 }); | 484 }); |
| 422 }, 'can clear a halt condition'); | 485 }, 'can clear a halt condition'); |
| 423 | 486 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 434 return assertRejectsWithNotFoundError(device.clearHalt('in', 1)); | 497 return assertRejectsWithNotFoundError(device.clearHalt('in', 1)); |
| 435 }); | 498 }); |
| 436 }); | 499 }); |
| 437 }, 'clearHalt rejects when called on a disconnected device'); | 500 }, 'clearHalt rejects when called on a disconnected device'); |
| 438 | 501 |
| 439 usb_test(usb => { | 502 usb_test(usb => { |
| 440 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); | 503 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
| 441 return navigator.usb.getDevices().then(devices => { | 504 return navigator.usb.getDevices().then(devices => { |
| 442 assert_equals(devices.length, 1); | 505 assert_equals(devices.length, 1); |
| 443 let device = devices[0]; | 506 let device = devices[0]; |
| 507 let data = new DataView(new ArrayBuffer(1024)); |
| 508 for (let i = 0; i < 1024; ++i) |
| 509 data.setUint8(i, i & 0xff); |
| 510 const notFoundMessage = 'The specified endpoint is not part of a claimed ' + |
| 511 'and selected alternate interface.'; |
| 512 const rangeError = 'The specified endpoint number is out of range.'; |
| 513 return device.open() |
| 514 .then(() => device.selectConfiguration(1)) |
| 515 .then(() => device.claimInterface(0)) |
| 516 .then(() => Promise.all([ |
| 517 assertRejectsWithError(device.transferIn(2, 8), |
| 518 'NotFoundError', notFoundMessage), // Unclaimed |
| 519 assertRejectsWithError(device.transferIn(3, 8), 'NotFoundError', |
| 520 notFoundMessage), // Non-existent |
| 521 assertRejectsWithError( |
| 522 device.transferIn(16, 8), 'IndexSizeError', rangeError), |
| 523 assertRejectsWithError(device.transferOut(2, data), |
| 524 'NotFoundError', notFoundMessage), // Unclaimed |
| 525 assertRejectsWithError(device.transferOut(3, data), 'NotFoundError', |
| 526 notFoundMessage), // Non-existent |
| 527 assertRejectsWithError( |
| 528 device.transferOut(16, data), 'IndexSizeError', rangeError), |
| 529 ])); |
| 530 }); |
| 531 }, 'transfers to unavailable endpoints are rejected'); |
| 532 |
| 533 usb_test(usb => { |
| 534 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
| 535 return navigator.usb.getDevices().then(devices => { |
| 536 assert_equals(devices.length, 1); |
| 537 let device = devices[0]; |
| 444 return device.open() | 538 return device.open() |
| 445 .then(() => device.selectConfiguration(1)) | 539 .then(() => device.selectConfiguration(1)) |
| 446 .then(() => device.claimInterface(0)) | 540 .then(() => device.claimInterface(0)) |
| 447 .then(() => device.transferIn(1, 8)) | 541 .then(() => device.transferIn(1, 8)) |
| 448 .then(result => { | 542 .then(result => { |
| 449 assert_true(result instanceof USBInTransferResult); | 543 assert_true(result instanceof USBInTransferResult); |
| 450 assert_equals(result.status, 'ok'); | 544 assert_equals(result.status, 'ok'); |
| 451 assert_equals(result.data.byteLength, 8); | 545 assert_equals(result.data.byteLength, 8); |
| 452 for (let i = 0; i < 8; ++i) | 546 for (let i = 0; i < 8; ++i) |
| 453 assert_equals(result.data.getUint8(i), i, 'mismatch at byte ' + i); | 547 assert_equals(result.data.getUint8(i), i, 'mismatch at byte ' + i); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 return navigator.usb.getDevices().then(devices => { | 746 return navigator.usb.getDevices().then(devices => { |
| 653 assert_equals(1, devices.length); | 747 assert_equals(1, devices.length); |
| 654 let device = devices[0]; | 748 let device = devices[0]; |
| 655 return device.open().then(() => { | 749 return device.open().then(() => { |
| 656 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); | 750 usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
| 657 return assertRejectsWithNotFoundError(device.reset()); | 751 return assertRejectsWithNotFoundError(device.reset()); |
| 658 }); | 752 }); |
| 659 }); | 753 }); |
| 660 }, 'resetDevice rejects when called on a disconnected device'); | 754 }, 'resetDevice rejects when called on a disconnected device'); |
| 661 </script> | 755 </script> |
| OLD | NEW |