diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/bluetooth/descriptor/writeValue | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/bluetooth/descriptor/writeValue')
3 files changed, 80 insertions, 0 deletions
diff --git a/testing/web-platform/tests/bluetooth/descriptor/writeValue/buffer-is-detached.https.window.js b/testing/web-platform/tests/bluetooth/descriptor/writeValue/buffer-is-detached.https.window.js new file mode 100644 index 0000000000..49daf7cf86 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/descriptor/writeValue/buffer-is-detached.https.window.js @@ -0,0 +1,24 @@ +// META: script=/resources/testdriver.js +// META: script=/resources/testdriver-vendor.js +// META: script=/bluetooth/resources/bluetooth-test.js +// META: script=/bluetooth/resources/bluetooth-fake-devices.js +'use strict'; +const test_desc = 'writeValue() fails when passed a detached buffer'; + +function detachBuffer(buffer) { + window.postMessage('', '*', [buffer]); +} + +bluetooth_test(async (t) => { + const {descriptor, fake_descriptor} = await getUserDescriptionDescriptor(); + + const typed_array = Uint8Array.of(1, 2); + detachBuffer(typed_array.buffer); + await promise_rejects_dom( + t, 'InvalidStateError', descriptor.writeValue(typed_array)); + + const array_buffer = Uint8Array.of(3, 4).buffer; + detachBuffer(array_buffer); + await promise_rejects_dom( + t, 'InvalidStateError', descriptor.writeValue(array_buffer)); +}, test_desc); diff --git a/testing/web-platform/tests/bluetooth/descriptor/writeValue/detachedIframe.https.window.js b/testing/web-platform/tests/bluetooth/descriptor/writeValue/detachedIframe.https.window.js new file mode 100644 index 0000000000..aa143ca8e5 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/descriptor/writeValue/detachedIframe.https.window.js @@ -0,0 +1,34 @@ +// META: script=/resources/testdriver.js +// META: script=/resources/testdriver-vendor.js +// META: script=/common/gc.js +// META: script=/bluetooth/resources/bluetooth-test.js +// META: script=/bluetooth/resources/bluetooth-fake-devices.js + +bluetooth_test(async () => { + let iframe = document.createElement('iframe'); + let error; + + const {device, fakes} = await getHealthThermometerDeviceFromIframe(iframe); + await fakes.fake_peripheral.setNextGATTDiscoveryResponse({ + code: HCI_SUCCESS, + }); + let service = await device.gatt.getPrimaryService(health_thermometer.name); + let characteristic = + await service.getCharacteristic(measurement_interval.name); + let descriptor = await characteristic.getDescriptor(user_description.name); + + iframe.remove(); + // Set iframe to null to ensure that the GC cleans up as much as possible. + iframe = null; + await garbageCollect(); + + try { + await descriptor.writeValue(new ArrayBuffer(1 /* length */)); + } catch (e) { + // Cannot use promise_rejects_dom() because |e| is thrown from a different + // global. + error = e; + } + assert_not_equals(error, undefined); + assert_equals(error.name, 'NetworkError'); +}, 'writeValue() rejects in a detached context'); diff --git a/testing/web-platform/tests/bluetooth/descriptor/writeValue/gen-service-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/descriptor/writeValue/gen-service-is-removed.https.window.js new file mode 100644 index 0000000000..c7f6d6efe3 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/descriptor/writeValue/gen-service-is-removed.https.window.js @@ -0,0 +1,22 @@ +// META: script=/resources/testdriver.js +// META: script=/resources/testdriver-vendor.js +// META: script=/common/gc.js +// META: script=/bluetooth/resources/bluetooth-test.js +// META: script=/bluetooth/resources/bluetooth-fake-devices.js +// Generated by //third_party/WebKit/LayoutTests/bluetooth/generate.py +'use strict'; +const test_desc = 'Service gets removed. Reject with InvalidStateError.'; +const expected = new DOMException('GATT Service no longer exists.', + 'InvalidStateError'); +let descriptor, fake_peripheral, fake_service; + +bluetooth_test(() => getUserDescriptionDescriptor() + .then(_ => ({descriptor, fake_peripheral, fake_service} = _)) + .then(() => fake_service.remove()) + .then(() => fake_peripheral.simulateGATTServicesChanged()) + .then(() => assert_promise_rejects_with_message( + descriptor.writeValue(new ArrayBuffer(1 /* length */)), + expected, + 'Service got removed.')), + test_desc); + |