diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/bluetooth/characteristic/writeValue | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/bluetooth/characteristic/writeValue')
6 files changed, 161 insertions, 0 deletions
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValue/buffer-is-detached.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValue/buffer-is-detached.https.window.js new file mode 100644 index 0000000000..5d707775e1 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/characteristic/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 {characteristic} = await getMeasurementIntervalCharacteristic(); + + const typed_array = Uint8Array.of(1, 2); + detachBuffer(typed_array.buffer); + await promise_rejects_dom( + t, 'InvalidStateError', characteristic.writeValue(typed_array)); + + const array_buffer = Uint8Array.of(3, 4).buffer; + detachBuffer(array_buffer); + await promise_rejects_dom( + t, 'InvalidStateError', characteristic.writeValue(array_buffer)); +}, test_desc); diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValue/characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValue/characteristic-is-removed.https.window.js new file mode 100644 index 0000000000..6e9da8802c --- /dev/null +++ b/testing/web-platform/tests/bluetooth/characteristic/writeValue/characteristic-is-removed.https.window.js @@ -0,0 +1,17 @@ +// 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 = 'Characteristic gets removed. Reject with InvalidStateError.'; +const expected = new DOMException( + 'GATT Characteristic no longer exists.', 'InvalidStateError'); + +bluetooth_test(async () => { + const {characteristic, fake_characteristic} = + await getMeasurementIntervalCharacteristic(); + await fake_characteristic.remove(); + await assert_promise_rejects_with_message( + characteristic.writeValue(new ArrayBuffer(1 /* length */)), expected, + 'Characteristic got removed.'); +}, test_desc); diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValue/detachedIframe.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValue/detachedIframe.https.window.js new file mode 100644 index 0000000000..eb243a3508 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/characteristic/writeValue/detachedIframe.https.window.js @@ -0,0 +1,33 @@ +// 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); + + iframe.remove(); + // Set iframe to null to ensure that the GC cleans up as much as possible. + iframe = null; + await garbageCollect(); + + try { + await characteristic.writeValue(new DataView(new ArrayBuffer(2))); + } 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/characteristic/writeValue/gen-characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValue/gen-characteristic-is-removed.https.window.js new file mode 100644 index 0000000000..5750cb82c7 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/characteristic/writeValue/gen-characteristic-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 = 'Characteristic gets removed. Reject with InvalidStateError.'; +const expected = new DOMException('GATT Characteristic no longer exists.', + 'InvalidStateError'); +let fake_peripheral, characteristic, fake_characteristic; + +bluetooth_test(() => getMeasurementIntervalCharacteristic() + .then(_ => ({fake_peripheral, characteristic, fake_characteristic} = _)) + .then(() => characteristic.getDescriptor(user_description.name)) + .then(() => null, (e) => assert_unreached('Caught error unexpectedly.', e)) + .then(() => fake_characteristic.remove()) + .then(() => fake_peripheral.simulateGATTServicesChanged()) + .then(() => assert_promise_rejects_with_message( + characteristic.writeValue(new Uint8Array(1)), expected)), + test_desc); + diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValue/service-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValue/service-is-removed.https.window.js new file mode 100644 index 0000000000..89c3112475 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/characteristic/writeValue/service-is-removed.https.window.js @@ -0,0 +1,18 @@ +// 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 = 'Service gets removed. Reject with InvalidStateError.'; +const expected = + new DOMException('GATT Service no longer exists.', 'InvalidStateError'); + +bluetooth_test(async () => { + const {characteristic, fake_peripheral, fake_service} = + await getMeasurementIntervalCharacteristic(); + await fake_service.remove(); + await fake_peripheral.simulateGATTServicesChanged(); + await assert_promise_rejects_with_message( + characteristic.writeValue(new ArrayBuffer(1 /* length */)), expected, + 'Service got removed.'); +}, test_desc); diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValue/write-succeeds.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValue/write-succeeds.https.window.js new file mode 100644 index 0000000000..b57fe941d0 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/characteristic/writeValue/write-succeeds.https.window.js @@ -0,0 +1,47 @@ +// 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 = 'A regular write request to a writable characteristic ' + + 'should succeed.'; + +bluetooth_test(async () => { + const {characteristic, fake_characteristic} = + await getMeasurementIntervalCharacteristic(); + + let lastValue, lastWriteType; + ({lastValue, lastWriteType} = + await fake_characteristic.getLastWrittenValue()); + assert_equals(lastValue, null); + assert_equals(lastWriteType, 'none'); + + await fake_characteristic.setNextWriteResponse(GATT_SUCCESS); + + const typed_array = Uint8Array.of(1, 2); + await characteristic.writeValue(typed_array); + ({lastValue, lastWriteType} = + await fake_characteristic.getLastWrittenValue()); + assert_array_equals(lastValue, [1, 2]); + assert_equals(lastWriteType, 'default-deprecated'); + + await fake_characteristic.setNextWriteResponse(GATT_SUCCESS); + + const array_buffer = Uint8Array.of(3, 4).buffer; + await characteristic.writeValue(array_buffer); + ({lastValue, lastWriteType} = + await fake_characteristic.getLastWrittenValue()); + assert_array_equals(lastValue, [3, 4]); + assert_equals(lastWriteType, 'default-deprecated'); + + await fake_characteristic.setNextWriteResponse(GATT_SUCCESS); + + const data_view = new DataView(new ArrayBuffer(2)); + data_view.setUint8(0, 5); + data_view.setUint8(1, 6); + await characteristic.writeValue(data_view); + ({lastValue, lastWriteType} = + await fake_characteristic.getLastWrittenValue()); + assert_array_equals(lastValue, [5, 6]); + assert_equals(lastWriteType, 'default-deprecated'); +}, test_desc); |