-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetch/XHR/Beacon: test locked/disturbed ReadableStream #12639
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function assert_beacon(stream) { | ||
assert_throws(new TypeError(), () => navigator.sendBeacon("...", stream)); | ||
} | ||
|
||
test(() => { | ||
const stream = new ReadableStream(); | ||
stream.getReader(); | ||
assert_beacon(stream); | ||
}, "sendBeacon() with a stream on which getReader() is called"); | ||
|
||
test(() => { | ||
const stream = new ReadableStream(); | ||
stream.getReader().read(); | ||
assert_beacon(stream); | ||
}, "sendBeacon() 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_beacon(stream); | ||
}, "sendBeacon() with a stream on which read() and releaseLock() are called"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// META: global=window,worker | ||
|
||
"use strict"; | ||
|
||
function assert_request(input, init) { | ||
assert_throws(new TypeError(), () => new Request(input, init), "new Request()"); | ||
assert_throws(new TypeError(), () => fetch(input, init), "fetch()"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. await missing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because fetch never throws. Maybe we should make all tests asynchronous. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh my, thanks for spotting that. |
||
} | ||
|
||
test(() => { | ||
const stream = new ReadableStream(); | ||
stream.getReader(); | ||
assert_request("...", { method:"POST", body: stream }); | ||
}, "Constructing a Request with a stream on which getReader() is called"); | ||
|
||
test(() => { | ||
const stream = new ReadableStream(); | ||
stream.getReader().read(); | ||
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(); | ||
assert_request("...", { method:"POST", body: stream }); | ||
}, "Constructing a Request with a stream on which read() and releaseLock() are called"); | ||
|
||
test(() => { | ||
const request = new Request("...", { method: "POST", body: "..." }); | ||
request.body.getReader(); | ||
assert_request(request); | ||
assert_class_string(new Request(request, { body: "..." }), "Request"); | ||
}, "Constructing a Request with a Request on which body.getReader() is called"); | ||
|
||
test(() => { | ||
const request = new Request("...", { method: "POST", body: "..." }); | ||
request.body.getReader().read(); | ||
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(); | ||
assert_request(request); | ||
assert_class_string(new Request(request, { body: "..." }), "Request"); | ||
}, "Constructing a Request with a Request on which read() and releaseLock() are called"); |
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"); |
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beacon with streams is never going to work because it's keepalive + ReadableStream which is rejected by another reason.