Commit dcda3596 authored by bsheedy's avatar bsheedy Committed by Commit Bot

Fix VR controller test flakiness

For whatever reason,
WebVrInputTest#testControllerClicksRegisteredOnDaydream recently became
flaky due to not always detecting the connected controller. This patch
fixes that by explicitly trying to get the controller to be detected
instead of just assuming that the Gamepad API will work.

Bug: 
Change-Id: I14fc8f0e16f895fc1893fa27b1ccf4d2054b0f28
Reviewed-on: https://chromium-review.googlesource.com/741865Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512552}
parent 1d4c1f19
...@@ -128,6 +128,29 @@ public class WebVrInputTest { ...@@ -128,6 +128,29 @@ public class WebVrInputTest {
// Wait to enter VR // Wait to enter VR
VrTransitionUtils.enterPresentationAndWait( VrTransitionUtils.enterPresentationAndWait(
mVrTestFramework.getFirstTabCvc(), mVrTestFramework.getFirstTabWebContents()); mVrTestFramework.getFirstTabCvc(), mVrTestFramework.getFirstTabWebContents());
// The Gamepad API can flakily fail to detect the gamepad from a single button press, so
// spam it with button presses
boolean controllerConnected = false;
for (int i = 0; i < 10; i++) {
// The Gamepad API doesn't like detecting pressReleaseTouchpadButton() as it's too fast,
// so manually send the up and down events with a delay
controller.sendClickButtonToggleEvent();
SystemClock.sleep(100);
controller.sendClickButtonToggleEvent();
SystemClock.sleep(100);
if (VrTestFramework
.runJavaScriptOrFail("index != -1", POLL_TIMEOUT_SHORT_MS,
mVrTestFramework.getFirstTabWebContents())
.equals("true")) {
controllerConnected = true;
break;
}
}
Assert.assertTrue("Gamepad API detected controller", controllerConnected);
// Have a separate start condition so that the above presses/releases don't get
// accidentally detected during the actual test
VrTestFramework.runJavaScriptOrFail("canStartTest = true;", POLL_TIMEOUT_SHORT_MS,
mVrTestFramework.getFirstTabWebContents());
// 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();
VrTestFramework.waitOnJavaScriptStep(mVrTestFramework.getFirstTabWebContents()); VrTestFramework.waitOnJavaScriptStep(mVrTestFramework.getFirstTabWebContents());
...@@ -148,6 +171,10 @@ public class WebVrInputTest { ...@@ -148,6 +171,10 @@ public class WebVrInputTest {
public void testScreenTapsRegisteredOnCardboard() throws InterruptedException { public void testScreenTapsRegisteredOnCardboard() throws InterruptedException {
mVrTestFramework.loadUrlAndAwaitInitialization( mVrTestFramework.loadUrlAndAwaitInitialization(
VrTestFramework.getHtmlTestFile("test_gamepad_button"), PAGE_LOAD_TIMEOUT_S); VrTestFramework.getHtmlTestFile("test_gamepad_button"), PAGE_LOAD_TIMEOUT_S);
// This boolean is used by testControllerClicksRegisteredOnDaydream to prevent some
// flakiness, but is unnecessary here, so set immediately
VrTestFramework.runJavaScriptOrFail("canStartTest = true;", POLL_TIMEOUT_SHORT_MS,
mVrTestFramework.getFirstTabWebContents());
// Wait to enter VR // Wait to enter VR
VrTransitionUtils.enterPresentationAndWait( VrTransitionUtils.enterPresentationAndWait(
mVrTestFramework.getFirstTabCvc(), mVrTestFramework.getFirstTabWebContents()); mVrTestFramework.getFirstTabCvc(), mVrTestFramework.getFirstTabWebContents());
......
<!doctype html> <!doctype html>
<!-- <!--
Tests that either screen taps are registered in VR when viewer is Cardboard Tests that screen taps when using Cardboard are translated into controller
or that controller clicks are registered as screen taps in VR when viewer is input, and that Daydream controller input is registered when using Daydream
Daydream View. View.
--> -->
<html> <html>
<head> <head>
...@@ -19,14 +19,16 @@ Daydream View. ...@@ -19,14 +19,16 @@ Daydream View.
() => {finishJavaScriptStep();}, false); () => {finishJavaScriptStep();}, false);
var pressed = false; var pressed = false;
var index = -1; var index = -1;
var canStartTest = false;
window.addEventListener("gamepadconnected", function(e) { window.addEventListener("gamepadconnected", function(e) {
t.step( () => { t.step( () => {
assert_equals(index, -1, "Should only receive gamepadconnected once"); assert_equals(index, -1, "Should only receive gamepadconnected once");
index = e.gamepad.index;
}); });
index = e.gamepad.index;
}); });
onAnimationFrameCallback = function() { onAnimationFrameCallback = function() {
if (index == -1) return; if (index == -1) return;
if (!canStartTest) return;
var gp = navigator.getGamepads()[index]; var gp = navigator.getGamepads()[index];
if (!pressed && gp.buttons[0].pressed == true) { if (!pressed && gp.buttons[0].pressed == true) {
pressed = true; pressed = true;
......
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