summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/xhr/cors-upload.any.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/xhr/cors-upload.any.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/xhr/cors-upload.any.js')
-rw-r--r--testing/web-platform/tests/xhr/cors-upload.any.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/testing/web-platform/tests/xhr/cors-upload.any.js b/testing/web-platform/tests/xhr/cors-upload.any.js
new file mode 100644
index 0000000000..3beb0637cc
--- /dev/null
+++ b/testing/web-platform/tests/xhr/cors-upload.any.js
@@ -0,0 +1,59 @@
+// META: title=Cross-Origin POST with preflight and FormData body should send body
+// META: script=/common/get-host-info.sub.js
+"use strict";
+
+function testCorsFormDataUpload(description, path, method, form, headers, withCredentials) {
+ const test = async_test(description);
+ const client = new XMLHttpRequest();
+ const url = corsURL(path);
+
+ client.open(method, url, true);
+ client.withCredentials = withCredentials;
+ for (const key of Object.keys(headers)) {
+ client.setRequestHeader(key, headers[key]);
+ }
+
+ client.send(form);
+
+ client.onload = () => {
+ test.step(() => {
+ assert_equals(client.status, 200);
+ assert_regexp_match(client.responseText, /Content-Disposition: form-data/);
+
+ for (const key of form.keys()) {
+ assert_regexp_match(client.responseText, new RegExp(key));
+ assert_regexp_match(client.responseText, new RegExp(form.get(key)));
+ }
+ });
+ test.done();
+ };
+}
+
+function corsURL(path) {
+ const url = new URL(path, location.href);
+ url.hostname = get_host_info().REMOTE_HOST;
+ return url.href;
+}
+
+const form = new FormData();
+form.append("key", "value");
+
+testCorsFormDataUpload(
+ "Cross-Origin POST FormData body but no preflight",
+ "resources/echo-content-cors.py",
+ "POST",
+ form,
+ {},
+ false
+);
+
+testCorsFormDataUpload(
+ "Cross-Origin POST with preflight and FormData body",
+ "resources/echo-content-cors.py",
+ "POST",
+ form,
+ {
+ Authorization: "Bearer access-token"
+ },
+ true
+);