| 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-helpers.js"></script> | 
|  | 5 <script> | 
|  | 6 'use strict'; | 
|  | 7 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, | 
|  | 8      'window.testRunner is required for the following tests.'); | 
|  | 9 | 
|  | 10 promise_test(() => { | 
|  | 11   testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 
|  | 12   return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 
|  | 13     .then(device => device.connectGATT()) | 
|  | 14     .then(gattServer => gattServer.getPrimaryService('heart_rate')) | 
|  | 15     .then(service => service.getCharacteristic('body_sensor_location')) | 
|  | 16     .then(characteristic => { | 
|  | 17       return assert_event_fires_after_promise(characteristic, | 
|  | 18                                               'readValue', | 
|  | 19                                               'characteristicvaluechanged'); | 
|  | 20     }).then(results => { | 
|  | 21       let read_value = new Uint8Array(results[0]); | 
|  | 22       let event_value = new Uint8Array(results[1]); | 
|  | 23       // TODO(ortuno): The ArrayBuffer used to resolve the promise | 
|  | 24       // should be the same ArrayBuffer as the one saved in the | 
|  | 25       // characteristic. | 
|  | 26       // http://crbug.com/543347 | 
|  | 27       // assert_equals(event.target.value, value); | 
|  | 28       assert_array_equals(event_value, read_value); | 
|  | 29     }); | 
|  | 30 }, 'Reading a characteristic should fire an event.'); | 
|  | 31 | 
|  | 32 promise_test(() => { | 
|  | 33   testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 
|  | 34   return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 
|  | 35     .then(device => device.connectGATT()) | 
|  | 36     .then(gattServer => gattServer.getPrimaryService('heart_rate')) | 
|  | 37     .then(service => service.getCharacteristic('body_sensor_location')) | 
|  | 38     .then(characteristic => { | 
|  | 39       return assert_event_fires_after_promise(characteristic, | 
|  | 40                                               'readValue', | 
|  | 41                                               'characteristicvaluechanged', | 
|  | 42                                               3 /* attach 3 listeners */); | 
|  | 43     }).then(results => { | 
|  | 44       let read_value = new Uint8Array(results[0]); | 
|  | 45       let event_values = results.slice(1).map(v => new Uint8Array(v)); | 
|  | 46       for (let event_value of event_values) { | 
|  | 47         // TODO(ortuno): The ArrayBuffer used to resolve the promise | 
|  | 48         // should be the same ArrayBuffer as the one saved in the | 
|  | 49         // characteristic. | 
|  | 50         // http://crbug.com/543347 | 
|  | 51         // assert_equals(event.target.value, value); | 
|  | 52         assert_array_equals(event_value, read_value); | 
|  | 53       } | 
|  | 54     }); | 
|  | 55 }, 'Add multiple event listeners then readValue().'); | 
|  | 56 | 
|  | 57 promise_test(() => { | 
|  | 58   testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 
|  | 59   let char; | 
|  | 60   return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 
|  | 61    .then(device => device.connectGATT()) | 
|  | 62    .then(gattServer => gattServer.getPrimaryService('heart_rate')) | 
|  | 63    .then(service => service.getCharacteristic('heart_rate_measurement')) | 
|  | 64    .then(characteristic => { | 
|  | 65      char = characteristic; | 
|  | 66      return assert_event_fires_after_promise(characteristic, | 
|  | 67                                              'startNotifications', | 
|  | 68                                              'characteristicvaluechanged'); | 
|  | 69    }).then(() => char.stopNotifications()) | 
|  | 70    .then(() => assert_no_events(char, 'characteristicvaluechanged')); | 
|  | 71 }, 'Starting notifications should fire an event.'); | 
|  | 72 | 
|  | 73 promise_test(() => { | 
|  | 74   testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 
|  | 75   let char; | 
|  | 76   return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 
|  | 77    .then(device => device.connectGATT()) | 
|  | 78    .then(gattServer => gattServer.getPrimaryService('heart_rate')) | 
|  | 79    .then(service => service.getCharacteristic('heart_rate_measurement')) | 
|  | 80    .then(characteristic => { | 
|  | 81      char = characteristic; | 
|  | 82      return assert_event_fires_after_promise(characteristic, | 
|  | 83                                              'startNotifications', | 
|  | 84                                              'characteristicvaluechanged', | 
|  | 85                                              3 /* add 3 listeners */); | 
|  | 86    }).then(() => char.stopNotifications()) | 
|  | 87    .then(() => assert_no_events(char, 'characteristicvaluechanged')); | 
|  | 88 }, 'Add multiple event listeners then startNotifications().'); | 
|  | 89 </script> | 
| OLD | NEW | 
|---|