Debian Codegraph @

testing/web-platform/tests/streams/writable-streams/count-queuing-strategy.any.js

raw
1 // META: global=window,worker,shadowrealm
2 'use strict';
3
4 test(() => {
5 new WritableStream({}, new CountQueuingStrategy({ highWaterMark: 4 }));
6 }, 'Can construct a writable stream with a valid CountQueuingStrategy');
7
8 promise_test(() => {
9 const dones = Object.create(null);
10
11 const ws = new WritableStream(
12 {
13 write(chunk) {
14 return new Promise(resolve => {
15 dones[chunk] = resolve;
16 });
17 }
18 },
19 new CountQueuingStrategy({ highWaterMark: 0 })
20 );
21
22 const writer = ws.getWriter();
23 let writePromiseB;
24 let writePromiseC;
25
26 return Promise.resolve().then(() => {
27 assert_equals(writer.desiredSize, 0, 'desiredSize should be initially 0');
28
29 const writePromiseA = writer.write('a');
30 assert_equals(writer.desiredSize, -1, 'desiredSize should be -1 after 1st write()');
31
32 writePromiseB = writer.write('b');
33 assert_equals(writer.desiredSize, -2, 'desiredSize should be -2 after 2nd write()');
34
35 dones.a();
36 return writePromiseA;
37 }).then(() => {
38 assert_equals(writer.desiredSize, -1, 'desiredSize should be -1 after completing 1st write()');
39
40 dones.b();
41 return writePromiseB;
42 }).then(() => {
43 assert_equals(writer.desiredSize, 0, 'desiredSize should be 0 after completing 2nd write()');
44
45 writePromiseC = writer.write('c');
46 assert_equals(writer.desiredSize, -1, 'desiredSize should be -1 after 3rd write()');
47
48 dones.c();
49 return writePromiseC;
50 }).then(() => {
51 assert_equals(writer.desiredSize, 0, 'desiredSize should be 0 after completing 3rd write()');
52 });
53 }, 'Correctly governs the value of a WritableStream\'s state property (HWM = 0)');
54
55 promise_test(() => {
56 const dones = Object.create(null);
57
58 const ws = new WritableStream(
59 {
60 write(chunk) {
61 return new Promise(resolve => {
62 dones[chunk] = resolve;
63 });
64 }
65 },
66 new CountQueuingStrategy({ highWaterMark: 4 })
67 );
68
69 const writer = ws.getWriter();
70 let writePromiseB;
71 let writePromiseC;
72 let writePromiseD;
73
74 return Promise.resolve().then(() => {
75 assert_equals(writer.desiredSize, 4, 'desiredSize should be initially 4');
76
77 const writePromiseA = writer.write('a');
78 assert_equals(writer.desiredSize, 3, 'desiredSize should be 3 after 1st write()');
79
80 writePromiseB = writer.write('b');
81 assert_equals(writer.desiredSize, 2, 'desiredSize should be 2 after 2nd write()');
82
83 writePromiseC = writer.write('c');
84 assert_equals(writer.desiredSize, 1, 'desiredSize should be 1 after 3rd write()');
85
86 writePromiseD = writer.write('d');
87 assert_equals(writer.desiredSize, 0, 'desiredSize should be 0 after 4th write()');
88
89 writer.write('e');
90 assert_equals(writer.desiredSize, -1, 'desiredSize should be -1 after 5th write()');
91
92 writer.write('f');
93 assert_equals(writer.desiredSize, -2, 'desiredSize should be -2 after 6th write()');
94
95 writer.write('g');
96 assert_equals(writer.desiredSize, -3, 'desiredSize should be -3 after 7th write()');
97
98 dones.a();
99 return writePromiseA;
100 }).then(() => {
101 assert_equals(writer.desiredSize, -2, 'desiredSize should be -2 after completing 1st write()');
102
103 dones.b();
104 return writePromiseB;
105 }).then(() => {
106 assert_equals(writer.desiredSize, -1, 'desiredSize should be -1 after completing 2nd write()');
107
108 dones.c();
109 return writePromiseC;
110 }).then(() => {
111 assert_equals(writer.desiredSize, 0, 'desiredSize should be 0 after completing 3rd write()');
112
113 writer.write('h');
114 assert_equals(writer.desiredSize, -1, 'desiredSize should be -1 after 8th write()');
115
116 dones.d();
117 return writePromiseD;
118 }).then(() => {
119 assert_equals(writer.desiredSize, 0, 'desiredSize should be 0 after completing 4th write()');
120
121 writer.write('i');
122 assert_equals(writer.desiredSize, -1, 'desiredSize should be -1 after 9th write()');
123 });
124 }, 'Correctly governs the value of a WritableStream\'s state property (HWM = 4)');