tor-browser

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

test_peerConnection_encodingsNegotiation.html (2668B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <script type="application/javascript" src="pc.js"></script>
      5  <script type="application/javascript" src="simulcast.js"></script>
      6  <script type="application/javascript" src="helpers_from_wpt/sdp.js"></script>
      7 </head>
      8 <body>
      9 <pre id="test">
     10 <script type="application/javascript">
     11 createHTML({
     12  bug: "1401592",
     13  title: "Simulcast negotiation tests",
     14  visible: true
     15 });
     16 
     17 // simulcast negotiation is mostly tested in wpt, but we test a few
     18 // implementation-specific things here.
     19 const tests = [
     20  async function checkVideoEncodingLimit() {
     21    const pc1 = new RTCPeerConnection();
     22    const pc2 = new RTCPeerConnection();
     23 
     24    const stream = await navigator.mediaDevices.getUserMedia({video: true});
     25    const sender = pc1.addTrack(stream.getTracks()[0]);
     26    pc2.addTrack(stream.getTracks()[0]);
     27 
     28    await doOfferToRecvSimulcast(pc2, pc1, ["1", "2", "3", "4"]);
     29 
     30    const {encodings} = sender.getParameters();
     31    const rids = encodings.map(({rid}) => rid);
     32    isDeeply(rids, ["1", "2", "3"]);
     33 
     34    pc1.close();
     35    pc2.close();
     36    stream.getTracks().forEach(track => track.stop());
     37  },
     38 
     39  // wpt currently does not assume support for 3 encodings, which limits the
     40  // effectiveness of its powers-of-2 test (since it can test only for 1 and 2)
     41  async function checkScaleResolutionDownByAutoFillPowersOf2() {
     42    const pc1 = new RTCPeerConnection();
     43    const pc2 = new RTCPeerConnection();
     44    const stream = await navigator.mediaDevices.getUserMedia({video: true});
     45    const sender = pc1.addTrack(stream.getTracks()[0]);
     46    pc2.addTrack(stream.getTracks()[0]);
     47 
     48    await doOfferToRecvSimulcast(pc2, pc1, ["1", "2", "3"]);
     49 
     50    const {encodings} = sender.getParameters();
     51    const scaleValues = encodings.map(({scaleResolutionDownBy}) => scaleResolutionDownBy);
     52    isDeeply(scaleValues, [4, 2, 1]);
     53  },
     54 
     55  async function checkLibwebrtcRidLengthLimit() {
     56    const pc1 = new RTCPeerConnection();
     57    const pc2 = new RTCPeerConnection();
     58 
     59    const stream = await navigator.mediaDevices.getUserMedia({video: true});
     60    const sender = pc1.addTrack(stream.getTracks()[0]);
     61    pc2.addTrack(stream.getTracks()[0]);
     62 
     63    await doOfferToRecvSimulcast(pc2, pc1, ["foo", "wibblywobblyjeremybearimy"]);
     64    const {encodings} = sender.getParameters();
     65    const rids = encodings.map(({rid}) => rid);
     66    isDeeply(rids, ["foo"]);
     67 
     68    pc1.close();
     69    pc2.close();
     70    stream.getTracks().forEach(track => track.stop());
     71  },
     72 ];
     73 
     74 runNetworkTest(async () => {
     75  for (const test of tests) {
     76    info(`Running test: ${test.name}`);
     77    await test();
     78    info(`Done running test: ${test.name}`);
     79  }
     80 });
     81 
     82 </script>
     83 </pre>
     84 </body>
     85 </html>