servo/tests/wpt/web-platform-tests/webxr/xrSession_exclusive_requestAnimationFrame.https.html

91 lines
3.1 KiB
HTML

<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<canvas id="webgl-canvas"></canvas>
<script>
const identityMatrix = new Float32Array([
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
]);
const rightFakeXRViewInit =
{eye:"right", projectionMatrix: identityMatrix, viewMatrix: identityMatrix};
const leftFakeXRViewInit =
{eye:"left", projectionMatrix: identityMatrix, viewMatrix: identityMatrix};
const immersiveFakeXRDeviceInit = { supportsImmersive:true };
const webglCanvas = document.getElementById('webgl-canvas');
let gl = webglCanvas.getContext('webgl', { alpha: false, antialias: false });
let testDevice;
let testDeviceController;
let testSession;
xr_promise_test(
(t) => XRTest.simulateDeviceConnection(immersiveFakeXRDeviceInit)
.then((controller) => {
testDeviceController = controller;
return navigator.xr.requestDevice();
})
.then((device) => {
testDevice = device;
return gl.setCompatibleXRDevice(device);
})
.then(() => new Promise((resolve, reject) => {
// Perform the session request in a user gesture.
XRTest.simulateUserActivation(() => {
testDevice.requestSession({ immersive: true })
.then((session) => {
testSession = session;
return session.requestFrameOfReference('eye-level');
})
.then((frameOfRef) => {
// Session must have a baseLayer or frame requests will be ignored.
testSession.baseLayer = new XRWebGLLayer(testSession, gl);
function onFrame(time, xrFrame) {
assert_true(xrFrame instanceof XRFrame);
assert_not_equals(xrFrame.views, null);
assert_equals(xrFrame.views.length, 2);
let devicePose = xrFrame.getDevicePose(frameOfRef);
assert_not_equals(devicePose, null);
for(let i = 0; i < identityMatrix.length; i++) {
assert_equals(devicePose.poseModelMatrix[i], identityMatrix[i]);
}
assert_not_equals(devicePose.getViewMatrix(xrFrame.views[0]), null);
assert_equals(devicePose.getViewMatrix(xrFrame.views[0]).length, 16);
assert_not_equals(devicePose.getViewMatrix(xrFrame.views[1]), null);
assert_equals(devicePose.getViewMatrix(xrFrame.views[1]).length, 16);
// Test does not complete until the returned promise resolves.
resolve();
}
testDeviceController.setXRPresentationFrameData(
identityMatrix,
[rightFakeXRViewInit, leftFakeXRViewInit]
);
testSession.requestAnimationFrame(onFrame);
}).catch((err) => {
reject("Session was rejected with error: "+err);
});
});
})
),
"RequestAnimationFrame resolves with good data"
);
</script>
</body>