Index: content/public/android/javatests/src/org/chromium/content/browser/ContentViewPointerIconTest.java |
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ContentViewPointerIconTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewPointerIconTest.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..edeca0382c1aaf8b25f8a0ee82b669a28fcd9f7f |
--- /dev/null |
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewPointerIconTest.java |
@@ -0,0 +1,106 @@ |
+// 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.annotation.TargetApi; |
+import android.content.Context; |
+import android.graphics.Rect; |
+import android.os.Build; |
+import android.os.SystemClock; |
+import android.support.test.filters.SmallTest; |
+import android.view.InputDevice; |
+import android.view.MotionEvent; |
+import android.view.PointerIcon; |
+ |
+import org.junit.Assert; |
+ |
+import org.chromium.base.test.util.CallbackHelper; |
+import org.chromium.base.test.util.Feature; |
+import org.chromium.base.test.util.MinAndroidSdkLevel; |
+import org.chromium.base.test.util.UrlUtils; |
+import org.chromium.content.browser.test.util.DOMUtils; |
+import org.chromium.content_shell_apk.ContentShellTestBase; |
+ |
+/** |
+ * Tests that we can move mouse cursor and test cursor icon. |
+ */ |
+@MinAndroidSdkLevel(Build.VERSION_CODES.N) |
boliu
2017/05/31 16:30:03
which part of this test requires N specifically?
jaebaek
2017/06/01 06:20:56
I am sorry but this is still unclear ..
Even thoug
boliu
2017/06/01 16:14:50
Just check WebCursorInfoType in ViewAndroidDelegat
|
+@TargetApi(Build.VERSION_CODES.N) |
+public class ContentViewPointerIconTest extends ContentShellTestBase { |
boliu
2017/05/31 16:32:47
also, most of content test have already been conve
jaebaek
2017/06/01 06:20:56
Done.
|
+ private final CallbackHelper mOnCursorUpdateHelper = new CallbackHelper(); |
+ |
+ 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>"); |
+ |
+ @Override |
+ protected void setUp() throws Exception { |
+ super.setUp(); |
+ |
+ launchContentShellWithUrl(CURSOR_PAGE); |
+ waitForActiveShellToBeDoneLoading(); |
+ } |
+ |
+ private void assertPointerIcon(final int type) { |
+ PointerIcon currentPointerIcon = getContentViewCore().getContainerView().getPointerIcon(); |
+ Context context = getInstrumentationForTestCommon().getContext(); |
+ Assert.assertEquals(currentPointerIcon, PointerIcon.getSystemIcon(context, type)); |
+ } |
+ |
+ private void moveCursor(final float x, final float y) throws Throwable { |
+ runTestOnUiThread(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); |
+ getContentViewCore().getContainerView().dispatchGenericMotionEvent(cursorMoveEvent); |
+ } |
+ }); |
+ } |
+ |
+ private void checkPointerIconForNode(final String nodeId, final int type) throws Throwable { |
+ Rect rect = DOMUtils.getNodeBounds(getWebContents(), nodeId); |
+ float x = (float) (rect.left + rect.right) / 2.0f; |
+ float y = (float) (rect.top + rect.bottom) / 2.0f; |
+ |
+ int onCursorUpdateCount = mOnCursorUpdateHelper.getCallCount(); |
+ moveCursor(x, y); |
+ mOnCursorUpdateHelper.waitForCallback(onCursorUpdateCount); |
+ assertPointerIcon(type); |
+ } |
+ |
+ @SmallTest |
+ @Feature({"Main"}) |
+ public void testPointerIcon() throws Throwable { |
+ setCursorUpdateCallback(new Runnable() { |
+ @Override |
+ public void run() { |
+ mOnCursorUpdateHelper.notifyCalled(); |
+ } |
+ }); |
+ |
+ checkPointerIconForNode("hand", PointerIcon.TYPE_HAND); |
+ checkPointerIconForNode("text", PointerIcon.TYPE_TEXT); |
+ checkPointerIconForNode("help", PointerIcon.TYPE_HELP); |
+ } |
+} |