tor-browser

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

test_getUserMedia_peerIdentity.html (1712B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
      5  <script type="application/javascript" src="blacksilence.js"></script>
      6 </head>
      7 <body>
      8 <pre id="test">
      9 <script type="application/javascript">
     10 createHTML({
     11  title: "Test getUserMedia peerIdentity Constraint",
     12  bug: "942367"
     13 });
     14 async function theTest() {
     15  async function testPeerIdentityConstraint(withConstraint) {
     16    const config = { audio: true, video: true };
     17    if (withConstraint) {
     18      config.peerIdentity = 'user@example.com';
     19    }
     20    info('getting media with constraints: ' + JSON.stringify(config));
     21    const stream = await getUserMedia(config);
     22    for (const track of stream.getTracks()) {
     23      const recorder = new MediaRecorder(new MediaStream([track]));
     24      try {
     25        recorder.start();
     26        ok(!withConstraint,
     27          `gUM ${track.kind} track without peerIdentity must not throw`);
     28        recorder.stop();
     29      } catch(e) {
     30        ok(withConstraint,
     31          `gUM ${track.kind} track with peerIdentity must throw`);
     32      }
     33    }
     34    await Promise.all([
     35      audioIsSilence(withConstraint, stream),
     36      videoIsBlack(withConstraint, stream),
     37    ]);
     38    stream.getTracks().forEach(t => t.stop());
     39  };
     40 
     41  // Start a tone so that the gUM call will record something even
     42  // with --use-test-media-devices.
     43  const audioContext = new AudioContext();
     44  const tone = new LoopbackTone(audioContext, TEST_AUDIO_FREQ);
     45  tone.start();
     46 
     47  try {
     48    // both without and with the constraint
     49    await testPeerIdentityConstraint(false);
     50    await testPeerIdentityConstraint(true);
     51  } finally {
     52    tone.stop();
     53  }
     54 }
     55 
     56 runTest(theTest);
     57 
     58 </script>
     59 </pre>
     60 </body>
     61 </html>