Skip to content

Commit 1061f6c

Browse files
KhafraDevronag
authored andcommitted
wpt: add header-values.any.js
1 parent 979dccd commit 1061f6c

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

test/wpt/status/fetch.status.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,14 @@
153153
"Redirect 308 in \"manual\" mode with invalid location",
154154
"Redirect 308 in \"manual\" mode with data location"
155155
]
156+
},
157+
"header-values.any.js": {
158+
"fail": [
159+
"XMLHttpRequest with value x%00x needs to throw",
160+
"XMLHttpRequest with value x%0Ax needs to throw",
161+
"XMLHttpRequest with value x%0Dx needs to throw",
162+
"XMLHttpRequest with all valid values",
163+
"fetch() with all valid values"
164+
]
156165
}
157166
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// META: title=Header value test
2+
// META: global=window,worker
3+
// META: timeout=long
4+
5+
"use strict";
6+
7+
// Invalid values
8+
[0, 0x0A, 0x0D].forEach(val => {
9+
val = "x" + String.fromCharCode(val) + "x"
10+
11+
// XMLHttpRequest is not available in service workers
12+
if (!self.GLOBAL.isWorker()) {
13+
test(() => {
14+
let xhr = new XMLHttpRequest()
15+
xhr.open("POST", "/")
16+
assert_throws_dom("SyntaxError", () => xhr.setRequestHeader("value-test", val))
17+
}, "XMLHttpRequest with value " + encodeURI(val) + " needs to throw")
18+
}
19+
20+
promise_test(t => promise_rejects_js(t, TypeError, fetch("/", { headers: {"value-test": val} })), "fetch() with value " + encodeURI(val) + " needs to throw")
21+
})
22+
23+
// Valid values
24+
let headerValues =[]
25+
for(let i = 0; i < 0x100; i++) {
26+
if(i === 0 || i === 0x0A || i === 0x0D) {
27+
continue
28+
}
29+
headerValues.push("x" + String.fromCharCode(i) + "x")
30+
}
31+
var url = "../resources/inspect-headers.py?headers="
32+
headerValues.forEach((_, i) => {
33+
url += "val" + i + "|"
34+
})
35+
36+
// XMLHttpRequest is not available in service workers
37+
if (!self.GLOBAL.isWorker()) {
38+
async_test((t) => {
39+
let xhr = new XMLHttpRequest()
40+
xhr.open("POST", url)
41+
headerValues.forEach((val, i) => {
42+
xhr.setRequestHeader("val" + i, val)
43+
})
44+
xhr.onload = t.step_func_done(() => {
45+
headerValues.forEach((val, i) => {
46+
assert_equals(xhr.getResponseHeader("x-request-val" + i), val)
47+
})
48+
})
49+
xhr.send()
50+
}, "XMLHttpRequest with all valid values")
51+
}
52+
53+
promise_test((t) => {
54+
const headers = new Headers
55+
headerValues.forEach((val, i) => {
56+
headers.append("val" + i, val)
57+
})
58+
return fetch(url, { headers }).then((res) => {
59+
headerValues.forEach((val, i) => {
60+
assert_equals(res.headers.get("x-request-val" + i), val)
61+
})
62+
})
63+
}, "fetch() with all valid values")

0 commit comments

Comments
 (0)