gecko/dom/media/mediasource/test/test_WaitingOnMissingData.html
2014-11-11 20:50:22 -08:00

73 lines
2.9 KiB
HTML

<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<title>MSE: |waiting| event when source data is missing</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="mediasource.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test"><script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
var receivedSourceOpen = false;
runWithMSE(function(ms, v) {
ms.addEventListener("sourceopen", function() {
ok(true, "Receive a sourceopen event");
ok(!receivedSourceOpen, "Should only receive one sourceopen for this test");
receivedSourceOpen = true;
var sb = ms.addSourceBuffer("video/webm");
ok(sb, "Create a SourceBuffer");
function once(target, name, cb) {
target.addEventListener(name, function() {
target.removeEventListener(name, cb);
cb();
});
}
function loadSegment(typedArray) {
info(`Loading buffer: [${typedArray.byteOffset}, ${typedArray.byteOffset + typedArray.byteLength})`);
return new Promise(function(resolve, reject) {
once(sb, 'update', resolve);
sb.appendBuffer(typedArray);
});
}
fetchWithXHR("seek.webm", function(arrayBuffer) {
sb.addEventListener('error', (e) => { ok(false, "Got Error: " + e); SimpleTest.finish(); });
loadSegment.bind(null, new Uint8Array(arrayBuffer, 0, 318))().then(
loadSegment.bind(null, new Uint8Array(arrayBuffer, 318, 25223-318))).then(
loadSegment.bind(null, new Uint8Array(arrayBuffer, 25223, 46712-25223))).then(
/* Note - Missing |46712, 67833 - 46712| segment here */
loadSegment.bind(null, new Uint8Array(arrayBuffer, 67833, 88966 - 67833))).then(
loadSegment.bind(null, new Uint8Array(arrayBuffer, 88966))).then(function() {
v.addEventListener("waiting", function onwaiting() {
ok(true, "Got a waiting event at " + v.currentTime);
if (v.currentTime > 0.7 && v.currentTime < 1.2) {
v.removeEventListener("waiting", onwaiting);
todo(v.currentTime >= 0.8, "See bug 1091774");
gotWaiting = true;
ok(true, "Received waiting event at time " + v.currentTime);
loadSegment(new Uint8Array(arrayBuffer, 46712, 67833 - 46712)).then(() => ms.endOfStream());
}
});
info("Playing video. It should play for a bit, then fire 'waiting'");
v.play();
});
});
});
v.addEventListener("ended", function () {
ok(Math.abs(v.duration - 4) < 0.1, "Video has correct duration. This fuzz factor is due to bug 1065207");
is(v.currentTime, v.duration, "Video has correct current time: " + v.currentTime);
ok(gotWaiting, "Received waiting event and playback continued after data added");
SimpleTest.finish();
});
});
</script>
</pre>
</body>
</html>