Skip to content

Commit af38ecb

Browse files
KhafraDevronag
authored andcommitted
wpt: add header-value-combining.any.js
1 parent 3bda21f commit af38ecb

File tree

11 files changed

+79
-3
lines changed

11 files changed

+79
-3
lines changed

test/wpt/runner/runner/runner.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { readdirSync, readFileSync, statSync } from 'node:fs'
33
import { basename, isAbsolute, join, resolve } from 'node:path'
44
import { fileURLToPath } from 'node:url'
55
import { Worker } from 'node:worker_threads'
6-
import { parseMeta, handlePipes } from './util.mjs'
6+
import { parseMeta, handlePipes, normalizeName } from './util.mjs'
77

88
const basePath = fileURLToPath(join(import.meta.url, '../../..'))
99
const testPath = join(basePath, 'tests')
@@ -130,7 +130,9 @@ export class WPTRunner extends EventEmitter {
130130
if (message.result.status === 1) {
131131
this.#stats.failed += 1
132132

133-
if (allowUnexpectedFailures || (fail && fail.includes(message.result.name))) {
133+
const name = normalizeName(message.result.name)
134+
135+
if (allowUnexpectedFailures || fail?.includes(name)) {
134136
this.#stats.expectedFailures += 1
135137
} else {
136138
process.exitCode = 1

test/wpt/runner/runner/util.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { exit } from 'node:process'
2+
import { inspect } from 'node:util'
23

34
/**
45
* Parse the `Meta:` tags sometimes included in tests.
@@ -117,3 +118,16 @@ export function handlePipes (code, url) {
117118
}
118119
})
119120
}
121+
122+
/**
123+
* Some test names may contain characters that JSON cannot handle.
124+
* @param {string} name
125+
*/
126+
export function normalizeName (name) {
127+
return name.replace(/(\v)/g, (_, match) => {
128+
switch (inspect(match)) {
129+
case `'\\x0B'`: return '\\x0B'
130+
default: return match
131+
}
132+
})
133+
}

test/wpt/server/server.mjs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createServer } from 'node:http'
33
import { join } from 'node:path'
44
import process from 'node:process'
55
import { fileURLToPath } from 'node:url'
6-
import { createReadStream } from 'node:fs'
6+
import { createReadStream, readFileSync } from 'node:fs'
77
import { setTimeout as sleep } from 'node:timers/promises'
88

99
const tests = fileURLToPath(join(import.meta.url, '../../tests'))
@@ -204,6 +204,20 @@ const server = createServer(async (req, res) => {
204204
res.end('garbage')
205205
break
206206
}
207+
case '/xhr/resources/headers-www-authenticate.asis':
208+
case '/xhr/resources/headers-some-are-empty.asis':
209+
case '/xhr/resources/headers-basic':
210+
case '/xhr/resources/headers-double-empty.asis':
211+
case '/xhr/resources/header-content-length-twice.asis':
212+
case '/xhr/resources/header-content-length.asis': {
213+
let asis = readFileSync(join(tests, fullUrl.pathname), 'utf-8')
214+
asis = asis.replace(/\n/g, '\r\n')
215+
asis = `${asis}\r\n`
216+
217+
res.socket.write(asis)
218+
res.end()
219+
break
220+
}
207221
default: {
208222
res.statusCode = 200
209223
res.end('body')

test/wpt/status/fetch.status.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,13 @@
5454
"Set content type to the empty string for slice with invalid content type",
5555
"Set content type to the empty string for slice with no content type "
5656
]
57+
},
58+
"header-value-combining.any.js": {
59+
"fail": [
60+
"response.headers.get('content-length') expects 0, 0",
61+
"response.headers.get('double-trouble') expects , ",
62+
"response.headers.get('foo-test') expects 1, 2, 3",
63+
"response.headers.get('heya') expects , \\x0B\f, 1, , , 2"
64+
]
5765
}
5866
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// META: global=window,worker
2+
3+
[
4+
["content-length", "0", "header-content-length"],
5+
["content-length", "0, 0", "header-content-length-twice"],
6+
["double-trouble", ", ", "headers-double-empty"],
7+
["foo-test", "1, 2, 3", "headers-basic"],
8+
["heya", ", \u000B\u000C, 1, , , 2", "headers-some-are-empty"],
9+
["www-authenticate", "1, 2, 3, 4", "headers-www-authenticate"],
10+
].forEach(testValues => {
11+
promise_test(async t => {
12+
const response = await fetch("../../../xhr/resources/" + testValues[2] + ".asis");
13+
assert_equals(response.headers.get(testValues[0]), testValues[1]);
14+
}, "response.headers.get('" + testValues[0] + "') expects " + testValues[1]);
15+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
HTTP/1.0 200 NANANA
2+
CONTENT-LENGTH: 0
3+
content-length: 0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
HTTP/1.0 200 NANANA
2+
CONTENT-LENGTH: 0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
HTTP/1.1 280 HELLO
2+
foo-test: 1
3+
foo-test: 2
4+
foo-test: 3
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
HTTP/1.1 444 HI
2+
double-trouble:
3+
double-trouble:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
HTTP/1.0 200 MEH
2+
HEYA:
3+
HEYA:
4+
HEYA: 1
5+
HEYA:
6+
HEYA:
7+
HEYA: 2

0 commit comments

Comments
 (0)