diff options
Diffstat (limited to 'testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse')
5 files changed, 125 insertions, 0 deletions
diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/buffer-is-detached.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/buffer-is-detached.https.window.js new file mode 100644 index 0000000000..75d4cf0805 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/buffer-is-detached.https.window.js @@ -0,0 +1,27 @@ +// 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 = + 'writeValueWithoutResponse() 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.writeValueWithoutResponse(typed_array)); + + const array_buffer = Uint8Array.of(3, 4).buffer; + detachBuffer(array_buffer); + await promise_rejects_dom( + t, 'InvalidStateError', + characteristic.writeValueWithoutResponse(array_buffer)); +}, test_desc); diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/characteristic-is-removed.https.window.js new file mode 100644 index 0000000000..8d3ed1f663 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/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.writeValueWithoutResponse(new ArrayBuffer(1 /* length */)), + expected, 'Characteristic got removed.'); +}, test_desc); diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/gen-characteristic-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/gen-characteristic-is-removed.https.window.js new file mode 100644 index 0000000000..b88246aae8 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/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.writeValueWithoutResponse(new Uint8Array(1)), expected)), + test_desc); + diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/service-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/service-is-removed.https.window.js new file mode 100644 index 0000000000..feb711c64e --- /dev/null +++ b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/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.writeValueWithoutResponse(new ArrayBuffer(1 /* length */)), + expected, 'Service got removed.'); +}, test_desc); diff --git a/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/write-succeeds.https.window.js b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/write-succeeds.https.window.js new file mode 100644 index 0000000000..0dcf8ad0b1 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/characteristic/writeValueWithoutResponse/write-succeeds.https.window.js @@ -0,0 +1,41 @@ +// 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'); + + const typed_array = Uint8Array.of(1, 2); + await characteristic.writeValueWithoutResponse(typed_array); + ({lastValue, lastWriteType} = + await fake_characteristic.getLastWrittenValue()); + assert_array_equals(lastValue, [1, 2]); + assert_equals(lastWriteType, 'without-response'); + + const array_buffer = Uint8Array.of(3, 4).buffer; + await characteristic.writeValueWithoutResponse(array_buffer); + ({lastValue, lastWriteType} = + await fake_characteristic.getLastWrittenValue()); + assert_array_equals(lastValue, [3, 4]); + assert_equals(lastWriteType, 'without-response'); + + const data_view = new DataView(new ArrayBuffer(2)); + data_view.setUint8(0, 5); + data_view.setUint8(1, 6); + await characteristic.writeValueWithoutResponse(data_view); + ({lastValue, lastWriteType} = + await fake_characteristic.getLastWrittenValue()); + assert_array_equals(lastValue, [5, 6]); + assert_equals(lastWriteType, 'without-response'); +}, test_desc); |