| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>media-source-real-state-errors</title> |
| <script src="mp4-generator.js"></script> |
| <script src="../video-test.js"></script> |
| <script> |
| // Tests that MSE methods throw correct exceptions when called in |
| // invalid states. MSE spec sections 2 and 3. |
| |
| var source; |
| var sourceBuffer; |
| var thrownError; |
| |
| async function runTest() { |
| findMediaElement(); |
| |
| source = new MediaSource(); |
| video.src = URL.createObjectURL(source); |
| await waitFor(source, 'sourceopen'); |
| |
| sourceBuffer = source.addSourceBuffer(MP4.VIDEO_TYPE); |
| |
| var initData = MP4.initSegment({ |
| timescale: 1000, |
| tracks: [{ id: 1, type: 'video', timescale: 1000 }] |
| }); |
| sourceBuffer.appendBuffer(initData); |
| |
| // --- appendBuffer while updating --- |
| consoleWrite('Test: appendBuffer while updating must throw InvalidStateError'); |
| testExpected('sourceBuffer.updating', true); |
| thrownError = null; |
| try { sourceBuffer.appendBuffer(initData); } catch (e) { thrownError = e; } |
| testExpected('thrownError.name', 'InvalidStateError'); |
| |
| // --- remove while updating --- |
| consoleWrite('Test: remove while updating must throw InvalidStateError'); |
| thrownError = null; |
| try { sourceBuffer.remove(0, 1); } catch (e) { thrownError = e; } |
| testExpected('thrownError.name', 'InvalidStateError'); |
| |
| await waitFor(sourceBuffer, 'updateend'); |
| |
| // --- abort while not updating is allowed --- |
| consoleWrite('Test: abort while not updating does not throw'); |
| thrownError = null; |
| try { sourceBuffer.abort(); } catch (e) { thrownError = e; } |
| testExpected('thrownError', null); |
| |
| // --- set duration while updating --- |
| consoleWrite('Test: set duration while updating must throw InvalidStateError'); |
| sourceBuffer.appendBuffer(initData); |
| testExpected('sourceBuffer.updating', true); |
| thrownError = null; |
| try { source.duration = 10; } catch (e) { thrownError = e; } |
| testExpected('thrownError.name', 'InvalidStateError'); |
| await waitFor(sourceBuffer, 'updateend'); |
| |
| // --- endOfStream while updating --- |
| consoleWrite('Test: endOfStream while updating must throw InvalidStateError'); |
| sourceBuffer.appendBuffer(initData); |
| thrownError = null; |
| try { source.endOfStream(); } catch (e) { thrownError = e; } |
| testExpected('thrownError.name', 'InvalidStateError'); |
| await waitFor(sourceBuffer, 'updateend'); |
| |
| // --- addSourceBuffer when ended --- |
| consoleWrite('Test: addSourceBuffer when ended must throw InvalidStateError'); |
| source.endOfStream(); |
| testExpected('source.readyState', 'ended'); |
| thrownError = null; |
| try { source.addSourceBuffer(MP4.VIDEO_TYPE); } catch (e) { thrownError = e; } |
| testExpected('thrownError.name', 'InvalidStateError'); |
| } |
| |
| window.addEventListener('load', event => { |
| runTest().then(endTest).catch(failTest); |
| }); |
| </script> |
| </head> |
| <body> |
| <video></video> |
| </body> |
| </html> |