Skip to content

Commit

Permalink
Bluetooth: Migrate some WPT tests to use Bidi SimulateAdapter
Browse files Browse the repository at this point in the history
Migrate some Web Bluetooth WPT tests to use WebDriver Bidi
SimulateAdapter.

HeadlessBluetoothDelegate is created in order to use navigator.bluetooth.getAvailability.

Change-Id: I9ee03ec00a67e95c8c0a485fa9f6a247e1f0ff59
Bug: 41484719
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6165347
Commit-Queue: Jack Hsieh <[email protected]>
Reviewed-by: Peter Kvitek <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1416319}
  • Loading branch information
chengweih001 authored and chromium-wpt-export-bot committed Feb 5, 2025
1 parent f158680 commit 79b8d99
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver.js?feature=bidi
// META: script=/resources/testdriver-vendor.js
// META: script=/bluetooth/resources/bluetooth-test.js
// META: script=/bluetooth/resources/bluetooth-fake-devices.js
'use strict';
const test_desc = 'getAvailability() resolves with false if the system does ' +
'not have an adapter.';

bluetooth_test(async () => {
await navigator.bluetooth.test.simulateCentral({state: 'absent'});
bluetooth_bidi_test(async () => {
await test_driver.bidi.bluetooth.simulate_adapter({state: "absent"});
let availability = await navigator.bluetooth.getAvailability();
assert_false(
availability,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver.js?feature=bidi
// META: script=/resources/testdriver-vendor.js
// META: script=/bluetooth/resources/bluetooth-test.js
// META: script=/bluetooth/resources/bluetooth-fake-devices.js
'use strict';
const test_desc = 'getAvailability() resolves with true if the Bluetooth ' +
'radio is powered off, but the platform that supports Bluetooth LE.';

bluetooth_test(async () => {
await navigator.bluetooth.test.simulateCentral({state: 'powered-off'});
bluetooth_bidi_test(async () => {
await test_driver.bidi.bluetooth.simulate_adapter({state: "powered-off"});
let availability = await navigator.bluetooth.getAvailability();
assert_true(
availability,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver.js?feature=bidi
// META: script=/resources/testdriver-vendor.js
// META: script=/bluetooth/resources/bluetooth-test.js
// META: script=/bluetooth/resources/bluetooth-fake-devices.js
'use strict';
const test_desc = 'getAvailability() resolves with true if the Bluetooth ' +
'radio is powered on and the platform supports Bluetooth LE.';

bluetooth_test(async () => {
await navigator.bluetooth.test.simulateCentral({state: 'powered-on'});
bluetooth_bidi_test(async () => {
await test_driver.bidi.bluetooth.simulate_adapter({state: "powered-on"});
let availability = await navigator.bluetooth.getAvailability();
assert_true(
availability,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver.js?feature=bidi
// META: script=/resources/testdriver-vendor.js
// META: script=/bluetooth/resources/bluetooth-test.js
// META: script=/bluetooth/resources/bluetooth-fake-devices.js
Expand All @@ -9,8 +9,8 @@ const cross_origin_src = 'https://{{domains[www]}}:{{ports[https][0]}}' +
'/bluetooth/resources/health-thermometer-iframe.html'
let iframe = document.createElement('iframe');

bluetooth_test(async () => {
await navigator.bluetooth.test.simulateCentral({state: 'powered-on'});
bluetooth_bidi_test(async () => {
await test_driver.bidi.bluetooth.simulate_adapter({state: "powered-on"});
await new Promise(resolve => {
iframe.src = cross_origin_src;
document.body.appendChild(iframe);
Expand Down
20 changes: 20 additions & 0 deletions bluetooth/resources/bluetooth-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ function bluetooth_test(
}, name, properties);
}

/**
* These tests rely on the User Agent providing an implementation of the
* WebDriver-Bidi for testing Web Bluetooth
* https://webbluetoothcg.github.io/web-bluetooth/#automated-testing
* @param {function{*}: Promise<*>} test_function The Web Bluetooth test to run.
* @param {string} name The name or description of the test.
* @param {object} properties An object containing extra options for the test.
* @param {Boolean} validate_response_consumed Whether to validate all response
* consumed or not.
* @returns {Promise<void>} Resolves if Web Bluetooth test ran successfully, or
* rejects if the test failed.
*/
function bluetooth_bidi_test(
test_function, name, properties, validate_response_consumed = true) {
return promise_test(async (t) => {
assert_implements(navigator.bluetooth, 'missing navigator.bluetooth');
await test_function(t);
}, name, properties);
}

/**
* Test Helpers
*/
Expand Down

0 comments on commit 79b8d99

Please sign in to comment.