tor-browser

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

test_peerConnection_basicAudioRelayPolicy.html (3284B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <script type="application/javascript" src="pc.js"></script>
      5 </head>
      6 <body>
      7 <pre id="test">
      8 <script type="application/javascript">
      9 createHTML({
     10  bug: "1663746",
     11  title: "Basic tests for relay ice policy"
     12 });
     13 
     14 runNetworkTest(async () => {
     15  await pushPrefs(
     16      // Enable mDNS, since there are some checks we want to run with that
     17      ['media.peerconnection.ice.obfuscate_host_addresses', true],
     18      // The above triggers warning about 5 ICE servers
     19      ['media.peerconnection.treat_warnings_as_errors', false],
     20  );
     21 
     22  const offerer = new RTCPeerConnection({iceServers: iceServersArray, iceTransportPolicy: 'relay'});
     23  const answerer = new RTCPeerConnection({iceServers: iceServersArray});
     24 
     25  offerer.onicecandidate = e => {
     26    if (e.candidate) {
     27      ok(!e.candidate.candidate.includes(' host '), 'IceTransportPolicy \"relay\" should prevent the advertisement of host candidates');
     28      ok(!e.candidate.candidate.includes(' srflx '), 'IceTransportPolicy \"relay\" should prevent the advertisement of srflx candidates');
     29    }
     30    answerer.addIceCandidate(e.candidate);
     31  };
     32 
     33  answerer.onicecandidate = e => {
     34    if (e.candidate && e.candidate.candidate.includes(' host ')) {
     35      ok(e.candidate.candidate.includes('.local'), 'When obfuscate_host_addresses is true, we expect host candidates to use mDNS');
     36    }
     37    offerer.addIceCandidate(e.candidate);
     38  };
     39 
     40  const offererConnected = new Promise(r => {
     41    offerer.oniceconnectionstatechange = () => {
     42      if (offerer.iceConnectionState == 'connected') {
     43        r();
     44      }
     45    };
     46  });
     47 
     48  const answererConnected = new Promise(r => {
     49    answerer.oniceconnectionstatechange = () => {
     50      if (answerer.iceConnectionState == 'connected') {
     51        r();
     52      }
     53    };
     54  });
     55 
     56  const offer = await offerer.createOffer({offerToReceiveAudio: true});
     57  await Promise.all([offerer.setLocalDescription(offer), answerer.setRemoteDescription(offer)]);
     58  const answer = await answerer.createAnswer();
     59  await Promise.all([answerer.setLocalDescription(answer), offerer.setRemoteDescription(answer)]);
     60 
     61  info('Waiting for ICE to connect');
     62  await Promise.all([offererConnected, answererConnected]);
     63 
     64  const offererStats = await offerer.getStats();
     65  const localCandidates = [...offererStats.values()].filter(stat => stat.type == 'local-candidate');
     66  const remoteCandidates = [...offererStats.values()].filter(stat => stat.type == 'remote-candidate');
     67  isnot(localCandidates, []);
     68  isnot(remoteCandidates, []);
     69 
     70  const localNonRelayCandidates =
     71      localCandidates.filter(cand => cand.candidateType != 'relay');
     72  is(localNonRelayCandidates.length, 0, `There should only be local relay candidates, because we are using the "relay" IceTransportPolicy, but we got ${JSON.stringify(localNonRelayCandidates)}`);
     73 
     74  const remoteHostCandidates =
     75      remoteCandidates.filter(cand => cand.candidateType == 'host');
     76  is(remoteHostCandidates.length, 0, `There should be no remote host candidates in the stats, because mDNS resolution should have been disabled by the "relay" IceTransportPolicy, but we got ${JSON.stringify(remoteHostCandidates)}`);
     77 
     78  offerer.close();
     79  answerer.close();
     80 
     81  await SpecialPowers.popPrefEnv();
     82 }, { useIceServer: true });
     83 </script>
     84 </pre>
     85 </body>
     86 </html>