content/media/test/test_source.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Media test: append source child</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="v1"></video>
    11 <audio id="a1"></audio>
    12 <pre id="test">
    13 <script class="testbody" type="text/javascript">
    14 var v1 = document.getElementById("v1");
    15 var a1 = document.getElementById("a1");
    16 v1.preload = "auto";
    17 a1.preload = "auto";
    19 is(v1.src, "", "src should be null");
    20 is(a1.src, "", "src should be null");
    21 is(v1.currentSrc, "", "currentSrc should be null");
    22 is(a1.currentSrc, "", "currentSrc should be null");
    23 is(v1.childNodes.length, 0, "should have no children");
    24 is(a1.childNodes.length, 0, "should have no children");
    26 function newSource(filter) {
    27   var test = null;
    28   var candidates = gSmallTests.filter(function(x){return filter.test(x.type);});
    29   if (candidates.length > 0) {
    30     var e = document.createElement("source");
    31     e.type = candidates[0].type;
    32     e.src = candidates[0].name;
    33     return e;
    34   } else {
    35     return null
    36   }
    37 }
    39 var audioLoaded = false;
    40 var videoLoaded = false;
    42 function loaded(e) {
    43   var media = e.target;
    44   ok(media.networkState > 0, "networkState should be > 0");
    45   is(media.childNodes.length, 1, "should have 1 child");
    46   var sourceFile = media.currentSrc.substring(media.currentSrc.lastIndexOf('/')+1);
    47   var resource = media.firstChild.src.substring(media.firstChild.src.lastIndexOf('/')+1);
    48   is(sourceFile, resource, "loaded wrong resource!");
    49   if (media == a1)
    50     audioLoaded = true;
    51   else if (media == v1)
    52     videoLoaded = true;
    53   if (audioLoaded && videoLoaded) {
    54     SimpleTest.finish();
    55   }
    56 }
    58 v1.addEventListener('loadeddata', loaded, false);
    59 a1.addEventListener('loadeddata', loaded, false);
    61 var videoSource = newSource(/^video/);
    62 if (videoSource) {
    63   v1.appendChild(videoSource);
    64   v1.load();
    65 } else {
    66   // No video backends? Don't test anything.
    67   videoLoaded = true;
    68 }
    70 var audioSource = newSource(/^audio/);
    71 if (audioSource) {
    72   a1.appendChild(audioSource);
    73   a1.load();
    74 } else {
    75   audioLoaded = true;
    76 }
    78 if (!audioLoaded && !videoLoaded) {
    79   SimpleTest.waitForExplicitFinish();
    80 } else {
    81   if (audioLoaded) {
    82     todo(false, "No audio types supported");
    83   }
    84   if (videoLoaded) {
    85     todo(false, "No video types supported");
    86   }
    87 }
    89 </script>
    90 </pre>
    91 </body>
    92 </html>

mercurial