https://github.com/web-platform-tests/wpt
Raw File
Tip revision: d8d1e562cf597bc2314419b46aff77d9e3664247 authored by Anne van Kesteren on 08 October 2014, 07:34:29 UTC
Make new Blob throw
Tip revision: d8d1e56
mediasource-closed.html
<!DOCTYPE html>
<html>
    <head>
        <title>MediaSource.readyState equals "closed" test cases.</title>
        <script src="/resources/testharness.js"></script>
        <script src="/resources/testharnessreport.js"></script>
        <script src="mediasource-util.js"></script>
    </head>
    <body>
        <div id="log"></div>
        <script>
          test(function ()
          {
              var mediaSource = new MediaSource();
              assert_equals(mediaSource.sourceBuffers.length, 0, "sourceBuffers is empty");
              assert_equals(mediaSource.activeSourceBuffers.length, 0, "activeSourceBuffers is empty");
              assert_equals(mediaSource.readyState, "closed", "readyState is 'closed'");
              assert_true(Number.isNaN(mediaSource.duration), "duration is NaN");
          }, "Test attribute values on a closed MediaSource object.");

          test(function ()
          {
              var mediaSource = new MediaSource();
              assert_throws("InvalidStateError",
                  function() { mediaSource.addSourceBuffer(MediaSourceUtil.VIDEO_ONLY_TYPE); },
                  "addSourceBuffer() throws an exception when closed.");
          }, "Test addSourceBuffer() while closed.");

          mediasource_test(function(test, mediaElement, mediaSource)
          {
              var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_ONLY_TYPE);

              // Setup a handler to run when the MediaSource closes.
              mediaSource.addEventListener('sourceclose', test.step_func(function (event)
              {
                  assert_equals(mediaSource.sourceBuffers.length, 0, "sourceBuffers is empty");
                  assert_equals(mediaSource.activeSourceBuffers.length, 0, "activeSourceBuffers is empty");
                  assert_equals(mediaSource.readyState, "closed", "readyState is 'closed'");
                  assert_throws("NotFoundError",
                      function() { mediaSource.removeSourceBuffer(sourceBuffer); },
                      "removeSourceBuffer() throws an exception when closed.");
                  test.done();
              }));

              // Trigger the MediaSource to close.
              mediaElement.src = "";
          }, "Test removeSourceBuffer() while closed.");

          test(function ()
          {
              var mediaSource = new MediaSource();
              assert_throws("InvalidStateError",
                  function() { mediaSource.endOfStream(); },
                  "endOfStream() throws an exception when closed.");
          }, "Test endOfStream() while closed.");


          test(function ()
          {
              var mediaSource = new MediaSource();
              assert_throws("InvalidStateError",
                  function() { mediaSource.duration = 10; },
                  "Setting duration throws an exception when closed.");
          }, "Test setting duration while closed.");

        </script>
    </body>
</html>
back to top