Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: third_party/WebKit/LayoutTests/bluetooth/gattserverdisconnected-event/reconnect-during-disconnected-event.html

Issue 2441313002: bluetooth: Introduce helper function for requesting a disconnection (Closed)
Patch Set: Add example to function Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src="../../resources/testharness.js"></script> 2 <script src="../../resources/testharness.js"></script>
3 <script src="../../resources/testharnessreport.js"></script> 3 <script src="../../resources/testharnessreport.js"></script>
4 <script src="../../resources/bluetooth/bluetooth-helpers.js"></script> 4 <script src="../../resources/bluetooth/bluetooth-helpers.js"></script>
5 <script> 5 <script>
6 'use strict'; 6 'use strict';
7 promise_test(t => { 7 promise_test(t => {
8 return setBluetoothFakeAdapter('DisconnectingHeartRateAdapter') 8 return setBluetoothFakeAdapter('DisconnectingHeartRateAdapter')
9 .then(() => requestDeviceWithKeyDown({ 9 .then(() => requestDeviceWithKeyDown({
10 filters: [{services: ['heart_rate']}], 10 filters: [{services: ['heart_rate']}],
11 optionalServices: [request_disconnection_service_uuid] 11 optionalServices: [request_disconnection_service_uuid]
12 })) 12 }))
13 .then(device => { 13 .then(device => {
14 return device.gatt.connect() 14 return device.gatt.connect()
15 .then(gattServer => gattServer.getPrimaryService(request_disconnection_s ervice_uuid)) 15 .then(gattServer => get_request_disconnection(gattServer))
16 .then(service => service.getCharacteristic(request_disconnection_charact eristic_uuid))
17 .then(requestDisconnection => { 16 .then(requestDisconnection => {
18 // 1. Attach a listener that tries to reconnect. 17 // 1. Attach a listener that tries to reconnect.
19 let reconnection = new Promise(resolve => { 18 let reconnection = new Promise(resolve => {
20 let wrapper = function(event) { 19 let wrapper = function(event) {
21 device.removeEventListener('gattserverdisconnected', wrapper); 20 device.removeEventListener('gattserverdisconnected', wrapper);
22 device.gatt.connect().then(resolve); 21 device.gatt.connect().then(resolve);
23 }; 22 };
24 device.addEventListener('gattserverdisconnected', wrapper); 23 device.addEventListener('gattserverdisconnected', wrapper);
25 }); 24 });
26 // 2. Disconnect. 25 // 2. Disconnect.
27 requestDisconnection.writeValue(new Uint8Array([0])); 26 requestDisconnection();
28 return reconnection.then(() => { 27 return reconnection.then(() => {
29 // Resolves after disconnected event. 28 // Resolves after disconnected event.
30 let disconnected = eventPromise(device, 'gattserverdisconnected'); 29 let disconnected = eventPromise(device, 'gattserverdisconnected');
31 // 3. Disconnect after reconnecting. 30 // 3. Disconnect after reconnecting.
32 requestDisconnection.writeValue(new Uint8Array([0])); 31 requestDisconnection();
33 return disconnected; 32 return disconnected;
34 }); 33 });
35 }); 34 });
36 }); 35 });
37 }, 'A device that reconnects during the gattserverdisconnected event ' + 36 }, 'A device that reconnects during the gattserverdisconnected event ' +
38 'should still receive gattserverdisconnected events after re-connection.'); 37 'should still receive gattserverdisconnected events after re-connection.');
39 </script> 38 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698