tor-browser

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

test_peerConnection_basicScreenshare.html (3214B)


      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: "1039666",
     11    title: "Basic screenshare-only peer connection"
     12  });
     13 
     14  async function supportedVideoPayloadTypes() {
     15    const pc = new RTCPeerConnection();
     16    const offer = await pc.createOffer({offerToReceiveVideo: true});
     17    return sdputils.getPayloadTypes(offer.sdp);
     18  }
     19 
     20  async function testScreenshare(payloadType) {
     21    const options = {};
     22    options.h264 = payloadType == 97 || payloadType == 126 || payloadType == 103 || payloadType == 105;
     23    options.av1 = payloadType == 99;
     24    const test = new PeerConnectionTest(options);
     25    const constraints = {
     26      video: { mediaSource: "screen" },
     27    };
     28    test.setMediaConstraints([constraints], []);
     29    test.chain.insertAfterEach("PC_LOCAL_CREATE_OFFER", [
     30      function PC_LOCAL_ISOLATE_CODEC() {
     31        info(`Forcing payload type ${payloadType}. Note that other associated ` +
     32             `payload types, like RTX, are removed too.`);
     33        test.originalOffer.sdp =
     34          sdputils.removeAllButPayloadType(test.originalOffer.sdp, payloadType);
     35        ok(test.originalOffer.sdp.match(new RegExp(`m=.*UDP/TLS/RTP/SAVPF.* ${payloadType}[^0-9]`, "gi")),
     36          `Tested codec ${payloadType} should remain after filtering`);
     37        ok(test.originalOffer.sdp.match(new RegExp(`a=rtpmap:${payloadType}[^0-9]`, "gi")),
     38          `Tested codec ${payloadType} rtpmap should remain after filtering`);
     39      },
     40    ]);
     41    await test.run();
     42  }
     43 
     44  runNetworkTest(async () => {
     45    await pushPrefs(
     46      ["media.navigator.video.red_ulpfec_enabled", true],
     47      ["media.navigator.video.disable_h264_baseline", false],
     48      ["media.webrtc.codec.video.av1.enabled", true],
     49    );
     50    let hasH264 = await checkPlatformH264CodecPrefs();
     51    const allPts = await supportedVideoPayloadTypes();
     52    const pts = {
     53      pts: allPts,
     54      take(pt) {
     55        const result = this.pts.includes(pt);
     56        this.pts = this.pts.filter(p => pt != p);
     57        return result;
     58      },
     59      empty() {
     60        return !this.pts.length;
     61      },
     62    };
     63    ok(pts.take("120"), "VP8 is supported");
     64    ok(pts.take("121"), "VP9 is supported");
     65    ok(pts.take("99"), "AV1 is supported");
     66    if (hasH264.any) {
     67      ok(pts.take("97"), "H264 with no packetization-mode is supported");
     68      ok(pts.take("126"), "H264 with packetization-mode=1 is supported");
     69      ok(pts.take("103"), "H264 Baseline with no packetization-mode is supported");
     70      ok(pts.take("105"), "H264 Baseline with packetization-mode=1 is supported");
     71      ok(pts.take("122"), "RED is supported");
     72      ok(pts.take("123"), "ULPFEC is supported");
     73    }
     74    ok(pts.empty(), `All supported codecs were tested. Untested codecs: ${JSON.stringify(pts.pts, null, 2)}`);
     75    for (const pt of allPts) {
     76      if (pt == "122" || pt == "123") {
     77        // ULPFEC and RED are meant to work combined with other codecs.
     78        // Forcing sdp with only one of them is not supported and will result in failures.
     79        continue;
     80      }
     81      await testScreenshare(pt);
     82    }
     83  });
     84 </script>
     85 </pre>
     86 </body>
     87 </html>