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: improve ReadableStream upload test #21718

Merged
merged 2 commits into from
Feb 11, 2020
Merged
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
30 changes: 16 additions & 14 deletions fetch/api/basic/request-upload.any.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// META: script=../resources/utils.js

function testUpload(desc, url, method, createBody, expectedBody) {
var requestInit = {"method": method}
const requestInit = {"method": method}
promise_test(function(test){
let body = createBody();
if (body)
const body = createBody();
if (body) {
requestInit["body"] = body;
}
return fetch(url, requestInit).then(function(resp) {
return resp.text().then((text)=> {
assert_equals(text, expectedBody);
Expand All @@ -16,15 +17,16 @@ function testUpload(desc, url, method, createBody, expectedBody) {

function testUploadFailure(desc, url, method, createBody) {
const requestInit = {"method": method};
promise_test(test => {
let body = createBody();
if (body)
promise_test(t => {
const body = createBody();
if (body) {
requestInit["body"] = body;
return promise_rejects(new TypeError(), fetch(url, requestInit));
}
return promise_rejects_js(t, TypeError, fetch(url, requestInit));
}, desc);
}

var url = RESOURCES_DIR + "echo-content.py"
const url = RESOURCES_DIR + "echo-content.py"

testUpload("Fetch with PUT with body", url,
"PUT",
Expand Down Expand Up @@ -73,7 +75,7 @@ testUpload("Fetch with POST with Blob body with mime type", url,
testUpload("Fetch with POST with ReadableStream", url,
"POST",
() => {
new ReadableStream({start: controller => {
return new ReadableStream({start: controller => {
const encoder = new TextEncoder();
controller.enqueue(encoder.encode("Test"));
controller.close();
Expand All @@ -83,39 +85,39 @@ testUpload("Fetch with POST with ReadableStream", url,
testUploadFailure("Fetch with POST with ReadableStream containing String", url,
"POST",
() => {
new ReadableStream({start: controller => {
return new ReadableStream({start: controller => {
controller.enqueue("Test");
controller.close();
}})
});
testUploadFailure("Fetch with POST with ReadableStream containing null", url,
"POST",
() => {
new ReadableStream({start: controller => {
return new ReadableStream({start: controller => {
controller.enqueue(null);
controller.close();
}})
});
testUploadFailure("Fetch with POST with ReadableStream containing number", url,
"POST",
() => {
new ReadableStream({start: controller => {
return new ReadableStream({start: controller => {
controller.enqueue(99);
controller.close();
}})
});
testUploadFailure("Fetch with POST with ReadableStream containing ArrayBuffer", url,
"POST",
() => {
new ReadableStream({start: controller => {
return new ReadableStream({start: controller => {
controller.enqueue(new ArrayBuffer());
controller.close();
}})
});
testUploadFailure("Fetch with POST with ReadableStream containing Blob", url,
"POST",
() => {
new ReadableStream({start: controller => {
return new ReadableStream({start: controller => {
controller.enqueue(new Blob());
controller.close();
}})
Expand Down