-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See whatwg/fetch#332 for context. Once w3c/wptserve#111 is fixed these tests can be further updated.
- Loading branch information
Showing
3 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!doctype html> | ||
<meta charset=utf8> | ||
<meta name=timeout content=long> | ||
<title>Header value normalizing test</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<div id=log></div> | ||
<script> | ||
for(let i = 0; i < 0x21; i++) { | ||
let fail = false, | ||
strip = false | ||
|
||
// REMOVE 0x0B/0x0C exception once https://github.com/w3c/wptserve/issues/111 is fixed | ||
if(i === 0x0B || i === 0x0C) | ||
continue | ||
|
||
if(i === 0) { | ||
fail = true | ||
} | ||
|
||
if(i === 0x09 || i === 0x0A || i === 0x0D || i === 0x20) { | ||
strip = true | ||
} | ||
|
||
let val = String.fromCharCode(i), | ||
expectedVal = strip ? "" : val | ||
for(let y = 0; y < 3; y++) { | ||
let useVal = val, | ||
useExpectedVal = expectedVal | ||
if(y === 0) { | ||
useVal = "x" + val | ||
useExpectedVal = "x" + expectedVal | ||
} else if(y === 2) { | ||
useVal = val + "x" | ||
useExpectedVal = expectedVal + "x" | ||
} | ||
|
||
async_test((t) => { | ||
let xhr = new XMLHttpRequest() | ||
xhr.open("POST", "../resources/inspect-headers.py?headers=value-test") | ||
if(fail) { | ||
assert_throws("SyntaxError", () => xhr.setRequestHeader("value-test", useVal)) | ||
t.done() | ||
} else { | ||
xhr.setRequestHeader("value-test", useVal) | ||
xhr.onload = t.step_func_done(() => { | ||
assert_equals(xhr.getResponseHeader("x-request-value-test"), useExpectedVal) | ||
}) | ||
xhr.send() | ||
} | ||
}, "XMLHttpRequest with value " + encodeURI(useVal)) | ||
|
||
promise_test((t) => { | ||
if(fail) { | ||
return promise_rejects(t, new TypeError(), fetch("about:blank", { headers: {"value-test": useVal} })) | ||
} else { | ||
return fetch("../resources/inspect-headers.py?headers=value-test", { headers: {"value-test": useVal} }).then((res) => { | ||
assert_equals(res.headers.get("x-request-value-test"), useExpectedVal) | ||
}) | ||
} | ||
}, "fetch() with value " + encodeURI(useVal)) | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!doctype html> | ||
<meta charset=utf8> | ||
<meta name=timeout content=long> | ||
<title>Header value test</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<div id=log></div> | ||
<script> | ||
for(let i = 0; i < 0x100; i++) { | ||
let fail = false | ||
if(i === 0 || i === 0x0A || i === 0x0D) { | ||
fail = true | ||
} | ||
|
||
let val = "x" + String.fromCharCode(i) + "x" | ||
async_test((t) => { | ||
let xhr = new XMLHttpRequest() | ||
xhr.open("POST", "../resources/inspect-headers.py?headers=value-test") | ||
if(fail) { | ||
assert_throws("SyntaxError", () => xhr.setRequestHeader("value-test", val)) | ||
t.done() | ||
} else { | ||
xhr.setRequestHeader("value-test", val) | ||
xhr.onload = t.step_func_done(() => { | ||
assert_equals(xhr.getResponseHeader("x-request-value-test"), val) | ||
}) | ||
xhr.send() | ||
} | ||
}, "XMLHttpRequest with value " + encodeURI(val)) | ||
|
||
promise_test((t) => { | ||
if(fail) { | ||
return promise_rejects(t, new TypeError(), fetch("about:blank", { headers: {"value-test": val} })) | ||
} else { | ||
return fetch("../resources/inspect-headers.py?headers=value-test", { headers: {"value-test": val} }).then((res) => { | ||
assert_equals(res.headers.get("x-request-value-test"), val) | ||
}) | ||
} | ||
}, "fetch() with value " + encodeURI(val)) | ||
} | ||
</script> |