content/media/test/test_metadata.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/test/test_metadata.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,80 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <meta charset="utf-8">
     1.8 +  <title>Test returning metadata from media files with mozGetMetadata()</title>
     1.9 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +  <script type="text/javascript" src="manifest.js"></script>
    1.12 +</head>
    1.13 +<body>
    1.14 +<pre id="test">
    1.15 +<div id="output"></div>
    1.16 +<script class="testbody" type="text/javascript">
    1.17 +
    1.18 +var manager = new MediaTestManager;
    1.19 +
    1.20 +function startTest(test, token) {
    1.21 +  var a = document.createElement('audio');
    1.22 +  a.preload = "auto";
    1.23 +  a.token = token;
    1.24 +  manager.started(token);
    1.25 +
    1.26 +  a.src = test.name;
    1.27 +  a.name = test.name;
    1.28 +
    1.29 +  // Tags should not be available immediately.
    1.30 +  var exception_fired = false;
    1.31 +  try {
    1.32 +    var m = a.mozGetMetadata();
    1.33 +  } catch (e) {
    1.34 +    is(e.name, 'InvalidStateError',
    1.35 +       "early mozGetMetadata() should throw InvalidStateError");
    1.36 +    exception_fired = true;
    1.37 +  }
    1.38 +  ok(exception_fired,
    1.39 +     "mozGetMetadata() should throw an exception before HAVE_METADATA");
    1.40 +
    1.41 +  // Wait until metadata has loaded.
    1.42 +  a.addEventListener('loadedmetadata', function() {
    1.43 +    // read decoded tags
    1.44 +    tags = a.mozGetMetadata();
    1.45 +    ok(tags, "mozGetMetadata() should return a truthy value");
    1.46 +    // Dump them out.
    1.47 +    var d = document.getElementById('output');
    1.48 +    var html = '<table>\n';
    1.49 +    html += '<caption><p>Called getMozMetadata()'
    1.50 +    html += ' on '+test.name+'</p></caption>\n';
    1.51 +    html += '<tr><th>tag</th>';
    1.52 +    html += '<th>decoded value</th><th>expected value</th></tr>\n';
    1.53 +    for (tag in tags) {
    1.54 +      html += '<tr><td>'+tag+'</td>';
    1.55 +      html += '<td>'+tags[tag]+'</td>';
    1.56 +      html += '<td>'+test.tags[tag]+'</td>';
    1.57 +      html += '</tr>\n';
    1.58 +    }
    1.59 +    if (!Object.keys(tags).length) {
    1.60 +      html += '<tr><td colspan=3 align=center><em>no tags</em></td></tr>\n';
    1.61 +    }
    1.62 +    html += '</table>\n';
    1.63 +    var div = document.createElement('div');
    1.64 +    div.innerHTML = html;
    1.65 +    d.appendChild(div);
    1.66 +    // Verify decoded tag values.
    1.67 +    for (tag in tags) {
    1.68 +      is(tags[tag], test.tags[tag], "Tag '"+tag+"' should match");
    1.69 +    }
    1.70 +    // Verify expected tag values
    1.71 +    for (tag in test.tags) {
    1.72 +      is(tags[tag], test.tags[tag], "Tag '"+tag+"' should match");
    1.73 +    }
    1.74 +    manager.finished(token);
    1.75 +  }, false);
    1.76 +}
    1.77 +
    1.78 +manager.runTests(gMetadataTests, startTest);
    1.79 +
    1.80 +</script>
    1.81 +</pre>
    1.82 +</body>
    1.83 +</html>

mercurial