Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.content.browser; | |
| 6 | |
| 7 import android.annotation.TargetApi; | |
| 8 import android.content.Context; | |
| 9 import android.graphics.Rect; | |
| 10 import android.os.Build; | |
| 11 import android.os.SystemClock; | |
| 12 import android.support.test.filters.SmallTest; | |
| 13 import android.view.InputDevice; | |
| 14 import android.view.MotionEvent; | |
| 15 import android.view.PointerIcon; | |
| 16 | |
| 17 import org.junit.Assert; | |
| 18 | |
| 19 import org.chromium.base.test.util.CallbackHelper; | |
| 20 import org.chromium.base.test.util.Feature; | |
| 21 import org.chromium.base.test.util.MinAndroidSdkLevel; | |
| 22 import org.chromium.base.test.util.UrlUtils; | |
| 23 import org.chromium.content.browser.test.util.DOMUtils; | |
| 24 import org.chromium.content_shell_apk.ContentShellTestBase; | |
| 25 | |
| 26 /** | |
| 27 * Tests that we can move mouse cursor and test cursor icon. | |
| 28 */ | |
| 29 @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
| |
| 30 @TargetApi(Build.VERSION_CODES.N) | |
| 31 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.
| |
| 32 private final CallbackHelper mOnCursorUpdateHelper = new CallbackHelper(); | |
| 33 | |
| 34 private static final String CURSOR_PAGE = UrlUtils.encodeHtmlDataUri("<html> " | |
| 35 + "<body><a id=\"hand\" href=\"about:blank\">pointer</a>" | |
| 36 + "<span id=\"text\">text</span>" | |
| 37 + "<span id=\"help\" style=\"cursor:help;\">help</span></body>" | |
| 38 + "</html>"); | |
| 39 | |
| 40 @Override | |
| 41 protected void setUp() throws Exception { | |
| 42 super.setUp(); | |
| 43 | |
| 44 launchContentShellWithUrl(CURSOR_PAGE); | |
| 45 waitForActiveShellToBeDoneLoading(); | |
| 46 } | |
| 47 | |
| 48 private void assertPointerIcon(final int type) { | |
| 49 PointerIcon currentPointerIcon = getContentViewCore().getContainerView() .getPointerIcon(); | |
| 50 Context context = getInstrumentationForTestCommon().getContext(); | |
| 51 Assert.assertEquals(currentPointerIcon, PointerIcon.getSystemIcon(contex t, type)); | |
| 52 } | |
| 53 | |
| 54 private void moveCursor(final float x, final float y) throws Throwable { | |
| 55 runTestOnUiThread(new Runnable() { | |
| 56 @Override | |
| 57 public void run() { | |
| 58 MotionEvent.PointerProperties[] pointerProperties = | |
| 59 new MotionEvent.PointerProperties[1]; | |
| 60 MotionEvent.PointerProperties pp = new MotionEvent.PointerProper ties(); | |
| 61 pp.id = 0; | |
| 62 pp.toolType = MotionEvent.TOOL_TYPE_MOUSE; | |
| 63 pointerProperties[0] = pp; | |
| 64 | |
| 65 MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.Poin terCoords[1]; | |
| 66 MotionEvent.PointerCoords pc = new MotionEvent.PointerCoords(); | |
| 67 pc.x = x; | |
| 68 pc.y = y; | |
| 69 pointerCoords[0] = pc; | |
| 70 | |
| 71 MotionEvent cursorMoveEvent = MotionEvent.obtain(SystemClock.upt imeMillis(), | |
| 72 SystemClock.uptimeMillis() + 1, MotionEvent.ACTION_HOVER _MOVE, 1, | |
| 73 pointerProperties, pointerCoords, 0, 0, 1.0f, 1.0f, 0, 0 , | |
| 74 InputDevice.SOURCE_MOUSE, 0); | |
| 75 cursorMoveEvent.setSource(InputDevice.SOURCE_MOUSE); | |
| 76 getContentViewCore().getContainerView().dispatchGenericMotionEve nt(cursorMoveEvent); | |
| 77 } | |
| 78 }); | |
| 79 } | |
| 80 | |
| 81 private void checkPointerIconForNode(final String nodeId, final int type) th rows Throwable { | |
| 82 Rect rect = DOMUtils.getNodeBounds(getWebContents(), nodeId); | |
| 83 float x = (float) (rect.left + rect.right) / 2.0f; | |
| 84 float y = (float) (rect.top + rect.bottom) / 2.0f; | |
| 85 | |
| 86 int onCursorUpdateCount = mOnCursorUpdateHelper.getCallCount(); | |
| 87 moveCursor(x, y); | |
| 88 mOnCursorUpdateHelper.waitForCallback(onCursorUpdateCount); | |
| 89 assertPointerIcon(type); | |
| 90 } | |
| 91 | |
| 92 @SmallTest | |
| 93 @Feature({"Main"}) | |
| 94 public void testPointerIcon() throws Throwable { | |
| 95 setCursorUpdateCallback(new Runnable() { | |
| 96 @Override | |
| 97 public void run() { | |
| 98 mOnCursorUpdateHelper.notifyCalled(); | |
| 99 } | |
| 100 }); | |
| 101 | |
| 102 checkPointerIconForNode("hand", PointerIcon.TYPE_HAND); | |
| 103 checkPointerIconForNode("text", PointerIcon.TYPE_TEXT); | |
| 104 checkPointerIconForNode("help", PointerIcon.TYPE_HELP); | |
| 105 } | |
| 106 } | |
| OLD | NEW |