tor-browser

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

RTCPeerConnection-addIceCandidate-connectionSetup.html (3604B)


      1 <!doctype html>
      2 <meta name="timeout" content="long">
      3 <title>Test RTCPeerConnection.prototype.addIceCandidate</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 // This test may be flaky, so it's in its own file.
     11 // The test belongs in RTCPeerConnection-addIceCandidate.
     12 
     13 promise_test(async t => {
     14  const pc1 = new RTCPeerConnection();
     15  const pc2 = new RTCPeerConnection();
     16  t.add_cleanup(() => pc1.close());
     17  t.add_cleanup(() => pc2.close());
     18  const transceiver = pc1.addTransceiver('video');
     19 
     20  exchangeIceCandidates(pc1, pc2);
     21  await exchangeOffer(pc1, pc2);
     22  const answer = await pc2.createAnswer();
     23  // Note that sequence of the following two calls is critical
     24  // for test stability.
     25  await pc1.setRemoteDescription(answer);
     26  await pc2.setLocalDescription(answer);
     27  await waitForState(transceiver.sender.transport, 'connected');
     28 }, 'Candidates are added dynamically; connection should work');
     29 
     30 promise_test(async t => {
     31  const pc1 = new RTCPeerConnection();
     32  const pc2 = new RTCPeerConnection();
     33  t.add_cleanup(() => pc1.close());
     34  t.add_cleanup(() => pc2.close());
     35  const transceiver = pc1.addTransceiver('video');
     36 
     37  let candidates1to2 = [];
     38  let candidates2to1 = [];
     39  pc1.onicecandidate = e => candidates1to2.push(e.candidate);
     40  pc2.onicecandidate = e => candidates2to1.push(e.candidate);
     41  const pc2GatheredCandidates = new Promise((resolve) => {
     42    pc2.addEventListener('icegatheringstatechange', () => {
     43      if (pc2.iceGatheringState == 'complete') {
     44        resolve();
     45      }
     46    });
     47  });
     48  await exchangeOffer(pc1, pc2);
     49  let answer = await pc2.createAnswer();
     50  await pc1.setRemoteDescription(answer);
     51  await pc2.setLocalDescription(answer);
     52  await pc2GatheredCandidates;
     53  // Add candidates to pc1, ensuring that it goes to "connecting" state before "connected".
     54  // We do not iterate/await because repeatedly awaiting while we serially add
     55  // the candidates opens the opportunity to miss the 'connecting' transition.
     56  const addCandidatesDone = Promise.all(candidates2to1.map(c => pc1.addIceCandidate(c)));
     57  await waitForState(transceiver.sender.transport, 'connecting');
     58  await addCandidatesDone;
     59  await waitForState(transceiver.sender.transport, 'connected');
     60 }, 'Candidates are added at PC1; connection should work');
     61 
     62 promise_test(async t => {
     63  const pc1 = new RTCPeerConnection();
     64  const pc2 = new RTCPeerConnection();
     65  t.add_cleanup(() => pc1.close());
     66  t.add_cleanup(() => pc2.close());
     67  const transceiver = pc1.addTransceiver('video');
     68 
     69  let candidates1to2 = [];
     70  let candidates2to1 = [];
     71  pc1.onicecandidate = e => candidates1to2.push(e.candidate);
     72  pc2.onicecandidate = e => candidates2to1.push(e.candidate);
     73  const pc1GatheredCandidates = new Promise((resolve) => {
     74    pc1.addEventListener('icegatheringstatechange', () => {
     75      if (pc1.iceGatheringState == 'complete') {
     76        resolve();
     77      }
     78    });
     79  });
     80  await exchangeOffer(pc1, pc2);
     81  let answer = await pc2.createAnswer();
     82  await pc1.setRemoteDescription(answer);
     83  await pc2.setLocalDescription(answer);
     84  await pc1GatheredCandidates;
     85  // Add candidates to pc2
     86  // We do not iterate/await because repeatedly awaiting while we serially add
     87  // the candidates opens the opportunity to miss the ICE state transitions.
     88  await Promise.all(candidates1to2.map(c => pc2.addIceCandidate(c)));
     89  await waitForState(transceiver.sender.transport, 'connected');
     90 }, 'Candidates are added at PC2; connection should work');
     91 
     92 </script>