summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/bluetooth/script-tests/characteristic
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/bluetooth/script-tests/characteristic
parentInitial commit. (diff)
downloadfirefox-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/script-tests/characteristic')
-rw-r--r--testing/web-platform/tests/bluetooth/script-tests/characteristic/characteristic-is-removed.js24
-rw-r--r--testing/web-platform/tests/bluetooth/script-tests/characteristic/descriptor-get-same-object.js32
-rw-r--r--testing/web-platform/tests/bluetooth/script-tests/characteristic/service-is-removed.js20
3 files changed, 76 insertions, 0 deletions
diff --git a/testing/web-platform/tests/bluetooth/script-tests/characteristic/characteristic-is-removed.js b/testing/web-platform/tests/bluetooth/script-tests/characteristic/characteristic-is-removed.js
new file mode 100644
index 0000000000..48aaec3e93
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/script-tests/characteristic/characteristic-is-removed.js
@@ -0,0 +1,24 @@
+'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.CALLS([
+ getDescriptor(user_description.name)|
+ getDescriptors(user_description.name)[UUID]|
+ getDescriptors()|
+ readValue()|
+ writeValue(new Uint8Array(1))|
+ writeValueWithResponse(new Uint8Array(1))|
+ writeValueWithoutResponse(new Uint8Array(1))|
+ startNotifications()
+ ]), expected)),
+ test_desc);
diff --git a/testing/web-platform/tests/bluetooth/script-tests/characteristic/descriptor-get-same-object.js b/testing/web-platform/tests/bluetooth/script-tests/characteristic/descriptor-get-same-object.js
new file mode 100644
index 0000000000..4e6bc3519b
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/script-tests/characteristic/descriptor-get-same-object.js
@@ -0,0 +1,32 @@
+'use strict';
+const test_desc = 'Calls to FUNCTION_NAME should return the same object.';
+let characteristic;
+
+bluetooth_test(() => getMeasurementIntervalCharacteristic()
+ .then(_ => ({characteristic} = _))
+ .then(() => Promise.all([
+ characteristic.CALLS([
+ getDescriptor(user_description.alias)|
+ getDescriptors(user_description.alias)
+ ]),
+ characteristic.FUNCTION_NAME(user_description.name),
+ characteristic.FUNCTION_NAME(user_description.uuid)
+ ]))
+ .then(descriptors_arrays => {
+ assert_true(descriptors_arrays.length > 0)
+
+ // Convert to arrays if necessary.
+ for (let i = 0; i < descriptors_arrays.length; i++) {
+ descriptors_arrays[i] = [].concat(descriptors_arrays[i]);
+ }
+
+ for (let i = 1; i < descriptors_arrays.length; i++) {
+ assert_equals(descriptors_arrays[0].length,
+ descriptors_arrays[i].length);
+ }
+
+ let base_set = new Set(descriptors_arrays[0]);
+ for (let descriptors of descriptors_arrays) {
+ descriptors.forEach(descriptor => assert_true(base_set.has(descriptor)));
+ }
+ }), test_desc);
diff --git a/testing/web-platform/tests/bluetooth/script-tests/characteristic/service-is-removed.js b/testing/web-platform/tests/bluetooth/script-tests/characteristic/service-is-removed.js
new file mode 100644
index 0000000000..2f5824082b
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/script-tests/characteristic/service-is-removed.js
@@ -0,0 +1,20 @@
+// TODO(https://crbug.com/672127) Use this test case to test the rest of
+// characteristic functions.
+'use strict';
+const test_desc = 'Service is removed. Reject with InvalidStateError.';
+const expected = new DOMException('GATT Service no longer exists.',
+ 'InvalidStateError');
+let characteristic, fake_peripheral, fake_service;
+
+bluetooth_test(() => getMeasurementIntervalCharacteristic()
+ .then(_ => ({characteristic, fake_peripheral, fake_service} = _))
+ .then(() => fake_service.remove())
+ .then(() => fake_peripheral.simulateGATTServicesChanged())
+ .then(() => assert_promise_rejects_with_message(
+ characteristic.CALLS([
+ getDescriptor(user_description.name)|
+ getDescriptors(user_description.uuid)[UUID]|
+ getDescriptors(user_description.name)]),
+ expected,
+ 'Service got removed.')),
+ test_desc);