Commit 2b1109ab authored by bsheedy's avatar bsheedy Committed by Commit Bot

Reduce VR NFC flakiness

Adds simNfcScanUntilVrEntered, which in most cases, replaces simNfcScan.
This is to deal with flakiness that stems from VrCore thinking that it's
still in VR from a previous test and nooping when it receives an NFC
scan in a following test.

Bug: 736527, 812306
Change-Id: If7b135b99df03c463f5b393bfbe6290e06d0ee4e
Reviewed-on: https://chromium-review.googlesource.com/923099Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537342}
parent e4ae34da
......@@ -13,8 +13,8 @@ import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_D
import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_VIEWER_DAYDREAM;
import android.app.Activity;
import android.os.SystemClock;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.LargeTest;
import android.support.test.filters.MediumTest;
import android.widget.ImageView;
......@@ -71,17 +71,14 @@ public class VrShellTransitionTest {
private void enterVrShellNfc(boolean supported) {
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
NfcSimUtils.simNfcScan(mTestRule.getActivity());
if (supported) {
TransitionUtils.waitForVrEntry(POLL_TIMEOUT_LONG_MS);
NfcSimUtils.simNfcScanUntilVrEntry(mTestRule.getActivity());
Assert.assertTrue(VrShellDelegate.isInVr());
} else {
NfcSimUtils.simNfcScan(mTestRule.getActivity());
Assert.assertFalse(VrShellDelegate.isInVr());
}
TransitionUtils.forceExitVr();
// TODO(bsheedy): Figure out why NFC tests cause the next test to fail
// to enter VR unless we sleep for some amount of time after exiting VR
// in the NFC test
}
private void enterExitVrShell(boolean supported) {
......@@ -108,10 +105,8 @@ public class VrShellTransitionTest {
@Test
@Restriction({RESTRICTION_TYPE_DEVICE_DAYDREAM, RESTRICTION_TYPE_VIEWER_DAYDREAM})
@RetryOnFailure(message = "crbug.com/736527")
@MediumTest
@LargeTest
public void test2dtoVrShellNfcSupported() {
// Sleep necessary to deal with https://crbug.com/736527
SystemClock.sleep(10000);
enterVrShellNfc(true /* supported */);
}
......
......@@ -33,7 +33,6 @@ import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
import org.chromium.base.test.params.ParameterSet;
import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.ChromeActivity;
......@@ -165,14 +164,13 @@ public class WebVrTransitionTest {
@LargeTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
@VrActivityRestriction({VrActivityRestriction.SupportedActivity.ALL})
@DisabledTest(message = "crbug.com/812306")
public void testNfcFiresVrdisplayactivate() throws InterruptedException {
mVrTestFramework.loadUrlAndAwaitInitialization(
VrTestFramework.getHtmlTestFile("test_nfc_fires_vrdisplayactivate"),
PAGE_LOAD_TIMEOUT_S);
VrTestFramework.runJavaScriptOrFail(
"addListener()", POLL_TIMEOUT_LONG_MS, mVrTestFramework.getFirstTabWebContents());
NfcSimUtils.simNfcScan(mTestRule.getActivity());
NfcSimUtils.simNfcScanUntilVrEntry(mTestRule.getActivity());
VrTestFramework.waitOnJavaScriptStep(mVrTestFramework.getFirstTabWebContents());
VrTestFramework.endTest(mVrTestFramework.getFirstTabWebContents());
// VrCore has a 2000 ms debounce timeout on NFC scans. When run multiple times in different
......
......@@ -12,6 +12,10 @@ import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import org.chromium.chrome.browser.vr_shell.TestVrShellDelegate;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
......@@ -32,6 +36,10 @@ public class NfcSimUtils {
private static final int VERSION = 123;
private static final int RESERVED = 456;
// VrCore always seems to recover within ~10 seconds, so give it that plus some extra to be safe
private static final int NFC_SCAN_TIMEOUT_MS = 15000;
private static final int NFC_SCAN_INTERVAL_MS = 2000;
/**
* Makes an Intent that triggers VrCore as if the Daydream headset's NFC
* tag was scanned.
......@@ -52,7 +60,7 @@ public class NfcSimUtils {
/**
* Simulates the NFC tag of the Daydream headset being scanned.
* @param context The Context that the activity will be started from.
* @param context The Context that the NFC scan activity will be started from.
*/
public static void simNfcScan(Context context) {
Intent nfcIntent = NfcSimUtils.makeNfcIntent();
......@@ -63,6 +71,23 @@ public class NfcSimUtils {
}
}
/**
* Repeatedly simulates an NFC scan until VR is actually entered. This is a workaround for
* https://crbug.com/736527.
* @param context The Context that the NFC scan activity will be started from.
*/
public static void simNfcScanUntilVrEntry(final Context context) {
final TestVrShellDelegate delegate = VrShellDelegateUtils.getDelegateInstance();
CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override
public boolean isSatisfied() {
if (delegate.isVrEntryComplete()) return true;
simNfcScan(context);
return false;
}
}, NFC_SCAN_TIMEOUT_MS, NFC_SCAN_INTERVAL_MS);
}
private static byte[] intToByteArray(int i) {
final ByteBuffer bb = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE);
bb.order(BYTE_ORDER);
......
......@@ -6,6 +6,7 @@ vrdisplayactivate event
<html>
<head>
<link rel="stylesheet" type="text/css" href="../resources/webvr_e2e.css">
<meta name="timeout" content="long">
</head>
<body>
<canvas id="webgl-canvas"></canvas>
......
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