mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-20 16:28:54 +00:00
Tests/LibWeb: Add test to prove we can pipe to a WriteableStream
This proves our ability to pipe the current ReadableStream to a given WriteableStream.
This commit is contained in:
parent
d3b2cd8ab6
commit
8ff52582ce
Notes:
sideshowbarker
2024-07-17 05:02:42 +09:00
Author: https://github.com/kennethmyhra
Commit: 8ff52582ce
Pull-request: https://github.com/SerenityOS/serenity/pull/23869
Reviewed-by: https://github.com/shannonbooth ✅
2 changed files with 50 additions and 0 deletions
47
Tests/LibWeb/Text/input/Streams/ReadableStream-pipeTo.html
Normal file
47
Tests/LibWeb/Text/input/Streams/ReadableStream-pipeTo.html
Normal file
|
@ -0,0 +1,47 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
const CHUNK1 = "abcdefghijklmnopqrstuvwxyz";
|
||||
const CHUNK2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
const CHUNK3 = "0123456789!@#$%^&*()-=_+,<";
|
||||
|
||||
asyncTest(done => {
|
||||
const writableStream = new WritableStream(
|
||||
{
|
||||
write(chunk) {
|
||||
return new Promise((resolve) => {
|
||||
const textDecoder = new TextDecoder("utf-8");
|
||||
println(textDecoder.decode(new Uint8Array(chunk)));
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
const stream = new ReadableStream({
|
||||
start(controller) {
|
||||
pullCount = 0;
|
||||
},
|
||||
|
||||
pull(controller) {
|
||||
const textEncoder = new TextEncoder();
|
||||
|
||||
++pullCount;
|
||||
|
||||
if (pullCount == 1) {
|
||||
controller.enqueue(textEncoder.encode(CHUNK1));
|
||||
} else if (pullCount == 2) {
|
||||
controller.enqueue(textEncoder.encode(CHUNK2));
|
||||
} else if (pullCount == 3) {
|
||||
controller.enqueue(textEncoder.encode(CHUNK3));
|
||||
} else {
|
||||
controller.close();
|
||||
}
|
||||
},
|
||||
|
||||
cancel() {},
|
||||
});
|
||||
|
||||
stream.pipeTo(writableStream).then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue