зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1618017 [wpt PR 21972] - bluetooth: getDevices() implementation, a=testonly
Automatic update from web-platform-tests bluetooth: getDevices() implementation This change implements getDevices() which returns a list of WebBluetoothDevice objects that the current site has permission to access. If the kWebBluetoothNewPermissionsBackend flag is enabled, the list of devices will contain all of the permitted devices. If the flag is not enabled, then the list of devices will contain the permitted devices that are currently connected to the system. Design doc: https://docs.google.com/document/d/1h3uAVXJARHrNWaNACUPiQhLt7XI-fFFQoARSs1WgMDM/edit#heading=h.5ugemo7p04z9 Bug: 577953 Change-Id: I9785f24ee46ac634b6a96d6146f54da37d132a4e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2044660 Commit-Queue: Ovidio de Jesús Ruiz-Henríquez <odejesush@chromium.org> Reviewed-by: Reilly Grant <reillyg@chromium.org> Reviewed-by: Vincent Scheib <scheib@chromium.org> Reviewed-by: John Abd-El-Malek <jam@chromium.org> Reviewed-by: Mustafa Emre Acer <meacer@chromium.org> Reviewed-by: Philip Jägenstedt <foolip@chromium.org> Cr-Commit-Position: refs/heads/master@{#748917} -- wpt-commits: 298c1a238766be0140170f39e5c883fe2ca00ac3 wpt-pr: 21972
This commit is contained in:
Родитель
3619e7ca04
Коммит
aaeeaa9c66
|
@ -0,0 +1,71 @@
|
|||
// META: script=/resources/testdriver.js
|
||||
// META: script=/resources/testdriver-vendor.js
|
||||
// META: script=/bluetooth/resources/bluetooth-helpers.js
|
||||
'use strict';
|
||||
const test_desc = 'getDevices() resolves with permitted devices that can be ' +
|
||||
'GATT connected to.';
|
||||
|
||||
bluetooth_test(async () => {
|
||||
// Set up two connectable Bluetooth devices with their services discovered.
|
||||
// One device is a Health Thermometer device with the 'health_thermometer'
|
||||
// service while the other is a Heart Rate device with the 'heart_rate'
|
||||
// service. Both devices contain the 'generic_access' service.
|
||||
let fake_peripherals = await setUpHealthThermometerAndHeartRateDevices();
|
||||
for (let fake_peripheral of fake_peripherals) {
|
||||
await fake_peripheral.setNextGATTConnectionResponse({code: HCI_SUCCESS});
|
||||
await fake_peripheral.addFakeService({uuid: 'generic_access'});
|
||||
if (fake_peripheral.address === '09:09:09:09:09:09')
|
||||
await fake_peripheral.addFakeService({uuid: 'health_thermometer'});
|
||||
else
|
||||
await fake_peripheral.addFakeService({uuid: 'heart_rate'});
|
||||
await fake_peripheral.setNextGATTDiscoveryResponse({code: HCI_SUCCESS});
|
||||
}
|
||||
|
||||
// Request the Health Thermometer device with access to its 'generic_access'
|
||||
// service.
|
||||
await requestDeviceWithTrustedClick(
|
||||
{filters: [{name: 'Health Thermometer', services: ['generic_access']}]});
|
||||
let devices = await navigator.bluetooth.getDevices();
|
||||
assert_equals(
|
||||
devices.length, 1,
|
||||
`getDevices() should return the 'Health Thermometer' device.`);
|
||||
|
||||
// Only the 'generic_access' service can be accessed.
|
||||
try {
|
||||
await devices[0].gatt.connect();
|
||||
await devices[0].gatt.getPrimaryService('generic_access');
|
||||
assert_promise_rejects_with_message(
|
||||
devices[0].gatt.getPrimaryService('health_thermometer'),
|
||||
{name: 'SecurityError'});
|
||||
} catch (err) {
|
||||
assert_unreached(`${err.name}: ${err.message}`);
|
||||
}
|
||||
|
||||
// Request the Heart Rate device with access to both of its services.
|
||||
await requestDeviceWithTrustedClick({
|
||||
filters: [{name: 'Heart Rate', services: ['generic_access', 'heart_rate']}]
|
||||
});
|
||||
devices = await navigator.bluetooth.getDevices();
|
||||
assert_equals(
|
||||
devices.length, 2,
|
||||
`getDevices() should return the 'Health Thermometer' and 'Health ` +
|
||||
`Monitor' devices`);
|
||||
|
||||
// All of Heart Rate device's services can be accessed, while only the
|
||||
// 'generic_access' service can be accessed on Health Thermometer.
|
||||
try {
|
||||
for (let device of devices) {
|
||||
await device.gatt.connect();
|
||||
await device.gatt.getPrimaryService('generic_access');
|
||||
if (device.name === 'Heart Rate') {
|
||||
await device.gatt.getPrimaryService('heart_rate');
|
||||
} else {
|
||||
assert_promise_rejects_with_message(
|
||||
devices[0].gatt.getPrimaryService('health_thermometer'),
|
||||
{name: 'SecurityError'});
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
assert_unreached(`${err.name}: ${err.message}`);
|
||||
}
|
||||
}, test_desc);
|
|
@ -0,0 +1,14 @@
|
|||
// META: script=/resources/testdriver.js
|
||||
// META: script=/resources/testdriver-vendor.js
|
||||
// META: script=/bluetooth/resources/bluetooth-helpers.js
|
||||
'use strict';
|
||||
const test_desc = 'getDevices() resolves with empty array if no device ' +
|
||||
'permissions have been granted.';
|
||||
|
||||
bluetooth_test(async () => {
|
||||
await navigator.bluetooth.test.simulateCentral({state: 'powered-on'});
|
||||
let devices = await navigator.bluetooth.getDevices();
|
||||
|
||||
assert_equals(
|
||||
0, devices.length, 'getDevices() should resolve with an empty array');
|
||||
}, test_desc);
|
|
@ -0,0 +1,22 @@
|
|||
// META: script=/resources/testdriver.js
|
||||
// META: script=/resources/testdriver-vendor.js
|
||||
// META: script=/bluetooth/resources/bluetooth-helpers.js
|
||||
'use strict';
|
||||
const test_desc = 'multiple calls to getDevices() resolves with the same' +
|
||||
'BluetoothDevice objects for each granted Bluetooth device.';
|
||||
|
||||
bluetooth_test(async () => {
|
||||
await getConnectedHealthThermometerDevice();
|
||||
let firstDevices = await navigator.bluetooth.getDevices();
|
||||
assert_equals(
|
||||
firstDevices.length, 1, 'getDevices() should return the granted device.');
|
||||
|
||||
let secondDevices = await navigator.bluetooth.getDevices();
|
||||
assert_equals(
|
||||
secondDevices.length, 1,
|
||||
'getDevices() should return the granted device.');
|
||||
assert_equals(
|
||||
firstDevices[0], secondDevices[0],
|
||||
'getDevices() should produce the same BluetoothDevice objects for a ' +
|
||||
'given Bluetooth device.');
|
||||
}, test_desc);
|
|
@ -16,6 +16,7 @@ test(() => {
|
|||
|
||||
// Bluetooth implements BluetoothDiscovery;
|
||||
assert_true('requestDevice' in navigator.bluetooth);
|
||||
assert_true('getDevices' in navigator.bluetooth);
|
||||
assert_equals(navigator.bluetooth.requestDevice.length, 0);
|
||||
}, test_desc);
|
||||
</script>
|
||||
|
|
Загрузка…
Ссылка в новой задаче