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
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test playback of media files that should play OK</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 7 | <script type="text/javascript" src="manifest.js"></script> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | <pre id="test"> |
michael@0 | 11 | <script class="testbody" type="text/javascript"> |
michael@0 | 12 | |
michael@0 | 13 | var manager = new MediaTestManager; |
michael@0 | 14 | |
michael@0 | 15 | function startTest(test, token) { |
michael@0 | 16 | var v = document.createElement('video'); |
michael@0 | 17 | v.preload = "metadata"; |
michael@0 | 18 | v.token = token; |
michael@0 | 19 | manager.started(token); |
michael@0 | 20 | |
michael@0 | 21 | v.src = test.name; |
michael@0 | 22 | v.name = test.name; |
michael@0 | 23 | var check = function(test, v) { return function() { |
michael@0 | 24 | is(test.name, v.name, "Name should match test.name #1"); |
michael@0 | 25 | checkMetadata(test.name, v, test); |
michael@0 | 26 | }}(test, v); |
michael@0 | 27 | var noLoad = function(test, v) { return function() { |
michael@0 | 28 | ok(false, test.name + " should not fire 'load' event"); |
michael@0 | 29 | }}(test, v); |
michael@0 | 30 | var checkEnded = function(test, v) { return function() { |
michael@0 | 31 | if (test.duration) { |
michael@0 | 32 | ok(Math.abs(v.currentTime - test.duration) < 0.1, |
michael@0 | 33 | test.name + " current time at end: " + v.currentTime + " should be: " + test.duration); |
michael@0 | 34 | } |
michael@0 | 35 | is(test.name, v.name, "Name should match test.name #2"); |
michael@0 | 36 | is(v.readyState, v.HAVE_CURRENT_DATA, test.name + " checking readyState"); |
michael@0 | 37 | ok(v.readyState != v.NETWORK_LOADED, test.name + " shouldn't report NETWORK_LOADED"); |
michael@0 | 38 | ok(v.ended, test.name + " checking playback has ended"); |
michael@0 | 39 | if (v.ended && v.seenSuspend && !v.finished) { |
michael@0 | 40 | v.finished = true; |
michael@0 | 41 | v.removeEventListener("timeupdate", timeUpdate, false); |
michael@0 | 42 | removeNodeAndSource(v); |
michael@0 | 43 | manager.finished(v.token); |
michael@0 | 44 | } |
michael@0 | 45 | }}(test, v); |
michael@0 | 46 | var checkSuspended = function(test, v) { return function() { |
michael@0 | 47 | is(test.name, v.name, "Name should match test.name #3"); |
michael@0 | 48 | if (v.seenSuspend) |
michael@0 | 49 | return; |
michael@0 | 50 | |
michael@0 | 51 | v.seenSuspend = true; |
michael@0 | 52 | ok(true, test.name + " got suspend"); |
michael@0 | 53 | if (v.ended && !v.finished) { |
michael@0 | 54 | v.finished = true; |
michael@0 | 55 | v.removeEventListener("timeupdate", timeUpdate, false); |
michael@0 | 56 | removeNodeAndSource(v); |
michael@0 | 57 | manager.finished(v.token); |
michael@0 | 58 | } |
michael@0 | 59 | }}(test, v); |
michael@0 | 60 | v.prevTime = 0; |
michael@0 | 61 | var timeUpdate = function(test, v) { return function() { |
michael@0 | 62 | is(test.name, v.name, "Name should match test.name #4"); |
michael@0 | 63 | checkMetadata(test.name, v, test); |
michael@0 | 64 | ok(v.prevTime <= v.currentTime, |
michael@0 | 65 | test.name + " time should run forwards: p=" + |
michael@0 | 66 | v.prevTime + " c=" + v.currentTime); |
michael@0 | 67 | v.prevTime = v.currentTime; |
michael@0 | 68 | }}(test, v); |
michael@0 | 69 | v.addEventListener("load", noLoad, false); |
michael@0 | 70 | v.addEventListener("loadedmetadata", check, false); |
michael@0 | 71 | v.addEventListener("timeupdate", timeUpdate, false); |
michael@0 | 72 | |
michael@0 | 73 | // We should get "ended" and "suspend" events for every resource |
michael@0 | 74 | v.addEventListener("ended", checkEnded, false); |
michael@0 | 75 | v.addEventListener("suspend", checkSuspended, false); |
michael@0 | 76 | |
michael@0 | 77 | document.body.appendChild(v); |
michael@0 | 78 | v.play(); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | manager.runTests(gPlayTests, startTest); |
michael@0 | 82 | |
michael@0 | 83 | </script> |
michael@0 | 84 | </pre> |
michael@0 | 85 | </body> |
michael@0 | 86 | </html> |