Skip to content

Commit

Permalink
wpt: add header-values.any.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and ronag committed Oct 17, 2022
1 parent 979dccd commit 1061f6c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/wpt/status/fetch.status.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,14 @@
"Redirect 308 in \"manual\" mode with invalid location",
"Redirect 308 in \"manual\" mode with data location"
]
},
"header-values.any.js": {
"fail": [
"XMLHttpRequest with value x%00x needs to throw",
"XMLHttpRequest with value x%0Ax needs to throw",
"XMLHttpRequest with value x%0Dx needs to throw",
"XMLHttpRequest with all valid values",
"fetch() with all valid values"
]
}
}
63 changes: 63 additions & 0 deletions test/wpt/tests/fetch/api/headers/header-values.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// META: title=Header value test
// META: global=window,worker
// META: timeout=long

"use strict";

// Invalid values
[0, 0x0A, 0x0D].forEach(val => {
val = "x" + String.fromCharCode(val) + "x"

// XMLHttpRequest is not available in service workers
if (!self.GLOBAL.isWorker()) {
test(() => {
let xhr = new XMLHttpRequest()
xhr.open("POST", "/")
assert_throws_dom("SyntaxError", () => xhr.setRequestHeader("value-test", val))
}, "XMLHttpRequest with value " + encodeURI(val) + " needs to throw")
}

promise_test(t => promise_rejects_js(t, TypeError, fetch("/", { headers: {"value-test": val} })), "fetch() with value " + encodeURI(val) + " needs to throw")
})

// Valid values
let headerValues =[]
for(let i = 0; i < 0x100; i++) {
if(i === 0 || i === 0x0A || i === 0x0D) {
continue
}
headerValues.push("x" + String.fromCharCode(i) + "x")
}
var url = "../resources/inspect-headers.py?headers="
headerValues.forEach((_, i) => {
url += "val" + i + "|"
})

// XMLHttpRequest is not available in service workers
if (!self.GLOBAL.isWorker()) {
async_test((t) => {
let xhr = new XMLHttpRequest()
xhr.open("POST", url)
headerValues.forEach((val, i) => {
xhr.setRequestHeader("val" + i, val)
})
xhr.onload = t.step_func_done(() => {
headerValues.forEach((val, i) => {
assert_equals(xhr.getResponseHeader("x-request-val" + i), val)
})
})
xhr.send()
}, "XMLHttpRequest with all valid values")
}

promise_test((t) => {
const headers = new Headers
headerValues.forEach((val, i) => {
headers.append("val" + i, val)
})
return fetch(url, { headers }).then((res) => {
headerValues.forEach((val, i) => {
assert_equals(res.headers.get("x-request-val" + i), val)
})
})
}, "fetch() with all valid values")

0 comments on commit 1061f6c

Please sign in to comment.