11cb0ef41Sopenharmony_ci// Flags: --expose-internals
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst { recordState } = require('../common/heap');
51cb0ef41Sopenharmony_ciif (!common.hasCrypto)
61cb0ef41Sopenharmony_ci  common.skip('missing crypto');
71cb0ef41Sopenharmony_ciconst http2 = require('http2');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci{
101cb0ef41Sopenharmony_ci  const state = recordState();
111cb0ef41Sopenharmony_ci  state.validateSnapshotNodes('Node / Http2Session', []);
121cb0ef41Sopenharmony_ci  state.validateSnapshotNodes('Node / Http2Stream', []);
131cb0ef41Sopenharmony_ci}
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciconst server = http2.createServer();
161cb0ef41Sopenharmony_ciserver.on('stream', (stream) => {
171cb0ef41Sopenharmony_ci  stream.respondWithFile(process.execPath);
181cb0ef41Sopenharmony_ci});
191cb0ef41Sopenharmony_ciserver.listen(0, () => {
201cb0ef41Sopenharmony_ci  const client = http2.connect(`http://localhost:${server.address().port}`);
211cb0ef41Sopenharmony_ci  const req = client.request();
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  req.on('response', common.mustCall(() => {
241cb0ef41Sopenharmony_ci    const state = recordState();
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci    // `Node / Http2Stream` (C++) -> Http2Stream (JS)
271cb0ef41Sopenharmony_ci    state.validateSnapshotNodes('Node / Http2Stream', [
281cb0ef41Sopenharmony_ci      {
291cb0ef41Sopenharmony_ci        children: [
301cb0ef41Sopenharmony_ci          // current_headers and/or queue could be empty
311cb0ef41Sopenharmony_ci          { node_name: 'Http2Stream', edge_name: 'native_to_javascript' },
321cb0ef41Sopenharmony_ci        ],
331cb0ef41Sopenharmony_ci      },
341cb0ef41Sopenharmony_ci    ], { loose: true });
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci    // `Node / FileHandle` (C++) -> FileHandle (JS)
371cb0ef41Sopenharmony_ci    state.validateSnapshotNodes('Node / FileHandle', [
381cb0ef41Sopenharmony_ci      {
391cb0ef41Sopenharmony_ci        children: [
401cb0ef41Sopenharmony_ci          { node_name: 'FileHandle', edge_name: 'native_to_javascript' },
411cb0ef41Sopenharmony_ci          // current_headers could be empty
421cb0ef41Sopenharmony_ci        ],
431cb0ef41Sopenharmony_ci      },
441cb0ef41Sopenharmony_ci    ], { loose: true });
451cb0ef41Sopenharmony_ci    state.validateSnapshotNodes('Node / TCPSocketWrap', [
461cb0ef41Sopenharmony_ci      {
471cb0ef41Sopenharmony_ci        children: [
481cb0ef41Sopenharmony_ci          { node_name: 'TCP', edge_name: 'native_to_javascript' },
491cb0ef41Sopenharmony_ci        ],
501cb0ef41Sopenharmony_ci      },
511cb0ef41Sopenharmony_ci    ], { loose: true });
521cb0ef41Sopenharmony_ci    state.validateSnapshotNodes('Node / TCPServerWrap', [
531cb0ef41Sopenharmony_ci      {
541cb0ef41Sopenharmony_ci        children: [
551cb0ef41Sopenharmony_ci          { node_name: 'TCP', edge_name: 'native_to_javascript' },
561cb0ef41Sopenharmony_ci        ],
571cb0ef41Sopenharmony_ci      },
581cb0ef41Sopenharmony_ci    ], { loose: true });
591cb0ef41Sopenharmony_ci    // `Node / StreamPipe` (C++) -> StreamPipe (JS)
601cb0ef41Sopenharmony_ci    state.validateSnapshotNodes('Node / StreamPipe', [
611cb0ef41Sopenharmony_ci      {
621cb0ef41Sopenharmony_ci        children: [
631cb0ef41Sopenharmony_ci          { node_name: 'StreamPipe', edge_name: 'native_to_javascript' },
641cb0ef41Sopenharmony_ci        ],
651cb0ef41Sopenharmony_ci      },
661cb0ef41Sopenharmony_ci    ]);
671cb0ef41Sopenharmony_ci    // `Node / Http2Session` (C++) -> Http2Session (JS)
681cb0ef41Sopenharmony_ci    state.validateSnapshotNodes('Node / Http2Session', [
691cb0ef41Sopenharmony_ci      {
701cb0ef41Sopenharmony_ci        children: [
711cb0ef41Sopenharmony_ci          { node_name: 'Http2Session', edge_name: 'native_to_javascript' },
721cb0ef41Sopenharmony_ci          { node_name: 'Node / nghttp2_memory', edge_name: 'nghttp2_memory' },
731cb0ef41Sopenharmony_ci          {
741cb0ef41Sopenharmony_ci            node_name: 'Node / streams', edge_name: 'streams',
751cb0ef41Sopenharmony_ci          },
761cb0ef41Sopenharmony_ci          // outstanding_pings, outgoing_buffers, outgoing_storage,
771cb0ef41Sopenharmony_ci          // pending_rst_streams could be empty
781cb0ef41Sopenharmony_ci        ],
791cb0ef41Sopenharmony_ci      },
801cb0ef41Sopenharmony_ci    ], { loose: true });
811cb0ef41Sopenharmony_ci  }));
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci  req.resume();
841cb0ef41Sopenharmony_ci  req.on('end', common.mustCall(() => {
851cb0ef41Sopenharmony_ci    client.close();
861cb0ef41Sopenharmony_ci    server.close();
871cb0ef41Sopenharmony_ci  }));
881cb0ef41Sopenharmony_ci  req.end();
891cb0ef41Sopenharmony_ci});
90