2 <script src=
"../resources/testharness.js"></script>
3 <script src=
"../resources/testharnessreport.js"></script>
4 <script src=
"resources/bluetooth-helpers.js"></script>
8 test(t
=> { assert_true(window
.testRunner
instanceof Object
); t
.done(); },
9 'window.testRunner is required for the following tests.');
12 testRunner
.setBluetoothMockDataSet('GenericAccessAdapter');
13 return requestDeviceWithKeyDown({filters
: [{services
: ['generic_access']}]})
15 testRunner
.setBluetoothMockDataSet('EmptyAdapter');
16 return assert_promise_rejects_with_message(
17 device
.connectGATT(),{
19 message
: 'Bluetooth Device is no longer in range.'
20 }, 'Device went out of range.');
22 }, 'Device goes out of range. Reject with NetworkError.');
24 // The following tests make sure the Web Bluetooth implementation
25 // responds correctly to the different types of errors the
26 // underlying platform might throw.
28 // Each implementation maps these devices to specific code paths
29 // that result in different errors thus increasing code coverage
30 // when testing. Therefore some of these devices might not be useful
31 // for all implementations.
33 testName
: 'Unknown error when connnecting.',
37 message
: 'Unknown error when connecting to the device.'
40 testName
: 'Connection was already in progress.',
44 message
: 'Connection already in progress.'
47 testName
: 'Connection failed.',
51 message
: 'Connection failed for unknown reason.'
54 testName
: 'Authentication failed when connecting.',
58 message
: 'Authentication failed.'
61 testName
: 'Authentication canceled when connecting.',
65 message
: 'Authentication canceled.'
68 testName
: 'Authentication rejected when connecting.',
72 message
: 'Authentication rejected.'
75 testName
: 'Authentication timed out when connecting.',
79 message
: 'Authentication timeout.'
82 testName
: 'Tried to connect to an unsupported device.',
86 message
: 'Unsupported device.'
88 }].forEach(testSpec
=> {
90 testRunner
.setBluetoothMockDataSet('FailingConnectionsAdapter');
91 return requestDeviceWithKeyDown({filters
: [{services
: [testSpec
.uuid
]}]})
93 assert_promise_rejects_with_message(
96 'Adapter failed to connect to device.');
98 }, testSpec
.testName
);
102 testRunner
.setBluetoothMockDataSet('GenericAccessAdapter');
103 return requestDeviceWithKeyDown({filters
: [{services
: ['generic_access']}]})
104 .then(device
=> device
.connectGATT())
105 .then(gattServer
=> assert_true(gattServer
.connected
));
106 }, 'Device will connect');