content/media/test/test_preload_suspend.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 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=479863
     5 -->
     6 <head>
     7   <title>Test for Bug 479863</title>
     8   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    10 </head>
    11 <body>
    12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=479863">Mozilla Bug 479863</a>
    13 <p id="display"></p>
    14 <div id="content" style="display: none">
    16 </div>
    18 <video id='v1'></video>
    19 <video id='v2' preload="auto"></video>
    20 <video id='v3' autoplay></video>
    21 <video id='v4'></video>
    22 <video id='v5'></video>
    23 <video id='v6'></video>
    25 <pre id="test">
    26 <script type="application/javascript">
    27 function is() {}
    29 var suspendCount = {};
    30 var expectedSuspendCount = {v1:2, v2:1, v3:1, v4:2, v5:2, v6:2};
    31 var totalSuspendCount = 0;
    32 for (var i = 0; i < expectedSuspendCount.length; ++i) {
    33   totalSuspendCount += expectedSuspendCount[i];
    34 }
    36 function suspended(event) {
    37   // If the element suspends the download, it should not then be able to
    38   // complete it, so we should be stuck in NETWORK_IDLE even though this
    39   // event handler could run a long time after the actual suspend.
    40   var expectedState = event.type == "load" ? event.target.NETWORK_LOADED
    41     : event.target.NETWORK_IDLE;
    43   is(event.target.networkState, expectedState,
    44      event.target.id + " suspended networkState");
    45   suspendCount[event.target.id]++;
    47   --totalSuspendCount;
    48   if (totalSuspendCount == 0) {
    49     // We're done.
    50     for (var i = 1; i <= 6; ++i) {
    51       var id = "v" + i;
    52       is(suspendCount[id], expectedSuspendCount[id], "Suspend count for " + id);
    53     }
    54     SimpleTest.finish();
    55   }
    57   if (suspendCount[event.target.id] > 1)
    58     return;
    60   if (event.target.id == "v1") {
    61     event.target.preload = "auto";
    62   } else if (event.target.id == "v4") {
    63     event.target.play();
    64   } else if (event.target.id == "v5") {
    65     event.target.currentTime = 0.1;
    66   } else if (event.target.id == "v6") {
    67     event.target.autoplay = true;
    68   }
    69 }
    71 var key = Math.random();
    73 SimpleTest.waitForExplicitFinish();
    74 SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]}, beginTest);
    75 function beginTest() {
    76   for (var i = 1; i <= 6; ++i) {
    77     var id = "v" + i;
    78     var v = document.getElementById(id);
    79     suspendCount[id] = 0;
    80     v.addEventListener("suspend", suspended, false);
    81     // Treat "load" as "suspend" for now, it means the same thing: we
    82     // stopped the download.
    83     v.addEventListener("load", suspended, false);
    84     v.src = "seek.ogv?key=" + key + "&id=" + id;
    85   }
    86 }
    87 </script>
    88 </pre>
    89 </body>
    90 </html>

mercurial