11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst http2 = require('http2');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci{
111cb0ef41Sopenharmony_ci  const server = http2.createServer();
121cb0ef41Sopenharmony_ci  server.on('stream', common.mustNotCall((stream) => {
131cb0ef41Sopenharmony_ci    stream.respond();
141cb0ef41Sopenharmony_ci    stream.end('ok');
151cb0ef41Sopenharmony_ci  }));
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci  const types = {
181cb0ef41Sopenharmony_ci    boolean: true,
191cb0ef41Sopenharmony_ci    function: () => {},
201cb0ef41Sopenharmony_ci    number: 1,
211cb0ef41Sopenharmony_ci    object: {},
221cb0ef41Sopenharmony_ci    array: [],
231cb0ef41Sopenharmony_ci    null: null,
241cb0ef41Sopenharmony_ci  };
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
271cb0ef41Sopenharmony_ci    const client = http2.connect(`http://localhost:${server.address().port}`);
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci    client.on('connect', common.mustCall(() => {
301cb0ef41Sopenharmony_ci      const outOfRangeNum = 2 ** 32;
311cb0ef41Sopenharmony_ci      assert.throws(
321cb0ef41Sopenharmony_ci        () => client.setLocalWindowSize(outOfRangeNum),
331cb0ef41Sopenharmony_ci        {
341cb0ef41Sopenharmony_ci          name: 'RangeError',
351cb0ef41Sopenharmony_ci          code: 'ERR_OUT_OF_RANGE',
361cb0ef41Sopenharmony_ci          message: 'The value of "windowSize" is out of range.' +
371cb0ef41Sopenharmony_ci            ' It must be >= 0 && <= 2147483647. Received ' + outOfRangeNum
381cb0ef41Sopenharmony_ci        }
391cb0ef41Sopenharmony_ci      );
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci      // Throw if something other than number is passed to setLocalWindowSize
421cb0ef41Sopenharmony_ci      Object.entries(types).forEach(([type, value]) => {
431cb0ef41Sopenharmony_ci        if (type === 'number') {
441cb0ef41Sopenharmony_ci          return;
451cb0ef41Sopenharmony_ci        }
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci        assert.throws(
481cb0ef41Sopenharmony_ci          () => client.setLocalWindowSize(value),
491cb0ef41Sopenharmony_ci          {
501cb0ef41Sopenharmony_ci            name: 'TypeError',
511cb0ef41Sopenharmony_ci            code: 'ERR_INVALID_ARG_TYPE',
521cb0ef41Sopenharmony_ci            message: 'The "windowSize" argument must be of type number.' +
531cb0ef41Sopenharmony_ci                    common.invalidArgTypeHelper(value)
541cb0ef41Sopenharmony_ci          }
551cb0ef41Sopenharmony_ci        );
561cb0ef41Sopenharmony_ci      });
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci      server.close();
591cb0ef41Sopenharmony_ci      client.close();
601cb0ef41Sopenharmony_ci    }));
611cb0ef41Sopenharmony_ci  }));
621cb0ef41Sopenharmony_ci}
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ci{
651cb0ef41Sopenharmony_ci  const server = http2.createServer();
661cb0ef41Sopenharmony_ci  server.on('stream', common.mustNotCall((stream) => {
671cb0ef41Sopenharmony_ci    stream.respond();
681cb0ef41Sopenharmony_ci    stream.end('ok');
691cb0ef41Sopenharmony_ci  }));
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
721cb0ef41Sopenharmony_ci    const client = http2.connect(`http://localhost:${server.address().port}`);
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci    client.on('connect', common.mustCall(() => {
751cb0ef41Sopenharmony_ci      const windowSize = 2 ** 20;
761cb0ef41Sopenharmony_ci      const defaultSetting = http2.getDefaultSettings();
771cb0ef41Sopenharmony_ci      client.setLocalWindowSize(windowSize);
781cb0ef41Sopenharmony_ci
791cb0ef41Sopenharmony_ci      assert.strictEqual(client.state.effectiveLocalWindowSize, windowSize);
801cb0ef41Sopenharmony_ci      assert.strictEqual(client.state.localWindowSize, windowSize);
811cb0ef41Sopenharmony_ci      assert.strictEqual(
821cb0ef41Sopenharmony_ci        client.state.remoteWindowSize,
831cb0ef41Sopenharmony_ci        defaultSetting.initialWindowSize
841cb0ef41Sopenharmony_ci      );
851cb0ef41Sopenharmony_ci
861cb0ef41Sopenharmony_ci      server.close();
871cb0ef41Sopenharmony_ci      client.close();
881cb0ef41Sopenharmony_ci    }));
891cb0ef41Sopenharmony_ci  }));
901cb0ef41Sopenharmony_ci}
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ci{
931cb0ef41Sopenharmony_ci  const server = http2.createServer();
941cb0ef41Sopenharmony_ci  server.on('stream', common.mustNotCall((stream) => {
951cb0ef41Sopenharmony_ci    stream.respond();
961cb0ef41Sopenharmony_ci    stream.end('ok');
971cb0ef41Sopenharmony_ci  }));
981cb0ef41Sopenharmony_ci
991cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
1001cb0ef41Sopenharmony_ci    const client = http2.connect(`http://localhost:${server.address().port}`);
1011cb0ef41Sopenharmony_ci
1021cb0ef41Sopenharmony_ci    client.on('connect', common.mustCall(() => {
1031cb0ef41Sopenharmony_ci      const windowSize = 20;
1041cb0ef41Sopenharmony_ci      const defaultSetting = http2.getDefaultSettings();
1051cb0ef41Sopenharmony_ci      client.setLocalWindowSize(windowSize);
1061cb0ef41Sopenharmony_ci
1071cb0ef41Sopenharmony_ci      assert.strictEqual(client.state.effectiveLocalWindowSize, windowSize);
1081cb0ef41Sopenharmony_ci      assert.strictEqual(
1091cb0ef41Sopenharmony_ci        client.state.localWindowSize,
1101cb0ef41Sopenharmony_ci        defaultSetting.initialWindowSize
1111cb0ef41Sopenharmony_ci      );
1121cb0ef41Sopenharmony_ci      assert.strictEqual(
1131cb0ef41Sopenharmony_ci        client.state.remoteWindowSize,
1141cb0ef41Sopenharmony_ci        defaultSetting.initialWindowSize
1151cb0ef41Sopenharmony_ci      );
1161cb0ef41Sopenharmony_ci
1171cb0ef41Sopenharmony_ci      server.close();
1181cb0ef41Sopenharmony_ci      client.close();
1191cb0ef41Sopenharmony_ci    }));
1201cb0ef41Sopenharmony_ci  }));
1211cb0ef41Sopenharmony_ci}
122