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_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 filters: [{services: ['heart_rate']}]})) | |
| 14 .then(device => { | 15 .then(device => { |
| 15 testRunner.setBluetoothMockDataSet('EmptyAdapter'); | 16 return setBluetoothFakeAdapter('EmptyAdapter') |
| 16 return assert_promise_rejects_with_message( | 17 .then(() => assert_promise_rejects_with_message( |
| 17 device.gatt.connect(), | 18 device.gatt.connect(), |
| 18 new DOMException('Bluetooth Device is no longer in range.', | 19 new DOMException('Bluetooth Device is no longer in range.', |
| 19 'NetworkError'), | 20 'NetworkError'), |
| 20 'Device went out of range.'); | 21 'Device went out of range.')); |
| 21 }); | 22 }); |
| 22 }, 'Device goes out of range. Reject with NetworkError.'); | 23 }, 'Device goes out of range. Reject with NetworkError.'); |
| 23 | 24 |
| 24 // The following tests make sure the Web Bluetooth implementation | 25 // The following tests make sure the Web Bluetooth implementation |
| 25 // responds correctly to the different types of errors the | 26 // responds correctly to the different types of errors the |
| 26 // underlying platform might throw. | 27 // underlying platform might throw. |
| 27 | 28 |
| 28 // Each implementation maps these devices to specific code paths | 29 // Each implementation maps these devices to specific code paths |
| 29 // that result in different errors thus increasing code coverage | 30 // that result in different errors thus increasing code coverage |
| 30 // when testing. Therefore some of these devices might not be useful | 31 // when testing. Therefore some of these devices might not be useful |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 uuid: errorUUID(0xd), | 100 uuid: errorUUID(0xd), |
| 100 error: new DOMException('Request not supported.', | 101 error: new DOMException('Request not supported.', |
| 101 'NetworkError') | 102 'NetworkError') |
| 102 }, { | 103 }, { |
| 103 testName: 'GATT write operation is not permitted.', | 104 testName: 'GATT write operation is not permitted.', |
| 104 uuid: errorUUID(0xe), | 105 uuid: errorUUID(0xe), |
| 105 error: new DOMException('Write not permitted.', | 106 error: new DOMException('Write not permitted.', |
| 106 'NetworkError') | 107 'NetworkError') |
| 107 }].forEach(testSpec => { | 108 }].forEach(testSpec => { |
| 108 promise_test(() => { | 109 promise_test(() => { |
| 109 testRunner.setBluetoothMockDataSet('FailingConnectionsAdapter'); | 110 return setBluetoothFakeAdapter('FailingConnectionsAdapter') |
| 110 return requestDeviceWithKeyDown({filters: [{services: [testSpec.uuid]}]}) | 111 .then(() => requestDeviceWithKeyDown({ |
| 111 .then(device => { | 112 filters: [{services: [testSpec.uuid]}]})) |
| 112 assert_promise_rejects_with_message( | 113 // This test was not returning th assert_promise_rejects_with_message |
|
Jeffrey Yasskin
2016/03/29 01:59:13
s/th/the/ and d'oh.
ortuno
2016/03/29 16:05:17
Done.
| |
| 113 device.gatt.connect(), | 114 // promise so when the underlying implementation of BluetoothDevice |
| 114 testSpec.error, | 115 // changed no one noticed that the promise started to reject. |
| 115 'Adapter failed to connect to device.'); | 116 // Furthermore, no platform returns the new errors added so they |
| 116 }); | 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.')) | |
| 117 }, testSpec.testName); | 124 }, testSpec.testName); |
| 118 }); | 125 }); |
| 119 | 126 |
| 120 // TODO(ortuno): Allow connections when the tab is in the background. | 127 // TODO(ortuno): Allow connections when the tab is in the background. |
| 121 // This is a short term solution instead of implementing a tab indicator | 128 // This is a short term solution instead of implementing a tab indicator |
| 122 // for bluetooth connections. | 129 // for bluetooth connections. |
| 123 // https://crbug.com/579746 | 130 // https://crbug.com/579746 |
| 124 promise_test(() => { | 131 promise_test(() => { |
| 125 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 132 return setBluetoothFakeAdapter('HeartRateAdapter') |
| 126 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 133 .then(() => requestDeviceWithKeyDown({ |
| 134 filters: [{services: ['heart_rate']}]})) | |
| 127 .then(device => { | 135 .then(device => { |
| 128 testRunner.setPageVisibility('hidden'); | 136 testRunner.setPageVisibility('hidden'); |
| 129 return assert_promise_rejects_with_message( | 137 return assert_promise_rejects_with_message( |
| 130 device.gatt.connect(), | 138 device.gatt.connect(), |
| 131 new DOMException('Connection is only allowed while the page is visible. ' + | 139 new DOMException('Connection is only allowed while the page is visible. ' + |
| 132 'This is a temporary measure until we are able to ' + | 140 'This is a temporary measure until we are able to ' + |
| 133 'effectively communicate to the user that a page is ' + | 141 'effectively communicate to the user that a page is ' + |
| 134 'connected to a device.', | 142 'connected to a device.', |
| 135 'SecurityError')) | 143 'SecurityError')) |
| 136 .then(() => { | 144 .then(() => { |
| 137 assert_false(device.gatt.connected); | 145 assert_false(device.gatt.connected); |
| 138 }); | 146 }); |
| 139 }) | 147 }) |
| 140 .then(() => testRunner.setPageVisibility('visible')) | 148 .then(() => testRunner.setPageVisibility('visible')) |
| 141 .catch(error => { | 149 .catch(error => { |
| 142 testRunner.setPageVisibility('visible'); | 150 testRunner.setPageVisibility('visible'); |
| 143 throw error; | 151 throw error; |
| 144 }); | 152 }); |
| 145 }, 'Device should not be able to connect in background.'); | 153 }, 'Device should not be able to connect in background.'); |
| 146 | 154 |
| 147 promise_test(() => { | 155 promise_test(() => { |
| 148 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 156 return setBluetoothFakeAdapter('HeartRateAdapter') |
| 149 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 157 .then(() => requestDeviceWithKeyDown({ |
| 158 filters: [{services: ['heart_rate']}]})) | |
| 150 .then(device => device.gatt.connect()) | 159 .then(device => device.gatt.connect()) |
| 151 .then(gattServer => assert_true(gattServer.connected)); | 160 .then(gattServer => assert_true(gattServer.connected)); |
| 152 }, 'Device will connect'); | 161 }, 'Device will connect'); |
| 153 | 162 |
| 154 promise_test(() => { | 163 promise_test(() => { |
| 155 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 164 return setBluetoothFakeAdapter('HeartRateAdapter') |
| 156 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 165 .then(() => requestDeviceWithKeyDown({ |
| 166 filters: [{services: ['heart_rate']}]})) | |
| 157 .then(device => { | 167 .then(device => { |
| 158 return Promise.all([device.gatt.connect(), device.gatt.connect()]) | 168 return Promise.all([device.gatt.connect(), device.gatt.connect()]) |
| 159 }).then(gattServers => { | 169 }).then(gattServers => { |
| 160 assert_equals(gattServers[0], gattServers[1]); | 170 assert_equals(gattServers[0], gattServers[1]); |
| 161 }); | 171 }); |
| 162 }); | 172 }); |
| 163 | 173 |
| 164 // TODO(ortuno): Remove connectGATT in M52. | 174 // TODO(ortuno): Remove connectGATT in M52. |
| 165 // http://crbug.com/582292 | 175 // http://crbug.com/582292 |
| 166 promise_test(() => { | 176 promise_test(() => { |
| 167 testRunner.setBluetoothMockDataSet('HeartRateAdapter'); | 177 return setBluetoothFakeAdapter('HeartRateAdapter') |
| 168 return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]}) | 178 .then(() => requestDeviceWithKeyDown({ |
| 179 filters: [{services: ['heart_rate']}]})) | |
| 169 .then(device => device.connectGATT()) | 180 .then(device => device.connectGATT()) |
| 170 }, 'Make sure deprecated method is still usable.') | 181 }, 'Make sure deprecated method is still usable.') |
| 171 </script> | 182 </script> |
| OLD | NEW |