Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 381e705

Browse filesBrowse files
MattiasBuelensruyadorno
authored andcommitted
test: update streams wpt
PR-URL: #56072 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
1 parent d352b04 commit 381e705
Copy full SHA for 381e705

File tree

Expand file treeCollapse file tree

11 files changed

+161
-29
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

11 files changed

+161
-29
lines changed
Open diff view settings
Collapse file

‎test/fixtures/wpt/README.md‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/README.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Last update:
2727
- performance-timeline: https://github.com/web-platform-tests/wpt/tree/94caab7038/performance-timeline
2828
- resource-timing: https://github.com/web-platform-tests/wpt/tree/22d38586d0/resource-timing
2929
- resources: https://github.com/web-platform-tests/wpt/tree/1e140d63ec/resources
30-
- streams: https://github.com/web-platform-tests/wpt/tree/2bd26e124c/streams
30+
- streams: https://github.com/web-platform-tests/wpt/tree/bc9dcbbf1a/streams
3131
- url: https://github.com/web-platform-tests/wpt/tree/67880a4eb8/url
3232
- user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing
3333
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
Collapse file

‎test/fixtures/wpt/streams/idlharness-shadowrealm.window.js‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/streams/idlharness-shadowrealm.window.js
-2Lines changed: 0 additions & 2 deletions
This file was deleted.
Collapse file

‎test/fixtures/wpt/streams/idlharness.any.js‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/streams/idlharness.any.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// META: global=window,worker
1+
// META: global=window,worker,shadowrealm-in-window
22
// META: script=/resources/WebIDLParser.js
33
// META: script=/resources/idlharness.js
44
// META: timeout=long
Collapse file

