mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-29 20:57:43 -10:00
<!-- Please describe your changes on the following line: --> This implements the [Permissions API](https://w3c.github.io/permissions/) spec. Also includes the WebBluetooth related implementation for this. There are some know issues: - [ ] If the descriptor name is invalid [this](https://gist.github.com/dati91/7a6a0a563d90f49ba5a351e48c5b626b#file-permissionstatusbindings-rs-L323) will throw an error, rather that return it and we could handle it. - [x] The [environment settings object](https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object) is not implemented in servo and the spec rely on it. - [x] There is a popup in the implementation which prevent us to add wpt test, we should figure out a way to make it work - [ ] The allowedDevice's allowed_services attribute is not used in our implementation, because we store these in the lower level, not in the dom side. - [ ] We think the bluetooth revoke function will need some more work, but the problem is the spec needs clarifications on that part. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: a537cf48b18d9bba3453b924a4453f5e19dea4ed
70 lines
2.3 KiB
HTML
70 lines
2.3 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<title>Bluetooth Permission Test</title>
|
|
<body>
|
|
<button type="button" onclick="onRequestButtonClick()">request</button>
|
|
<button type="button" onclick="onQueryButtonClick()">query</button>
|
|
<pre id="log"></pre>
|
|
<script>
|
|
if (window.testRunner)
|
|
window.testRunner.setBluetoothMockDataSet('HeartRateAdapter');
|
|
|
|
function onRequestButtonClick() {
|
|
clear();
|
|
window.navigator.permissions.request({
|
|
name: 'bluetooth',
|
|
filters: [{
|
|
services: ['heart_rate'],
|
|
}],
|
|
})
|
|
.then(r => {
|
|
log("Result is instance of PermissionStatus: " + (r instanceof PermissionStatus));
|
|
log("Result is instance of BluetoothPermissionResult subclass: " + (r instanceof BluetoothPermissionResult));
|
|
log("State of result: " + r.state);
|
|
let device = r.devices()[0];
|
|
if (device) {
|
|
log("Result contains device: " + device.name);
|
|
sessionStorage.lastDevice = device.id;
|
|
log("Device id stored: " + device.id);
|
|
} else {
|
|
log("No device found!");
|
|
}
|
|
})
|
|
.catch(err => log(err));
|
|
}
|
|
|
|
function onQueryButtonClick() {
|
|
clear();
|
|
if (!sessionStorage.lastDevice)
|
|
return log("No stored device id!");
|
|
window.navigator.permissions.query({
|
|
name: "bluetooth",
|
|
deviceId: sessionStorage.lastDevice,
|
|
})
|
|
.then(r => {
|
|
log("Result is instance of PermissionStatus: " + (r instanceof PermissionStatus));
|
|
log("Result is instance of BluetoothPermissionResult subclass: " + (r instanceof BluetoothPermissionResult));
|
|
log("State of result: " + r.state);
|
|
log("Stored Device id: " + sessionStorage.lastDevice);
|
|
let device = r.devices()[0];
|
|
if (device) {
|
|
log("Result contains device: " + device.name);
|
|
log("Device id: " + device.id);
|
|
} else {
|
|
log("No device found!");
|
|
}
|
|
})
|
|
.catch(err => log(err));
|
|
}
|
|
|
|
function log(line) {
|
|
document.getElementById("log").textContent += line + '\n';
|
|
}
|
|
|
|
function clear() {
|
|
document.getElementById("log").textContent = "";
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|