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

[Gecko Bug 1771423] Add test for fetching empty blobs. #35469

Merged
merged 1 commit into from
Aug 15, 2022
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
40 changes: 40 additions & 0 deletions fetch/api/basic/scheme-blob.sub.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,47 @@ invalidRequestMethods.forEach(function(method) {
checkKoUrl(URL.createObjectURL(blob2), method, "Fetching [" + method + "] URL.createObjectURL(blob) is KO");
});

var empty_blob = new Blob([]);
checkFetchResponse(URL.createObjectURL(empty_blob), "", "", 0,
"Fetching URL.createObjectURL(empty_blob) is OK");

var empty_type_blob = new Blob([], {type: ""});
checkFetchResponse(URL.createObjectURL(empty_type_blob), "", "", 0,
"Fetching URL.createObjectURL(empty_type_blob) is OK");

var empty_data_blob = new Blob([], {type: "text/plain"});
checkFetchResponse(URL.createObjectURL(empty_data_blob), "", "text/plain", 0,
"Fetching URL.createObjectURL(empty_data_blob) is OK");

checkKoUrl("blob:not-backed-by-a-blob/", "GET",
"Fetching [GET] blob:not-backed-by-a-blob/ is KO");

promise_test(function(test) {
var blob = new Blob(["content type with invalid character"], {"type": "text/plain"});
let slice = blob.slice(8, 25, "\0");
return fetch(URL.createObjectURL(slice)).then(function (resp) {
assert_equals(resp.status, 200, "HTTP status is 200");
assert_equals(resp.type, "basic", "response type is basic");
assert_equals(resp.headers.get("Content-Type"), "");
assert_equals(resp.headers.get("Content-Length"), "17");
return resp.text();
}).then(function(bodyAsText) {
assert_equals(bodyAsText, "type with invalid");
});
}, "Set content type to the empty string for slice with invalid content type");

promise_test(function(test) {
var blob = new Blob(["content type that is empty"], {"type": "text/plain"});
let slice = blob.slice(8, 20);
return fetch(URL.createObjectURL(slice)).then(function (resp) {
assert_equals(resp.status, 200, "HTTP status is 200");
assert_equals(resp.type, "basic", "response type is basic");
assert_equals(resp.headers.get("Content-Type"), "");
assert_equals(resp.headers.get("Content-Length"), "12");
return resp.text();
}).then(function(bodyAsText) {
assert_equals(bodyAsText, "type that is");
});
}, "Set content type to the empty string for slice with no content type ");

done();