Skip to content

Commit 87be5d0

Browse files
Bug 1988681 - [wdspec] avoid race conditions with requests blocked in responseStarted phase r=webdriver-reviewers,whimboo
Differential Revision: https://phabricator.services.mozilla.com/D264909
1 parent c64e31f commit 87be5d0

File tree

8 files changed

+26
-47
lines changed

8 files changed

+26
-47
lines changed

testing/web-platform/meta/webdriver/tests/bidi/network/add_intercept/__dir__.ini

Lines changed: 0 additions & 2 deletions
This file was deleted.

testing/web-platform/meta/webdriver/tests/bidi/network/add_intercept/add_intercept.py.ini

Lines changed: 0 additions & 6 deletions
This file was deleted.

testing/web-platform/meta/webdriver/tests/bidi/network/add_intercept/contexts.py.ini

Lines changed: 0 additions & 12 deletions
This file was deleted.

testing/web-platform/meta/webdriver/tests/bidi/network/add_intercept/phases.py.ini

Lines changed: 0 additions & 12 deletions
This file was deleted.

testing/web-platform/tests/webdriver/tests/bidi/network/add_intercept/add_intercept.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import random
23
import uuid
34

45
import pytest
@@ -33,7 +34,7 @@ async def test_other_url(
3334
)
3435

