| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../../../resources/testharness.js"></script> |
| 3 <script src="../../../resources/testharnessreport.js"></script> |
| 4 <script src="../../../resources/bluetooth/bluetooth-helpers.js"></script> |
| 5 <script> |
| 6 'use strict'; |
| 7 promise_test(() => { |
| 8 // The iframe we create will subscribe to notifications and will ensure |
| 9 // that the browser keeps receiving notifications even after this frame's |
| 10 // device disconnects. |
| 11 let iframe_connected = new Promise(resolve => { |
| 12 window.onmessage = messageEvent => { |
| 13 if (messageEvent.data === 'Ready') { |
| 14 let iframe = document.querySelector('iframe'); |
| 15 callWithKeyDown(() => { |
| 16 iframe.contentWindow.postMessage('RequestAndConnect', '*'); |
| 17 }); |
| 18 } else if (messageEvent.data === 'Connected') { |
| 19 let iframe = document.querySelector('iframe'); |
| 20 iframe.contentWindow.postMessage('StartNotifications', '*'); |
| 21 } else if (messageEvent.data === 'NotificationsStarted') { |
| 22 resolve(); |
| 23 } else { |
| 24 reject(); |
| 25 } |
| 26 } |
| 27 }); |
| 28 |
| 29 return setBluetoothFakeAdapter('HeartRateAdapter') |
| 30 .then(() => { |
| 31 let iframe = document.createElement('iframe'); |
| 32 iframe.src = '../../../resources/bluetooth/heart-rate-iframe.html'; |
| 33 document.body.appendChild(iframe); |
| 34 |
| 35 return iframe_connected |
| 36 .then(() => requestDeviceWithKeyDown( |
| 37 {filters: [{services: ['heart_rate']}]})) |
| 38 .then(device => device.gatt.connect()) |
| 39 .then(gatt => gatt.getPrimaryService('heart_rate')) |
| 40 .then(service => service.getCharacteristic('heart_rate_measurement')) |
| 41 .then(characteristic => characteristic.startNotifications()) |
| 42 .then(characteristic => new Promise(resolve => { |
| 43 // Make sure we are receiving events. |
| 44 let event_listener = e => { |
| 45 characteristic.removeEventListener( |
| 46 'characteristicvaluechanged', event_listener); |
| 47 resolve(characteristic); |
| 48 }; |
| 49 characteristic.addEventListener( |
| 50 'characteristicvaluechanged', event_listener); |
| 51 })) |
| 52 .then(characteristic => { |
| 53 characteristic.service.device.gatt.disconnect() |
| 54 // The browser still receives notifications because of the iframe but |
| 55 // no events should be dispatched on this characteristic because |
| 56 // the characteristic's device disconnected. |
| 57 return assert_no_events(characteristic, |
| 58 'characteristicvaluechanged'); |
| 59 }); |
| 60 }); |
| 61 }, 'Characteristic sends notification after disconnection. Should not ' + |
| 62 'fire an event.'); |
| 63 </script> |
| OLD | NEW |