summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/bluetooth/idl
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/bluetooth/idl
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/bluetooth/idl')
-rw-r--r--testing/web-platform/tests/bluetooth/idl/idl-Bluetooth.https.window.js18
-rw-r--r--testing/web-platform/tests/bluetooth/idl/idl-BluetoothDevice.https.window.js37
-rw-r--r--testing/web-platform/tests/bluetooth/idl/idl-BluetoothUUID.window.js177
-rw-r--r--testing/web-platform/tests/bluetooth/idl/idl-NavigatorBluetooth.https.window.js12
-rw-r--r--testing/web-platform/tests/bluetooth/idl/idl-NavigatorBluetooth.window.js7
-rw-r--r--testing/web-platform/tests/bluetooth/idl/idlharness.tentative.https.window.js25
6 files changed, 276 insertions, 0 deletions
diff --git a/testing/web-platform/tests/bluetooth/idl/idl-Bluetooth.https.window.js b/testing/web-platform/tests/bluetooth/idl/idl-Bluetooth.https.window.js
new file mode 100644
index 0000000000..2b40eaff49
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/idl/idl-Bluetooth.https.window.js
@@ -0,0 +1,18 @@
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+'use strict';
+const test_desc = 'Bluetooth IDL test';
+
+test(() => {
+ assert_throws_js(
+ TypeError, () => new Bluetooth(),
+ 'the constructor should not be callable with "new"');
+ assert_throws_js(
+ TypeError, () => Bluetooth(),
+ 'the constructor should not be callable');
+
+ // Bluetooth implements BluetoothDiscovery;
+ assert_true('requestDevice' in navigator.bluetooth);
+ assert_true('getDevices' in navigator.bluetooth);
+ assert_equals(navigator.bluetooth.requestDevice.length, 0);
+}, test_desc); \ No newline at end of file
diff --git a/testing/web-platform/tests/bluetooth/idl/idl-BluetoothDevice.https.window.js b/testing/web-platform/tests/bluetooth/idl/idl-BluetoothDevice.https.window.js
new file mode 100644
index 0000000000..c715926df3
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/idl/idl-BluetoothDevice.https.window.js
@@ -0,0 +1,37 @@
+// 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_idl = 'BluetoothDevice IDL test.';
+
+test(() => {
+ assert_throws_js(
+ TypeError, () => new BluetoothDevice(),
+ 'the constructor should not be callable with "new"');
+ assert_throws_js(
+ TypeError, () => BluetoothDevice(),
+ 'the constructor should not be callable');
+}, test_desc_idl);
+
+const test_desc_attr = 'BluetoothDevice attributes.';
+let device;
+
+bluetooth_test(async () => {
+ let {device} = await getConnectedHealthThermometerDevice();
+
+ assert_equals(device.constructor.name, 'BluetoothDevice');
+ var old_device_id = device.id;
+ assert_throws_js(
+ TypeError, () => device.id = 'overwritten',
+ 'the device id should not be writable');
+ assert_throws_js(
+ TypeError, () => device.name = 'overwritten',
+ 'the device name should not be writable');
+ assert_throws_js(
+ TypeError, () => device.watchingAdvertisements = true,
+ 'the device watchingAdvertisements should not be writable');
+ assert_equals(device.id, old_device_id);
+ assert_equals(device.name, 'Health Thermometer');
+ assert_equals(device.watchingAdvertisements, false);
+}, test_desc_attr);
diff --git a/testing/web-platform/tests/bluetooth/idl/idl-BluetoothUUID.window.js b/testing/web-platform/tests/bluetooth/idl/idl-BluetoothUUID.window.js
new file mode 100644
index 0000000000..cf9c14bb2c
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/idl/idl-BluetoothUUID.window.js
@@ -0,0 +1,177 @@
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+'use strict'
+
+var base_uuid = '00000000-0000-1000-8000-00805f9b34fb'
+
+test(() => {
+ let base_alias = 0x0
+ assert_equals(BluetoothUUID.getService(base_alias), base_uuid);
+ assert_equals(BluetoothUUID.getCharacteristic(base_alias), base_uuid);
+ assert_equals(BluetoothUUID.getDescriptor(base_alias), base_uuid);
+}, '0x0 should produce valid UUID.');
+
+test(() => {
+ assert_equals(BluetoothUUID.getService(NaN), base_uuid);
+ assert_equals(BluetoothUUID.getCharacteristic(NaN), base_uuid);
+ assert_equals(BluetoothUUID.getDescriptor(NaN), base_uuid);
+}, 'NaN returns basic uuid');
+
+test(
+ () => {
+ let max_uuid = 'ffffffff-0000-1000-8000-00805f9b34fb';
+ let nine_digits = 0xfffffffff;
+ let thirteen_digits = 0xfffffffffffff;
+ let fourteen_digits = 0xffffffffffffff;
+ assert_equals(BluetoothUUID.getService(nine_digits), max_uuid);
+ assert_equals(BluetoothUUID.getCharacteristic(nine_digits), max_uuid);
+ assert_equals(BluetoothUUID.getDescriptor(nine_digits), max_uuid);
+ assert_equals(BluetoothUUID.getService(thirteen_digits), max_uuid);
+ assert_equals(BluetoothUUID.getCharacteristic(thirteen_digits), max_uuid);
+ assert_equals(BluetoothUUID.getDescriptor(thirteen_digits), max_uuid);
+ assert_equals(BluetoothUUID.getService(fourteen_digits), base_uuid);
+ assert_equals(
+ BluetoothUUID.getCharacteristic(fourteen_digits), base_uuid);
+ assert_equals(BluetoothUUID.getDescriptor(fourteen_digits), base_uuid);
+ },
+ 'Values between 0xfffffffff (8 digits) and 0xffffffffffffff (14 digits)' +
+ 'should return max UUID');
+
+test(() => {
+ assert_equals(BluetoothUUID.getService(Infinity), base_uuid);
+ assert_equals(BluetoothUUID.getCharacteristic(Infinity), base_uuid);
+ assert_equals(BluetoothUUID.getDescriptor(Infinity), base_uuid);
+}, 'Infinity returns base UUID');
+
+test(() => {
+ let deadbeef_alias = 0xDEADBEEF;
+ let deadbeef_uuid = 'deadbeef-0000-1000-8000-00805f9b34fb';
+ assert_equals(BluetoothUUID.getService(deadbeef_alias), deadbeef_uuid);
+ assert_equals(BluetoothUUID.getCharacteristic(deadbeef_alias), deadbeef_uuid);
+ assert_equals(BluetoothUUID.getDescriptor(deadbeef_alias), deadbeef_uuid);
+}, '0xdeadbeef should produce valid UUID.');
+
+test(() => {
+ let adeadbeef_alias = 0xADEADBEEF;
+ let adeadbeef_uuid = 'deadbeef-0000-1000-8000-00805f9b34fb';
+ assert_equals(BluetoothUUID.getService(adeadbeef_alias), adeadbeef_uuid);
+ assert_equals(
+ BluetoothUUID.getCharacteristic(adeadbeef_alias), adeadbeef_uuid);
+ assert_equals(BluetoothUUID.getDescriptor(adeadbeef_alias), adeadbeef_uuid);
+}, 'Only first 32bits should be used.');
+
+test(() => {
+ let basic_uuid = '1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d';
+ assert_equals(BluetoothUUID.getService(basic_uuid), basic_uuid);
+ assert_equals(BluetoothUUID.getCharacteristic(basic_uuid), basic_uuid);
+ assert_equals(BluetoothUUID.getDescriptor(basic_uuid), basic_uuid);
+}, 'A valid UUID String should return the same UUID.');
+
+test(() => {
+ let all_caps_uuid = '1A2B3C4D-5E6F-7A8B-9C0D-1E2F3A4B5C6D';
+ assert_throws_js(TypeError, () => BluetoothUUID.getService(all_caps_uuid));
+ assert_throws_js(
+ TypeError, () => BluetoothUUID.getCharacteristic(all_caps_uuid));
+ assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(all_caps_uuid));
+}, 'A UUID String with uppercase letters is an invalid UUID.');
+
+test(() => {
+ let string_alias = 'deadbeef';
+ assert_throws_js(TypeError, () => BluetoothUUID.getService(string_alias));
+ assert_throws_js(
+ TypeError, () => BluetoothUUID.getCharacteristic(string_alias));
+ assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(string_alias));
+}, 'A 32bit *String* alias is invalid.');
+
+test(() => {
+ let invalid_character_uuid = '0000000g-0000-1000-8000-00805f9b34fb';
+ assert_throws_js(
+ TypeError, () => BluetoothUUID.getService(invalid_character_uuid));
+ assert_throws_js(
+ TypeError,
+ () => BluetoothUUID.getCharacteristic(invalid_character_uuid));
+ assert_throws_js(
+ TypeError, () => BluetoothUUID.getDescriptor(invalid_character_uuid));
+}, 'A UUID with invalid characters is an invalid UUID.');
+
+test(() => {
+ assert_equals(
+ BluetoothUUID.getService('alert_notification'),
+ '00001811-0000-1000-8000-00805f9b34fb');
+ assert_equals(
+ BluetoothUUID.getCharacteristic('aerobic_heart_rate_lower_limit'),
+ '00002a7e-0000-1000-8000-00805f9b34fb');
+ assert_equals(
+ BluetoothUUID.getDescriptor('gatt.characteristic_extended_properties'),
+ '00002900-0000-1000-8000-00805f9b34fb');
+}, 'A valid UUID from a name.');
+
+test(() => {
+ assert_throws_js(TypeError, () => {
+ BluetoothUUID.getService('aerobic_heart_rate_lower_limit');
+ });
+ assert_throws_js(TypeError, () => {
+ BluetoothUUID.getService('gatt.characteristic_extended_properties');
+ });
+ assert_throws_js(TypeError, () => {
+ BluetoothUUID.getCharacteristic('alert_notification');
+ });
+ assert_throws_js(TypeError, () => {
+ BluetoothUUID.getCharacteristic('gatt.characteristic_extended_properties');
+ });
+ assert_throws_js(TypeError, () => {
+ BluetoothUUID.getDescriptor('alert_notification');
+ });
+ assert_throws_js(TypeError, () => {
+ BluetoothUUID.getDescriptor('aerobic_heart_rate_lower_limit');
+ });
+}, 'Make sure attributes don\'t share a map');
+
+test(() => {
+ let wrong_name = 'wrong_name';
+ assert_throws_js(TypeError, () => BluetoothUUID.getService(wrong_name));
+ assert_throws_js(TypeError, () => BluetoothUUID.getCharacteristic(wrong_name));
+ assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(wrong_name));
+}, 'Invalid Descriptor name');
+
+test(() => {
+ let object = {};
+ let array = [];
+ let func = () => {};
+
+ // cannonicalUUID
+ assert_throws_js(TypeError, () => BluetoothUUID.canonicalUUID(object));
+ // [] converts to '', which converts to 0 before the range check.
+ assert_equals(BluetoothUUID.canonicalUUID(array), base_uuid);
+ assert_throws_js(TypeError, () => BluetoothUUID.canonicalUUID(func));
+ assert_throws_js(TypeError, () => BluetoothUUID.canonicalUUID(undefined));
+ assert_equals(BluetoothUUID.canonicalUUID(null), base_uuid);
+ assert_equals(BluetoothUUID.canonicalUUID(false), base_uuid);
+ assert_equals(
+ BluetoothUUID.canonicalUUID(true), BluetoothUUID.canonicalUUID(1));
+ assert_throws_js(TypeError, () => BluetoothUUID.canonicalUUID(NaN));
+
+ // getService
+ assert_throws_js(TypeError, () => BluetoothUUID.getService(object));
+ assert_throws_js(TypeError, () => BluetoothUUID.getService(array));
+ assert_throws_js(TypeError, () => BluetoothUUID.getService(func));
+ assert_throws_js(TypeError, () => BluetoothUUID.getService(undefined));
+ assert_throws_js(TypeError, () => BluetoothUUID.getService(null));
+ assert_throws_js(TypeError, () => BluetoothUUID.getService(false));
+
+ // getCharacteristic
+ assert_throws_js(TypeError, () => BluetoothUUID.getCharacteristic(object));
+ assert_throws_js(TypeError, () => BluetoothUUID.getCharacteristic(array));
+ assert_throws_js(TypeError, () => BluetoothUUID.getCharacteristic(func));
+ assert_throws_js(TypeError, () => BluetoothUUID.getCharacteristic(undefined));
+ assert_throws_js(TypeError, () => BluetoothUUID.getCharacteristic(null));
+ assert_throws_js(TypeError, () => BluetoothUUID.getCharacteristic(false));
+
+ // getDescriptor
+ assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(object));
+ assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(array));
+ assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(func));
+ assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(undefined));
+ assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(null));
+ assert_throws_js(TypeError, () => BluetoothUUID.getDescriptor(false));
+}, 'Non-number and non-strings');
diff --git a/testing/web-platform/tests/bluetooth/idl/idl-NavigatorBluetooth.https.window.js b/testing/web-platform/tests/bluetooth/idl/idl-NavigatorBluetooth.https.window.js
new file mode 100644
index 0000000000..a087d30896
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/idl/idl-NavigatorBluetooth.https.window.js
@@ -0,0 +1,12 @@
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+'use strict';
+const test_desc = '[SameObject] test for navigator.bluetooth';
+
+test(() => {
+ assert_true('bluetooth' in navigator, 'navigator.bluetooth exists.');
+}, 'navigator.bluetooth IDL test');
+
+test(() => {
+ assert_equals(navigator.bluetooth, navigator.bluetooth);
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/idl/idl-NavigatorBluetooth.window.js b/testing/web-platform/tests/bluetooth/idl/idl-NavigatorBluetooth.window.js
new file mode 100644
index 0000000000..db6bf89f9f
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/idl/idl-NavigatorBluetooth.window.js
@@ -0,0 +1,7 @@
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+'use strict';
+
+test(() => {
+ assert_false('bluetooth' in navigator);
+}, 'navigator.bluetooth not available in insecure contexts');
diff --git a/testing/web-platform/tests/bluetooth/idl/idlharness.tentative.https.window.js b/testing/web-platform/tests/bluetooth/idl/idlharness.tentative.https.window.js
new file mode 100644
index 0000000000..a632060e20
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/idl/idlharness.tentative.https.window.js
@@ -0,0 +1,25 @@
+// META: script=/resources/WebIDLParser.js
+// META: script=/resources/idlharness.js
+// META: timeout=long
+
+'use strict';
+
+// https://webbluetoothcg.github.io/web-bluetooth/
+
+idl_test(
+ ['web-bluetooth'],
+ ['dom', 'html', 'permissions'],
+ idl_array => {
+ try {
+ self.event = new BluetoothAdvertisingEvent('type');
+ } catch(e) {
+ // Surfaced when 'event' is undefined below.
+ }
+
+ idl_array.add_objects({
+ Navigator: ['navigator'],
+ Bluetooth: ['navigator.bluetooth'],
+ BluetoothAdvertisingEvent: ['event'],
+ });
+ }
+);