summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webusb/usb.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/usb.https.any.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.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/usb.https.any.js')
-rw-r--r--testing/web-platform/tests/webusb/usb.https.any.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webusb/usb.https.any.js b/testing/web-platform/tests/webusb/usb.https.any.js
new file mode 100644
index 0000000000..c9a95b10ad
--- /dev/null
+++ b/testing/web-platform/tests/webusb/usb.https.any.js
@@ -0,0 +1,50 @@
+// META: script=/resources/test-only-api.js
+// META: script=/webusb/resources/fake-devices.js
+// META: script=/webusb/resources/usb-helpers.js
+'use strict';
+
+let usbDevice, devicesFirstTime, fakeDevice, removedDevice;
+
+usb_test(() => getFakeDevice()
+ .then(_ => usbDevice = _.device)
+ .then(() => navigator.usb.getDevices())
+ .then(devices => {
+ assert_equals(devices.length, 1);
+ assert_equals(usbDevice, devices[0]);
+ assertDeviceInfoEquals(devices[0], fakeDeviceInit);
+ }), 'getDevices returns devices that are connected');
+
+usb_test(() => getFakeDevice()
+ .then(() => navigator.usb.getDevices())
+ .then(_ => devicesFirstTime = _)
+ .then(() => assert_equals(devicesFirstTime.length, 1))
+ .then(() => navigator.usb.getDevices())
+ .then(devicesSecondTime => assert_array_equals(devicesSecondTime,
+ devicesFirstTime)),
+ 'getDevices returns the same objects for each USB device');
+
+usb_test(() => getFakeDevice()
+ .then(_ => usbDevice = _.device)
+ .then(() => assertDeviceInfoEquals(usbDevice, fakeDeviceInit))
+ .then(() => usbDevice.open())
+ .then(() => usbDevice.close()),
+ 'onconnect event is trigged by adding a device');
+
+usb_test(() => getFakeDevice()
+ .then(_ => {
+ usbDevice = _.device;
+ fakeDevice = _.fakeDevice;
+ })
+ .then(() => waitForDisconnect(fakeDevice))
+ .then(_ => removedDevice = _)
+ .then(() => {
+ assertDeviceInfoEquals(removedDevice, fakeDeviceInit);
+ assert_equals(removedDevice, usbDevice);
+ })
+ .then(() => removedDevice.open())
+ .then(() =>
+ assert_unreachable('should not be able to open a disconnected device'),
+ error => assert_equals(error.code, DOMException.NOT_FOUND_ERR)),
+ 'ondisconnect event is triggered by removing a device');
+
+done();