summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/bluetooth/script-tests/service
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/bluetooth/script-tests/service
parentInitial commit. (diff)
downloadfirefox-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/script-tests/service')
-rw-r--r--testing/web-platform/tests/bluetooth/script-tests/service/blocklisted-characteristic.js19
-rw-r--r--testing/web-platform/tests/bluetooth/script-tests/service/characteristic-not-found.js15
-rw-r--r--testing/web-platform/tests/bluetooth/script-tests/service/garbage-collection-ran-during-error.js24
-rw-r--r--testing/web-platform/tests/bluetooth/script-tests/service/get-same-object.js24
-rw-r--r--testing/web-platform/tests/bluetooth/script-tests/service/invalid-characteristic-name.js23
-rw-r--r--testing/web-platform/tests/bluetooth/script-tests/service/reconnect-during.js36
-rw-r--r--testing/web-platform/tests/bluetooth/script-tests/service/service-is-removed.js20
7 files changed, 161 insertions, 0 deletions
diff --git a/testing/web-platform/tests/bluetooth/script-tests/service/blocklisted-characteristic.js b/testing/web-platform/tests/bluetooth/script-tests/service/blocklisted-characteristic.js
new file mode 100644
index 0000000000..b26f039a70
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/script-tests/service/blocklisted-characteristic.js
@@ -0,0 +1,19 @@
+'use strict';
+const test_desc = 'Serial Number String characteristic is blocklisted. ' +
+ 'Should reject with SecurityError.';
+const expected = new DOMException(
+ 'getCharacteristic(s) called with blocklisted UUID. https://goo.gl/4NeimX',
+ 'SecurityError');
+
+bluetooth_test(() => getHIDDevice({
+ filters: [{services: ['device_information']}]
+})
+ .then(({device}) => device.gatt.getPrimaryService('device_information'))
+ .then(service => assert_promise_rejects_with_message(
+ service.CALLS([
+ getCharacteristic('serial_number_string')|
+ getCharacteristics('serial_number_string')[UUID]
+ ]),
+ expected,
+ 'Serial Number String characteristic is blocklisted.')),
+ test_desc);
diff --git a/testing/web-platform/tests/bluetooth/script-tests/service/characteristic-not-found.js b/testing/web-platform/tests/bluetooth/script-tests/service/characteristic-not-found.js
new file mode 100644
index 0000000000..366e046774
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/script-tests/service/characteristic-not-found.js
@@ -0,0 +1,15 @@
+'use strict';
+const test_desc = 'Request for absent characteristics with UUID. ' +
+ 'Reject with NotFoundError.';
+
+bluetooth_test(() => getEmptyHealthThermometerService()
+ .then(({service}) => assert_promise_rejects_with_message(
+ service.CALLS([
+ getCharacteristic('battery_level')|
+ getCharacteristics('battery_level')[UUID]
+ ]),
+ new DOMException(
+ `No Characteristics matching UUID ${battery_level.uuid} found ` +
+ `in Service with UUID ${health_thermometer.uuid}.`,
+ 'NotFoundError'))),
+ test_desc);
diff --git a/testing/web-platform/tests/bluetooth/script-tests/service/garbage-collection-ran-during-error.js b/testing/web-platform/tests/bluetooth/script-tests/service/garbage-collection-ran-during-error.js
new file mode 100644
index 0000000000..7ed4aaa962
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/script-tests/service/garbage-collection-ran-during-error.js
@@ -0,0 +1,24 @@
+'use strict';
+const test_desc = 'Garbage Collection ran during FUNCTION_NAME ' +
+ 'call that fails. Should not crash';
+const expected = new DOMException(
+ 'GATT Server is disconnected. Cannot retrieve characteristics. ' +
+ '(Re)connect first with `device.gatt.connect`.',
+ 'NetworkError');
+let promise;
+
+bluetooth_test(() => getHealthThermometerService()
+ .then(({service}) => {
+ promise = assert_promise_rejects_with_message(
+ service.CALLS([
+ getCharacteristic('measurement_interval')|
+ getCharacteristics()|
+ getCharacteristics('measurement_interval')[UUID]
+ ]), expected);
+ // Disconnect called to clear attributeInstanceMap and allow the object to
+ // get garbage collected.
+ service.device.gatt.disconnect();
+ })
+ .then(garbageCollect)
+ .then(() => promise),
+ test_desc);
diff --git a/testing/web-platform/tests/bluetooth/script-tests/service/get-same-object.js b/testing/web-platform/tests/bluetooth/script-tests/service/get-same-object.js
new file mode 100644
index 0000000000..db9d740c83
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/script-tests/service/get-same-object.js
@@ -0,0 +1,24 @@
+'use strict';
+const test_desc = 'Calls to FUNCTION_NAME should return the same object.';
+
+bluetooth_test(() => getHealthThermometerService()
+ .then(({service}) => Promise.all([
+ service.CALLS([
+ getCharacteristic('measurement_interval')|
+ getCharacteristics()|
+ getCharacteristics('measurement_interval')[UUID]]),
+ service.PREVIOUS_CALL]))
+ .then(([characteristics_first_call, characteristics_second_call]) => {
+ // Convert to arrays if necessary.
+ characteristics_first_call = [].concat(characteristics_first_call);
+ characteristics_second_call = [].concat(characteristics_second_call);
+
+ let first_call_set = new Set(characteristics_first_call);
+ assert_equals(characteristics_first_call.length, first_call_set.size);
+ let second_call_set = new Set(characteristics_second_call);
+ assert_equals(characteristics_second_call.length, second_call_set.size);
+
+ characteristics_first_call.forEach(characteristic => {
+ assert_true(second_call_set.has(characteristic));
+ });
+ }), test_desc);
diff --git a/testing/web-platform/tests/bluetooth/script-tests/service/invalid-characteristic-name.js b/testing/web-platform/tests/bluetooth/script-tests/service/invalid-characteristic-name.js
new file mode 100644
index 0000000000..74cba7ec43
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/script-tests/service/invalid-characteristic-name.js
@@ -0,0 +1,23 @@
+'use strict';
+const test_desc = 'Wrong Characteristic name. Reject with TypeError.';
+const expected = new DOMException(
+ "Failed to execute 'FUNCTION_NAME' on " +
+ "'BluetoothRemoteGATTService': Invalid Characteristic name: " +
+ "'wrong_name'. " +
+ "It must be a valid UUID alias (e.g. 0x1234), " +
+ "UUID (lowercase hex characters e.g. " +
+ "'00001234-0000-1000-8000-00805f9b34fb'), " +
+ "or recognized standard name from " +
+ "https://www.bluetooth.com/specifications/gatt/characteristics" +
+ " e.g. 'aerobic_heart_rate_lower_limit'.",
+ 'TypeError');
+
+bluetooth_test(() => getHealthThermometerService()
+ .then(({service}) => assert_promise_rejects_with_message(
+ service.CALLS([
+ getCharacteristic('wrong_name')|
+ getCharacteristics('wrong_name')
+ ]),
+ expected,
+ 'Wrong Characteristic name passed.')),
+ test_desc);
diff --git a/testing/web-platform/tests/bluetooth/script-tests/service/reconnect-during.js b/testing/web-platform/tests/bluetooth/script-tests/service/reconnect-during.js
new file mode 100644
index 0000000000..cc71547ac2
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/script-tests/service/reconnect-during.js
@@ -0,0 +1,36 @@
+'use strict';
+const test_desc = 'disconnect() and connect() called during ' +
+ 'FUNCTION_NAME. Reject with NetworkError.';
+const expected = new DOMException(
+ 'GATT Server is disconnected. Cannot retrieve characteristics. ' +
+ '(Re)connect first with `device.gatt.connect`.',
+ 'NetworkError');
+let device;
+
+bluetooth_test(() => getHealthThermometerDeviceWithServicesDiscovered({
+ filters: [{services: [health_thermometer.name]}],
+})
+ .then(_ => ({device} = _))
+ .then(() => device.gatt.getPrimaryService(health_thermometer.name))
+ .then(service => Promise.all([
+ // 1. Make a call to service.FUNCTION_NAME, while the service is still
+ // valid.
+ assert_promise_rejects_with_message(service.CALLS([
+ getCharacteristic(measurement_interval.name)|
+ getCharacteristics()|
+ getCharacteristics(measurement_interval.name)[UUID]
+ ]), expected),
+
+ // 2. disconnect() and connect before the initial call completes.
+ // This is accomplished by making the calls without waiting for the
+ // earlier promises to resolve.
+ // connect() guarantees on OS-level connection, but disconnect()
+ // only disconnects the current instance.
+ // getHealthThermometerDeviceWithServicesDiscovered holds another
+ // connection in an iframe, so disconnect() and connect() are certain to
+ // reconnect. However, disconnect() will invalidate the service object so
+ // the subsequent calls made to it will fail, even after reconnecting.
+ device.gatt.disconnect(),
+ device.gatt.connect()
+ ])),
+ test_desc);
diff --git a/testing/web-platform/tests/bluetooth/script-tests/service/service-is-removed.js b/testing/web-platform/tests/bluetooth/script-tests/service/service-is-removed.js
new file mode 100644
index 0000000000..aaf0f14436
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/script-tests/service/service-is-removed.js
@@ -0,0 +1,20 @@
+'use strict';
+const test_desc = 'Service is removed before FUNCTION_NAME call. ' +
+ 'Reject with InvalidStateError.';
+const expected = new DOMException('GATT Service no longer exists.',
+ 'InvalidStateError');
+let service, fake_service, fake_peripheral;
+
+bluetooth_test(() => getHealthThermometerService()
+ .then(_ => ({service, fake_service, fake_peripheral} = _))
+ .then(() => fake_service.remove())
+ .then(() => fake_peripheral.simulateGATTServicesChanged())
+ .then(() => assert_promise_rejects_with_message(
+ service.CALLS([
+ getCharacteristic('measurement_interval')|
+ getCharacteristics()|
+ getCharacteristics('measurement_interval')[UUID]
+ ]),
+ expected,
+ 'Service got removed.')),
+ test_desc);