tor-browser

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

mediasource-appendbuffer-quota-exceeded.html (5076B)


      1 <!DOCTYPE html>
      2 <!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
      3 <meta charset="utf-8">
      4 <meta name="timeout" content="long">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="mediasource-util.js"></script>
      8 <script>
      9    var subType = MediaSourceUtil.getSubType(MediaSourceUtil.AUDIO_ONLY_TYPE);
     10    var manifestFilenameAudio = subType + '/test-a-128k-44100Hz-1ch-manifest.json';
     11 
     12    // Fill up a given SourceBuffer by appending data repeatedly via doAppendDataFunc until
     13    // an exception is thrown. The thrown exception is passed to onCaughtExceptionCallback.
     14    function fillUpSourceBuffer(test, sourceBuffer, doAppendDataFunc, onCaughtExceptionCallback) {
     15        assert_false(sourceBuffer.updating, 'updating should be false before attempting an append operation');
     16 
     17        // We are appending data repeatedly in sequence mode, there should be no gaps.
     18        let sbLength = sourceBuffer.buffered.length;
     19        assert_false(sbLength > 1, 'unexpected gap in buffered ranges.');
     20 
     21        let previousBufferedStart = sbLength == 0 ? -Infinity : sourceBuffer.buffered.start(0);
     22        let previousBufferedEnd = sbLength == 0 ? -Infinity : sourceBuffer.buffered.end(0);
     23        let appendSucceeded = true;
     24        try {
     25            doAppendDataFunc();
     26        } catch(ex) {
     27            onCaughtExceptionCallback(ex, previousBufferedStart, previousBufferedEnd);
     28            appendSucceeded = false;
     29        }
     30        if (appendSucceeded) {
     31          assert_true(sourceBuffer.updating, 'updating should be true if synchronous portion of appendBuffer succeeded');
     32          test.expectEvent(sourceBuffer, 'updateend', 'append ended.');
     33          test.waitForExpectedEvents(function() { fillUpSourceBuffer(test, sourceBuffer, doAppendDataFunc, onCaughtExceptionCallback); });
     34        }
     35    }
     36 
     37    mediasource_test(function(test, mediaElement, mediaSource)
     38    {
     39        mediaElement.addEventListener('error', test.unreached_func('Unexpected media element error event'));
     40        MediaSourceUtil.fetchManifestAndData(test, manifestFilenameAudio, function(typeAudio, dataAudio)
     41        {
     42            var sourceBuffer = mediaSource.addSourceBuffer(typeAudio);
     43            sourceBuffer.mode = 'sequence';
     44            fillUpSourceBuffer(test, sourceBuffer,
     45                function () { // doAppendDataFunc
     46                    sourceBuffer.appendBuffer(dataAudio);
     47                },
     48                function (ex, previousBufferedStart, previousBufferedEnd) { // onCaughtExceptionCallback
     49                    assert_equals(ex.constructor, globalThis.QuotaExceededError, 'QuotaExceededError constructor match');
     50                    assert_equals(ex.quota, null, 'quota');
     51                    assert_equals(ex.requested, null, 'requested');
     52 
     53                    // Verify that the state looks like appendBuffer stops executing its steps if the prepare append
     54                    // algorithm aborts after throwing `QuotaExceededError`.
     55 
     56                    assert_false(sourceBuffer.updating, 'updating should be false if appendBuffer throws QuotaExceededError');
     57 
     58                    sourceBuffer.onupdatestart = test.unreached_func('buffer append, signalled by updatestart, should not be in progress');
     59                    sourceBuffer.onupdate = test.unreached_func('buffer append, signalled by update, should not be in progress');
     60                    sourceBuffer.onupdateend = test.unreached_func('buffer append, signalled by updateend, should not be in progress');
     61 
     62                    // Ensure the async append was not actually run by letting their event handlers have some time before we proceed.
     63                    test.step_timeout(function() {
     64                        // At least the first doAppendDataFunc call shouldn't throw QuotaExceededError, unless the audio
     65                        // test media itself is too large for one append. If that's the case, then many other tests should
     66                        // fail and the choice of test media may need to be changed.
     67                        assert_equals(sourceBuffer.buffered.length, 1, 'test expects precisely one buffered range here');
     68                        assert_equals(sourceBuffer.buffered.start(0), previousBufferedStart, 'QuotaExceededError should not update buffered media');
     69                        assert_equals(sourceBuffer.buffered.end(0), previousBufferedEnd, 'QuotaExceededError should not update buffered media');
     70 
     71                        // Note, it's difficult to verify that the user agent does not "Add |data| to the end of the |input buffer|" if
     72                        // the attempted appendBuffer() of that |data| caused QuotaExceededError.
     73                        test.done();
     74                    }, 1000 /* 1 second, modifiable by harness multiplier */ );
     75                });
     76        });
     77    }, 'Appending data repeatedly should fill up the buffer and throw a QuotaExceededError when buffer is full.');
     78 </script>