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 { ...@@ -194,6 +194,9 @@ public class WebXrVrInputTest {
// Send a controller click and wait for JavaScript to receive it. // Send a controller click and wait for JavaScript to receive it.
controller.sendClickButtonToggleEvent(); controller.sendClickButtonToggleEvent();
mWebVrTestFramework.waitOnJavaScriptStep(); mWebVrTestFramework.waitOnJavaScriptStep();
// Re-register the callback since it unregisters itself after finishing the step.
mWebVrTestFramework.runJavaScriptOrFail(
"onPresentingAnimationFrameCallback = gamepadFrameCallback", POLL_TIMEOUT_SHORT_MS);
controller.sendClickButtonToggleEvent(); controller.sendClickButtonToggleEvent();
mWebVrTestFramework.waitOnJavaScriptStep(); mWebVrTestFramework.waitOnJavaScriptStep();
mWebVrTestFramework.endTest(); mWebVrTestFramework.endTest();
...@@ -380,6 +383,9 @@ public class WebXrVrInputTest { ...@@ -380,6 +383,9 @@ public class WebXrVrInputTest {
TestVrShellDelegate.getVrShellForTesting().getPresentationViewForTesting(); TestVrShellDelegate.getVrShellForTesting().getPresentationViewForTesting();
long downTime = sendScreenTouchDown(presentationView, x, y); long downTime = sendScreenTouchDown(presentationView, x, y);
mWebVrTestFramework.waitOnJavaScriptStep(); 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); sendScreenTouchUp(presentationView, x, y, downTime);
mWebVrTestFramework.waitOnJavaScriptStep(); mWebVrTestFramework.waitOnJavaScriptStep();
mWebVrTestFramework.endTest(); mWebVrTestFramework.endTest();
......
...@@ -771,6 +771,10 @@ IN_PROC_BROWSER_TEST_F(WebVrOpenVrBrowserTest, TestControllerInputRegistered) { ...@@ -771,6 +771,10 @@ IN_PROC_BROWSER_TEST_F(WebVrOpenVrBrowserTest, TestControllerInputRegistered) {
// Press and release the trigger, ensuring the Gamepad API detects both. // Press and release the trigger, ensuring the Gamepad API detects both.
my_mock.TogglePrimaryTrigger(controller_index); my_mock.TogglePrimaryTrigger(controller_index);
WaitOnJavaScriptStep(); WaitOnJavaScriptStep();
// Re-register the callback since it unregisters itself after finishing the
// step.
RunJavaScriptOrFail(
"onPresentingAnimationFrameCallback = gamepadFrameCallback");
my_mock.TogglePrimaryTrigger(controller_index); my_mock.TogglePrimaryTrigger(controller_index);
WaitOnJavaScriptStep(); WaitOnJavaScriptStep();
EndTest(); EndTest();
......
...@@ -37,7 +37,7 @@ View. ...@@ -37,7 +37,7 @@ View.
return frameCounter - lastInputChangeFrame > 60; return frameCounter - lastInputChangeFrame > 60;
} }
onPresentingAnimationFrameCallback = function() { function gamepadFrameCallback() {
if (index == -1) return; if (index == -1) return;
frameCounter++; frameCounter++;
var gp = navigator.getGamepads()[index]; var gp = navigator.getGamepads()[index];
...@@ -52,12 +52,19 @@ View. ...@@ -52,12 +52,19 @@ View.
} }
if (!pressed && gp.buttons[0].pressed == true) { if (!pressed && gp.buttons[0].pressed == true) {
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(); finishJavaScriptStep();
} }
if (pressed && gp.buttons[0].pressed == false) { if (pressed && gp.buttons[0].pressed == false) {
onPresentingAnimationFrameCallback = null;
done(); done();
} }
} }
onPresentingAnimationFrameCallback = gamepadFrameCallback;
</script> </script>
</body> </body>
</html> </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