summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/usb/usbDevice.html
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/WebKit/LayoutTests/usb/usbDevice.html')
-rw-r--r--third_party/WebKit/LayoutTests/usb/usbDevice.html94
1 files changed, 94 insertions, 0 deletions
diff --git a/third_party/WebKit/LayoutTests/usb/usbDevice.html b/third_party/WebKit/LayoutTests/usb/usbDevice.html
index e611148..763228a 100644
--- a/third_party/WebKit/LayoutTests/usb/usbDevice.html
+++ b/third_party/WebKit/LayoutTests/usb/usbDevice.html
@@ -411,6 +411,69 @@ usb_test(usb => {
usb_test(usb => {
usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
return navigator.usb.getDevices().then(devices => {
+ assert_equals(1, devices.length);
+ let device = devices[0];
+ let interfaceRequest = {
+ requestType: 'vendor',
+ recipient: 'interface',
+ request: 0x42,
+ value: 0x1234,
+ index: 0x5600 // Last byte of index is interface number.
+ };
+ let endpointRequest = {
+ requestType: 'vendor',
+ recipient: 'endpoint',
+ request: 0x42,
+ value: 0x1234,
+ index: 0x5681 // Last byte of index is endpoint address.
+ };
+ let data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
+ return device.open()
+ .then(() => device.selectConfiguration(1))
+ .then(() => Promise.all([
+ assertRejectsWithError(
+ device.controlTransferIn(interfaceRequest, 7),
+ 'InvalidStateError'),
+ assertRejectsWithError(
+ device.controlTransferIn(endpointRequest, 7),
+ 'NotFoundError'),
+ assertRejectsWithError(
+ device.controlTransferOut(interfaceRequest, data),
+ 'InvalidStateError'),
+ assertRejectsWithError(
+ device.controlTransferOut(endpointRequest, data),
+ 'NotFoundError'),
+ ]))
+ .then(() => device.claimInterface(0))
+ .then(() => Promise.all([
+ device.controlTransferIn(interfaceRequest, 7).then(result => {
+ assert_true(result instanceof USBInTransferResult);
+ assert_equals(result.status, 'ok');
+ assert_equals(result.data.byteLength, 7);
+ assert_equals(result.data.getUint16(0), 0x07);
+ assert_equals(result.data.getUint8(2), 0x42);
+ assert_equals(result.data.getUint16(3), 0x1234);
+ assert_equals(result.data.getUint16(5), 0x5600);
+ }),
+ device.controlTransferIn(endpointRequest, 7).then(result => {
+ assert_true(result instanceof USBInTransferResult);
+ assert_equals(result.status, 'ok');
+ assert_equals(result.data.byteLength, 7);
+ assert_equals(result.data.getUint16(0), 0x07);
+ assert_equals(result.data.getUint8(2), 0x42);
+ assert_equals(result.data.getUint16(3), 0x1234);
+ assert_equals(result.data.getUint16(5), 0x5681);
+ }),
+ device.controlTransferOut(interfaceRequest, data),
+ device.controlTransferOut(endpointRequest, data),
+ ]))
+ .then(() => device.close());
+ });
+}, 'requests to interfaces and endpoint require an interface claim');
+
+usb_test(usb => {
+ usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
+ return navigator.usb.getDevices().then(devices => {
assert_equals(devices.length, 1);
let device = devices[0];
return device.open()
@@ -441,6 +504,37 @@ usb_test(usb => {
return navigator.usb.getDevices().then(devices => {
assert_equals(devices.length, 1);
let device = devices[0];
+ let data = new DataView(new ArrayBuffer(1024));
+ for (let i = 0; i < 1024; ++i)
+ data.setUint8(i, i & 0xff);
+ const notFoundMessage = 'The specified endpoint is not part of a claimed ' +
+ 'and selected alternate interface.';
+ const rangeError = 'The specified endpoint number is out of range.';
+ return device.open()
+ .then(() => device.selectConfiguration(1))
+ .then(() => device.claimInterface(0))
+ .then(() => Promise.all([
+ assertRejectsWithError(device.transferIn(2, 8),
+ 'NotFoundError', notFoundMessage), // Unclaimed
+ assertRejectsWithError(device.transferIn(3, 8), 'NotFoundError',
+ notFoundMessage), // Non-existent
+ assertRejectsWithError(
+ device.transferIn(16, 8), 'IndexSizeError', rangeError),
+ assertRejectsWithError(device.transferOut(2, data),
+ 'NotFoundError', notFoundMessage), // Unclaimed
+ assertRejectsWithError(device.transferOut(3, data), 'NotFoundError',
+ notFoundMessage), // Non-existent
+ assertRejectsWithError(
+ device.transferOut(16, data), 'IndexSizeError', rangeError),
+ ]));
+ });
+}, 'transfers to unavailable endpoints are rejected');
+
+usb_test(usb => {
+ usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
+ return navigator.usb.getDevices().then(devices => {
+ assert_equals(devices.length, 1);
+ let device = devices[0];
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(0))