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