Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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');
</script>
</body>