summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/beacon/headers
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/beacon/headers
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/beacon/headers')
-rw-r--r--testing/web-platform/tests/beacon/headers/header-content-type-and-body.html89
-rw-r--r--testing/web-platform/tests/beacon/headers/header-referrer-no-referrer-when-downgrade.https.html21
-rw-r--r--testing/web-platform/tests/beacon/headers/header-referrer-no-referrer.html19
-rw-r--r--testing/web-platform/tests/beacon/headers/header-referrer-origin-when-cross-origin.html21
-rw-r--r--testing/web-platform/tests/beacon/headers/header-referrer-origin.html19
-rw-r--r--testing/web-platform/tests/beacon/headers/header-referrer-same-origin.html21
-rw-r--r--testing/web-platform/tests/beacon/headers/header-referrer-strict-origin-when-cross-origin.https.html21
-rw-r--r--testing/web-platform/tests/beacon/headers/header-referrer-strict-origin.https.html21
-rw-r--r--testing/web-platform/tests/beacon/headers/header-referrer-unsafe-url.https.html21
-rw-r--r--testing/web-platform/tests/beacon/headers/header-referrer.js44
10 files changed, 297 insertions, 0 deletions
diff --git a/testing/web-platform/tests/beacon/headers/header-content-type-and-body.html b/testing/web-platform/tests/beacon/headers/header-content-type-and-body.html
new file mode 100644
index 0000000000..0369cffdf4
--- /dev/null
+++ b/testing/web-platform/tests/beacon/headers/header-content-type-and-body.html
@@ -0,0 +1,89 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>SendBeacon Content-Type header</title>
+ <script src=/resources/testharness.js></script>
+ <script src=/resources/testharnessreport.js></script>
+ </head>
+ <body>
+ <script src="/common/utils.js"></script>
+ <script src="/common/get-host-info.sub.js"></script>
+ <script>
+const RESOURCES_DIR = "/beacon/resources/";
+
+function testContentTypeAndBody(what, expected, title) {
+ function wait(ms) {
+ return new Promise(resolve => step_timeout(resolve, ms));
+ }
+ promise_test(async t => {
+ const id = self.token();
+ const testUrl = new Request(RESOURCES_DIR + "content-type-and-body.py?cmd=put&id=" + id).url;
+ assert_equals(performance.getEntriesByName(testUrl).length, 0);
+ assert_true(navigator.sendBeacon(testUrl, what), "SendBeacon Succeeded");
+
+ do {
+ await wait(50);
+ } while (performance.getEntriesByName(testUrl).length === 0);
+ assert_equals(performance.getEntriesByName(testUrl).length, 1);
+ const checkUrl = RESOURCES_DIR + "content-type-and-body.py?cmd=get&id=" + id;
+ const response = await fetch(checkUrl);
+ const text = await response.text();
+ if (expected.startsWith("multipart/form-data")) {
+ const split = expected.split(":");
+ const contentType = split[0];
+ const contentDisposition = "Content-Disposition: form-data; name=\"" + split[1] + "\"; filename=\"blob\"";
+ assert_true(text.startsWith(contentType), "Correct Content-Type header result");
+ assert_true(text.includes(contentDisposition), "Body included value");
+ } else {
+ assert_equals(text, expected, "Correct Content-Type header result");
+ }
+ }, "Test content-type header for a body " + title);
+}
+
+function stringToArrayBufferView(input) {
+ var buffer = new ArrayBuffer(input.length * 2);
+ var view = new Uint16Array(buffer);
+
+ // dumbly copy over the bytes
+ for (var i = 0, len = input.length; i < len; i++) {
+ view[i] = input.charCodeAt(i);
+ }
+ return view;
+}
+
+function stringToArrayBuffer(input) {
+ var buffer = new ArrayBuffer(input.length * 2);
+ var view = new Uint16Array(buffer);
+
+ // dumbly copy over the bytes
+ for (var i = 0, len = input.length; i < len; i++) {
+ view[i] = input.charCodeAt(i);
+ }
+ return buffer;
+}
+
+function stringToBlob(input) {
+ return new Blob([input], {type: "text/plain"});
+}
+
+function stringToFormData(input) {
+ var formdata = new FormData();
+ formdata.append(input, new Blob(['hi']));
+ return formdata;
+}
+
+function stringToURLSearchParams(input)
+{
+ return new URLSearchParams(input);
+}
+
+testContentTypeAndBody("hi!", "text/plain;charset=UTF-8: hi!", "string");
+testContentTypeAndBody(stringToArrayBufferView("123"), ": 1\0" + "2\0" + "3\0", "ArrayBufferView");
+testContentTypeAndBody(stringToArrayBuffer("123"), ": 1\0" + "2\0" + "3\0", "ArrayBuffer");
+testContentTypeAndBody(stringToBlob("123"), "text/plain: 123", "Blob");
+testContentTypeAndBody(stringToFormData("qwerty"), "multipart/form-data:qwerty", "FormData");
+testContentTypeAndBody(stringToURLSearchParams("key1=value1&key2=value2"), "application/x-www-form-urlencoded;charset=UTF-8: key1=value1&key2=value2", "URLSearchParams");
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/beacon/headers/header-referrer-no-referrer-when-downgrade.https.html b/testing/web-platform/tests/beacon/headers/header-referrer-no-referrer-when-downgrade.https.html
new file mode 100644
index 0000000000..d09d4ea560
--- /dev/null
+++ b/testing/web-platform/tests/beacon/headers/header-referrer-no-referrer-when-downgrade.https.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>SendBeacon Referrer Header No Referrer When Downgrade Policy</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <meta name='referrer' content='no-referrer-when-downgrade'>
+ </head>
+ <body>
+ <script src="/common/utils.js"></script>
+ <script src="/common/get-host-info.sub.js"></script>
+ <script src="/beacon/headers/header-referrer.js"></script>
+ <script>
+ var testBase = get_host_info().HTTPS_ORIGIN + RESOURCES_DIR;
+ testReferrerHeader(testBase, referrerUrl);
+ testBase = get_host_info().HTTP_ORIGIN + RESOURCES_DIR;
+ testReferrerHeader(testBase, "", true);
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/beacon/headers/header-referrer-no-referrer.html b/testing/web-platform/tests/beacon/headers/header-referrer-no-referrer.html
new file mode 100644
index 0000000000..b26db4c2d5
--- /dev/null
+++ b/testing/web-platform/tests/beacon/headers/header-referrer-no-referrer.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>SendBeacon Referrer Header No Referrer Policy</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <meta name='referrer' content='no-referrer'>
+ </head>
+ <body>
+ <script src="/common/utils.js"></script>
+ <script src="/common/get-host-info.sub.js"></script>
+ <script src="header-referrer.js"></script>
+ <script>
+ var testBase = RESOURCES_DIR;
+ testReferrerHeader(testBase, "");
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/beacon/headers/header-referrer-origin-when-cross-origin.html b/testing/web-platform/tests/beacon/headers/header-referrer-origin-when-cross-origin.html
new file mode 100644
index 0000000000..a23c0210c5
--- /dev/null
+++ b/testing/web-platform/tests/beacon/headers/header-referrer-origin-when-cross-origin.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>SendBeacon Referrer Header Origin When Cross Origin Policy</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <meta name='referrer' content='origin-when-cross-origin'>
+ </head>
+ <body>
+ <script src="/common/utils.js"></script>
+ <script src="/common/get-host-info.sub.js"></script>
+ <script src="header-referrer.js"></script>
+ <script>
+ var testBase = get_host_info().HTTP_ORIGIN + RESOURCES_DIR;
+ testReferrerHeader(testBase, referrerUrl);
+ testBase = get_host_info().HTTP_REMOTE_ORIGIN + RESOURCES_DIR;
+ testReferrerHeader(testBase, referrerOrigin);
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/beacon/headers/header-referrer-origin.html b/testing/web-platform/tests/beacon/headers/header-referrer-origin.html
new file mode 100644
index 0000000000..c7a571e3a1
--- /dev/null
+++ b/testing/web-platform/tests/beacon/headers/header-referrer-origin.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>SendBeacon Referrer Header Origin Policy</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <meta name='referrer' content='origin'>
+ </head>
+ <body>
+ <script src="/common/utils.js"></script>
+ <script src="/common/get-host-info.sub.js"></script>
+ <script src="header-referrer.js"></script>
+ <script>
+ var testBase = get_host_info().HTTP_REMOTE_ORIGIN + RESOURCES_DIR;
+ testReferrerHeader(testBase, referrerOrigin);
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/beacon/headers/header-referrer-same-origin.html b/testing/web-platform/tests/beacon/headers/header-referrer-same-origin.html
new file mode 100644
index 0000000000..80455ab59e
--- /dev/null
+++ b/testing/web-platform/tests/beacon/headers/header-referrer-same-origin.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>SendBeacon Referrer Header Same Origin Policy</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <meta name='referrer' content='same-origin'>
+ </head>
+ <body>
+ <script src="/common/utils.js"></script>
+ <script src="/common/get-host-info.sub.js"></script>
+ <script src="header-referrer.js"></script>
+ <script>
+ var testBase = RESOURCES_DIR;
+ testReferrerHeader(testBase, referrerUrl);
+ testBase = get_host_info().HTTP_REMOTE_ORIGIN + RESOURCES_DIR;
+ testReferrerHeader(testBase, "");
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/beacon/headers/header-referrer-strict-origin-when-cross-origin.https.html b/testing/web-platform/tests/beacon/headers/header-referrer-strict-origin-when-cross-origin.https.html
new file mode 100644
index 0000000000..f310035009
--- /dev/null
+++ b/testing/web-platform/tests/beacon/headers/header-referrer-strict-origin-when-cross-origin.https.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>SendBeacon Referrer Header Strict Origin Policy</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <meta name='referrer' content='strict-origin'>
+ </head>
+ <body>
+ <script src="/common/utils.js"></script>
+ <script src="/common/get-host-info.sub.js"></script>
+ <script src="/beacon/headers/header-referrer.js"></script>
+ <script>
+ var testBase = get_host_info().HTTPS_REMOTE_ORIGIN + RESOURCES_DIR;
+ testReferrerHeader(testBase, referrerOrigin);
+ testBase = get_host_info().HTTP_REMOTE_ORIGIN + RESOURCES_DIR;
+ testReferrerHeader(testBase, "", true);
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/beacon/headers/header-referrer-strict-origin.https.html b/testing/web-platform/tests/beacon/headers/header-referrer-strict-origin.https.html
new file mode 100644
index 0000000000..b65bc795d2
--- /dev/null
+++ b/testing/web-platform/tests/beacon/headers/header-referrer-strict-origin.https.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>SendBeacon Referrer Header Strict Origin Policy</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <meta name='referrer' content='strict-origin'>
+ </head>
+ <body>
+ <script src="/common/utils.js"></script>
+ <script src="/common/get-host-info.sub.js"></script>
+ <script src="/beacon/headers/header-referrer.js"></script>
+ <script>
+ var testBase = get_host_info().HTTPS_ORIGIN + RESOURCES_DIR;
+ testReferrerHeader(testBase, referrerOrigin);
+ testBase = get_host_info().HTTP_ORIGIN + RESOURCES_DIR;
+ testReferrerHeader(testBase, "", true);
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/beacon/headers/header-referrer-unsafe-url.https.html b/testing/web-platform/tests/beacon/headers/header-referrer-unsafe-url.https.html
new file mode 100644
index 0000000000..26a062ebd8
--- /dev/null
+++ b/testing/web-platform/tests/beacon/headers/header-referrer-unsafe-url.https.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>SendBeacon Referrer Header Unsafe Url Policy</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <meta name='referrer' content='unsafe-url'>
+ </head>
+ <body>
+ <script src="/common/utils.js"></script>
+ <script src="/common/get-host-info.sub.js"></script>
+ <script src="/beacon/headers/header-referrer.js"></script>
+ <script>
+ var testBase = get_host_info().HTTPS_ORIGIN + RESOURCES_DIR;
+ testReferrerHeader(testBase, referrerUrl);
+ testBase = get_host_info().HTTP_ORIGIN + RESOURCES_DIR;
+ testReferrerHeader(testBase, referrerUrl, true);
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/beacon/headers/header-referrer.js b/testing/web-platform/tests/beacon/headers/header-referrer.js
new file mode 100644
index 0000000000..ebd67df1d7
--- /dev/null
+++ b/testing/web-platform/tests/beacon/headers/header-referrer.js
@@ -0,0 +1,44 @@
+var RESOURCES_DIR = "/beacon/resources/";
+
+var referrerOrigin = self.location.origin + '/';
+var referrerUrl = self.location.href;
+
+function testReferrerHeader(testBase, expectedReferrer, mayBeBlockedAsMixedContent = false) {
+ var id = self.token();
+ var testUrl = testBase + "inspect-header.py?header=referer&cmd=put&id=" + id;
+
+ promise_test(function(test) {
+ const sentBeacon = navigator.sendBeacon(testUrl);
+ if (mayBeBlockedAsMixedContent && !sentBeacon)
+ return Promise.resolve();
+ assert_true(sentBeacon, "SendBeacon Succeeded");
+ return pollResult(expectedReferrer, id) .then(result => {
+ assert_equals(result, expectedReferrer, "Correct referrer header result");
+ });
+ }, "Test referer header " + testBase);
+}
+
+// SendBeacon is an asynchronous and non-blocking request to a web server.
+// We may have to create a poll loop to get result from server
+function pollResult(expectedReferrer, id) {
+ var checkUrl = RESOURCES_DIR + "inspect-header.py?header=referer&cmd=get&id=" + id;
+
+ return new Promise(resolve => {
+ function checkResult() {
+ fetch(checkUrl).then(
+ function(response) {
+ assert_equals(response.status, 200, "Inspect header response's status is 200");
+ let result = response.headers.get("x-request-referer");
+
+ if (result != undefined) {
+ resolve(result);
+ } else {
+ step_timeout(checkResult.bind(this), 100);
+ }
+ });
+ }
+
+ checkResult();
+ });
+
+}