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