summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/bluetooth/adapter
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/adapter
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/adapter')
-rw-r--r--testing/web-platform/tests/bluetooth/adapter/adapter-absent-getAvailability.https.window.js15
-rw-r--r--testing/web-platform/tests/bluetooth/adapter/adapter-added-getAvailability.https.window.js23
-rw-r--r--testing/web-platform/tests/bluetooth/adapter/adapter-powered-off-getAvailability.https.window.js16
-rw-r--r--testing/web-platform/tests/bluetooth/adapter/adapter-powered-on-getAvailability.https.window.js16
-rw-r--r--testing/web-platform/tests/bluetooth/adapter/adapter-powered-on-off-on-getAvailability.https.window.js37
-rw-r--r--testing/web-platform/tests/bluetooth/adapter/adapter-removed-getAvailability.https.window.js24
-rw-r--r--testing/web-platform/tests/bluetooth/adapter/cross-origin-iframe-getAvailability.sub.https.window.js31
7 files changed, 162 insertions, 0 deletions
diff --git a/testing/web-platform/tests/bluetooth/adapter/adapter-absent-getAvailability.https.window.js b/testing/web-platform/tests/bluetooth/adapter/adapter-absent-getAvailability.https.window.js
new file mode 100644
index 0000000000..55f4a675da
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/adapter/adapter-absent-getAvailability.https.window.js
@@ -0,0 +1,15 @@
+// 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 = 'getAvailability() resolves with false if the system does ' +
+ 'not have an adapter.';
+
+bluetooth_test(async () => {
+ await navigator.bluetooth.test.simulateCentral({state: 'absent'});
+ let availability = await navigator.bluetooth.getAvailability();
+ assert_false(
+ availability,
+ 'getAvailability() resolves promise with false when adapter is absent.');
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/adapter/adapter-added-getAvailability.https.window.js b/testing/web-platform/tests/bluetooth/adapter/adapter-added-getAvailability.https.window.js
new file mode 100644
index 0000000000..f8e25b2ac2
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/adapter/adapter-added-getAvailability.https.window.js
@@ -0,0 +1,23 @@
+// 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 = 'getAvailability() resolves with true after adapter is ' +
+ 'inserted into a system with a platform that supports Bluetooth LE.';
+
+bluetooth_test(async () => {
+ const fake_central =
+ await navigator.bluetooth.test.simulateCentral({state: 'absent'});
+ let availability = await navigator.bluetooth.getAvailability();
+ assert_false(
+ availability,
+ 'getAvailability() resolves promise with false when adapter is absent.');
+
+ await fake_central.setState('powered-on');
+ availability = await navigator.bluetooth.getAvailability();
+ assert_true(
+ availability,
+ 'getAvailability() resolves promise with true after Bluetooth LE ' +
+ 'capable adapter has been has been added.');
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/adapter/adapter-powered-off-getAvailability.https.window.js b/testing/web-platform/tests/bluetooth/adapter/adapter-powered-off-getAvailability.https.window.js
new file mode 100644
index 0000000000..1ffcd3bb09
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/adapter/adapter-powered-off-getAvailability.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 = 'getAvailability() resolves with true if the Bluetooth ' +
+ 'radio is powered off, but the platform that supports Bluetooth LE.';
+
+bluetooth_test(async () => {
+ await navigator.bluetooth.test.simulateCentral({state: 'powered-off'});
+ let availability = await navigator.bluetooth.getAvailability();
+ assert_true(
+ availability,
+ 'getAvailability() resolves promise with true when adapter is powered ' +
+ 'off.');
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/adapter/adapter-powered-on-getAvailability.https.window.js b/testing/web-platform/tests/bluetooth/adapter/adapter-powered-on-getAvailability.https.window.js
new file mode 100644
index 0000000000..84c7982d21
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/adapter/adapter-powered-on-getAvailability.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 = 'getAvailability() resolves with true if the Bluetooth ' +
+ 'radio is powered on and the platform supports Bluetooth LE.';
+
+bluetooth_test(async () => {
+ await navigator.bluetooth.test.simulateCentral({state: 'powered-on'});
+ let availability = await navigator.bluetooth.getAvailability();
+ assert_true(
+ availability,
+ 'getAvailability() resolves promise with true when adapter is powered ' +
+ 'on and it supports Bluetooth Low-Energy.');
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/adapter/adapter-powered-on-off-on-getAvailability.https.window.js b/testing/web-platform/tests/bluetooth/adapter/adapter-powered-on-off-on-getAvailability.https.window.js
new file mode 100644
index 0000000000..c4ba9b5f3a
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/adapter/adapter-powered-on-off-on-getAvailability.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 = 'getAvailability() is not affected by the powered state of ' +
+ 'the adapter.';
+
+bluetooth_test(async () => {
+ const fake_central =
+ await navigator.bluetooth.test.simulateCentral({state: 'powered-on'});
+ {
+ const availability = await navigator.bluetooth.getAvailability();
+ assert_true(
+ availability,
+ 'getAvailability() resolves promise with true when adapter is ' +
+ 'powered on and it supports Bluetooth Low-Energy.');
+ }
+
+ {
+ await fake_central.setState('powered-off');
+ const availability = await navigator.bluetooth.getAvailability();
+ assert_true(
+ availability,
+ 'getAvailability() resolves promise with true after adapter powered ' +
+ 'off.');
+ }
+
+ {
+ await fake_central.setState('powered-on');
+ const availability = await navigator.bluetooth.getAvailability();
+ assert_true(
+ availability,
+ 'getAvailability() resolves promise with true when adapter is ' +
+ 'powered back on.');
+ }
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/adapter/adapter-removed-getAvailability.https.window.js b/testing/web-platform/tests/bluetooth/adapter/adapter-removed-getAvailability.https.window.js
new file mode 100644
index 0000000000..ca0b51f47d
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/adapter/adapter-removed-getAvailability.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 = 'getAvailability() resolves with false after the powered ' +
+ 'on adapter is removed.';
+
+bluetooth_test(async () => {
+ const fake_central =
+ await navigator.bluetooth.test.simulateCentral({state: 'powered-on'});
+ let availability = await navigator.bluetooth.getAvailability();
+ assert_true(
+ availability,
+ 'getAvailability() resolves promise with true when adapter is powered ' +
+ 'on and it supports Bluetooth Low-Energy.');
+
+ await fake_central.setState('absent');
+ availability = await navigator.bluetooth.getAvailability();
+ assert_false(
+ availability,
+ 'getAvailability() resolves promise with false after adapter has been ' +
+ 'has been removed.');
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/adapter/cross-origin-iframe-getAvailability.sub.https.window.js b/testing/web-platform/tests/bluetooth/adapter/cross-origin-iframe-getAvailability.sub.https.window.js
new file mode 100644
index 0000000000..54abfbb5ce
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/adapter/cross-origin-iframe-getAvailability.sub.https.window.js
@@ -0,0 +1,31 @@
+// 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 = 'getAvailability() resolves with false if called from a ' +
+ 'unique origin';
+const cross_origin_src = 'https://{{domains[www]}}:{{ports[https][0]}}' +
+ '/bluetooth/resources/health-thermometer-iframe.html'
+let iframe = document.createElement('iframe');
+
+bluetooth_test(async () => {
+ await navigator.bluetooth.test.simulateCentral({state: 'powered-on'});
+ await new Promise(resolve => {
+ iframe.src = cross_origin_src;
+ document.body.appendChild(iframe);
+ iframe.addEventListener('load', resolve);
+ });
+ await new Promise(resolve => {
+ callWithTrustedClick(
+ () => iframe.contentWindow.postMessage({type: 'GetAvailability'}, '*'));
+
+ window.onmessage = messageEvent => {
+ assert_equals(
+ messageEvent.data, false,
+ 'getAvailability resolves to false when called from a unique ' +
+ 'origin.');
+ resolve();
+ };
+ });
+}, test_desc);