content/media/test/test_streams_element_capture_reset.html

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

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

mercurial