summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/resource-timing/content-type-parsing.html
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/resource-timing/content-type-parsing.html
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/resource-timing/content-type-parsing.html')
-rw-r--r--testing/web-platform/tests/resource-timing/content-type-parsing.html76
1 files changed, 76 insertions, 0 deletions
diff --git a/testing/web-platform/tests/resource-timing/content-type-parsing.html b/testing/web-platform/tests/resource-timing/content-type-parsing.html
new file mode 100644
index 0000000000..c0081eb413
--- /dev/null
+++ b/testing/web-platform/tests/resource-timing/content-type-parsing.html
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<head>
+<meta charset="utf-8" />
+<title>This test validates the parsing of content-type of resources.</title>
+<link rel="help" href="https://www.w3.org/TR/resource-timing-2/#sec-performanceresourcetiming"/>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+<script>
+
+// Utility function picked from https://github.com/web-platform-tests/wpt/blob/master/mimesniff/mime-types/charset-parameter.window.js
+function isByteCompatible(str) {
+ // see https://fetch.spec.whatwg.org/#concept-header-value-normalize
+ if(/^[\u0009\u0020\u000A\u000D]+|[\u0009\u0020\u000A\u000D]+$/.test(str)) {
+ return "header-value-incompatible";
+ }
+
+ for(let i = 0; i < str.length; i++) {
+ const charCode = str.charCodeAt(i);
+ // See https://fetch.spec.whatwg.org/#concept-header-value
+ if(charCode > 0xFF) {
+ return "incompatible";
+ } else if(charCode === 0x00 || charCode === 0x0A || charCode === 0x0D) {
+ return "header-value-incompatible";
+ }
+ }
+ return "compatible";
+}
+
+// Test for content-type parsing.
+const run_content_type_parsing_tests = (json_entries) => {
+ json_entries.forEach( (json_entry, i) => {
+ promise_test(async t => {
+ let url = "/fetch/content-type/resources/content-type.py?single_header&";
+ json_entry.contentType.forEach(val => {
+ url += "value=" + encodeURIComponent(val) + "&";
+ });
+ fetch(url);
+ const entry = await new Promise(resolve => new PerformanceObserver((entryList, observer) => {
+ observer.disconnect();
+ resolve(entryList.getEntries()[0]);
+ }).observe({entryTypes: ['resource']}));
+ assert_equals(entry.contentType, json_entry["mimeType"]);
+ }, "content-type " + i + " : " + json_entry.contentType);
+ });
+}
+
+// Test for mime-type parsing.
+const run_mime_type_parsing_tests = (json_entries) => {
+ json_entries.forEach( (val, i) => {
+ if(typeof val === "string" || val.navigable === undefined || isByteCompatible(val.input) !== "compatible") {
+ return;
+ }
+ const output = val.output === null ? "" : val.output
+ promise_test(async t => {
+ let url = `/fetch/content-type/resources/content-type.py?single_header&value=${val.input}`;
+ fetch(url);
+ const entry = await new Promise(resolve => new PerformanceObserver((entryList, observer) => {
+ observer.disconnect();
+ resolve(entryList.getEntries()[0]);
+ }).observe({entryTypes: ['resource']}));
+ assert_equals(entry.contentType, output);
+ }, "mime-type " + i + " : " + val.input);
+ });
+}
+
+Promise.all([
+ fetch("/fetch/content-type/resources/content-types.json"),
+ fetch("/mimesniff/mime-types/resources/mime-types.json")
+ ]).then(([res, res2]) => res.json().then(run_content_type_parsing_tests)
+ .then(() => res2.json().then(run_mime_type_parsing_tests)));
+
+</script>
+</body>
+</html> \ No newline at end of file