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