Commit 74cceb49 authored by Theresa Wellington's avatar Theresa Wellington Committed by Commit Bot

Add AppMenuTest#testDragHelper_ClickItem

Add an Android app menu test to exercise some basic drag helper
functionality.

BUG=966644

Change-Id: If1c159250d015a0cac0a50f3d848cc50bd243ad4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1899199
Commit-Queue: Theresa  <twellington@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714274}
parent 99a89101
...@@ -18,6 +18,7 @@ import android.widget.ListView; ...@@ -18,6 +18,7 @@ import android.widget.ListView;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -299,7 +300,8 @@ class AppMenuDragHelper { ...@@ -299,7 +300,8 @@ class AppMenuDragHelper {
/** /**
* @return Visible rect in screen coordinates for the given View. * @return Visible rect in screen coordinates for the given View.
*/ */
private Rect getScreenVisibleRect(View view) { @VisibleForTesting
Rect getScreenVisibleRect(View view) {
view.getLocalVisibleRect(mScreenVisibleRect); view.getLocalVisibleRect(mScreenVisibleRect);
view.getLocationOnScreen(mScreenVisiblePoint); view.getLocationOnScreen(mScreenVisiblePoint);
mScreenVisibleRect.offset(mScreenVisiblePoint[0], mScreenVisiblePoint[1]); mScreenVisibleRect.offset(mScreenVisiblePoint[0], mScreenVisiblePoint[1]);
......
...@@ -613,6 +613,44 @@ public class AppMenuTest extends DummyUiActivityTestCase { ...@@ -613,6 +613,44 @@ public class AppMenuTest extends DummyUiActivityTestCase {
Assert.assertTrue("Menu should be showing", mAppMenuHandler.isAppMenuShowing()); Assert.assertTrue("Menu should be showing", mAppMenuHandler.isAppMenuShowing());
} }
@Test
@MediumTest
public void testDragHelper_ClickItem() throws Exception {
AppMenuButtonHelperImpl buttonHelper =
(AppMenuButtonHelperImpl) mAppMenuHandler.createAppMenuButtonHelper();
Assert.assertFalse("View should start unpressed",
mTestMenuButtonDelegate.getMenuButtonView().isPressed());
Assert.assertFalse("App menu should be not be active", buttonHelper.isAppMenuActive());
MotionEvent downMotionEvent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0);
sendMotionEventToButtonHelper(
buttonHelper, mTestMenuButtonDelegate.getMenuButtonView(), downMotionEvent);
waitForMenuToShow(0);
Assert.assertTrue("Menu should be showing", mAppMenuHandler.isAppMenuShowing());
View firstItem = mAppMenuHandler.getAppMenu().getListView().getChildAt(0);
Rect firstItemScreenRect =
mAppMenuHandler.getAppMenuDragHelper().getScreenVisibleRect(firstItem);
int eventX = firstItemScreenRect.left + (firstItemScreenRect.right / 2);
int eventY = firstItemScreenRect.top + (firstItemScreenRect.bottom / 2);
MotionEvent dragMotionEvent =
MotionEvent.obtain(0, 100, MotionEvent.ACTION_MOVE, eventX, eventY, 0);
sendMotionEventToButtonHelper(
buttonHelper, mTestMenuButtonDelegate.getMenuButtonView(), dragMotionEvent);
MotionEvent upMotionEvent =
MotionEvent.obtain(0, 150, MotionEvent.ACTION_UP, eventX, eventY, 0);
sendMotionEventToButtonHelper(
buttonHelper, mTestMenuButtonDelegate.getMenuButtonView(), upMotionEvent);
Assert.assertEquals("Item selected callback should have been called.", 1,
mDelegate.itemSelectedCallbackHelper.getCallCount());
Assert.assertEquals("Incorrect id for last selected item.", R.id.menu_item_one,
mDelegate.lastSelectedItemId);
}
private void showMenuAndAssert() throws TimeoutException { private void showMenuAndAssert() throws TimeoutException {
int currentCallCount = mMenuObserver.menuShownCallback.getCallCount(); int currentCallCount = mMenuObserver.menuShownCallback.getCallCount();
TestThreadUtils.runOnUiThreadBlocking( TestThreadUtils.runOnUiThreadBlocking(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment