test_seek_duration.html (1710B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Media test: seek tests</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 <script type="text/javascript" src="seek_support.js"></script> 9 </head> 10 <body> 11 <pre id="test"> 12 <script class="testbody" type="text/javascript"> 13 14 /** 15 * This test is used to make sure video's duration won't be changed when it 16 * reachs to the end after seeking to position where the time is very close to 17 * video's end time. 18 */ 19 20 SimpleTest.waitForExplicitFinish(); 21 22 async function test(name, videoProperties) 23 { 24 const video = document.createElement('video'); 25 video.src = "bunny.webm"; 26 Object.assign(video, videoProperties); 27 document.body.appendChild(video); 28 29 const loadedMetadata = once(video, "loadedmetadata"); 30 const canplay = once(video, "canplay"); 31 const end = once(video, "ended"); 32 33 info(`- wait for ${name} video loading metadata -`); 34 await loadedMetadata; 35 const originalDuration = video.duration; 36 37 info(`- seek ${name} video to the position which is close to end time -`); 38 // video's duration is 2.1 and the last key frame is in 2.0, we want to seek 39 // to that keyframe. 40 video.currentTime = originalDuration - 0.1; 41 42 info(`- play ${name} video until it ends -`); 43 await canplay; 44 await video.play(); 45 await end; 46 47 is(video.duration, originalDuration, `${name} duration shouldn't change`); 48 removeNodeAndSource(video); 49 } 50 51 (async function startTest() { 52 await Promise.all([ 53 test("unmuted", {}), 54 test("muted", {muted: true}), 55 ]); 56 SimpleTest.finish(); 57 })(); 58 59 </script> 60 </pre> 61 </body> 62 </html>