Skip to content

Commit

Permalink
[wdspec] add invalid tests for session.subscribe with user contexts (w…
Browse files Browse the repository at this point in the history
…eb-platform-tests#50290)

* [wdspec] add invalid tests for session.subscribe with user contexts

* rename userContexts
  • Loading branch information
OrKoN authored Jan 29, 2025
1 parent dcdc147 commit 0d7d283
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
5 changes: 4 additions & 1 deletion tools/webdriver/webdriver/bidi/modules/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ def status(self) -> Mapping[str, Any]:
@command
def subscribe(self,
events: List[str],
contexts: Optional[List[str]] = None) -> Mapping[str, Any]:
contexts: Optional[List[str]] = None,
user_contexts: Optional[List[str]] = None) -> Mapping[str, Any]:
params: MutableMapping[str, Any] = {"events": events}
if contexts is not None:
params["contexts"] = contexts
if user_contexts is not None:
params["userContexts"] = user_contexts
return params

@command
Expand Down
44 changes: 43 additions & 1 deletion webdriver/tests/bidi/session/subscribe/invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from webdriver.bidi.error import InvalidArgumentException, NoSuchFrameException
from webdriver.bidi.error import InvalidArgumentException, NoSuchFrameException, NoSuchUserContextException

from ... import create_console_api_message

Expand Down Expand Up @@ -130,3 +130,45 @@ async def test_subscribe_to_closed_tab(bidi_session):
# Try to subscribe to the closed context
with pytest.raises(NoSuchFrameException):
await bidi_session.session.subscribe(events=["log.entryAdded"], contexts=[new_tab["context"]])


@pytest.mark.asyncio
@pytest.mark.parametrize("value", [True, "foo", 42, {}])
async def test_params_user_context_invalid_type(bidi_session, value):
with pytest.raises(InvalidArgumentException):
await bidi_session.session.subscribe(events=["browsingContext.load"], user_contexts=value)


@pytest.mark.asyncio
async def test_params_user_context_empty(bidi_session):
with pytest.raises(InvalidArgumentException):
await bidi_session.session.subscribe(events=["browsingContext.load"], user_contexts=[])


@pytest.mark.asyncio
@pytest.mark.parametrize("value", [None, True, 42, [], {}])
async def test_params_user_context_value_invalid_type(bidi_session, value):
with pytest.raises(InvalidArgumentException):
await bidi_session.session.subscribe(events=["browsingContext.load"], user_contexts=[value])


@pytest.mark.asyncio
async def test_params_user_context_value_invalid_value(bidi_session):
with pytest.raises(NoSuchUserContextException):
await bidi_session.session.subscribe(events=["browsingContext.load"], user_contexts=["foo"])


@pytest.mark.asyncio
async def test_params_user_context_and_contexts(bidi_session, top_context):
with pytest.raises(InvalidArgumentException):
await bidi_session.session.subscribe(events=["browsingContext.load"], user_contexts=["default"], contexts=[top_context["context"]])


@pytest.mark.asyncio
async def test_subscribe_to_closed_user_context(bidi_session, create_user_context):
user_context = await create_user_context()
await bidi_session.browser.remove_user_context(user_context=user_context)

# Try to subscribe to closed user context.
with pytest.raises(NoSuchUserContextException):
await bidi_session.session.subscribe(events=["log.entryAdded"], user_contexts=[user_context])

0 comments on commit 0d7d283

Please sign in to comment.