‎test/fixtures/wpt/streams/readable-byte-streams/general.any.js‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/streams/readable-byte-streams/general.any.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -870,11 +870,11 @@ promise_test(() => {
870870
start(c) {
871871
controller = c;
872872
},
873-
async pull() {
873+
pull() {
874874
byobRequestDefined.push(controller.byobRequest !== null);
875875
const initialByobRequest = controller.byobRequest;
876876

877-
const transferredView = await transferArrayBufferView(controller.byobRequest.view);
877+
const transferredView = transferArrayBufferView(controller.byobRequest.view);
878878
transferredView[0] = 0x01;
879879
controller.byobRequest.respondWithNewView(transferredView);
880880

@@ -2288,7 +2288,7 @@ promise_test(async t => {
22882288
await pullCalledPromise;
22892289

22902290
// Transfer the original BYOB request's buffer, and respond with a new view on that buffer
2291-
const transferredView = await transferArrayBufferView(controller.byobRequest.view);
2291+
const transferredView = transferArrayBufferView(controller.byobRequest.view);
22922292
const newView = transferredView.subarray(0, 1);
22932293
newView[0] = 42;
22942294

@@ -2328,7 +2328,7 @@ promise_test(async t => {
23282328
await pullCalledPromise;
23292329

23302330
// Transfer the original BYOB request's buffer, and respond with an empty view on that buffer
2331-
const transferredView = await transferArrayBufferView(controller.byobRequest.view);
2331+
const transferredView = transferArrayBufferView(controller.byobRequest.view);
23322332
const newView = transferredView.subarray(0, 0);
23332333

23342334
controller.close();
Collapse file
+54Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// META: global=window,worker,shadowrealm
2+
// META: script=../resources/test-utils.js
3+
'use strict';
4+
5+
// Tests which patch the global environment are kept separate to avoid
6+
// interfering with other tests.
7+
8+
promise_test(async (t) => {
9+
let controller;
10+
const rs = new ReadableStream({
11+
type: 'bytes',
12+
start(c) {
13+
controller = c;
14+
}
15+
});
16+
const reader = rs.getReader({mode: 'byob'});
17+
18+
const length = 0x4000;
19+
const buffer = new ArrayBuffer(length);
20+
const bigArray = new BigUint64Array(buffer, length - 8, 1);
21+
22+
const read1 = reader.read(new Uint8Array(new ArrayBuffer(0x100)));
23+
const read2 = reader.read(bigArray);
24+
25+
let flag = false;
26+
Object.defineProperty(Object.prototype, 'then', {
27+
get: t.step_func(() => {
28+
if (!flag) {
29+
flag = true;
30+
assert_equals(controller.byobRequest, null, 'byobRequest should be null after filling both views');
31+
}
32+
}),
33+
configurable: true
34+
});
35+
t.add_cleanup(() => {
36+
delete Object.prototype.then;
37+
});
38+
39+
controller.enqueue(new Uint8Array(0x110).fill(0x42));
40+
assert_true(flag, 'patched then() should be called');
41+
42+
// The first read() is filled entirely with 0x100 bytes
43+
const result1 = await read1;
44+
assert_false(result1.done, 'result1.done');
45+
assert_typed_array_equals(result1.value, new Uint8Array(0x100).fill(0x42), 'result1.value');
46+
47+
// The second read() is filled with the remaining 0x10 bytes
48+
const result2 = await read2;
49+
assert_false(result2.done, 'result2.done');
50+
assert_equals(result2.value.constructor, BigUint64Array, 'result2.value constructor');
51+
assert_equals(result2.value.byteOffset, length - 8, 'result2.value byteOffset');
52+
assert_equals(result2.value.length, 1, 'result2.value length');
53+
assert_array_equals([...result2.value], [0x42424242_42424242n], 'result2.value contents');
54+
}, 'Patched then() sees byobRequest after filling all pending pull-into descriptors');
Collapse file

‎test/fixtures/wpt/streams/readable-byte-streams/tee.any.js‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/streams/readable-byte-streams/tee.any.js
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,3 +934,36 @@ promise_test(async () => {
934934
assert_typed_array_equals(result4.value, new Uint8Array([0]).subarray(0, 0), 'second chunk from branch2 should be correct');
935935

936936
}, 'ReadableStream teeing with byte source: respond() and close() while both branches are pulling');
937+
938+
promise_test(async t => {
939+
let pullCount = 0;
940+
const arrayBuffer = new Uint8Array([0x01, 0x02, 0x03]).buffer;
941+
const enqueuedChunk = new Uint8Array(arrayBuffer, 2);
942+
assert_equals(enqueuedChunk.length, 1);
943+
assert_equals(enqueuedChunk.byteOffset, 2);
944+
const rs = new ReadableStream({
945+
type: 'bytes',
946+
pull(c) {
947+
++pullCount;
948+
if (pullCount === 1) {
949+
c.enqueue(enqueuedChunk);
950+
}
951+
}
952+
});
953+
954+
const [branch1, branch2] = rs.tee();
955+
const reader1 = branch1.getReader();
956+
const reader2 = branch2.getReader();
957+
958+
const [result1, result2] = await Promise.all([reader1.read(), reader2.read()]);
959+
assert_equals(result1.done, false, 'reader1 done');
960+
assert_equals(result2.done, false, 'reader2 done');
961+
962+
const view1 = result1.value;
963+
const view2 = result2.value;
964+
// The first stream has the transferred buffer, but the second stream has the
965+
// cloned buffer.
966+
const underlying = new Uint8Array([0x01, 0x02, 0x03]).buffer;
967+
assert_typed_array_equals(view1, new Uint8Array(underlying, 2), 'reader1 value');
968+
assert_typed_array_equals(view2, new Uint8Array([0x03]), 'reader2 value');
969+
}, 'ReadableStream teeing with byte source: reading an array with a byte offset should clone correctly');
Collapse file
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<html class="test-wait">
2+
<meta charset="utf-8">
3+
<script type="module">
4+
let a = window.open()
5+
try {
6+
let dir = await a.navigator.storage.getDirectory()
7+
let hdl = await dir.getFileHandle("7399d8cf-9ff9-494d-89eb-d3045f229c27", {"create": true})
8+
let map = new Map([[]])
9+
let b = ReadableStream.from(map)
10+
let c = await hdl.createWritable({ })
11+
await b.pipeTo(c, { }).catch(() => {
12+
// Error expected as we are not piping the right form of chunk to FileHandle
13+
})
14+
} finally {
15+
document.documentElement.classList.remove("test-wait")
16+
a.close()
17+
}
18+
</script>
Collapse file

‎test/fixtures/wpt/streams/readable-streams/owning-type-video-frame.any.js‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/streams/readable-streams/owning-type-video-frame.any.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// META: global=window,worker,shadowrealm
1+
// META: global=window,worker
22
// META: script=../resources/test-utils.js
33
// META: script=../resources/rs-utils.js
44
'use strict';
Collapse file

‎test/fixtures/wpt/streams/resources/rs-utils.js‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/streams/resources/rs-utils.js
+42-13Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
'use strict';
22
(function () {
3+
// Fake setInterval-like functionality in environments that don't have it
4+
class IntervalHandle {
5+
constructor(callback, delayMs) {
6+
this.callback = callback;
7+
this.delayMs = delayMs;
8+
this.cancelled = false;
9+
Promise.resolve().then(() => this.check());
10+
}
11+
12+
async check() {
13+
while (true) {
14+
await new Promise(resolve => step_timeout(resolve, this.delayMs));
15+
if (this.cancelled) {
16+
return;
17+
}
18+
this.callback();
19+
}
20+
}
21+
22+
cancel() {
23+
this.cancelled = true;
24+
}
25+
}
26+
27+
let localSetInterval, localClearInterval;
28+
if (typeof globalThis.setInterval !== "undefined" &&
29+
typeof globalThis.clearInterval !== "undefined") {
30+
localSetInterval = globalThis.setInterval;
31+
localClearInterval = globalThis.clearInterval;
32+
} else {
33+
localSetInterval = function setInterval(callback, delayMs) {
34+
return new IntervalHandle(callback, delayMs);
35+
}
36+
localClearInterval = function clearInterval(handle) {
37+
handle.cancel();
38+
}
39+
}
340

441
class RandomPushSource {
542
constructor(toPush) {
@@ -18,12 +55,12 @@
1855
}
1956

2057
if (!this.started) {
21-
this._intervalHandle = setInterval(writeChunk, 2);
58+
this._intervalHandle = localSetInterval(writeChunk, 2);
2259
this.started = true;
2360
}
2461

2562
if (this.paused) {
26-
this._intervalHandle = setInterval(writeChunk, 2);
63+
this._intervalHandle = localSetInterval(writeChunk, 2);
2764
this.paused = false;
2865
}
2966

@@ -37,7 +74,7 @@
3774

3875
if (source.toPush > 0 && source.pushed > source.toPush) {
3976
if (source._intervalHandle) {
40-
clearInterval(source._intervalHandle);
77+
localClearInterval(source._intervalHandle);
4178
source._intervalHandle = undefined;
4279
}
4380
source.closed = true;
@@ -55,7 +92,7 @@
5592

5693
if (this.started) {
5794
this.paused = true;
58-
clearInterval(this._intervalHandle);
95+
localClearInterval(this._intervalHandle);
5996
this._intervalHandle = undefined;
6097
} else {
6198
throw new Error('Can\'t pause reading an unstarted source.');
@@ -178,15 +215,7 @@
178215
}
179216

180217
function transferArrayBufferView(view) {
181-
const noopByteStream = new ReadableStream({
182-
type: 'bytes',
183-
pull(c) {
184-
c.byobRequest.respond(c.byobRequest.view.byteLength);
185-
c.close();
186-
}
187-
});
188-
const reader = noopByteStream.getReader({ mode: 'byob' });
189-
return reader.read(view).then((result) => result.value);
218+
return structuredClone(view, { transfer: [view.buffer] });
190219
}
191220

192221
self.RandomPushSource = RandomPushSource;
Collapse file

‎test/fixtures/wpt/streams/transferable/transfer-with-messageport.window.js‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/streams/transferable/transfer-with-messageport.window.js
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ async function transferMessagePortWith(constructor) {
105105
await transferMessagePortWithOrder3(new constructor());
106106
}
107107

108-
async function advancedTransferMesagePortWith(constructor) {
108+
async function advancedTransferMessagePortWith(constructor) {
109109
await transferMessagePortWithOrder4(new constructor());
110110
await transferMessagePortWithOrder5(new constructor());
111111
await transferMessagePortWithOrder6(new constructor());
@@ -166,7 +166,7 @@ async function mixedTransferMessagePortWithOrder3() {
166166
);
167167
}
168168

169-
async function mixedTransferMesagePortWith() {
169+
async function mixedTransferMessagePortWith() {
170170
await mixedTransferMessagePortWithOrder1();
171171
await mixedTransferMessagePortWithOrder2();
172172
await mixedTransferMessagePortWithOrder3();
@@ -185,19 +185,19 @@ promise_test(async t => {
185185
}, "Transferring a MessagePort with a TransformStream should set `.ports`");
186186

187187
promise_test(async t => {
188-
await transferMessagePortWith(ReadableStream);
188+
await advancedTransferMessagePortWith(ReadableStream);
189189
}, "Transferring a MessagePort with a ReadableStream should set `.ports`, advanced");
190190

191191
promise_test(async t => {
192-
await transferMessagePortWith(WritableStream);
192+
await advancedTransferMessagePortWith(WritableStream);
193193
}, "Transferring a MessagePort with a WritableStream should set `.ports`, advanced");
194194

195195
promise_test(async t => {
196-
await transferMessagePortWith(TransformStream);
196+
await advancedTransferMessagePortWith(TransformStream);
197197
}, "Transferring a MessagePort with a TransformStream should set `.ports`, advanced");
198198

199199
promise_test(async t => {
200-
await mixedTransferMesagePortWith();
200+
await mixedTransferMessagePortWith();
201201
}, "Transferring a MessagePort with multiple streams should set `.ports`");
202202

203203
test(() => {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.