tor-browser

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

playback-temporary-playduration-keystatus.js (3298B)


      1 function runTest(config,qualifier) {
      2 
      3    var testname = testnamePrefix(qualifier, config.keysystem)
      4                                    + ', temporary, '
      5                                    + /video\/([^;]*)/.exec(config.videoType)[1]
      6                                    + ', playback with limited playduration, check keystatus, ' + config.testcase;
      7 
      8    var configuration = {   initDataTypes: [ config.initDataType ],
      9                            audioCapabilities: [ { contentType: config.audioType } ],
     10                            videoCapabilities: [ { contentType: config.videoType } ],
     11                            sessionTypes: [ 'temporary' ] };
     12 
     13    async_test(function(test) {
     14 
     15        var _video = config.video,
     16            _mediaKeys,
     17            _mediaKeySession,
     18            _mediaSource;
     19 
     20        function onFailure(error) {
     21            forceTestFailureFromPromise(test, error);
     22        }
     23 
     24        function onEncrypted(event) {
     25            assert_equals(event.target, _video);
     26            assert_true(event instanceof window.MediaEncryptedEvent);
     27            assert_equals(event.type, 'encrypted');
     28 
     29            // Only create the session for the first encrypted event
     30            if (_mediaKeySession !== undefined) return;
     31 
     32            var initDataType = config.initData ? config.initDataType : event.initDataType;
     33            var initData = config.initData || event.initData;
     34 
     35            _mediaKeySession = _mediaKeys.createSession('temporary');
     36            waitForEventAndRunStep('message', _mediaKeySession, onMessage, test);
     37            _mediaKeySession.generateRequest( initDataType, initData ).catch(onFailure);
     38        }
     39 
     40        function onMessage(event) {
     41            assert_equals(event.target, _mediaKeySession);
     42            assert_true(event instanceof window.MediaKeyMessageEvent);
     43            assert_equals(event.type, 'message');
     44 
     45            assert_in_array(event.messageType, ['license-request', 'individualization-request']);
     46 
     47            config.messagehandler(event.messageType, event.message, {playDuration: config.playduration}).then(function(response) {
     48                return event.target.update(response);
     49            }).catch(onFailure);
     50        }
     51 
     52        function onPlaying(event) {
     53            waitForEventAndRunStep('keystatuseschange', _mediaKeySession, onKeystatuseschange, test);
     54        }
     55 
     56        function onKeystatuseschange(event) {
     57            for (var status of event.target.keyStatuses.values()) {
     58                assert_equals(status, "expired", "All keys should have keyStatus expired");
     59            }
     60            test.done();
     61        }
     62 
     63        navigator.requestMediaKeySystemAccess(config.keysystem, [configuration]).then(function(access) {
     64            return access.createMediaKeys();
     65        }).then(function(mediaKeys) {
     66            _mediaKeys = mediaKeys;
     67            return _video.setMediaKeys(_mediaKeys);
     68        }).then(function(){
     69            waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
     70            waitForEventAndRunStep('playing', _video, onPlaying, test);
     71            return testmediasource(config);
     72        }).then(function(source) {
     73            _mediaSource = source;
     74            _video.src = URL.createObjectURL(_mediaSource);
     75            _video.play();
     76        }).catch(onFailure);
     77    }, testname);
     78 }