Commit f1e50fa5 authored by bsheedy's avatar bsheedy Committed by Commit Bot

Automate VR manual test for suggestion hovering

Automates a manual VR regression test that ensures that the hover state
and hit testing of search suggestions in the VR browser function
as expected.

In order to prevent the test from flaking due to the blinking
omnibox cursor, also adds the ability to crop images before comparing
them in via the RenderTestRule.

Bug: 887561
Change-Id: Ifddd18ff492b14bee08658251dc2191e7e481dcb
Reviewed-on: https://chromium-review.googlesource.com/c/1479550Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634828}
parent c49f8f01
...@@ -10,6 +10,7 @@ import static org.chromium.chrome.browser.vr.XrTestFramework.POLL_TIMEOUT_LONG_M ...@@ -10,6 +10,7 @@ import static org.chromium.chrome.browser.vr.XrTestFramework.POLL_TIMEOUT_LONG_M
import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_VIEWER_DAYDREAM_OR_STANDALONE; import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_VIEWER_DAYDREAM_OR_STANDALONE;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.RectF;
import android.os.SystemClock; import android.os.SystemClock;
import android.support.test.filters.LargeTest; import android.support.test.filters.LargeTest;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
...@@ -528,4 +529,68 @@ public class VrBrowserNativeUiTest { ...@@ -528,4 +529,68 @@ public class VrBrowserNativeUiTest {
private String generateRenderTestIdentifier(String name, boolean incognito) { private String generateRenderTestIdentifier(String name, boolean incognito) {
return name + (incognito ? "_incognito" : "") + "_browser_ui"; return name + (incognito ? "_incognito" : "") + "_browser_ui";
} }
/**
* Tests that highlighting suggestions looks correct and that clicking just outside of the
* suggestion doesn't trigger its onclick. Regression test for https://crbug.com/799593.
*/
@Test
@MediumTest
@Feature({"Browser", "RenderTest"})
public void testSuggestionHovering()
throws InterruptedException, TimeoutException, IOException {
// Input some text to get suggestions.
NativeUiUtils.enableMockedKeyboard();
NativeUiUtils.clickElementAndWaitForUiQuiescence(UserFriendlyElementName.URL, new PointF());
NativeUiUtils.performActionAndWaitForVisibilityStatus(
UserFriendlyElementName.SUGGESTION_BOX, true /* visible */,
() -> { NativeUiUtils.inputString("chrome://"); });
// We need to crop the image before comparing to avoid the blinking cursor in the omnibox.
// So, crop roughly around the suggestion box. This tends to chop off the bottom half of
// the bottom suggestion on larger devices, but that's preferable to accidentally getting
// the omnibox in the image, and should still be sufficient to catch the intended issues
// (hover states, clicks actually registering).
final RectF cropBounds = new RectF(0.1f, 0.4f, 0.6f, 0.625f);
// There should be three suggestions, so hover the top then the middle one to ensure that
// the hover effect properly moves between the two.
NativeUiUtils.hoverElement(UserFriendlyElementName.SUGGESTION_BOX, new PointF(0.0f, 0.3f));
NativeUiUtils.waitForUiQuiescence();
RenderTestUtils.dumpAndCompareWithCrop(NativeUiUtils.FRAME_BUFFER_SUFFIX_BROWSER_UI,
"suggestion_hovering_top", cropBounds, mRenderTestRule);
NativeUiUtils.hoverElement(UserFriendlyElementName.SUGGESTION_BOX, new PointF());
NativeUiUtils.waitForUiQuiescence();
RenderTestUtils.dumpAndCompareWithCrop(NativeUiUtils.FRAME_BUFFER_SUFFIX_BROWSER_UI,
"suggestion_hovering_middle", cropBounds, mRenderTestRule);
// Ensure that the hover effect disappears when slightly to the right of the suggestion and
// that clicking doesn't do anything.
NativeUiUtils.clickElementAndWaitForUiQuiescence(
UserFriendlyElementName.SUGGESTION_BOX, new PointF(0.51f, 0.0f));
RenderTestUtils.dumpAndCompareWithCrop(NativeUiUtils.FRAME_BUFFER_SUFFIX_BROWSER_UI,
"suggestion_clicking_right", cropBounds, mRenderTestRule);
// Again on the left side.
NativeUiUtils.hoverElement(UserFriendlyElementName.SUGGESTION_BOX, new PointF());
NativeUiUtils.clickElementAndWaitForUiQuiescence(
UserFriendlyElementName.SUGGESTION_BOX, new PointF(-0.51f, 0.0f));
RenderTestUtils.dumpAndCompareWithCrop(NativeUiUtils.FRAME_BUFFER_SUFFIX_BROWSER_UI,
"suggestion_clicking_left", cropBounds, mRenderTestRule);
// Again above the top suggestion.
NativeUiUtils.hoverElement(UserFriendlyElementName.SUGGESTION_BOX, new PointF(0.0f, 0.3f));
NativeUiUtils.clickElementAndWaitForUiQuiescence(
UserFriendlyElementName.SUGGESTION_BOX, new PointF(0.0f, 0.51f));
RenderTestUtils.dumpAndCompareWithCrop(NativeUiUtils.FRAME_BUFFER_SUFFIX_BROWSER_UI,
"suggestion_clicking_top", cropBounds, mRenderTestRule);
// Again below the bottom suggestion.
NativeUiUtils.hoverElement(UserFriendlyElementName.SUGGESTION_BOX, new PointF(0.0f, -0.3f));
// For some reason, we have to aim slightly more offset than in other directions in order
// to not actually hit the suggestion (probably due to the way we calculate where to click
// not taking into account where the controller is, so hit testing can produce a slightly
// different result).
NativeUiUtils.clickElementAndWaitForUiQuiescence(
UserFriendlyElementName.SUGGESTION_BOX, new PointF(0.0f, -0.55f));
RenderTestUtils.dumpAndCompareWithCrop(NativeUiUtils.FRAME_BUFFER_SUFFIX_BROWSER_UI,
"suggestion_clicking_bottom", cropBounds, mRenderTestRule);
}
} }
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.vr.util; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.vr.util;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.RectF;
import org.junit.Assert; import org.junit.Assert;
...@@ -34,9 +35,18 @@ public class RenderTestUtils { ...@@ -34,9 +35,18 @@ public class RenderTestUtils {
*/ */
public static void dumpAndCompare(String suffix, String id, RenderTestRule rule) public static void dumpAndCompare(String suffix, String id, RenderTestRule rule)
throws IOException, InterruptedException { throws IOException, InterruptedException {
dumpAndCompareWithCrop(suffix, id, null /* bounds */, rule);
}
/**
* Helper function for running the general dumpAndCompare when only one image needs to be
* compared and it needs to be cropped before comparing.
*/
public static void dumpAndCompareWithCrop(String suffix, String id, RectF bounds,
RenderTestRule rule) throws IOException, InterruptedException {
HashMap<String, String> suffixToId = new HashMap<String, String>(); HashMap<String, String> suffixToId = new HashMap<String, String>();
suffixToId.put(suffix, id); suffixToId.put(suffix, id);
dumpAndCompare(suffixToId, rule); dumpAndCompare(suffixToId, bounds, rule);
} }
/** /**
...@@ -45,10 +55,12 @@ public class RenderTestUtils { ...@@ -45,10 +55,12 @@ public class RenderTestUtils {
* *
* @param suffixToIds a map from framebuffer suffixes from NativeUiUtils to RenderTest image * @param suffixToIds a map from framebuffer suffixes from NativeUiUtils to RenderTest image
* IDs. * IDs.
* @param bounds a RectF defining the bounds [0, 1] with the origin in the top left corner to
* crop the image to before comparing. Pass null to not crop.
* @param rule the RenderTestRule to use for comparing images. * @param rule the RenderTestRule to use for comparing images.
*/ */
public static void dumpAndCompare(HashMap<String, String> suffixToIds, RenderTestRule rule) public static void dumpAndCompare(HashMap<String, String> suffixToIds, RectF bounds,
throws IOException, InterruptedException { RenderTestRule rule) throws IOException, InterruptedException {
File dumpDirectory = new File(UrlUtils.getIsolatedTestFilePath(IMAGE_DUMP_DIR)); File dumpDirectory = new File(UrlUtils.getIsolatedTestFilePath(IMAGE_DUMP_DIR));
if (!dumpDirectory.exists() && !dumpDirectory.isDirectory()) { if (!dumpDirectory.exists() && !dumpDirectory.isDirectory()) {
Assert.assertTrue("Failed to make framebuffer dump directory", dumpDirectory.mkdirs()); Assert.assertTrue("Failed to make framebuffer dump directory", dumpDirectory.mkdirs());
...@@ -66,6 +78,27 @@ public class RenderTestUtils { ...@@ -66,6 +78,27 @@ public class RenderTestUtils {
options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(filepath, options); Bitmap bitmap = BitmapFactory.decodeFile(filepath, options);
// Crop the image if necessary
if (bounds != null) {
Assert.assertTrue(
"Given left bound is not in [0, 1)", bounds.left >= 0 && bounds.left < 1);
Assert.assertTrue("Given right bound is not in (0, 1]",
bounds.right > 0 && bounds.right <= 1);
Assert.assertTrue(
"Given horizontal bounds are not valid", bounds.left < bounds.right);
Assert.assertTrue(
"Given top bound is not in [0, 1)", bounds.top >= 0 && bounds.top < 1);
Assert.assertTrue("Given bottom bound is not in (0, 1]",
bounds.bottom > 0 && bounds.bottom <= 1);
Assert.assertTrue(
"Given vertical bounds are not valid", bounds.top < bounds.bottom);
bitmap = Bitmap.createBitmap(bitmap, (int) (bounds.left * bitmap.getWidth()),
(int) (bounds.top * bitmap.getHeight()),
(int) (bounds.width() * bitmap.getWidth()),
(int) (bounds.height() * bitmap.getHeight()));
}
// The browser UI dump contains both eyes rendered, which is unnecessary for comparing // The browser UI dump contains both eyes rendered, which is unnecessary for comparing
// since any difference in one should show up in the other. So, take the left half of // since any difference in one should show up in the other. So, take the left half of
// the image to get the left eye, which reduces the amount of space the image takes up. // the image to get the left eye, which reduces the amount of space the image takes up.
......
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