diff options
Diffstat (limited to 'testing/web-platform/tests/bluetooth/descriptor')
6 files changed, 152 insertions, 0 deletions
diff --git a/testing/web-platform/tests/bluetooth/descriptor/readValue/detachedIframe.https.window.js b/testing/web-platform/tests/bluetooth/descriptor/readValue/detachedIframe.https.window.js new file mode 100644 index 0000000000..47765a1315 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/descriptor/readValue/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.readValue(); + } 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'); +}, 'readValue() rejects in a detached context'); diff --git a/testing/web-platform/tests/bluetooth/descriptor/readValue/gen-service-is-removed.https.window.js b/testing/web-platform/tests/bluetooth/descriptor/readValue/gen-service-is-removed.https.window.js new file mode 100644 index 0000000000..d6c73ba60e --- /dev/null +++ b/testing/web-platform/tests/bluetooth/descriptor/readValue/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.readValue(), + expected, + 'Service got removed.')), + test_desc); + diff --git a/testing/web-platform/tests/bluetooth/descriptor/readValue/read-succeeds.https.window.js b/testing/web-platform/tests/bluetooth/descriptor/readValue/read-succeeds.https.window.js new file mode 100644 index 0000000000..d81db2f8c0 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/descriptor/readValue/read-succeeds.https.window.js @@ -0,0 +1,16 @@ +// 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 read request succeeds and returns the descriptor's value.`; + +bluetooth_test(async () => { + const {descriptor, fake_descriptor} = await getUserDescriptionDescriptor(); + + const EXPECTED_VALUE = [0, 1, 2]; + await fake_descriptor.setNextReadResponse(GATT_SUCCESS, EXPECTED_VALUE); + + const value = await descriptor.readValue(); + assert_array_equals(Array.from(new Uint8Array(value.buffer)), EXPECTED_VALUE); +}, test_desc); 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); + |