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

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

Issue 2876223004: Convert Vr tests to JUnit4 (Closed)
Patch Set: Rebase again 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
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrTestRule.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..a1f40ce8fae18f0857b4223b4b77b76c3cb28bea 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,21 @@ import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest;
import android.widget.TextView;
+import org.junit.Assert;
+import org.junit.Before;
+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 org.chromium.chrome.test.ChromeTabbedActivityTestRule;
+import org.chromium.content_public.browser.WebContents;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -26,48 +37,67 @@ 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 ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
+ @Rule
+ public VrTestRule mVrTestRule = new VrTestRule();
+
+ private WebContents mFirstTabWebContents;
+
+ @Before
+ public void setUp() throws InterruptedException {
+ mActivityTestRule.startMainActivityOnBlankPage();
+ mFirstTabWebContents = mActivityTestRule.getActivity().getActivityTab().getWebContents();
+ }
/**
* 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);
+ mActivityTestRule.loadUrl(
+ VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ Assert.assertTrue("VRDisplay found", mVrTestRule.vrDisplayFound(mFirstTabWebContents));
+ mVrTestRule.enterVrTapAndWait(mActivityTestRule.getActivity(), mFirstTabWebContents);
+ Assert.assertTrue("VrShellDelegate is in VR", VrShellDelegate.isInVr());
+ mVrTestRule.endTest(mFirstTabWebContents);
}
/**
* 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);
+ mActivityTestRule.loadUrl(
+ VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ mVrTestRule.simNfcScanAndWait(mActivityTestRule.getActivity(), mFirstTabWebContents);
+ mVrTestRule.endTest(mFirstTabWebContents);
}
/**
* 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);
+ mActivityTestRule.loadUrl(
+ VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ Assert.assertTrue("VRDisplay found", mVrTestRule.vrDisplayFound(mFirstTabWebContents));
+ mVrTestRule.executeStepAndWait("stepVerifyNoInitialTaps()", mFirstTabWebContents);
+ mVrTestRule.enterVrTapAndWait(mActivityTestRule.getActivity(), mFirstTabWebContents);
// 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 +106,44 @@ 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(mActivityTestRule.getActivity());
+ Assert.assertTrue("VrShellImpl dispatched touches",
touchRegisteredLatch.await(POLL_TIMEOUT_SHORT_MS, TimeUnit.MILLISECONDS));
- executeStepAndWait("stepVerifyNoAdditionalTaps()", mWebContents);
- endTest(mWebContents);
+ mVrTestRule.executeStepAndWait("stepVerifyNoAdditionalTaps()", mFirstTabWebContents);
+ mVrTestRule.endTest(mFirstTabWebContents);
}
/**
* 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(mActivityTestRule.getActivity());
String testName = "test_screen_taps_registered";
- loadUrl(getHtmlTestFile(testName), PAGE_LOAD_TIMEOUT_S);
- assertTrue("VRDisplay found", vrDisplayFound(mWebContents));
- executeStepAndWait("stepVerifyNoInitialTaps()", mWebContents);
+ mActivityTestRule.loadUrl(
+ VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ Assert.assertTrue("VRDisplay found", mVrTestRule.vrDisplayFound(mFirstTabWebContents));
+ mVrTestRule.executeStepAndWait("stepVerifyNoInitialTaps()", mFirstTabWebContents);
// Tap and wait to enter VR
- enterVrTapAndWait(mWebContents);
+ mVrTestRule.enterVrTapAndWait(mActivityTestRule.getActivity(), mFirstTabWebContents);
// Send a controller click and wait for JavaScript to receive it
controller.pressReleaseTouchpadButton();
- waitOnJavaScriptStep(mWebContents);
- endTest(mWebContents);
+ mVrTestRule.waitOnJavaScriptStep(mFirstTabWebContents);
+ mVrTestRule.endTest(mFirstTabWebContents);
}
/**
* 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 +151,34 @@ 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);
+ mActivityTestRule.loadUrl(
+ VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ Assert.assertTrue("VRDisplay found", mVrTestRule.vrDisplayFound(mFirstTabWebContents));
+ mVrTestRule.executeStepAndWait("stepVerifyNoInitialTaps()", mFirstTabWebContents);
// Tap and wait to enter VR
- enterVrTapAndWait(mWebContents);
+ mVrTestRule.enterVrTapAndWait(mActivityTestRule.getActivity(), mFirstTabWebContents);
// Tap and wait for JavaScript to receive it
- enterVrTapAndWait(mWebContents);
- endTest(mWebContents);
+ mVrTestRule.enterVrTapAndWait(mActivityTestRule.getActivity(), mFirstTabWebContents);
+ mVrTestRule.endTest(mFirstTabWebContents);
}
/**
* 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);
+ mActivityTestRule.loadUrl(
+ VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ Assert.assertTrue("VRDisplay found", mVrTestRule.vrDisplayFound(mFirstTabWebContents));
+ mVrTestRule.executeStepAndWait("stepCheckFrameDataWhileFocusedTab()", mFirstTabWebContents);
- loadUrlInNewTab("about:blank");
+ mActivityTestRule.loadUrlInNewTab("about:blank");
- executeStepAndWait("stepCheckFrameDataWhileNonFocusedTab()", mWebContents);
- endTest(mWebContents);
+ mVrTestRule.executeStepAndWait(
+ "stepCheckFrameDataWhileNonFocusedTab()", mFirstTabWebContents);
+ mVrTestRule.endTest(mFirstTabWebContents);
}
/**
@@ -155,54 +192,61 @@ public class WebVrTest extends VrTestBase {
mockChecker.setMockReturnValue(checkerReturnValue);
VrUtils.getVrShellDelegateInstance().overrideVrCoreVersionCheckerForTesting(mockChecker);
String testName = "generic_webvr_page";
- loadUrl(getHtmlTestFile(testName), PAGE_LOAD_TIMEOUT_S);
+ mActivityTestRule.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(mFirstTabWebContents));
+ Assert.assertFalse(barPresent,
VrUtils.isUpdateInstallInfoBarPresent(
- getActivity().getWindow().getDecorView()));
+ mActivityTestRule.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 = mActivityTestRule.getActivity().getString(
+ R.string.vr_services_check_infobar_update_text);
+ expectedButton = mActivityTestRule.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 = mActivityTestRule.getActivity().getString(
+ R.string.vr_services_check_infobar_install_text);
+ expectedButton = mActivityTestRule.getActivity().getString(
+ R.string.vr_services_check_infobar_install_button);
}
- assertFalse(displayFound, vrDisplayFound(mWebContents));
- assertTrue(barPresent,
+ Assert.assertFalse(displayFound, mVrTestRule.vrDisplayFound(mFirstTabWebContents));
+ 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(
- R.id.button_primary);
- assertEquals(expectedButton, tempView.getText().toString());
+ mActivityTestRule.getActivity().getWindow().getDecorView()));
+ TextView tempView = (TextView) mActivityTestRule.getActivity()
+ .getWindow()
+ .getDecorView()
+ .findViewById(R.id.infobar_message);
+ Assert.assertEquals(expectedMessage, tempView.getText().toString());
+ tempView = (TextView) mActivityTestRule.getActivity()
+ .getWindow()
+ .getDecorView()
+ .findViewById(R.id.button_primary);
+ Assert.assertEquals(expectedButton, tempView.getText().toString());
} else if (checkerReturnValue == VrCoreVersionChecker.VR_NOT_SUPPORTED) {
- assertFalse(displayFound, vrDisplayFound(mWebContents));
- assertFalse(barPresent,
+ Assert.assertFalse(displayFound, mVrTestRule.vrDisplayFound(mFirstTabWebContents));
+ Assert.assertFalse(barPresent,
VrUtils.isUpdateInstallInfoBarPresent(
- getActivity().getWindow().getDecorView()));
+ mActivityTestRule.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 +255,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 +264,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 +274,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 +284,32 @@ 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);
+ mActivityTestRule.loadUrl(
+ VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ Assert.assertTrue("VRDisplayFound", mVrTestRule.vrDisplayFound(mFirstTabWebContents));
+ mVrTestRule.executeStepAndWait(
+ "stepCheckDeviceCapabilities('" + Build.DEVICE + "')", mFirstTabWebContents);
+ mVrTestRule.endTest(mFirstTabWebContents);
}
/**
* 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);
+ mActivityTestRule.loadUrl(
+ VrTestRule.getHtmlTestFile(testName), VrTestRule.PAGE_LOAD_TIMEOUT_S);
+ mVrTestRule.enterVrTapAndWait(mActivityTestRule.getActivity(), mFirstTabWebContents);
+ mVrTestRule.waitOnJavaScriptStep(mFirstTabWebContents);
+ mVrTestRule.endTest(mFirstTabWebContents);
}
}
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrTestRule.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698