| Index: third_party/WebKit/LayoutTests/usb/usbDevice.html
|
| diff --git a/third_party/WebKit/LayoutTests/usb/usbDevice.html b/third_party/WebKit/LayoutTests/usb/usbDevice.html
|
| index bd71cc6be4028981c939ed326a3f5a2cb1023014..722f2dbdc0d97ba482d8db65970743024606f9d7 100644
|
| --- a/third_party/WebKit/LayoutTests/usb/usbDevice.html
|
| +++ b/third_party/WebKit/LayoutTests/usb/usbDevice.html
|
| @@ -7,14 +7,25 @@
|
| <script>
|
| 'use strict';
|
|
|
| -function assertRejectsWithNotFoundError(promise) {
|
| +function assertRejectsWithError(promise, name, message) {
|
| return promise.then(() => {
|
| - assert_unreached('promise should reject');
|
| + assert_unreached('expected promise to reject with ' + name);
|
| }, error => {
|
| - assert_equals(error.code, DOMException.NOT_FOUND_ERR);
|
| + assert_equals(error.name, name);
|
| + if (message !== undefined)
|
| + assert_equals(error.message, message);
|
| });
|
| }
|
|
|
| +function assertRejectsWithNotFoundError(promise) {
|
| + return assertRejectsWithError(promise, 'NotFoundError');
|
| +}
|
| +
|
| +function assertRejectsWithNotOpenError(promise) {
|
| + return assertRejectsWithError(
|
| + promise, 'InvalidStateError', 'The device must be open()ed first.')
|
| +}
|
| +
|
| usb_test(usb => {
|
| usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
|
| return navigator.usb.getDevices().then(devices => {
|
| @@ -29,7 +40,13 @@ usb_test(usb => {
|
| return navigator.usb.getDevices().then(devices => {
|
| assert_equals(1, devices.length);
|
| let device = devices[0];
|
| - return device.open().then(() => device.close());
|
| + assert_false(device.opened);
|
| + return device.open().then(() => {
|
| + assert_true(device.opened);
|
| + return device.close().then(() => {
|
| + assert_false(device.opened);
|
| + });
|
| + });
|
| });
|
| }, 'a device can be opened and closed');
|
|
|
| @@ -38,6 +55,43 @@ usb_test(usb => {
|
| return navigator.usb.getDevices().then(devices => {
|
| assert_equals(1, devices.length);
|
| let device = devices[0];
|
| + return device.open()
|
| + .then(() => device.open())
|
| + .then(() => device.open())
|
| + .then(() => device.open())
|
| + .then(() => device.close())
|
| + .then(() => device.close())
|
| + .then(() => device.close())
|
| + .then(() => device.close());
|
| + });
|
| +}, 'open and close can be called multiple times');
|
| +
|
| +usb_test(usb => {
|
| + usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
|
| + return navigator.usb.getDevices().then(devices => {
|
| + assert_equals(1, devices.length);
|
| + let device = devices[0];
|
| + return Promise.all([
|
| + device.open(),
|
| + assertRejectsWithError(device.open(), 'InvalidStateError',
|
| + 'An open() or close() task is in progress.'),
|
| + assertRejectsWithError(device.close(), 'InvalidStateError',
|
| + 'An open() or close() task is in progress.'),
|
| + ]).then(() => Promise.all([
|
| + device.close(),
|
| + assertRejectsWithError(device.open(), 'InvalidStateError',
|
| + 'An open() or close() task is in progress.'),
|
| + assertRejectsWithError(device.close(), 'InvalidStateError',
|
| + 'An open() or close() task is in progress.'),
|
| + ]));
|
| + });
|
| +}, 'open and close cannot be called again while open or close are in progress');
|
| +
|
| +usb_test(usb => {
|
| + usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
|
| + return navigator.usb.getDevices().then(devices => {
|
| + assert_equals(1, devices.length);
|
| + let device = devices[0];
|
| return device.open().then(() => {
|
| usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]);
|
| return assertRejectsWithNotFoundError(device.close());
|
| @@ -62,6 +116,42 @@ usb_test(usb => {
|
| usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
|
| return navigator.usb.getDevices().then(devices => {
|
| assert_equals(1, devices.length);
|
| + var device = devices[0];
|
| + return Promise.all([
|
| + assertRejectsWithNotOpenError(device.setConfiguration(1)),
|
| + assertRejectsWithNotOpenError(device.claimInterface(0)),
|
| + assertRejectsWithNotOpenError(device.releaseInterface(0)),
|
| + assertRejectsWithNotOpenError(device.setInterface(0, 1)),
|
| + assertRejectsWithNotOpenError(device.controlTransferIn({
|
| + requestType: 'vendor',
|
| + recipient: 'device',
|
| + request: 0x42,
|
| + value: 0x1234,
|
| + index: 0x5678
|
| + }, 7)),
|
| + assertRejectsWithNotOpenError(device.controlTransferOut({
|
| + requestType: 'vendor',
|
| + recipient: 'device',
|
| + request: 0x42,
|
| + value: 0x1234,
|
| + index: 0x5678
|
| + }, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]))),
|
| + assertRejectsWithNotOpenError(device.clearHalt(1)),
|
| + assertRejectsWithNotOpenError(device.transferIn(1, 8)),
|
| + assertRejectsWithNotOpenError(
|
| + device.transferOut(1, new ArrayBuffer(8))),
|
| + assertRejectsWithNotOpenError(device.isochronousTransferIn(1, [8])),
|
| + assertRejectsWithNotOpenError(
|
| + device.isochronousTransferOut(1, new ArrayBuffer(8), [8])),
|
| + assertRejectsWithNotOpenError(device.reset())
|
| + ]);
|
| + });
|
| +}, 'methods requiring it reject when the device is not open');
|
| +
|
| +usb_test(usb => {
|
| + usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
|
| + return navigator.usb.getDevices().then(devices => {
|
| + assert_equals(1, devices.length);
|
| let device = devices[0];
|
| return device.open()
|
| .then(() => device.setConfiguration(1))
|
| @@ -97,14 +187,8 @@ usb_test(usb => {
|
| assert_equals(devices.length, 1);
|
| let device = devices[0];
|
| return device.open()
|
| - .then(() => device.getConfiguration()
|
| - .then(() => {
|
| - assert_unreached('getConfiguration should reject');
|
| - })
|
| - .catch(error => {
|
| - assert_equals(error.code, DOMException.NOT_FOUND_ERR);
|
| - return Promise.resolve();
|
| - }))
|
| + .then(() =>
|
| + assertRejectsWithError(device.getConfiguration(), 'NotFoundError'))
|
| .then(() => device.close());
|
| });
|
| }, 'querying an unset configuration raises NotFoundError');
|
| @@ -128,15 +212,9 @@ usb_test(usb => {
|
| assert_equals(1, devices.length);
|
| let device = devices[0];
|
| return device.open()
|
| - .then(() => device.claimInterface(0)
|
| - .then(() => {
|
| - assert_unreached('claimInterface should reject');
|
| - })
|
| - .catch(error => {
|
| + .then(() =>
|
| // TODO(reillyg): This should be INVALID_STATE_ERR.
|
| - assert_equals(error.code, DOMException.NETWORK_ERR);
|
| - return Promise.resolve();
|
| - }))
|
| + assertRejectsWithError(device.claimInterface(0), 'NetworkError'))
|
| .then(() => device.close());
|
| });
|
| }, 'claiming an interface fails without an active configuration');
|
|
|