blob: d1a8ca5565d59622ff58fa7cbedfe353adbc3df8 [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 primary input presses properly fires off the "
+ "right events";
let watcherDone = new Event("watcherdone");
let fakeDeviceInitParams = { supportsImmersive:true };
let requestSessionModes = ['immersive-vr'];
let testFunction = function(session, t, fakeDeviceController) {
let eventWatcher = new EventWatcher(
t, session, ["selectstart", "select", "selectend", "watcherdone"]);
let eventPromise = eventWatcher.wait_for(
["selectstart", "select", "selectend", "watcherdone"]);
// Need to have a valid pose or input event's 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
}]);
function tryCallingFrameMethods(frame) {
t.step(() => {
// Frame is active but not an animation frame, so calling getPose is
// allowed while getViewerPose is not.
assert_throws('InvalidStateError', () => frame.getViewerPose(currentReferenceSpace));
let pose = frame.getPose(session.viewerSpace, currentReferenceSpace);
assert_not_equals(pose, null);
assert_true(pose instanceof XRPose);
assert_false(pose instanceof XRViewerPose);
});
}
function onSessionSelectStart(event) {
t.step( () => {
let input_sources = session.getInputSources();
assert_equals(event.frame.session, session);
assert_equals(event.inputSource, input_sources[0]);
tryCallingFrameMethods(event.frame);
});
}
function onSessionSelectEnd(event) {
t.step( () => {
let input_sources = session.getInputSources();
assert_equals(event.frame.session, session);
assert_equals(event.inputSource, input_sources[0]);
tryCallingFrameMethods(event.frame);
});
session.dispatchEvent(watcherDone);
}
function onSessionSelect(event) {
t.step( () => {
let input_sources = session.getInputSources();
assert_equals(event.frame.session, session);
assert_equals(event.inputSource, input_sources[0]);
tryCallingFrameMethods(event.frame);
});
}
session.addEventListener("selectstart", onSessionSelectStart, false);
session.addEventListener("selectend", onSessionSelectEnd, false);
session.addEventListener("select", onSessionSelect, false);
// Session must have a baseLayer or frame requests will be ignored.
session.updateRenderState({ baseLayer: new XRWebGLLayer(session, gl) });
let input_source = new MockXRInputSource();
fakeDeviceController.addInputSource(input_source);
let currentReferenceSpace = null;
session.requestReferenceSpace({ type: 'stationary', subtype: 'eye-level' }).then((referenceSpace) => {
currentReferenceSpace = referenceSpace;
// Press the primary input button and then release it a short time later.
session.requestAnimationFrame((time, xrFrame) => {
input_source.primaryInputPressed = true;
session.requestAnimationFrame((time, xrFrame) => {
input_source.primaryInputPressed = false;
session.requestAnimationFrame((time, xrFrame) => {
// Need to process one more frame to allow select to propegate.
});
});
});
});
return eventPromise;
};
xr_session_promise_test(
testFunction, fakeDeviceInitParams, requestSessionModes, testName);
</script>