summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webusb/usbInterface.https.any.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/webusb/usbInterface.https.any.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webusb/usbInterface.https.any.js')
-rw-r--r--testing/web-platform/tests/webusb/usbInterface.https.any.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webusb/usbInterface.https.any.js b/testing/web-platform/tests/webusb/usbInterface.https.any.js
new file mode 100644
index 0000000000..22692a7d94
--- /dev/null
+++ b/testing/web-platform/tests/webusb/usbInterface.https.any.js
@@ -0,0 +1,55 @@
+// 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.');