blob: 0c4ff44ff41e9fc77c54b2b7ece501a69281ba37 [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 src="../../../resources/bluetooth/web-bluetooth-test.js"></script>
<script src="../../../resources/mojo-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;
promise_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>