3536
# Add an intercept.
36-
text_url = url(PAGE_EMPTY_TEXT)
37+
text_url = f"{url(PAGE_EMPTY_TEXT)}?nocache={random.random()}"
3738
await add_intercept(
3839
phases=[phase],
3940
url_patterns=[{"type": "string", "pattern": text_url}],
@@ -75,7 +76,7 @@ async def test_two_intercepts(
7576
)
7677

7778
# Add a string intercept to catch requests to PAGE_EMPTY_TEXT.
78-
text_url = url(PAGE_EMPTY_TEXT)
79+
text_url = f"{url(PAGE_EMPTY_TEXT)}?nocache={random.random()}"
7980
string_intercept = await add_intercept(
8081
phases=["beforeRequestSent"],
8182
url_patterns=[{"type": "string", "pattern": text_url}],
@@ -96,7 +97,7 @@ async def test_two_intercepts(
9697
)
9798

9899
# Perform a request to PAGE_OTHER_TEXT, which should only match one intercept
99-
other_url = url(PAGE_OTHER_TEXT)
100+
other_url = f"{url(PAGE_OTHER_TEXT)}?nocache={random.random()}"
100101

101102
on_network_event = wait_for_event(BEFORE_REQUEST_SENT_EVENT)
102103
asyncio.ensure_future(fetch(other_url))

testing/web-platform/tests/webdriver/tests/bidi/network/add_intercept/contexts.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import random
23

34
import pytest
45
from webdriver.bidi.modules.script import ScriptEvaluateResultException
@@ -52,7 +53,7 @@ async def test_frame_context(
5253
frame = contexts[0]["children"][0]
5354

5455
# Add an intercept.
55-
text_url = url(PAGE_EMPTY_TEXT)
56+
text_url = f"{url(PAGE_EMPTY_TEXT)}?nocache={random.random()}"
5657
await add_intercept(
5758
phases=[phase],
5859
url_patterns=[{"type": "string", "pattern": text_url}],
@@ -97,13 +98,20 @@ async def test_other_context(
9798
)
9899

99100
# Add an intercept.
100-
text_url = url(PAGE_EMPTY_TEXT)
101+
text_url = f"{url(PAGE_EMPTY_TEXT)}?nocache={random.random()}"
102+
103+
# Note: generate two distinct URLs matching the pattern to avoid cases
104+
# where the blocked response of the first request is reused for the second
105+
# request on Firefox (https://bugzilla.mozilla.org/show_bug.cgi?id=1966494).
106+
text_url_other = f"{url(PAGE_EMPTY_TEXT)}?othercontext&nocache={random.random()}"
107+
101108
await add_intercept(
102109
phases=[phase],
103-
url_patterns=[{"type": "string", "pattern": text_url}],
110+
# Use a pattern url_pattern to match both URLs using different search
111+
# parameters.
112+
url_patterns=[{"type": "pattern", "pathname": PAGE_EMPTY_TEXT}],
104113
)
105114

106-
107115
# Request to new_tab should be blocked.
108116
[event_name, assert_network_event] = PHASE_TO_EVENT_MAP[phase]
109117
on_network_event = wait_for_event(event_name)
@@ -113,7 +121,7 @@ async def test_other_context(
113121

114122
# Request to other_context should not be blocked because we are not
115123
# subscribed to network events. Wait for fetch to resolve successfully.
116-
await asyncio.ensure_future(fetch(text_url, context=other_context))
124+
await asyncio.ensure_future(fetch(text_url_other, context=other_context))
117125

118126

119127
@pytest.mark.asyncio
@@ -144,7 +152,7 @@ async def test_other_context_with_event_subscription(
144152
)
145153

146154
# Add an intercept to new_tab only.
147-
text_url = url(PAGE_EMPTY_TEXT)
155+
text_url = f"{url(PAGE_EMPTY_TEXT)}?nocache={random.random()}"
148156
await add_intercept(
149157
phases=["beforeRequestSent"],
150158
url_patterns=[{"type": "string", "pattern": text_url}],
@@ -193,7 +201,7 @@ async def test_two_contexts_same_intercept(
193201
)
194202

195203
# Add an intercept to both contexts
196-
text_url = url(PAGE_EMPTY_TEXT)
204+
text_url = f"{url(PAGE_EMPTY_TEXT)}?nocache={random.random()}"
197205
intercept = await add_intercept(
198206
phases=["beforeRequestSent"],
199207
url_patterns=[{"type": "string", "pattern": text_url}],
@@ -242,7 +250,7 @@ async def test_two_contexts_global_intercept(
242250
)
243251

244252
# Add an intercept for new_tab and a global intercept.
245-
text_url = url(PAGE_EMPTY_TEXT)
253+
text_url = f"{url(PAGE_EMPTY_TEXT)}?nocache={random.random()}"
246254
context_intercept = await add_intercept(
247255
phases=["beforeRequestSent"],
248256
url_patterns=[{"type": "string", "pattern": text_url}],

testing/web-platform/tests/webdriver/tests/bidi/network/add_intercept/phase_auth_required.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import random
23

34
import asyncio
45

@@ -44,7 +45,7 @@ async def test_basic_authentication(
4445
auth_required_events = network_events[AUTH_REQUIRED_EVENT]
4546
response_completed_events = network_events[RESPONSE_COMPLETED_EVENT]
4647

47-
auth_url = url("/webdriver/tests/support/http_handlers/authentication.py")
48+
auth_url = url(f"/webdriver/tests/support/http_handlers/authentication.py?nocache={random.random()}")
4849
intercept = await add_intercept(
4950
phases=["authRequired"],
5051
url_patterns=[{"type": "string", "pattern": auth_url}],
@@ -105,7 +106,7 @@ async def test_no_authentication(
105106
auth_required_events = network_events[AUTH_REQUIRED_EVENT]
106107
response_completed_events = network_events[RESPONSE_COMPLETED_EVENT]
107108

108-
text_url = url(PAGE_EMPTY_TEXT)
109+
text_url = f"{url(PAGE_EMPTY_TEXT)}?nocache={random.random()}"
109110
intercept = await add_intercept(
110111
phases=["authRequired"],
111112
url_patterns=[{"type": "string", "pattern": text_url}],

testing/web-platform/tests/webdriver/tests/bidi/network/add_intercept/phases.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import random
23
from webdriver.bidi.modules.script import ScriptEvaluateResultException
34

45
from .. import (
@@ -43,7 +44,7 @@ async def test_request_response_phases(
4344
response_started_events = network_events[RESPONSE_STARTED_EVENT]
4445
response_completed_events = network_events[RESPONSE_COMPLETED_EVENT]
4546

46-
text_url = url(PAGE_EMPTY_TEXT)
47+
text_url = f"{url(PAGE_EMPTY_TEXT)}?nocache={random.random()}"
4748
intercept = await add_intercept(
4849
phases=phases,
4950
url_patterns=[{"type": "string", "pattern": text_url}],
@@ -111,7 +112,7 @@ async def test_not_listening_to_phase_event(
111112
await setup_network_test(events=events)
112113

113114
# Add an intercept without listening to the corresponding network event
114-
text_url = url(PAGE_EMPTY_TEXT)
115+
text_url = f"{url(PAGE_EMPTY_TEXT)}?nocache={random.random()}"
115116
await add_intercept(
116117
phases=[phase],
117118
url_patterns=[{"type": "string", "pattern": text_url}],

0 commit comments

Comments
 (0)