xrSession_requestAnimationFrame_timestamp.https.html (3088B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="resources/webxr_util.js"></script> 5 <script src="resources/webxr_test_constants.js"></script> 6 7 <script> 8 const TEN_SECONDS = 10000; // 10k ms in ten seconds 9 const ONE_MINUTE = 60000; // 60k ms in one minute 10 11 let immersiveTestName = "XRFrame getViewerPose updates on the next frame for immersive"; 12 let nonImmersiveTestName = "XRFrame getViewerPose updates on the next frame for non-immersive"; 13 14 let fakeDeviceInitParams = TRACKED_IMMERSIVE_DEVICE; 15 16 let testFunction = function(session, fakeDeviceController, t) { 17 return session.requestReferenceSpace('viewer') 18 .then((referenceSpace) => new Promise((resolve, reject) => { 19 let counter = 0; 20 let windowFrameTime = 0; 21 let frameTime = 0; 22 let lastFrameTime = 0; 23 24 let firstFrame = true; 25 26 function onFrameFirst(time, xrFrame) { 27 lastFrameTime = frameTime; 28 frameTime = time; 29 let now = performance.now(); 30 31 t.step( () => { 32 if(firstFrame) { 33 // This callback must be the first one called. 34 assert_equals(counter, 0); 35 } else { 36 // If it's a second animation frame, the timestamp must be greater 37 // than the timestamp on a previous frame. 38 assert_greater_than(frameTime, lastFrameTime); 39 // ... but not grater than 10 seconds. 40 assert_approx_equals(frameTime, lastFrameTime, TEN_SECONDS); 41 } 42 43 // There's going to be some disparity between performance.now() and 44 // the timestamp passed into the callback, but it shouldn't be huge. 45 // If they're more than ten seconds apart something has gone horribly 46 // wrong. 47 assert_approx_equals(frameTime, now, TEN_SECONDS); 48 }); 49 50 if (firstFrame) { 51 // We also want this method to run for the second animation frame. 52 session.requestAnimationFrame(onFrameFirst); 53 } else { 54 resolve(); 55 } 56 57 firstFrame = false; 58 counter++; 59 } 60 61 function onFrameSubsequent(time, xrFrame) { 62 t.step( () => { 63 // The timestamp passed to this callback should be exactly equal to 64 // the one passed to the first callback in this set. 65 assert_equals(time, frameTime); 66 }); 67 68 counter++; 69 } 70 71 function onFrameLast(time, xrFrame) { 72 t.step( () => { 73 // Make sure all the previous callbacks fired as expected. 74 assert_equals(counter, 11); 75 }); 76 } 77 78 session.requestAnimationFrame(onFrameFirst); 79 // Queue up several callbacks 80 for (let i = 0; i < 10; ++i) { 81 session.requestAnimationFrame(onFrameSubsequent); 82 } 83 session.requestAnimationFrame(onFrameLast); 84 85 })); 86 }; 87 88 xr_session_promise_test( 89 immersiveTestName, testFunction, fakeDeviceInitParams, 'immersive-vr'); 90 xr_session_promise_test( 91 nonImmersiveTestName, testFunction, fakeDeviceInitParams, 'inline'); 92 93 </script>