Commit c7b73e44 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Allow injecting input directly into r.id.content for DOMUtils.

This works around an issue where DOMUtils injects its input through the
rootView (view.getRootView()), which causes the input to be swallowed
by the GvrLayout in VR (this is because in VR, screen touches are used
for headset alignment rather than user input).

DOMUtils clicks will optionally get injected directly into r.id.content
rather than the root of the view hierarchy.

We need to inject into r.id.content, rather that cvc.getContainerView()
because the CompositorViewHolder needs to be able to intercept the
events to correctly set the EventForwarder offsets. Gross.

Bug: 804808
Change-Id: I6b246262d1e7b64437382b67db0a0d10518ee839
Reviewed-on: https://chromium-review.googlesource.com/884010
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532940}
parent f25d6c05
......@@ -20,7 +20,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Restriction;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.browser.ChromeSwitches;
......@@ -145,7 +144,6 @@ public class VrShellControllerInputTest {
* fullscreen
*/
@Test
@DisabledTest(message = "crbug.com/804808")
@MediumTest
@RetryOnFailure(message = "Very rarely, button press not registered (race condition?)")
public void testAppButtonExitsFullscreen() throws InterruptedException, TimeoutException {
......@@ -154,7 +152,8 @@ public class VrShellControllerInputTest {
VrTransitionUtils.forceEnterVr();
VrTransitionUtils.waitForVrEntry(POLL_TIMEOUT_LONG_MS);
// Enter fullscreen
DOMUtils.clickNode(mVrTestFramework.getFirstTabCvc(), "fullscreen");
DOMUtils.clickNode(mVrTestFramework.getFirstTabCvc(), "fullscreen",
false /* goThroughRootAndroidView */);
VrTestFramework.waitOnJavaScriptStep(mVrTestFramework.getFirstTabWebContents());
Assert.assertTrue(DOMUtils.isFullscreen(mVrTestFramework.getFirstTabWebContents()));
......
......@@ -22,7 +22,6 @@ import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.UrlConstants;
......@@ -105,7 +104,7 @@ public class VrShellNavigationTest {
private void enterFullscreenOrFail(ContentViewCore cvc)
throws InterruptedException, TimeoutException {
DOMUtils.clickNode(cvc, "fullscreen");
DOMUtils.clickNode(cvc, "fullscreen", false /* goThroughRootAndroidView */);
VrTestFramework.waitOnJavaScriptStep(cvc.getWebContents());
Assert.assertTrue(DOMUtils.isFullscreen(cvc.getWebContents()));
}
......@@ -179,7 +178,6 @@ public class VrShellNavigationTest {
* Tests navigation from a fullscreened 2D to a WebVR page.
*/
@Test
@DisabledTest(message = "crbug.com/804808")
@MediumTest
public void test2dFullscreenToWebVr()
throws IllegalArgumentException, InterruptedException, TimeoutException {
......@@ -228,7 +226,6 @@ public class VrShellNavigationTest {
* Tests navigation from a presenting WebVR to a 2D page.
*/
@Test
@DisabledTest(message = "crbug.com/804808")
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
public void testWebVrPresentingTo2d()
......@@ -246,7 +243,6 @@ public class VrShellNavigationTest {
* Tests navigation from a presenting WebVR to a WebVR page.
*/
@Test
@DisabledTest(message = "crbug.com/804808")
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
public void testWebVrPresentingToWebVr()
......@@ -264,7 +260,6 @@ public class VrShellNavigationTest {
* Tests navigation from a fullscreened WebVR to a 2D page.
*/
@Test
@DisabledTest(message = "crbug.com/804808")
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
public void testWebVrFullscreenTo2d()
......@@ -282,7 +277,6 @@ public class VrShellNavigationTest {
* Tests navigation from a fullscreened WebVR to a WebVR page.
*/
@Test
@DisabledTest(message = "crbug.com/804808")
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
public void testWebVrFullscreenToWebVr()
......
......@@ -24,7 +24,6 @@ import org.junit.runner.RunWith;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Restriction;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.browser.ChromeSwitches;
......@@ -194,7 +193,6 @@ public class VrShellTransitionTest {
*/
@Test
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
@DisabledTest(message = "crbug.com/804808")
@MediumTest
public void testExitFullscreenAfterExitingVrFromCinemaMode()
throws InterruptedException, TimeoutException {
......@@ -202,7 +200,8 @@ public class VrShellTransitionTest {
VrTransitionUtils.waitForVrEntry(POLL_TIMEOUT_LONG_MS);
mVrTestFramework.loadUrlAndAwaitInitialization(
VrTestFramework.getHtmlTestFile("test_navigation_2d_page"), PAGE_LOAD_TIMEOUT_S);
DOMUtils.clickNode(mVrTestFramework.getFirstTabCvc(), "fullscreen");
DOMUtils.clickNode(mVrTestFramework.getFirstTabCvc(), "fullscreen",
false /* goThroughRootAndroidView */);
VrTestFramework.waitOnJavaScriptStep(mVrTestFramework.getFirstTabWebContents());
Assert.assertTrue(DOMUtils.isFullscreen(mVrTestFramework.getFirstTabWebContents()));
......@@ -226,7 +225,6 @@ public class VrShellTransitionTest {
* from WebVR presentation to the VR browser.
*/
@Test
@DisabledTest(message = "crbug.com/804808")
@CommandLineFlags.Add("enable-webvr")
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
@MediumTest
......@@ -263,7 +261,6 @@ public class VrShellTransitionTest {
@Test
@CommandLineFlags.Add("enable-webvr")
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
@DisabledTest(message = "crbug.com/804808")
@MediumTest
public void testWebVrReEntryFromVrBrowser() throws InterruptedException, TimeoutException {
VrTransitionUtils.forceEnterVr();
......
......@@ -96,7 +96,7 @@ public class TransitionUtils {
*/
public static void enterPresentation(ContentViewCore cvc) {
try {
DOMUtils.clickNode(cvc, "webgl-canvas");
DOMUtils.clickNode(cvc, "webgl-canvas", false /* goThroughRootAndroidView */);
} catch (InterruptedException | TimeoutException e) {
Assert.fail("Failed to click canvas to enter presentation: " + e.toString());
}
......
......@@ -8,6 +8,7 @@ import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
import android.graphics.Rect;
import android.util.JsonReader;
import android.view.View;
import org.junit.Assert;
......@@ -233,10 +234,32 @@ public class DOMUtils {
*/
public static boolean clickNode(final ContentViewCore viewCore, String nodeId)
throws InterruptedException, TimeoutException {
return clickNode(viewCore, nodeId, true /* goThroughRootAndroidView */);
}
/**
* Click a DOM node by its id, scrolling it into view first.
* @param viewCore The ContentViewCore in which the node lives.
* @param nodeId The id of the node.
* @param goThroughRootAndroidView Whether the input should be routed through the Root View for
* the CVC.
*/
public static boolean clickNode(final ContentViewCore viewCore, String nodeId,
boolean goThroughRootAndroidView) throws InterruptedException, TimeoutException {
scrollNodeIntoView(viewCore.getWebContents(), nodeId);
int[] clickTarget = getClickTargetForNode(viewCore, nodeId);
return TouchCommon.singleClickView(
viewCore.getContainerView(), clickTarget[0], clickTarget[1]);
if (goThroughRootAndroidView) {
return TouchCommon.singleClickView(
viewCore.getContainerView(), clickTarget[0], clickTarget[1]);
} else {
// TODO(mthiesse): It should be sufficient to use viewCore.getContainerView() here
// directly, but content offsets are only updated in the EventForwarder when the
// CompositorViewHolder intercepts touch events.
View target =
viewCore.getContainerView().getRootView().findViewById(android.R.id.content);
return TouchCommon.singleClickViewThroughTarget(
viewCore.getContainerView(), target, clickTarget[0], clickTarget[1]);
}
}
/**
......@@ -256,8 +279,7 @@ public class DOMUtils {
* @param viewCore The ContentViewCore in which the node lives.
* @param rect The rect to click.
*/
public static boolean clickRect(final ContentViewCore viewCore, Rect rect)
throws InterruptedException, TimeoutException {
public static boolean clickRect(final ContentViewCore viewCore, Rect rect) {
int[] clickTarget = getClickTargetForBounds(viewCore, rect);
return TouchCommon.singleClickView(
viewCore.getContainerView(), clickTarget[0], clickTarget[1]);
......@@ -280,7 +302,7 @@ public class DOMUtils {
* <p>Note that content view should be located in the current position for a foreseeable
* amount of time because this involves sleep to simulate touch to long press transition.
* @param viewCore The ContentViewCore in which the node lives.
* @param nodeId The id of the node.
* @param jsCode js code that returns an element.
*/
public static void longPressNodeByJs(final ContentViewCore viewCore, String jsCode)
throws InterruptedException, TimeoutException {
......
......@@ -109,10 +109,26 @@ public class TouchCommon {
* @param y Y coordinate, relative to v.
*/
public static boolean singleClickView(View v, int x, int y) {
int windowXY[] = viewToWindowCoordinates(v, x, y);
return singleClickViewThroughTarget(v, v.getRootView(), x, y);
}
/**
* Sends a click event to the specified view, not going through the root view.
*
* This is mostly useful for tests in VR, where inputs to the root view are (in a sense)
* consumed by the platform, but the java test still wants to interact with, say, WebContents.
*
* @param view The view to be clicked.
* @param target The view to inject the input into.
* @param x X coordinate, relative to view.
* @param y Y coordinate, relative to view.
*/
/* package */ static boolean singleClickViewThroughTarget(
View view, View target, int x, int y) {
int windowXY[] = viewToWindowCoordinates(view, x, y);
int windowX = windowXY[0];
int windowY = windowXY[1];
return singleClickInternal(v.getRootView(), windowX, windowY);
return singleClickInternal(target, windowX, windowY);
}
/**
......
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