1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/test/test_streams_element_capture_reset.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,99 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test that reloading and seeking in a media element that's being captured doesn't crash</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.10 + <script type="text/javascript" src="manifest.js"></script> 1.11 +</head> 1.12 +<body> 1.13 +<video id="v"></video> 1.14 +<video id="vout"></video> 1.15 +<video id="vout_untilended"></video> 1.16 +<pre id="test"> 1.17 +<script class="testbody" type="text/javascript"> 1.18 +SimpleTest.waitForExplicitFinish(); 1.19 + 1.20 +var v = document.getElementById('v'); 1.21 +var vout = document.getElementById('vout'); 1.22 +var vout_untilended = document.getElementById('vout_untilended'); 1.23 +vout.mozSrcObject = v.mozCaptureStream(); 1.24 +vout_untilended.mozSrcObject = v.mozCaptureStreamUntilEnded(); 1.25 + 1.26 +function dumpEvent(event) { 1.27 + dump("GOT EVENT " + event.type + " currentTime=" + event.target.currentTime + 1.28 + " paused=" + event.target.paused + " ended=" + event.target.ended + 1.29 + " readyState=" + event.target.readyState + "\n"); 1.30 +} 1.31 +var events = ["timeupdate", "seeking", "seeked", "ended", "playing", "pause"]; 1.32 +for (var i = 0; i < events.length; ++i) { 1.33 + v.addEventListener(events[i], dumpEvent, false); 1.34 +} 1.35 +function isWithinEps(a, b, msg) { 1.36 + ok(Math.abs(a - b) < 0.01, 1.37 + "Got " + a + ", expected " + b + "; " + msg); 1.38 +} 1.39 + 1.40 +function startTest(test) { 1.41 + var seekTime = test.duration/2; 1.42 + 1.43 + function endedAfterReplay() { 1.44 + isWithinEps(v.currentTime, test.duration, "checking v.currentTime at third 'ended' event"); 1.45 + isWithinEps(vout.currentTime, (test.duration - seekTime) + test.duration*2, 1.46 + "checking vout.currentTime after seeking, playing through and reloading"); 1.47 + SimpleTest.finish(); 1.48 + }; 1.49 + function endedAfterSeek() { 1.50 + isWithinEps(v.currentTime, test.duration, "checking v.currentTime at second 'ended' event"); 1.51 + isWithinEps(vout.currentTime, (test.duration - seekTime) + test.duration, 1.52 + "checking vout.currentTime after seeking and playing through again"); 1.53 + v.removeEventListener("ended", endedAfterSeek, false); 1.54 + v.addEventListener("ended", endedAfterReplay, false); 1.55 + v.src = test.name + "?1"; 1.56 + v.play(); 1.57 + }; 1.58 + function seeked() { 1.59 + isWithinEps(v.currentTime, seekTime, "Finished seeking"); 1.60 + isWithinEps(vout.currentTime, test.duration, 1.61 + "checking vout.currentTime has not changed after seeking"); 1.62 + v.removeEventListener("seeked", seeked, false); 1.63 + function dontPlayAgain() { 1.64 + ok(false, "vout_untilended should not play again"); 1.65 + } 1.66 + vout_untilended.addEventListener("playing", dontPlayAgain, false); 1.67 + vout_untilended.addEventListener("ended", dontPlayAgain, false); 1.68 + v.addEventListener("ended", endedAfterSeek, false); 1.69 + v.play(); 1.70 + }; 1.71 + function ended() { 1.72 + isWithinEps(vout.currentTime, test.duration, "checking vout.currentTime at first 'ended' event"); 1.73 + isWithinEps(v.currentTime, test.duration, "checking v.currentTime at first 'ended' event"); 1.74 + is(vout.ended, false, "checking vout has not ended"); 1.75 + is(vout_untilended.ended, true, "checking vout_untilended has actually ended"); 1.76 + vout_untilended.removeEventListener("ended", ended, false); 1.77 + v.pause(); 1.78 + v.currentTime = seekTime; 1.79 + v.addEventListener("seeked", seeked, false); 1.80 + }; 1.81 + vout_untilended.addEventListener("ended", ended, false); 1.82 + 1.83 + v.src = test.name; 1.84 + v.play(); 1.85 + function checkNoEnded() { 1.86 + ok(false, "ended event received unexpectedly"); 1.87 + }; 1.88 + vout.addEventListener("ended", checkNoEnded, false); 1.89 + vout.play(); 1.90 + vout_untilended.play(); 1.91 +} 1.92 + 1.93 +var testVideo = getPlayableVideo(gSmallTests); 1.94 +if (testVideo) { 1.95 + startTest(testVideo); 1.96 +} else { 1.97 + todo(false, "No playable video"); 1.98 +} 1.99 +</script> 1.100 +</pre> 1.101 +</body> 1.102 +</html>