test_playback.html (3018B)
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"> 12 13 var manager = new MediaTestManager; 14 15 function startTest(test, token) { 16 const video = document.createElement('video'); 17 video.preload = "metadata"; 18 video.token = token; 19 video.prevTime = 0; 20 video.seenEnded = false; 21 video.seenSuspend = false; 22 23 var handler = { 24 "ontimeout": function() { 25 Log(token, "timed out: ended=" + video.seenEnded + ", suspend=" + video.seenSuspend); 26 } 27 }; 28 manager.started(token, handler); 29 30 video.src = test.name; 31 video.name = test.name; 32 33 var check = function() { 34 is(test.name, video.name, test.name + ": Name should match #1"); 35 checkMetadata(test.name, video, test); 36 }; 37 38 var noLoad = function() { 39 ok(false, test.name + " should not fire 'load' event"); 40 }; 41 42 var noError = function() { 43 ok(false, test.name + " should not fire 'error' event " + video.error.message); 44 finish(); 45 }; 46 47 var finish = function() { 48 video.finished = true; 49 video.removeEventListener("timeupdate", timeUpdate); 50 removeNodeAndSource(video); 51 manager.finished(video.token); 52 }; 53 54 // We should get "ended" and "suspend" events to finish the test. 55 var mayFinish = function() { 56 if (video.seenEnded && video.seenSuspend) { 57 finish(); 58 } 59 }; 60 61 var checkEnded = function() { 62 is(test.name, video.name, test.name + ": Name should match #2"); 63 checkMetadata(test.name, video, test); 64 is(video.readyState, video.HAVE_CURRENT_DATA, test.name + " checking readyState"); 65 ok(video.ended, test.name + " checking playback has ended"); 66 ok(!video.finished, test.name + " shouldn't be finished"); 67 ok(!video.seenEnded, test.name + " shouldn't be ended"); 68 69 video.seenEnded = true; 70 mayFinish(); 71 }; 72 73 var checkSuspended = function() { 74 if (video.seenSuspend) { 75 return; 76 } 77 is(test.name, video.name, test.name + ": Name should match #3"); 78 79 video.seenSuspend = true; 80 mayFinish(); 81 }; 82 83 var timeUpdate = function() { 84 if (video.prevTime > video.currentTime) { 85 ok(false, test.name + " time should run forwards: p=" + 86 video.prevTime + " c=" + video.currentTime); 87 } 88 video.prevTime = video.currentTime; 89 }; 90 91 video.addEventListener("load", noLoad); 92 video.addEventListener("error", noError); 93 video.addEventListener("loadedmetadata", check); 94 video.addEventListener("timeupdate", timeUpdate); 95 96 // We should get "ended" and "suspend" events for every resource 97 video.addEventListener("ended", checkEnded); 98 video.addEventListener("suspend", checkSuspended); 99 100 document.body.appendChild(video); 101 video.play(); 102 } 103 104 manager.runTests(gPlayTests, startTest); 105 106 </script> 107 </pre> 108 </body> 109 </html>