-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fetch/XHR/Beacon: test locked/disturbed ReadableStream
See whatwg/fetch#801 for context.
- Loading branch information
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test(() => { | ||
assert_throws(new TypeError(), () => navigator.sendBeacon("...", new ReadableStream())); | ||
}, "sendBeacon() with a stream does not work due to the keepalive flag being set"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// META: global=window,worker | ||
|
||
"use strict"; | ||
|
||
async function assert_request(input, init) { | ||
assert_throws(new TypeError(), () => new Request(input, init), "new Request()"); | ||
assert_throws(new TypeError(), async () => await fetch(input, init), "fetch()"); | ||
} | ||
|
||
promise_test(async () => { | ||
const stream = new ReadableStream(); | ||
stream.getReader(); | ||
await assert_request("...", { method:"POST", body: stream }); | ||
}, "Constructing a Request with a stream on which getReader() is called"); | ||
|
||
promise_test(async () => { | ||
const stream = new ReadableStream(); | ||
stream.getReader().read(); | ||
await assert_request("...", { method:"POST", body: stream }); | ||
}, "Constructing a Request with a stream on which read() is called"); | ||
|
||
promise_test(async () => { | ||
const stream = new ReadableStream({ pull: c => c.enqueue(new Uint8Array()) }), | ||
reader = stream.getReader(); | ||
await reader.read(); | ||
reader.releaseLock(); | ||
await assert_request("...", { method:"POST", body: stream }); | ||
}, "Constructing a Request with a stream on which read() and releaseLock() are called"); | ||
|
||
promise_test(async () => { | ||
const request = new Request("...", { method: "POST", body: "..." }); | ||
request.body.getReader(); | ||
await assert_request(request); | ||
assert_class_string(new Request(request, { body: "..." }), "Request"); | ||
}, "Constructing a Request with a Request on which body.getReader() is called"); | ||
|
||
promise_test(async () => { | ||
const request = new Request("...", { method: "POST", body: "..." }); | ||
request.body.getReader().read(); | ||
await assert_request(request); | ||
assert_class_string(new Request(request, { body: "..." }), "Request"); | ||
}, "Constructing a Request with a Request on which body.getReader().read() is called"); | ||
|
||
promise_test(async () => { | ||
const request = new Request("...", { method: "POST", body: "..." }), | ||
reader = request.body.getReader(); | ||
await reader.read(); | ||
reader.releaseLock(); | ||
await assert_request(request); | ||
assert_class_string(new Request(request, { body: "..." }), "Request"); | ||
}, "Constructing a Request with a Request on which read() and releaseLock() are called"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// META: global=window,worker | ||
|
||
"use strict"; | ||
|
||
test(() => { | ||
const stream = new ReadableStream(); | ||
stream.getReader(); | ||
assert_throws(new TypeError(), () => new Response(stream)); | ||
}, "Constructing a Response with a stream on which getReader() is called"); | ||
|
||
test(() => { | ||
const stream = new ReadableStream(); | ||
stream.getReader().read(); | ||
assert_throws(new TypeError(), () => new Response(stream)); | ||
}, "Constructing a Response with a stream on which read() is called"); | ||
|
||
promise_test(async () => { | ||
const stream = new ReadableStream({ pull: c => c.enqueue(new Uint8Array()) }), | ||
reader = stream.getReader(); | ||
await reader.read(); | ||
reader.releaseLock(); | ||
assert_throws(new TypeError(), () => new Response(stream)); | ||
}, "Constructing a Response with a stream on which read() and releaseLock() are called"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// META: global=window,dedicatedworker,sharedworker | ||
|
||
function assert_xhr(stream) { | ||
const client = new XMLHttpRequest(); | ||
client.open("POST", "..."); | ||
assert_throws(new TypeError(), () => client.send(stream)); | ||
} | ||
|
||
test(() => { | ||
const stream = new ReadableStream(); | ||
stream.getReader(); | ||
assert_xhr(stream); | ||
}, "XMLHttpRequest: send() with a stream on which getReader() is called"); | ||
|
||
test(() => { | ||
const stream = new ReadableStream(); | ||
stream.getReader().read(); | ||
assert_xhr(stream); | ||
}, "XMLHttpRequest: send() with a stream on which read() is called"); | ||
|
||
promise_test(async () => { | ||
const stream = new ReadableStream({ pull: c => c.enqueue(new Uint8Array()) }), | ||
reader = stream.getReader(); | ||
await reader.read(); | ||
reader.releaseLock(); | ||
assert_xhr(stream); | ||
}, "XMLHttpRequest: send() with a stream on which read() and releaseLock() are called"); |