Bug 1805176 - [wdspec] Add tests for network events with data URLs. r=webdriver-reviewers,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D213996
This commit is contained in:
Alexandra Borovova 2024-06-21 10:55:06 +00:00
parent 883403cbf3
commit 7f72bf8b3e
7 changed files with 231 additions and 2 deletions

View File

@ -0,0 +1,8 @@
[before_request_sent.py]
[test_fetch_data_url[html\]]
bug: 1903060
expected: FAIL
[test_fetch_data_url[image\]]
bug: 1903060
expected: FAIL

View File

@ -1,3 +1,8 @@
[response_completed.py]
expected:
if (processor == "x86") and not debug: [OK, TIMEOUT]
[test_fetch_data_url[html\]]
bug: 1903060
expected: FAIL
[test_fetch_data_url[image\]]
bug: 1903060
expected: FAIL

View File

@ -0,0 +1,8 @@
[response_started.py]
[test_fetch_data_url[html\]]
bug: 1903060
expected: FAIL
[test_fetch_data_url[image\]]
bug: 1903060
expected: FAIL

View File

@ -318,6 +318,8 @@ HTTP_STATUS_AND_STATUS_TEXT = [
(505, "HTTP Version Not Supported"),
]
PAGE_DATA_URL_HTML = "data:text/html,<div>foo</div>"
PAGE_DATA_URL_IMAGE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlPM0jRW/QAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII="
PAGE_EMPTY_HTML = "/webdriver/tests/bidi/network/support/empty.html"
PAGE_EMPTY_IMAGE = "/webdriver/tests/bidi/network/support/empty.png"
PAGE_EMPTY_SCRIPT = "/webdriver/tests/bidi/network/support/empty.js"

View File

