tor-browser

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

onencrypted.js (1797B)


      1 function runTest(config) {
      2    var expectedInitData = [];
      3    expectedInitData.push(stringToUint8Array(atob(config.keys[0].initData)));
      4    expectedInitData.push(stringToUint8Array(atob(config.keys[1].initData)));
      5 
      6    // Will get 2 identical events, one for audio, one for video.
      7    var expectedEvents = 2;
      8    var currentData;
      9 
     10    async_test(function (test) {
     11        var video = config.video,
     12            mediaSource,
     13            onEncrypted = function (event) {
     14                currentData = new Uint8Array(event.initData);
     15                assert_equals(event.target, config.video);
     16                assert_true(event instanceof window.MediaEncryptedEvent);
     17                assert_equals(event.type, 'encrypted');
     18                assert_equals(event.initDataType, 'cenc');
     19                // At this point we do not know if the event is related to audio or video. So check for both expected init data
     20                assert_true(checkInitData(currentData, expectedInitData[0]) || checkInitData(currentData, expectedInitData[1]));
     21 
     22                if (--expectedEvents === 0) {
     23                    test.done();
     24                }
     25            };
     26 
     27        waitForEventAndRunStep('encrypted', video, onEncrypted, test);
     28        testmediasource(config).then(function (source) {
     29            mediaSource = source;
     30            config.video.src = URL.createObjectURL(mediaSource);
     31            return source.done;
     32        }).then(function(){
     33            video.play();
     34        });
     35    }, 'encrypted fired on encrypted media file.');
     36 }
     37 
     38 function checkInitData(data, expectedData) {
     39    if (data.length !== expectedData.length) {
     40        return false;
     41    }
     42    for (var i = 0; i < data.length; i++) {
     43        if (data[i] !== expectedData[i]) {
     44            return false;
     45        }
     46    }
     47    return true;
     48 }