test_playback_reactivate.html (2195B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test playback with dormant 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 /* This testcase wants to test a video element's playback is not break 14 by dormant. 15 When the metadata is loaded, we remove the video element to trigger dormant. 16 Then set a timer to append the video element back and play it. 17 Test pass if the video plays to the end. 18 */ 19 20 var manager = new MediaTestManager; 21 22 function startTest(test, token) { 23 const video = document.createElement('video'); 24 video.preload = "metadata"; 25 video.token = token; 26 27 var handler = { 28 "ontimeout": function() { 29 Log(token, "timed out: ended=" + video.seenEnded + ", suspend=" + video.seenSuspend); 30 } 31 }; 32 manager.started(token, handler); 33 34 video.src = test.name; 35 video.name = test.name; 36 37 var check = function() { 38 is(test.name, video.name, test.name + ": Name should match #1"); 39 Log(video.token, "removeChild: " + video.name); 40 document.body.removeChild(video); 41 var appendAndPlayElement = function() { 42 Log(video.token, "appendChild: " + video.name); 43 document.body.appendChild(video); 44 Log(video.token, "Element play: " + video.name); 45 video.play(); 46 } 47 setTimeout(appendAndPlayElement, 2000); 48 }; 49 50 var finish = function() { 51 video.finished = true; 52 removeNodeAndSource(video); 53 manager.finished(video.token); 54 }; 55 56 var checkEnded = function() { 57 is(test.name, video.name, test.name + ": Name should match #2"); 58 checkMetadata(test.name, video, test); 59 is(video.readyState, video.HAVE_CURRENT_DATA, test.name + " checking readyState"); 60 ok(video.ended, test.name + " checking playback has ended"); 61 62 finish(); 63 }; 64 65 66 video.addEventListener("loadedmetadata", check); 67 video.addEventListener("ended", checkEnded); 68 69 document.body.appendChild(video); 70 } 71 72 manager.runTests(gSmallTests, startTest); 73 74 </script> 75 </pre> 76 </body> 77 </html>