OLD | NEW |
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 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, | 7 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, |
8 'window.testRunner is required for the following tests.'); | 8 'window.testRunner is required for the following tests.'); |
9 | 9 |
10 // WebBluetoothServiceImpl is in charge of sending characteristicvaluechanged | 10 // WebBluetoothServiceImpl is in charge of sending characteristicvaluechanged |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // TODO(ortuno): The DataView used to resolve the promise | 57 // TODO(ortuno): The DataView used to resolve the promise |
58 // should be the same DataView as the one saved in the | 58 // should be the same DataView as the one saved in the |
59 // characteristic. | 59 // characteristic. |
60 // http://crbug.com/543347 | 60 // http://crbug.com/543347 |
61 // assert_equals(event.target.value, value); | 61 // assert_equals(event.target.value, value); |
62 assert_array_equals(event_value, read_value); | 62 assert_array_equals(event_value, read_value); |
63 } | 63 } |
64 }); | 64 }); |
65 }, 'Add multiple event listeners then readValue().'); | 65 }, 'Add multiple event listeners then readValue().'); |
66 } | 66 } |
67 | |
68 promise_test(() => { | |
69 let char; | |
70 return setBluetoothFakeAdapter('HeartRateAdapter') | |
71 .then(() => requestDeviceWithKeyDown({ | |
72 filters: [{services: ['heart_rate']}]})) | |
73 .then(device => device.gatt.connect()) | |
74 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | |
75 .then(service => service.getCharacteristic('heart_rate_measurement')) | |
76 .then(characteristic => { | |
77 char = characteristic; | |
78 return assert_event_fires_after_promise(characteristic, | |
79 'startNotifications', | |
80 'characteristicvaluechanged'); | |
81 }) | |
82 .then(() => char.stopNotifications()) | |
83 .then(() => assert_no_events(char, 'characteristicvaluechanged')); | |
84 }, 'Starting notifications should fire an event.'); | |
85 | |
86 promise_test(() => { | |
87 let char; | |
88 return setBluetoothFakeAdapter('HeartRateAdapter') | |
89 .then(() => requestDeviceWithKeyDown({ | |
90 filters: [{services: ['heart_rate']}]})) | |
91 .then(device => device.gatt.connect()) | |
92 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | |
93 .then(service => service.getCharacteristic('heart_rate_measurement')) | |
94 .then(characteristic => { | |
95 char = characteristic; | |
96 return characteristic.startNotifications() | |
97 .then(() => new Promise(resolve => { | |
98 let event_listener = e => { | |
99 characteristic.removeEventListener('characteristicvaluechanged', | |
100 event_listener); | |
101 resolve(); | |
102 }; | |
103 characteristic.addEventListener('characteristicvaluechanged', | |
104 event_listener); | |
105 })); | |
106 }) | |
107 .then(() => char.stopNotifications()) | |
108 .then(() => assert_no_events(char, 'characteristicvaluechanged')); | |
109 }, 'Registering after the promise resolves shouldn\'t result in events ' + | |
110 'getting dropped.'); | |
111 | |
112 promise_test(() => { | |
113 let char; | |
114 return setBluetoothFakeAdapter('HeartRateAdapter') | |
115 .then(() => requestDeviceWithKeyDown({ | |
116 filters: [{services: ['heart_rate']}]})) | |
117 .then(device => device.gatt.connect()) | |
118 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | |
119 .then(service => service.getCharacteristic('heart_rate_measurement')) | |
120 .then(characteristic => { | |
121 char = characteristic; | |
122 return assert_event_fires_after_promise(characteristic, | |
123 'startNotifications', | |
124 'characteristicvaluechanged', | |
125 3 /* add 3 listeners */); | |
126 }) | |
127 .then(() => char.stopNotifications()) | |
128 .then(() => assert_no_events(char, 'characteristicvaluechanged')); | |
129 }, 'Add multiple event listeners then startNotifications().'); | |
130 </script> | 67 </script> |
OLD | NEW |