tor-browser

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

setmediakeys-multiple-times-with-different-mediakeys.js (4778B)


      1 function runTest(config, qualifier) {
      2    var testname = testnamePrefix( qualifier, config.keysystem )
      3                         + ', setmediakeys multiple times with different mediakeys';
      4 
      5    var configuration = getSimpleConfigurationForContent( config.content );
      6 
      7    async_test (function (test) {
      8        var _video = config.video,
      9            _access,
     10            _mediaKeys1,
     11            _mediaKeys2,
     12            _usingMediaKeys2 = false;;
     13 
     14        // Test MediaKeys assignment.
     15        assert_equals(_video.mediaKeys, null);
     16        assert_equals(typeof _video.setMediaKeys, 'function');
     17 
     18        function onFailure(error) {
     19            forceTestFailureFromPromise(test, error);
     20        }
     21 
     22        navigator.requestMediaKeySystemAccess(config.keysystem, [configuration]).then(function(access) {
     23            _access = access;
     24            return _access.createMediaKeys();
     25        }).then(test.step_func(function(result) {
     26            _mediaKeys1 = result;
     27            assert_not_equals(_mediaKeys1, null);
     28            // Create a second mediaKeys.
     29            return _access.createMediaKeys();
     30        })).then(test.step_func(function(result) {
     31            _mediaKeys2 = result;
     32            assert_not_equals(_mediaKeys2, null);
     33            // Set _mediaKeys1 on video.
     34            return _video.setMediaKeys(_mediaKeys1);
     35        })).then(test.step_func(function() {
     36            assert_equals(_video.mediaKeys, _mediaKeys1);
     37            // Set _mediaKeys2 on video (switching MediaKeys).
     38            return _video.setMediaKeys(_mediaKeys2);
     39        })).then(test.step_func(function() {
     40            assert_equals(_video.mediaKeys, _mediaKeys2);
     41            // Clear mediaKeys from video.
     42            return _video.setMediaKeys(null);
     43        })).then(test.step_func(function() {
     44            assert_equals(_video.mediaKeys, null);
     45            // Set _mediaKeys1 on video again.
     46            return _video.setMediaKeys(_mediaKeys1);
     47        })).then(test.step_func(function() {
     48            assert_equals(_video.mediaKeys, _mediaKeys1);
     49            return testmediasource(config);
     50        })).then(function(source) {
     51            // Set src attribute on Video Element
     52            _video.src = URL.createObjectURL(source);
     53            // According to the specification, support for changing the Media Keys object after
     54            // the src attribute on the video element has been set is optional. The following operation
     55            // may therefore either succeed or fail. We handle both cases.
     56            return _video.setMediaKeys(_mediaKeys2);
     57        }).then(test.step_func(function() {
     58            // Changing the Media Keys object succeeded
     59            _usingMediaKeys2 = true;
     60            assert_equals(_video.mediaKeys, _mediaKeys2);
     61            // Return something so the promise resolves properly.
     62            return Promise.resolve();
     63        }), test.step_func(function(error) {
     64            // Changing the Media Keys object failed
     65            _usingMediaKeys2 = false;
     66            assert_equals(_video.mediaKeys, _mediaKeys1);
     67            // The specification allows either NotSupportedError or InvalidStateError depending on
     68            // whether the failure was because changing Media Keys object is not supported
     69            // or just not allowed at this time, respectively.
     70            assert_in_array(error.name, ['InvalidStateError','NotSupportedError']);
     71            assert_not_equals(error.message, '');
     72            // Return something so the promise resolves properly.
     73            return Promise.resolve();
     74        })).then(function() {
     75            // According to the specification, support for clearing the Media Keys object associated
     76            // with the video element is optional. The following operation
     77            // may therefore either succeed or fail. We handle both cases.
     78            return _video.setMediaKeys(null);
     79        }).then(test.step_func(function() {
     80            // Clearing the media keys succeeded
     81            assert_equals(_video.mediaKeys, null);
     82            test.done();
     83        }), test.step_func(function(error) {
     84            // Clearing the media keys failed
     85            if(!_usingMediaKeys2) {
     86                assert_equals(_video.mediaKeys, _mediaKeys1);
     87            } else {
     88                assert_equals(_video.mediaKeys, _mediaKeys2);
     89            }
     90            // The specification allows either NotSupportedError or InvalidStateError depending on
     91            // whether the failure was because changing Media Keys object is not supported
     92            // or just not allowed at this time, respectively.
     93            assert_in_array(error.name, ['InvalidStateError','NotSupportedError']);
     94            assert_not_equals(error.message, '');
     95            test.done();
     96        })).catch(onFailure);
     97    }, testname);
     98 }