Bug 1615008 [wpt PR 21759] - Adding core support for WebXR squeezestart / squeeze / squeezeend events, a=testonly

Automatic update from web-platform-tests
Adding core support for WebXR squeezestart / squeeze / squeezeend events

New WebXR spec has a new set of input events. This commit adds core support for those. Still must be hooked up to the actual HW-specific code (I've added code for Oculus Rift (S) as an example).

Bug: 1051247,1019144
Change-Id: Iac0e66a39eff68c567af2234e583780af6dcaed2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2051369
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Mike West <mkwst@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Daniel Vogelheim <vogelheim@chromium.org>
Reviewed-by: Klaus Weidner <klausw@chromium.org>
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743715}

--

wpt-commits: 6c0160d3c0e99ffa3d3156b5f1b52d0c34b62b3f
wpt-pr: 21759
This commit is contained in:
Artem Bolgar 2020-02-24 18:50:20 +00:00 коммит произвёл moz-wptsync-bot
Родитель 53ec5e6dc0
Коммит 710736042f
2 изменённых файлов: 161 добавлений и 0 удалений

Просмотреть файл

@ -1012,6 +1012,9 @@ class MockXRInputSource {
this.primary_input_clicked_ = fakeInputSourceInit.selectionClicked;
}
this.primary_squeeze_pressed_ = false;
this.primary_squeeze_clicked_ = false;
this.mojo_from_input_ = null;
if (fakeInputSourceInit.gripOrigin != null) {
this.setGripOrigin(fakeInputSourceInit.gripOrigin);
@ -1163,6 +1166,20 @@ class MockXRInputSource {
throw new Error("Unknown Button Type!");
}
// is this a 'squeeze' button?
if (buttonIndex === this.getButtonIndex('grip')) {
// squeeze
if (buttonState.pressed) {
this.primary_squeeze_pressed_ = true;
} else if (this.gamepad_.buttons[buttonIndex].pressed) {
this.primary_squeeze_clicked_ = true;
this.primary_squeeze_pressed_ = false;
} else {
this.primary_squeeze_clicked_ = false;
this.primary_squeeze_pressed_ = false;
}
}
this.gamepad_.buttons[buttonIndex].pressed = buttonState.pressed;
this.gamepad_.buttons[buttonIndex].touched = buttonState.touched;
this.gamepad_.buttons[buttonIndex].value = buttonState.pressedValue;
@ -1181,10 +1198,17 @@ class MockXRInputSource {
input_state.primaryInputPressed = this.primary_input_pressed_;
input_state.primaryInputClicked = this.primary_input_clicked_;
input_state.primarySqueezePressed = this.primary_squeeze_pressed_;
input_state.primarySqueezeClicked = this.primary_squeeze_clicked_;
// Setting the input source's "clicked" state should generate one "select"
// event. Reset the input value to prevent it from continuously generating
// events.
this.primary_input_clicked_ = false;
// Setting the input source's "clicked" state should generate one "squeeze"
// event. Reset the input value to prevent it from continuously generating
// events.
this.primary_squeeze_clicked_ = false;
input_state.mojoFromInput = this.mojo_from_input_;

Просмотреть файл

@ -0,0 +1,137 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/webxr_util.js"></script>
<script src="resources/webxr_test_constants.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 = TRACKED_IMMERSIVE_DEVICE;
let xrViewerSpace = null;
let testFunction = function(session, fakeDeviceController, t) {
let eventWatcher = new EventWatcher(
t, session, ["squeezestart", "squeeze", "squeezeend", "watcherdone"]);
let eventPromise = eventWatcher.wait_for(
["squeezestart", "squeeze", "squeezeend", "watcherdone"]);
function tryCallingFrameMethods(frame) {
t.step(() => {
// Frame is active but not an animation frame, so calling getPose is
// allowed while getViewerPose is not.
assert_throws_dom('InvalidStateError', () => frame.getViewerPose(currentReferenceSpace));
let pose = frame.getPose(xrViewerSpace, currentReferenceSpace);
assert_not_equals(pose, null);
assert_true(pose instanceof XRPose);
assert_false(pose instanceof XRViewerPose);
});
}
function onSessionSqueezeStart(event) {
t.step( () => {
let input_sources = session.inputSources;
assert_equals(event.frame.session, session);
assert_equals(event.inputSource, input_sources[0]);
validateSameObject(event);
tryCallingFrameMethods(event.frame);
});
}
function onSessionSqueezeEnd(event) {
t.step( () => {
let input_sources = session.inputSources;
assert_equals(event.frame.session, session);
assert_equals(event.inputSource, input_sources[0]);
validateSameObject(event);
tryCallingFrameMethods(event.frame);
});
session.dispatchEvent(watcherDone);
}
function onSessionSqueeze(event) {
t.step( () => {
let input_sources = session.inputSources;
assert_equals(event.frame.session, session);
assert_equals(event.inputSource, input_sources[0]);
validateSameObject(event);
tryCallingFrameMethods(event.frame);
});
}
// Verifies that the same object is returned each time attributes are accessed
// on an XRInputSoruceEvent, as required by the spec.
function validateSameObject(event) {
let frame = event.frame;
let source = event.inputSource;
t.step(() => {
assert_equals(frame, event.frame,
"XRInputSourceEvent.frame returns the same object.");
assert_equals(source, event.inputSource,
"XRInputSourceEvent.inputSource returns the same object.");
});
}
session.addEventListener("squeezestart", onSessionSqueezeStart, false);
session.addEventListener("squeezeend", onSessionSqueezeEnd, false);
session.addEventListener("squeeze", onSessionSqueeze, false);
let pressed_grip_button = {
buttonType: "grip",
pressed: true,
touched: true,
pressedValue: 1.0
};
let unpressed_grip_button = {
buttonType: "grip",
pressed: false,
touched: false,
pressedValue: 0.0
};
let gripController = {
handedness: "none",
targetRayMode: "tracked-pointer",
pointerOrigin: VALID_POINTER_TRANSFORM,
profiles: [],
supportedButtons: [ unpressed_grip_button ]
};
let input_source =
fakeDeviceController.simulateInputSourceConnection(gripController);
let currentReferenceSpace = null;
session.requestReferenceSpace('viewer').then(function(viewerSpace) {
xrViewerSpace = viewerSpace;
session.requestReferenceSpace('local').then((referenceSpace) => {
currentReferenceSpace = referenceSpace;
//Simulate a grip starting then release it a short time later.
session.requestAnimationFrame((time, xrFrame) => {
input_source.updateButtonState(pressed_grip_button);
session.requestAnimationFrame((time, xrFrame) => {
input_source.updateButtonState(unpressed_grip_button);
session.requestAnimationFrame((time, xrFrame) => {
// Need to process one more frame to allow grip to propegate.
});
});
});
});
});
return eventPromise;
};
xr_session_promise_test(
testName, testFunction, fakeDeviceInitParams, 'immersive-vr');
</script>