Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2657)

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/ContentViewPointerIconTest.java

Issue 2878403002: Support setting mouse cursor icon in Android N. (Closed)
Patch Set: Support setting mouse cursor icon in Android N Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..440dce9e860a7b92685c995671f0c296557baa46
--- /dev/null
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewPointerIconTest.java
@@ -0,0 +1,98 @@
+// 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.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.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.Criteria;
+import org.chromium.content.browser.test.util.CriteriaHelper;
+import org.chromium.content_shell_apk.ContentShellTestBase;
+
+/**
+ * Tests that we can move mouse cursor and test cursor icon.
+ */
+@MinAndroidSdkLevel(Build.VERSION_CODES.N)
+@TargetApi(Build.VERSION_CODES.N)
+public class ContentViewPointerIconTest extends ContentShellTestBase {
+ private static final String CURSOR_PAGE = UrlUtils.encodeHtmlDataUri("<html>"
+ + "<style>div { height: 60px; }</style>"
+ + "<body><div><a href=\"about:blank\">pointer</a></div>"
+ + "<div>text</div>"
+ + "<div style=\"cursor:help;\">help</div></body>"
+ + "</html>");
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ launchContentShellWithUrl(CURSOR_PAGE);
+ waitForActiveShellToBeDoneLoading();
+ }
+
+ private void assertWaitForPointerIcon(final int type) {
+ CriteriaHelper.pollInstrumentationThread(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ PointerIcon currentPointerIcon =
+ getContentViewCore().getContainerView().getPointerIcon();
+ Context context = getInstrumentationForTestCommon().getContext();
+ return currentPointerIcon != null
+ && currentPointerIcon.equals(PointerIcon.getSystemIcon(context, type));
+ }
+ });
+ }
+
+ private void moveCursor(final float deltaAxisX, final float deltaAxisY) 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 = deltaAxisX;
+ pc.y = deltaAxisY;
+ 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);
+ }
+ });
+ }
+
+ @SmallTest
+ @Feature({"Main"})
+ public void testPointerIcon() throws Throwable {
+ moveCursor(11.0f, 20.0f);
boliu 2017/05/30 21:30:02 how are you getting these coordinates? in general
jaebaek 2017/05/31 13:29:08 Done.
+ assertWaitForPointerIcon(PointerIcon.TYPE_HAND);
+ Thread.sleep(20);
boliu 2017/05/30 21:30:02 no sleeps, you are polling already. do you really
jaebaek 2017/05/31 13:29:08 Done.
+
+ moveCursor(11.0f, 90.0f);
+ assertWaitForPointerIcon(PointerIcon.TYPE_TEXT);
+ Thread.sleep(20);
+
+ moveCursor(11.0f, 160.0f);
+ assertWaitForPointerIcon(PointerIcon.TYPE_HELP);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698