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

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

Issue 2857583005: Convert Vr tests to JUnit4 (Closed)
Patch Set: Address John's comments 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/VrShellTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrShellTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrShellTest.java
index db021397e9710e6079927e3a08f83fa83823350b..4f5c02db797571019ec178e964b93d56159ea84c 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrShellTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrShellTest.java
@@ -10,18 +10,30 @@ 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.content.pm.ActivityInfo;
+import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest;
import android.view.ViewGroup;
+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.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.Restriction;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R;
+import org.chromium.chrome.browser.ChromeSwitches;
+import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.compositor.CompositorViewHolder;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
+import org.chromium.chrome.test.ChromeActivityTestRule;
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
+import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.RenderUtils.ViewRenderer;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.test.util.Criteria;
@@ -37,27 +49,27 @@ import java.util.concurrent.atomic.AtomicReference;
* interacting with WebVR in addition to the VR browser, so inherit from
* VrTestBase for the WebVR test framework.
*/
-@CommandLineFlags.Add("enable-features=VrShell")
-public class VrShellTest extends VrTestBase {
+@RunWith(ChromeJUnit4ClassRunner.class)
+@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG, "enable-features=VrShell"})
+public class VrShellTest {
+ @Rule
+ public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
+
private static final String GOLDEN_DIR =
"chrome/test/data/android/render_tests";
private VrShellDelegate mDelegate;
private ViewRenderer mViewRenderer;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
+ mActivityTestRule.startMainActivityOnBlankPage();
+ mViewRenderer = new ViewRenderer(
+ mActivityTestRule.getActivity(), GOLDEN_DIR, this.getClass().getSimpleName());
mDelegate = VrUtils.getVrShellDelegateInstance();
}
- @Override
- public void startMainActivity() throws InterruptedException {
- startMainActivityOnBlankPage();
- mViewRenderer = new ViewRenderer(getActivity(),
- GOLDEN_DIR, this.getClass().getSimpleName());
- }
-
private void enterExitVrMode(boolean supported) {
MockVrDaydreamApi mockApi = new MockVrDaydreamApi();
if (!supported) {
@@ -66,22 +78,23 @@ public class VrShellTest extends VrTestBase {
VrUtils.forceEnterVr();
if (supported) {
VrUtils.waitForVrSupported(POLL_TIMEOUT_LONG_MS);
- assertTrue(VrShellDelegate.isInVr());
+ Assert.assertTrue(VrShellDelegate.isInVr());
} else {
- assertFalse(mockApi.getLaunchInVrCalled());
- assertFalse(VrShellDelegate.isInVr());
+ Assert.assertFalse(mockApi.getLaunchInVrCalled());
+ Assert.assertFalse(VrShellDelegate.isInVr());
}
VrUtils.forceExitVr(mDelegate);
- assertFalse(VrShellDelegate.isInVr());
+ Assert.assertFalse(VrShellDelegate.isInVr());
}
private void enterExitVrModeImage(boolean supported) throws IOException {
- int prevOrientation = getActivity().getRequestedOrientation();
- getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- getInstrumentation().waitForIdleSync();
+ ChromeTabbedActivity activity = mActivityTestRule.getActivity();
+ int prevOrientation = activity.getRequestedOrientation();
+ mActivityTestRule.getActivity().setRequestedOrientation(
+ ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
mViewRenderer.renderAndCompare(
- getActivity().getWindow().getDecorView().getRootView(),
- "blank_page");
+ activity.getWindow().getDecorView().getRootView(), "blank_page");
VrUtils.forceEnterVr();
// Currently, screenshots only show the static UI overlay, not the
@@ -93,34 +106,31 @@ public class VrShellTest extends VrTestBase {
if (supported) {
VrUtils.waitForVrSupported(POLL_TIMEOUT_LONG_MS);
mViewRenderer.renderAndCompare(
- getActivity().getWindow().getDecorView().getRootView(),
- "vr_entered");
+ activity.getWindow().getDecorView().getRootView(), "vr_entered");
} else {
// TODO(bsheedy): Find a good way to wait before taking a screenshot
// when running on an unsupported device
mViewRenderer.renderAndCompare(
- getActivity().getWindow().getDecorView().getRootView(),
- "blank_page");
+ activity.getWindow().getDecorView().getRootView(), "blank_page");
}
VrUtils.forceExitVr(mDelegate);
- getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- getInstrumentation().waitForIdleSync();
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
mViewRenderer.renderAndCompare(
- getActivity().getWindow().getDecorView().getRootView(),
- "blank_page");
+ activity.getWindow().getDecorView().getRootView(), "blank_page");
- getActivity().setRequestedOrientation(prevOrientation);
+ activity.setRequestedOrientation(prevOrientation);
}
private void enterVrModeNfc(boolean supported) {
- getInstrumentation().waitForIdleSync();
- VrUtils.simNfc(getActivity());
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
+ VrUtils.simNfc(mActivityTestRule.getActivity());
if (supported) {
VrUtils.waitForVrSupported(POLL_TIMEOUT_LONG_MS);
- assertTrue(VrShellDelegate.isInVr());
+ Assert.assertTrue(VrShellDelegate.isInVr());
} else {
- assertFalse(VrShellDelegate.isInVr());
+ Assert.assertFalse(VrShellDelegate.isInVr());
}
VrUtils.forceExitVr(mDelegate);
// TODO(bsheedy): Figure out why NFC tests cause the next test to fail
@@ -133,6 +143,7 @@ public class VrShellTest extends VrTestBase {
* NFC tag is scanned on a Daydream-ready device. Requires that the phone
* is unlocked.
*/
+ @Test
@Restriction({RESTRICTION_TYPE_DEVICE_DAYDREAM, RESTRICTION_TYPE_VIEWER_DAYDREAM})
@MediumTest
public void testSimNfcSupported() {
@@ -143,6 +154,7 @@ public class VrShellTest extends VrTestBase {
* Verifies that the browser does not enter VR mode on Non-Daydream-ready
* devices when the Daydream headset NFC tag is scanned.
*/
+ @Test
@Restriction(RESTRICTION_TYPE_DEVICE_NON_DAYDREAM)
@SmallTest
public void testSimNfcUnsupported() {
@@ -153,6 +165,7 @@ public class VrShellTest extends VrTestBase {
* Verifies that browser successfully enters and exits VR mode when told to
* on Daydream-ready devices. Requires that the phone is unlocked.
*/
+ @Test
@Restriction(RESTRICTION_TYPE_DEVICE_DAYDREAM)
@SmallTest
public void testEnterExitVrModeSupported() {
@@ -162,6 +175,7 @@ public class VrShellTest extends VrTestBase {
/**
* Verifies that browser does not enter VR mode on Non-Daydream-ready devices.
*/
+ @Test
@Restriction(RESTRICTION_TYPE_DEVICE_NON_DAYDREAM)
@SmallTest
public void testEnterExitVrModeUnsupported() {
@@ -173,6 +187,7 @@ public class VrShellTest extends VrTestBase {
* on Daydream-ready devices via a screendiffing check.
* Requires that the phone is unlocked.
*/
+ @Test
@Restriction(RESTRICTION_TYPE_DEVICE_DAYDREAM)
@Feature("RenderTest")
@MediumTest
@@ -184,6 +199,7 @@ public class VrShellTest extends VrTestBase {
* Verifies that browser does not enter VR mode on Non-Daydream-ready devices
* via a screendiffing check. Requires that the phone is unlocked.
*/
+ @Test
@Restriction(RESTRICTION_TYPE_DEVICE_NON_DAYDREAM)
@Feature("RenderTest")
@MediumTest
@@ -197,6 +213,7 @@ public class VrShellTest extends VrTestBase {
* @throws InterruptedException
* @throws TimeoutException
*/
+ @Test
@SmallTest
@RetryOnFailure
public void testResizeWithCompositorViewHolderDetached()
@@ -204,13 +221,15 @@ public class VrShellTest extends VrTestBase {
final AtomicReference<TabModelSelector> selector = new AtomicReference<>();
final AtomicReference<Integer> oldWidth = new AtomicReference<>();
final int testWidth = 123;
- final ContentViewCore cvc = getActivity().getActivityTab().getActiveContentViewCore();
+ final ContentViewCore cvc =
+ mActivityTestRule.getActivity().getActivityTab().getActiveContentViewCore();
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
- CompositorViewHolder compositorViewHolder = (CompositorViewHolder)
- getActivity().findViewById(R.id.compositor_view_holder);
+ CompositorViewHolder compositorViewHolder =
+ (CompositorViewHolder) mActivityTestRule.getActivity().findViewById(
+ R.id.compositor_view_holder);
selector.set(compositorViewHolder.detachForVr());
oldWidth.set(cvc.getViewportWidthPix());
@@ -223,20 +242,22 @@ public class VrShellTest extends VrTestBase {
CriteriaHelper.pollUiThread(Criteria.equals(testWidth, new Callable<Integer>() {
@Override
public Integer call() {
- return getActivity().findViewById(R.id.compositor_view_holder).getMeasuredWidth();
+ return mActivityTestRule.getActivity()
+ .findViewById(R.id.compositor_view_holder)
+ .getMeasuredWidth();
}
}));
- assertEquals("Viewport width should not have changed when resizing a detached "
- + "CompositorViewHolder",
- cvc.getViewportWidthPix(),
- oldWidth.get().intValue());
+ Assert.assertEquals("Viewport width should not have changed when resizing a detached "
+ + "CompositorViewHolder",
+ cvc.getViewportWidthPix(), oldWidth.get().intValue());
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
- CompositorViewHolder compositorViewHolder = (CompositorViewHolder) getActivity()
- .findViewById(R.id.compositor_view_holder);
+ CompositorViewHolder compositorViewHolder =
+ (CompositorViewHolder) mActivityTestRule.getActivity().findViewById(
+ R.id.compositor_view_holder);
compositorViewHolder.onExitVr(selector.get());
}
});

Powered by Google App Engine
This is Rietveld 408576698