test_vrDisplay_getFrameData.html (7237B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>VRDisplay GetFrameData</title> 5 <meta name="timeout" content="long"/> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="VRSimulationDriver.js"></script> 9 <script src="WebVRHelpers.js"></script> 10 <script src="requestPresent.js"></script> 11 <script src="runVRTest.js"></script> 12 </head> 13 <body id="body"> 14 <canvas id="webglCanvas"></canvas> 15 <script> 16 "use strict"; 17 var vrDisplay; 18 var vrRAF; 19 var canvas = document.getElementById('webglCanvas'); 20 function startTest() { 21 promise_test((test) => { 22 return attachVRDisplay(test).then(() => { 23 VRSimulationDriver.SetEyeResolution(1332, 1586); 24 VRSimulationDriver.SetEyeParameter("left", -0.029, 0, 0, 41.65, 35.57, 48.00, 43.97); 25 VRSimulationDriver.SetEyeParameter("right", 0.029, 0, 0, 41.65, 43.97, 48.00, 35.57); 26 var poseOrient = new Float32Array([-0.188, -0.007, 0.045, -0.980]); 27 var posePos = new Float32Array([-0.161, 0.076, -0.250]); 28 var poseAngVel = new Float32Array([0.008, -0.002, -0.006]); 29 var poseAngAcc = new Float32Array([3.404, -1.469, -5.901]); 30 var poseLinVel = new Float32Array([0.001, -0.003, -0.002]); 31 var poseLinAcc = new Float32Array([0.007, 0.068, -0.052]); 32 VRSimulationDriver.SetVRDisplayPose(posePos, poseLinVel, poseLinAcc, 33 poseOrient, poseAngVel, poseAngAcc); 34 VRSimulationDriver.UpdateVRDisplay(); 35 }).then(() => { 36 return promise_test((test) => { 37 return setupVRDisplay(test).then(() => { 38 return WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, 39 [{ source: canvas }]); 40 }).then(() => { 41 assert_true(vrDisplay.isPresenting, "vrDisplay.isPresenting must be true if requestPresent is fulfilled."); 42 assert_equals(vrDisplay.getLayers().length, 1, "vrDisplay.getLayers() should return one layer."); 43 44 verifyFrameData(); 45 }) 46 }, "WebVR requestPresent fulfilled"); 47 }) 48 }, "Finish setting up VR test data."); 49 50 function verifyFrameData() { 51 async_test(function (test) { 52 navigator.getVRDisplays().then((displays) => { 53 assert_equals(displays.length, 1, "displays.length must be one after attach."); 54 vrDisplay = displays[0]; 55 vrDisplay.requestAnimationFrame(callback); 56 57 function callback() { 58 var frameData1 = new VRFrameData(); 59 vrDisplay.getFrameData(frameData1); 60 61 // We insert a new frame to confirm we still can get 62 // the same data as the last getter. 63 insertNewFrameData(); 64 65 var frameData2 = new VRFrameData(); 66 vrDisplay.getFrameData(frameData2); 67 68 assert_equals(frameData1.timestamp, frameData2.timestamp, 69 "frameData.timestamp at a frame should be equal."); 70 71 assert_true(checkValueInFloat32Array(frameData1.leftProjectionMatrix, 72 frameData2.leftProjectionMatrix), 73 "frameData.leftProjectionMatrix at a frame should be equal."); 74 75 assert_true(checkValueInFloat32Array(frameData1.leftViewMatrix, 76 frameData2.leftViewMatrix), 77 "frameData.leftViewMatrix at a frame should be equal."); 78 79 assert_true(checkValueInFloat32Array(frameData1.rightProjectionMatrix, 80 frameData2.rightProjectionMatrix), 81 "frameData.rightProjectionMatrix at a frame should be equal."); 82 83 assert_true(checkValueInFloat32Array(frameData1.rightViewMatrix, 84 frameData2.rightViewMatrix), 85 "frameData.rightViewMatrix at a frame should be equal."); 86 87 var pose1 = frameData1.pose; 88 var pose2 = frameData2.pose; 89 assert_true(checkValueInFloat32Array(pose1.position, 90 pose2.position), 91 "pose.position at a frame should be equal."); 92 93 assert_true(checkValueInFloat32Array(pose1.linearVelocity, 94 pose2.linearVelocity), 95 "pose.linearVelocity at a frame should be equal."); 96 97 assert_true(checkValueInFloat32Array(pose1.linearAcceleration, 98 pose2.linearAcceleration), 99 "pose.linearAcceleration at a frame should be equal."); 100 101 assert_true(checkValueInFloat32Array(pose1.orientation, 102 pose2.orientation), 103 "pose.orientation at a frame should be equal."); 104 105 assert_true(checkValueInFloat32Array(pose1.angularVelocity, 106 pose2.angularVelocity), 107 "pose.angularVelocity at a frame should be equal."); 108 109 assert_true(checkValueInFloat32Array(pose1.angularAcceleration, 110 pose2.angularAcceleration), 111 "pose.angularAcceleration at a frame should be equal."); 112 test.done(); 113 } 114 }); 115 }, "WebVR returns the same frameData within a frame fulfilled"); 116 } 117 118 function insertNewFrameData() { 119 var poseOrient = new Float32Array([-0.208, -0.017, 0.055, -0.930]); 120 var posePos = new Float32Array([-0.261, 0.036, -0.150]); 121 var poseAngVel = new Float32Array([0.018, -0.001, -0.003]); 122 var poseAngAcc = new Float32Array([1.504, -1.339, -4.901]); 123 var poseLinVel = new Float32Array([0.002, -0.001, -0.003]); 124 var poseLinAcc = new Float32Array([0.017, 0.061, -0.022]); 125 VRSimulationDriver.SetVRDisplayPose(posePos, poseLinVel, poseLinAcc, 126 poseOrient, poseAngVel, poseAngAcc); 127 VRSimulationDriver.UpdateVRDisplay(); 128 } 129 130 function checkValueInFloat32Array(array1, array2) { 131 if (array1.length != array2.length) { 132 return false; 133 } 134 var index = 0; 135 while (index < array2.length) { 136 if (array1[index] != array2[index]) { 137 return false; 138 } 139 ++index; 140 } 141 return true; 142 } 143 } 144 145 runVRTest(startTest); 146 </script> 147 </body> 148 </html>