| Index: chrome/android/javatests/src/org/chromium/chrome/browser/appmenu/AppMenuTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/appmenu/AppMenuTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/appmenu/AppMenuTest.java
|
| index 6c31a21dd7335d44edbc349c50ebffe9ed62e423..efee85a43ca3bb55335f17206ddb28d110f821d5 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/appmenu/AppMenuTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/appmenu/AppMenuTest.java
|
| @@ -10,6 +10,8 @@ import android.test.suitebuilder.annotation.SmallTest;
|
| import android.view.KeyEvent;
|
| import android.view.MenuItem;
|
| import android.view.View;
|
| +import android.widget.ListPopupWindow;
|
| +import android.widget.ListView;
|
|
|
| import org.chromium.base.ThreadUtils;
|
| import org.chromium.base.test.util.Feature;
|
| @@ -79,6 +81,7 @@ public class AppMenuTest extends ChromeShellTestBase {
|
| pressKey(KeyEvent.KEYCODE_SPACE);
|
|
|
| }
|
| +
|
| /**
|
| * Test bounds when accessing the menu through the keyboard.
|
| * Make sure that the menu stays open when trying to move past the first and last items.
|
| @@ -87,11 +90,11 @@ public class AppMenuTest extends ChromeShellTestBase {
|
| @Feature({"Browser", "Main"})
|
| public void testKeyboardMenuBoundaries() throws InterruptedException {
|
| moveToBoundary(false, true);
|
| - assertEquals(mAppMenu.getCount() - 1, mAppMenu.getCurrentFocusedPosition());
|
| + assertEquals(getCount() - 1, getCurrentFocusedRow());
|
| moveToBoundary(true, true);
|
| - assertEquals(0, mAppMenu.getCurrentFocusedPosition());
|
| + assertEquals(0, getCurrentFocusedRow());
|
| moveToBoundary(false, true);
|
| - assertEquals(mAppMenu.getCount() - 1, mAppMenu.getCurrentFocusedPosition());
|
| + assertEquals(getCount() - 1, getCurrentFocusedRow());
|
| }
|
|
|
| /**
|
| @@ -100,7 +103,7 @@ public class AppMenuTest extends ChromeShellTestBase {
|
| @SmallTest
|
| @Feature({"Browser", "Main"})
|
| public void testKeyboardMenuEnterOnOpen() throws InterruptedException {
|
| - hitEnterAndAssertItemSelected();
|
| + hitEnterAndAssertAppMenuDismissed();
|
| }
|
|
|
| /**
|
| @@ -110,8 +113,8 @@ public class AppMenuTest extends ChromeShellTestBase {
|
| @Feature({"Browser", "Main"})
|
| public void testKeyboardEnterAfterMovePastTopItem() throws InterruptedException {
|
| moveToBoundary(true, true);
|
| - assertEquals(0, mAppMenu.getCurrentFocusedPosition());
|
| - hitEnterAndAssertItemSelected();
|
| + assertEquals(0, getCurrentFocusedRow());
|
| + hitEnterAndAssertAppMenuDismissed();
|
| }
|
|
|
| /**
|
| @@ -122,8 +125,8 @@ public class AppMenuTest extends ChromeShellTestBase {
|
| @Feature({"Browser", "Main"})
|
| public void testKeyboardEnterAfterMovePastBottomItem() throws InterruptedException {
|
| moveToBoundary(false, true);
|
| - assertEquals(mAppMenu.getCount() - 1, mAppMenu.getCurrentFocusedPosition());
|
| - hitEnterAndAssertItemSelected();
|
| + assertEquals(getCount() - 1, getCurrentFocusedRow());
|
| + hitEnterAndAssertAppMenuDismissed();
|
| }
|
|
|
| /**
|
| @@ -135,8 +138,8 @@ public class AppMenuTest extends ChromeShellTestBase {
|
| public void testKeyboardMenuEnterOnTopItemLandscape() throws InterruptedException {
|
| getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
| moveToBoundary(true, false);
|
| - assertEquals(0, mAppMenu.getCurrentFocusedPosition());
|
| - hitEnterAndAssertItemSelected();
|
| + assertEquals(0, getCurrentFocusedRow());
|
| + hitEnterAndAssertAppMenuDismissed();
|
| }
|
|
|
| /**
|
| @@ -147,34 +150,33 @@ public class AppMenuTest extends ChromeShellTestBase {
|
| public void testKeyboardMenuEnterOnTopItemPortrait() throws InterruptedException {
|
| getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
| moveToBoundary(true, false);
|
| - assertEquals(0, mAppMenu.getCurrentFocusedPosition());
|
| - hitEnterAndAssertItemSelected();
|
| + assertEquals(0, getCurrentFocusedRow());
|
| + hitEnterAndAssertAppMenuDismissed();
|
| }
|
|
|
| - private void hitEnterAndAssertItemSelected() throws InterruptedException {
|
| - final int expectedItemId = mAppMenu.getCurrentFocusedItemId();
|
| + private void hitEnterAndAssertAppMenuDismissed() throws InterruptedException {
|
| pressKey(KeyEvent.KEYCODE_ENTER);
|
| - assertTrue("Did not select a correct menu item",
|
| + assertTrue("AppMenu did not dismiss",
|
| CriteriaHelper.pollForCriteria(new Criteria() {
|
| @Override
|
| public boolean isSatisfied() {
|
| - return mAppMenuHandler.mLastSelectedItemId == expectedItemId;
|
| + return !mAppMenuHandler.isAppMenuShowing();
|
| }
|
| }));
|
| }
|
|
|
| private void moveToBoundary(boolean towardsTop, boolean movePast) throws InterruptedException {
|
| // Move to the boundary.
|
| - final int end = towardsTop ? 0 : mAppMenu.getCount() - 1;
|
| + final int end = towardsTop ? 0 : getCount() - 1;
|
| int increment = towardsTop ? -1 : 1;
|
| - for (int index = mAppMenu.getCurrentFocusedPosition(); index != end; index += increment) {
|
| + for (int index = getCurrentFocusedRow(); index != end; index += increment) {
|
| pressKey(towardsTop ? KeyEvent.KEYCODE_DPAD_UP : KeyEvent.KEYCODE_DPAD_DOWN);
|
| final int expectedPosition = index + increment;
|
| assertTrue("Focus did not move to the next menu item",
|
| CriteriaHelper.pollForCriteria(new Criteria() {
|
| @Override
|
| public boolean isSatisfied() {
|
| - return mAppMenu.getCurrentFocusedPosition() == expectedPosition;
|
| + return getCurrentFocusedRow() == expectedPosition;
|
| }
|
| }));
|
| }
|
| @@ -186,7 +188,7 @@ public class AppMenuTest extends ChromeShellTestBase {
|
| CriteriaHelper.pollForCriteria(new Criteria() {
|
| @Override
|
| public boolean isSatisfied() {
|
| - return mAppMenu.getCurrentFocusedPosition() == end;
|
| + return getCurrentFocusedRow() == end;
|
| }
|
| }));
|
| }
|
| @@ -199,4 +201,17 @@ public class AppMenuTest extends ChromeShellTestBase {
|
| getInstrumentation().sendKeyDownUpSync(keycode);
|
| getInstrumentation().waitForIdleSync();
|
| }
|
| +
|
| + private int getCurrentFocusedRow() {
|
| + ListPopupWindow popup = mAppMenu.getPopup();
|
| + if (popup == null || popup.getListView() == null) return ListView.INVALID_POSITION;
|
| + ListView listView = popup.getListView();
|
| + return listView.getSelectedItemPosition();
|
| + }
|
| +
|
| + private int getCount() {
|
| + ListPopupWindow popup = mAppMenu.getPopup();
|
| + if (popup == null || popup.getListView() == null) return 0;
|
| + return popup.getListView().getCount();
|
| + }
|
| }
|
|
|