Copy as Markdown
# Web Bluetooth API Tests
The Web Bluetooth API enables sites to connect to and interact with Bluetooth
Low Energy devices. Please check the [Web Bluetooth specification] for more
Web Bluetooth testing relies on the [FakeBluetooth][Web Bluetooth
Testing] test API which must be provided by browsers under test.
TODO([#485]): Update the links to [FakeBluetooth][Web Bluetooth Testing] to
point to the [Testing Web Bluetooth specification].
In this test suite `resources/bluetooth-test.js` detects and triggers
the API to be loaded as needed. This file also contains test helper methods,
such as for asserting that Bluetooth events are fired in a specific order.
The `resources/bluetooth-fake-devices.js` contains several helper methods that set
up fake Bluetooth devices.
[Web Bluetooth specification]: https://WebBluetoothCG.github.io/web-bluetooth
[Web Bluetooth Testing]:
[Testing Web Bluetooth specification]:
## Generated Tests
Several Web Bluetooth tests share common test logic. For these tests, the
`script-tests` directory contains templates that are used by the
`generate.py` script to create several tests from these templates. The templates
a `|` character. A test will be created for each function in the `CALLS()` by
`generate.py`. Note that for each subdirectory in `script-tests` there is a
matching directory under `bluetooth`. The generator will expand `CALLS`
functions into the
The `./script-tests/server/get-same-object.js` contains the following
The functions in `CALLS()` will be expanded to generate 3 test files prefixed
### Generate Tests
To generate the tests in `script-tests`, run the following command from the
$ python bluetooth/generate.py
To check that generated tests are correct and that there are no obsolete tests,
or tests for which a template does not exist anymore, run:
$ python bluetooth/generate_test.py
More details can be found in `generate.py` and `generate_test.py`.
## Chromium Implementation
The Chromium implementation is provided by
`../resources/chromium/web-bluetooth-test.js` using [MojoJS].
The Chromium implementation is not included in stable Chrome builds since it
would add too much to the binary size. On Chromium infrastructure, it is run
using the `content_shell` executable.
In the future, Chromium `src/device/bluetooth` may be refactored into a Mojo
service. At this point, it would be possible to add the necessary testing hooks
into stable Chrome without substantially increasing the binary size, similar to
These Bluetooth tests are upstreamed here because other browsers can reuse them
by implementing the [Web Bluetooth Testing] API, even if only on their internal
For more implementation details, see the [Web Bluetooth Service README].
[Web Bluetooth Service README]:
# Resources and Documentation
For any issues pertaining to the specification, please file a [GitHub]
issue. For issues pertaining to an implementation of Web Bluetooth, please
file an issue with the implementor's bug tracker.
* [Web Bluetooth specification]
* [Web Bluetooth Testing]
* [Testing Web Bluetooth specification]
Mailing list: firstname.lastname@example.org
Bug tracker: [Blink>Bluetooth]
* [Web Bluetooth Service README]