Bug 1826198 - [wdspec] Add wdspec tests for network.authRequired r=webdriver-reviewers,whimboo

Depends on D189516

Differential Revision: https://phabricator.services.mozilla.com/D189517
This commit is contained in:
Julian Descottes 2023-10-25 15:39:24 +00:00
Родитель bc8b00bb43
Коммит 4658db41b9
3 изменённых файлов: 101 добавлений и 6 удалений

Просмотреть файл

Просмотреть файл

@ -0,0 +1,95 @@
import asyncio
import pytest
from tests.support.sync import AsyncPoll
from .. import assert_response_event
PAGE_EMPTY_HTML = "/webdriver/tests/bidi/network/support/empty.html"
AUTH_REQUIRED_EVENT = "network.authRequired"
@pytest.mark.asyncio
async def test_subscribe_status(
bidi_session, new_tab, subscribe_events, wait_for_event, url
):
await subscribe_events(events=[AUTH_REQUIRED_EVENT])
# Track all received network.authRequired events in the events array.
events = []
async def on_event(method, data):
events.append(data)
remove_listener = bidi_session.add_event_listener(AUTH_REQUIRED_EVENT, on_event)
auth_url = url(
"/webdriver/tests/support/http_handlers/authentication.py?realm=testrealm"
)
on_auth_required = wait_for_event(AUTH_REQUIRED_EVENT)
# navigate using wait="none" as other wait conditions would hang because of
# the authentication prompt.
await bidi_session.browsing_context.navigate(
context=new_tab["context"],
url=auth_url,
wait="none",
)
await on_auth_required
assert len(events) == 1
expected_request = {"method": "GET", "url": auth_url}
expected_response = {
"url": auth_url,
"authChallenges": [
({"scheme": "Basic", "realm": "testrealm"}),
],
}
assert_response_event(
events[0],
expected_request=expected_request,
expected_response=expected_response,
redirect_count=0,
)
await bidi_session.session.unsubscribe(events=[AUTH_REQUIRED_EVENT])
# Navigate to authentication.py again and check no new event is received.
await bidi_session.browsing_context.navigate(
context=new_tab["context"],
url=auth_url,
wait="none",
)
await asyncio.sleep(0.5)
assert len(events) == 1
remove_listener()
@pytest.mark.asyncio
async def test_no_authentication(
bidi_session, new_tab, subscribe_events, wait_for_event, url
):
await subscribe_events(events=[AUTH_REQUIRED_EVENT])
# Track all received network.authRequired events in the events array.
events = []
async def on_event(method, data):
events.append(data)
remove_listener = bidi_session.add_event_listener(AUTH_REQUIRED_EVENT, on_event)
# Navigate to a page which should not trigger any authentication.
await bidi_session.browsing_context.navigate(
context=new_tab["context"],
url=url(PAGE_EMPTY_HTML),
wait="complete",
)
assert len(events) == 0
remove_listener()

Просмотреть файл

@ -209,7 +209,7 @@ async def test_response_mime_type_file(
@pytest.mark.asyncio
async def test_www_authenticate(
bidi_session, new_tab, url, wait_for_event, setup_network_test
bidi_session, url, fetch, new_tab, wait_for_event, setup_network_test
):
auth_url = url(
f"/webdriver/tests/support/http_handlers/authentication.py?realm=testrealm"
@ -219,11 +219,11 @@ async def test_www_authenticate(
events = network_events[RESPONSE_STARTED_EVENT]
on_response_started = wait_for_event(RESPONSE_STARTED_EVENT)
await bidi_session.browsing_context.navigate(
context=new_tab["context"],
url=auth_url,
wait="none",
)
# Note that here we explicitly do not navigate to the auth_url and instead
# simply do a fetch, because otherwise Firefox fails to cleanly cancel the
# authentication prompt on test teardown.
asyncio.ensure_future(fetch(auth_url, context=new_tab, method="GET"))
await on_response_started