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

Add a fetch test for upload streaming #4362

Merged
merged 4 commits into from
Jan 7, 2017
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
36 changes: 36 additions & 0 deletions fetch/api/basic/request-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ function testUpload(desc, url, method, body, expectedBody) {
}, desc);
}

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

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

testUpload("Fetch with PUT with body", url, "PUT", "Request's body", "Request's body");
Expand All @@ -31,5 +42,30 @@ testUpload("Fetch with POST with Float32Array body", url, "POST", new Float32Arr
testUpload("Fetch with POST with Float64Array body", url, "POST", new Float64Array(1), "\0\0\0\0\0\0\0\0");
testUpload("Fetch with POST with DataView body", url, "POST", new DataView(new ArrayBuffer(8), 0, 4), "\0\0\0\0");
testUpload("Fetch with POST with Blob body with mime type", url, "POST", new Blob(["Test"], { type: "text/maybe" }), "Test");
testUpload("Fetch with POST with ReadableStream", url, "POST", new ReadableStream({start: controller => {
const encoder = new TextEncoder();
controller.enqueue(encoder.encode("Test"));
controller.close();
}}), "Test");
testUploadFailure("Fetch with POST with ReadableStream containing String", url, "POST", new ReadableStream({start: controller => {
controller.enqueue("Test");
controller.close();
}}));
testUploadFailure("Fetch with POST with ReadableStream containing null", url, "POST", new ReadableStream({start: controller => {
controller.enqueue(null);
controller.close();
}}));
testUploadFailure("Fetch with POST with ReadableStream containing number", url, "POST", new ReadableStream({start: controller => {
controller.enqueue(99);
controller.close();
}}));
Copy link
Member

Choose a reason for hiding this comment

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

We should also test ArrayBuffer and Blob are not allowed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

testUploadFailure("Fetch with POST with ReadableStream containing ArrayBuffer", url, "POST", new ReadableStream({start: controller => {
controller.enqueue(new ArrayBuffer());
controller.close();
}}));
testUploadFailure("Fetch with POST with ReadableStream containing Blob", url, "POST", new ReadableStream({start: controller => {
controller.enqueue(new Blob());
controller.close();
}}));

done();