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: play() method via DOM 0 handlers</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 | |
michael@0 | 12 | <script> |
michael@0 | 13 | var manager = new MediaTestManager; |
michael@0 | 14 | |
michael@0 | 15 | var tokens = { |
michael@0 | 16 | 0: ["play"], |
michael@0 | 17 | "play": ["canplay"], |
michael@0 | 18 | "canplay": ["playing"], |
michael@0 | 19 | "playing": ["canplay", "canplaythrough"], |
michael@0 | 20 | "canplaythrough": ["canplay", "canplaythrough"] |
michael@0 | 21 | }; |
michael@0 | 22 | |
michael@0 | 23 | function gotPlayEvent(event) { |
michael@0 | 24 | var v = event.target; |
michael@0 | 25 | ok(tokens[v._state].indexOf(event.type) >= 0, |
michael@0 | 26 | "Check expected event got " + event.type + " at " + v._state + " for " + v.src); |
michael@0 | 27 | v._state = event.type; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function ended(event) { |
michael@0 | 31 | var v = event.target; |
michael@0 | 32 | v._finished = true; |
michael@0 | 33 | removeNodeAndSource(v); |
michael@0 | 34 | manager.finished(v.token); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | function startTest(test, token) { |
michael@0 | 38 | var v = document.createElement('video'); |
michael@0 | 39 | v.token = token; |
michael@0 | 40 | manager.started(token); |
michael@0 | 41 | v._state = 0; |
michael@0 | 42 | v._finished = false; |
michael@0 | 43 | |
michael@0 | 44 | ["play", "canplay", "playing", "canplaythrough"].forEach(function (e) { |
michael@0 | 45 | v["on" + e] = gotPlayEvent; |
michael@0 | 46 | }); |
michael@0 | 47 | |
michael@0 | 48 | v.onended = ended; |
michael@0 | 49 | |
michael@0 | 50 | v.src = test.name; |
michael@0 | 51 | document.body.appendChild(v); // Causes load. |
michael@0 | 52 | v.play(); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | manager.runTests(gSmallTests, startTest); |
michael@0 | 56 | |
michael@0 | 57 | </script> |
michael@0 | 58 | </pre> |
michael@0 | 59 | </body> |
michael@0 | 60 | </html> |