Skip to content

Commit

Permalink
test: add network interception fail request invalidation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiago Perrotta committed Oct 23, 2023
1 parent 47d5fbd commit a97349b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/webdriver/webdriver/bidi/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class NoSuchNodeException(BidiException):
error_code = "no such node"


class NoSuchRequestException(BidiException):
error_code = "no such request"


class NoSuchScriptException(BidiException):
error_code = "no such script"

Expand Down
5 changes: 5 additions & 0 deletions tools/webdriver/webdriver/bidi/modules/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def _add_intercept(self, result: Mapping[str, Any]) -> Any:
assert result["intercept"] is not None
return result["intercept"]

@command
def fail_request(self, request: str) -> Mapping[str, Any]:
params: MutableMapping[str, Any] = {"request": request}
return params

@command
def remove_intercept(self, intercept: str) -> Mapping[str, Any]:
params: MutableMapping[str, Any] = {"intercept": intercept}
Expand Down
Empty file.
35 changes: 35 additions & 0 deletions webdriver/tests/bidi/network/fail_request/invalid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest
import webdriver.bidi.error as error

pytestmark = pytest.mark.asyncio

PAGE_EMPTY_TEXT = "/webdriver/tests/bidi/network/support/empty.txt"


@pytest.mark.parametrize("value", [None, False, 42, {}, []])
async def test_params_request_invalid_type(bidi_session, value):
with pytest.raises(error.InvalidArgumentException):
await bidi_session.network.fail_request(request=value)


@pytest.mark.parametrize("value", ["", "foo"])
async def test_params_request_invalid_value(bidi_session, value):
with pytest.raises(error.NoSuchRequestException):
await bidi_session.network.fail_request(request=value)


async def test_params_request_no_such_request(bidi_session, setup_network_test,
wait_for_event, fetch, url):
await setup_network_test(events=[
"network.responseCompleted",
])
on_response_completed = wait_for_event("network.responseCompleted")

text_url = url(PAGE_EMPTY_TEXT)
await fetch(text_url)

response_completed_event = await on_response_completed
request = response_completed_event["request"]["request"]

with pytest.raises(error.NoSuchRequestException):
await bidi_session.network.fail_request(request=request)

0 comments on commit a97349b

Please sign in to comment.