| Index: content/public/android/javatests/src/org/chromium/content/browser/ContentViewPointerTypeTest.java
|
| diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ContentViewPointerTypeTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewPointerTypeTest.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f7efabc08a91a540df59bb5b14e5f634d1c477f3
|
| --- /dev/null
|
| +++ b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewPointerTypeTest.java
|
| @@ -0,0 +1,96 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.content.browser;
|
| +
|
| +import android.graphics.Rect;
|
| +import android.os.SystemClock;
|
| +import android.support.test.filters.SmallTest;
|
| +import android.view.InputDevice;
|
| +import android.view.MotionEvent;
|
| +
|
| +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.Feature;
|
| +import org.chromium.base.test.util.UrlUtils;
|
| +import org.chromium.blink_public.web.WebCursorInfoType;
|
| +import org.chromium.content.browser.test.ContentJUnit4ClassRunner;
|
| +import org.chromium.content.browser.test.util.DOMUtils;
|
| +import org.chromium.content_shell.ShellViewAndroidDelegate.OnCursorUpdateHelper;
|
| +import org.chromium.content_shell_apk.ContentShellActivityTestRule;
|
| +
|
| +/**
|
| + * Tests that we can move mouse cursor and test cursor icon.
|
| + */
|
| +@RunWith(ContentJUnit4ClassRunner.class)
|
| +public class ContentViewPointerTypeTest {
|
| + @Rule
|
| + public ContentShellActivityTestRule mActivityTestRule = new ContentShellActivityTestRule();
|
| +
|
| + private static final String CURSOR_PAGE = UrlUtils.encodeHtmlDataUri("<html>"
|
| + + "<body><a id=\"hand\" href=\"about:blank\">pointer</a>"
|
| + + "<span id=\"text\">text</span>"
|
| + + "<span id=\"help\" style=\"cursor:help;\">help</span></body>"
|
| + + "</html>");
|
| +
|
| + @Before
|
| + public void setUp() throws Exception {
|
| + mActivityTestRule.launchContentShellWithUrl(CURSOR_PAGE);
|
| + mActivityTestRule.waitForActiveShellToBeDoneLoading();
|
| + }
|
| +
|
| + private void moveCursor(final float x, final float y) throws Throwable {
|
| + mActivityTestRule.runOnUiThreadForTestCommon(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + MotionEvent.PointerProperties[] pointerProperties =
|
| + new MotionEvent.PointerProperties[1];
|
| + MotionEvent.PointerProperties pp = new MotionEvent.PointerProperties();
|
| + pp.id = 0;
|
| + pp.toolType = MotionEvent.TOOL_TYPE_MOUSE;
|
| + pointerProperties[0] = pp;
|
| +
|
| + MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[1];
|
| + MotionEvent.PointerCoords pc = new MotionEvent.PointerCoords();
|
| + pc.x = x;
|
| + pc.y = y;
|
| + pointerCoords[0] = pc;
|
| +
|
| + MotionEvent cursorMoveEvent = MotionEvent.obtain(SystemClock.uptimeMillis(),
|
| + SystemClock.uptimeMillis() + 1, MotionEvent.ACTION_HOVER_MOVE, 1,
|
| + pointerProperties, pointerCoords, 0, 0, 1.0f, 1.0f, 0, 0,
|
| + InputDevice.SOURCE_MOUSE, 0);
|
| + cursorMoveEvent.setSource(InputDevice.SOURCE_MOUSE);
|
| + mActivityTestRule.getContentViewCore()
|
| + .getContainerView()
|
| + .dispatchGenericMotionEvent(cursorMoveEvent);
|
| + }
|
| + });
|
| + }
|
| +
|
| + private void checkPointerTypeForNode(final String nodeId, final int type) throws Throwable {
|
| + Rect rect = DOMUtils.getNodeBounds(mActivityTestRule.getWebContents(), nodeId);
|
| + float x = (float) (rect.left + rect.right) / 2.0f;
|
| + float y = (float) (rect.top + rect.bottom) / 2.0f;
|
| +
|
| + OnCursorUpdateHelper onCursorUpdateHelper = mActivityTestRule.getOnCursorUpdateHelper();
|
| + int onCursorUpdateCount = onCursorUpdateHelper.getCallCount();
|
| + moveCursor(x, y);
|
| + onCursorUpdateHelper.waitForCallback(onCursorUpdateCount);
|
| + Assert.assertEquals(type, onCursorUpdateHelper.getPointerType());
|
| + }
|
| +
|
| + @Test
|
| + @SmallTest
|
| + @Feature({"Main"})
|
| + public void testPointerType() throws Throwable {
|
| + checkPointerTypeForNode("hand", WebCursorInfoType.TYPE_HAND);
|
| + checkPointerTypeForNode("text", WebCursorInfoType.TYPE_I_BEAM);
|
| + checkPointerTypeForNode("help", WebCursorInfoType.TYPE_HELP);
|
| + }
|
| +}
|
|
|