Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test that reloading and seeking in a media element that's being captured doesn't crash</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 7 | <script type="text/javascript" src="manifest.js"></script> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | <video id="v"></video> |
michael@0 | 11 | <video id="vout"></video> |
michael@0 | 12 | <video id="vout_untilended"></video> |
michael@0 | 13 | <pre id="test"> |
michael@0 | 14 | <script class="testbody" type="text/javascript"> |
michael@0 | 15 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 16 | |
michael@0 | 17 | var v = document.getElementById('v'); |
michael@0 | 18 | var vout = document.getElementById('vout'); |
michael@0 | 19 | var vout_untilended = document.getElementById('vout_untilended'); |
michael@0 | 20 | vout.mozSrcObject = v.mozCaptureStream(); |
michael@0 | 21 | vout_untilended.mozSrcObject = v.mozCaptureStreamUntilEnded(); |
michael@0 | 22 | |
michael@0 | 23 | function dumpEvent(event) { |
michael@0 | 24 | dump("GOT EVENT " + event.type + " currentTime=" + event.target.currentTime + |
michael@0 | 25 | " paused=" + event.target.paused + " ended=" + event.target.ended + |
michael@0 | 26 | " readyState=" + event.target.readyState + "\n"); |
michael@0 | 27 | } |
michael@0 | 28 | var events = ["timeupdate", "seeking", "seeked", "ended", "playing", "pause"]; |
michael@0 | 29 | for (var i = 0; i < events.length; ++i) { |
michael@0 | 30 | v.addEventListener(events[i], dumpEvent, false); |
michael@0 | 31 | } |
michael@0 | 32 | function isWithinEps(a, b, msg) { |
michael@0 | 33 | ok(Math.abs(a - b) < 0.01, |
michael@0 | 34 | "Got " + a + ", expected " + b + "; " + msg); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | function startTest(test) { |
michael@0 | 38 | var seekTime = test.duration/2; |
michael@0 | 39 | |
michael@0 | 40 | function endedAfterReplay() { |
michael@0 | 41 | isWithinEps(v.currentTime, test.duration, "checking v.currentTime at third 'ended' event"); |
michael@0 | 42 | isWithinEps(vout.currentTime, (test.duration - seekTime) + test.duration*2, |
michael@0 | 43 | "checking vout.currentTime after seeking, playing through and reloading"); |
michael@0 | 44 | SimpleTest.finish(); |
michael@0 | 45 | }; |
michael@0 | 46 | function endedAfterSeek() { |
michael@0 | 47 | isWithinEps(v.currentTime, test.duration, "checking v.currentTime at second 'ended' event"); |
michael@0 | 48 | isWithinEps(vout.currentTime, (test.duration - seekTime) + test.duration, |
michael@0 | 49 | "checking vout.currentTime after seeking and playing through again"); |
michael@0 | 50 | v.removeEventListener("ended", endedAfterSeek, false); |
michael@0 | 51 | v.addEventListener("ended", endedAfterReplay, false); |
michael@0 | 52 | v.src = test.name + "?1"; |
michael@0 | 53 | v.play(); |
michael@0 | 54 | }; |
michael@0 | 55 | function seeked() { |
michael@0 | 56 | isWithinEps(v.currentTime, seekTime, "Finished seeking"); |
michael@0 | 57 | isWithinEps(vout.currentTime, test.duration, |
michael@0 | 58 | "checking vout.currentTime has not changed after seeking"); |
michael@0 | 59 | v.removeEventListener("seeked", seeked, false); |
michael@0 | 60 | function dontPlayAgain() { |
michael@0 | 61 | ok(false, "vout_untilended should not play again"); |
michael@0 | 62 | } |
michael@0 | 63 | vout_untilended.addEventListener("playing", dontPlayAgain, false); |
michael@0 | 64 | vout_untilended.addEventListener("ended", dontPlayAgain, false); |
michael@0 | 65 | v.addEventListener("ended", endedAfterSeek, false); |
michael@0 | 66 | v.play(); |
michael@0 | 67 | }; |
michael@0 | 68 | function ended() { |
michael@0 | 69 | isWithinEps(vout.currentTime, test.duration, "checking vout.currentTime at first 'ended' event"); |
michael@0 | 70 | isWithinEps(v.currentTime, test.duration, "checking v.currentTime at first 'ended' event"); |
michael@0 | 71 | is(vout.ended, false, "checking vout has not ended"); |
michael@0 | 72 | is(vout_untilended.ended, true, "checking vout_untilended has actually ended"); |
michael@0 | 73 | vout_untilended.removeEventListener("ended", ended, false); |
michael@0 | 74 | v.pause(); |
michael@0 | 75 | v.currentTime = seekTime; |
michael@0 | 76 | v.addEventListener("seeked", seeked, false); |
michael@0 | 77 | }; |
michael@0 | 78 | vout_untilended.addEventListener("ended", ended, false); |
michael@0 | 79 | |
michael@0 | 80 | v.src = test.name; |
michael@0 | 81 | v.play(); |
michael@0 | 82 | function checkNoEnded() { |
michael@0 | 83 | ok(false, "ended event received unexpectedly"); |
michael@0 | 84 | }; |
michael@0 | 85 | vout.addEventListener("ended", checkNoEnded, false); |
michael@0 | 86 | vout.play(); |
michael@0 | 87 | vout_untilended.play(); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | var testVideo = getPlayableVideo(gSmallTests); |
michael@0 | 91 | if (testVideo) { |
michael@0 | 92 | startTest(testVideo); |
michael@0 | 93 | } else { |
michael@0 | 94 | todo(false, "No playable video"); |
michael@0 | 95 | } |
michael@0 | 96 | </script> |
michael@0 | 97 | </pre> |
michael@0 | 98 | </body> |
michael@0 | 99 | </html> |