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 details.

Web Bluetooth testing relies on the FakeBluetooth test API which must be provided by browsers under test.

TODO(#485): Update the links to FakeBluetooth 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.

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 are JavaScript files that contain a CALLS() keyword with functions delimited by 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 corresponding directory.


The ./script-tests/server/get-same-object.js contains the following code:


The functions in CALLS() will be expanded to generate 3 test files prefixed with gen-:


Generate Tests

To generate the tests in script-tests, run the following command from the source root:

$ 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.

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 WebUSB.

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 infrastructure.

For more implementation details, see the 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.


Mailing list: web-bluetooth@chromium.org

Bug tracker: Blink>Bluetooth