-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement Bluetooth Emulation BiDi mapping #2624
Merged
+224
−0
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1337725
Initial mapping for simulateAdapter.
alexnj c3fb815
Map simulatePreconnectedPeripheral command
alexnj c4076be
Map simulateAdvertisement command.
alexnj b6c759f
Use CDDLconv to generate type definitions from BT spec.
alexnj 6527e2d
Update tests to use new BiDi apis
alexnj 03ed42a
Fix precommit lint
alexnj 7ee958b
Update CDDL to the latest and merged spec.
alexnj f1330aa
Update BluetoothManufacturerData data type that got missed.
alexnj f229821
Merge remote-tracking branch 'upstream/main' into bt-bidi-mapper
alexnj 935b269
Revert the last change, in favor of spec modification
alexnj e46b8c4
Merge branch 'main' into bt-bidi-mapper
alexnj 039e551
Fix flake8 errors
alexnj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
# Copyright 2024 Google LLC. | ||
# Copyright (c) Microsoft Corporation. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import pytest | ||
from test_helpers import (AnyExtending, execute_command, goto_url, | ||
send_JSON_command, subscribe, wait_for_event) | ||
|
||
HTML_SINGLE_PERIPHERAL = """ | ||
<div> | ||
<button id="bluetooth">bluetooth</button> | ||
<script> | ||
const options = {filters: [{name:"SomeDevice"}]}; | ||
document.getElementById('bluetooth').addEventListener('click', () => { | ||
navigator.bluetooth.requestDevice(options); | ||
}); | ||
</script> | ||
</div> | ||
""" | ||
|
||
# Create a fake BT device. | ||
fake_device_address = '09:09:09:09:09:09' | ||
|
||
|
||
async def setup_device(websocket, context_id): | ||
# Simulate a Bluetooth adapter. | ||
await execute_command( | ||
websocket, { | ||
'method': 'bluetooth.simulateAdapter', | ||
'params': { | ||
'context': context_id, | ||
'state': 'powered-on', | ||
} | ||
}) | ||
|
||
# Create a fake BT device. | ||
fake_device_address = '09:09:09:09:09:09' | ||
await execute_command( | ||
websocket, { | ||
'method': 'bluetooth.simulatePreconnectedPeripheral', | ||
'params': { | ||
'context': context_id, | ||
'address': fake_device_address, | ||
'name': 'SomeDevice', | ||
'manufacturerData': [{ | ||
'key': 17, | ||
'data': 'AP8BAX8=', | ||
}], | ||
'knownServiceUuids': | ||
['12345678-1234-5678-9abc-def123456789', ], | ||
} | ||
}) | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize('capabilities', [{ | ||
'goog:chromeOptions': { | ||
'args': ['--enable-features=WebBluetooth'] | ||
} | ||
}], | ||
indirect=True) | ||
async def test_bluetooth_requestDevicePromptUpdated(websocket, context_id, | ||
html, test_headless_mode): | ||
if test_headless_mode == "old": | ||
pytest.xfail("Old headless mode does not support Bluetooth") | ||
|
||
await subscribe(websocket, ['bluetooth']) | ||
|
||
url = html(HTML_SINGLE_PERIPHERAL) | ||
await goto_url(websocket, context_id, url) | ||
|
||
await setup_device(websocket, context_id) | ||
|
||
await send_JSON_command( | ||
websocket, { | ||
'method': 'script.evaluate', | ||
'params': { | ||
'expression': 'document.querySelector("#bluetooth").click();', | ||
'awaitPromise': True, | ||
'target': { | ||
'context': context_id, | ||
}, | ||
'userActivation': True | ||
} | ||
}) | ||
|
||
response = await wait_for_event(websocket, | ||
'bluetooth.requestDevicePromptUpdated') | ||
assert response == AnyExtending({ | ||
'type': 'event', | ||
'method': 'bluetooth.requestDevicePromptUpdated', | ||
'params': { | ||
'context': context_id, | ||
'devices': [{ | ||
'id': fake_device_address | ||
}], | ||
} | ||
}) | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize('capabilities', [{ | ||
'goog:chromeOptions': { | ||
'args': ['--enable-features=WebBluetooth'] | ||
} | ||
}], | ||
indirect=True) | ||
@pytest.mark.parametrize('accept', [True, False]) | ||
async def test_bluetooth_handleRequestDevicePrompt(websocket, context_id, html, | ||
test_headless_mode, accept): | ||
if test_headless_mode == "old": | ||
pytest.xfail("Old headless mode does not support Bluetooth") | ||
|
||
await subscribe(websocket, ['bluetooth']) | ||
|
||
url = html(HTML_SINGLE_PERIPHERAL) | ||
await goto_url(websocket, context_id, url) | ||
|
||
await setup_device(websocket, context_id) | ||
|
||
await send_JSON_command( | ||
websocket, { | ||
'method': 'script.evaluate', | ||
'params': { | ||
'expression': 'document.querySelector("#bluetooth").click();', | ||
'awaitPromise': True, | ||
'target': { | ||
'context': context_id, | ||
}, | ||
'userActivation': True | ||
} | ||
}) | ||
|
||
event = await wait_for_event(websocket, | ||
'bluetooth.requestDevicePromptUpdated') | ||
|
||
await execute_command( | ||
websocket, { | ||
'method': 'bluetooth.handleRequestDevicePrompt', | ||
'params': { | ||
'context': context_id, | ||
'accept': accept, | ||
'prompt': event['params']['prompt'], | ||
'device': event['params']['devices'][0]['id'] | ||
} | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: the params should be parsed