|
| 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