tor-browser

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

RTCPeerConnection-constructor.html (2149B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>RTCPeerConnection constructor</title>
      4 <script src=/resources/testharness.js></script>
      5 <script src=/resources/testharnessreport.js></script>
      6 <script>
      7 test(function() {
      8  assert_equals(RTCPeerConnection.length, 0);
      9 }, 'RTCPeerConnection.length');
     10 
     11 // These are used for string and number dictionary members to see if they are
     12 // being accessed at all.
     13 const toStringThrows = { toString: function() { throw new Error; } };
     14 const toNumberThrows = Symbol();
     15 
     16 // Test the first argument of the constructor. The key is the argument itself,
     17 // and the value is the first argument for assert_throws_js, or false if no
     18 // exception should be thrown.
     19 const testArgs = {
     20  // No argument or equivalent.
     21  '': false,
     22  'null': false,
     23  'undefined': false,
     24  '{}': false,
     25 
     26  // certificates
     27  '{ certificates: null }': TypeError,
     28  '{ certificates: undefined }': false,
     29  '{ certificates: [] }': false,
     30  '{ certificates: [null] }': TypeError,
     31  '{ certificates: [undefined] }': TypeError,
     32 
     33  // iceCandidatePoolSize
     34  '{ iceCandidatePoolSize: toNumberThrows }': TypeError,
     35 }
     36 
     37 for (const arg in testArgs) {
     38  const expr = 'new RTCPeerConnection(' + arg + ')';
     39  test(function() {
     40    const throws = testArgs[arg];
     41    if (throws) {
     42      assert_throws_js(throws, function() {
     43        eval(expr);
     44      });
     45    } else {
     46      eval(expr);
     47    }
     48  }, expr);
     49 }
     50 
     51 // The initial values of attributes of RTCPeerConnection.
     52 const initialState = {
     53  'localDescription': null,
     54  'currentLocalDescription': null,
     55  'pendingLocalDescription': null,
     56  'remoteDescription': null,
     57  'currentRemoteDescription': null,
     58  'pendingRemoteDescription': null,
     59  'signalingState': 'stable',
     60  'iceGatheringState': 'new',
     61  'iceConnectionState': 'new',
     62  'connectionState': 'new',
     63  'canTrickleIceCandidates': null,
     64  // TODO: defaultIceServers
     65 };
     66 
     67 for (const attr in initialState) {
     68  test(function() {
     69    // Use one RTCPeerConnection instance for all initial value tests.
     70    if (!window.pc) {
     71      window.pc = new RTCPeerConnection;
     72    }
     73    assert_equals(window.pc[attr], initialState[attr]);
     74  }, attr + ' initial value');
     75 }
     76 </script>