Skip to content

Commit be61793

Browse files
Nahee-Parktargos
authored andcommitted
test: update wpt test for streams
PR-URL: #54129 Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 350e699 commit be61793

7 files changed

Lines changed: 107 additions & 38 deletions

File tree

‎test/fixtures/wpt/README.md‎

Lines changed: 1 addition & 1 deletion
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/17ebc3aea0/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/9b03282a99/streams
30+
- streams: https://github.com/web-platform-tests/wpt/tree/2bd26e124c/streams
3131
- url: https://github.com/web-platform-tests/wpt/tree/6a39784534/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

‎test/fixtures/wpt/streams/piping/abort.any.js‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,46 @@ for (const reason of [null, undefined, error1]) {
183183
},`(reason: '${reason}') all pending writes should complete on abort`);
184184
}
185185

186+
for(constreasonof[null,undefined,error1]){
187+
promise_test(asynct=>{
188+
letrejectPull;
189+
constpullPromise=newPromise((_,reject)=>{
190+
rejectPull=reject;
191+
});
192+
letrejectCancel;
193+
constcancelPromise=newPromise((_,reject)=>{
194+
rejectCancel=reject;
195+
});
196+
constrs=recordingReadableStream({
197+
asyncpull(){
198+
awaitPromise.race([
199+
pullPromise,
200+
cancelPromise,
201+
]);
202+
},
203+
cancel(reason){
204+
rejectCancel(reason);
205+
},
206+
});
207+
constws=newWritableStream();
208+
constabortController=newAbortController();
209+
constsignal=abortController.signal;
210+
constpipeToPromise=rs.pipeTo(ws,{ signal });
211+
pipeToPromise.catch(()=>{});// Prevent unhandled rejection.
212+
awaitdelay(0);
213+
abortController.abort(reason);
214+
rejectPull('should not catch pull rejection');
215+
awaitdelay(0);
216+
assert_equals(rs.eventsWithoutPulls.length,2,'cancel should have been called');
217+
assert_equals(rs.eventsWithoutPulls[0],'cancel','first event should be cancel');
218+
if(reason!==undefined){
219+
awaitpromise_rejects_exactly(t,reason,pipeToPromise,'pipeTo rejects with abort reason');
220+
}else{
221+
awaitpromise_rejects_dom(t,'AbortError',pipeToPromise,'pipeTo rejects with AbortError');
222+
}
223+
},`(reason: '${reason}') underlyingSource.cancel() should called when abort, even with pending pull`);
224+
}
225+
186226
promise_test(t=>{
187227
constrs=newReadableStream({
188228
pull(controller){

‎test/fixtures/wpt/streams/piping/detached-context-crash.html‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎test/fixtures/wpt/streams/readable-streams/cancel.any.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,28 @@ promise_test(() => {
234234
returnPromise.all([rs.cancel(),rs.getReader().closed]);
235235

236236
},'ReadableStream cancellation: cancelling before start finishes should prevent pull() from being called');
237+
238+
promise_test(async()=>{
239+
240+
constevents=[];
241+
242+
constpendingPromise=newPromise(()=>{});
243+
244+
constrs=newReadableStream({
245+
pull(){
246+
events.push('pull');
247+
returnpendingPromise;
248+
},
249+
cancel(){
250+
events.push('cancel');
251+
}
252+
});
253+
254+
constreader=rs.getReader();
255+
reader.read().catch(()=>{});// No await.
256+
awaitdelay(0);
257+
awaitPromise.all([reader.cancel(),reader.closed]);
258+
259+
assert_array_equals(events,['pull','cancel'],'cancel should have been called');
260+
261+
},'ReadableStream cancellation: underlyingSource.cancel() should called, even with pending pull');

‎test/fixtures/wpt/streams/readable-streams/from.any.js‎

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,44 +51,50 @@ const iterableFactories = [
5151

5252
['a sync iterable of values',()=>{
5353
constchunks=['a','b'];
54-
constit={
54+
constiterator={
5555
next(){
5656
return{
5757
done: chunks.length===0,
5858
value: chunks.shift()
5959
};
60-
},
61-
[Symbol.iterator]: ()=>it
60+
}
61+
};
62+
constiterable={
63+
[Symbol.iterator]: ()=>iterator
6264
};
63-
returnit;
65+
returniterable;
6466
}],
6567

6668
['a sync iterable of promises',()=>{
6769
constchunks=['a','b'];
68-
constit={
70+
constiterator={
6971
next(){
7072
returnchunks.length===0 ? {done: true} : {
7173
done: false,
7274
value: Promise.resolve(chunks.shift())
7375
};
74-
},
75-
[Symbol.iterator]: ()=>it
76+
}
77+
};
78+
constiterable={
79+
[Symbol.iterator]: ()=>iterator
7680
};
77-
returnit;
81+
returniterable;
7882
}],
7983

8084
['an async iterable',()=>{
8185
constchunks=['a','b'];
82-
constit={
86+
constasyncIterator={
8387
next(){
8488
returnPromise.resolve({
8589
done: chunks.length===0,
8690
value: chunks.shift()
8791
})
88-
},
89-
[Symbol.asyncIterator]: ()=>it
92+
}
93+
};
94+
constasyncIterable={
95+
[Symbol.asyncIterator]: ()=>asyncIterator
9096
};
91-
returnit;
97+
returnasyncIterable;
9298
}],
9399

94100
['a ReadableStream',()=>{
@@ -186,6 +192,18 @@ test(t => {
186192
assert_throws_exactly(theError,()=>ReadableStream.from(iterable),'from() should re-throw the error');
187193
},`ReadableStream.from ignores @@iterator if @@asyncIterator exists`);
188194

195+
test(()=>{
196+
consttheError=newError('a unique string');
197+
constiterable={
198+
[Symbol.asyncIterator]: null,
199+
[Symbol.iterator](){
200+
throwtheError
201+
}
202+
};
203+
204+
assert_throws_exactly(theError,()=>ReadableStream.from(iterable),'from() should re-throw the error');
205+
},`ReadableStream.from ignores a null @@asyncIterator`);
206+
189207
promise_test(async()=>{
190208

191209
constiterable={

‎test/fixtures/wpt/versions.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"path": "resources"
6969
},
7070
"streams": {
71-
"commit": "9b03282a99ef2314c1c2d5050a105a74a2940019",
71+
"commit": "2bd26e124cf17b2f0a25c150794d640b07b2a870",
7272
"path": "streams"
7373
},
7474
"url": {

‎test/wpt/status/streams.json‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
"readable-streams/cross-realm-crash.window.js": {
1717
"skip": "Browser-specific test"
1818
},
19+
"readable-streams/from.any.js": {
20+
"fail": {
21+
"expected": [
22+
"ReadableStream.from ignores a null @@asyncIterator"
23+
]
24+
}
25+
},
1926
"readable-streams/owning-type-message-port.any.js": {
2027
"fail": {
2128
"note": "Readable streams with type owning are not yet supported",
@@ -40,6 +47,9 @@
4047
]
4148
}
4249
},
50+
"readable-streams/read-task-handling.window.js": {
51+
"skip": "Browser-specific test"
52+
},
4353
"transferable/deserialize-error.window.js": {
4454
"skip": "Browser-specific test"
4555
},
@@ -56,8 +66,5 @@
5666
},
5767
"transform-streams/invalid-realm.tentative.window.js": {
5868
"skip": "Browser-specific test"
59-
},
60-
"readable-streams/read-task-handling.window.js": {
61-
"skip": "Browser-specific test"
6269
}
6370
}

0 commit comments

Comments
 (0)