summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/api
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /testing/web-platform/tests/fetch/api
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-upstream/125.0.1.tar.xz
firefox-upstream/125.0.1.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/fetch/api')
-rw-r--r--testing/web-platform/tests/fetch/api/basic/request-upload.h2.any.js23
-rw-r--r--testing/web-platform/tests/fetch/api/body/formdata.any.js11
-rw-r--r--testing/web-platform/tests/fetch/api/request/request-consume-empty.any.js22
-rw-r--r--testing/web-platform/tests/fetch/api/request/request-consume.any.js29
-rw-r--r--testing/web-platform/tests/fetch/api/response/response-consume-empty.any.js23
5 files changed, 54 insertions, 54 deletions
diff --git a/testing/web-platform/tests/fetch/api/basic/request-upload.h2.any.js b/testing/web-platform/tests/fetch/api/basic/request-upload.h2.any.js
index eedc2bf6a7..68122278cc 100644
--- a/testing/web-platform/tests/fetch/api/basic/request-upload.h2.any.js
+++ b/testing/web-platform/tests/fetch/api/basic/request-upload.h2.any.js
@@ -184,3 +184,26 @@ promise_test(async (t) => {
await promise_rejects_js(t, TypeError, fetch(url, { method, body, duplex }));
}, "Streaming upload should fail on a 401 response");
+promise_test(async (t) => {
+ const abortMessage = 'foo abort';
+ let streamCancelPromise = new Promise(async res => {
+ var stream = new ReadableStream({
+ cancel: function(reason) {
+ res(reason);
+ }
+ });
+ let abortController = new AbortController();
+ let fetchPromise = promise_rejects_exactly(t, abortMessage, fetch('', {
+ method: 'POST',
+ body: stream,
+ duplex: 'half',
+ signal: abortController.signal
+ }));
+ abortController.abort(abortMessage);
+ await fetchPromise;
+ });
+
+ let cancelReason = await streamCancelPromise;
+ assert_equals(
+ cancelReason, abortMessage, 'ReadableStream.cancel should be called.');
+}, 'ReadbleStream should be closed on signal.abort');
diff --git a/testing/web-platform/tests/fetch/api/body/formdata.any.js b/testing/web-platform/tests/fetch/api/body/formdata.any.js
index e25035923c..6733fa0ed7 100644
--- a/testing/web-platform/tests/fetch/api/body/formdata.any.js
+++ b/testing/web-platform/tests/fetch/api/body/formdata.any.js
@@ -12,3 +12,14 @@ promise_test(async t => {
const fd = await req.formData();
assert_true(fd instanceof FormData);
}, 'Consume empty request.formData() as FormData');
+
+promise_test(async t => {
+ let formdata = new FormData();
+ formdata.append('foo', new Blob([JSON.stringify({ bar: "baz", })], { type: "application/json" }));
+ let blob = await new Response(formdata).blob();
+ let body = await blob.text();
+ blob = new Blob([body.toLowerCase()], { type: blob.type.toLowerCase() });
+ let formdataWithLowercaseBody = await new Response(blob).formData();
+ assert_true(formdataWithLowercaseBody.has("foo"));
+ assert_equals(formdataWithLowercaseBody.get("foo").type, "application/json");
+}, 'Consume multipart/form-data headers case-insensitively');
diff --git a/testing/web-platform/tests/fetch/api/request/request-consume-empty.any.js b/testing/web-platform/tests/fetch/api/request/request-consume-empty.any.js
index 034a86041a..0bf9672a79 100644
--- a/testing/web-platform/tests/fetch/api/request/request-consume-empty.any.js
+++ b/testing/web-platform/tests/fetch/api/request/request-consume-empty.any.js
@@ -8,23 +8,11 @@ function checkBodyText(test, request) {
});
}
-function checkBodyBlob(test, request) {
- return request.blob().then(function(bodyAsBlob) {
- var promise = new Promise(function(resolve, reject) {
- var reader = new FileReader();
- reader.onload = function(evt) {
- resolve(reader.result)
- };
- reader.onerror = function() {
- reject("Blob's reader failed");
- };
- reader.readAsText(bodyAsBlob);
- });
- return promise.then(function(body) {
- assert_equals(body, "", "Resolved value should be empty");
- assert_false(request.bodyUsed);
- });
- });
+async function checkBodyBlob(test, request) {
+ const bodyAsBlob = await request.blob();
+ const body = await bodyAsBlob.text();
+ assert_equals(body, "", "Resolved value should be empty");
+ assert_false(request.bodyUsed);
}
function checkBodyArrayBuffer(test, request) {
diff --git a/testing/web-platform/tests/fetch/api/request/request-consume.any.js b/testing/web-platform/tests/fetch/api/request/request-consume.any.js
index aff5d65244..3db9e8f265 100644
--- a/testing/web-platform/tests/fetch/api/request/request-consume.any.js
+++ b/testing/web-platform/tests/fetch/api/request/request-consume.any.js
@@ -9,26 +9,15 @@ function checkBodyText(request, expectedBody) {
});
}
-function checkBodyBlob(request, expectedBody, checkContentType) {
- return request.blob().then(function(bodyAsBlob) {
- if (checkContentType)
- assert_equals(bodyAsBlob.type, "text/plain", "Blob body type should be computed from the request Content-Type");
-
- var promise = new Promise(function (resolve, reject) {
- var reader = new FileReader();
- reader.onload = function(evt) {
- resolve(reader.result)
- };
- reader.onerror = function() {
- reject("Blob's reader failed");
- };
- reader.readAsText(bodyAsBlob);
- });
- return promise.then(function(body) {
- assert_equals(body, expectedBody, "Retrieve and verify request's body");
- assert_true(request.bodyUsed, "body as blob: bodyUsed turned true");
- });
- });
+async function checkBodyBlob(request, expectedBody, checkContentType) {
+ const bodyAsBlob = await request.blob();
+
+ if (checkContentType)
+ assert_equals(bodyAsBlob.type, "text/plain", "Blob body type should be computed from the request Content-Type");
+
+ const body = await bodyAsBlob.text();
+ assert_equals(body, expectedBody, "Retrieve and verify request's body");
+ assert_true(request.bodyUsed, "body as blob: bodyUsed turned true");
}
function checkBodyArrayBuffer(request, expectedBody) {
diff --git a/testing/web-platform/tests/fetch/api/response/response-consume-empty.any.js b/testing/web-platform/tests/fetch/api/response/response-consume-empty.any.js
index 0fa85ecbcb..a5df356258 100644
--- a/testing/web-platform/tests/fetch/api/response/response-consume-empty.any.js
+++ b/testing/web-platform/tests/fetch/api/response/response-consume-empty.any.js
@@ -8,23 +8,12 @@ function checkBodyText(test, response) {
});
}
-function checkBodyBlob(test, response) {
- return response.blob().then(function(bodyAsBlob) {
- var promise = new Promise(function(resolve, reject) {
- var reader = new FileReader();
- reader.onload = function(evt) {
- resolve(reader.result)
- };
- reader.onerror = function() {
- reject("Blob's reader failed");
- };
- reader.readAsText(bodyAsBlob);
- });
- return promise.then(function(body) {
- assert_equals(body, "", "Resolved value should be empty");
- assert_false(response.bodyUsed);
- });
- });
+async function checkBodyBlob(test, response) {
+ const bodyAsBlob = await response.blob();
+ const body = await bodyAsBlob.text();
+
+ assert_equals(body, "", "Resolved value should be empty");
+ assert_false(response.bodyUsed);
}
function checkBodyArrayBuffer(test, response) {