blob: ec6133ee14475d9a4c9930b18f35608138d31d33 [file] [log] [blame]
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/bluetooth/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(() => getHealthThermometerDevice()
.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>