Fri, 16 Jan 2015 04:50:19 +0100
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 <head>
4 <title>Test playback of media files that should play OK</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 <pre id="test">
11 <script class="testbody" type="text/javascript">
13 var manager = new MediaTestManager;
15 function startTest(test, token) {
16 var v = document.createElement('video');
17 v.preload = "metadata";
18 v.token = token;
19 manager.started(token);
20 v.src = test.name;
21 v.name = test.name;
22 v.playingCount = 0;
23 var check = function(test, v) { return function() {
24 checkMetadata(test.name, v, test);
25 }}(test, v);
26 var noLoad = function(test, v) { return function() {
27 ok(false, test.name + " should not fire 'load' event");
28 }}(test, v);
29 var checkEnded = function(test, v) { return function() {
30 if (test.duration) {
31 ok(Math.abs(v.currentTime - test.duration) < 0.1,
32 test.name + " current time at end: " + v.currentTime);
33 }
34 is(v.readyState, v.HAVE_CURRENT_DATA, test.name + " checking readyState");
35 ok(v.readyState != v.NETWORK_LOADED, test.name + " shouldn't report NETWORK_LOADED");
36 ok(v.ended, test.name + " checking playback has ended");
37 ok(v.playingCount > 0, "Expect at least one playing event");
38 v.playingCount = 0;
39 if (v._playedOnce && v.seenSuspend) {
40 v.parentNode.removeChild(v);
41 manager.finished(v.token);
42 } else {
43 v._playedOnce = true;
44 v.play();
45 }
46 }}(test, v);
47 var checkSuspended = function(test, v) { return function() {
48 if (v.seenSuspend)
49 return;
51 v.seenSuspend = true;
52 ok(true, test.name + " got suspend");
53 if (v._playedOnce && v.seenSuspend) {
54 v.parentNode.removeChild(v);
55 manager.finished(v.token);
56 }
57 }}(test, v);
58 var checkPlaying = function(test, v) { return function() {
59 is(test.name, v.name, "Should be testing file we think we're testing...");
60 v.playingCount++;
61 }}(test, v);
62 v.addEventListener("load", noLoad, false);
63 v.addEventListener("loadedmetadata", check, false);
64 v.addEventListener("playing", checkPlaying, false);
66 // We should get "ended" and "suspend" events for every resource
67 v.addEventListener("ended", checkEnded, false);
68 v.addEventListener("suspend", checkSuspended, false);
70 document.body.appendChild(v);
71 v.play();
72 }
74 manager.runTests(gReplayTests, startTest);
76 </script>
77 </pre>
78 </body>
79 </html>