Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wpt: add gzip-body.any.js #1778

Merged
merged 2 commits into from Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion test/wpt/server/server.mjs
Expand Up @@ -3,7 +3,7 @@ import { createServer } from 'node:http'
import { join } from 'node:path'
import process from 'node:process'
import { fileURLToPath } from 'node:url'
import { createReadStream, readFileSync } from 'node:fs'
import { createReadStream, readFileSync, existsSync } from 'node:fs'
import { setTimeout as sleep } from 'node:timers/promises'
import { route as networkPartitionRoute } from './routes/network-partition-key.mjs'
import { route as redirectRoute } from './routes/redirect.mjs'
Expand Down Expand Up @@ -32,6 +32,8 @@ const server = createServer(async (req, res) => {
const fullUrl = new URL(req.url, `http://localhost:${server.address().port}`)

switch (fullUrl.pathname) {
case '/fetch/content-encoding/resources/foo.octetstream.gz':
case '/fetch/content-encoding/resources/foo.text.gz':
case '/fetch/api/resources/cors-top.txt':
case '/fetch/api/resources/top.txt':
case '/mimesniff/mime-types/resources/generated-mime-types.json':
Expand All @@ -47,6 +49,23 @@ const server = createServer(async (req, res) => {
case '/fetch/data-urls/resources/data-urls.json':
case '/fetch/api/resources/empty.txt':
case '/fetch/api/resources/data.json': {
// If this specific resources requires custom headers
const customHeadersPath = join(tests, fullUrl.pathname + '.headers')
if (existsSync(customHeadersPath)) {
const headers = readFileSync(customHeadersPath, 'utf-8')
.trim()
.split(/\r?\n/g)
.map((h) => h.split(': '))

for (const [key, value] of headers) {
if (!key || !value) {
console.warn(`Skipping ${key}:${value} header pair`)
continue
}
res.setHeader(key, value)
}
}

// https://github.com/web-platform-tests/wpt/blob/6ae3f702a332e8399fab778c831db6b7dca3f1c6/fetch/api/resources/data.json
return createReadStream(join(tests, fullUrl.pathname))
.on('end', () => res.end())
Expand Down
16 changes: 16 additions & 0 deletions test/wpt/tests/fetch/content-encoding/gzip-body.any.js
@@ -0,0 +1,16 @@
// META: global=window,worker

const expectedDecompressedSize = 10500;
[
"text",
"octetstream"
].forEach(contentType => {
promise_test(async t => {
let response = await fetch(`resources/foo.${contentType}.gz`);
assert_true(response.ok);
let arrayBuffer = await response.arrayBuffer()
let u8 = new Uint8Array(arrayBuffer);
assert_equals(u8.length, expectedDecompressedSize);
}, `fetched gzip data with content type ${contentType} should be decompressed.`);
});

Binary file not shown.
@@ -0,0 +1,2 @@
Content-type: application/octet-stream
Content-Encoding: gzip
Binary file not shown.
@@ -0,0 +1,2 @@
Content-type: text/plain
Content-Encoding: gzip