Skip to content

Commit 6b817d4

Browse files
authored
Add FetchEvent test that should reject none Uint8Array ReadableStream
For whatwg/fetch#1199.
1 parent 73722db commit 6b817d4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

service-workers/service-worker/fetch-event.https.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,32 @@
509509
'the network fallback request should include the request body');
510510
}, 'FetchEvent#body is a ReadableStream and is passed to network fallback');
511511

512+
// Test that the request body is sent to network upon network fallback,
513+
// for a ReadableStream body.
514+
promise_test(async t => {
515+
const rs = new ReadableStream({start(c) {
516+
c.enqueue('i a');
517+
c.enqueue('m the request');
518+
t.step_timeout(t.step_func(() => {
519+
c.enqueue(' body');
520+
c.close();
521+
}, 10));
522+
}});
523+
// Set page_url to "?ignore" so the service worker falls back to network
524+
// for the main resource request, and add a suffix to avoid colliding
525+
// with other tests.
526+
const page_url = 'resources/?ignore-for-request-body-fallback-string';
527+
const frame = await with_iframe(page_url);
528+
t.add_cleanup(() => { frame.remove(); });
529+
// Add "?ignore" so the service worker falls back to echo-content.py.
530+
const echo_url = '/fetch/api/resources/echo-content.py?ignore';
531+
const w = frame.contentWindow;
532+
await promise_rejects_js(t, w.TypeError, w.fetch(echo_url, {
533+
method: 'POST',
534+
body: rs
535+
}));
536+
}, 'FetchEvent#body is a none Uint8Array ReadableStream and is passed to a service worker');
537+
512538
// Test that the request body is sent to network upon network fallback even when
513539
// the request body is used in the service worker, for a string body.
514540
promise_test(async t => {

0 commit comments

Comments
 (0)