Commit 63142332 authored by bsheedy's avatar bsheedy Committed by Commit bot

Add VR Shell image diff instrumentation tests

Adds basic image diffing capabilities to the VR Shell instrumentation tests
and adds image diffing versions of the enter/exit VR mode tests. Will require
adding new reference images as more devices with different resolutions are
tested (currently only has 2560 x 1440).

BUG=

Review-Url: https://codereview.chromium.org/2455683002
Cr-Commit-Position: refs/heads/master@{#435038}
parent 916f5ba0
......@@ -7,18 +7,25 @@ package org.chromium.chrome.browser.vr_shell;
import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_DAYDREAM;
import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_NON_DAYDREAM;
import android.os.SystemClock;
import android.content.pm.ActivityInfo;
import android.test.suitebuilder.annotation.MediumTest;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
import org.chromium.chrome.test.util.RenderUtils.ViewRenderer;
import java.io.IOException;
/**
* Instrumentation tests for VR Shell (Chrome VR)
*/
public class VrShellTest extends ChromeTabbedActivityTestBase {
private static final String GOLDEN_DIR =
"chrome/test/data/android/render_tests";
private VrShellDelegate mDelegate;
private ViewRenderer mViewRenderer;
@Override
protected void setUp() throws Exception {
......@@ -29,6 +36,8 @@ public class VrShellTest extends ChromeTabbedActivityTestBase {
@Override
public void startMainActivity() throws InterruptedException {
startMainActivityOnBlankPage();
mViewRenderer = new ViewRenderer(getActivity(),
GOLDEN_DIR, this.getClass().getSimpleName());
}
private void forceEnterVr() {
......@@ -51,8 +60,7 @@ public class VrShellTest extends ChromeTabbedActivityTestBase {
private void testEnterExitVrMode(boolean supported) {
forceEnterVr();
// TODO(bsheedy): Remove sleep once crbug.com/644533 is fixed
SystemClock.sleep(1500);
getInstrumentation().waitForIdleSync();
if (supported) {
assertTrue(mDelegate.isInVR());
} else {
......@@ -62,6 +70,42 @@ public class VrShellTest extends ChromeTabbedActivityTestBase {
assertFalse(mDelegate.isInVR());
}
private void testEnterExitVrModeImage(boolean supported) throws IOException {
int prevOrientation = getActivity().getRequestedOrientation();
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
getInstrumentation().waitForIdleSync();
mViewRenderer.renderAndCompare(
getActivity().getWindow().getDecorView().getRootView(),
"blank_page");
forceEnterVr();
getInstrumentation().waitForIdleSync();
// Currently, screenshots only show the static UI overlay, not the
// actual content. Thus, 1:1 pixel checking is reliable until a
// way to take screenshots of VR content is added, in which case
// % similarity or some other method will need to be used. We're
// assuming that if the UI overlay is visible, then the device has
// successfully entered VR mode.
if (supported) {
mViewRenderer.renderAndCompare(
getActivity().getWindow().getDecorView().getRootView(),
"vr_entered");
} else {
mViewRenderer.renderAndCompare(
getActivity().getWindow().getDecorView().getRootView(),
"blank_page");
}
forceExitVr();
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
getInstrumentation().waitForIdleSync();
mViewRenderer.renderAndCompare(
getActivity().getWindow().getDecorView().getRootView(),
"blank_page");
getActivity().setRequestedOrientation(prevOrientation);
}
/**
* Verifies that browser successfully enters and exits VR mode when told to
* on Daydream-ready devices. Requires that the phone is unlocked.
......@@ -80,4 +124,27 @@ public class VrShellTest extends ChromeTabbedActivityTestBase {
public void testEnterExitVrModeUnsupported() {
testEnterExitVrMode(false);
}
/**
* Verifies that browser successfully enters and exits VR mode when told to
* on Daydream-ready devices via a screendiffing check.
* Requires that the phone is unlocked.
*/
@Restriction(RESTRICTION_TYPE_DAYDREAM)
@Feature("RenderTest")
@MediumTest
public void testEnterExitVrModeSupportedImage() throws IOException {
testEnterExitVrModeImage(true);
}
/**
* Verifies that browser does not enter VR mode on Non-Daydream-ready devices
* via a screendiffing check. Requires that the phone is unlocked.
*/
@Restriction(RESTRICTION_TYPE_NON_DAYDREAM)
@Feature("RenderTest")
@MediumTest
public void testEnterExitVrModeUnsupportedImage() throws IOException {
testEnterExitVrModeImage(false);
}
}
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