tor-browser

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

SourceBuffer-abort-readyState.html (2473B)


      1 <!doctype html>
      2 <html>
      3 <head>
      4  <meta charset='utf-8'>
      5  <title>SourceBuffer#abort() when readyState attribute is not in the "open"</title>
      6  <meta name="timeout" content="long">
      7  <script src="/resources/testharness.js"></script>
      8  <script src="/resources/testharnessreport.js"></script>
      9 </head>
     10 <body>
     11 <div id="log"></div>
     12 
     13 <script>
     14 var contents = {'/media/white.webm': 'video/webm; codecs="vorbis,vp8"',
     15                '/media/white.mp4' : 'video/mp4'};
     16 
     17 //check the browser supports the MIME used in this test
     18 function isTypeSupported(mime) {
     19    if(!MediaSource.isTypeSupported(mime)) {
     20        this.step(function() {
     21            assert_unreached("Browser doesn't support the MIME used in this test: " + mime);
     22        });
     23        this.done();
     24        return false;
     25    }
     26    return true;
     27 }
     28 function GET(url, processBody) {
     29    var xhr = new XMLHttpRequest();
     30    xhr.open('GET', url, true);
     31    xhr.responseType = 'arraybuffer';
     32    xhr.send();
     33    xhr.onload = function(e) {
     34        if (xhr.status != 200) {
     35            alert("Unexpected status code " + xhr.status + " for " + url);
     36            return false;
     37        }
     38        processBody(new Uint8Array(xhr.response));
     39    };
     40 }
     41 function mediaTest(file, mime) {
     42    async_test(function(t) {
     43        if(!isTypeSupported.bind(t)(mime)) {
     44            return;
     45        }
     46        GET(file, function(data) {
     47            var mediaSource = new MediaSource();
     48            var sourceBuffer = null;
     49            mediaSource.addEventListener('sourceopen', function(e) {
     50                sourceBuffer = mediaSource.addSourceBuffer(mime);
     51                mediaSource.endOfStream();
     52                assert_equals(mediaSource.readyState, 'ended',
     53                              'mediaSource.readyState is "ended" after endOfStream()');
     54            });
     55            mediaSource.addEventListener('sourceended', t.step_func_done(function(e) {
     56                assert_throws_dom('InvalidStateError', function() {
     57                    sourceBuffer.abort();
     58                });
     59            }));
     60            var video = document.createElement('video');
     61            video.src = window.URL.createObjectURL(mediaSource);
     62        });
     63    }, 'SourceBuffer#abort() (' + mime + ') : If the readyState attribute ' +
     64       'of the parent media source is not in the "open" state then throw ' +
     65       'an INVALID_STATE_ERR exception and abort these steps.');
     66 }
     67 for(var file in contents) {
     68    mediaTest(file, contents[file]);
     69 }
     70 </script>
     71 </body>
     72 </html>