summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event')
-rw-r--r--testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/disconnected.https.window.js16
-rw-r--r--testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/disconnected_gc.https.window.js23
-rw-r--r--testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/one-event-per-disconnection.https.window.js30
-rw-r--r--testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/reconnect-during-disconnected-event.https.window.js31
4 files changed, 100 insertions, 0 deletions
diff --git a/testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/disconnected.https.window.js b/testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/disconnected.https.window.js
new file mode 100644
index 0000000000..43a11a88cb
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/disconnected.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 = 'A device disconnecting while connected should fire the ' +
+ 'gattserverdisconnected event.';
+
+bluetooth_test(async () => {
+ const {device, fake_peripheral} = await getConnectedHealthThermometerDevice();
+ const disconnectPromise = eventPromise(device, 'gattserverdisconnected');
+
+ await fake_peripheral.simulateGATTDisconnection();
+ let disconnectEvent = await disconnectPromise;
+ assert_true(disconnectEvent.bubbles);
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/disconnected_gc.https.window.js b/testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/disconnected_gc.https.window.js
new file mode 100644
index 0000000000..0cf4973e21
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/disconnected_gc.https.window.js
@@ -0,0 +1,23 @@
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+// META: script=/common/gc.js
+// META: script=/bluetooth/resources/bluetooth-test.js
+// META: script=/bluetooth/resources/bluetooth-fake-devices.js
+'use strict';
+const test_desc = 'A device disconnecting after the BluetoothDevice object ' +
+ 'has been GC\'ed should not access freed memory.';
+
+bluetooth_test(async () => {
+ let {fake_peripheral} = await getConnectedHealthThermometerDevice();
+
+ // 1. Disconnect.
+ await fake_peripheral.simulateGATTDisconnection();
+
+ // 2. Run garbage collection.
+ fake_peripheral = undefined;
+ await garbageCollect();
+
+ // 3. Wait 50ms after the GC runs for the disconnection event to come back.
+ // There's nothing to assert other than that only valid memory is used.
+ await new Promise(resolve => step_timeout(resolve, 50));
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/one-event-per-disconnection.https.window.js b/testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/one-event-per-disconnection.https.window.js
new file mode 100644
index 0000000000..ab273adbc8
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/one-event-per-disconnection.https.window.js
@@ -0,0 +1,30 @@
+// 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 = 'If a site disconnects from a device while the platform is ' +
+ 'disconnecting that device, only one gattserverdisconnected event should ' +
+ 'fire.';
+
+bluetooth_test(async () => {
+ const {device, fake_peripheral} = await getConnectedHealthThermometerDevice();
+ let num_events = 0;
+
+ // 1. Listen for disconnections.
+ device.addEventListener('gattserverdisconnected', () => num_events++);
+
+ // 2. Disconnect several times.
+ await Promise.all([
+ eventPromise(device, 'gattserverdisconnected'),
+ fake_peripheral.simulateGATTDisconnection(),
+ device.gatt.disconnect(),
+ device.gatt.disconnect(),
+ ]);
+
+ // 3. Wait to catch disconnect events.
+ await new Promise(resolve => step_timeout(resolve, 50));
+
+ // 4. Ensure there is exactly 1 disconnection recorded.
+ assert_equals(num_events, 1);
+}, test_desc);
diff --git a/testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/reconnect-during-disconnected-event.https.window.js b/testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/reconnect-during-disconnected-event.https.window.js
new file mode 100644
index 0000000000..bdaf47c661
--- /dev/null
+++ b/testing/web-platform/tests/bluetooth/device/gattserverdisconnected-event/reconnect-during-disconnected-event.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 = 'A device that reconnects during the ' +
+ 'gattserverdisconnected event should still receive ' +
+ 'gattserverdisconnected events after re-connection.';
+
+bluetooth_test(async () => {
+ const {device, fake_peripheral} = await getConnectedHealthThermometerDevice();
+
+ const reconnectPromise = new Promise(async (resolve) => {
+ device.addEventListener('gattserverdisconnected', async () => {
+ // 2. Reconnect.
+ await fake_peripheral.setNextGATTConnectionResponse({
+ code: HCI_SUCCESS,
+ });
+ await device.gatt.connect();
+
+ // 3. Disconnect after reconnecting.
+ const disconnectPromise = eventPromise(device, 'gattserverdisconnected');
+ fake_peripheral.simulateGATTDisconnection();
+ resolve(disconnectPromise);
+ }, {once: true});
+ });
+
+ // 1. Disconnect.
+ await fake_peripheral.simulateGATTDisconnection();
+ await reconnectPromise;
+}, test_desc);