Skip to content

Commit

Permalink
[wdspec] Add test for network events with CORS preflight requests
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D216542

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1907847
gecko-commit: 3a5d49bcfa154ba26e325dc6f3722df2c9ce7067
gecko-reviewers: webdriver-reviewers, Sasha
  • Loading branch information
juliandescottes authored and sadym-chromium committed Jul 18, 2024
1 parent afb0bde commit d3bd9a6
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions webdriver/tests/bidi/network/combined/network_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,85 @@
)


@pytest.mark.asyncio
async def test_cors_preflight_request(bidi_session, url, fetch, setup_network_test):
network_events = await setup_network_test(
events=[
BEFORE_REQUEST_SENT_EVENT,
RESPONSE_COMPLETED_EVENT,
RESPONSE_STARTED_EVENT,
],
test_url=url(PAGE_EMPTY_HTML),
)

# Track all received network.beforeRequestSent, responseStarted &
# responseCompleted events in the events array.
events = []

async def on_event(method, data):
events.append(data)

remove_before_request_sent_listener = bidi_session.add_event_listener(
BEFORE_REQUEST_SENT_EVENT, on_event
)
remove_response_completed_listener = bidi_session.add_event_listener(
RESPONSE_COMPLETED_EVENT, on_event
)
remove_response_started_listener = bidi_session.add_event_listener(
RESPONSE_STARTED_EVENT, on_event
)

fetch_url = url(
"/webdriver/tests/support/http_handlers/headers.py?"
+ "header=Access-Control-Allow-Origin:*&header=Access-Control-Allow-Headers:Content-Type",
domain="alt",
)
asyncio.ensure_future(
fetch(fetch_url, method="GET", headers={"Content-Type": "custom/type"})
)

wait = AsyncPoll(bidi_session, timeout=2)
await wait.until(lambda _: len(events) >= 6)

# Check that all events for the CORS preflight request are received before
# receiving events for the actual request

# Preflight beforeRequestSent
assert_before_request_sent_event(
events[0],
expected_request={"method": "OPTIONS", "url": fetch_url},
)
# Preflight responseStarted
assert_response_event(
events[1],
expected_request={"method": "OPTIONS", "url": fetch_url},
)
# Preflight responseCompleted
assert_response_event(
events[2],
expected_request={"method": "OPTIONS", "url": fetch_url},
)
# Actual request beforeRequestSent
assert_before_request_sent_event(
events[3],
expected_request={"method": "GET", "url": fetch_url},
)
# Actual request responseStarted
assert_response_event(
events[4],
expected_request={"method": "GET", "url": fetch_url},
)
# Actual request responseCompleted
assert_response_event(
events[5],
expected_request={"method": "GET", "url": fetch_url},
)

remove_before_request_sent_listener()
remove_response_completed_listener()
remove_response_started_listener()


@pytest.mark.asyncio
async def test_iframe_navigation_request(
bidi_session,
Expand Down

0 comments on commit d3bd9a6

Please sign in to comment.