blob: a44188a51516399634b5c98a48aec5d7ebc13ae7 [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/device/vr/public/mojom/vr_service.mojom.js"></script>
<script src="../external/wpt/resources/chromium/webxr-test.js"></script>
<script src="../xr/resources/xr-internal-device-mocking.js"></script>
<script src="../xr/resources/xr-test-utils.js"></script>
<script src="../xr/resources/test-constants.js"></script>
<canvas id="webgl-canvas"></canvas>
<script>
let testName = "XRInputSources with a target ray mode of 'tracked-pointer' "
+ "properly communicate their poses";
let fakeDeviceInitParams = { supportsImmersive: true };
let requestSessionOptions = [{ immersive: true }];
let testFunction =
(session, t, fakeDeviceController) => new Promise((resolve) => {
// Session must have a baseLayer or frame requests will be ignored.
session.baseLayer = new XRWebGLLayer(session, gl);
// Need to have a valid pose or input events don't process.
fakeDeviceController.setXRPresentationFrameData(VALID_POSE_MATRIX, [{
eye:"left",
projectionMatrix: VALID_PROJECTION_MATRIX,
viewMatrix: VALID_VIEW_MATRIX
}, {
eye:"right",
projectionMatrix: VALID_PROJECTION_MATRIX,
viewMatrix: VALID_VIEW_MATRIX
}]);
let input_source = new MockXRInputSource();
input_source.targetRayMode = "tracked-pointer";
input_source.handedness = "right";
// Don't set a grip matrix yet
fakeDeviceController.addInputSource(input_source);
// Must have a frameOfReference to get input poses. eye-level doesn't apply
// any transforms to the given matrix.
session.requestFrameOfReference("eye-level").then( (frameOfRef) => {
function CheckInvalidGrip(time, xrFrame) {
let source = session.getInputSources()[0];
let input_pose = xrFrame.getInputPose(source, frameOfRef);
t.step( () => {
// The input pose should be null when no grip matrix is provided.
assert_equals(source.targetRayMode, "tracked-pointer");
assert_equals(input_pose, null);
});
input_source.grip = VALID_GRIP;
session.requestAnimationFrame(CheckValidGrip);
}
function CheckValidGrip(time, xrFrame) {
let source = session.getInputSources()[0];
let input_pose = xrFrame.getInputPose(source, frameOfRef);
t.step( () => {
// When a grip matrix is present but no pointer offset is specified,
// the grip and pointer matrices should be the same.
assert_matrices_approx_equal(input_pose.gripMatrix, VALID_GRIP,
FLOAT_EPSILON, "Grip matrix is not equal to input.");
assert_matrices_approx_equal(input_pose.targetRay.transformMatrix,
input_pose.gripMatrix, FLOAT_EPSILON,
"Grip matrix is not equal to target ray matrix.");
});
input_source.pointerOffset = VALID_POINTER_OFFSET;
session.requestAnimationFrame(CheckValidGripAndPointer);
}
function CheckValidGripAndPointer(time, xrFrame) {
let source = session.getInputSources()[0];
let input_pose = xrFrame.getInputPose(source, frameOfRef);
t.step( () => {
// When a grip matrix and pointer offset are specified,
// pointer matrix should be grip matrix multiplied with the pointer
// offset.
assert_matrices_approx_equal(input_pose.gripMatrix, VALID_GRIP,
FLOAT_EPSILON, "Grip matrix is not equal to input valid grip.");
assert_matrices_approx_equal(input_pose.targetRay.transformMatrix,
VALID_GRIP_WITH_POINTER_OFFSET, FLOAT_EPSILON,
"Grip matrix not multipled properly.");
});
resolve();
}
// Can only request input poses in an xr frame.
session.requestAnimationFrame(CheckInvalidGrip);
});
});
xr_session_promise_test(
testFunction, fakeDeviceInitParams, requestSessionOptions, testName);
</script>