Skip to content

[Bluetooth] Align bluetooth tests with the spec #51018

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

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tools/webdriver/webdriver/bidi/modules/bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ def handle_request_device_prompt(self, context: str, prompt: str, accept: bool,
}

@command
def simulate_adapter(self, context: str, state: str) -> Mapping[str, Any]:
def simulate_adapter(self, context: str, state: str, type_: str) -> Mapping[str, Any]:
"""
Represents a command `bluetooth.simulateAdapter` specified in
https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateAdapter-command
"""
return {
"context": context,
"state": state
"state": state,
"type": type_
}

@command
Expand Down
4 changes: 3 additions & 1 deletion tools/wptrunner/wptrunner/executors/asyncactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ async def __call__(self, payload):
raise ValueError("Unexpected context type: %s" % context)

state = payload["state"]
return await self.protocol.bidi_bluetooth.simulate_adapter(context, state)
return await self.protocol.bidi_bluetooth.simulate_adapter(context,
state,
type_="create")

class BidiBluetoothSimulatePreconnectedPeripheralAction:
name = "bidi.bluetooth.simulate_preconnected_peripheral"
Expand Down
5 changes: 3 additions & 2 deletions tools/wptrunner/wptrunner/executors/executorwebdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ def setup(self):

async def simulate_adapter(self,
context: str,
state: str) -> None:
state: str,
type_: str) -> None:
await self.webdriver.bidi_session.bluetooth.simulate_adapter(
context=context, state=state)
context=context, state=state, type_=type_)

async def simulate_preconnected_peripheral(self,
context: str,
Expand Down
3 changes: 2 additions & 1 deletion tools/wptrunner/wptrunner/executors/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ async def handle_request_device_prompt(self,
@abstractmethod
async def simulate_adapter(self,
context: str,
state: str) -> None:
state: str,
type_: str) -> None:
"""
Creates a simulated bluetooth adapter.
:param context: Browsing context to set the simulated adapter to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ async def set_simulate_adapter(bidi_session, context, test_page, state):
url=test_page, wait="complete")

await bidi_session.bluetooth.simulate_adapter(context=context["context"],
state=state)
state=state, type_="create")
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@
async def test_state_invalid_type(bidi_session, top_context, state):
with pytest.raises(error.InvalidArgumentException):
await bidi_session.bluetooth.simulate_adapter(
context=top_context["context"], state=state)
context=top_context["context"], state=state, type_="create")


@pytest.mark.parametrize("state", ["", "invalid"])
async def test_state_invalid_value(bidi_session, top_context, state):
with pytest.raises(error.InvalidArgumentException):
await bidi_session.bluetooth.simulate_adapter(
context=top_context["context"], state=state)
context=top_context["context"], state=state, type_="create")


@pytest.mark.parametrize("context", [None, False, 42, {}, []])
async def test_context_invalid_type(bidi_session, context):
with pytest.raises(error.InvalidArgumentException):
await bidi_session.bluetooth.simulate_adapter(
context=context, state="powered-on")
context=context, state="powered-on", type_="create")


async def test_context_unknown_value(bidi_session):
with pytest.raises(error.NoSuchFrameException):
await bidi_session.bluetooth.simulate_adapter(
context="UNKNOWN_CONTEXT", state="powered-on")
context="UNKNOWN_CONTEXT", state="powered-on", type_="create")
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async def set_simulate_preconnected_peripheral(bidi_session, context, test_page,
await bidi_session.browsing_context.navigate(context=context['context'],
url=test_page, wait="complete")
await bidi_session.bluetooth.simulate_adapter(context=context["context"],
state="powered-on")
state="powered-on", type_="create")
await bidi_session.bluetooth.simulate_preconnected_peripheral(
context=context["context"],
address=address, name=name,
Expand Down
Loading