Bug 1839170 - Refactor Snap pulling, Add Firefox Snap Core22 and GNOME 42 SDK symbols...
[gecko.git] / dom / media / test / test_play_twice.html
blobe94f28a03135a42602e84405c938b9d7855291ba
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Test playback of media files that should play OK</title>
5 <script 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 video = document.createElement('video');
17 video.token = token;
18 manager.started(token);
19 video.src = test.name;
20 video.name = test.name;
21 video.playingCount = 0;
22 video._playedOnce = false;
24 var check = function(t, v) { return function() {
25 checkMetadata(t.name, v, test);
26 }}(test, video);
28 var noLoad = function(t, v) { return function() {
29 ok(false, t.name + " should not fire 'load' event");
30 }}(test, video);
32 function finish(v) {
33 removeNodeAndSource(v);
34 manager.finished(v.token);
37 function mayFinish(v) {
38 if (v.seenEnded && v.seenSuspend) {
39 finish(v);
43 var checkEnded = function(t, v) { return function() {
44 if (t.duration) {
45 ok(Math.abs(v.currentTime - t.duration) < 0.1,
46 t.name + " current time at end: " + v.currentTime);
49 is(v.readyState, v.HAVE_CURRENT_DATA, t.name + " checking readyState");
50 ok(v.ended, t.name + " checking playback has ended");
51 ok(v.playingCount > 0, "Expect at least one playing event");
52 v.playingCount = 0;
54 if (v._playedOnce) {
55 v.seenEnded = true;
56 mayFinish(v);
57 } else {
58 v._playedOnce = true;
59 v.play();
61 }}(test, video);
63 var checkSuspended = function(t, v) { return function() {
64 if (v.seenSuspend) {
65 return;
68 v.seenSuspend = true;
69 ok(true, t.name + " got suspend");
70 mayFinish(v);
71 }}(test, video);
73 var checkPlaying = function(t, v) { return function() {
74 is(t.name, v.name, "Should be testing file we think we're testing...");
75 v.playingCount++;
76 }}(test, video);
78 video.addEventListener("load", noLoad);
79 video.addEventListener("loadedmetadata", check);
80 video.addEventListener("playing", checkPlaying);
82 // We should get "ended" and "suspend" events for every resource
83 video.addEventListener("ended", checkEnded);
84 video.addEventListener("suspend", checkSuspended);
86 document.body.appendChild(video);
87 video.play();
90 manager.runTests(gReplayTests, startTest);
92 </script>
93 </pre>
94 </body>
95 </html>