11cb0ef41Sopenharmony_ci// META: global=window,worker 21cb0ef41Sopenharmony_ci'use strict'; 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_citest(() => { 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci new ReadableStream({}, new CountQueuingStrategy({ highWaterMark: 4 })); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci}, 'Can construct a readable stream with a valid CountQueuingStrategy'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cipromise_test(() => { 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci let controller; 131cb0ef41Sopenharmony_ci const rs = new ReadableStream( 141cb0ef41Sopenharmony_ci { 151cb0ef41Sopenharmony_ci start(c) { 161cb0ef41Sopenharmony_ci controller = c; 171cb0ef41Sopenharmony_ci } 181cb0ef41Sopenharmony_ci }, 191cb0ef41Sopenharmony_ci new CountQueuingStrategy({ highWaterMark: 0 }) 201cb0ef41Sopenharmony_ci ); 211cb0ef41Sopenharmony_ci const reader = rs.getReader(); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 0, '0 reads, 0 enqueues: desiredSize should be 0'); 241cb0ef41Sopenharmony_ci controller.enqueue('a'); 251cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -1, '0 reads, 1 enqueue: desiredSize should be -1'); 261cb0ef41Sopenharmony_ci controller.enqueue('b'); 271cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -2, '0 reads, 2 enqueues: desiredSize should be -2'); 281cb0ef41Sopenharmony_ci controller.enqueue('c'); 291cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -3, '0 reads, 3 enqueues: desiredSize should be -3'); 301cb0ef41Sopenharmony_ci controller.enqueue('d'); 311cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -4, '0 reads, 4 enqueues: desiredSize should be -4'); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci return reader.read() 341cb0ef41Sopenharmony_ci .then(result => { 351cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'a', done: false }, 361cb0ef41Sopenharmony_ci '1st read gives back the 1st chunk enqueued (queue now contains 3 chunks)'); 371cb0ef41Sopenharmony_ci return reader.read(); 381cb0ef41Sopenharmony_ci }) 391cb0ef41Sopenharmony_ci .then(result => { 401cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'b', done: false }, 411cb0ef41Sopenharmony_ci '2nd read gives back the 2nd chunk enqueued (queue now contains 2 chunks)'); 421cb0ef41Sopenharmony_ci return reader.read(); 431cb0ef41Sopenharmony_ci }) 441cb0ef41Sopenharmony_ci .then(result => { 451cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'c', done: false }, 461cb0ef41Sopenharmony_ci '3rd read gives back the 3rd chunk enqueued (queue now contains 1 chunk)'); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -1, '3 reads, 4 enqueues: desiredSize should be -1'); 491cb0ef41Sopenharmony_ci controller.enqueue('e'); 501cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -2, '3 reads, 5 enqueues: desiredSize should be -2'); 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci return reader.read(); 531cb0ef41Sopenharmony_ci }) 541cb0ef41Sopenharmony_ci .then(result => { 551cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'd', done: false }, 561cb0ef41Sopenharmony_ci '4th read gives back the 4th chunk enqueued (queue now contains 1 chunks)'); 571cb0ef41Sopenharmony_ci return reader.read(); 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci }).then(result => { 601cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'e', done: false }, 611cb0ef41Sopenharmony_ci '5th read gives back the 5th chunk enqueued (queue now contains 0 chunks)'); 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 0, '5 reads, 5 enqueues: desiredSize should be 0'); 641cb0ef41Sopenharmony_ci controller.enqueue('f'); 651cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -1, '5 reads, 6 enqueues: desiredSize should be -1'); 661cb0ef41Sopenharmony_ci controller.enqueue('g'); 671cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -2, '5 reads, 7 enqueues: desiredSize should be -2'); 681cb0ef41Sopenharmony_ci }); 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci}, 'Correctly governs a ReadableStreamController\'s desiredSize property (HWM = 0)'); 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_cipromise_test(() => { 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ci let controller; 751cb0ef41Sopenharmony_ci const rs = new ReadableStream( 761cb0ef41Sopenharmony_ci { 771cb0ef41Sopenharmony_ci start(c) { 781cb0ef41Sopenharmony_ci controller = c; 791cb0ef41Sopenharmony_ci } 801cb0ef41Sopenharmony_ci }, 811cb0ef41Sopenharmony_ci new CountQueuingStrategy({ highWaterMark: 1 }) 821cb0ef41Sopenharmony_ci ); 831cb0ef41Sopenharmony_ci const reader = rs.getReader(); 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 1, '0 reads, 0 enqueues: desiredSize should be 1'); 861cb0ef41Sopenharmony_ci controller.enqueue('a'); 871cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 0, '0 reads, 1 enqueue: desiredSize should be 0'); 881cb0ef41Sopenharmony_ci controller.enqueue('b'); 891cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -1, '0 reads, 2 enqueues: desiredSize should be -1'); 901cb0ef41Sopenharmony_ci controller.enqueue('c'); 911cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -2, '0 reads, 3 enqueues: desiredSize should be -2'); 921cb0ef41Sopenharmony_ci controller.enqueue('d'); 931cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -3, '0 reads, 4 enqueues: desiredSize should be -3'); 941cb0ef41Sopenharmony_ci 951cb0ef41Sopenharmony_ci return reader.read() 961cb0ef41Sopenharmony_ci .then(result => { 971cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'a', done: false }, 981cb0ef41Sopenharmony_ci '1st read gives back the 1st chunk enqueued (queue now contains 3 chunks)'); 991cb0ef41Sopenharmony_ci return reader.read(); 1001cb0ef41Sopenharmony_ci }) 1011cb0ef41Sopenharmony_ci .then(result => { 1021cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'b', done: false }, 1031cb0ef41Sopenharmony_ci '2nd read gives back the 2nd chunk enqueued (queue now contains 2 chunks)'); 1041cb0ef41Sopenharmony_ci return reader.read(); 1051cb0ef41Sopenharmony_ci }) 1061cb0ef41Sopenharmony_ci .then(result => { 1071cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'c', done: false }, 1081cb0ef41Sopenharmony_ci '3rd read gives back the 3rd chunk enqueued (queue now contains 1 chunk)'); 1091cb0ef41Sopenharmony_ci 1101cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 0, '3 reads, 4 enqueues: desiredSize should be 0'); 1111cb0ef41Sopenharmony_ci controller.enqueue('e'); 1121cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -1, '3 reads, 5 enqueues: desiredSize should be -1'); 1131cb0ef41Sopenharmony_ci 1141cb0ef41Sopenharmony_ci return reader.read(); 1151cb0ef41Sopenharmony_ci }) 1161cb0ef41Sopenharmony_ci .then(result => { 1171cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'd', done: false }, 1181cb0ef41Sopenharmony_ci '4th read gives back the 4th chunk enqueued (queue now contains 1 chunks)'); 1191cb0ef41Sopenharmony_ci return reader.read(); 1201cb0ef41Sopenharmony_ci }) 1211cb0ef41Sopenharmony_ci .then(result => { 1221cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'e', done: false }, 1231cb0ef41Sopenharmony_ci '5th read gives back the 5th chunk enqueued (queue now contains 0 chunks)'); 1241cb0ef41Sopenharmony_ci 1251cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 1, '5 reads, 5 enqueues: desiredSize should be 1'); 1261cb0ef41Sopenharmony_ci controller.enqueue('f'); 1271cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 0, '5 reads, 6 enqueues: desiredSize should be 0'); 1281cb0ef41Sopenharmony_ci controller.enqueue('g'); 1291cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -1, '5 reads, 7 enqueues: desiredSize should be -1'); 1301cb0ef41Sopenharmony_ci }); 1311cb0ef41Sopenharmony_ci 1321cb0ef41Sopenharmony_ci}, 'Correctly governs a ReadableStreamController\'s desiredSize property (HWM = 1)'); 1331cb0ef41Sopenharmony_ci 1341cb0ef41Sopenharmony_cipromise_test(() => { 1351cb0ef41Sopenharmony_ci 1361cb0ef41Sopenharmony_ci let controller; 1371cb0ef41Sopenharmony_ci const rs = new ReadableStream( 1381cb0ef41Sopenharmony_ci { 1391cb0ef41Sopenharmony_ci start(c) { 1401cb0ef41Sopenharmony_ci controller = c; 1411cb0ef41Sopenharmony_ci } 1421cb0ef41Sopenharmony_ci }, 1431cb0ef41Sopenharmony_ci new CountQueuingStrategy({ highWaterMark: 4 }) 1441cb0ef41Sopenharmony_ci ); 1451cb0ef41Sopenharmony_ci const reader = rs.getReader(); 1461cb0ef41Sopenharmony_ci 1471cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 4, '0 reads, 0 enqueues: desiredSize should be 4'); 1481cb0ef41Sopenharmony_ci controller.enqueue('a'); 1491cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 3, '0 reads, 1 enqueue: desiredSize should be 3'); 1501cb0ef41Sopenharmony_ci controller.enqueue('b'); 1511cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 2, '0 reads, 2 enqueues: desiredSize should be 2'); 1521cb0ef41Sopenharmony_ci controller.enqueue('c'); 1531cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 1, '0 reads, 3 enqueues: desiredSize should be 1'); 1541cb0ef41Sopenharmony_ci controller.enqueue('d'); 1551cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 0, '0 reads, 4 enqueues: desiredSize should be 0'); 1561cb0ef41Sopenharmony_ci controller.enqueue('e'); 1571cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -1, '0 reads, 5 enqueues: desiredSize should be -1'); 1581cb0ef41Sopenharmony_ci controller.enqueue('f'); 1591cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -2, '0 reads, 6 enqueues: desiredSize should be -2'); 1601cb0ef41Sopenharmony_ci 1611cb0ef41Sopenharmony_ci 1621cb0ef41Sopenharmony_ci return reader.read() 1631cb0ef41Sopenharmony_ci .then(result => { 1641cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'a', done: false }, 1651cb0ef41Sopenharmony_ci '1st read gives back the 1st chunk enqueued (queue now contains 5 chunks)'); 1661cb0ef41Sopenharmony_ci return reader.read(); 1671cb0ef41Sopenharmony_ci }) 1681cb0ef41Sopenharmony_ci .then(result => { 1691cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'b', done: false }, 1701cb0ef41Sopenharmony_ci '2nd read gives back the 2nd chunk enqueued (queue now contains 4 chunks)'); 1711cb0ef41Sopenharmony_ci 1721cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 0, '2 reads, 6 enqueues: desiredSize should be 0'); 1731cb0ef41Sopenharmony_ci controller.enqueue('g'); 1741cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -1, '2 reads, 7 enqueues: desiredSize should be -1'); 1751cb0ef41Sopenharmony_ci 1761cb0ef41Sopenharmony_ci return reader.read(); 1771cb0ef41Sopenharmony_ci }) 1781cb0ef41Sopenharmony_ci .then(result => { 1791cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'c', done: false }, 1801cb0ef41Sopenharmony_ci '3rd read gives back the 3rd chunk enqueued (queue now contains 4 chunks)'); 1811cb0ef41Sopenharmony_ci return reader.read(); 1821cb0ef41Sopenharmony_ci }) 1831cb0ef41Sopenharmony_ci .then(result => { 1841cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'd', done: false }, 1851cb0ef41Sopenharmony_ci '4th read gives back the 4th chunk enqueued (queue now contains 3 chunks)'); 1861cb0ef41Sopenharmony_ci return reader.read(); 1871cb0ef41Sopenharmony_ci }) 1881cb0ef41Sopenharmony_ci .then(result => { 1891cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'e', done: false }, 1901cb0ef41Sopenharmony_ci '5th read gives back the 5th chunk enqueued (queue now contains 2 chunks)'); 1911cb0ef41Sopenharmony_ci return reader.read(); 1921cb0ef41Sopenharmony_ci }) 1931cb0ef41Sopenharmony_ci .then(result => { 1941cb0ef41Sopenharmony_ci assert_object_equals(result, { value: 'f', done: false }, 1951cb0ef41Sopenharmony_ci '6th read gives back the 6th chunk enqueued (queue now contains 0 chunks)'); 1961cb0ef41Sopenharmony_ci 1971cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 3, '6 reads, 7 enqueues: desiredSize should be 3'); 1981cb0ef41Sopenharmony_ci controller.enqueue('h'); 1991cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 2, '6 reads, 8 enqueues: desiredSize should be 2'); 2001cb0ef41Sopenharmony_ci controller.enqueue('i'); 2011cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 1, '6 reads, 9 enqueues: desiredSize should be 1'); 2021cb0ef41Sopenharmony_ci controller.enqueue('j'); 2031cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, 0, '6 reads, 10 enqueues: desiredSize should be 0'); 2041cb0ef41Sopenharmony_ci controller.enqueue('k'); 2051cb0ef41Sopenharmony_ci assert_equals(controller.desiredSize, -1, '6 reads, 11 enqueues: desiredSize should be -1'); 2061cb0ef41Sopenharmony_ci }); 2071cb0ef41Sopenharmony_ci 2081cb0ef41Sopenharmony_ci}, 'Correctly governs a ReadableStreamController\'s desiredSize property (HWM = 4)'); 209