Skip to content
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

Merged
merged 3 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 23 additions & 0 deletions beacon/beacon-readablestream.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function assert_beacon(stream) {
Copy link
Contributor

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.

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");
51 changes: 51 additions & 0 deletions fetch/api/request/request-init-stream.any.js
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()");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await missing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because fetch never throws. Maybe we should make all tests asynchronous.

Copy link
Member Author

Choose a reason for hiding this comment

The 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");
23 changes: 23 additions & 0 deletions fetch/api/response/response-from-stream.any.js
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");
27 changes: 27 additions & 0 deletions xhr/send-data-readablestream.any.js
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");