request-video-frame-callback-repeating.html (3149B)
1 <!DOCTYPE html> 2 <html> 3 <title>Test repeatedly chaining video.rVFC() callbacks.</title> 4 <body></body> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/common/media.js"></script> 8 <script> 9 10 promise_test(async function(t) { 11 let done; 12 const promise = new Promise(resolve => done = resolve); 13 14 let video = document.createElement('video'); 15 video.muted = true; 16 document.body.appendChild(video); 17 18 let firstTime; 19 video.requestVideoFrameCallback(t.step_func((time) => { 20 firstTime = time; 21 22 // Queue up a callback and make sure it's not immediately executed. 23 let secondTime; 24 video.requestVideoFrameCallback(t.step_func((time) => { 25 secondTime = time; 26 assert_greater_than(secondTime, firstTime, "Callbacks should be executed on the next frame"); 27 })) 28 29 // Queue up a second callback, and make sure it's called at the same time 30 // as the one we just queued up. 31 video.requestVideoFrameCallback(t.step_func((time) => { 32 assert_equals(time, secondTime, "Callbacks queued together should be called at the same time"); 33 done(); 34 })) 35 36 })); 37 38 video.src = getVideoURI('/media/movie_5'); 39 await video.play(); 40 41 return promise; 42 }, 'Test new callbacks are only called on the next frame.'); 43 44 promise_test(async function(t) { 45 let done; 46 const promise = new Promise(resolve => done = resolve); 47 48 let video = document.createElement('video'); 49 video.muted = true; 50 document.body.appendChild(video); 51 52 let maxNumberOfCalls = 10; 53 let currentCallNumber = 0; 54 let lastMetadata; 55 56 function verifyMetadata(last, current) { 57 assert_greater_than(current.presentedFrames, last.presentedFrames, "presentedFrames should be monotonically increasing"); 58 assert_greater_than(current.presentationTime, last.presentationTime, "presentationTime should be monotonically increasing"); 59 assert_greater_than(current.expectedDisplayTime, last.expectedDisplayTime, "expectedDisplayTime should be monotonically increasing"); 60 61 // We aren't seeking through the file, so this should be increasing from frame to frame. 62 assert_greater_than(current.mediaTime, last.mediaTime, "mediaTime should be increasing"); 63 64 // The test video's size doesn't change. 65 assert_equals(current.width, last.width, "width should remain constant"); 66 assert_equals(current.height, last.height, "height should remain constant"); 67 } 68 69 function repeatingCallback(time, metadata) { 70 // Skip the first call to verifyMetadata. 71 if (currentCallNumber) 72 verifyMetadata(lastMetadata, metadata) 73 74 lastMetadata = metadata; 75 76 if (++currentCallNumber > maxNumberOfCalls) { 77 done() 78 } else { 79 video.requestVideoFrameCallback(t.step_func(repeatingCallback)); 80 } 81 } 82 83 video.requestVideoFrameCallback(t.step_func(repeatingCallback)); 84 85 video.src = getVideoURI('/media/movie_5'); 86 await video.play(); 87 88 return promise; 89 }, 'Test chaining calls to video.rVFC, and verify the required parameters.'); 90 </script> 91 </html>