| 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 => { | 18 .then(service => { |
| 18 testRunner.setBluetoothMockDataSet('EmptyAdapter'); | 19 return setBluetoothFakeAdapter('EmptyAdapter') |
| 19 return assert_promise_rejects_with_message( | 20 .then(() => assert_promise_rejects_with_message( |
| 20 service.getCharacteristic('gap.device_name'), | 21 service.getCharacteristic('gap.device_name'), |
| 21 new DOMException('Bluetooth Device is no longer in range.', | 22 new DOMException('Bluetooth Device is no longer in range.', |
| 22 'NetworkError'), | 23 'NetworkError'), |
| 23 'Device went out of range.'); | 24 'Device went out of range.')); |
| 24 }); | 25 }); |
| 25 }, 'Device goes out of range. Reject with NetworkError.'); | 26 }, 'Device goes out of range. Reject with NetworkError.'); |
| 26 | 27 |
| 27 promise_test(() => { | 28 promise_test(() => { |
| 28 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 29 return setBluetoothFakeAdapter('HeartRateAdapter') |
| 29 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}], | 30 .then(() => requestDeviceWithKeyDown({ |
| 30 optionalServices: ['generic_access']}) | 31 filters: [{services: ['heart_rate']}], |
| 32 optionalServices: ['generic_access']})) |
| 31 .then(device => device.gatt.connect()) | 33 .then(device => device.gatt.connect()) |
| 32 .then(gattService => gattService.getPrimaryService('generic_access')) | 34 .then(gattService => gattService.getPrimaryService('generic_access')) |
| 33 .then(service => { | 35 .then(service => { |
| 34 testRunner.setBluetoothMockDataSet('MissingServiceHeartRateAdapter'); | 36 return setBluetoothFakeAdapter('MissingServiceHeartRateAdapter') |
| 35 return assert_promise_rejects_with_message( | 37 .then(() => assert_promise_rejects_with_message( |
| 36 service.getCharacteristic('gap.device_name'), | 38 service.getCharacteristic('gap.device_name'), |
| 37 new DOMException('GATT Service no longer exists.', | 39 new DOMException('GATT Service no longer exists.', |
| 38 'InvalidStateError'), | 40 'InvalidStateError'), |
| 39 'Service got removed.'); | 41 'Service got removed.')); |
| 40 }); | 42 }); |
| 41 }, 'Service is removed. Reject with InvalidStateError.'); | 43 }, 'Service is removed. Reject with InvalidStateError.'); |
| 42 | 44 |
| 43 promise_test(() => { | 45 promise_test(() => { |
| 44 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 46 let expected = new DOMException( |
| 45 let expected = new DOMException('No Characteristics with specified UUID found
in Service.', | 47 'No Characteristics with specified UUID found in Service.', |
| 46 'NotFoundError'); | 48 'NotFoundError'); |
| 47 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}], | 49 return setBluetoothFakeAdapter('HeartRateAdapter') |
| 48 optionalServices: ['generic_access']}) | 50 .then(() => requestDeviceWithKeyDown({ |
| 51 filters: [{services: ['heart_rate']}], |
| 52 optionalServices: ['generic_access']})) |
| 49 .then(device => device.gatt.connect()) | 53 .then(device => device.gatt.connect()) |
| 50 .then(gattServer => gattServer.getPrimaryService('generic_access')) | 54 .then(gattServer => gattServer.getPrimaryService('generic_access')) |
| 51 .then(service => Promise.all( | 55 .then(service => Promise.all( |
| 52 [assert_promise_rejects_with_message( | 56 [assert_promise_rejects_with_message( |
| 53 service.getCharacteristic(battery_level.alias), expected), | 57 service.getCharacteristic(battery_level.alias), expected), |
| 54 assert_promise_rejects_with_message( | 58 assert_promise_rejects_with_message( |
| 55 service.getCharacteristic(battery_level.name), expected), | 59 service.getCharacteristic(battery_level.name), expected), |
| 56 assert_promise_rejects_with_message( | 60 assert_promise_rejects_with_message( |
| 57 service.getCharacteristic(battery_level.uuid), expected)])); | 61 service.getCharacteristic(battery_level.uuid), expected)])); |
| 58 }, 'Request for wrong characteristic. Reject with NotFoundError.'); | 62 }, 'Request for wrong characteristic. Reject with NotFoundError.'); |
| 59 | 63 |
| 60 promise_test(() => { | 64 promise_test(() => { |
| 61 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 65 return setBluetoothFakeAdapter('HeartRateAdapter') |
| 62 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}], | 66 .then(() => requestDeviceWithKeyDown({ |
| 63 optionalServices: ['generic_access']}) | 67 filters: [{services: ['heart_rate']}], |
| 68 optionalServices: ['generic_access']})) |
| 64 .then(device => device.gatt.connect()) | 69 .then(device => device.gatt.connect()) |
| 65 .then(gattServer => gattServer.getPrimaryService('generic_access')) | 70 .then(gattServer => gattServer.getPrimaryService('generic_access')) |
| 66 .then(service => Promise.all( | 71 .then(service => Promise.all( |
| 67 [service.getCharacteristic(device_name.alias), | 72 [service.getCharacteristic(device_name.alias), |
| 68 service.getCharacteristic(device_name.name), | 73 service.getCharacteristic(device_name.name), |
| 69 service.getCharacteristic(device_name.uuid)])) | 74 service.getCharacteristic(device_name.uuid)])) |
| 70 .then(characteristics => { | 75 .then(characteristics => { |
| 71 characteristics.forEach(characteristic => { | 76 characteristics.forEach(characteristic => { |
| 72 assert_equals( | 77 assert_equals( |
| 73 characteristic.uuid, device_name.uuid, | 78 characteristic.uuid, device_name.uuid, |
| 74 'Characteristic UUID should be the same as requested UUID.'); | 79 'Characteristic UUID should be the same as requested UUID.'); |
| 75 }); | 80 }); |
| 76 }); | 81 }); |
| 77 }, 'Request for characteristic. Should return right characteristic'); | 82 }, 'Request for characteristic. Should return right characteristic'); |
| 78 | 83 |
| 79 promise_test(() => { | 84 promise_test(() => { |
| 80 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 85 return setBluetoothFakeAdapter('HeartRateAdapter') |
| 81 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}], | 86 .then(() => requestDeviceWithKeyDown({ |
| 82 optionalServices: ['generic_access']}) | 87 filters: [{services: ['heart_rate']}], |
| 88 optionalServices: ['generic_access']})) |
| 83 .then(device => device.gatt.connect()) | 89 .then(device => device.gatt.connect()) |
| 84 .then(gattServer => gattServer.getPrimaryService('generic_access')) | 90 .then(gattServer => gattServer.getPrimaryService('generic_access')) |
| 85 .then(services => Promise.all( | 91 .then(services => Promise.all( |
| 86 [services.getCharacteristic(device_name.alias), | 92 [services.getCharacteristic(device_name.alias), |
| 87 services.getCharacteristic(device_name.alias), | 93 services.getCharacteristic(device_name.alias), |
| 88 services.getCharacteristic(device_name.name), | 94 services.getCharacteristic(device_name.name), |
| 89 services.getCharacteristic(device_name.name), | 95 services.getCharacteristic(device_name.name), |
| 90 services.getCharacteristic(device_name.uuid), | 96 services.getCharacteristic(device_name.uuid), |
| 91 services.getCharacteristic(device_name.uuid)])) | 97 services.getCharacteristic(device_name.uuid)])) |
| 92 .then(characteristics => { | 98 .then(characteristics => { |
| 93 // TODO(ortuno): getCharacteristic should return the same object | 99 // TODO(ortuno): getCharacteristic should return the same object |
| 94 // if it was created earlier. | 100 // if it was created earlier. |
| 95 // https://crbug.com/495270 | 101 // https://crbug.com/495270 |
| 96 for (var i = 1; i < characteristics.length; i++) { | 102 for (var i = 1; i < characteristics.length; i++) { |
| 97 assert_not_equals( | 103 assert_not_equals( |
| 98 characteristics[0], characteristics[i], | 104 characteristics[0], characteristics[i], |
| 99 'Should return the same characteristic as the first call.'); | 105 'Should return the same characteristic as the first call.'); |
| 100 } | 106 } |
| 101 }); | 107 }); |
| 102 }, 'Calls to get the same characteristic should return the same object.'); | 108 }, 'Calls to get the same characteristic should return the same object.'); |
| 103 | 109 |
| 104 promise_test(() => { | 110 promise_test(() => { |
| 105 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 111 return setBluetoothFakeAdapter('HeartRateAdapter') |
| 106 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}], | 112 .then(() => requestDeviceWithKeyDown({ |
| 107 optionalServices: ['generic_access']}) | 113 filters: [{services: ['heart_rate']}], |
| 114 optionalServices: ['generic_access']})) |
| 108 .then(device => device.gatt.connect()) | 115 .then(device => device.gatt.connect()) |
| 109 .then(gattServer => gattServer.getPrimaryService('generic_access')) | 116 .then(gattServer => gattServer.getPrimaryService('generic_access')) |
| 110 .then(service => { | 117 .then(service => { |
| 111 return assert_promise_rejects_with_message( | 118 return assert_promise_rejects_with_message( |
| 112 service.getCharacteristic('wrong_name'), new DOMException( | 119 service.getCharacteristic('wrong_name'), new DOMException( |
| 113 'Failed to execute \'getCharacteristic\' on ' + | 120 'Failed to execute \'getCharacteristic\' on ' + |
| 114 '\'BluetoothRemoteGATTService\': Invalid Characteristic name: ' + | 121 '\'BluetoothRemoteGATTService\': Invalid Characteristic name: ' + |
| 115 '\'wrong_name\'. ' + | 122 '\'wrong_name\'. ' + |
| 116 'It must be a valid UUID alias (e.g. 0x1234), ' + | 123 'It must be a valid UUID alias (e.g. 0x1234), ' + |
| 117 'UUID (lowercase hex characters e.g. ' + | 124 'UUID (lowercase hex characters e.g. ' + |
| 118 '\'00001234-0000-1000-8000-00805f9b34fb\'), ' + | 125 '\'00001234-0000-1000-8000-00805f9b34fb\'), ' + |
| 119 'or recognized standard name from ' + | 126 'or recognized standard name from ' + |
| 120 'https://developer.bluetooth.org/gatt/characteristics/' + | 127 'https://developer.bluetooth.org/gatt/characteristics/' + |
| 121 'Pages/CharacteristicsHome.aspx' + | 128 'Pages/CharacteristicsHome.aspx' + |
| 122 ' e.g. \'aerobic_heart_rate_lower_limit\'.', | 129 ' e.g. \'aerobic_heart_rate_lower_limit\'.', |
| 123 'SyntaxError'), | 130 'SyntaxError'), |
| 124 'Wrong Characteristic name passed.'); | 131 'Wrong Characteristic name passed.'); |
| 125 }); | 132 }); |
| 126 }, 'Wrong Characteristic name. Reject with SyntaxError.'); | 133 }, 'Wrong Characteristic name. Reject with SyntaxError.'); |
| 127 </script> | 134 </script> |
| OLD | NEW |