bluetooth: disconnect evt to standalone tests
This change updates the gattserverdisconnected-event tests in wpt/ to be
standalone window tests. This change allows the tests to be formatted
with clang-format.
Bug: 994756
Change-Id: Id08fd9bdef1fc8b37d8ad192b23e11a77a99f4c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1761071
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Matt Reynolds <mattreynolds@chromium.org>
Auto-Submit: Ovidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689743}
diff --git a/bluetooth/device/gattserverdisconnected-event/disconnected.https.html b/bluetooth/device/gattserverdisconnected-event/disconnected.https.html
deleted file mode 100644
index c406e50..0000000
--- a/bluetooth/device/gattserverdisconnected-event/disconnected.https.html
+++ /dev/null
@@ -1,19 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="/resources/testdriver.js"></script>
-<script src="/resources/testdriver-vendor.js"></script>
-<script src="/bluetooth/resources/bluetooth-helpers.js"></script>
-<script>
-'use strict';
-const test_desc = 'A device disconnecting while connected should fire the ' +
- 'gattserverdisconnected event.';
-
-bluetooth_test(() => getConnectedHealthThermometerDevice()
- .then(({device, fake_peripheral}) => {
- fake_peripheral.simulateGATTDisconnection();
- return eventPromise(device, 'gattserverdisconnected');
- })
- .then(e => assert_true(e.bubbles)),
- test_desc);
-</script>
diff --git a/bluetooth/device/gattserverdisconnected-event/disconnected.https.window.js b/bluetooth/device/gattserverdisconnected-event/disconnected.https.window.js
new file mode 100644
index 0000000..245e43d
--- /dev/null
+++ b/bluetooth/device/gattserverdisconnected-event/disconnected.https.window.js
@@ -0,0 +1,17 @@
+// META: script=/resources/testharness.js
+// META: script=/resources/testharnessreport.js
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+// META: script=/bluetooth/resources/bluetooth-helpers.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/bluetooth/device/gattserverdisconnected-event/disconnected_gc.https.html b/bluetooth/device/gattserverdisconnected-event/disconnected_gc.https.html
deleted file mode 100644
index 8208231..0000000
--- a/bluetooth/device/gattserverdisconnected-event/disconnected_gc.https.html
+++ /dev/null
@@ -1,24 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="/resources/testdriver.js"></script>
-<script src="/resources/testdriver-vendor.js"></script>
-<script src="/bluetooth/resources/bluetooth-helpers.js"></script>
-<script>
-'use strict';
-const test_desc = 'A device disconnecting after the BluetoothDevice object ' +
- 'has been GC\'ed should not access freed memory.';
-
-bluetooth_test(() => getConnectedHealthThermometerDevice()
- .then(({fake_peripheral}) => {
- // 1. Disconnect.
- fake_peripheral.simulateGATTDisconnection();
- // 2. Run garbage collection.
- fake_peripheral = undefined;
- runGarbageCollection();
- })
- // 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.
- .then(() => new Promise(resolve => step_timeout(resolve, 50))),
- test_desc);
-</script>
diff --git a/bluetooth/device/gattserverdisconnected-event/disconnected_gc.https.window.js b/bluetooth/device/gattserverdisconnected-event/disconnected_gc.https.window.js
new file mode 100644
index 0000000..69e3044
--- /dev/null
+++ b/bluetooth/device/gattserverdisconnected-event/disconnected_gc.https.window.js
@@ -0,0 +1,23 @@
+// META: script=/resources/testharness.js
+// META: script=/resources/testharnessreport.js
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+// META: script=/bluetooth/resources/bluetooth-helpers.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 runGarbageCollection();
+
+ // 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/bluetooth/device/gattserverdisconnected-event/one-event-per-disconnection.https.html b/bluetooth/device/gattserverdisconnected-event/one-event-per-disconnection.https.html
deleted file mode 100644
index 92be9c3..0000000
--- a/bluetooth/device/gattserverdisconnected-event/one-event-per-disconnection.https.html
+++ /dev/null
@@ -1,32 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="/resources/testdriver.js"></script>
-<script src="/resources/testdriver-vendor.js"></script>
-<script src="/bluetooth/resources/bluetooth-helpers.js"></script>
-<script>
-'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.';
-let device, fake_peripheral;
-let num_events = 0;
-
-bluetooth_test(() => getConnectedHealthThermometerDevice()
- .then(_ => ({device, fake_peripheral} = _))
- // 1. Listen for disconnections.
- .then(() =>
- device.addEventListener('gattserverdisconnected', () => num_events++))
- // 2. Disconnect several times.
- .then(() => Promise.all([
- eventPromise(device, 'gattserverdisconnected'),
- fake_peripheral.simulateGATTDisconnection(),
- device.gatt.disconnect(),
- device.gatt.disconnect(),
- ]))
- // 3. Wait to catch disconnect events.
- .then(() => new Promise(resolve => step_timeout(resolve, 50)))
- // 4. Ensure there is exactly 1 disconnection recorded.
- .then(() => assert_equals(num_events, 1)),
- test_desc);
-</script>
diff --git a/bluetooth/device/gattserverdisconnected-event/one-event-per-disconnection.https.window.js b/bluetooth/device/gattserverdisconnected-event/one-event-per-disconnection.https.window.js
new file mode 100644
index 0000000..317edde
--- /dev/null
+++ b/bluetooth/device/gattserverdisconnected-event/one-event-per-disconnection.https.window.js
@@ -0,0 +1,31 @@
+// META: script=/resources/testharness.js
+// META: script=/resources/testharnessreport.js
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+// META: script=/bluetooth/resources/bluetooth-helpers.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/bluetooth/device/gattserverdisconnected-event/reconnect-during-disconnected-event.https.html b/bluetooth/device/gattserverdisconnected-event/reconnect-during-disconnected-event.https.html
deleted file mode 100644
index 6d0c8e2..0000000
--- a/bluetooth/device/gattserverdisconnected-event/reconnect-during-disconnected-event.https.html
+++ /dev/null
@@ -1,34 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="/resources/testdriver.js"></script>
-<script src="/resources/testdriver-vendor.js"></script>
-<script src="/bluetooth/resources/bluetooth-helpers.js"></script>
-<script>
-'use strict';
-let test_desc = 'A device that reconnects during the gattserverdisconnected ' +
- 'event should still receive gattserverdisconnected events after ' +
- 're-connection.';
-let device, fake_peripheral;
-bluetooth_test(() => getConnectedHealthThermometerDevice()
- .then(_ => ({device, fake_peripheral} = _))
- // 1. Disconnect.
- .then(() => new Promise(resolve => {
- fake_peripheral.simulateGATTDisconnection();
- device.addEventListener(
- 'gattserverdisconnected', function onDisconnected() {
- device.removeEventListener('gattserverdisconnected', onDisconnected);
- // 2. Reconnect.
- fake_peripheral.setNextGATTConnectionResponse({
- code: HCI_SUCCESS,
- })
- .then(() => device.gatt.connect())
- .then(() => resolve());
- });
- }))
- // 3. Disconnect after reconnecting.
- .then(() => {
- fake_peripheral.simulateGATTDisconnection();
- return eventPromise(device, 'gattserverdisconnected')
- }), test_desc);
-</script>
diff --git a/bluetooth/device/gattserverdisconnected-event/reconnect-during-disconnected-event.https.window.js b/bluetooth/device/gattserverdisconnected-event/reconnect-during-disconnected-event.https.window.js
new file mode 100644
index 0000000..93a46ee
--- /dev/null
+++ b/bluetooth/device/gattserverdisconnected-event/reconnect-during-disconnected-event.https.window.js
@@ -0,0 +1,32 @@
+// META: script=/resources/testharness.js
+// META: script=/resources/testharnessreport.js
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+// META: script=/bluetooth/resources/bluetooth-helpers.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);