| 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 | |
| 8 test(t => { assert_true(window.testRunner instanceof Object); t.done(); }, | |
| 9 'window.testRunner is required for the following tests.'); | |
| 10 | |
| 11 promise_test(() => { | |
| 12 return setBluetoothFakeAdapter('HeartRateAdapter') | |
| 13 .then(() => requestDeviceWithKeyDown({ | |
| 14 filters: [{services: ['heart_rate']}], | |
| 15 optionalServices: ['generic_access']})) | |
| 16 .then(device => device.gatt.connect()) | |
| 17 .then(gattServer => gattServer.getPrimaryService('generic_access')) | |
| 18 .then(service => service.getCharacteristic('gap.device_name')) | |
| 19 .then(characteristic => { | |
| 20 return setBluetoothFakeAdapter('EmptyAdapter') | |
| 21 .then(() => assert_promise_rejects_with_message( | |
| 22 characteristic.readValue(), | |
| 23 new DOMException( | |
| 24 'Bluetooth Device is no longer in range.', | |
| 25 'NetworkError'), | |
| 26 'Device went out of range')); | |
| 27 }); | |
| 28 }, 'Device goes out of range. Reject with NetworkError.'); | |
| 29 | |
| 30 promise_test(() => { | |
| 31 return setBluetoothFakeAdapter('HeartRateAdapter') | |
| 32 .then(() => requestDeviceWithKeyDown({ | |
| 33 filters: [{services: ['heart_rate']}], | |
| 34 optionalServices: ['generic_access']})) | |
| 35 .then(device => device.gatt.connect()) | |
| 36 .then(gattServer => gattServer.getPrimaryService('generic_access')) | |
| 37 .then(service => service.getCharacteristic('gap.device_name')) | |
| 38 .then(characteristic => { | |
| 39 return setBluetoothFakeAdapter('MissingServiceHeartRateAdapter') | |
| 40 .then(() => assert_promise_rejects_with_message( | |
| 41 characteristic.readValue(), | |
| 42 new DOMException( | |
| 43 'GATT Service no longer exists.', | |
| 44 'InvalidStateError'), | |
| 45 'Service got removed.')); | |
| 46 }); | |
| 47 }, 'Service gets removed. Reject with InvalidStateError.'); | |
| 48 | |
| 49 promise_test(() => { | |
| 50 return setBluetoothFakeAdapter('HeartRateAdapter') | |
| 51 .then(() => requestDeviceWithKeyDown({ | |
| 52 filters: [{services: ['heart_rate']}], | |
| 53 optionalServices: ['generic_access']})) | |
| 54 .then(device => device.gatt.connect()) | |
| 55 .then(gattService => gattService.getPrimaryService('generic_access')) | |
| 56 .then(service => service.getCharacteristic('gap.device_name')) | |
| 57 .then(characteristic => { | |
| 58 return setBluetoothFakeAdapter('MissingCharacteristicHeartRateAdapter') | |
| 59 .then(() => assert_promise_rejects_with_message( | |
| 60 characteristic.readValue(), | |
| 61 new DOMException( | |
| 62 'GATT Characteristic no longer exists.', | |
| 63 'InvalidStateError'), | |
| 64 'Characteristic got removed.')); | |
| 65 }); | |
| 66 }, 'Characteristic gets removed. Reject with InvalidStateError.'); | |
| 67 | |
| 68 gatt_errors_tests.forEach(testSpec => { | |
| 69 promise_test(() => { | |
| 70 return setBluetoothFakeAdapter('FailingGATTOperationsAdapter') | |
| 71 .then(() => requestDeviceWithKeyDown({ | |
| 72 filters: [{services: [errorUUID(0xA0)]}]})) | |
| 73 .then(device => device.gatt.connect()) | |
| 74 .then(gattServer => gattServer.getPrimaryService(errorUUID(0xA0))) | |
| 75 .then(service => service.getCharacteristic(testSpec.uuid)) | |
| 76 .then(characteristic => { | |
| 77 return assert_promise_rejects_with_message( | |
| 78 characteristic.readValue(), | |
| 79 testSpec.error, | |
| 80 'Trying to read the characteristic failed'); | |
| 81 }); | |
| 82 }, testSpec.testName); | |
| 83 }); | |
| 84 | |
| 85 promise_test(() => { | |
| 86 return setBluetoothFakeAdapter('HeartRateAdapter') | |
| 87 .then(() => requestDeviceWithKeyDown({ | |
| 88 filters: [{services: ['heart_rate']}], | |
| 89 optionalServices: ['generic_access']})) | |
| 90 .then(device => device.gatt.connect()) | |
| 91 .then(gattServer => gattServer.getPrimaryService('generic_access')) | |
| 92 .then(service => service.getCharacteristic('gap.device_name')) | |
| 93 .then(characteristic => characteristic.readValue()) | |
| 94 .then(value => { | |
| 95 let decoder = new TextDecoder('utf-8'); | |
| 96 let value_str = decoder.decode(value); | |
| 97 assert_equals(value_str, 'Heart Rate Device'); | |
| 98 }); | |
| 99 }, 'Request for characteristic. Should return right characteristic'); | |
| 100 | |
| 101 promise_test(() => { | |
| 102 return setBluetoothFakeAdapter('HeartRateAdapter') | |
| 103 .then(() => requestDeviceWithKeyDown({ | |
| 104 filters: [{services: ['heart_rate']}], | |
| 105 optionalServices: ['generic_access']})) | |
| 106 .then(device => device.gatt.connect()) | |
| 107 .then(gattServer => gattServer.getPrimaryService('generic_access')) | |
| 108 .then(service => service.getCharacteristic('gap.device_name')) | |
| 109 .then(characteristic => { | |
| 110 assert_equals(characteristic.value, null); | |
| 111 return characteristic.readValue().then(() => { | |
| 112 let decoder = new TextDecoder('utf-8'); | |
| 113 let value_str = decoder.decode(characteristic.value); | |
| 114 assert_equals(value_str, 'Heart Rate Device'); | |
| 115 }) | |
| 116 }); | |
| 117 }, 'Request for characteristic. Should update characteristic.value'); | |
| 118 </script> | |
| OLD | NEW |