tor-browser

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

cross-origin.html (1593B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <script src=/resources/testharness.js></script>
      5 <script src=/resources/testharnessreport.js></script>
      6 </head>
      7 <body>
      8 <video autoplay controls id="output"></video>
      9 <script>
     10 
     11 // Run captureStream() on cross-origin <video> content
     12  async_test(function() {
     13    const video = document.createElement('video');
     14    video.src = location.origin.replace("//", "//www1.") + "/media/white.webm";
     15    video.onerror = this.unreached_func("<video> error");
     16    video.loop = true;
     17    video.play();
     18 
     19    const stream = video.captureStream();
     20    assert_not_equals(stream, null, "error generating stream");
     21    const output = document.getElementById("output");
     22    const canvas = document.createElement("canvas");
     23    const ctx = canvas.getContext('2d');
     24 
     25    stream.onaddtrack = this.step_func_done(function() {
     26      canvas.width = output.videoWidth || 320;
     27      canvas.height = output.videoHeight || 240;
     28      // The stream got a (number of) MediaStreamTracks added.
     29      assert_equals(stream.getVideoTracks().length, 1, 'video tracks');
     30      assert_equals(stream.getAudioTracks().length, 0, 'audio');
     31      assert_true(stream.getVideoTracks()[0].muted, 'cross-origin video is muted');
     32      ctx.drawImage(output, 0, 0, canvas.width, canvas.height);
     33 
     34      const pixels = ctx.getImageData(0,0,canvas.width, canvas.height);
     35      assert_equals(pixels.data[canvas.width*canvas.height*4 - 4], 0, "cross-origin content appears black");
     36     }, "<video>.captureStream() returns muted/black stream");
     37  }, "Capturing stream from cross-origin video");
     38 
     39 </script>
     40 </body>
     41 </html>