xrSession_requestAnimationFrame_getViewerPose.https.html (3164B)
1 <!DOCTYPE html> 2 <body> 3 <script src=/resources/testharness.js></script> 4 <script src=/resources/testharnessreport.js></script> 5 <script src="resources/webxr_util.js"></script> 6 <script src="resources/webxr_test_constants.js"></script> 7 <script src="resources/webxr_test_asserts.js"></script> 8 9 <script> 10 11 let immersiveTestName = 12 "XRFrame getViewerPose updates on the next frame for immersive sessions"; 13 let nonImmersiveTestName = 14 "XRFrame getViewerPose updates on the next frame for non-immersive sessions"; 15 16 let fakeDeviceInitParams = { 17 supportsImmersive: true, 18 supportedModes: ["inline", "immersive-vr"], 19 views: VALID_VIEWS, 20 supportedFeatures: ALL_FEATURES 21 }; 22 23 // A valid pose matrix/transform for when we don't care about specific values 24 // Note that these two should be identical, just different representations 25 const expectedPoseMatrix = [0, 1, 0, 0, 26 0, 0, 1, 0, 27 1, 0, 0, 0, 28 1, 1, 1, 1]; 29 30 const poseTransform = { 31 position: [1, 1, 1], 32 orientation: [0.5, 0.5, 0.5, 0.5] 33 }; 34 35 let testFunction = function(session, fakeDeviceController, t) { 36 return session.requestReferenceSpace('local') 37 .then((referenceSpace) => new Promise((resolve, reject) => { 38 let counter = 0; 39 function onFrame(time, vrFrame) { 40 if (counter == 0) { 41 t.step( () => { 42 // Expecting to not get a pose since none has been supplied 43 assert_equals(vrFrame.getViewerPose(referenceSpace), null); 44 45 fakeDeviceController.setViewerOrigin(poseTransform); 46 47 // Check that pose does not update pose within the same frame. 48 assert_equals(vrFrame.getViewerPose(referenceSpace), null); 49 }); 50 51 // In order to avoid race conditions, after we've set the viewer 52 // pose, we queue up the next requestAnimationFrame. This should 53 // ensure that the next frame will be able to get the appropriate 54 // pose. 55 // Note that since the next frame will immediately resolve and end 56 // the test we only need to request a new frame once, here. 57 session.requestAnimationFrame(onFrame); 58 } else { 59 t.step( () => { 60 let pose = vrFrame.getViewerPose(referenceSpace); 61 assert_not_equals(pose, null); 62 63 let poseMatrix = pose.transform.matrix; 64 assert_not_equals(poseMatrix, null); 65 assert_matrix_approx_equals(poseMatrix, expectedPoseMatrix); 66 }); 67 68 // Finished. 69 resolve(); 70 } 71 counter++; 72 } 73 74 session.requestAnimationFrame(onFrame); 75 })); 76 }; 77 78 xr_session_promise_test(nonImmersiveTestName, testFunction, 79 fakeDeviceInitParams, 'inline', { 'requiredFeatures': ['local'] }); 80 xr_session_promise_test(immersiveTestName, testFunction, 81 fakeDeviceInitParams, 'immersive-vr'); 82 83 </script> 84 </body>