summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/usb/usbDevice.html
diff options
context:
space:
mode:
authorreillyg <reillyg@chromium.org>2016-03-24 16:55:39 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-24 23:58:26 +0000
commit6cfa6305dc22be1489cec97f8ddcf595d75f2a75 (patch)
treed8eaf9338d4fd022ea18bc81cce920a4665c7217 /third_party/WebKit/LayoutTests/usb/usbDevice.html
parent6781323221029e2f5c0ca1b0f055b81bb2d69153 (diff)
downloadchromium_src-6cfa6305dc22be1489cec97f8ddcf595d75f2a75.zip
chromium_src-6cfa6305dc22be1489cec97f8ddcf595d75f2a75.tar.gz
chromium_src-6cfa6305dc22be1489cec97f8ddcf595d75f2a75.tar.bz2
Track USB endpoint state in Blink.lkgr
The last in a series of patches putting input validation for the WebUSB directly into Blink. This one adds bit vectors that track which endpoints are available given the current set of claimed interfaces and selected alternate interfaces. BUG=593164 Review URL: https://codereview.chromium.org/1830833002 Cr-Commit-Position: refs/heads/master@{#383194}
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))