diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/bluetooth/script-tests/server | |
parent | Initial commit. (diff) | |
download | firefox-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/server')
17 files changed, 426 insertions, 0 deletions
diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/disconnect-called-before.js b/testing/web-platform/tests/bluetooth/script-tests/server/disconnect-called-before.js new file mode 100644 index 0000000000..57704ee299 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/disconnect-called-before.js @@ -0,0 +1,22 @@ +'use strict'; +const test_desc = 'disconnect() called before FUNCTION_NAME. ' + + 'Reject with NetworkError.'; +const expected = new DOMException( + 'GATT Server is disconnected. Cannot retrieve services. (Re)connect ' + + 'first with `device.gatt.connect`.', + 'NetworkError'); +let device; + +bluetooth_test(() => getConnectedHealthThermometerDevice({ + filters: [{services: ['health_thermometer']}], + optionalServices: ['generic_access'] + }) + .then(_ => ({device} = _)) + .then(() => device.gatt.disconnect()) + .then(() => assert_promise_rejects_with_message( + device.gatt.CALLS([ + getPrimaryService('health_thermometer')| + getPrimaryServices()| + getPrimaryServices('health_thermometer')[UUID]]), + expected)), + test_desc); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/disconnect-called-during-error.js b/testing/web-platform/tests/bluetooth/script-tests/server/disconnect-called-during-error.js new file mode 100644 index 0000000000..edabb07bcc --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/disconnect-called-during-error.js @@ -0,0 +1,22 @@ +'use strict'; +const test_desc = 'disconnect() called during a FUNCTION_NAME ' + + 'call that fails. Reject with NetworkError.'; +const expected = new DOMException( + 'GATT Server is disconnected. Cannot retrieve services. (Re)connect ' + + 'first with `device.gatt.connect`.', 'NetworkError'); +let device; + +bluetooth_test(() => getEmptyHealthThermometerDevice() + .then(_ => ({device} = _)) + .then(() => { + let promise = assert_promise_rejects_with_message( + device.gatt.CALLS([ + getPrimaryService('health_thermometer')| + getPrimaryServices()| + getPrimaryServices('health_thermometer')[UUID] + ]), + expected) + device.gatt.disconnect(); + return promise; + }), + test_desc); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/disconnect-called-during-success.js b/testing/web-platform/tests/bluetooth/script-tests/server/disconnect-called-during-success.js new file mode 100644 index 0000000000..84157a0693 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/disconnect-called-during-success.js @@ -0,0 +1,23 @@ +'use strict'; +const test_desc = 'disconnect() called during a FUNCTION_NAME call that ' + + 'succeeds. Reject with NetworkError.'; +const expected = new DOMException( + 'GATT Server is disconnected. Cannot retrieve services. (Re)connect ' + + 'first with `device.gatt.connect`.', + 'NetworkError'); + +bluetooth_test(() => getHealthThermometerDevice({ + filters: [{services: ['health_thermometer']}], + optionalServices: ['generic_access'] + }) + .then(({device}) => { + let promise = assert_promise_rejects_with_message( + device.gatt.CALLS([ + getPrimaryService('health_thermometer')| + getPrimaryServices()| + getPrimaryServices('health_thermometer')[UUID] + ]), + expected); + device.gatt.disconnect(); + return promise; + }), test_desc); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/disconnect-discovery-timeout.js b/testing/web-platform/tests/bluetooth/script-tests/server/disconnect-discovery-timeout.js new file mode 100644 index 0000000000..718e290950 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/disconnect-discovery-timeout.js @@ -0,0 +1,42 @@ +'use strict'; +const test_desc = + 'Calls to FUNCTION_NAME when device disconnects and discovery' + + ' times out should reject promise rather than get stuck.'; +let device; + +bluetooth_test( + async (t) => { + let {device, fake_peripheral} = + await getConnectedHealthThermometerDevice({ + filters: [{services: ['health_thermometer']}], + optionalServices: ['generic_access'] + }); + + await fake_peripheral.setNextGATTDiscoveryResponse({ + code: HCI_CONNECTION_TIMEOUT, + }); + await Promise.all([ + fake_peripheral.simulateGATTDisconnection({ + code: HCI_SUCCESS, + }), + // Using promise_rejects_dom here rather than + // assert_promise_rejects_with_message as the race between + // simulateGATTDisconnection and getPrimaryServices might end up giving + // slightly different exception message (i.e has "Failed to execute ... + // on + // ... " prefix when disconnected state is reflected on the renderer + // side). The point of the test is no matter how race between them, the + // promise will be rejected as opposed to get stuck. + promise_rejects_dom(t, 'NetworkError', device.gatt.CALLS([ + getPrimaryService('health_thermometer') | getPrimaryServices() | + getPrimaryServices('health_thermometer')[UUID] + ])), + ]); + }, + test_desc, '', + // As specified above there is a race condition between + // simulateGATTDisconnection and getPrimaryServices, the artificial + // GATTDiscoveryResponse might not be consumed in case + // simulateGATTDisconnection happens first. As a result explicitly skip + // all response consumed validation at the end of the test. + /*validate_response_consumed=*/ false); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/disconnect-invalidates-objects.js b/testing/web-platform/tests/bluetooth/script-tests/server/disconnect-invalidates-objects.js new file mode 100644 index 0000000000..995fda3441 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/disconnect-invalidates-objects.js @@ -0,0 +1,39 @@ +'use strict'; +const test_desc = 'Calls on services after we disconnect and connect again. '+ + 'Should reject with InvalidStateError.'; +let device, services; + +bluetooth_test(() => getHealthThermometerDevice({ + filters: [{services: ['health_thermometer']}] + }) + .then(_ => ({device} = _)) + .then(() => device.gatt.CALLS([ + getPrimaryService('health_thermometer')| + getPrimaryServices()| + getPrimaryServices('health_thermometer')[UUID]])) + // Convert to array if necessary. + .then(s => services = [].concat(s)) + .then(() => device.gatt.disconnect()) + .then(() => device.gatt.connect()) + .then(() => { + let promises = Promise.resolve(); + for (let service of services) { + let error = new DOMException( + `Service with UUID ${service.uuid} is no longer valid. Remember ` + + `to retrieve the service again after reconnecting.`, + 'InvalidStateError'); + promises = promises.then(() => + assert_promise_rejects_with_message( + service.getCharacteristic('measurement_interval'), + error)); + promises = promises.then(() => + assert_promise_rejects_with_message( + service.getCharacteristics(), + error)); + promises = promises.then(() => + assert_promise_rejects_with_message( + service.getCharacteristics('measurement_interval'), + error)); + } + return promises; + }), test_desc); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/disconnected-device.js b/testing/web-platform/tests/bluetooth/script-tests/server/disconnected-device.js new file mode 100644 index 0000000000..2b6011642b --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/disconnected-device.js @@ -0,0 +1,20 @@ +'use strict'; +const test_desc = 'FUNCTION_NAME called before connecting. Reject with ' + + 'NetworkError.'; +const expected = new DOMException( + 'GATT Server is disconnected. Cannot retrieve services. (Re)connect ' + + 'first with `device.gatt.connect`.', + 'NetworkError'); + +bluetooth_test(() => getDiscoveredHealthThermometerDevice({ + filters: [{services: ['health_thermometer']}], + optionalServices: ['generic_access'] + }) + .then(({device}) => assert_promise_rejects_with_message( + device.gatt.CALLS([ + getPrimaryService('health_thermometer')| + getPrimaryServices()| + getPrimaryServices('health_thermometer')[UUID] + ]), + expected)), + test_desc); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/discovery-complete-no-permission-absent-service.js b/testing/web-platform/tests/bluetooth/script-tests/server/discovery-complete-no-permission-absent-service.js new file mode 100644 index 0000000000..e9e972359a --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/discovery-complete-no-permission-absent-service.js @@ -0,0 +1,25 @@ +'use strict'; +const test_desc = 'Request for absent service without permission. Should ' + + 'Reject with SecurityError even if services have been discovered already.'; +const expected = new DOMException( + 'Origin is not allowed to access the service. Tip: Add the service ' + + 'UUID to \'optionalServices\' in requestDevice() options. ' + + 'https://goo.gl/HxfxSQ', + 'SecurityError'); +let device; + +bluetooth_test(() => getHealthThermometerDeviceWithServicesDiscovered({ + filters: [{services: ['health_thermometer']}] + }) + .then(_ => ({device} = _)) + .then(() => Promise.all([ + assert_promise_rejects_with_message( + device.gatt.CALLS([ + getPrimaryService(glucose.alias)| + getPrimaryServices(glucose.alias)[UUID] + ]), expected), + assert_promise_rejects_with_message( + device.gatt.FUNCTION_NAME(glucose.name), expected), + assert_promise_rejects_with_message( + device.gatt.FUNCTION_NAME(glucose.uuid), expected)])), + test_desc); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/discovery-complete-service-not-found.js b/testing/web-platform/tests/bluetooth/script-tests/server/discovery-complete-service-not-found.js new file mode 100644 index 0000000000..6b745d7e2a --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/discovery-complete-service-not-found.js @@ -0,0 +1,16 @@ +'use strict'; +const test_desc = 'Request for absent service. Must reject with ' + + 'NotFoundError even when the services have previously been discovered.'; + +bluetooth_test(() => getHealthThermometerDeviceWithServicesDiscovered({ + filters: [{services: ['health_thermometer']}], + optionalServices: ['glucose']}) + .then(({device}) => assert_promise_rejects_with_message( + device.gatt.CALLS([ + getPrimaryService('glucose')| + getPrimaryServices('glucose')[UUID] + ]), + new DOMException( + `No Services matching UUID ${glucose.uuid} found in Device.`, + 'NotFoundError'))), + test_desc); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/garbage-collection-ran-during-error.js b/testing/web-platform/tests/bluetooth/script-tests/server/garbage-collection-ran-during-error.js new file mode 100644 index 0000000000..cf508a928e --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/garbage-collection-ran-during-error.js @@ -0,0 +1,25 @@ +'use strict'; +const test_desc = 'Garbage Collection ran during a FUNCTION_NAME ' + + 'call that failed. Should not crash.' +const expected = new DOMException( + 'GATT Server is disconnected. Cannot retrieve services. (Re)connect first ' + + 'with `device.gatt.connect`.', + 'NetworkError'); +let promise; + +bluetooth_test(() => getEmptyHealthThermometerDevice() + .then(({device}) => { + promise = assert_promise_rejects_with_message( + device.gatt.CALLS([ + getPrimaryService('health_thermometer')| + getPrimaryServices()| + getPrimaryServices('health_thermometer')[UUID] + ]), + expected); + // Disconnect called to clear attributeInstanceMap and allow the + // object to get garbage collected. + device.gatt.disconnect(); + return garbageCollect(); + }) + .then(() => promise), + test_desc); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/garbage-collection-ran-during-success.js b/testing/web-platform/tests/bluetooth/script-tests/server/garbage-collection-ran-during-success.js new file mode 100644 index 0000000000..bb472fcca4 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/garbage-collection-ran-during-success.js @@ -0,0 +1,24 @@ +'use strict'; +const test_desc = 'Garbage Collection ran during a FUNCTION_NAME call that ' + + 'succeeds. Should not crash.'; +const expected = new DOMException( + 'GATT Server is disconnected. Cannot retrieve services. ' + + '(Re)connect first with `device.gatt.connect`.', + 'NetworkError'); +let promise; + +bluetooth_test(() => getHealthThermometerDevice({ + filters: [{services: ['health_thermometer']}] + }) + .then(({device}) => { + promise = assert_promise_rejects_with_message( + device.gatt.CALLS([ + getPrimaryService('health_thermometer') | + getPrimaryServices() | + getPrimaryServices('health_thermometer')[UUID]]), + expected); + device.gatt.disconnect(); + return garbageCollect(); + }) + .then(() => promise), + test_desc); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/get-different-service-after-reconnection.js b/testing/web-platform/tests/bluetooth/script-tests/server/get-different-service-after-reconnection.js new file mode 100644 index 0000000000..e72128a76f --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/get-different-service-after-reconnection.js @@ -0,0 +1,35 @@ +'use strict'; +const test_desc = 'Calls to FUNCTION_NAME after a disconnection should return ' + + 'a different object.'; +let device, services_first_connection, services_second_connection; + +bluetooth_test(() => getHealthThermometerDevice({ + filters: [{services: ['health_thermometer']}], + optionalServices: ['generic_access'] + }) + .then(_ => ({device} = _)) + .then(() => device.gatt.CALLS([ + getPrimaryService('health_thermometer')| + getPrimaryServices()| + getPrimaryServices('health_thermometer')[UUID]])) + .then(services => services_first_connection = services) + .then(() => device.gatt.disconnect()) + .then(() => device.gatt.connect()) + .then(() => device.gatt.PREVIOUS_CALL) + .then(services => services_second_connection = services) + .then(() => { + // Convert to arrays if necessary. + services_first_connection = [].concat(services_first_connection); + services_second_connection = [].concat(services_second_connection); + + assert_equals(services_first_connection.length, + services_second_connection.length); + + let first_connection_set = new Set(services_first_connection); + let second_connection_set = new Set(services_second_connection); + + // The two sets should be disjoint. + let common_services = services_first_connection.filter( + val => second_connection_set.has(val)); + assert_equals(common_services.length, 0); + }), test_desc); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/get-same-object.js b/testing/web-platform/tests/bluetooth/script-tests/server/get-same-object.js new file mode 100644 index 0000000000..3b3bdd19d2 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/get-same-object.js @@ -0,0 +1,33 @@ +'use strict'; +const test_desc = 'Calls to FUNCTION_NAME should return the same object.'; +let device; + +bluetooth_test(() => getHealthThermometerDevice({ + filters: [{services: ['health_thermometer']}], + optionalServices: ['generic_access']}) + .then(({device}) => Promise.all([ + device.gatt.CALLS([ + getPrimaryService('health_thermometer')| + getPrimaryServices()| + getPrimaryServices('health_thermometer')[UUID]]), + device.gatt.PREVIOUS_CALL])) + .then(([services_first_call, services_second_call]) => { + // Convert to arrays if necessary. + services_first_call = [].concat(services_first_call); + services_second_call = [].concat(services_second_call); + + assert_equals(services_first_call.length, services_second_call.length); + + let first_call_set = new Set(services_first_call); + assert_equals(services_first_call.length, first_call_set.size); + let second_call_set = new Set(services_second_call); + assert_equals(services_second_call.length, second_call_set.size); + + services_first_call.forEach(service => { + assert_true(second_call_set.has(service)) + }); + + services_second_call.forEach(service => { + assert_true(first_call_set.has(service)); + }); + }), test_desc); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/invalid-service-name.js b/testing/web-platform/tests/bluetooth/script-tests/server/invalid-service-name.js new file mode 100644 index 0000000000..52cbb24f4a --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/invalid-service-name.js @@ -0,0 +1,22 @@ +'use strict'; +const test_desc = 'Wrong Service name. Reject with TypeError.'; +const expected = new DOMException( + "Failed to execute 'FUNCTION_NAME' on " + + "'BluetoothRemoteGATTServer': Invalid Service 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/services" + + " e.g. 'alert_notification'.", + 'TypeError'); + +bluetooth_test(() => getConnectedHealthThermometerDevice() + .then(({device}) => assert_promise_rejects_with_message( + device.gatt.CALLS([ + getPrimaryService('wrong_name')| + getPrimaryServices('wrong_name') + ]), + expected, + 'Wrong Service name passed.')), + test_desc); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/no-permission-absent-service.js b/testing/web-platform/tests/bluetooth/script-tests/server/no-permission-absent-service.js new file mode 100644 index 0000000000..200dab3e93 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/no-permission-absent-service.js @@ -0,0 +1,23 @@ +'use strict'; +const test_desc = 'Request for absent service without permission. ' + + 'Reject with SecurityError.'; +const expected = new DOMException( + 'Origin is not allowed to access the service. Tip: Add the service UUID ' + + 'to \'optionalServices\' in requestDevice() options. ' + + 'https://goo.gl/HxfxSQ', + 'SecurityError'); + +bluetooth_test(() => getConnectedHealthThermometerDevice({ + filters: [{services: ['health_thermometer']}] + }) + .then(({device}) => Promise.all([ + assert_promise_rejects_with_message( + device.gatt.CALLS([ + getPrimaryService(glucose.alias)| + getPrimaryServices(glucose.alias)[UUID] + ]), expected), + assert_promise_rejects_with_message( + device.gatt.FUNCTION_NAME(glucose.name), expected), + assert_promise_rejects_with_message( + device.gatt.FUNCTION_NAME(glucose.uuid), expected)])), + test_desc); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/no-permission-for-any-service.js b/testing/web-platform/tests/bluetooth/script-tests/server/no-permission-for-any-service.js new file mode 100644 index 0000000000..60e3ef0080 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/no-permission-for-any-service.js @@ -0,0 +1,17 @@ +'use strict'; +const test_desc = 'Request for present service without permission to access ' + + 'any service. Reject with SecurityError.'; +const expected = new DOMException( + 'Origin is not allowed to access any service. Tip: Add the service ' + + 'UUID to \'optionalServices\' in requestDevice() options. ' + + 'https://goo.gl/HxfxSQ', + 'SecurityError'); + +bluetooth_test(() => getConnectedHealthThermometerDevice({acceptAllDevices: true}) + .then(({device}) => assert_promise_rejects_with_message( + device.gatt.CALLS([ + getPrimaryService('heart_rate')| + getPrimaryServices()| + getPrimaryServices('heart_rate')[UUID]]), + expected)), + test_desc); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/no-permission-present-service.js b/testing/web-platform/tests/bluetooth/script-tests/server/no-permission-present-service.js new file mode 100644 index 0000000000..3257410685 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/no-permission-present-service.js @@ -0,0 +1,22 @@ +'use strict'; +const test_desc = 'Request for present service without permission. ' + + 'Reject with SecurityError.'; +const expected = new DOMException( + 'Origin is not allowed to access the service. Tip: Add the service UUID ' + + 'to \'optionalServices\' in requestDevice() options. https://goo.gl/HxfxSQ', + 'SecurityError'); + +bluetooth_test(() => getConnectedHealthThermometerDevice({ + filters: [{services: ['health_thermometer']}] + }) + .then(({device}) => Promise.all([ + assert_promise_rejects_with_message( + device.gatt.CALLS([ + getPrimaryService(generic_access.alias)| + getPrimaryServices(generic_access.alias)[UUID] + ]), expected), + assert_promise_rejects_with_message( + device.gatt.FUNCTION_NAME(generic_access.name), expected), + assert_promise_rejects_with_message( + device.gatt.FUNCTION_NAME(generic_access.uuid), expected)])), + test_desc); diff --git a/testing/web-platform/tests/bluetooth/script-tests/server/service-not-found.js b/testing/web-platform/tests/bluetooth/script-tests/server/service-not-found.js new file mode 100644 index 0000000000..0fd2dace78 --- /dev/null +++ b/testing/web-platform/tests/bluetooth/script-tests/server/service-not-found.js @@ -0,0 +1,16 @@ +'use strict'; +const test_desc = 'Request for absent service. Reject with NotFoundError.'; + +bluetooth_test(() => getHealthThermometerDevice({ + filters: [{services: ['health_thermometer']}], + optionalServices: ['glucose'] + }) + .then(({device}) => assert_promise_rejects_with_message( + device.gatt.CALLS([ + getPrimaryService('glucose')| + getPrimaryServices('glucose')[UUID] + ]), + new DOMException( + `No Services matching UUID ${glucose.uuid} found in Device.`, + 'NotFoundError'))), + test_desc); |