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 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
3 changes: 3 additions & 0 deletions beacon/beacon-readablestream.window.js
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");
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";

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");
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");