summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/media-source/mediasource-closed.html
blob: 4b22cae85445d73da19de7cd145a8789cd9f562f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<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(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.endOfStream("decode"); },
                  "endOfStream(decode) throws an exception when closed.");
          }, "Test endOfStream(decode) while closed.");

          test(function ()
          {
              var mediaSource = new MediaSource();
              assert_throws("InvalidStateError",
                  function() { mediaSource.endOfStream("network"); },
                  "endOfStream(network) throws an exception when closed.");
          }, "Test endOfStream(network) 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.");

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

              assert_equals(mediaSource.readyState, "open", "readyState is 'open'");
              // Setup a handler to run when the MediaSource closes.
              mediaSource.addEventListener("sourceclose", test.step_func(function (event)
              {
                  assert_equals(mediaSource.readyState, "closed", "readyState is 'closed'");
                  assert_throws("InvalidStateError",
                      function() { mediaSource.duration = 10; },
                      "Setting duration when closed throws an exception");
                  test.done();
              }));

              // Trigger the MediaSource to close.
              mediaElement.src = "";
          }, "Test setting duration while open->closed.");

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

              assert_equals(mediaSource.readyState, "open", "readyState is 'open'");
              // Setup a handler to run when the MediaSource closes.
              mediaSource.addEventListener("sourceclose", test.step_func(function (event)
              {
                  assert_equals(mediaSource.readyState, "closed", "readyState is 'closed'");
                  assert_true(isNaN(mediaSource.duration), "duration is NaN");
                  test.done();
              }));

              // Trigger the MediaSource to close.
              mediaElement.src = "";
          }, "Test getting duration while open->closed.");

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

              assert_equals(mediaSource.readyState, "open", "readyState is open");

              // Setup a handler to run when the MediaSource closes.
              mediaSource.addEventListener("sourceclose", test.step_func(function (event)
              {
                  assert_equals(mediaSource.readyState, "closed", "readyState is closed");
                  assert_throws("InvalidStateError",
                    function() { sourceBuffer.abort(); },
                    "sourceBuffer.abort() throws INVALID_STATE_ERROR");
                  test.done();
              }));

              // Trigger the MediaSource to close.
              mediaElement.src = "";
          }, "Test sourcebuffer.abort when closed.");

        </script>
    </body>
</html>