Commit 5b4af07d authored by Brian Sheedy's avatar Brian Sheedy Committed by Commit Bot

Fix XR controller test race condition

Fixes a race condition in XR tests that use the test_gamepad_button.html
test page. It was possible for finishJavaScriptStep() to be called
multiple times before the Java/C++ code could ack the first one, leading
to test failures.

Bug: 990843
Change-Id: I6e1a92c9cc3512862fb6441a1bad5efecff3a83c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1736801
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684120}
parent ac7514b0
......@@ -194,6 +194,9 @@ public class WebXrVrInputTest {
// Send a controller click and wait for JavaScript to receive it.
controller.sendClickButtonToggleEvent();
mWebVrTestFramework.waitOnJavaScriptStep();
// Re-register the callback since it unregisters itself after finishing the step.
mWebVrTestFramework.runJavaScriptOrFail(
"onPresentingAnimationFrameCallback = gamepadFrameCallback", POLL_TIMEOUT_SHORT_MS);
controller.sendClickButtonToggleEvent();
mWebVrTestFramework.waitOnJavaScriptStep();
mWebVrTestFramework.endTest();
......@@ -380,6 +383,9 @@ public class WebXrVrInputTest {
TestVrShellDelegate.getVrShellForTesting().getPresentationViewForTesting();
long downTime = sendScreenTouchDown(presentationView, x, y);
mWebVrTestFramework.waitOnJavaScriptStep();
// Re-register the callback since it unregisters itself after finishing the step.
mWebVrTestFramework.runJavaScriptOrFail(
"onPresentingAnimationFrameCallback = gamepadFrameCallback", POLL_TIMEOUT_SHORT_MS);
sendScreenTouchUp(presentationView, x, y, downTime);
mWebVrTestFramework.waitOnJavaScriptStep();
mWebVrTestFramework.endTest();
......
......@@ -771,6 +771,10 @@ IN_PROC_BROWSER_TEST_F(WebVrOpenVrBrowserTest, TestControllerInputRegistered) {
// Press and release the trigger, ensuring the Gamepad API detects both.
my_mock.TogglePrimaryTrigger(controller_index);
WaitOnJavaScriptStep();
// Re-register the callback since it unregisters itself after finishing the
// step.
RunJavaScriptOrFail(
"onPresentingAnimationFrameCallback = gamepadFrameCallback");
my_mock.TogglePrimaryTrigger(controller_index);
WaitOnJavaScriptStep();
EndTest();
......
......@@ -37,7 +37,7 @@ View.
return frameCounter - lastInputChangeFrame > 60;
}
onPresentingAnimationFrameCallback = function() {
function gamepadFrameCallback() {
if (index == -1) return;
frameCounter++;
var gp = navigator.getGamepads()[index];
......@@ -52,12 +52,19 @@ View.
}
if (!pressed && gp.buttons[0].pressed == true) {
pressed = true;
// Unregister the callback so that we don't call
// finishJavaScriptStep() multiple times without acking if the test
// code doesn't ack within a single frame.
onPresentingAnimationFrameCallback = null;
finishJavaScriptStep();
}
if (pressed && gp.buttons[0].pressed == false) {
onPresentingAnimationFrameCallback = null;
done();
}
}
onPresentingAnimationFrameCallback = gamepadFrameCallback;
</script>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment