11cb0ef41Sopenharmony_ci// META: global=window,worker 21cb0ef41Sopenharmony_ci'use strict'; 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_citest(() => { 51cb0ef41Sopenharmony_ci new WritableStream({}, new CountQueuingStrategy({ highWaterMark: 4 })); 61cb0ef41Sopenharmony_ci}, 'Can construct a writable stream with a valid CountQueuingStrategy'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_cipromise_test(() => { 91cb0ef41Sopenharmony_ci const dones = Object.create(null); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci const ws = new WritableStream( 121cb0ef41Sopenharmony_ci { 131cb0ef41Sopenharmony_ci write(chunk) { 141cb0ef41Sopenharmony_ci return new Promise(resolve => { 151cb0ef41Sopenharmony_ci dones[chunk] = resolve; 161cb0ef41Sopenharmony_ci }); 171cb0ef41Sopenharmony_ci } 181cb0ef41Sopenharmony_ci }, 191cb0ef41Sopenharmony_ci new CountQueuingStrategy({ highWaterMark: 0 }) 201cb0ef41Sopenharmony_ci ); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci const writer = ws.getWriter(); 231cb0ef41Sopenharmony_ci let writePromiseB; 241cb0ef41Sopenharmony_ci let writePromiseC; 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci return Promise.resolve().then(() => { 271cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, 0, 'desiredSize should be initially 0'); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci const writePromiseA = writer.write('a'); 301cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, -1, 'desiredSize should be -1 after 1st write()'); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci writePromiseB = writer.write('b'); 331cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, -2, 'desiredSize should be -2 after 2nd write()'); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci dones.a(); 361cb0ef41Sopenharmony_ci return writePromiseA; 371cb0ef41Sopenharmony_ci }).then(() => { 381cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, -1, 'desiredSize should be -1 after completing 1st write()'); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci dones.b(); 411cb0ef41Sopenharmony_ci return writePromiseB; 421cb0ef41Sopenharmony_ci }).then(() => { 431cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, 0, 'desiredSize should be 0 after completing 2nd write()'); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci writePromiseC = writer.write('c'); 461cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, -1, 'desiredSize should be -1 after 3rd write()'); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci dones.c(); 491cb0ef41Sopenharmony_ci return writePromiseC; 501cb0ef41Sopenharmony_ci }).then(() => { 511cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, 0, 'desiredSize should be 0 after completing 3rd write()'); 521cb0ef41Sopenharmony_ci }); 531cb0ef41Sopenharmony_ci}, 'Correctly governs the value of a WritableStream\'s state property (HWM = 0)'); 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_cipromise_test(() => { 561cb0ef41Sopenharmony_ci const dones = Object.create(null); 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci const ws = new WritableStream( 591cb0ef41Sopenharmony_ci { 601cb0ef41Sopenharmony_ci write(chunk) { 611cb0ef41Sopenharmony_ci return new Promise(resolve => { 621cb0ef41Sopenharmony_ci dones[chunk] = resolve; 631cb0ef41Sopenharmony_ci }); 641cb0ef41Sopenharmony_ci } 651cb0ef41Sopenharmony_ci }, 661cb0ef41Sopenharmony_ci new CountQueuingStrategy({ highWaterMark: 4 }) 671cb0ef41Sopenharmony_ci ); 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci const writer = ws.getWriter(); 701cb0ef41Sopenharmony_ci let writePromiseB; 711cb0ef41Sopenharmony_ci let writePromiseC; 721cb0ef41Sopenharmony_ci let writePromiseD; 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ci return Promise.resolve().then(() => { 751cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, 4, 'desiredSize should be initially 4'); 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci const writePromiseA = writer.write('a'); 781cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, 3, 'desiredSize should be 3 after 1st write()'); 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ci writePromiseB = writer.write('b'); 811cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, 2, 'desiredSize should be 2 after 2nd write()'); 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci writePromiseC = writer.write('c'); 841cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, 1, 'desiredSize should be 1 after 3rd write()'); 851cb0ef41Sopenharmony_ci 861cb0ef41Sopenharmony_ci writePromiseD = writer.write('d'); 871cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, 0, 'desiredSize should be 0 after 4th write()'); 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ci writer.write('e'); 901cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, -1, 'desiredSize should be -1 after 5th write()'); 911cb0ef41Sopenharmony_ci 921cb0ef41Sopenharmony_ci writer.write('f'); 931cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, -2, 'desiredSize should be -2 after 6th write()'); 941cb0ef41Sopenharmony_ci 951cb0ef41Sopenharmony_ci writer.write('g'); 961cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, -3, 'desiredSize should be -3 after 7th write()'); 971cb0ef41Sopenharmony_ci 981cb0ef41Sopenharmony_ci dones.a(); 991cb0ef41Sopenharmony_ci return writePromiseA; 1001cb0ef41Sopenharmony_ci }).then(() => { 1011cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, -2, 'desiredSize should be -2 after completing 1st write()'); 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_ci dones.b(); 1041cb0ef41Sopenharmony_ci return writePromiseB; 1051cb0ef41Sopenharmony_ci }).then(() => { 1061cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, -1, 'desiredSize should be -1 after completing 2nd write()'); 1071cb0ef41Sopenharmony_ci 1081cb0ef41Sopenharmony_ci dones.c(); 1091cb0ef41Sopenharmony_ci return writePromiseC; 1101cb0ef41Sopenharmony_ci }).then(() => { 1111cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, 0, 'desiredSize should be 0 after completing 3rd write()'); 1121cb0ef41Sopenharmony_ci 1131cb0ef41Sopenharmony_ci writer.write('h'); 1141cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, -1, 'desiredSize should be -1 after 8th write()'); 1151cb0ef41Sopenharmony_ci 1161cb0ef41Sopenharmony_ci dones.d(); 1171cb0ef41Sopenharmony_ci return writePromiseD; 1181cb0ef41Sopenharmony_ci }).then(() => { 1191cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, 0, 'desiredSize should be 0 after completing 4th write()'); 1201cb0ef41Sopenharmony_ci 1211cb0ef41Sopenharmony_ci writer.write('i'); 1221cb0ef41Sopenharmony_ci assert_equals(writer.desiredSize, -1, 'desiredSize should be -1 after 9th write()'); 1231cb0ef41Sopenharmony_ci }); 1241cb0ef41Sopenharmony_ci}, 'Correctly governs the value of a WritableStream\'s state property (HWM = 4)'); 125