tor-browser

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

reset-src-after-setmediakeys.js (2360B)


      1 function runTest(config)
      2 {
      3    async_test(function(test) {
      4        var mediaKeys;
      5        var mediaSource;
      6        var encryptedEventIndex = 0;
      7        var video = config.video;
      8        var keysystem = config.keysystem;
      9        var configuration = {
     10            initDataTypes: [config.initDataType],
     11            audioCapabilities: [{
     12                contentType: config.audioType
     13            }],
     14            videoCapabilities: [{
     15                contentType: config.videoType
     16            }],
     17            sessionTypes: ['temporary']
     18        };
     19 
     20        assert_not_equals(video, null);
     21 
     22        var onEncrypted = function(event) {
     23            ++encryptedEventIndex;
     24            assert_equals(video.mediaKeys, mediaKeys);
     25 
     26            // This event is fired once for the audio stream and once
     27            // for the video stream each time .src is set.
     28            if (encryptedEventIndex === 2) {
     29                // Finished first video; Create new media source and wait for two more encrypted events
     30                return testmediasource(config).then(function (source) {
     31                    video.src = URL.createObjectURL(source);
     32                }).catch(function (error) {
     33                    forceTestFailureFromPromise(test, error)
     34                });
     35            } else if (encryptedEventIndex === 4) {
     36                // Finished second video.
     37                test.done();
     38            }
     39        };
     40 
     41        // Create a MediaKeys object and assign it to video.
     42        navigator.requestMediaKeySystemAccess(keysystem, [configuration]).then(test.step_func(function (access) {
     43            assert_equals(access.keySystem, keysystem);
     44            return access.createMediaKeys();
     45        })).then(test.step_func(function (result) {
     46            mediaKeys = result;
     47            assert_not_equals(mediaKeys, null);
     48            return video.setMediaKeys(mediaKeys);
     49        })).then(test.step_func(function () {
     50            assert_equals(video.mediaKeys, mediaKeys);
     51            return testmediasource(config);
     52        })).then(function (source) {
     53            waitForEventAndRunStep('encrypted', video, onEncrypted, test);
     54            mediaSource = source;
     55            video.src = URL.createObjectURL(mediaSource);
     56        }).catch(function (error) {
     57            forceTestFailureFromPromise(test, error);
     58        });
     59 
     60    }, 'Reset src after setMediaKeys().');
     61 }