blob: 6933037c9bda11c186dd5eb2a2f4f5de97549132 [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 = "Ensures that an XRInputSources primary input being pressed and "
+ "released in the space of a single frame properly fires off the right "
+ "events";
let watcherDone = new Event("watcherdone");
let fakeDeviceInitParams = { supportsImmersive:true };
let requestSessionOptions = ['immersive-vr'];
let testFunction = function(session, t, fakeDeviceController) {
let eventWatcher = new EventWatcher(
t, session, ["selectstart", "selectend", "select", "watcherdone"]);
let eventPromise = eventWatcher.wait_for(
["selectstart", "selectend", "select", "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 onSessionSelectStart(event) {
t.step( () => {
let input_sources = session.getInputSources();
assert_equals(event.frame.session, session);
assert_equals(event.inputSource, input_sources[0]);
});
}
function onSessionSelectEnd(event) {
t.step( () => {
let input_sources = session.getInputSources();
assert_equals(event.frame.session, session);
assert_equals(event.inputSource, input_sources[0]);
});
}
function onSessionSelect(event) {
t.step( () => {
let input_sources = session.getInputSources();
assert_equals(event.frame.session, session);
assert_equals(event.inputSource, input_sources[0]);
});
session.dispatchEvent(watcherDone);
}
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);
// Press the primary input button and then release it a short time later.
session.requestAnimationFrame((time, xrFrame) => {
input_source.primaryInputPressed = true;
input_source.primaryInputPressed = false;
session.requestAnimationFrame((time, xrFrame) => {
// Need to process one more frame to allow select to propegate.
});
});
};
xr_session_promise_test(
testFunction, fakeDeviceInitParams, requestSessionOptions, testName);
</script>