@ -8,6 +8,8 @@ from tests.support.sync import AsyncPoll
from .. import (
assert_before_request_sent_event,
PAGE_DATA_URL_HTML,
PAGE_DATA_URL_IMAGE,
PAGE_EMPTY_HTML,
PAGE_EMPTY_TEXT,
PAGE_REDIRECT_HTTP_EQUIV,
@ -459,3 +461,55 @@ async def test_url_with_fragment(
expected_request={"method": "GET", "url": fragment_url},
redirect_count=0,
)
@pytest.mark.parametrize(
"page_url",
[PAGE_DATA_URL_HTML, PAGE_DATA_URL_IMAGE],
ids=["html", "image"],
)
@pytest.mark.asyncio
async def test_navigate_data_url(
bidi_session, top_context, wait_for_event, wait_for_future_safe, setup_network_test, page_url
):
network_events = await setup_network_test(events=[BEFORE_REQUEST_SENT_EVENT])
events = network_events[BEFORE_REQUEST_SENT_EVENT]
on_before_request_sent = wait_for_event(BEFORE_REQUEST_SENT_EVENT)
await bidi_session.browsing_context.navigate(
context=top_context["context"], url=page_url, wait="complete"
)
await wait_for_future_safe(on_before_request_sent)
assert len(events) == 1
assert_before_request_sent_event(
events[0],
expected_request={"method": "GET", "url": page_url},
redirect_count=0,
)
@pytest.mark.parametrize(
"fetch_url",
[PAGE_DATA_URL_HTML, PAGE_DATA_URL_IMAGE],
ids=["html", "image"],
)
@pytest.mark.asyncio
async def test_fetch_data_url(
wait_for_event, wait_for_future_safe, fetch, setup_network_test, fetch_url
):
network_events = await setup_network_test(events=[BEFORE_REQUEST_SENT_EVENT])
events = network_events[BEFORE_REQUEST_SENT_EVENT]
on_before_request_sent = wait_for_event(BEFORE_REQUEST_SENT_EVENT)
await fetch(fetch_url, method="GET")
await wait_for_future_safe(on_before_request_sent)
assert len(events) == 1
assert_before_request_sent_event(
events[0],
expected_request={"method": "GET", "url": fetch_url},
redirect_count=0,
)

View File

@ -10,6 +10,8 @@ from tests.support.sync import AsyncPoll
from .. import (
assert_response_event,
HTTP_STATUS_AND_STATUS_TEXT,
PAGE_DATA_URL_HTML,
PAGE_DATA_URL_IMAGE,
PAGE_EMPTY_HTML,
PAGE_EMPTY_IMAGE,
PAGE_EMPTY_SCRIPT,
@ -442,3 +444,77 @@ async def test_url_with_fragment(
expected_response={"url": fragment_url},
redirect_count=0,
)
@pytest.mark.parametrize(
"page_url, mimeType",
[(PAGE_DATA_URL_HTML, "text/html"), (PAGE_DATA_URL_IMAGE, "image/png")],
ids=["html", "image"],
)
@pytest.mark.asyncio
async def test_navigate_data_url(
bidi_session, top_context, wait_for_event, wait_for_future_safe, setup_network_test, page_url, mimeType
):
network_events = await setup_network_test(events=[RESPONSE_COMPLETED_EVENT])
events = network_events[RESPONSE_COMPLETED_EVENT]
on_response_completed = wait_for_event(RESPONSE_COMPLETED_EVENT)
await bidi_session.browsing_context.navigate(
context=top_context["context"], url=page_url, wait="complete"
)
await wait_for_future_safe(on_response_completed)
assert len(events) == 1
assert_response_event(
events[0],
expected_request={"method": "GET", "url": page_url},
expected_response={
"headers": [{
"name": "Content-Type",
"value": {"type": "string", "value": mimeType}
}],
"mimeType": mimeType,
"protocol": "data",
"status": 200,
"statusText": "OK",
"url": page_url,
},
redirect_count=0,
)
@pytest.mark.parametrize(
"fetch_url, mimeType",
[(PAGE_DATA_URL_HTML, "text/html"), (PAGE_DATA_URL_IMAGE, "image/png")],
ids=["html", "image"],
)
@pytest.mark.asyncio
async def test_fetch_data_url(
wait_for_event, wait_for_future_safe, fetch, setup_network_test, fetch_url, mimeType
):
network_events = await setup_network_test(events=[RESPONSE_COMPLETED_EVENT])
events = network_events[RESPONSE_COMPLETED_EVENT]
on_before_request_sent = wait_for_event(RESPONSE_COMPLETED_EVENT)
await fetch(fetch_url, method="GET")
await wait_for_future_safe(on_before_request_sent)
assert len(events) == 1
assert_response_event(
events[0],
expected_request={"method": "GET", "url": fetch_url},
expected_response={
"headers": [{
"name": "Content-Type",
"value": {"type": "string", "value": mimeType}
}],
"mimeType": mimeType,
"protocol": "data",
"status": 200,
"statusText": "OK",
"url": fetch_url,
},
redirect_count=0,
)

View File

@ -9,6 +9,8 @@ from tests.support.sync import AsyncPoll
from .. import (
assert_response_event,
HTTP_STATUS_AND_STATUS_TEXT,
PAGE_DATA_URL_HTML,
PAGE_DATA_URL_IMAGE,
PAGE_EMPTY_HTML,
PAGE_EMPTY_IMAGE,
PAGE_EMPTY_SCRIPT,
@ -411,3 +413,77 @@ async def test_url_with_fragment(
expected_response={"url": fragment_url},
redirect_count=0,
)
@pytest.mark.parametrize(
"page_url, mimeType",
[(PAGE_DATA_URL_HTML, "text/html"), (PAGE_DATA_URL_IMAGE, "image/png")],
ids=["html", "image"],
)
@pytest.mark.asyncio
async def test_navigate_data_url(
bidi_session, top_context, wait_for_event, wait_for_future_safe, setup_network_test, page_url, mimeType
):
network_events = await setup_network_test(events=[RESPONSE_STARTED_EVENT])
events = network_events[RESPONSE_STARTED_EVENT]
on_response_started = wait_for_event(RESPONSE_STARTED_EVENT)
await bidi_session.browsing_context.navigate(
context=top_context["context"], url=page_url, wait="complete"
)
await wait_for_future_safe(on_response_started)
assert len(events) == 1
assert_response_event(
events[0],
expected_request={"method": "GET", "url": page_url},
expected_response={
"headers": [{
"name": "Content-Type",
"value": {"type": "string", "value": mimeType}
}],
"mimeType": mimeType,
"protocol": "data",
"status": 200,
"statusText": "OK",
"url": page_url,
},
redirect_count=0,
)
@pytest.mark.parametrize(
"fetch_url, mimeType",
[(PAGE_DATA_URL_HTML, "text/html"), (PAGE_DATA_URL_IMAGE, "image/png")],
ids=["html", "image"],
)
@pytest.mark.asyncio
async def test_fetch_data_url(
wait_for_event, wait_for_future_safe, fetch, setup_network_test, fetch_url, mimeType
):
network_events = await setup_network_test(events=[RESPONSE_STARTED_EVENT])
events = network_events[RESPONSE_STARTED_EVENT]
on_response_started = wait_for_event(RESPONSE_STARTED_EVENT)
await fetch(fetch_url, method="GET")
await wait_for_future_safe(on_response_started)
assert len(events) == 1
assert_response_event(
events[0],
expected_request={"method": "GET", "url": fetch_url},
expected_response={
"headers": [{
"name": "Content-Type",
"value": {"type": "string", "value": mimeType}
}],
"mimeType": mimeType,
"protocol": "data",
"status": 200,
"statusText": "OK",
"url": fetch_url,
},
redirect_count=0,
)