chromium/third_party/blink/web_tests/http/tests/media/media-source/mediasource-endofstream-invaliderror.html

<!DOCTYPE html>
<html>
    <head>
        <script src="/w3c/resources/testharness.js"></script>
        <script src="/w3c/resources/testharnessreport.js"></script>
        <script src="mediasource-util.js"></script>
        <link rel='stylesheet' href='/w3c/resources/testharness.css'>
    </head>
    <body>
        <div id="log"></div>
        <script>
          mediasource_test(function(test, mediaElement, mediaSource)
          {
              test.failOnEvent(mediaElement, 'error');
              assert_equals(mediaSource.readyState, 'open');

              assert_throws_js(TypeError,
                  function() { mediaSource.endOfStream('garbage'); },
                  'endOfStream(\'garbage\') throws TypeError');

              assert_equals(mediaSource.readyState, 'open');
              test.done();
          }, 'Test MediaSource.endOfStream() with invalid non-empty error string.');

          mediasource_test(function(test, mediaElement, mediaSource)
          {
              test.failOnEvent(mediaElement, 'error');
              assert_equals(mediaSource.readyState, 'open');

              assert_throws_js(TypeError,
                  function() { mediaSource.endOfStream(''); },
                  'endOfStream(\'\') throws TypeError');

              assert_equals(mediaSource.readyState, 'open');
              test.done();
          }, 'Test MediaSource.endOfStream() with invalid empty error string.');

          mediasource_test(function(test, mediaElement, mediaSource)
          {
              test.failOnEvent(mediaElement, 'error');
              assert_equals(mediaSource.readyState, 'open');

              test.expectEvent(mediaSource, 'sourceend');
              mediaSource.endOfStream();

              assert_equals(mediaSource.readyState, 'ended');
              assert_throws_dom("InvalidStateError",
                  function() {  mediaSource.endOfStream(); },
                  "endofStream() threw an exception when in ended state");
             
              test.done();
          }, 'Test MediaSource.endOfStream() with when readyState is ended.');
          
          mediasource_test(function(test, mediaElement, mediaSource)
          {
              test.failOnEvent(mediaElement, 'error');
              assert_equals(mediaSource.readyState, 'open');

              test.expectEvent(mediaSource, 'sourceend');
              mediaSource.endOfStream();

              assert_equals(mediaSource.readyState, 'ended');
              assert_throws_dom("InvalidStateError",
                  function() {  mediaSource.endOfStream("decode"); },
                  "endofStream() threw an exception when in ended state");
   
              test.done();
          }, 'Test MediaSource.endOfStream(decode) with when readyState is ended.');

          mediasource_test(function(test, mediaElement, mediaSource)
          {
              test.failOnEvent(mediaElement, 'error');
              assert_equals(mediaSource.readyState, 'open');

              test.expectEvent(mediaSource, 'sourceend');
              mediaSource.endOfStream();

              assert_equals(mediaSource.readyState, 'ended');
              assert_throws_dom("InvalidStateError",
                  function() {  mediaSource.endOfStream("network"); },
                  "endofStream() threw an exception when in ended state");
              
              test.done();
          }, 'Test MediaSource.endOfStream(network) with when readyState is ended.');
                              
          mediasource_test(function(test, mediaElement, mediaSource)
          {
              test.failOnEvent(mediaElement, 'error');
              assert_equals(mediaSource.readyState, 'open');

              assert_throws_js(TypeError,
                  function() { mediaSource.endOfStream(null); },
                  'endOfStream(null) throws TypeError');

              assert_equals(mediaSource.readyState, 'open');
              test.done();
          }, 'Test MediaSource.endOfStream() with invalid null error parameter.');
        </script>
    </body>
</html>