blob: 90b6dfb0cd1aa6dbdcc25305c3058a1659619815 [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="../external/wpt/webxr/resources/webxr_test_constants.js"></script>
<script src="../xr/resources/xr-internal-device-mocking.js"></script>
<script src="../xr/resources/xr-test-utils.js"></script>
<canvas id="webgl-canvas"></canvas>
<script>
let testName = "XRInputSources can be properly added and removed from the "
+ "session";
let fakeDeviceInitParams = { supportsImmersive:true };
let requestSessionOptions = [{ mode: 'immersive-vr' }];
let testFunction = (session, t, fakeDeviceController) => new Promise((resolve) => {
// Session must have a baseLayer or frame requests will be ignored.
session.updateRenderState({ 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_sources = session.getInputSources();
t.step( () => {
assert_equals(input_sources.length, 0);
});
let input_source_1 = new MockXRInputSource();
input_source_1.targetRayMode = "tracked-pointer";
input_source_1.handedness = "right";
fakeDeviceController.addInputSource(input_source_1);
session.requestAnimationFrame((time, xrFrame) => {
let input_sources = session.getInputSources();
t.step( () => {
assert_equals(input_sources.length, 1);
assert_equals(input_sources[0].targetRayMode, "tracked-pointer");
assert_equals(input_sources[0].handedness, "right");
});
let input_source_2 = new MockXRInputSource();
input_source_2.targetRayMode = "gaze";
input_source_2.emulatedPosition = "true";
fakeDeviceController.addInputSource(input_source_2);
session.requestAnimationFrame((time, xrFrame) => {
let input_sources = session.getInputSources();
t.step( () => {
assert_equals(input_sources.length, 2);
assert_equals(input_sources[1].targetRayMode, "gaze");
assert_equals(input_sources[1].handedness, "none");
});
fakeDeviceController.removeInputSource(input_source_1);
session.requestAnimationFrame((time, xrFrame) => {
let input_sources = session.getInputSources();
t.step( () => {
assert_equals(input_sources.length, 1);
assert_equals(input_sources[0].targetRayMode, "gaze");
assert_equals(input_sources[0].handedness, "none");
});
resolve();
});
});
});
});
xr_session_promise_test(
testFunction, fakeDeviceInitParams, requestSessionOptions, testName);
</script>