blob: 1c3f52ae7ca396b411f34e48a3851f1b79f0ae04 [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/bluetooth-helpers.js"></script>
<script>
'use strict';
test(t => { assert_true(window.testRunner instanceof Object); t.done(); },
'window.testRunner is required for the following tests.');
promise_test(() => {
testRunner.setBluetoothMockDataSet('HeartRateAdapter');
return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]})
.then(device => {
testRunner.setBluetoothMockDataSet('EmptyAdapter');
return assert_promise_rejects_with_message(
device.connectGATT(),
new DOMException('Bluetooth Device is no longer in range.',
'NetworkError'),
'Device went out of range.');
});
}, 'Device goes out of range. Reject with NetworkError.');
// The following tests make sure the Web Bluetooth implementation
// responds correctly to the different types of errors the
// underlying platform might throw.
// Each implementation maps these devices to specific code paths
// that result in different errors thus increasing code coverage
// when testing. Therefore some of these devices might not be useful
// for all implementations.
[{
testName: 'Unknown error when connnecting.',
uuid: errorUUID(0x0),
error: new DOMException('Unknown error when connecting to the device.',
'NetworkError')
}, {
testName: 'Connection was already in progress.',
uuid: errorUUID(0x1),
error: new DOMException('Connection already in progress.',
'NetworkError')
}, {
testName: 'Connection failed.',
uuid: errorUUID(0x2),
error: new DOMException('Connection failed for unknown reason.',
'NetworkError')
}, {
testName: 'Authentication failed when connecting.',
uuid: errorUUID(0x3),
error: new DOMException('Authentication failed.',
'NetworkError')
}, {
testName: 'Authentication canceled when connecting.',
uuid: errorUUID(0x4),
error: new DOMException('Authentication canceled.',
'NetworkError')
}, {
testName: 'Authentication rejected when connecting.',
uuid: errorUUID(0x5),
error: new DOMException('Authentication rejected.',
'NetworkError')
}, {
testName: 'Authentication timed out when connecting.',
uuid: errorUUID(0x6),
error: new DOMException('Authentication timeout.',
'NetworkError')
}, {
testName: 'Tried to connect to an unsupported device.',
uuid: errorUUID(0x7),
error: new DOMException('Unsupported device.',
'NetworkError')
}].forEach(testSpec => {
promise_test(() => {
testRunner.setBluetoothMockDataSet('FailingConnectionsAdapter');
return requestDeviceWithKeyDown({filters: [{services: [testSpec.uuid]}]})
.then(device => {
assert_promise_rejects_with_message(
device.connectGATT(),
testSpec.error,
'Adapter failed to connect to device.');
});
}, testSpec.testName);
});
promise_test(() => {
testRunner.setBluetoothMockDataSet('HeartRateAdapter');
return requestDeviceWithKeyDown({filters: [{services: ['heart_rate']}]})
.then(device => device.connectGATT())
.then(gattServer => assert_true(gattServer.connected));
}, 'Device will connect');
</script>