Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/fetch/api/headers/header-values.html

Issue 2778753002: Import //fetch from Web Platform Tests. (Closed)
Patch Set: Baselines. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!doctype html>
2 <meta charset=utf8>
3 <meta name=timeout content=long>
4 <title>Header value test</title>
5 <script src=/resources/testharness.js></script>
6 <script src=/resources/testharnessreport.js></script>
7 <div id=log></div>
8 <script>
9 // Invalid values
10 [0, 0x0A, 0x0D].forEach(val => {
11 val = "x" + String.fromCharCode(val) + "x"
12 test(() => {
13 let xhr = new XMLHttpRequest()
14 xhr.open("POST", "/")
15 assert_throws("SyntaxError", () => xhr.setRequestHeader("value-test", val))
16 }, "XMLHttpRequest with value " + encodeURI(val) + " needs to throw")
17
18 promise_test(t => promise_rejects(t, new TypeError(), fetch("about:blank", { h eaders: {"value-test": val} })), "fetch() with value " + encodeURI(val) + " need s to throw")
19 })
20
21 // Valid values
22 let headerValues =[]
23 for(let i = 0; i < 0x100; i++) {
24 if(i === 0 || i === 0x0A || i === 0x0D) {
25 continue
26 }
27 headerValues.push("x" + String.fromCharCode(i) + "x")
28 }
29 var url = "../resources/inspect-headers.py?headers="
30 headerValues.forEach((_, i) => {
31 url += "val" + i + "|"
32 })
33
34 async_test((t) => {
35 let xhr = new XMLHttpRequest()
36 xhr.open("POST", url)
37 headerValues.forEach((val, i) => {
38 xhr.setRequestHeader("val" + i, val)
39 })
40 xhr.onload = t.step_func_done(() => {
41 headerValues.forEach((val, i) => {
42 assert_equals(xhr.getResponseHeader("x-request-val" + i), val)
43 })
44 })
45 xhr.send()
46 }, "XMLHttpRequest with all valid values")
47
48 promise_test((t) => {
49 const headers = new Headers
50 headerValues.forEach((val, i) => {
51 headers.append("val" + i, val)
52 })
53 return fetch(url, { headers }).then((res) => {
54 headerValues.forEach((val, i) => {
55 assert_equals(res.headers.get("x-request-val" + i), val)
56 })
57 })
58 }, "fetch() with all valid values")
59 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698