mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 02:13:56 +09:00
LibWeb: Change hardcoded compression test to round trip
As compression is not always deterministic, we cannot hardcode what it'll be like, do a round trip instead.
This commit is contained in:
parent
3d3e77cd3e
commit
1612c1688e
Notes:
github-actions[bot]
2025-03-19 12:49:15 +00:00
Author: https://github.com/devgianlu
Commit: 1612c1688e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3755
Reviewed-by: https://github.com/gmta ✅
Reviewed-by: https://github.com/trflynn89
4 changed files with 80 additions and 34 deletions
|
@ -1,3 +0,0 @@
|
|||
format=deflate: eJwLT83JUchIzcnJV0grykzNSylWBABGEQb1
|
||||
format=deflate-raw: C0/NyVHISM3JyVdIK8pMzUspVgQA
|
||||
format=gzip: H4sIAAAAAAADAwtPzclRyEjNyclXSCvKTM1LKVYEAHN0w4sTAAAA
|
24
Tests/LibWeb/Text/expected/Compression/round-trip.txt
Normal file
24
Tests/LibWeb/Text/expected/Compression/round-trip.txt
Normal file
|
@ -0,0 +1,24 @@
|
|||
prefix=120,156
|
||||
equal=false
|
||||
format=deflate: Well hello friends!
|
||||
--------------
|
||||
prefix=
|
||||
equal=false
|
||||
format=deflate-raw: Well hello friends!
|
||||
--------------
|
||||
prefix=31,139
|
||||
equal=false
|
||||
format=gzip: Well hello friends!
|
||||
--------------
|
||||
prefix=120,156
|
||||
equal=false
|
||||
format=deflate: Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!
|
||||
--------------
|
||||
prefix=
|
||||
equal=false
|
||||
format=deflate-raw: Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!
|
||||
--------------
|
||||
prefix=31,139
|
||||
equal=false
|
||||
format=gzip: Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!Well hello friends!
|
||||
--------------
|
|
@ -1,31 +0,0 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
asyncTest(async done => {
|
||||
const text = "Well hello friends!";
|
||||
|
||||
for (const format of ["deflate", "deflate-raw", "gzip"]) {
|
||||
let stream = new Blob([text]).stream();
|
||||
|
||||
let compressor = stream.pipeThrough(new CompressionStream(format));
|
||||
let reader = compressor.getReader();
|
||||
|
||||
let buffer = new ArrayBuffer(256);
|
||||
let offset = 0;
|
||||
|
||||
while (true) {
|
||||
let result = await reader.read();
|
||||
if (result.done) {
|
||||
break;
|
||||
}
|
||||
|
||||
new Uint8Array(buffer).set(result.value, offset);
|
||||
offset += result.value.byteLength;
|
||||
}
|
||||
|
||||
let result = new Uint8Array(buffer, 0, offset).toBase64();
|
||||
println(`format=${format}: ${result}`);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
</script>
|
56
Tests/LibWeb/Text/input/Compression/round-trip.html
Normal file
56
Tests/LibWeb/Text/input/Compression/round-trip.html
Normal file
|
@ -0,0 +1,56 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
function readStream(reader) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let chunks = [];
|
||||
reader.read().then(function pump({value, done}) {
|
||||
if (done) {
|
||||
let blob = new Blob(chunks);
|
||||
blob.arrayBuffer().then((b) => resolve(new Uint8Array(b, 0, blob.size))).catch(reject)
|
||||
return;
|
||||
}
|
||||
chunks.push(value);
|
||||
reader.read().then(pump);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function compress(data, format) {
|
||||
let stream = new Blob([data]).stream();
|
||||
let compressor = stream.pipeThrough(new CompressionStream(format));
|
||||
let reader = compressor.getReader();
|
||||
return readStream(reader);
|
||||
}
|
||||
|
||||
function decompress(data, format) {
|
||||
let stream = new Blob([data]).stream();
|
||||
let decompressor = stream.pipeThrough(new DecompressionStream(format));
|
||||
let reader = decompressor.getReader();
|
||||
return readStream(reader);
|
||||
}
|
||||
|
||||
async function roundTrip(data) {
|
||||
let expectedPrefixLengths = {
|
||||
'deflate': 2,
|
||||
'deflate-raw': 0,
|
||||
'gzip': 2
|
||||
}
|
||||
|
||||
for (const format of ["deflate", "deflate-raw", "gzip"]) {
|
||||
let compressed = await compress(data, format);
|
||||
println(`prefix=${compressed.slice(0, expectedPrefixLengths[format])}`)
|
||||
println(`equal=${data === compressed}`)
|
||||
|
||||
let decompressed = await decompress(compressed, format);
|
||||
let result = new TextDecoder().decode(decompressed);
|
||||
println(`format=${format}: ${result}`);
|
||||
println('--------------')
|
||||
}
|
||||
}
|
||||
|
||||
asyncTest(async done => {
|
||||
await roundTrip('Well hello friends!')
|
||||
await roundTrip('Well hello friends!'.repeat(100))
|
||||
done();
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue