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.os.Build; | |
| 10 import android.os.SystemClock; | |
| 11 import android.support.test.filters.SmallTest; | |
| 12 import android.view.InputDevice; | |
| 13 import android.view.MotionEvent; | |
| 14 import android.view.PointerIcon; | |
| 15 | |
| 16 import org.chromium.base.test.util.Feature; | |
| 17 import org.chromium.base.test.util.MinAndroidSdkLevel; | |
| 18 import org.chromium.base.test.util.UrlUtils; | |
| 19 import org.chromium.content.browser.test.util.Criteria; | |
| 20 import org.chromium.content.browser.test.util.CriteriaHelper; | |
| 21 import org.chromium.content_shell_apk.ContentShellTestBase; | |
| 22 | |
| 23 /** | |
| 24 * Tests that we can move mouse cursor and test cursor icon. | |
| 25 */ | |
| 26 @MinAndroidSdkLevel(Build.VERSION_CODES.N) | |
| 27 @TargetApi(Build.VERSION_CODES.N) | |
| 28 public class ContentViewPointerIconTest extends ContentShellTestBase { | |
| 29 private static final String CURSOR_PAGE = UrlUtils.encodeHtmlDataUri("<html> " | |
| 30 + "<style>div { height: 60px; }</style>" | |
| 31 + "<body><div><a href=\"about:blank\">pointer</a></div>" | |
| 32 + "<div>text</div>" | |
| 33 + "<div style=\"cursor:help;\">help</div></body>" | |
| 34 + "</html>"); | |
| 35 | |
| 36 @Override | |
| 37 protected void setUp() throws Exception { | |
| 38 super.setUp(); | |
| 39 | |
| 40 launchContentShellWithUrl(CURSOR_PAGE); | |
| 41 waitForActiveShellToBeDoneLoading(); | |
| 42 } | |
| 43 | |
| 44 private void assertWaitForPointerIcon(final int type) { | |
| 45 CriteriaHelper.pollInstrumentationThread(new Criteria() { | |
| 46 @Override | |
| 47 public boolean isSatisfied() { | |
| 48 PointerIcon currentPointerIcon = | |
| 49 getContentViewCore().getContainerView().getPointerIcon() ; | |
| 50 Context context = getInstrumentationForTestCommon().getContext() ; | |
| 51 return currentPointerIcon != null | |
| 52 && currentPointerIcon.equals(PointerIcon.getSystemIcon(c ontext, type)); | |
| 53 } | |
| 54 }); | |
| 55 } | |
| 56 | |
| 57 private void moveCursor(final float deltaAxisX, final float deltaAxisY) thro ws Throwable { | |
| 58 runTestOnUiThread(new Runnable() { | |
| 59 @Override | |
| 60 public void run() { | |
| 61 MotionEvent.PointerProperties[] pointerProperties = | |
| 62 new MotionEvent.PointerProperties[1]; | |
| 63 MotionEvent.PointerProperties pp = new MotionEvent.PointerProper ties(); | |
| 64 pp.id = 0; | |
| 65 pp.toolType = MotionEvent.TOOL_TYPE_MOUSE; | |
| 66 pointerProperties[0] = pp; | |
| 67 | |
| 68 MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.Poin terCoords[1]; | |
| 69 MotionEvent.PointerCoords pc = new MotionEvent.PointerCoords(); | |
| 70 pc.x = deltaAxisX; | |
| 71 pc.y = deltaAxisY; | |
| 72 pointerCoords[0] = pc; | |
| 73 | |
| 74 MotionEvent cursorMoveEvent = MotionEvent.obtain(SystemClock.upt imeMillis(), | |
| 75 SystemClock.uptimeMillis() + 1, MotionEvent.ACTION_HOVER _MOVE, 1, | |
| 76 pointerProperties, pointerCoords, 0, 0, 1.0f, 1.0f, 0, 0 , | |
| 77 InputDevice.SOURCE_MOUSE, 0); | |
| 78 cursorMoveEvent.setSource(InputDevice.SOURCE_MOUSE); | |
| 79 getContentViewCore().getContainerView().dispatchGenericMotionEve nt(cursorMoveEvent); | |
| 80 } | |
| 81 }); | |
| 82 } | |
| 83 | |
| 84 @SmallTest | |
| 85 @Feature({"Main"}) | |
| 86 public void testPointerIcon() throws Throwable { | |
| 87 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.
| |
| 88 assertWaitForPointerIcon(PointerIcon.TYPE_HAND); | |
| 89 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.
| |
| 90 | |
| 91 moveCursor(11.0f, 90.0f); | |
| 92 assertWaitForPointerIcon(PointerIcon.TYPE_TEXT); | |
| 93 Thread.sleep(20); | |
| 94 | |
| 95 moveCursor(11.0f, 160.0f); | |
| 96 assertWaitForPointerIcon(PointerIcon.TYPE_HELP); | |
| 97 } | |
| 98 } | |
| OLD | NEW |