Skip to content

Commit e680383

Browse files
sadym-chromiummoz-wptsync-bot
authored andcommitted
Bug 1930177 [wpt PR 49066] - [wdspec] add bluetooth module, a=testonly
Automatic update from web-platform-tests [wdspec] add `bluetooth` module (#49066) Add BiDi bluetooth module and and some wdspec tests. https://webbluetoothcg.github.io/web-bluetooth -- wpt-commits: 7b542308b66f77878714f851a8baac291ee2a39e wpt-pr: 49066
1 parent 5424c15 commit e680383

File tree

9 files changed

+122
-0
lines changed

9 files changed

+122
-0
lines changed

testing/web-platform/tests/tools/webdriver/webdriver/bidi/client.py

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def __init__(self,
9090

9191
# Modules.
9292
# For each module, have a property representing that module
93+
self.bluetooth = modules.Bluetooth(self)
9394
self.browser = modules.Browser(self)
9495
self.browsing_context = modules.BrowsingContext(self)
9596
self.input = modules.Input(self)

testing/web-platform/tests/tools/webdriver/webdriver/bidi/modules/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# flake8: noqa
22

3+
from .bluetooth import Bluetooth
34
from .browser import Browser
45
from .browsing_context import BrowsingContext
56
from .input import Input
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typing import Any, Mapping
2+
3+
from ._module import BidiModule, command
4+
5+
6+
class Bluetooth(BidiModule):
7+
"""
8+
Represents bluetooth automation module specified in
9+
https://webbluetoothcg.github.io/web-bluetooth/#automated-testing
10+
"""
11+
12+
@command
13+
def simulate_adapter(self, context: str, state: str) -> Mapping[str, Any]:
14+
"""
15+
Represents a command `bluetooth.simulateAdapter` specified in
16+
https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateAdapter-command
17+
"""
18+
return {
19+
"context": context,
20+
"state": state
21+
}

testing/web-platform/tests/webdriver/tests/bidi/external/__init__.py

Whitespace-only changes.

testing/web-platform/tests/webdriver/tests/bidi/external/bluetooth/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from webdriver.bidi.modules.script import ContextTarget
2+
3+
4+
async def get_bluetooth_availability(bidi_session, context):
5+
result = await bidi_session.script.evaluate(
6+
expression="navigator.bluetooth.getAvailability()",
7+
target=ContextTarget(context["context"]), await_promise=True, )
8+
return result['value']
9+
10+
11+
async def set_simulate_adapter(bidi_session, context, test_page, state):
12+
# Navigate to a page, as bluetooth is not guaranteed to work on
13+
# `about:blank`.
14+
await bidi_session.browsing_context.navigate(context=context['context'],
15+
url=test_page, wait="complete")
16+
17+
await bidi_session.bluetooth.simulate_adapter(context=context["context"],
18+
state=state)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pytest
2+
3+
from . import get_bluetooth_availability, set_simulate_adapter
4+
5+
pytestmark = pytest.mark.asyncio
6+
7+
8+
async def test_contexts_are_isolated(bidi_session, top_context, test_page):
9+
another_browsing_context = await bidi_session.browsing_context.create(
10+
type_hint="tab")
11+
12+
await set_simulate_adapter(bidi_session, top_context, test_page,
13+
"powered-on")
14+
await set_simulate_adapter(bidi_session, another_browsing_context,
15+
test_page, "absent")
16+
17+
assert await get_bluetooth_availability(bidi_session, top_context) is True
18+
assert await get_bluetooth_availability(bidi_session,
19+
another_browsing_context) is False
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
import webdriver.bidi.error as error
3+
4+
pytestmark = pytest.mark.asyncio
5+
6+
7+
@pytest.mark.parametrize("state", [None, False, 42, {}, []])
8+
async def test_state_invalid_type(bidi_session, top_context, state):
9+
with pytest.raises(error.InvalidArgumentException):
10+
await bidi_session.bluetooth.simulate_adapter(
11+
context=top_context["context"], state=state)
12+
13+
14+
@pytest.mark.parametrize("state", ["", "invalid"])
15+
async def test_state_invalid_value(bidi_session, top_context, state):
16+
with pytest.raises(error.InvalidArgumentException):
17+
await bidi_session.bluetooth.simulate_adapter(
18+
context=top_context["context"], state=state)
19+
20+
21+
@pytest.mark.parametrize("context", [None, False, 42, {}, []])
22+
async def test_context_invalid_type(bidi_session, context):
23+
with pytest.raises(error.InvalidArgumentException):
24+
await bidi_session.bluetooth.simulate_adapter(
25+
context=context, state="powered-on")
26+
27+
28+
async def test_context_unknown_value(bidi_session):
29+
with pytest.raises(error.NoSuchFrameException):
30+
await bidi_session.bluetooth.simulate_adapter(
31+
context="UNKNOWN_CONTEXT", state="powered-on")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
3+
from . import get_bluetooth_availability, set_simulate_adapter
4+
5+
pytestmark = pytest.mark.asyncio
6+
7+
8+
@pytest.mark.parametrize("state,availability",
9+
[("absent", False), ("powered-off", True),
10+
("powered-on", True)])
11+
async def test_state(bidi_session, top_context, test_page, state, availability):
12+
await set_simulate_adapter(bidi_session, top_context, test_page, state)
13+
assert await get_bluetooth_availability(bidi_session,
14+
top_context) == availability
15+
16+
17+
@pytest.mark.parametrize("state_1,availability_1",
18+
[("absent", False), ("powered-off", True),
19+
("powered-on", True)])
20+
@pytest.mark.parametrize("state_2,availability_2",
21+
[("absent", False), ("powered-off", True),
22+
("powered-on", True)])
23+
async def test_set_twice(bidi_session, top_context, test_page, state_1,
24+
availability_1, state_2, availability_2):
25+
await set_simulate_adapter(bidi_session, top_context, test_page, state_1)
26+
assert await get_bluetooth_availability(bidi_session,
27+
top_context) == availability_1
28+
29+
await set_simulate_adapter(bidi_session, top_context, test_page, state_2)
30+
assert await get_bluetooth_availability(bidi_session,
31+
top_context) == availability_2

0 commit comments

Comments
 (0)