gecko-dev/testing/web-platform/tests/streams/transform-streams/terminate.any.js
Jason Orendorff 47519c94b2 Bug 1513570 - Part 1: Adapt stream tests to run in the shell. r=Ms2ger
We don't support byte streams, transform streams, writable streams, or piping
yet, but we will, and in the meantime our own meta files disable those tests
for us.

Differential Revision: https://phabricator.services.mozilla.com/D14314

--HG--
extra : moz-landing-system : lando
2018-12-14 18:14:56 +00:00

100 lines
3.4 KiB
JavaScript

// META: global=worker,jsshell
// META: script=../resources/recording-streams.js
// META: script=../resources/test-utils.js
'use strict';
promise_test(t => {
const ts = recordingTransformStream({}, undefined, { highWaterMark: 0 });
const rs = new ReadableStream({
start(controller) {
controller.enqueue(0);
}
});
let pipeToRejected = false;
const pipeToPromise = promise_rejects(t, new TypeError(), rs.pipeTo(ts.writable), 'pipeTo should reject').then(() => {
pipeToRejected = true;
});
return delay(0).then(() => {
assert_array_equals(ts.events, [], 'transform() should have seen no chunks');
assert_false(pipeToRejected, 'pipeTo() should not have rejected yet');
ts.controller.terminate();
return pipeToPromise;
}).then(() => {
assert_array_equals(ts.events, [], 'transform() should still have seen no chunks');
assert_true(pipeToRejected, 'pipeToRejected must be true');
});
}, 'controller.terminate() should error pipeTo()');
promise_test(t => {
const ts = recordingTransformStream({}, undefined, { highWaterMark: 1 });
const rs = new ReadableStream({
start(controller) {
controller.enqueue(0);
controller.enqueue(1);
}
});
const pipeToPromise = rs.pipeTo(ts.writable);
return delay(0).then(() => {
assert_array_equals(ts.events, ['transform', 0], 'transform() should have seen one chunk');
ts.controller.terminate();
return promise_rejects(t, new TypeError(), pipeToPromise, 'pipeTo() should reject');
}).then(() => {
assert_array_equals(ts.events, ['transform', 0], 'transform() should still have seen only one chunk');
});
}, 'controller.terminate() should prevent remaining chunks from being processed');
test(() => {
new TransformStream({
start(controller) {
controller.enqueue(0);
controller.terminate();
assert_throws(new TypeError(), () => controller.enqueue(1), 'enqueue should throw');
}
});
}, 'controller.enqueue() should throw after controller.terminate()');
const error1 = new Error('error1');
error1.name = 'error1';
promise_test(t => {
const ts = new TransformStream({
start(controller) {
controller.enqueue(0);
controller.terminate();
controller.error(error1);
}
});
return Promise.all([
promise_rejects(t, new TypeError(), ts.writable.abort(), 'abort() should reject with a TypeError'),
promise_rejects(t, error1, ts.readable.cancel(), 'cancel() should reject with error1'),
promise_rejects(t, error1, ts.readable.getReader().closed, 'closed should reject with error1')
]);
}, 'controller.error() after controller.terminate() with queued chunk should error the readable');
promise_test(t => {
const ts = new TransformStream({
start(controller) {
controller.terminate();
controller.error(error1);
}
});
return Promise.all([
promise_rejects(t, new TypeError(), ts.writable.abort(), 'abort() should reject with a TypeError'),
ts.readable.cancel(),
ts.readable.getReader().closed
]);
}, 'controller.error() after controller.terminate() without queued chunk should do nothing');
promise_test(() => {
const ts = new TransformStream({
flush(controller) {
controller.terminate();
}
});
const writer = ts.writable.getWriter();
return Promise.all([
writer.close(),
writer.closed,
ts.readable.getReader().closed
]);
}, 'controller.terminate() inside flush() should not prevent writer.close() from succeeding');