Files
tubestation/testing/web-platform/tests/webusb/usbInterface.https.any.js
Reilly Grant 52381d8952 Bug 1743530 [wpt PR 31787] - usb: Return zeroth alternate interface by default, a=testonly
Automatic update from web-platform-tests
usb: Return zeroth alternate interface by default

As specified in https://wicg.github.io/webusb/#dom-usbinterface-alternate
the alternate attribute of the USBInterface interface should be set to
the zeroth alternate interface descriptor by default. As implemented
however this attribute returned null when the interface was not claimed.

The behavior in this patch matches the specification and the Node WebUSB
implementation of this attribute. Web Platform Tests have been updated
to test the specified behavior.

Bug: 1093502
Change-Id: I79ccc5302617f1435cb490971d3d917ce88a1717
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3307829
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Ovidio Ruiz-Henríquez <odejesush@chromium.org>
Reviewed-by: Ovidio Ruiz-Henríquez <odejesush@chromium.org>
Cr-Commit-Position: refs/heads/main@{#947509}

--

wpt-commits: 4d4c746a57114535e21a7f21044d7eb86cf99d2f
wpt-pr: 31787
2021-12-20 11:37:31 +00:00

56 lines
2.2 KiB
JavaScript

// META: script=/resources/test-only-api.js
// META: script=/webusb/resources/fake-devices.js
// META: script=/webusb/resources/usb-helpers.js
'use strict';
usb_test(async () => {
let { device } = await getFakeDevice();
let configuration = new USBConfiguration(
device, device.configurations[1].configurationValue);
let usbInterface = new USBInterface(
configuration, configuration.interfaces[0].interfaceNumber);
assertDeviceInfoEquals(
usbInterface, fakeDeviceInit.configurations[1].interfaces[0]);
}, 'Can construct a USBInterface.');
usb_test(async () => {
let { device } = await getFakeDevice();
let configuration = new USBConfiguration(
device, device.configurations[1].configurationValue);
try {
let usbInterface = new USBInterface(
configuration, configuration.interfaces.length);
assert_unreached('USBInterface should reject an invalid interface number');
} catch (error) {
assert_equals(error.name, 'RangeError');
}
}, 'Constructing a USBInterface with an invalid interface number ' +
'throws a range error.');
usb_test(async () => {
let { device } = await getFakeDevice();
await device.open();
await device.selectConfiguration(2);
let configuration = new USBConfiguration(
device, device.configurations[1].configurationValue);
let usbInterface = new USBInterface(
configuration, configuration.interfaces[0].interfaceNumber);
assert_equals(usbInterface.alternate.alternateSetting, 0);
}, 'The alternate attribute of USBInterface returns the one with ' +
'bAlternateSetting 0 if the interface has not been claimed.');
usb_test(async () => {
let { device } = await getFakeDevice();
await device.open();
await device.selectConfiguration(2);
await device.claimInterface(0);
let configuration = new USBConfiguration(
device, device.configurations[1].configurationValue);
let usbInterface = new USBInterface(
configuration, configuration.interfaces[0].interfaceNumber);
assert_equals(usbInterface.alternate.alternateSetting, 0);
await device.selectAlternateInterface(0, 1);
assert_equals(usbInterface.alternate.alternateSetting, 1);
}, 'The alternate attribute of USBInterface returns the active alternate ' +
'interface.');