Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/WebVrTest.java

Issue 2857583005: Convert Vr tests to JUnit4 (Closed)
Patch Set: Change base class for VrTestRule Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/WebVrTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/WebVrTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/WebVrTest.java
index 87c4dc534a127f31464efea236d5ccdb8235caa7..40355bf733f2a6db7c7e5183a34972145d92d05a 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/WebVrTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/WebVrTest.java
@@ -15,10 +15,18 @@ import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest;
import android.widget.TextView;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisableIf;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.R;
+import org.chromium.chrome.browser.ChromeSwitches;
+import org.chromium.chrome.test.ChromeActivityTestRule;
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -26,48 +34,56 @@ import java.util.concurrent.TimeUnit;
/**
* End-to-end tests for WebVR using the WebVR test framework from VrTestBase.
*/
-@CommandLineFlags.Add("enable-webvr")
+@RunWith(ChromeJUnit4ClassRunner.class)
+@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG, "enable-webvr"})
@Restriction(RESTRICTION_TYPE_WEBVR_SUPPORTED)
-public class WebVrTest extends VrTestBase {
- private static final String TAG = "WebVrTest";
+public class WebVrTest {
+ @Rule
+ public VrTestRule mVrTestRule = new VrTestRule();
/**
* Tests that a successful requestPresent call actually enters VR
*/
+ @Test
@SmallTest
public void testRequestPresentEntersVr() throws InterruptedException {
String testName = "test_requestPresent_enters_vr";
- loadUrl(getHtmlTestFile(testName), PAGE_LOAD_TIMEOUT_S);
- assertTrue("VRDisplay found", vrDisplayFound(mWebContents));
- enterVrTapAndWait(mWebContents);
- assertTrue("VrShellDelegate is in VR", VrShellDelegate.isInVr());
- endTest(mWebContents);
+ mVrTestRule.loadUrl(VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ Assert.assertTrue(
+ "VRDisplay found", mVrTestRule.vrDisplayFound(mVrTestRule.getWebContents()));
+ mVrTestRule.enterVrTapAndWait(mVrTestRule.getWebContents());
+ Assert.assertTrue("VrShellDelegate is in VR", VrShellDelegate.isInVr());
+ mVrTestRule.endTest(mVrTestRule.getWebContents());
}
/**
* Tests that scanning the Daydream View NFC tag on supported devices fires the
* vrdisplayactivate event.
*/
+ @Test
@SmallTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
public void testNfcFiresVrdisplayactivate() throws InterruptedException {
String testName = "test_nfc_fires_vrdisplayactivate";
- loadUrl(getHtmlTestFile(testName), PAGE_LOAD_TIMEOUT_S);
- simNfcScanAndWait(mWebContents);
- endTest(mWebContents);
+ mVrTestRule.loadUrl(VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ mVrTestRule.simNfcScanAndWait(mVrTestRule.getWebContents());
+ mVrTestRule.endTest(mVrTestRule.getWebContents());
}
/**
* Tests that screen touches are not registered when the viewer is a Daydream View.
*/
+ @Test
@LargeTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
public void testScreenTapsNotRegisteredOnDaydream() throws InterruptedException {
String testName = "test_screen_taps_not_registered_on_daydream";
- loadUrl(getHtmlTestFile(testName), PAGE_LOAD_TIMEOUT_S);
- assertTrue("VRDisplay found", vrDisplayFound(mWebContents));
- executeStepAndWait("stepVerifyNoInitialTaps()", mWebContents);
- enterVrTapAndWait(mWebContents);
+ mVrTestRule.loadUrl(VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ Assert.assertTrue(
+ "VRDisplay found", mVrTestRule.vrDisplayFound(mVrTestRule.getWebContents()));
+ mVrTestRule.executeStepAndWait("stepVerifyNoInitialTaps()", mVrTestRule.getWebContents());
+ mVrTestRule.enterVrTapAndWait(mVrTestRule.getWebContents());
// Wait on VrShellImpl to say that its parent consumed the touch event
// Set to 2 because there's an ACTION_DOWN followed by ACTION_UP
final CountDownLatch touchRegisteredLatch = new CountDownLatch(2);
@@ -76,41 +92,45 @@ public class WebVrTest extends VrTestBase {
@Override
public void onDispatchTouchEvent(
boolean parentConsumed, boolean cardboardTriggered) {
- if (!parentConsumed) fail("Parent did not consume event");
- if (cardboardTriggered) fail("Cardboard event triggered");
+ if (!parentConsumed) Assert.fail("Parent did not consume event");
+ if (cardboardTriggered) Assert.fail("Cardboard event triggered");
touchRegisteredLatch.countDown();
}
});
- enterVrTap();
- assertTrue("VrShellImpl dispatched touches",
+ mVrTestRule.enterVrTap();
+ Assert.assertTrue("VrShellImpl dispatched touches",
touchRegisteredLatch.await(POLL_TIMEOUT_SHORT_MS, TimeUnit.MILLISECONDS));
- executeStepAndWait("stepVerifyNoAdditionalTaps()", mWebContents);
- endTest(mWebContents);
+ mVrTestRule.executeStepAndWait(
+ "stepVerifyNoAdditionalTaps()", mVrTestRule.getWebContents());
+ mVrTestRule.endTest(mVrTestRule.getWebContents());
}
/**
* Tests that Daydream controller clicks are registered as screen taps when the viewer is a
* Daydream View.
*/
+ @Test
@LargeTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
public void testControllerClicksRegisteredAsTapsOnDaydream() throws InterruptedException {
- EmulatedVrController controller = new EmulatedVrController(getActivity());
+ EmulatedVrController controller = new EmulatedVrController(mVrTestRule.getActivity());
String testName = "test_screen_taps_registered";
- loadUrl(getHtmlTestFile(testName), PAGE_LOAD_TIMEOUT_S);
- assertTrue("VRDisplay found", vrDisplayFound(mWebContents));
- executeStepAndWait("stepVerifyNoInitialTaps()", mWebContents);
+ mVrTestRule.loadUrl(VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ Assert.assertTrue(
+ "VRDisplay found", mVrTestRule.vrDisplayFound(mVrTestRule.getWebContents()));
+ mVrTestRule.executeStepAndWait("stepVerifyNoInitialTaps()", mVrTestRule.getWebContents());
// Tap and wait to enter VR
- enterVrTapAndWait(mWebContents);
+ mVrTestRule.enterVrTapAndWait(mVrTestRule.getWebContents());
// Send a controller click and wait for JavaScript to receive it
controller.pressReleaseTouchpadButton();
- waitOnJavaScriptStep(mWebContents);
- endTest(mWebContents);
+ mVrTestRule.waitOnJavaScriptStep(mVrTestRule.getWebContents());
+ mVrTestRule.endTest(mVrTestRule.getWebContents());
}
/**
* Tests that screen touches are still registered when the viewer is Cardboard.
*/
+ @Test
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_NON_DAYDREAM)
@DisableIf.Build(message = "Flaky on L crbug.com/713781",
@@ -118,30 +138,35 @@ public class WebVrTest extends VrTestBase {
sdk_is_less_than = Build.VERSION_CODES.M)
public void testScreenTapsRegisteredOnCardboard() throws InterruptedException {
String testName = "test_screen_taps_registered";
- loadUrl(getHtmlTestFile(testName), PAGE_LOAD_TIMEOUT_S);
- assertTrue("VRDisplay found", vrDisplayFound(mWebContents));
- executeStepAndWait("stepVerifyNoInitialTaps()", mWebContents);
+ mVrTestRule.loadUrl(VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ Assert.assertTrue(
+ "VRDisplay found", mVrTestRule.vrDisplayFound(mVrTestRule.getWebContents()));
+ mVrTestRule.executeStepAndWait("stepVerifyNoInitialTaps()", mVrTestRule.getWebContents());
// Tap and wait to enter VR
- enterVrTapAndWait(mWebContents);
+ mVrTestRule.enterVrTapAndWait(mVrTestRule.getWebContents());
// Tap and wait for JavaScript to receive it
- enterVrTapAndWait(mWebContents);
- endTest(mWebContents);
+ mVrTestRule.enterVrTapAndWait(mVrTestRule.getWebContents());
+ mVrTestRule.endTest(mVrTestRule.getWebContents());
}
/**
* Tests that non-focused tabs cannot get pose information.
*/
+ @Test
@SmallTest
public void testPoseDataUnfocusedTab() throws InterruptedException {
String testName = "test_pose_data_unfocused_tab";
- loadUrl(getHtmlTestFile(testName), PAGE_LOAD_TIMEOUT_S);
- assertTrue("VRDisplay found", vrDisplayFound(mWebContents));
- executeStepAndWait("stepCheckFrameDataWhileFocusedTab()", mWebContents);
+ mVrTestRule.loadUrl(VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ Assert.assertTrue(
+ "VRDisplay found", mVrTestRule.vrDisplayFound(mVrTestRule.getWebContents()));
+ mVrTestRule.executeStepAndWait(
+ "stepCheckFrameDataWhileFocusedTab()", mVrTestRule.getWebContents());
- loadUrlInNewTab("about:blank");
+ mVrTestRule.loadUrlInNewTab("about:blank");
- executeStepAndWait("stepCheckFrameDataWhileNonFocusedTab()", mWebContents);
- endTest(mWebContents);
+ mVrTestRule.executeStepAndWait(
+ "stepCheckFrameDataWhileNonFocusedTab()", mVrTestRule.getWebContents());
+ mVrTestRule.endTest(mVrTestRule.getWebContents());
}
/**
@@ -155,54 +180,60 @@ public class WebVrTest extends VrTestBase {
mockChecker.setMockReturnValue(checkerReturnValue);
VrUtils.getVrShellDelegateInstance().overrideVrCoreVersionCheckerForTesting(mockChecker);
String testName = "generic_webvr_page";
- loadUrl(getHtmlTestFile(testName), PAGE_LOAD_TIMEOUT_S);
+ mVrTestRule.loadUrl(VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
String displayFound = "VRDisplay Found";
String barPresent = "InfoBar present";
if (checkerReturnValue == VrCoreVersionChecker.VR_READY) {
- assertTrue(displayFound, vrDisplayFound(mWebContents));
- assertFalse(barPresent,
+ Assert.assertTrue(
+ displayFound, mVrTestRule.vrDisplayFound(mVrTestRule.getWebContents()));
+ Assert.assertFalse(barPresent,
VrUtils.isUpdateInstallInfoBarPresent(
- getActivity().getWindow().getDecorView()));
+ mVrTestRule.getActivity().getWindow().getDecorView()));
} else if (checkerReturnValue == VrCoreVersionChecker.VR_OUT_OF_DATE
|| checkerReturnValue == VrCoreVersionChecker.VR_NOT_AVAILABLE) {
// Out of date and missing cases are the same, but with different text
String expectedMessage, expectedButton;
if (checkerReturnValue == VrCoreVersionChecker.VR_OUT_OF_DATE) {
- expectedMessage =
- getActivity().getString(R.string.vr_services_check_infobar_update_text);
- expectedButton =
- getActivity().getString(R.string.vr_services_check_infobar_update_button);
+ expectedMessage = mVrTestRule.getActivity().getString(
+ R.string.vr_services_check_infobar_update_text);
+ expectedButton = mVrTestRule.getActivity().getString(
+ R.string.vr_services_check_infobar_update_button);
} else {
- expectedMessage =
- getActivity().getString(R.string.vr_services_check_infobar_install_text);
- expectedButton =
- getActivity().getString(R.string.vr_services_check_infobar_install_button);
+ expectedMessage = mVrTestRule.getActivity().getString(
+ R.string.vr_services_check_infobar_install_text);
+ expectedButton = mVrTestRule.getActivity().getString(
+ R.string.vr_services_check_infobar_install_button);
}
- assertFalse(displayFound, vrDisplayFound(mWebContents));
- assertTrue(barPresent,
+ Assert.assertFalse(
+ displayFound, mVrTestRule.vrDisplayFound(mVrTestRule.getWebContents()));
+ Assert.assertTrue(barPresent,
VrUtils.isUpdateInstallInfoBarPresent(
- getActivity().getWindow().getDecorView()));
- TextView tempView = (TextView) getActivity().getWindow().getDecorView().findViewById(
- R.id.infobar_message);
- assertEquals(expectedMessage, tempView.getText().toString());
- tempView = (TextView) getActivity().getWindow().getDecorView().findViewById(
+ mVrTestRule.getActivity().getWindow().getDecorView()));
+ TextView tempView =
+ (TextView) mVrTestRule.getActivity().getWindow().getDecorView().findViewById(
+ R.id.infobar_message);
+ Assert.assertEquals(expectedMessage, tempView.getText().toString());
+ tempView = (TextView) mVrTestRule.getActivity().getWindow().getDecorView().findViewById(
R.id.button_primary);
- assertEquals(expectedButton, tempView.getText().toString());
+ Assert.assertEquals(expectedButton, tempView.getText().toString());
} else if (checkerReturnValue == VrCoreVersionChecker.VR_NOT_SUPPORTED) {
- assertFalse(displayFound, vrDisplayFound(mWebContents));
- assertFalse(barPresent,
+ Assert.assertFalse(
+ displayFound, mVrTestRule.vrDisplayFound(mVrTestRule.getWebContents()));
+ Assert.assertFalse(barPresent,
VrUtils.isUpdateInstallInfoBarPresent(
- getActivity().getWindow().getDecorView()));
+ mVrTestRule.getActivity().getWindow().getDecorView()));
} else {
- fail("Invalid VrCoreVersionChecker value: " + String.valueOf(checkerReturnValue));
+ Assert.fail(
+ "Invalid VrCoreVersionChecker value: " + String.valueOf(checkerReturnValue));
}
- assertEquals(checkerReturnValue, mockChecker.getLastReturnValue());
+ Assert.assertEquals(checkerReturnValue, mockChecker.getLastReturnValue());
}
/**
* Tests that the upgrade/install VR Services InfoBar is not present when VR Services is
* installed and up to date.
*/
+ @Test
@MediumTest
public void testInfoBarNotPresentWhenVrServicesCurrent() throws InterruptedException {
infoBarTestHelper(VrCoreVersionChecker.VR_READY);
@@ -211,6 +242,7 @@ public class WebVrTest extends VrTestBase {
/**
* Tests that the upgrade VR Services InfoBar is present when VR Services is outdated.
*/
+ @Test
@MediumTest
public void testInfoBarPresentWhenVrServicesOutdated() throws InterruptedException {
infoBarTestHelper(VrCoreVersionChecker.VR_OUT_OF_DATE);
@@ -219,6 +251,7 @@ public class WebVrTest extends VrTestBase {
/**
* Tests that the install VR Services InfoBar is present when VR Services is missing.
*/
+ @Test
@MediumTest
public void testInfoBarPresentWhenVrServicesMissing() throws InterruptedException {
infoBarTestHelper(VrCoreVersionChecker.VR_NOT_AVAILABLE);
@@ -228,6 +261,7 @@ public class WebVrTest extends VrTestBase {
* Tests that the install VR Services InfoBar is not present when VR is not supported on the
* device.
*/
+ @Test
@MediumTest
public void testInfoBarNotPresentWhenVrServicesNotSupported() throws InterruptedException {
infoBarTestHelper(VrCoreVersionChecker.VR_NOT_SUPPORTED);
@@ -237,27 +271,31 @@ public class WebVrTest extends VrTestBase {
* Tests that the reported WebVR capabilities match expectations on the devices the WebVR tests
* are run on continuously.
*/
+ @Test
@MediumTest
public void testDeviceCapabilitiesMatchExpectations() throws InterruptedException {
String testName = "test_device_capabilities_match_expectations";
- loadUrl(getHtmlTestFile(testName), PAGE_LOAD_TIMEOUT_S);
- assertTrue("VRDisplayFound", vrDisplayFound(mWebContents));
- executeStepAndWait("stepCheckDeviceCapabilities('" + Build.DEVICE + "')", mWebContents);
- endTest(mWebContents);
+ mVrTestRule.loadUrl(VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ Assert.assertTrue(
+ "VRDisplayFound", mVrTestRule.vrDisplayFound(mVrTestRule.getWebContents()));
+ mVrTestRule.executeStepAndWait("stepCheckDeviceCapabilities('" + Build.DEVICE + "')",
+ mVrTestRule.getWebContents());
+ mVrTestRule.endTest(mVrTestRule.getWebContents());
}
/**
* Tests that focus is locked to the presenting display for purposes of VR input.
*/
+ @Test
@MediumTest
@DisableIf.Build(message = "Flaky on L crbug.com/713781",
sdk_is_greater_than = Build.VERSION_CODES.KITKAT,
sdk_is_less_than = Build.VERSION_CODES.M)
public void testPresentationLocksFocus() throws InterruptedException {
String testName = "test_presentation_locks_focus";
- loadUrl(getHtmlTestFile(testName), PAGE_LOAD_TIMEOUT_S);
- enterVrTapAndWait(mWebContents);
- waitOnJavaScriptStep(mWebContents);
- endTest(mWebContents);
+ mVrTestRule.loadUrl(VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ mVrTestRule.enterVrTapAndWait(mVrTestRule.getWebContents());
+ mVrTestRule.waitOnJavaScriptStep(mVrTestRule.getWebContents());
+ mVrTestRule.endTest(mVrTestRule.getWebContents());
}
}

Powered by Google App Engine
This is Rietveld 408576698