haikuwebkit/LayoutTests/streams/pipe-to.html

104 lines
5.9 KiB
HTML
Raw Permalink Normal View History

[Streams API] Implement pipeTo method in readable Stream https://bugs.webkit.org/show_bug.cgi?id=151588 Reviewed by Darin Adler. Source/WebCore: Implemented pipeTo method according to the reference implementation in the spec as the spec is not written yet. It can be found at https://github.com/whatwg/streams/blob/632b26a05f3106650b1ec91239ad5b012e6c64af/reference-implementation/lib/readable-stream.js#L75. Tests: streams/pipe-to.html streams/reference-implementation/brand-checks.html streams/reference-implementation/pipe-through.html streams/reference-implementation/pipe-to.html streams/reference-implementation/pipe-to-options.html streams/reference-implementation/readable-stream-templated * Modules/streams/ReadableStream.js: (doPipe): Internal function of pipeTo. (closeDest): Internal function of pipeTo. (abortDest): Internal function of pipeTo. (pipeTo): Implemented as per spec with some other internal functions as helpers. LayoutTests: Test "Piping to a writable stream that does not consume the writes fast enough exerts backpressure on the source" was moved to its own file because it causes timing issues. * streams/reference-implementation/pipe-to.html: Moved "Piping to a writable stream that does not consume the writes fast enough exerts backpressure on the source" test to its own file. * streams/pipe-to.html: Added with "Piping to a writable stream that does not consume the writes fast enough exerts backpressure on the source" test. * streams/reference-implementation/brand-checks.html: Fixed issue with the creation of a ReadableStreamReader. * streams/pipe-to-expected.txt: * streams/reference-implementation/brand-checks-expected.txt: * streams/reference-implementation/pipe-through-expected.txt: * streams/reference-implementation/pipe-to-expected.txt: * streams/reference-implementation/pipe-to-options-expected.txt: * streams/reference-implementation/readable-stream-templated-expected.txt: Expectations. * platform/mac/TestExpectations: * platform/win/TestExpectations: Flagged pipe-to test because of webkit.org/b/147933. Canonical link: https://commits.webkit.org/169726@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192765 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-11-24 18:47:19 +00:00
<!DOCTYPE html>
<script src='../resources/testharness.js'></script>
<script src='../resources/testharnessreport.js'></script>
<script src='reference-implementation/resources/streams-utils.js'></script>
<script>
[Streams API] Fix cosmetic things after importing spec tests https://bugs.webkit.org/show_bug.cgi?id=152479 Reviewed by Youenn Fablet. Spec version are mainly updated in this patch as it wasn't done when importing tests from the spec. Some other minor changes were done, as renumbering some tests, removing some orphan expectations and other styling issues. * streams/brand-checks.html: * streams/pipe-to.html: * streams/readable-stream-controller-error.html: * streams/readable-stream-pipeThrough.html: * streams/readable-stream-reader-read.html: * streams/reference-implementation/abstract-ops.html: * streams/reference-implementation/bad-strategies.html: * streams/reference-implementation/bad-underlying-sinks.html: * streams/reference-implementation/bad-underlying-sources-expected.txt: Removed. * streams/reference-implementation/brand-checks.html: * streams/reference-implementation/byte-length-queuing-strategy.html: * streams/reference-implementation/count-queuing-strategy.html: * streams/reference-implementation/pipe-through.html: * streams/reference-implementation/pipe-to-options.html: * streams/reference-implementation/pipe-to.html: * streams/reference-implementation/readable-stream-templated.html: * streams/reference-implementation/transform-stream-errors.html: * streams/reference-implementation/transform-stream.html: * streams/reference-implementation/writable-stream-abort.html: * streams/reference-implementation/writable-stream-expected.txt: * streams/reference-implementation/writable-stream.html: Canonical link: https://commits.webkit.org/170606@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@194366 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-12-22 18:20:49 +00:00
// This is updated till https://github.com/whatwg/streams/commit/4ba861e6f60c248060811830e11271c84b439cc3
[Streams API] Implement pipeTo method in readable Stream https://bugs.webkit.org/show_bug.cgi?id=151588 Reviewed by Darin Adler. Source/WebCore: Implemented pipeTo method according to the reference implementation in the spec as the spec is not written yet. It can be found at https://github.com/whatwg/streams/blob/632b26a05f3106650b1ec91239ad5b012e6c64af/reference-implementation/lib/readable-stream.js#L75. Tests: streams/pipe-to.html streams/reference-implementation/brand-checks.html streams/reference-implementation/pipe-through.html streams/reference-implementation/pipe-to.html streams/reference-implementation/pipe-to-options.html streams/reference-implementation/readable-stream-templated * Modules/streams/ReadableStream.js: (doPipe): Internal function of pipeTo. (closeDest): Internal function of pipeTo. (abortDest): Internal function of pipeTo. (pipeTo): Implemented as per spec with some other internal functions as helpers. LayoutTests: Test "Piping to a writable stream that does not consume the writes fast enough exerts backpressure on the source" was moved to its own file because it causes timing issues. * streams/reference-implementation/pipe-to.html: Moved "Piping to a writable stream that does not consume the writes fast enough exerts backpressure on the source" test to its own file. * streams/pipe-to.html: Added with "Piping to a writable stream that does not consume the writes fast enough exerts backpressure on the source" test. * streams/reference-implementation/brand-checks.html: Fixed issue with the creation of a ReadableStreamReader. * streams/pipe-to-expected.txt: * streams/reference-implementation/brand-checks-expected.txt: * streams/reference-implementation/pipe-through-expected.txt: * streams/reference-implementation/pipe-to-expected.txt: * streams/reference-implementation/pipe-to-options-expected.txt: * streams/reference-implementation/readable-stream-templated-expected.txt: Expectations. * platform/mac/TestExpectations: * platform/win/TestExpectations: Flagged pipe-to test because of webkit.org/b/147933. Canonical link: https://commits.webkit.org/169726@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192765 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-11-24 18:47:19 +00:00
// This test is alone here for timing reasons though it should be at streams/reference-implementation/pipe-to.html.
var test24 = async_test('Piping to a writable stream that does not consume the writes fast enough exerts backpressure on the source');
test24.step(function() {
const timeoutMultiplier = 15;
[Streams API] Implement pipeTo method in readable Stream https://bugs.webkit.org/show_bug.cgi?id=151588 Reviewed by Darin Adler. Source/WebCore: Implemented pipeTo method according to the reference implementation in the spec as the spec is not written yet. It can be found at https://github.com/whatwg/streams/blob/632b26a05f3106650b1ec91239ad5b012e6c64af/reference-implementation/lib/readable-stream.js#L75. Tests: streams/pipe-to.html streams/reference-implementation/brand-checks.html streams/reference-implementation/pipe-through.html streams/reference-implementation/pipe-to.html streams/reference-implementation/pipe-to-options.html streams/reference-implementation/readable-stream-templated * Modules/streams/ReadableStream.js: (doPipe): Internal function of pipeTo. (closeDest): Internal function of pipeTo. (abortDest): Internal function of pipeTo. (pipeTo): Implemented as per spec with some other internal functions as helpers. LayoutTests: Test "Piping to a writable stream that does not consume the writes fast enough exerts backpressure on the source" was moved to its own file because it causes timing issues. * streams/reference-implementation/pipe-to.html: Moved "Piping to a writable stream that does not consume the writes fast enough exerts backpressure on the source" test to its own file. * streams/pipe-to.html: Added with "Piping to a writable stream that does not consume the writes fast enough exerts backpressure on the source" test. * streams/reference-implementation/brand-checks.html: Fixed issue with the creation of a ReadableStreamReader. * streams/pipe-to-expected.txt: * streams/reference-implementation/brand-checks-expected.txt: * streams/reference-implementation/pipe-through-expected.txt: * streams/reference-implementation/pipe-to-expected.txt: * streams/reference-implementation/pipe-to-options-expected.txt: * streams/reference-implementation/readable-stream-templated-expected.txt: Expectations. * platform/mac/TestExpectations: * platform/win/TestExpectations: Flagged pipe-to test because of webkit.org/b/147933. Canonical link: https://commits.webkit.org/169726@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192765 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-11-24 18:47:19 +00:00
var desiredSizes = [];
var rs = new ReadableStream({
start: function(c) {
setTimeout(test24.step_func(function() { enqueue('a'); }), 100 * timeoutMultiplier);
setTimeout(test24.step_func(function() { enqueue('b'); }), 200 * timeoutMultiplier);
setTimeout(test24.step_func(function() { enqueue('c'); }), 300 * timeoutMultiplier);
setTimeout(test24.step_func(function() { enqueue('d'); }), 400 * timeoutMultiplier);
setTimeout(test24.step_func(function() { c.close(); }), 500 * timeoutMultiplier);
function enqueue(chunk) {
c.enqueue(chunk);
desiredSizes.push(c.desiredSize);
}
}
});
var chunksGivenToWrite = [];
var chunksFinishedWriting = [];
var startPromise = Promise.resolve();
var ws = new WritableStream({
start: function() {
return startPromise;
},
write: function(chunk) {
chunksGivenToWrite.push(chunk);
return new Promise(test24.step_func(function(resolve) {
setTimeout(test24.step_func(function() {
chunksFinishedWriting.push(chunk);
resolve();
}), 350 * timeoutMultiplier);
}));
}
});
startPromise.then(test24.step_func(function() {
rs.pipeTo(ws).then(test24.step_func(function() {
assert_array_equals(desiredSizes, [1, 1, 0, -1], 'backpressure was correctly exerted at the source');
assert_array_equals(chunksFinishedWriting, ['a', 'b', 'c', 'd'], 'all chunks were written');
test24.done();
}));
assert_equals(ws.state, 'writable', 'at t = 0 ms, ws should be writable');
setTimeout(test24.step_func(function() {
assert_equals(ws.state, 'waiting', 'at t = 125 ms, ws should be waiting');
assert_array_equals(chunksGivenToWrite, ['a'], 'at t = 125 ms, ws.write should have been called with one chunk');
assert_array_equals(chunksFinishedWriting, [], 'at t = 125 ms, no chunks should have finished writing');
// When 'a' (the very first chunk) was enqueued, it was immediately used to fulfill the outstanding read request
// promise, leaving room in the queue
assert_array_equals(desiredSizes, [1], 'at t = 125 ms, the one enqueued chunk in rs did not cause backpressure');
}), 125 * timeoutMultiplier);
setTimeout(test24.step_func(function() {
assert_equals(ws.state, 'waiting', 'at t = 225 ms, ws should be waiting');
assert_array_equals(chunksGivenToWrite, ['a'], 'at t = 225 ms, ws.write should have been called with one chunk');
assert_array_equals(chunksFinishedWriting, [], 'at t = 225 ms, no chunks should have finished writing');
// When 'b' was enqueued at 200 ms, the queue was also empty, since immediately after enqueuing 'a' at
// t = 100 ms, it was dequeued in order to fulfill the read() call that was made at time t = 0.
assert_array_equals(desiredSizes, [1, 1], 'at t = 225 ms, the two enqueued chunks in rs did not cause backpressure');
}), 225 * timeoutMultiplier);
setTimeout(test24.step_func(function() {
assert_equals(ws.state, 'waiting', 'at t = 325 ms, ws should be waiting');
assert_array_equals(chunksGivenToWrite, ['a'], 'at t = 325 ms, ws.write should have been called with one chunk');
assert_array_equals(chunksFinishedWriting, [], 'at t = 325 ms, no chunks should have finished writing');
// When 'c' was enqueued at 300 ms, the queue was again empty, since at time t = 200 ms when 'b' was enqueued,
// it was immediately dequeued in order to fulfill the second read() call that was made at time t = 0.
// However, this time there was no pending read request to whisk it away, so after the enqueue desired size is 0.
assert_array_equals(desiredSizes, [1, 1, 0], 'at t = 325 ms, the three enqueued chunks in rs did not cause backpressure');
}), 325 * timeoutMultiplier);
setTimeout(test24.step_func(function() {
assert_equals(ws.state, 'waiting', 'at t = 425 ms, ws should be waiting');
assert_array_equals(chunksGivenToWrite, ['a'], 'at t = 425 ms, ws.write should have been called with one chunk');
assert_array_equals(chunksFinishedWriting, [], 'at t = 425 ms, no chunks should have finished writing');
// When 'd' was enqueued at 400 ms, the queue was *not* empty. 'c' was still in it, since the write() of 'b' will
// not finish until t = 100 ms + 350 ms = 450 ms. Thus backpressure should have been exerted.
assert_array_equals(desiredSizes, [1, 1, 0, -1], 'at t = 425 ms, the fourth enqueued chunks in rs did cause backpressure');
}), 425 * timeoutMultiplier);
setTimeout(test24.step_func(function() {
assert_equals(ws.state, 'waiting', 'at t = 475 ms, ws should be waiting');
assert_array_equals(chunksGivenToWrite, ['a', 'b'], 'at t = 475 ms, ws.write should have been called with two chunks');
assert_array_equals(chunksFinishedWriting, ['a'], 'at t = 475 ms, one chunk should have finished writing');
}), 475 * timeoutMultiplier);
}));
});
</script>