summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_metadata.html
blob: 29b2f30ff058891cd806ce46f5d294c27ba2f265 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test returning metadata from media files with mozGetMetadata()</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  <script type="text/javascript" src="manifest.js"></script>
</head>
<body>
<pre id="test">
<div id="output"></div>
<script class="testbody" type="text/javascript">

var manager = new MediaTestManager;

function startTest(test, token) {
  var a = document.createElement('audio');
  a.preload = "metadata";
  a.token = token;
  manager.started(token);

  a.src = test.name;
  a.name = test.name;

  // Tags should not be available immediately.
  var exception_fired = false;
  try {
    var m = a.mozGetMetadata();
  } catch (e) {
    is(e.name, 'InvalidStateError',
       "early mozGetMetadata() should throw InvalidStateError");
    exception_fired = true;
  }
  ok(exception_fired,
     "mozGetMetadata() should throw an exception before HAVE_METADATA");

  // Wait until metadata has loaded.
  a.addEventListener('loadedmetadata', function() {
    // read decoded tags
    tags = a.mozGetMetadata();
    ok(tags, "mozGetMetadata() should return a truthy value");
    // Dump them out.
    var d = document.getElementById('output');
    var html = '<table>\n';
    html += '<caption><p>Called getMozMetadata()'
    html += ' on '+test.name+'</p></caption>\n';
    html += '<tr><th>tag</th>';
    html += '<th>decoded value</th><th>expected value</th></tr>\n';
    for (tag in tags) {
      html += '<tr><td>'+tag+'</td>';
      html += '<td>'+tags[tag]+'</td>';
      html += '<td>'+test.tags[tag]+'</td>';
      html += '</tr>\n';
    }
    if (!Object.keys(tags).length) {
      html += '<tr><td colspan=3 align=center><em>no tags</em></td></tr>\n';
    }
    html += '</table>\n';
    var div = document.createElement('div');
    div.innerHTML = html;
    d.appendChild(div);
    // Verify decoded tag values.
    for (tag in tags) {
      is(tags[tag], test.tags[tag], "Tag '"+tag+"' should match");
    }
    // Verify expected tag values
    for (tag in test.tags) {
      is(tags[tag], test.tags[tag], "Tag '"+tag+"' should match");
    }
    removeNodeAndSource(a);
    manager.finished(token);
  }, false);
}

manager.runTests(gMetadataTests, startTest);

</script>
</pre>
</body>
</html>