Skip to content

Commit

Permalink
fix: allow setting bluetooth.simulateAdapter multiple times (#2762)
Browse files Browse the repository at this point in the history
Align with the spec (step 6) of
[`bluetooth.simulateAdapter`](https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateAdapter-command).
  • Loading branch information
sadym-chromium authored Nov 8, 2024
1 parent ae24e37 commit 3963880
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/bidiMapper/modules/bluetooth/BluetoothProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export class BluetoothProcessor {
params: Bluetooth.SimulateAdapterParameters,
): Promise<EmptyResult> {
const context = this.#browsingContextStorage.getContext(params.context);
// Bluetooth spec requires overriding the existing adapter (step 6). From the CDP
// perspective, we need to disable the emulation first.
// https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateAdapter-command
await context.cdpTarget.browserCdpClient.sendCommand(
'BluetoothEmulation.disable',
);
await context.cdpTarget.browserCdpClient.sendCommand(
'BluetoothEmulation.enable',
{
Expand Down
33 changes: 33 additions & 0 deletions tests/bluetooth/test_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,39 @@ async def setup_device(websocket, context_id):
})


@pytest.mark.asyncio
@pytest.mark.parametrize("state_1", ["absent", "powered-off", "powered-on"])
@pytest.mark.parametrize("state_2", ["absent", "powered-off", "powered-on"])
@pytest.mark.parametrize('capabilities', [{
'goog:chromeOptions': {
'args': ['--enable-features=WebBluetooth']
}
}],
indirect=True)
async def test_simulate_adapter_twice(websocket, context_id, state_1, state_2,
test_headless_mode):
if test_headless_mode == "old":
pytest.xfail("Old headless mode does not support Bluetooth")

await execute_command(
websocket, {
'method': 'bluetooth.simulateAdapter',
'params': {
'context': context_id,
'state': state_1,
}
})

await execute_command(
websocket, {
'method': 'bluetooth.simulateAdapter',
'params': {
'context': context_id,
'state': state_2,
}
})


@pytest.mark.asyncio
@pytest.mark.parametrize('capabilities', [{
'goog:chromeOptions': {
Expand Down

0 comments on commit 3963880

Please sign in to comment.