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 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, | |
8 'window.testRunner is required for the following tests.'); | |
9 | |
10 promise_test(() => { | |
11 let start_promise; | |
12 return setBluetoothFakeAdapter('HeartRateAdapter') | |
13 .then(() => requestDeviceWithKeyDown({ | |
14 filters: [{services: ['heart_rate']}]})) | |
15 .then(device => device.gatt.connect()) | |
16 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | |
17 .then(service => service.getCharacteristic('heart_rate_measurement')) | |
18 .then(characteristic => { | |
19 start_promise = characteristic.startNotifications(); | |
20 // We itentionally don't return the promise so that 'characteristic' goes | |
21 // out of scope while the request is still pending. | |
22 }).then(() => runGarbageCollection()) | |
23 .then(() => start_promise); | |
24 }, 'Object gets garbage collected while start request is pending.'); | |
25 | |
26 promise_test(() => { | |
27 let stop_promise; | |
28 return setBluetoothFakeAdapter('HeartRateAdapter') | |
29 .then(() => requestDeviceWithKeyDown({ | |
30 filters: [{services: ['heart_rate']}]})) | |
31 .then(device => device.gatt.connect()) | |
32 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | |
33 .then(service => service.getCharacteristic('heart_rate_measurement')) | |
34 .then(characteristic => { | |
35 return characteristic.startNotifications().then(() => { | |
36 stop_promise = characteristic.stopNotifications(); | |
37 // We itentionally don't return the promise so that 'characteristic' goes | |
38 // out of scope while the request is still pending. | |
39 }); | |
40 }).then(() => runGarbageCollection()) | |
41 .then(() => stop_promise); | |
42 }, 'Object gets garbage collected while stop request is pending.'); | |
43 | |
44 promise_test(() => { | |
45 return setBluetoothFakeAdapter('HeartRateAdapter') | |
46 .then(() => requestDeviceWithKeyDown({ | |
47 filters: [{services: ['heart_rate']}]})) | |
48 .then(device => device.gatt.connect()) | |
49 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | |
50 .then(service => service.getCharacteristic('heart_rate_measurement')) | |
51 .then(characteristic => { | |
52 return characteristic.startNotifications() | |
53 .then(() => characteristic.stopNotifications()); | |
54 }).then(() => runGarbageCollection()); | |
55 }, 'Single start notifications succeeds.'); | |
56 | |
57 promise_test(() => { | |
58 return setBluetoothFakeAdapter('HeartRateAdapter') | |
59 .then(() => requestDeviceWithKeyDown({ | |
60 filters: [{services: ['heart_rate']}]})) | |
61 .then(device => device.gatt.connect()) | |
62 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | |
63 .then(service => service.getCharacteristic('heart_rate_measurement')) | |
64 .then(characteristic => { | |
65 return characteristic.startNotifications() | |
66 .then(() => characteristic.startNotifications()) | |
67 .then(() => characteristic.stopNotifications()); | |
68 }).then(() => runGarbageCollection()); | |
69 }, 'Start notifications after succesfully starting before.'); | |
70 | |
71 promise_test(() => { | |
72 return setBluetoothFakeAdapter('HeartRateAdapter') | |
73 .then(() => requestDeviceWithKeyDown({ | |
74 filters: [{services: ['heart_rate']}]})) | |
75 .then(device => device.gatt.connect()) | |
76 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | |
77 .then(service => service.getCharacteristic('heart_rate_measurement')) | |
78 .then(characteristic => { | |
79 return characteristic.startNotifications() | |
80 .then(() => characteristic.stopNotifications()) | |
81 .then(() => characteristic.startNotifications()) | |
82 .then(() => characteristic.stopNotifications()); | |
83 }).then(() => runGarbageCollection()); | |
84 }, 'Start -> stop -> start -> stop.'); | |
85 | |
86 promise_test(() => { | |
87 return setBluetoothFakeAdapter('HeartRateAdapter') | |
88 .then(() => requestDeviceWithKeyDown({ | |
89 filters: [{services: ['heart_rate']}]})) | |
90 .then(device => device.gatt.connect()) | |
91 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | |
92 .then(service => service.getCharacteristic('heart_rate_measurement')) | |
93 .then(characteristic => { | |
94 return Promise.all([characteristic.startNotifications(), | |
95 characteristic.startNotifications(), | |
96 characteristic.startNotifications()]) | |
97 .then(() => characteristic.stopNotifications()); | |
98 }).then(() => runGarbageCollection()); | |
99 }, 'Multiple starts in a row.'); | |
100 | |
101 promise_test(() => { | |
102 return setBluetoothFakeAdapter('HeartRateAdapter') | |
103 .then(() => requestDeviceWithKeyDown({ | |
104 filters: [{services: ['heart_rate']}]})) | |
105 .then(device => device.gatt.connect()) | |
106 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | |
107 .then(service => service.getCharacteristic('heart_rate_measurement')) | |
108 .then(characteristic => { | |
109 return Promise.all([characteristic.startNotifications(), | |
110 characteristic.stopNotifications()]); | |
111 }).then(() => runGarbageCollection()); | |
112 }, "Parallel start and stop."); | |
113 | |
114 promise_test(() => { | |
115 return setBluetoothFakeAdapter('HeartRateAdapter') | |
116 .then(() => requestDeviceWithKeyDown({ | |
117 filters: [{services: ['heart_rate']}]})) | |
118 .then(device => device.gatt.connect()) | |
119 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | |
120 .then(service => service.getCharacteristic('heart_rate_measurement')) | |
121 .then(characteristic => { | |
122 return characteristic.startNotifications().then(() => { | |
123 return Promise.all([characteristic.stopNotifications(), | |
124 characteristic.stopNotifications()]); | |
125 }); | |
126 }).then(() => runGarbageCollection()); | |
127 }, "Concurrent stop requests."); | |
128 | |
129 promise_test(() => { | |
130 return setBluetoothFakeAdapter('HeartRateAdapter') | |
131 .then(() => requestDeviceWithKeyDown({ | |
132 filters: [{services: ['heart_rate']}]})) | |
133 .then(device => device.gatt.connect()) | |
134 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | |
135 .then(service => service.getCharacteristic('heart_rate_measurement')) | |
136 .then(characteristic => { | |
137 return characteristic.startNotifications() | |
138 .then(() => characteristic.stopNotifications()) | |
139 .then(() => characteristic.stopNotifications()); | |
140 }).then(() => runGarbageCollection()); | |
141 }, "Stopping twice."); | |
142 | |
143 promise_test(() => { | |
144 return setBluetoothFakeAdapter('HeartRateAdapter') | |
145 .then(() => requestDeviceWithKeyDown({ | |
146 filters: [{services: ['heart_rate']}]})) | |
147 .then(device => device.gatt.connect()) | |
148 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | |
149 .then(service => service.getCharacteristic('heart_rate_measurement')) | |
150 .then(characteristic => { | |
151 return characteristic.startNotifications().then(() => { | |
152 return Promise.all([characteristic.stopNotifications(), | |
153 characteristic.startNotifications()]); | |
154 }).then(() => characteristic.stopNotifications()); | |
155 }).then(() => runGarbageCollection()); | |
156 }, "Start request before stop request resolves"); | |
157 | |
158 promise_test(() => { | |
159 return setBluetoothFakeAdapter('HeartRateAdapter') | |
160 .then(() => requestDeviceWithKeyDown({ | |
161 filters: [{services: ['heart_rate']}]})) | |
162 .then(device => device.gatt.connect()) | |
163 .then(gattServer => gattServer.getPrimaryService('heart_rate')) | |
164 .then(service => service.getCharacteristic('heart_rate_measurement')) | |
165 .then(characteristic => characteristic.stopNotifications()) | |
166 .then(() => runGarbageCollection()); | |
167 }, "Stop without starting."); | |
168 | |
169 gatt_errors_tests.forEach(testSpec => { | |
170 promise_test(() => { | |
171 return setBluetoothFakeAdapter('FailingGATTOperationsAdapter') | |
172 .then(() => requestDeviceWithKeyDown({ | |
173 filters: [{services: [errorUUID(0xA0)]}]})) | |
174 .then(device => device.gatt.connect()) | |
175 .then(gattServer => gattServer.getPrimaryService(errorUUID(0xA0))) | |
176 .then(service => service.getCharacteristic(testSpec.uuid)) | |
177 .then(characteristic => { | |
178 return assert_promise_rejects_with_message( | |
179 characteristic.startNotifications(), | |
180 testSpec.error, | |
181 'Trying to start notifications failed.'); | |
182 }); | |
183 }, testSpec.testName); | |
184 }); | |
185 </script> | |
OLD | NEW |