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>Media test: unseekable</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 | /* |
michael@0 | 14 | |
michael@0 | 15 | Test that unseekable media can't be seeked. We load a media that shouldn't |
michael@0 | 16 | be seekable, and play through once. While playing through we repeatedly try |
michael@0 | 17 | to seek and check that nothing happens when we do. We also verify that the |
michael@0 | 18 | seekable ranges are empty. |
michael@0 | 19 | |
michael@0 | 20 | */ |
michael@0 | 21 | |
michael@0 | 22 | var manager = new MediaTestManager; |
michael@0 | 23 | |
michael@0 | 24 | var onseeking = function(event) { |
michael@0 | 25 | var v = event.target; |
michael@0 | 26 | v.actuallySeeked = true; |
michael@0 | 27 | }; |
michael@0 | 28 | |
michael@0 | 29 | var onseeked = function(event) { |
michael@0 | 30 | var v = event.target; |
michael@0 | 31 | v.actuallySeeked = true; |
michael@0 | 32 | }; |
michael@0 | 33 | |
michael@0 | 34 | var ontimeupdate = function(event) { |
michael@0 | 35 | var v = event.target; |
michael@0 | 36 | |
michael@0 | 37 | // Check that when we seek nothing happens. |
michael@0 | 38 | var t = v.currentTime; |
michael@0 | 39 | v.currentTime = v.currentTime /= 2; |
michael@0 | 40 | ok(Math.abs(t - v.currentTime) < 0.01, "Current time shouldn't change when seeking in unseekable media: " + v.name); |
michael@0 | 41 | |
michael@0 | 42 | // Check that the seekable ranges are empty. |
michael@0 | 43 | is(v.seekable.length, 0, "Should have no seekable ranges in unseekable media: " + v.name); |
michael@0 | 44 | }; |
michael@0 | 45 | |
michael@0 | 46 | var onended = function(event) { |
michael@0 | 47 | var v = event.target; |
michael@0 | 48 | |
michael@0 | 49 | // Remove the event listeners so that they can't run if there are any pending |
michael@0 | 50 | // events. |
michael@0 | 51 | v.removeEventListener("seeking", onseeking, false); |
michael@0 | 52 | v.removeEventListener("seeked", onseeked, false); |
michael@0 | 53 | v.removeEventListener("timeupdate", ontimeupdate, false); |
michael@0 | 54 | v.removeEventListener("ended", onended, false); |
michael@0 | 55 | |
michael@0 | 56 | v.src = ""; |
michael@0 | 57 | if (v.parentNode) { |
michael@0 | 58 | v.parentNode.removeChild(v); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | // Verify that none of the seeks we did in timeupdate actually seeked. |
michael@0 | 62 | ok(!v.actuallySeeked, "Should not be able to seek in unseekable media: " + v.name); |
michael@0 | 63 | |
michael@0 | 64 | manager.finished(v.token); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | function startTest(test, token) { |
michael@0 | 68 | var v = document.createElement('video'); |
michael@0 | 69 | manager.started(token); |
michael@0 | 70 | v.name = test.name; |
michael@0 | 71 | v.src = test.name; |
michael@0 | 72 | v.token = token; |
michael@0 | 73 | v.autoplay = "true"; |
michael@0 | 74 | |
michael@0 | 75 | v.actuallySeeked = false; |
michael@0 | 76 | |
michael@0 | 77 | v.addEventListener("seeking", onseeking, false); |
michael@0 | 78 | v.addEventListener("seeked", onseeked, false); |
michael@0 | 79 | v.addEventListener("timeupdate", ontimeupdate, false); |
michael@0 | 80 | v.addEventListener("ended", onended, false); |
michael@0 | 81 | |
michael@0 | 82 | document.body.appendChild(v); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | function canPlay(candidates) { |
michael@0 | 86 | var v = document.createElement("video"); |
michael@0 | 87 | var resources = candidates.filter(function(x){return v.canPlayType(x.type);}); |
michael@0 | 88 | return (resources.length > 0); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | if (canPlay(gUnseekableTests)) { |
michael@0 | 92 | manager.runTests(gUnseekableTests, startTest); |
michael@0 | 93 | } else { |
michael@0 | 94 | todo(false, "No files of supported format to test"); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | |
michael@0 | 98 | </script> |
michael@0 | 99 | </pre> |
michael@0 | 100 | </body> |
michael@0 | 101 | </html> |