Chromium Code Reviews| 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_exists(window, 'testRunner'); t.done(); }, | 8 test(t => { assert_exists(window, 'testRunner'); 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 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); |
|
Jeffrey Yasskin
2016/03/24 23:47:54
Should you replace these at the same time?
ortuno
2016/03/28 23:26:44
We could. I've been doing it patch by patch. I'll
| |
| 13 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}], | 13 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}], |
| 14 optionalServices: ['generic_access']}) | 14 optionalServices: ['generic_access']}) |
| 15 .then(device => device.gatt.connect()) | 15 .then(device => device.gatt.connect()) |
| 16 .then(gattServer => gattServer.getPrimaryService('generic_access')) | 16 .then(gattServer => gattServer.getPrimaryService('generic_access')) |
| 17 .then(service => service.getCharacteristic('gap.device_name')) | 17 .then(service => service.getCharacteristic('gap.device_name')) |
| 18 .then(characteristic => { | 18 .then(characteristic => { |
| 19 testRunner.setBluetoothMockDataSet('EmptyAdapter'); | 19 return setBluetoothFakeAdapter('EmptyAdapter') |
| 20 return assert_promise_rejects_with_message( | 20 .then(() => assert_promise_rejects_with_message( |
| 21 characteristic.writeValue(new ArrayBuffer(1 /* length */)), | 21 characteristic.writeValue(new ArrayBuffer(1 /* length */)), |
| 22 new DOMException( | 22 new DOMException( |
| 23 'Bluetooth Device is no longer in range.', 'NetworkError'), | 23 'Bluetooth Device is no longer in range.', 'NetworkError'), |
| 24 'Device went out of range.'); | 24 'Device went out of range.')); |
| 25 }); | 25 }); |
| 26 }, 'Device goes out of range. Reject with NetworkError.'); | 26 }, 'Device goes out of range. Reject with NetworkError.'); |
| 27 | 27 |
| 28 promise_test(() => { | 28 promise_test(() => { |
| 29 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 29 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); |
| 30 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}], | 30 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}], |
| 31 optionalServices: ['generic_access']}) | 31 optionalServices: ['generic_access']}) |
| 32 .then(device => device.gatt.connect()) | 32 .then(device => device.gatt.connect()) |
| 33 .then(gattServer => gattServer.getPrimaryService('generic_access')) | 33 .then(gattServer => gattServer.getPrimaryService('generic_access')) |
| 34 .then(service => service.getCharacteristic('gap.device_name')) | 34 .then(service => service.getCharacteristic('gap.device_name')) |
| 35 .then(characteristic => { | 35 .then(characteristic => { |
| 36 testRunner.setBluetoothMockDataSet('MissingServiceHeartRateAdapter'); | 36 return setBluetoothFakeAdapter('MissingServiceHeartRateAdapter') |
| 37 return assert_promise_rejects_with_message( | 37 .then(() => assert_promise_rejects_with_message( |
| 38 characteristic.writeValue(new ArrayBuffer(1 /* length */)), | 38 characteristic.writeValue(new ArrayBuffer(1 /* length */)), |
| 39 new DOMException('GATT Service no longer exists.', | 39 new DOMException('GATT Service no longer exists.', |
| 40 'InvalidStateError'), | 40 'InvalidStateError'), |
| 41 'Service got removed.'); | 41 'Service got removed.')); |
| 42 }); | 42 }); |
| 43 }, 'Service gets removed. Reject with InvalidStateError.'); | 43 }, 'Service gets removed. Reject with InvalidStateError.'); |
| 44 | 44 |
| 45 promise_test(() => { | 45 promise_test(() => { |
| 46 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 46 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); |
| 47 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}], | 47 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}], |
| 48 optionalServices: ['generic_access']}) | 48 optionalServices: ['generic_access']}) |
| 49 .then(device => device.gatt.connect()) | 49 .then(device => device.gatt.connect()) |
| 50 .then(gattServer => gattServer.getPrimaryService('generic_access')) | 50 .then(gattServer => gattServer.getPrimaryService('generic_access')) |
| 51 .then(service => service.getCharacteristic('gap.device_name')) | 51 .then(service => service.getCharacteristic('gap.device_name')) |
| 52 .then(characteristic => { | 52 .then(characteristic => { |
| 53 testRunner.setBluetoothMockDataSet('MissingCharacteristicHeartRateAdapter' ); | 53 return setBluetoothFakeAdapter('MissingCharacteristicHeartRateAdapter') |
| 54 return assert_promise_rejects_with_message( | 54 .then(() => assert_promise_rejects_with_message( |
| 55 characteristic.writeValue(new ArrayBuffer(1 /* length */)), | 55 characteristic.writeValue(new ArrayBuffer(1 /* length */)), |
| 56 new DOMException( | 56 new DOMException( |
| 57 'GATT Characteristic no longer exists.', 'InvalidStateError'), | 57 'GATT Characteristic no longer exists.', 'InvalidStateError'), |
| 58 'Characteristic got removed.'); | 58 'Characteristic got removed.')); |
| 59 }); | 59 }); |
| 60 }, 'Characteristic gets removed. Reject with InvalidStateError.'); | 60 }, 'Characteristic gets removed. Reject with InvalidStateError.'); |
| 61 | 61 |
| 62 gatt_errors_tests.forEach(testSpec => { | 62 gatt_errors_tests.forEach(testSpec => { |
| 63 promise_test(() => { | 63 promise_test(() => { |
| 64 testRunner.setBluetoothMockDataSet('FailingGATTOperationsAdapter'); | 64 testRunner.setBluetoothMockDataSet('FailingGATTOperationsAdapter'); |
| 65 return requestDeviceWithKeyDown({filters: [{services: [errorUUID(0xA0)]}]}) | 65 return requestDeviceWithKeyDown({filters: [{services: [errorUUID(0xA0)]}]}) |
| 66 .then(device => device.gatt.connect()) | 66 .then(device => device.gatt.connect()) |
| 67 .then(gattServer => gattServer.getPrimaryService(errorUUID(0xA0))) | 67 .then(gattServer => gattServer.getPrimaryService(errorUUID(0xA0))) |
| 68 .then(service => service.getCharacteristic(testSpec.uuid)) | 68 .then(service => service.getCharacteristic(testSpec.uuid)) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 .then(characteristic => { | 114 .then(characteristic => { |
| 115 assert_equals(characteristic.value, null); | 115 assert_equals(characteristic.value, null); |
| 116 let textEncoder = new TextEncoder(); | 116 let textEncoder = new TextEncoder(); |
| 117 let newValue = textEncoder.encode('foo'); | 117 let newValue = textEncoder.encode('foo'); |
| 118 return characteristic.writeValue(newValue).then(() => { | 118 return characteristic.writeValue(newValue).then(() => { |
| 119 assert_array_equals(characteristic.value.buffer, newValue.buffer); | 119 assert_array_equals(characteristic.value.buffer, newValue.buffer); |
| 120 }); | 120 }); |
| 121 }); | 121 }); |
| 122 }, 'A regular write request to a writable characteristic should update value.'); | 122 }, 'A regular write request to a writable characteristic should update value.'); |
| 123 </script> | 123 </script> |
| OLD | NEW |