From 3bdcaf1cf62d3d5aaef026f726776e47bb37542b Mon Sep 17 00:00:00 2001 From: Taym Haddadi Date: Tue, 15 Apr 2025 22:44:06 +0200 Subject: [PATCH] Add pipeTo with different readers type Signed-off-by: Taym Haddadi --- .../mozilla/stream/pipeTo-reader-locks.any.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/wpt/mozilla/tests/mozilla/stream/pipeTo-reader-locks.any.js diff --git a/tests/wpt/mozilla/tests/mozilla/stream/pipeTo-reader-locks.any.js b/tests/wpt/mozilla/tests/mozilla/stream/pipeTo-reader-locks.any.js new file mode 100644 index 00000000000..e4ef1799ff0 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/stream/pipeTo-reader-locks.any.js @@ -0,0 +1,33 @@ +'use strict'; + +promise_test(t => { + const rs = new ReadableStream(); + const ws = new WritableStream(); + + rs.getReader(); + + assert_true(rs.locked, 'sanity check: the ReadableStream starts locked'); + assert_false(ws.locked, 'sanity check: the WritableStream does not start locked'); + + return promise_rejects_js(t, TypeError, rs.pipeTo(ws)).then(() => { + assert_false(ws.locked, 'the WritableStream must still be unlocked'); + }); + +}, 'pipeTo must fail if the ReadableStream is locked with a Default reader, and not lock the WritableStream'); + + +promise_test(t => { + const rs = new ReadableStream({ + type: 'bytes', + pull(controller) { + // No chunks are enqueued; the stream remains readable but empty. + } + }); + const ws = new WritableStream(); + rs.getReader({ mode: 'byob' }); + assert_true(rs.locked, 'sanity check: the ReadableStream is locked by the BYOB reader'); + assert_false(ws.locked, 'sanity check: the WritableStream starts unlocked'); + return promise_rejects_js(t, TypeError, rs.pipeTo(ws)).then(() => { + assert_false(ws.locked, 'the WritableStream must remain unlocked after pipeTo rejection'); + }); +}, 'pipeTo must fail if the ReadableStream is locked with a BYOB reader, and must not lock the WritableStream');