| 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/testharness-helpers.js"></script> | |
| 4 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
| 5 <script src="resources/bluetooth-helpers.js"></script> | 4 <script src="resources/bluetooth-helpers.js"></script> |
| 6 <script> | 5 <script> |
| 7 'use strict'; | 6 'use strict'; |
| 8 | 7 |
| 9 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, | 8 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, |
| 10 'window.testRunner is required for the following tests.'); | 9 'window.testRunner is required for the following tests.'); |
| 11 | 10 |
| 12 sequential_promise_test(() => { | 11 promise_test(() => { |
| 13 testRunner.setBluetoothMockDataSet('GenericAccessAdapter'); | 12 testRunner.setBluetoothMockDataSet('GenericAccessAdapter'); |
| 14 return requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}) | 13 return requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}) |
| 15 .then(device => device.connectGATT()) | 14 .then(device => device.connectGATT()) |
| 16 .then(gattServer => gattServer.getPrimaryService('generic_access')) | 15 .then(gattServer => gattServer.getPrimaryService('generic_access')) |
| 17 .then(service => service.getCharacteristic('gap.device_name')) | 16 .then(service => service.getCharacteristic('gap.device_name')) |
| 18 .then(characteristic => { | 17 .then(characteristic => { |
| 19 testRunner.setBluetoothMockDataSet('EmptyAdapter'); | 18 testRunner.setBluetoothMockDataSet('EmptyAdapter'); |
| 20 return assert_promise_rejects_with_message( | 19 return assert_promise_rejects_with_message( |
| 21 characteristic.readValue(), { | 20 characteristic.readValue(), { |
| 22 name: 'NetworkError', | 21 name: 'NetworkError', |
| 23 message: 'Bluetooth Device is no longer in range.' | 22 message: 'Bluetooth Device is no longer in range.' |
| 24 }, 'Device went out of range'); | 23 }, 'Device went out of range'); |
| 25 }); | 24 }); |
| 26 }, 'Device goes out of range. Reject with NetworkError.'); | 25 }, 'Device goes out of range. Reject with NetworkError.'); |
| 27 | 26 |
| 28 sequential_promise_test(() => { | 27 promise_test(() => { |
| 29 testRunner.setBluetoothMockDataSet('GenericAccessAdapter'); | 28 testRunner.setBluetoothMockDataSet('GenericAccessAdapter'); |
| 30 return requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}) | 29 return requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}) |
| 31 .then(device => device.connectGATT()) | 30 .then(device => device.connectGATT()) |
| 32 .then(gattServer => gattServer.getPrimaryService('generic_access')) | 31 .then(gattServer => gattServer.getPrimaryService('generic_access')) |
| 33 .then(service => service.getCharacteristic('gap.device_name')) | 32 .then(service => service.getCharacteristic('gap.device_name')) |
| 34 .then(characteristic => { | 33 .then(characteristic => { |
| 35 testRunner.setBluetoothMockDataSet('MissingServiceGenericAccessAdapter'); | 34 testRunner.setBluetoothMockDataSet('MissingServiceGenericAccessAdapter'); |
| 36 return assert_promise_rejects_with_message( | 35 return assert_promise_rejects_with_message( |
| 37 characteristic.readValue(), { | 36 characteristic.readValue(), { |
| 38 name: 'InvalidStateError', | 37 name: 'InvalidStateError', |
| 39 message: 'GATT Service no longer exists.' | 38 message: 'GATT Service no longer exists.' |
| 40 }, 'Service got removed.'); | 39 }, 'Service got removed.'); |
| 41 }); | 40 }); |
| 42 }, 'Service gets removed. Reject with InvalidStateError.'); | 41 }, 'Service gets removed. Reject with InvalidStateError.'); |
| 43 | 42 |
| 44 sequential_promise_test(() => { | 43 promise_test(() => { |
| 45 testRunner.setBluetoothMockDataSet('GenericAccessAdapter'); | 44 testRunner.setBluetoothMockDataSet('GenericAccessAdapter'); |
| 46 return requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}) | 45 return requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}) |
| 47 .then(device => device.connectGATT()) | 46 .then(device => device.connectGATT()) |
| 48 .then(gattService => gattService.getPrimaryService('generic_access')) | 47 .then(gattService => gattService.getPrimaryService('generic_access')) |
| 49 .then(service => service.getCharacteristic('gap.device_name')) | 48 .then(service => service.getCharacteristic('gap.device_name')) |
| 50 .then(characteristic => { | 49 .then(characteristic => { |
| 51 testRunner.setBluetoothMockDataSet( | 50 testRunner.setBluetoothMockDataSet( |
| 52 'MissingCharacteristicGenericAccessAdapter'); | 51 'MissingCharacteristicGenericAccessAdapter'); |
| 53 return assert_promise_rejects_with_message( | 52 return assert_promise_rejects_with_message( |
| 54 characteristic.readValue(), { | 53 characteristic.readValue(), { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 message: 'GATT Error: Not paired.' | 118 message: 'GATT Error: Not paired.' |
| 120 } | 119 } |
| 121 }, { | 120 }, { |
| 122 testName: 'GATT Error: Not Supported.', | 121 testName: 'GATT Error: Not Supported.', |
| 123 uuid: errorUUID(0xA8), | 122 uuid: errorUUID(0xA8), |
| 124 error: { | 123 error: { |
| 125 name: 'NotSupportedError', | 124 name: 'NotSupportedError', |
| 126 message: 'GATT Error: Not supported.' | 125 message: 'GATT Error: Not supported.' |
| 127 } | 126 } |
| 128 }].forEach(testSpec => { | 127 }].forEach(testSpec => { |
| 129 sequential_promise_test(() => { | 128 promise_test(() => { |
| 130 testRunner.setBluetoothMockDataSet('FailingGATTOperationsAdapter'); | 129 testRunner.setBluetoothMockDataSet('FailingGATTOperationsAdapter'); |
| 131 return requestDeviceWithKeyDown({filters: [{services: [errorUUID(0xA0)]}]}) | 130 return requestDeviceWithKeyDown({filters: [{services: [errorUUID(0xA0)]}]}) |
| 132 .then(device => device.connectGATT()) | 131 .then(device => device.connectGATT()) |
| 133 .then(gattServer => gattServer.getPrimaryService(errorUUID(0xA0))) | 132 .then(gattServer => gattServer.getPrimaryService(errorUUID(0xA0))) |
| 134 .then(service => service.getCharacteristic(testSpec.uuid)) | 133 .then(service => service.getCharacteristic(testSpec.uuid)) |
| 135 .then(characteristic => { | 134 .then(characteristic => { |
| 136 return assert_promise_rejects_with_message( | 135 return assert_promise_rejects_with_message( |
| 137 characteristic.readValue(), | 136 characteristic.readValue(), |
| 138 testSpec.error, | 137 testSpec.error, |
| 139 'Trying to read the characteristic failed'); | 138 'Trying to read the characteristic failed'); |
| 140 }); | 139 }); |
| 141 }, testSpec.testName); | 140 }, testSpec.testName); |
| 142 }); | 141 }); |
| 143 | 142 |
| 144 sequential_promise_test(() => { | 143 promise_test(() => { |
| 145 testRunner.setBluetoothMockDataSet('GenericAccessAdapter'); | 144 testRunner.setBluetoothMockDataSet('GenericAccessAdapter'); |
| 146 return requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}) | 145 return requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}) |
| 147 .then(device => device.connectGATT()) | 146 .then(device => device.connectGATT()) |
| 148 .then(gattServer => gattServer.getPrimaryService('generic_access')) | 147 .then(gattServer => gattServer.getPrimaryService('generic_access')) |
| 149 .then(service => service.getCharacteristic('gap.device_name')) | 148 .then(service => service.getCharacteristic('gap.device_name')) |
| 150 .then(characteristic => characteristic.readValue()) | 149 .then(characteristic => characteristic.readValue()) |
| 151 .then(value => { | 150 .then(value => { |
| 152 let decoder = new TextDecoder('utf-8'); | 151 let decoder = new TextDecoder('utf-8'); |
| 153 let value_str = decoder.decode(value); | 152 let value_str = decoder.decode(value); |
| 154 assert_equals(value_str, 'Generic Access Device'); | 153 assert_equals(value_str, 'Generic Access Device'); |
| 155 }); | 154 }); |
| 156 }, 'Request for characteristic. Should return right characteristic'); | 155 }, 'Request for characteristic. Should return right characteristic'); |
| 157 </script> | 156 </script> |
| OLD | NEW |