content/media/test/test_metadata.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <meta charset="utf-8">
     5   <title>Test returning metadata from media files with mozGetMetadata()</title>
     6   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     7   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     8   <script type="text/javascript" src="manifest.js"></script>
     9 </head>
    10 <body>
    11 <pre id="test">
    12 <div id="output"></div>
    13 <script class="testbody" type="text/javascript">
    15 var manager = new MediaTestManager;
    17 function startTest(test, token) {
    18   var a = document.createElement('audio');
    19   a.preload = "auto";
    20   a.token = token;
    21   manager.started(token);
    23   a.src = test.name;
    24   a.name = test.name;
    26   // Tags should not be available immediately.
    27   var exception_fired = false;
    28   try {
    29     var m = a.mozGetMetadata();
    30   } catch (e) {
    31     is(e.name, 'InvalidStateError',
    32        "early mozGetMetadata() should throw InvalidStateError");
    33     exception_fired = true;
    34   }
    35   ok(exception_fired,
    36      "mozGetMetadata() should throw an exception before HAVE_METADATA");
    38   // Wait until metadata has loaded.
    39   a.addEventListener('loadedmetadata', function() {
    40     // read decoded tags
    41     tags = a.mozGetMetadata();
    42     ok(tags, "mozGetMetadata() should return a truthy value");
    43     // Dump them out.
    44     var d = document.getElementById('output');
    45     var html = '<table>\n';
    46     html += '<caption><p>Called getMozMetadata()'
    47     html += ' on '+test.name+'</p></caption>\n';
    48     html += '<tr><th>tag</th>';
    49     html += '<th>decoded value</th><th>expected value</th></tr>\n';
    50     for (tag in tags) {
    51       html += '<tr><td>'+tag+'</td>';
    52       html += '<td>'+tags[tag]+'</td>';
    53       html += '<td>'+test.tags[tag]+'</td>';
    54       html += '</tr>\n';
    55     }
    56     if (!Object.keys(tags).length) {
    57       html += '<tr><td colspan=3 align=center><em>no tags</em></td></tr>\n';
    58     }
    59     html += '</table>\n';
    60     var div = document.createElement('div');
    61     div.innerHTML = html;
    62     d.appendChild(div);
    63     // Verify decoded tag values.
    64     for (tag in tags) {
    65       is(tags[tag], test.tags[tag], "Tag '"+tag+"' should match");
    66     }
    67     // Verify expected tag values
    68     for (tag in test.tags) {
    69       is(tags[tag], test.tags[tag], "Tag '"+tag+"' should match");
    70     }
    71     manager.finished(token);
    72   }, false);
    73 }
    75 manager.runTests(gMetadataTests, startTest);
    77 </script>
    78 </pre>
    79 </body>
    80 </html>

mercurial