Skip to content

Commit

Permalink
Bug 1705848 [wpt PR 28557] - Streams: tests for readable byte stream …
Browse files Browse the repository at this point in the history
…fixes, a=testonly

Automatic update from web-platform-tests
Streams: tests for readable byte stream fixes

Follows whatwg/streams#1123.
--

wpt-commits: 7b29ee36cc22bdad06b4f98df73358ca959fe0a7
wpt-pr: 28557
  • Loading branch information
MattiasBuelens authored and moz-wptsync-bot committed May 28, 2021
1 parent 63bf99b commit 19d39e8
Show file tree
Hide file tree
Showing 5 changed files with 412 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ async_test(t => {
async_test(t => {
const stream = new ReadableStream({
pull: t.step_func_done(c => {
c.close();

// Detach it by reading into it
reader.read(c.byobRequest.view);

c.close();

assert_throws_js(TypeError, () => c.byobRequest.respond(0),
'respond() must throw if the corresponding view has become detached');
}),
Expand Down Expand Up @@ -191,7 +191,7 @@ async_test(t => {
async_test(t => {
const stream = new ReadableStream({
pull: t.step_func_done(c => {
const view = new Uint8Array(new ArrayBuffer(10), 0, 0);
const view = new Uint8Array(c.byobRequest.view.buffer, 0, 0);

assert_throws_js(TypeError, () => c.byobRequest.respondWithNewView(view));
}),
Expand All @@ -206,12 +206,51 @@ async_test(t => {
async_test(t => {
const stream = new ReadableStream({
pull: t.step_func_done(c => {
const view = new Uint8Array(new ArrayBuffer(10), 0, 3);

assert_throws_js(RangeError, () => c.byobRequest.respondWithNewView(view));
}),
type: 'bytes'
});
const reader = stream.getReader({ mode: 'byob' });

reader.read(new Uint8Array([4, 5, 6]));
}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view\'s buffer has a ' +
'different length (in the readable state)');

async_test(t => {
const stream = new ReadableStream({
pull: t.step_func_done(c => {
const view = new Uint8Array(c.byobRequest.view.buffer, 0, 4);
view[0] = 20;
view[1] = 21;
view[2] = 22;
view[3] = 23;

assert_throws_js(RangeError, () => c.byobRequest.respondWithNewView(view));
}),
type: 'bytes'
});
const reader = stream.getReader({ mode: 'byob' });

const buffer = new ArrayBuffer(10);
const view = new Uint8Array(buffer, 0, 3);
view[0] = 10;
view[1] = 11;
view[2] = 12;
reader.read(view);
}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view has a larger length ' +
'(in the readable state)');

async_test(t => {
const stream = new ReadableStream({
pull: t.step_func_done(c => {
c.close();

// Detach it by reading into it
const view = new Uint8Array([1, 2, 3]);
reader.read(view);

c.close();

assert_throws_js(TypeError, () => c.byobRequest.respondWithNewView(view));
}),
type: 'bytes'
Expand All @@ -229,7 +268,7 @@ async_test(t => {

c.close();

assert_throws_js(TypeError, () => c.byobRequest.respondWithNewView(view));
assert_throws_js(RangeError, () => c.byobRequest.respondWithNewView(view));
}),
type: 'bytes'
});
Expand All @@ -242,7 +281,7 @@ async_test(t => {
async_test(t => {
const stream = new ReadableStream({
pull: t.step_func_done(c => {
const view = new Uint8Array(new ArrayBuffer(10), 0, 0);
const view = new Uint8Array(c.byobRequest.view.buffer, 0, 1);

c.close();

Expand All @@ -253,5 +292,58 @@ async_test(t => {
const reader = stream.getReader({ mode: 'byob' });

reader.read(new Uint8Array([4, 5, 6]));
}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view is zero-length on a ' +
'non-zero-length buffer (in the closed state)');
}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view is non-zero-length ' +
'(in the closed state)');

async_test(t => {
const stream = new ReadableStream({
pull: t.step_func_done(c => {
const view = new Uint8Array(new ArrayBuffer(10), 0, 0);

c.close();

assert_throws_js(RangeError, () => c.byobRequest.respondWithNewView(view));
}),
type: 'bytes'
});
const reader = stream.getReader({ mode: 'byob' });

reader.read(new Uint8Array([4, 5, 6]));
}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view\'s buffer has a ' +
'different length (in the closed state)');

async_test(t => {
const stream = new ReadableStream({
pull: t.step_func_done(c => {
// Detach it by reading into it
reader.read(c.byobRequest.view);

assert_throws_js(TypeError, () => c.enqueue(new Uint8Array([1])),
'enqueue() must throw if the BYOB request\'s buffer has become detached');
}),
type: 'bytes'
});
const reader = stream.getReader({ mode: 'byob' });

reader.read(new Uint8Array([4, 5, 6]));
}, 'ReadableStream with byte source: enqueue() throws if the BYOB request\'s buffer has been detached (in the ' +
'readable state)');

async_test(t => {
const stream = new ReadableStream({
pull: t.step_func_done(c => {
c.close();

// Detach it by reading into it
reader.read(c.byobRequest.view);

assert_throws_js(TypeError, () => c.enqueue(new Uint8Array([1])),
'enqueue() must throw if the BYOB request\'s buffer has become detached');
}),
type: 'bytes'
});
const reader = stream.getReader({ mode: 'byob' });

reader.read(new Uint8Array([4, 5, 6]));
}, 'ReadableStream with byte source: enqueue() throws if the BYOB request\'s buffer has been detached (in the ' +
'closed state)');
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ promise_test(async t => {
const error = new Error('cannot proceed');
const rs = new ReadableStream({
type: 'bytes',
pull(controller) {
t.step(() => {
const buffer = controller.byobRequest.view.buffer;
// Detach the buffer.
postMessage(buffer, '*', [buffer]);
pull: t.step_func((controller) => {
const buffer = controller.byobRequest.view.buffer;
// Detach the buffer.
postMessage(buffer, '*', [buffer]);

// Try to enqueue with a new buffer.
assert_throws_js(TypeError, () => controller.enqueue(new Uint8Array([42])));
// Try to enqueue with a new buffer.
assert_throws_js(TypeError, () => controller.enqueue(new Uint8Array([42])));

// If we got here the test passed.
controller.error(error);
});
}
// If we got here the test passed.
controller.error(error);
})
});
const reader = rs.getReader({ mode: 'byob' });
await promise_rejects_exactly(t, error, reader.read(new Uint8Array(1)));
Expand Down
Loading

0 comments on commit 19d39e8

Please sign in to comment.