blob: c26713536f61d7d94f6f3b7a8505ce1fd48cb048 [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';
promise_test(() => {
// The iframe we create will subscribe to notifications and will ensure
// that the browser keeps receiving notifications even after this frame's
// device disconnects.
let iframe_connected = new Promise((resolve, reject) => {
window.onmessage = messageEvent => {
if (messageEvent.data === 'Ready') {
let iframe = document.querySelector('iframe');
callWithKeyDown(() => {
iframe.contentWindow.postMessage('RequestAndConnect', '*');
});
} else if (messageEvent.data === 'Connected') {
let iframe = document.querySelector('iframe');
iframe.contentWindow.postMessage('StartNotifications', '*');
} else if (messageEvent.data === 'NotificationsStarted') {
resolve();
} else {
reject();
}
}
});
return setBluetoothFakeAdapter('HeartRateAdapter')
.then(() => {
let iframe = document.createElement('iframe');
iframe.src = '../../../resources/bluetooth/heart-rate-iframe.html';
document.body.appendChild(iframe);
return iframe_connected
.then(() => requestDeviceWithKeyDown(
{filters: [{services: ['heart_rate']}]}))
.then(device => device.gatt.connect())
.then(gatt => gatt.getPrimaryService('heart_rate'))
.then(service => service.getCharacteristic('heart_rate_measurement'))
.then(characteristic => characteristic.startNotifications())
.then(characteristic => new Promise(resolve => {
// Make sure we are receiving events.
let event_listener = () => {
characteristic.removeEventListener(
'characteristicvaluechanged', event_listener);
resolve(characteristic);
};
characteristic.addEventListener(
'characteristicvaluechanged', event_listener);
}))
.then(characteristic => {
characteristic.service.device.gatt.disconnect()
// The browser still receives notifications because of the iframe but
// no events should be dispatched on this characteristic because
// the characteristic's device disconnected.
return assert_no_events(characteristic,
'characteristicvaluechanged');
});
});
}, 'Characteristic sends notification after disconnection. Should not ' +
'fire an event.');
</script>