11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled();
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst { Session } = require('inspector');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst session = new Session();
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciassert.throws(
131cb0ef41Sopenharmony_ci  () => session.post('Runtime.evaluate', { expression: '2 + 2' }),
141cb0ef41Sopenharmony_ci  {
151cb0ef41Sopenharmony_ci    code: 'ERR_INSPECTOR_NOT_CONNECTED',
161cb0ef41Sopenharmony_ci    name: 'Error',
171cb0ef41Sopenharmony_ci    message: 'Session is not connected'
181cb0ef41Sopenharmony_ci  }
191cb0ef41Sopenharmony_ci);
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_cisession.connect();
221cb0ef41Sopenharmony_cisession.post('Runtime.evaluate', { expression: '2 + 2' });
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci[1, {}, [], true, Infinity, undefined].forEach((i) => {
251cb0ef41Sopenharmony_ci  assert.throws(
261cb0ef41Sopenharmony_ci    () => session.post(i),
271cb0ef41Sopenharmony_ci    {
281cb0ef41Sopenharmony_ci      code: 'ERR_INVALID_ARG_TYPE',
291cb0ef41Sopenharmony_ci      name: 'TypeError',
301cb0ef41Sopenharmony_ci      message:
311cb0ef41Sopenharmony_ci        'The "method" argument must be of type string.' +
321cb0ef41Sopenharmony_ci        common.invalidArgTypeHelper(i)
331cb0ef41Sopenharmony_ci    }
341cb0ef41Sopenharmony_ci  );
351cb0ef41Sopenharmony_ci});
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci[1, true, Infinity].forEach((i) => {
381cb0ef41Sopenharmony_ci  assert.throws(
391cb0ef41Sopenharmony_ci    () => session.post('test', i),
401cb0ef41Sopenharmony_ci    {
411cb0ef41Sopenharmony_ci      code: 'ERR_INVALID_ARG_TYPE',
421cb0ef41Sopenharmony_ci      name: 'TypeError',
431cb0ef41Sopenharmony_ci      message:
441cb0ef41Sopenharmony_ci        'The "params" argument must be of type object.' +
451cb0ef41Sopenharmony_ci        common.invalidArgTypeHelper(i)
461cb0ef41Sopenharmony_ci    }
471cb0ef41Sopenharmony_ci  );
481cb0ef41Sopenharmony_ci});
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci[1, 'a', {}, [], true, Infinity].forEach((i) => {
511cb0ef41Sopenharmony_ci  assert.throws(
521cb0ef41Sopenharmony_ci    () => session.post('test', {}, i),
531cb0ef41Sopenharmony_ci    {
541cb0ef41Sopenharmony_ci      code: 'ERR_INVALID_ARG_TYPE',
551cb0ef41Sopenharmony_ci      name: 'TypeError',
561cb0ef41Sopenharmony_ci    }
571cb0ef41Sopenharmony_ci  );
581cb0ef41Sopenharmony_ci});
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ciassert.throws(
611cb0ef41Sopenharmony_ci  () => session.connect(),
621cb0ef41Sopenharmony_ci  {
631cb0ef41Sopenharmony_ci    code: 'ERR_INSPECTOR_ALREADY_CONNECTED',
641cb0ef41Sopenharmony_ci    name: 'Error',
651cb0ef41Sopenharmony_ci    message: 'The inspector session is already connected'
661cb0ef41Sopenharmony_ci  }
671cb0ef41Sopenharmony_ci);
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_cisession.disconnect();
701cb0ef41Sopenharmony_ci// Calling disconnect twice should not throw.
711cb0ef41Sopenharmony_cisession.disconnect();
72