2013-06-20 20:16:14 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
2014-09-04 00:35:01 -07:00
|
|
|
<title>MSE: basic functionality</title>
|
2013-06-20 20:16:14 -07:00
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
2014-09-04 22:10:42 -07:00
|
|
|
<script type="text/javascript" src="mediasource.js"></script>
|
2013-06-20 20:16:14 -07:00
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2014-09-04 22:10:42 -07:00
|
|
|
addLoadEvent(function () {
|
|
|
|
ok(!window.MediaSource && !window.SourceBuffer && !window.SourceBufferList,
|
|
|
|
"MediaSource should be hidden behind a pref");
|
|
|
|
SimpleTest.doesThrow(() => new MediaSource, "MediaSource should be hidden behind a pref");
|
|
|
|
});
|
|
|
|
|
|
|
|
runWithMSE(function () {
|
|
|
|
SimpleTest.doesThrow(() => new SourceBuffer, "new SourceBuffer should fail");
|
|
|
|
SimpleTest.doesThrow(() => new SourceBufferList, "new SourceBufferList direct should fail");
|
|
|
|
|
|
|
|
var ms = new MediaSource();
|
|
|
|
ok(ms, "Create a MediaSource object");
|
|
|
|
ok(ms instanceof EventTarget, "MediaSource must be an EventTarget");
|
|
|
|
is(ms.readyState, "closed", "New MediaSource must be in closed state");
|
|
|
|
|
|
|
|
// Wrapper creation, tests for leaks.
|
|
|
|
SpecialPowers.wrap(ms);
|
|
|
|
|
|
|
|
// Set an expando to force wrapper creation, tests for leaks.
|
|
|
|
ms.foo = null;
|
|
|
|
|
|
|
|
var o = URL.createObjectURL(ms);
|
|
|
|
ok(o, "Create an objectURL from the MediaSource");
|
|
|
|
|
|
|
|
var v = document.createElement("video");
|
|
|
|
v.preload = "auto";
|
|
|
|
v.src = o;
|
|
|
|
document.body.appendChild(v);
|
|
|
|
|
|
|
|
ms.addEventListener("sourceopen", function () {
|
|
|
|
ok(true, "Receive a sourceopen event");
|
|
|
|
is(ms.readyState, "open", "MediaSource must be in open state after sourceopen");
|
|
|
|
var sb = ms.addSourceBuffer("video/webm");
|
|
|
|
ok(sb, "Create a SourceBuffer");
|
|
|
|
is(ms.sourceBuffers.length, 1, "MediaSource.sourceBuffers is expected length");
|
|
|
|
is(ms.sourceBuffers[0], sb, "SourceBuffer in list matches our SourceBuffer");
|
|
|
|
is(ms.activeSourceBuffers[0], sb, "SourceBuffer in active list matches our SourceBuffer");
|
|
|
|
|
|
|
|
fetchWithXHR("seek.webm", function (arrayBuffer) {
|
|
|
|
sb.appendBuffer(new Uint8Array(arrayBuffer));
|
2014-09-08 15:29:41 -07:00
|
|
|
is(sb.updating, true, "SourceBuffer.updating is expected value after appendBuffer");
|
|
|
|
});
|
|
|
|
|
|
|
|
sb.addEventListener("update", function () {
|
|
|
|
is(sb.updating, false, "SourceBuffer.updating is expected value in update event");
|
2014-09-04 22:10:42 -07:00
|
|
|
ms.endOfStream();
|
2014-09-08 15:29:41 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
sb.addEventListener("updateend", function () {
|
|
|
|
is(sb.updating, false, "SourceBuffer.updating is expected value in updateend event");
|
2014-09-04 22:10:42 -07:00
|
|
|
v.play();
|
2013-09-26 22:22:37 -07:00
|
|
|
});
|
2013-06-20 20:16:14 -07:00
|
|
|
});
|
|
|
|
|
2014-09-04 22:10:42 -07:00
|
|
|
ms.addEventListener("sourceended", function () {
|
|
|
|
ok(true, "Receive a sourceended event");
|
|
|
|
is(ms.readyState, "ended", "MediaSource must be in ended state after sourceended");
|
2013-06-20 20:16:14 -07:00
|
|
|
});
|
2014-09-04 22:10:42 -07:00
|
|
|
|
|
|
|
v.addEventListener("ended", function () {
|
|
|
|
is(v.duration, 4, "Video has correct duration");
|
|
|
|
is(v.currentTime, 4, "Video has played to end");
|
|
|
|
v.parentNode.removeChild(v);
|
|
|
|
SimpleTest.finish();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-06-20 20:16:14 -07:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|