OLD | NEW |
1 'use strict'; | 1 'use strict'; |
2 promise_test(() => { | 2 promise_test(() => { |
3 return setBluetoothFakeAdapter('DisconnectingHealthThermometerAdapter') | 3 return setBluetoothFakeAdapter('DisconnectingHealthThermometerAdapter') |
4 .then(() => requestDeviceWithKeyDown({ | 4 .then(() => requestDeviceWithKeyDown({ |
5 filters: [{services: ['health_thermometer']}], | 5 filters: [{services: ['health_thermometer']}], |
6 optionalServices: [request_disconnection_service_uuid]})) | 6 optionalServices: [request_disconnection_service_uuid]})) |
7 .then(device => device.gatt.connect()) | 7 .then(device => device.gatt.connect()) |
8 .then(gattServer => { | 8 .then(gattServer => { |
9 let characteristics; | 9 let characteristics; |
10 return gattServer.getPrimaryService('health_thermometer') | 10 return gattServer.getPrimaryService('health_thermometer') |
11 .then(service => service.CALLS([ | 11 .then(service => service.CALLS([ |
12 getCharacteristic('measurement_interval')| | 12 getCharacteristic('measurement_interval')| |
13 getCharacteristics()| | 13 getCharacteristics()| |
14 getCharacteristics('measurement_interval')[UUID]])) | 14 getCharacteristics('measurement_interval')[UUID]])) |
15 .then(c => { | 15 .then(c => { |
16 // Convert to array if necessary. | 16 // Convert to array if necessary. |
17 characteristics = [].concat(c); | 17 characteristics = [].concat(c); |
18 return get_request_disconnection(gattServer); | 18 return get_request_disconnection(gattServer); |
19 }) | 19 }) |
20 .then(requestDisconnection => requestDisconnection()) | 20 .then(requestDisconnection => requestDisconnection()) |
21 .then(() => gattServer.connect()) | 21 .then(() => gattServer.connect()) |
22 .then(() => characteristics); | 22 .then(() => characteristics); |
23 }) | 23 }) |
24 .then(characteristics => { | 24 .then(characteristics => { |
25 let promises = Promise.resolve(); | 25 let promises = Promise.resolve(); |
26 for (let characteristic of characteristics) { | 26 for (let characteristic of characteristics) { |
27 let error = new DOMException( | 27 let error = new DOMException( |
28 'Characteristic is no longer valid. Remember to retrieve the ' + | 28 'Characteristic with UUID ' + characteristic.uuid + |
| 29 ' is no longer valid. Remember to retrieve the ' + |
29 'characteristic again after reconnecting.', | 30 'characteristic again after reconnecting.', |
30 'InvalidStateError'); | 31 'InvalidStateError'); |
31 promises = promises.then(() => | 32 promises = promises.then(() => |
32 assert_promise_rejects_with_message( | 33 assert_promise_rejects_with_message( |
33 characteristic.readValue(), | 34 characteristic.readValue(), |
34 error)); | 35 error)); |
35 promises = promises.then(() => | 36 promises = promises.then(() => |
36 assert_promise_rejects_with_message( | 37 assert_promise_rejects_with_message( |
37 characteristic.writeValue(new Uint8Array([1])), | 38 characteristic.writeValue(new Uint8Array([1])), |
38 error)); | 39 error)); |
39 promises = promises.then(() => | 40 promises = promises.then(() => |
40 assert_promise_rejects_with_message( | 41 assert_promise_rejects_with_message( |
41 characteristic.startNotifications(), | 42 characteristic.startNotifications(), |
42 error)); | 43 error)); |
43 promises = promises.then(() => | 44 promises = promises.then(() => |
44 assert_promise_rejects_with_message( | 45 assert_promise_rejects_with_message( |
45 characteristic.stopNotifications(), | 46 characteristic.stopNotifications(), |
46 error)); | 47 error)); |
47 } | 48 } |
48 return promises; | 49 return promises; |
49 }); | 50 }); |
50 }, 'Calls on characteristics after device disconnects and we reconnect. ' + | 51 }, 'Calls on characteristics after device disconnects and we reconnect. ' + |
51 'Should reject with InvalidStateError.'); | 52 'Should reject with InvalidStateError.'); |
OLD | NEW |