tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RTCSctpTransport-constructor.html (4600B)


      1 <!doctype html>
      2 <meta charset="utf-8">
      3 <title>RTCSctpTransport constructor</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="RTCPeerConnection-helper.js"></script>
      7 <script>
      8 'use strict';
      9 
     10 // Test is based on the following revision:
     11 // https://rawgit.com/w3c/webrtc-pc/1cc5bfc3ff18741033d804c4a71f7891242fb5b3/webrtc.html
     12 
     13 // The following helper functions are called from RTCPeerConnection-helper.js:
     14 //   generateDataChannelOffer()
     15 //   generateAnswer()
     16 
     17 /*
     18  6.1.
     19 
     20    partial interface RTCPeerConnection {
     21      readonly attribute RTCSctpTransport? sctp;
     22      ...
     23    };
     24 
     25  6.1.1.
     26 
     27    interface RTCSctpTransport {
     28        readonly attribute RTCDtlsTransport      transport;
     29        readonly attribute RTCSctpTransportState state;
     30        readonly attribute unrestricted double   maxMessageSize;
     31                 attribute EventHandler          onstatechange;
     32    };
     33 
     34  4.4.1.1.  Constructor
     35    9.      Let connection have an [[SctpTransport]] internal slot, initialized to null.
     36 
     37  4.4.1.6.  Set the RTCSessionSessionDescription
     38    2.2.6.  If description is of type "answer" or "pranswer", then run the
     39            following steps:
     40      1.    If description initiates the establishment of a new SCTP association, as defined in
     41            [SCTP-SDP], Sections 10.3 and 10.4, create an RTCSctpTransport with an initial state
     42            of "connecting" and assign the result to the [[SctpTransport]] slot.
     43 */
     44 
     45 promise_test(async (t) => {
     46  const pc1 = new RTCPeerConnection();
     47  const pc2 = new RTCPeerConnection();
     48  t.add_cleanup(() => pc1.close());
     49  t.add_cleanup(() => pc2.close());
     50 
     51  assert_equals(pc1.sctp, null, 'RTCSctpTransport must be null');
     52 
     53  const offer = await generateAudioReceiveOnlyOffer(pc1);
     54  await Promise.all([pc1.setLocalDescription(offer), pc2.setRemoteDescription(offer)]);
     55  const answer = await pc2.createAnswer();
     56  await pc1.setRemoteDescription(answer);
     57 
     58  assert_equals(pc1.sctp, null, 'RTCSctpTransport must remain null');
     59 }, 'setRemoteDescription() with answer not containing data media should not initialize pc.sctp');
     60 
     61 promise_test(async (t) => {
     62  const pc1 = new RTCPeerConnection();
     63  const pc2 = new RTCPeerConnection();
     64  t.add_cleanup(() => pc1.close());
     65  t.add_cleanup(() => pc2.close());
     66 
     67  assert_equals(pc1.sctp, null, 'RTCSctpTransport must be null');
     68 
     69  const offer = await generateAudioReceiveOnlyOffer(pc2);
     70  await Promise.all([pc2.setLocalDescription(offer), pc1.setRemoteDescription(offer)]);
     71  const answer = await pc1.createAnswer();
     72  await pc1.setLocalDescription(answer);
     73 
     74  assert_equals(pc1.sctp, null, 'RTCSctpTransport must remain null');
     75 }, 'setLocalDescription() with answer not containing data media should not initialize pc.sctp');
     76 
     77 function validateSctpTransport(sctp) {
     78  assert_not_equals(sctp, null, 'RTCSctpTransport must be available');
     79 
     80  assert_true(sctp instanceof RTCSctpTransport,
     81    'Expect pc.sctp to be instance of RTCSctpTransport');
     82 
     83  assert_true(sctp.transport instanceof RTCDtlsTransport,
     84    'Expect sctp.transport to be instance of RTCDtlsTransport');
     85 
     86  assert_equals(sctp.state, 'connecting', 'RTCSctpTransport should be in the connecting state');
     87 
     88  // Note: Yes, Number.POSITIVE_INFINITY is also a 'number'
     89  assert_equals(typeof sctp.maxMessageSize, 'number',
     90    'Expect sctp.maxMessageSize to be a number');
     91 }
     92 
     93 promise_test(async (t) => {
     94  const pc1 = new RTCPeerConnection();
     95  const pc2 = new RTCPeerConnection();
     96  t.add_cleanup(() => pc1.close());
     97  t.add_cleanup(() => pc2.close());
     98 
     99  assert_equals(pc1.sctp, null, 'RTCSctpTransport must be null');
    100 
    101  const offer = await generateDataChannelOffer(pc1);
    102  await Promise.all([pc1.setLocalDescription(offer), pc2.setRemoteDescription(offer)]);
    103  const answer = await pc2.createAnswer();
    104  await pc1.setRemoteDescription(answer);
    105 
    106  validateSctpTransport(pc1.sctp);
    107 }, 'setRemoteDescription() with answer containing data media should initialize pc.sctp');
    108 
    109 promise_test(async (t) => {
    110  const pc1 = new RTCPeerConnection();
    111  const pc2 = new RTCPeerConnection();
    112  t.add_cleanup(() => pc1.close());
    113  t.add_cleanup(() => pc2.close());
    114 
    115  assert_equals(pc1.sctp, null, 'RTCSctpTransport must be null');
    116 
    117  const offer = await generateDataChannelOffer(pc2);
    118  await Promise.all([pc2.setLocalDescription(offer), pc1.setRemoteDescription(offer)]);
    119  const answer = await pc1.createAnswer();
    120  await pc1.setLocalDescription(answer);
    121 
    122  validateSctpTransport(pc1.sctp);
    123 }, 'setLocalDescription() with answer containing data media should initialize pc.sctp');
    124 
    125 </script>