| 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/bluetooth-helpers.js"></script> | 4 <script src="../../resources/bluetooth/bluetooth-helpers.js"></script> |
| 5 <script> | 5 <script> |
| 6 'use strict'; | 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 .then(device => { | |
| 16 return setBluetoothFakeAdapter('EmptyAdapter') | |
| 17 .then(() => assert_promise_rejects_with_message( | |
| 18 device.gatt.connect(), | |
| 19 new DOMException('Bluetooth Device is no longer in range.', | |
| 20 'NetworkError'), | |
| 21 'Device went out of range.')); | |
| 22 }); | |
| 23 }, 'Device goes out of range. Reject with NetworkError.'); | |
| 24 | |
| 25 // The following tests make sure the Web Bluetooth implementation | 7 // The following tests make sure the Web Bluetooth implementation |
| 26 // responds correctly to the different types of errors the | 8 // responds correctly to the different types of errors the |
| 27 // underlying platform might throw. | 9 // underlying platform might throw. |
| 28 | 10 |
| 29 // Each implementation maps these devices to specific code paths | 11 // Each implementation maps these devices to specific code paths |
| 30 // that result in different errors thus increasing code coverage | 12 // that result in different errors thus increasing code coverage |
| 31 // when testing. Therefore some of these devices might not be useful | 13 // when testing. Therefore some of these devices might not be useful |
| 32 // for all implementations. | 14 // for all implementations. |
| 33 [{ | 15 |
| 16 let connection_test_specs = [{ |
| 34 testName: 'Unknown error when connnecting.', | 17 testName: 'Unknown error when connnecting.', |
| 35 uuid: errorUUID(0x0), | 18 uuid: errorUUID(0x0), |
| 36 error: new DOMException('Unknown error when connecting to the device.', | 19 error: new DOMException('Unknown error when connecting to the device.', |
| 37 'NetworkError') | 20 'NetworkError') |
| 38 }, { | 21 }, { |
| 39 testName: 'Connection was already in progress.', | 22 testName: 'Connection was already in progress.', |
| 40 uuid: errorUUID(0x1), | 23 uuid: errorUUID(0x1), |
| 41 error: new DOMException('Connection already in progress.', | 24 error: new DOMException('Connection already in progress.', |
| 42 'NetworkError') | 25 'NetworkError') |
| 43 }, { | 26 }, { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 }, { | 81 }, { |
| 99 testName: 'The given request is not supported.', | 82 testName: 'The given request is not supported.', |
| 100 uuid: errorUUID(0xd), | 83 uuid: errorUUID(0xd), |
| 101 error: new DOMException('Request not supported.', | 84 error: new DOMException('Request not supported.', |
| 102 'NetworkError') | 85 'NetworkError') |
| 103 }, { | 86 }, { |
| 104 testName: 'GATT write operation is not permitted.', | 87 testName: 'GATT write operation is not permitted.', |
| 105 uuid: errorUUID(0xe), | 88 uuid: errorUUID(0xe), |
| 106 error: new DOMException('Write not permitted.', | 89 error: new DOMException('Write not permitted.', |
| 107 'NetworkError') | 90 'NetworkError') |
| 108 }].forEach(testSpec => { | 91 }]; |
| 109 promise_test(() => { | |
| 110 return setBluetoothFakeAdapter('FailingConnectionsAdapter') | |
| 111 .then(() => requestDeviceWithKeyDown({ | |
| 112 filters: [{services: [testSpec.uuid]}]})) | |
| 113 // This test was not returning the assert_promise_rejects_with_message | |
| 114 // promise so when the underlying implementation of BluetoothDevice | |
| 115 // changed no one noticed that the promise started to reject. | |
| 116 // Furthermore, no platform returns the new errors added so they | |
| 117 // need to be cleaned up. | |
| 118 // TODO(ortuno): Re-enable the test when the errors are cleaned up. | |
| 119 // http://crbug.com/598341 | |
| 120 // .then(device => assert_promise_rejects_with_message( | |
| 121 // device.gatt.connect(), | |
| 122 // testSpec.error, | |
| 123 // 'Adapter failed to connect to device.')) | |
| 124 }, testSpec.testName); | |
| 125 }); | |
| 126 | 92 |
| 127 promise_test(() => { | 93 promise_test(() => { |
| 128 return setBluetoothFakeAdapter('HeartRateAdapter') | 94 return setBluetoothFakeAdapter('FailingConnectionsAdapter') |
| 129 .then(() => requestDeviceWithKeyDown({ | 95 .then(() => { |
| 130 filters: [{services: ['heart_rate']}]})) | 96 let test_promises = Promise.resolve(); |
| 131 .then(device => device.gatt.connect()) | 97 connection_test_specs.forEach(testSpec => { |
| 132 .then(gattServer => assert_true(gattServer.connected)); | 98 test_promises = test_promises |
| 133 }, 'Device will connect'); | 99 .then(() => requestDeviceWithKeyDown({ |
| 134 | 100 filters: [{services: [testSpec.uuid]}]})); |
| 135 promise_test(() => { | 101 // This test was not returning the assert_promise_rejects_with_messa
ge |
| 136 return setBluetoothFakeAdapter('HeartRateAdapter') | 102 // promise so when the underlying implementation of BluetoothDevice |
| 137 .then(() => requestDeviceWithKeyDown({ | 103 // changed no one noticed that the promise started to reject. |
| 138 filters: [{services: ['heart_rate']}]})) | 104 // Furthermore, no platform returns the new errors added so they |
| 139 .then(device => { | 105 // need to be cleaned up. |
| 140 return Promise.all([device.gatt.connect(), device.gatt.connect()]) | 106 // TODO(ortuno): Re-enable the test when the errors are cleaned up. |
| 141 }).then(gattServers => { | 107 // http://crbug.com/598341 |
| 142 assert_equals(gattServers[0], gattServers[1]); | 108 // .then(device => assert_promise_rejects_with_message( |
| 143 }); | 109 // device.gatt.connect(), |
| 144 }); | 110 // testSpec.error, |
| 145 | 111 // testSpec.testName)); |
| 146 // TODO(ortuno): Remove connectGATT in M52. | 112 }); |
| 147 // http://crbug.com/582292 | 113 return test_promises; |
| 148 promise_test(() => { | 114 }); |
| 149 return setBluetoothFakeAdapter('HeartRateAdapter') | 115 }, 'Adapter fails to connect to device. Should reject with the correct ' + |
| 150 .then(() => requestDeviceWithKeyDown({ | 116 'exception.'); |
| 151 filters: [{services: ['heart_rate']}]})) | |
| 152 .then(device => device.connectGATT()) | |
| 153 }, 'Make sure deprecated method is still usable.') | |
| 154 </script> | 117 </script> |
| OLD | NEW |