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.graphics.Rect; | |
8 import android.os.SystemClock; | |
9 import android.support.test.filters.SmallTest; | |
10 import android.view.InputDevice; | |
11 import android.view.MotionEvent; | |
12 | |
13 import org.junit.Assert; | |
14 import org.junit.Before; | |
15 import org.junit.Rule; | |
16 import org.junit.Test; | |
17 import org.junit.runner.RunWith; | |
18 | |
19 import org.chromium.base.test.util.Feature; | |
20 import org.chromium.base.test.util.UrlUtils; | |
21 import org.chromium.blink_public.web.WebCursorInfoType; | |
22 import org.chromium.content.browser.test.ContentJUnit4ClassRunner; | |
23 import org.chromium.content.browser.test.util.DOMUtils; | |
24 import org.chromium.content_shell.ShellViewAndroidDelegate.OnCursorUpdateHelper; | |
25 import org.chromium.content_shell_apk.ContentShellActivityTestRule; | |
26 | |
27 /** | |
28 * Tests that we can move mouse cursor and test cursor icon. | |
29 */ | |
30 @RunWith(ContentJUnit4ClassRunner.class) | |
31 public class ContentViewPointerTypeTest { | |
32 @Rule | |
33 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi vityTestRule(); | |
34 | |
35 private static final String CURSOR_PAGE = UrlUtils.encodeHtmlDataUri("<html> " | |
36 + "<body><a id=\"hand\" href=\"about:blank\">pointer</a>" | |
37 + "<span id=\"text\">text</span>" | |
38 + "<span id=\"help\" style=\"cursor:help;\">help</span></body>" | |
39 + "</html>"); | |
40 | |
41 @Before | |
42 public void setUp() throws Exception { | |
43 mActivityTestRule.launchContentShellWithUrl(CURSOR_PAGE); | |
44 mActivityTestRule.waitForActiveShellToBeDoneLoading(); | |
45 } | |
46 | |
47 private void moveCursor(final float x, final float y) throws Throwable { | |
48 mActivityTestRule.runOnUiThreadForTestCommon(new Runnable() { | |
49 @Override | |
50 public void run() { | |
51 MotionEvent.PointerProperties[] pointerProperties = | |
52 new MotionEvent.PointerProperties[1]; | |
53 MotionEvent.PointerProperties pp = new MotionEvent.PointerProper ties(); | |
54 pp.id = 0; | |
55 pp.toolType = MotionEvent.TOOL_TYPE_MOUSE; | |
56 pointerProperties[0] = pp; | |
57 | |
58 MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.Poin terCoords[1]; | |
59 MotionEvent.PointerCoords pc = new MotionEvent.PointerCoords(); | |
60 pc.x = x; | |
61 pc.y = y; | |
62 pointerCoords[0] = pc; | |
63 | |
64 MotionEvent cursorMoveEvent = MotionEvent.obtain(SystemClock.upt imeMillis(), | |
65 SystemClock.uptimeMillis() + 1, MotionEvent.ACTION_HOVER _MOVE, 1, | |
66 pointerProperties, pointerCoords, 0, 0, 1.0f, 1.0f, 0, 0 , | |
67 InputDevice.SOURCE_MOUSE, 0); | |
68 cursorMoveEvent.setSource(InputDevice.SOURCE_MOUSE); | |
69 mActivityTestRule.getContentViewCore() | |
70 .getContainerView() | |
71 .dispatchGenericMotionEvent(cursorMoveEvent); | |
72 } | |
73 }); | |
74 } | |
75 | |
76 private void checkPointerTypeForNode(final String nodeId, final int type) th rows Throwable { | |
77 Rect rect = DOMUtils.getNodeBounds(mActivityTestRule.getWebContents(), n odeId); | |
78 float x = (float) (rect.left + rect.right) / 2.0f; | |
79 float y = (float) (rect.top + rect.bottom) / 2.0f; | |
80 | |
81 OnCursorUpdateHelper onCursorUpdateHelper = mActivityTestRule.getOnCurso rUpdateHelper(); | |
82 int onCursorUpdateCount = onCursorUpdateHelper.getCallCount(); | |
83 moveCursor(x, y); | |
84 onCursorUpdateHelper.waitForCallback(onCursorUpdateCount); | |
85 Assert.assertEquals(mActivityTestRule.getOnCursorUpdateHelper().getPoint erType(), type); | |
boliu
2017/06/07 02:38:09
nit: expected first, actual second
jaebaek
2017/06/08 01:00:10
Done.
| |
86 } | |
87 | |
88 @Test | |
89 @SmallTest | |
90 @Feature({"Main"}) | |
91 public void testPointerType() throws Throwable { | |
92 checkPointerTypeForNode("hand", WebCursorInfoType.TYPE_HAND); | |
93 checkPointerTypeForNode("text", WebCursorInfoType.TYPE_I_BEAM); | |
94 checkPointerTypeForNode("help", WebCursorInfoType.TYPE_HELP); | |
95 } | |
96 } | |
OLD | NEW |