diff --git a/service-workers/service-worker/tentative/static-router/resources/direct.py b/service-workers/service-worker/tentative/static-router/resources/direct.py index c2bcfce67c5aaf..d30d41b44e27a8 100644 --- a/service-workers/service-worker/tentative/static-router/resources/direct.py +++ b/service-workers/service-worker/tentative/static-router/resources/direct.py @@ -4,4 +4,8 @@ def main(request, response): if 'server_slow' in request.url_parts.query: time.sleep(0.2) + if 'server_no_content' in request.url_parts.query: + return 204, [(b'Content-Type', b'text/plain')], u'Network with %s request' % request.method + if 'server_not_found' in request.url_parts.query: + return 404, [(b'Content-Type', b'text/plain')], u'Not Found' return 200, [(b'Content-Type', b'text/plain')], u'Network with %s request' % request.method diff --git a/service-workers/service-worker/tentative/static-router/static-router-race-network-and-fetch-handler.https.html b/service-workers/service-worker/tentative/static-router/static-router-race-network-and-fetch-handler.https.html index de31f6c53ff098..0dad64ad992343 100644 --- a/service-workers/service-worker/tentative/static-router/static-router-race-network-and-fetch-handler.https.html +++ b/service-workers/service-worker/tentative/static-router/static-router-race-network-and-fetch-handler.https.html @@ -61,5 +61,31 @@ const {requests} = await get_info_from_worker(worker); assert_equals(requests.length, 2); }, 'Subresource load matched the rule with race-network-and-fetch-handler source, and the server reseponse is faster than the fetch handler'); + +promise_test(async t => { + const rnd = randomString(); + const worker = await registerAndActivate(t, ROUTER_KEY, SW_SRC); + const iframe = await createIframe(t, FRAME_SRC); + // Expect the response from the network request. + const response = await iframe.contentWindow.fetch(`?nonce=${rnd}&sw_slow&server_no_content`); + assert_equals(response.status, 204); + // Ensure the fetch handler is also executed. + const {requests} = await get_info_from_worker(worker); + assert_equals(requests.length, 2); +}, 'Subresource load matched the rule with race-network-and-fetch-handler source, and the server reseponse with 204 response is faster than the fetch handler'); + + +promise_test(async t => { + const rnd = randomString(); + const worker = await registerAndActivate(t, ROUTER_KEY, SW_SRC); + const iframe = await createIframe(t, FRAME_SRC); + const response = await iframe.contentWindow.fetch(`?nonce=${rnd}&sw_slow&server_not_found`); + // Expect the response from the network request was faster, but the result was 404. + // So, the fetch handler result will be used instead. + assert_equals(response.status, 200); + assert_equals(await response.text(), rnd); + const {requests} = await get_info_from_worker(worker); + assert_equals(requests.length, 2); +}, 'Subresource load matched the rule with race-network-and-fetch-handler source, and the server reseponse is faster than the fetch handler, but not found');