-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add network interception continue request invalidation tests
- Loading branch information
Thiago Perrotta
committed
Oct 20, 2023
1 parent
aa4bba2
commit 177e311
Showing
3 changed files
with
120 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
Empty file.
106 changes: 106 additions & 0 deletions
106
webdriver/tests/bidi/network/continue_request/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,106 @@ | ||
import asyncio | ||
import pytest | ||
import webdriver.bidi.error as error | ||
from webdriver.bidi.modules.script import ScriptEvaluateResultException | ||
|
||
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.continue_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.continue_request(request=value) | ||
|
||
|
||
async def test_params_request_no_such_request(bidi_session, setup_network_test, | ||
wait_for_event, fetch, url): | ||
network_events = await setup_network_test(events=[ | ||
"network.responseCompleted", | ||
]) | ||
|
||
text_url = url(PAGE_EMPTY_TEXT) | ||
on_response_completed = wait_for_event("network.responseCompleted") | ||
await fetch(text_url) | ||
await on_response_completed | ||
|
||
request = network_events["network.responseCompleted"][0]["request"]["request"] | ||
|
||
with pytest.raises(error.NoSuchRequestException): | ||
await bidi_session.network.continue_request(request=request) | ||
|
||
|
||
@pytest.mark.parametrize("value", [False, 42, {}, []]) | ||
async def test_params_method_invalid_type( | ||
bidi_session, value, setup_network_test, url, fetch, wait_for_event, | ||
add_intercept): | ||
await setup_network_test(events=["network.beforeRequestSent"]) | ||
|
||
text_url = url(PAGE_EMPTY_TEXT) | ||
await add_intercept( | ||
phases=["beforeRequestSent"], | ||
url_patterns=[{ | ||
"type": "string", | ||
"pattern": text_url, | ||
}], | ||
) | ||
|
||
asyncio.ensure_future(fetch(text_url)) | ||
event = await wait_for_event("network.beforeRequestSent") | ||
request = event["request"]["request"] | ||
|
||
with pytest.raises(error.InvalidArgumentException): | ||
await bidi_session.network.continue_request(request=request, | ||
method=value) | ||
|
||
|
||
# TODO: https://github.com/w3c/webdriver-bidi/issues/575 | ||
@pytest.mark.parametrize("value", ["", "GETT"]) | ||
async def test_params_method_invalid_value( | ||
bidi_session, value, setup_network_test, url, fetch, wait_for_event, | ||
add_intercept): | ||
request = await create_blocked_request(setup_network_test, url, add_intercept, fetch, wait_for_event) | ||
|
||
with pytest.raises(error.InvalidArgumentException): | ||
await bidi_session.network.continue_request(request=request, | ||
url=value) | ||
|
||
|
||
@pytest.mark.parametrize("protocol", ["http", "https"]) | ||
@pytest.mark.parametrize("value", [":invalid", "#invalid"]) | ||
async def test_params_url_invalid_value( | ||
bidi_session, protocol, value, setup_network_test, url, fetch, wait_for_event, | ||
add_intercept): | ||
request = await create_blocked_request(setup_network_test, url, add_intercept, fetch, wait_for_event) | ||
|
||
with pytest.raises(error.InvalidArgumentException): | ||
await bidi_session.network.continue_request(request=request, | ||
url=f"{protocol}://{value}") | ||
|
||
|
||
async def create_blocked_request(setup_network_test, url, add_intercept, fetch, wait_for_event): | ||
await setup_network_test(events=["network.beforeRequestSent"]) | ||
|
||
text_url = url(PAGE_EMPTY_TEXT) | ||
await add_intercept( | ||
phases=["beforeRequestSent"], | ||
url_patterns=[{ | ||
"type": "string", | ||
"pattern": text_url, | ||
}], | ||
) | ||
|
||
asyncio.ensure_future(fetch(text_url)) | ||
event = await wait_for_event("network.beforeRequestSent") | ||
request = event["request"]["request"] | ||
|
||
with pytest.raises(error.InvalidArgumentException): | ||
await bidi_session.network.continue_request(request=request, | ||
method=value) |