@@ -65,6 +65,26 @@ async def on_event(method, data):
65
65
remove_listener ()
66
66
67
67
68
+ @pytest .mark .asyncio
69
+ async def test_aborted_request (
70
+ wait_for_event ,
71
+ wait_for_future_safe ,
72
+ setup_network_test ,
73
+ url ,
74
+ fetch ,
75
+ ):
76
+ network_events = await setup_network_test (events = [FETCH_ERROR_EVENT ])
77
+ events = network_events [FETCH_ERROR_EVENT ]
78
+
79
+ # Prepare a slow url
80
+ slow_url = url (
81
+ "/webdriver/tests/bidi/browsing_context/support/empty.txt?pipe=trickle(d10)"
82
+ )
83
+ on_fetch_error = wait_for_event (FETCH_ERROR_EVENT )
84
+ asyncio .ensure_future (fetch (PAGE_INVALID_URL , timeout_in_seconds = 0 ))
85
+ fetch_error_event = await wait_for_future_safe (on_fetch_error )
86
+
87
+
68
88
@pytest .mark .asyncio
69
89
async def test_iframe_load (
70
90
bidi_session ,
@@ -140,14 +160,15 @@ async def test_navigation_id(
140
160
("GET" , False ),
141
161
("HEAD" , False ),
142
162
("POST" , False ),
143
- ("OPTIONS" , False ),
163
+ ("OPTIONS" , True ),
144
164
("DELETE" , True ),
145
165
("PATCH" , True ),
146
166
("PUT" , True ),
147
167
],
148
168
)
149
169
@pytest .mark .asyncio
150
170
async def test_request_method (
171
+ bidi_session ,
151
172
wait_for_event ,
152
173
wait_for_future_safe ,
153
174
fetch ,
@@ -158,23 +179,30 @@ async def test_request_method(
158
179
network_events = await setup_network_test (events = [FETCH_ERROR_EVENT ])
159
180
events = network_events [FETCH_ERROR_EVENT ]
160
181
161
- on_fetch_error = wait_for_event (FETCH_ERROR_EVENT )
162
182
asyncio .ensure_future (fetch (PAGE_INVALID_URL , method = method ))
163
- await wait_for_future_safe (on_fetch_error )
164
183
165
- assert len (events ) == 1
166
-
167
- # Requests which might update the server will fail on the CORS preflight
184
+ # Requests which might update the server will also fail the CORS preflight
168
185
# request which uses the OPTIONS method.
186
+ expected_events = 2 if has_preflight else 1
187
+
188
+ wait = AsyncPoll (bidi_session , timeout = 2 )
189
+ await wait .until (lambda _ : len (events ) >= expected_events )
190
+ assert len (events ) == expected_events
191
+
192
+ # TODO: At the moment the event order for preflight requests differs between
193
+ # Chrome and Firefox so we cannot assume the order of fetchError events.
194
+ # See https://bugzilla.mozilla.org/show_bug.cgi?id=1879402.
195
+
196
+ # Check that fetch_error events have the expected methods.
197
+ assert method in [e ["request" ]["method" ] for e in events ]
169
198
if has_preflight :
170
- method = "OPTIONS"
199
+ assert "OPTIONS" in [ e [ "request" ][ "method" ] for e in events ]
171
200
172
- expected_request = {"method" : method , "url" : PAGE_INVALID_URL }
173
- assert_fetch_error_event (
174
- events [0 ],
175
- expected_request = expected_request ,
176
- redirect_count = 0 ,
177
- )
201
+ for event in events :
202
+ assert_fetch_error_event (
203
+ event ,
204
+ expected_request = {"url" : PAGE_INVALID_URL },
205
+ )
178
206
179
207
180
208
@pytest .mark .asyncio
0 commit comments