tor-browser

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

SourceBuffer-abort-updating.html (3545B)


      1 <!doctype html>
      2 <html>
      3 <head>
      4  <meta charset='utf-8'>
      5  <title>Check SourceBuffer#abort() when the updating attribute is true</title>
      6  <script src="/resources/testharness.js"></script>
      7  <script src="/resources/testharnessreport.js"></script>
      8 </head>
      9 <body>
     10 <div id="log"></div>
     11 
     12 <script>
     13 var contents = {'/media/white.webm': 'video/webm; codecs="vorbis,vp8"',
     14                '/media/white.mp4' : 'video/mp4'};
     15 
     16 function GET(url, processBody) {
     17    var xhr = new XMLHttpRequest();
     18    xhr.open('GET', url, true);
     19    xhr.responseType = 'arraybuffer';
     20    xhr.send();
     21    xhr.onload = function(e) {
     22        if (xhr.status != 200) {
     23            alert("Unexpected status code " + xhr.status + " for " + url);
     24            return false;
     25        }
     26        processBody(new Uint8Array(xhr.response));
     27    };
     28 }
     29 //check the browser supports the MIME used in this test
     30 function isTypeSupported(mime) {
     31    if(!MediaSource.isTypeSupported(mime)) {
     32        this.step(function() {
     33            assert_unreached("Browser doesn't support the MIME used in this test: " + mime);
     34        });
     35        this.done();
     36        return false;
     37    }
     38    return true;
     39 }
     40 function mediaTest(file, mime) {
     41    async_test(function(t) {
     42        if(!isTypeSupported.bind(t)(mime)) {
     43            return;
     44        }
     45        GET(file, function(data) {
     46            var mediaSource = new MediaSource();
     47            var num_updateend = 0;
     48            var events = [];
     49            mediaSource.addEventListener('sourceopen', t.step_func(function(e) {
     50                var sourceBuffer = mediaSource.addSourceBuffer(mime);
     51                assert_equals(sourceBuffer.updating, false);
     52                sourceBuffer.addEventListener('updatestart', t.step_func(function(e) {
     53                    events.push('updatestart');
     54                    //abort when sourceBuffer#updating is true
     55                    sourceBuffer.abort();
     56 
     57                    assert_equals(sourceBuffer.updating, false,
     58                                  'Check updating value after calling abort.');
     59                    assert_equals(sourceBuffer.appendWindowStart, 0);
     60                    assert_equals(sourceBuffer.appendWindowEnd, Number.POSITIVE_INFINITY);
     61                }));
     62                sourceBuffer.addEventListener('update', t.step_func(function(e) {
     63                    assert_unreached("Can't touch this");
     64                }));
     65                sourceBuffer.addEventListener('updateend', function(e) {
     66                    events.push('updateend');
     67                    mediaSource.endOfStream();
     68                });
     69                sourceBuffer.addEventListener('abort', function(e) {
     70                    events.push('abort');
     71                });
     72                sourceBuffer.addEventListener('error', t.step_func(function(e) {
     73                    assert_unreached("Can't touch this");
     74                }));
     75                sourceBuffer.appendBuffer(data);
     76            }));
     77            mediaSource.addEventListener('sourceended', t.step_func_done(function(e) {
     78                assert_array_equals(events,
     79                                    ['updatestart', 'abort', 'updateend'],
     80                                    'Check the sequence of fired events.');
     81            }));
     82            var video = document.createElement('video');
     83            video.src = window.URL.createObjectURL(mediaSource);
     84        });
     85    }, 'SourceBuffer#abort() (' + mime + ') : Check the algorithm when the updating attribute is true.');
     86 }
     87 for(var file in contents) {
     88    mediaTest(file, contents[file]);
     89 }
     90 </script>
     91 </body>
     92 </html>