tor-browser

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

test_eme_missing_pssh.html (3409B)


      1 <!DOCTYPE HTML>
      2 <html>
      3  <head>
      4    <title>Test Encrypted Media Extensions</title>
      5    <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7    <script type="text/javascript" src="manifest.js"></script>
      8    <script type="text/javascript" src="eme.js"></script>
      9  </head>
     10  <body>
     11    <audio controls id="audio"></audio>
     12    <pre id="test">
     13    <script class="testbody" type="text/javascript">
     14 
     15      // Tests that a fragmented MP4 file without a PSSH, but with valid encrypted
     16      // tracks with valid TENC boxes, is able to load with EME.
     17      // We setup MSE before starting up EME, so that we exercise the "waiting for
     18      // cdm" step in the MediaDecoderStateMachine.
     19 
     20      SimpleTest.waitForExplicitFinish();
     21 
     22      var pssh = [
     23        0x00, 0x00, 0x00, 0x00,
     24        0x70, 0x73, 0x73, 0x68, // BMFF box header (76 bytes, 'pssh')
     25        0x01, 0x00, 0x00, 0x00,                         // Full box header (version = 1, flags = 0)
     26        0x10, 0x77, 0xef, 0xec, 0xc0, 0xb2, 0x4d, 0x02, // SystemID
     27        0xac, 0xe3, 0x3c, 0x1e, 0x52, 0xe2, 0xfb, 0x4b,
     28        0x00, 0x00, 0x00, 0x01,                         // KID_count (1)
     29        0x2f, 0xef, 0x8a, 0xd8, 0x12, 0xdf, 0x42, 0x97,
     30        0x83, 0xe9, 0xbf, 0x6e, 0x5e, 0x49, 0x3e, 0x53,
     31        0x00, 0x00, 0x00, 0x00                         // Size of Data (0)
     32      ];
     33 
     34      var audio = document.getElementById("audio");
     35 
     36      function LoadEME() {
     37        var options = [{
     38          initDataType: 'cenc',
     39          audioType: 'audio/mp4; codecs="mp4a.40.2"',
     40        }];
     41        navigator.requestMediaKeySystemAccess("org.w3.clearkey", options)
     42          .then((keySystemAccess) => {
     43            return keySystemAccess.createMediaKeys();
     44          }, bail("Failed to request key system access."))
     45 
     46          .then((mediaKeys) => {
     47            audio.setMediaKeys(mediaKeys);
     48            var session = mediaKeys.createSession();
     49            once(session, "message", (message) => {
     50              is(message.messageType, 'license-request', "Expected a license-request");
     51              var license = new TextEncoder().encode(JSON.stringify({
     52                'keys': [{
     53                  'kty':'oct',
     54                  'kid':'L--K2BLfQpeD6b9uXkk-Uw',
     55                  'k':HexToBase64('7f412f0575f44f718259beef56ec7771')
     56                 }],
     57                 'type': 'temporary'
     58              }));
     59              session.update(license);
     60            });
     61            session.generateRequest('cenc', new Uint8Array(pssh));
     62          });
     63      }
     64 
     65      function DownloadMedia(url, type, mediaSource) {
     66        return new Promise(function(resolve) {
     67          var sourceBuffer = mediaSource.addSourceBuffer(type);
     68          fetchWithXHR(url, (response) => {
     69            once(sourceBuffer, "updateend", resolve);
     70            sourceBuffer.appendBuffer(new Uint8Array(response));
     71          });
     72        });
     73      }
     74 
     75      function LoadMSE() {
     76        var ms = new MediaSource();
     77        audio.src = URL.createObjectURL(ms);
     78 
     79        once(ms, "sourceopen", ()=>{
     80          DownloadMedia('short-audio-fragmented-cenc-without-pssh.mp4', 'audio/mp4; codecs="mp4a.40.2"', ms)
     81            .then(() => { ms.endOfStream(); LoadEME();});
     82        });
     83 
     84        audio.addEventListener("loadeddata", SimpleTest.finish);
     85      }
     86 
     87      LoadMSE();
     88 
     89  </script>
     90  </pre>
     91  </body>
     92 </html>