diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /netwerk/test/mochitests/test_accept_header.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | netwerk/test/mochitests/test_accept_header.html | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/netwerk/test/mochitests/test_accept_header.html b/netwerk/test/mochitests/test_accept_header.html new file mode 100644 index 0000000000..0acae2a825 --- /dev/null +++ b/netwerk/test/mochitests/test_accept_header.html @@ -0,0 +1,87 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Accept header</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> +<script> +SimpleTest.requestCompleteLog(); + +// All the requests are sent to test_accept_header.sjs which will return +// different content based on the queryString. When the queryString is 'get', +// test_accept_header.sjs returns a JSON object with the latest request and its +// accept header value. + +function test_last_request_and_continue(query, expected) { + fetch("test_accept_header.sjs?get").then(r => r.json()).then(json => { + is(json.type, query, "Expected: " + query); + is(json.accept, expected, "Accept header: " + expected); + next(); + }); +} + +function test_iframe() { + let ifr = document.createElement("iframe"); + ifr.src = "test_accept_header.sjs?iframe"; + ifr.onload = () => { + test_last_request_and_continue("iframe", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"); + }; + document.body.appendChild(ifr); +} + +function test_image() { + let i = new Image(); + i.src = "test_accept_header.sjs?image"; + i.onload = function() { + // Fetch spec says we should have: "image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5" + test_last_request_and_continue("image", "image/avif,image/webp,*/*"); + } +} + +function test_style() { + let head = document.getElementsByTagName("head")[0]; + let link = document.createElement("link"); + link.rel = "stylesheet"; + link.type = "text/css"; + link.href = "test_accept_header.sjs?style"; + link.onload = () => { + test_last_request_and_continue("style", "text/css,*/*;q=0.1"); + }; + head.appendChild(link); +} + +function test_worker() { + let w = new Worker("test_accept_header.sjs?worker"); + w.onmessage = function() { + test_last_request_and_continue("worker", "*/*"); + } +} + +let tests = [ + test_iframe, + test_image, + test_style, + test_worker, +]; + +function next() { + if (!tests.length) { + SimpleTest.finish(); + return; + } + + let test = tests.shift(); + test(); +} + +SimpleTest.waitForExplicitFinish(); + +SpecialPowers.pushPrefEnv({ "set": [ + [ "dom.enable_performance_observer", true ] +]}, next); + +</script> +</body> +</html> |