-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wdspec] add
bluetooth
module (#49066)
Add BiDi bluetooth module and and some wdspec tests. https://webbluetoothcg.github.io/web-bluetooth
- Loading branch information
1 parent
e44f453
commit 7b54230
Showing
9 changed files
with
122 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typing import Any, Mapping | ||
|
||
from ._module import BidiModule, command | ||
|
||
|
||
class Bluetooth(BidiModule): | ||
""" | ||
Represents bluetooth automation module specified in | ||
https://webbluetoothcg.github.io/web-bluetooth/#automated-testing | ||
""" | ||
|
||
@command | ||
def simulate_adapter(self, context: str, state: 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 | ||
} |
Empty file.
Empty file.
18 changes: 18 additions & 0 deletions
18
webdriver/tests/bidi/external/bluetooth/simulate_adapter/__init__.py
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,18 @@ | ||
from webdriver.bidi.modules.script import ContextTarget | ||
|
||
|
||
async def get_bluetooth_availability(bidi_session, context): | ||
result = await bidi_session.script.evaluate( | ||
expression="navigator.bluetooth.getAvailability()", | ||
target=ContextTarget(context["context"]), await_promise=True, ) | ||
return result['value'] | ||
|
||
|
||
async def set_simulate_adapter(bidi_session, context, test_page, state): | ||
# Navigate to a page, as bluetooth is not guaranteed to work on | ||
# `about:blank`. | ||
await bidi_session.browsing_context.navigate(context=context['context'], | ||
url=test_page, wait="complete") | ||
|
||
await bidi_session.bluetooth.simulate_adapter(context=context["context"], | ||
state=state) |
19 changes: 19 additions & 0 deletions
19
webdriver/tests/bidi/external/bluetooth/simulate_adapter/context.py
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,19 @@ | ||
import pytest | ||
|
||
from . import get_bluetooth_availability, set_simulate_adapter | ||
|
||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
async def test_contexts_are_isolated(bidi_session, top_context, test_page): | ||
another_browsing_context = await bidi_session.browsing_context.create( | ||
type_hint="tab") | ||
|
||
await set_simulate_adapter(bidi_session, top_context, test_page, | ||
"powered-on") | ||
await set_simulate_adapter(bidi_session, another_browsing_context, | ||
test_page, "absent") | ||
|
||
assert await get_bluetooth_availability(bidi_session, top_context) is True | ||
assert await get_bluetooth_availability(bidi_session, | ||
another_browsing_context) is False |
31 changes: 31 additions & 0 deletions
31
webdriver/tests/bidi/external/bluetooth/simulate_adapter/invalid.py
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,31 @@ | ||
import pytest | ||
import webdriver.bidi.error as error | ||
|
||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
@pytest.mark.parametrize("state", [None, False, 42, {}, []]) | ||
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) | ||
|
||
|
||
@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) | ||
|
||
|
||
@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") | ||
|
||
|
||
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") |
31 changes: 31 additions & 0 deletions
31
webdriver/tests/bidi/external/bluetooth/simulate_adapter/state.py
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,31 @@ | ||
import pytest | ||
|
||
from . import get_bluetooth_availability, set_simulate_adapter | ||
|
||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
@pytest.mark.parametrize("state,availability", | ||
[("absent", False), ("powered-off", True), | ||
("powered-on", True)]) | ||
async def test_state(bidi_session, top_context, test_page, state, availability): | ||
await set_simulate_adapter(bidi_session, top_context, test_page, state) | ||
assert await get_bluetooth_availability(bidi_session, | ||
top_context) == availability | ||
|
||
|
||
@pytest.mark.parametrize("state_1,availability_1", | ||
[("absent", False), ("powered-off", True), | ||
("powered-on", True)]) | ||
@pytest.mark.parametrize("state_2,availability_2", | ||
[("absent", False), ("powered-off", True), | ||
("powered-on", True)]) | ||
async def test_set_twice(bidi_session, top_context, test_page, state_1, | ||
availability_1, state_2, availability_2): | ||
await set_simulate_adapter(bidi_session, top_context, test_page, state_1) | ||
assert await get_bluetooth_availability(bidi_session, | ||
top_context) == availability_1 | ||
|
||
await set_simulate_adapter(bidi_session, top_context, test_page, state_2) | ||
assert await get_bluetooth_availability(bidi_session, | ||
top_context) == availability_2 |