content/media/test/test_unseekable.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Media test: unseekable</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 <pre id="test">
    11 <script class="testbody" type="text/javascript">
    13 /*
    15 Test that unseekable media can't be seeked. We load a media that shouldn't
    16 be seekable, and play through once. While playing through we repeatedly try
    17 to seek and check that nothing happens when we do. We also verify that the
    18 seekable ranges are empty.
    20 */
    22 var manager = new MediaTestManager;
    24 var onseeking = function(event) {
    25   var v = event.target;
    26   v.actuallySeeked = true;
    27 };
    29 var onseeked = function(event) {
    30   var v = event.target;
    31   v.actuallySeeked = true;
    32 };
    34 var ontimeupdate = function(event) {
    35   var v = event.target;
    37   // Check that when we seek nothing happens.
    38   var t = v.currentTime;
    39   v.currentTime = v.currentTime /= 2;
    40   ok(Math.abs(t - v.currentTime) < 0.01, "Current time shouldn't change when seeking in unseekable media: " + v.name);
    42   // Check that the seekable ranges are empty.
    43   is(v.seekable.length, 0, "Should have no seekable ranges in unseekable media: " + v.name);
    44 };
    46 var onended = function(event) {
    47   var v = event.target;
    49   // Remove the event listeners so that they can't run if there are any pending
    50   // events.
    51   v.removeEventListener("seeking", onseeking, false);
    52   v.removeEventListener("seeked", onseeked, false);
    53   v.removeEventListener("timeupdate", ontimeupdate, false);
    54   v.removeEventListener("ended", onended, false);
    56   v.src = "";
    57   if (v.parentNode) {
    58     v.parentNode.removeChild(v);
    59   }
    61   // Verify that none of the seeks we did in timeupdate actually seeked.
    62   ok(!v.actuallySeeked, "Should not be able to seek in unseekable media: " + v.name);
    64   manager.finished(v.token);
    65 }
    67 function startTest(test, token) {
    68   var v = document.createElement('video');
    69   manager.started(token);
    70   v.name = test.name;
    71   v.src = test.name;
    72   v.token = token;
    73   v.autoplay = "true";
    75   v.actuallySeeked = false;
    77   v.addEventListener("seeking", onseeking, false);
    78   v.addEventListener("seeked", onseeked, false);
    79   v.addEventListener("timeupdate", ontimeupdate, false);
    80   v.addEventListener("ended", onended, false);
    82   document.body.appendChild(v);
    83 }
    85 function canPlay(candidates) {
    86   var v = document.createElement("video");  
    87   var resources = candidates.filter(function(x){return v.canPlayType(x.type);});
    88   return (resources.length > 0);
    89 }
    91 if (canPlay(gUnseekableTests)) {
    92   manager.runTests(gUnseekableTests, startTest);
    93 } else {
    94   todo(false, "No files of supported format to test");
    95 }
    98 </script>
    99 </pre>
   100 </body>
   101 </html>

mercurial