11cb0ef41Sopenharmony_ci// META: global=window,worker
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciconst highWaterMarkConversions = new Map([
51cb0ef41Sopenharmony_ci  [-Infinity, -Infinity],
61cb0ef41Sopenharmony_ci  [-5, -5],
71cb0ef41Sopenharmony_ci  [false, 0],
81cb0ef41Sopenharmony_ci  [true, 1],
91cb0ef41Sopenharmony_ci  [NaN, NaN],
101cb0ef41Sopenharmony_ci  ['foo', NaN],
111cb0ef41Sopenharmony_ci  ['0', 0],
121cb0ef41Sopenharmony_ci  [{}, NaN],
131cb0ef41Sopenharmony_ci  [() => {}, NaN]
141cb0ef41Sopenharmony_ci]);
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_cifor (const QueuingStrategy of [CountQueuingStrategy, ByteLengthQueuingStrategy]) {
171cb0ef41Sopenharmony_ci  test(() => {
181cb0ef41Sopenharmony_ci    new QueuingStrategy({ highWaterMark: 4 });
191cb0ef41Sopenharmony_ci  }, `${QueuingStrategy.name}: Can construct a with a valid high water mark`);
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci  test(() => {
221cb0ef41Sopenharmony_ci    const highWaterMark = 1;
231cb0ef41Sopenharmony_ci    const highWaterMarkObjectGetter = {
241cb0ef41Sopenharmony_ci      get highWaterMark() { return highWaterMark; }
251cb0ef41Sopenharmony_ci    };
261cb0ef41Sopenharmony_ci    const error = new Error('wow!');
271cb0ef41Sopenharmony_ci    const highWaterMarkObjectGetterThrowing = {
281cb0ef41Sopenharmony_ci      get highWaterMark() { throw error; }
291cb0ef41Sopenharmony_ci    };
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci    assert_throws_js(TypeError, () => new QueuingStrategy(), 'construction fails with undefined');
321cb0ef41Sopenharmony_ci    assert_throws_js(TypeError, () => new QueuingStrategy(null), 'construction fails with null');
331cb0ef41Sopenharmony_ci    assert_throws_js(TypeError, () => new QueuingStrategy(true), 'construction fails with true');
341cb0ef41Sopenharmony_ci    assert_throws_js(TypeError, () => new QueuingStrategy(5), 'construction fails with 5');
351cb0ef41Sopenharmony_ci    assert_throws_js(TypeError, () => new QueuingStrategy({}), 'construction fails with {}');
361cb0ef41Sopenharmony_ci    assert_throws_exactly(error, () => new QueuingStrategy(highWaterMarkObjectGetterThrowing),
371cb0ef41Sopenharmony_ci      'construction fails with an object with a throwing highWaterMark getter');
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci    assert_equals((new QueuingStrategy(highWaterMarkObjectGetter)).highWaterMark, highWaterMark);
401cb0ef41Sopenharmony_ci  }, `${QueuingStrategy.name}: Constructor behaves as expected with strange arguments`);
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci  test(() => {
431cb0ef41Sopenharmony_ci    for (const [input, output] of highWaterMarkConversions.entries()) {
441cb0ef41Sopenharmony_ci      const strategy = new QueuingStrategy({ highWaterMark: input });
451cb0ef41Sopenharmony_ci      assert_equals(strategy.highWaterMark, output, `${input} gets set correctly`);
461cb0ef41Sopenharmony_ci    }
471cb0ef41Sopenharmony_ci  }, `${QueuingStrategy.name}: highWaterMark constructor values are converted per the unrestricted double rules`);
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci  test(() => {
501cb0ef41Sopenharmony_ci    const size1 = (new QueuingStrategy({ highWaterMark: 5 })).size;
511cb0ef41Sopenharmony_ci    const size2 = (new QueuingStrategy({ highWaterMark: 10 })).size;
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci    assert_equals(size1, size2);
541cb0ef41Sopenharmony_ci  }, `${QueuingStrategy.name}: size is the same function across all instances`);
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci  test(() => {
571cb0ef41Sopenharmony_ci    const size = (new QueuingStrategy({ highWaterMark: 5 })).size;
581cb0ef41Sopenharmony_ci    assert_equals(size.name, 'size');
591cb0ef41Sopenharmony_ci  }, `${QueuingStrategy.name}: size should have the right name`);
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci  test(() => {
621cb0ef41Sopenharmony_ci    class SubClass extends QueuingStrategy {
631cb0ef41Sopenharmony_ci      size() {
641cb0ef41Sopenharmony_ci        return 2;
651cb0ef41Sopenharmony_ci      }
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci      subClassMethod() {
681cb0ef41Sopenharmony_ci        return true;
691cb0ef41Sopenharmony_ci      }
701cb0ef41Sopenharmony_ci    }
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci    const sc = new SubClass({ highWaterMark: 77 });
731cb0ef41Sopenharmony_ci    assert_equals(sc.constructor.name, 'SubClass', 'constructor.name should be correct');
741cb0ef41Sopenharmony_ci    assert_equals(sc.highWaterMark, 77, 'highWaterMark should come from the parent class');
751cb0ef41Sopenharmony_ci    assert_equals(sc.size(), 2, 'size() on the subclass should override the parent');
761cb0ef41Sopenharmony_ci    assert_true(sc.subClassMethod(), 'subClassMethod() should work');
771cb0ef41Sopenharmony_ci  }, `${QueuingStrategy.name}: subclassing should work correctly`);
781cb0ef41Sopenharmony_ci
791cb0ef41Sopenharmony_ci  test(() => {
801cb0ef41Sopenharmony_ci    const size = new QueuingStrategy({ highWaterMark: 5 }).size;
811cb0ef41Sopenharmony_ci    assert_false('prototype' in size);
821cb0ef41Sopenharmony_ci  }, `${QueuingStrategy.name}: size should not have a prototype property`);
831cb0ef41Sopenharmony_ci}
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_citest(() => {
861cb0ef41Sopenharmony_ci  const size = new CountQueuingStrategy({ highWaterMark: 5 }).size;
871cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => new size());
881cb0ef41Sopenharmony_ci}, `CountQueuingStrategy: size should not be a constructor`);
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_citest(() => {
911cb0ef41Sopenharmony_ci  const size = new ByteLengthQueuingStrategy({ highWaterMark: 5 }).size;
921cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => new size({ byteLength: 1024 }));
931cb0ef41Sopenharmony_ci}, `ByteLengthQueuingStrategy: size should not be a constructor`);
941cb0ef41Sopenharmony_ci
951cb0ef41Sopenharmony_citest(() => {
961cb0ef41Sopenharmony_ci  const size = (new CountQueuingStrategy({ highWaterMark: 5 })).size;
971cb0ef41Sopenharmony_ci  assert_equals(size.length, 0);
981cb0ef41Sopenharmony_ci}, 'CountQueuingStrategy: size should have the right length');
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_citest(() => {
1011cb0ef41Sopenharmony_ci  const size = (new ByteLengthQueuingStrategy({ highWaterMark: 5 })).size;
1021cb0ef41Sopenharmony_ci  assert_equals(size.length, 1);
1031cb0ef41Sopenharmony_ci}, 'ByteLengthQueuingStrategy: size should have the right length');
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_citest(() => {
1061cb0ef41Sopenharmony_ci  const size = 1024;
1071cb0ef41Sopenharmony_ci  const chunk = { byteLength: size };
1081cb0ef41Sopenharmony_ci  const chunkGetter = {
1091cb0ef41Sopenharmony_ci    get byteLength() { return size; }
1101cb0ef41Sopenharmony_ci  };
1111cb0ef41Sopenharmony_ci  const error = new Error('wow!');
1121cb0ef41Sopenharmony_ci  const chunkGetterThrowing = {
1131cb0ef41Sopenharmony_ci    get byteLength() { throw error; }
1141cb0ef41Sopenharmony_ci  };
1151cb0ef41Sopenharmony_ci
1161cb0ef41Sopenharmony_ci  const sizeFunction = (new CountQueuingStrategy({ highWaterMark: 5 })).size;
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ci  assert_equals(sizeFunction(), 1, 'size returns 1 with undefined');
1191cb0ef41Sopenharmony_ci  assert_equals(sizeFunction(null), 1, 'size returns 1 with null');
1201cb0ef41Sopenharmony_ci  assert_equals(sizeFunction('potato'), 1, 'size returns 1 with non-object type');
1211cb0ef41Sopenharmony_ci  assert_equals(sizeFunction({}), 1, 'size returns 1 with empty object');
1221cb0ef41Sopenharmony_ci  assert_equals(sizeFunction(chunk), 1, 'size returns 1 with a chunk');
1231cb0ef41Sopenharmony_ci  assert_equals(sizeFunction(chunkGetter), 1, 'size returns 1 with chunk getter');
1241cb0ef41Sopenharmony_ci  assert_equals(sizeFunction(chunkGetterThrowing), 1,
1251cb0ef41Sopenharmony_ci    'size returns 1 with chunk getter that throws');
1261cb0ef41Sopenharmony_ci}, 'CountQueuingStrategy: size behaves as expected with strange arguments');
1271cb0ef41Sopenharmony_ci
1281cb0ef41Sopenharmony_citest(() => {
1291cb0ef41Sopenharmony_ci  const size = 1024;
1301cb0ef41Sopenharmony_ci  const chunk = { byteLength: size };
1311cb0ef41Sopenharmony_ci  const chunkGetter = {
1321cb0ef41Sopenharmony_ci    get byteLength() { return size; }
1331cb0ef41Sopenharmony_ci  };
1341cb0ef41Sopenharmony_ci  const error = new Error('wow!');
1351cb0ef41Sopenharmony_ci  const chunkGetterThrowing = {
1361cb0ef41Sopenharmony_ci    get byteLength() { throw error; }
1371cb0ef41Sopenharmony_ci  };
1381cb0ef41Sopenharmony_ci
1391cb0ef41Sopenharmony_ci  const sizeFunction = (new ByteLengthQueuingStrategy({ highWaterMark: 5 })).size;
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => sizeFunction(), 'size fails with undefined');
1421cb0ef41Sopenharmony_ci  assert_throws_js(TypeError, () => sizeFunction(null), 'size fails with null');
1431cb0ef41Sopenharmony_ci  assert_equals(sizeFunction('potato'), undefined, 'size succeeds with undefined with a random non-object type');
1441cb0ef41Sopenharmony_ci  assert_equals(sizeFunction({}), undefined, 'size succeeds with undefined with an object without hwm property');
1451cb0ef41Sopenharmony_ci  assert_equals(sizeFunction(chunk), size, 'size succeeds with the right amount with an object with a hwm');
1461cb0ef41Sopenharmony_ci  assert_equals(sizeFunction(chunkGetter), size,
1471cb0ef41Sopenharmony_ci    'size succeeds with the right amount with an object with a hwm getter');
1481cb0ef41Sopenharmony_ci  assert_throws_exactly(error, () => sizeFunction(chunkGetterThrowing),
1491cb0ef41Sopenharmony_ci    'size fails with the error thrown by the getter');
1501cb0ef41Sopenharmony_ci}, 'ByteLengthQueuingStrategy: size behaves as expected with strange arguments');
151