tor-browser

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

playback-persistent-license.js (3503B)


      1 function runTest(config,qualifier) {
      2 
      3    var testname = testnamePrefix(qualifier, config.keysystem)
      4                                    + ', persistent-license, '
      5                                    + /video\/([^;]*)/.exec(config.videoType)[1]
      6                                    + 'playback';
      7 
      8    var configuration = {   initDataTypes: [ config.initDataType ],
      9                            audioCapabilities: [ { contentType: config.audioType } ],
     10                            videoCapabilities: [ { contentType: config.videoType } ],
     11                            sessionTypes: [ 'persistent-license' ] };
     12 
     13 
     14    async_test(function(test) {
     15        var _video = config.video,
     16            _mediaKeys,
     17            _mediaKeySession,
     18            _mediaSource;
     19 
     20        function onFailure(error) {
     21            forceTestFailureFromPromise(test, error);
     22        }
     23 
     24        function onMessage(event) {
     25            assert_equals( event.target, _mediaKeySession );
     26            assert_true( event instanceof window.MediaKeyMessageEvent );
     27            assert_equals( event.type, 'message');
     28 
     29            assert_in_array( event.messageType, [ 'license-request', 'individualization-request' ] );
     30 
     31            config.messagehandler(event.messageType, event.message).then( function( response ) {
     32                return _mediaKeySession.update(response)
     33            }).catch(onFailure);
     34        }
     35 
     36        function onEncrypted(event) {
     37            assert_equals(event.target, _video);
     38            assert_true(event instanceof window.MediaEncryptedEvent);
     39            assert_equals(event.type, 'encrypted');
     40 
     41            waitForEventAndRunStep('message', _mediaKeySession, onMessage, test);
     42            _mediaKeySession.generateRequest(   config.initData ? config.initDataType : event.initDataType,
     43                                                config.initData || event.initData ).catch(onFailure);
     44        }
     45 
     46        function onTimeupdate(event) {
     47            if (_video.currentTime > (config.duration || 1)) {
     48                _video.pause();
     49                test.done();
     50            }
     51        }
     52 
     53        function onPlaying(event) {
     54            // Not using waitForEventAndRunStep() to avoid too many
     55            // EVENT(onTimeUpdate) logs.
     56            _video.addEventListener('timeupdate', onTimeupdate, true);
     57        }
     58 
     59        navigator.requestMediaKeySystemAccess(config.keysystem, [ configuration ]).then(function(access) {
     60            return access.createMediaKeys();
     61        }).then(function(mediaKeys) {
     62            _mediaKeys = mediaKeys;
     63            return _video.setMediaKeys(_mediaKeys);
     64        }).then(function() {
     65            _mediaKeySession = _mediaKeys.createSession( 'persistent-license' );
     66            waitForEventAndRunStep('encrypted', _video, onEncrypted, test);
     67            waitForEventAndRunStep('playing', _video, onPlaying, test);
     68            return testmediasource(config);
     69        }).then(function(source) {
     70            _mediaSource = source;
     71            _video.src = URL.createObjectURL(_mediaSource);
     72            return source.done;
     73        }).then(function(){
     74            _video.play();
     75        }).catch(function (error) {
     76            if (error && error.name === 'NotSupportedError') {
     77                // If persistent license is not supported, skip test as
     78                // key systems are not required to support this session
     79                // type.
     80                test.done();
     81            } else {
     82                onFailure(error);
     83            }
     84        });
     85    }, testname);
     86 }