diff options
Diffstat (limited to 'tests/func/src/com/android/tv/tests/ui/PlayControlsRowViewTest.java')
-rw-r--r-- | tests/func/src/com/android/tv/tests/ui/PlayControlsRowViewTest.java | 54 |
1 files changed, 16 insertions, 38 deletions
diff --git a/tests/func/src/com/android/tv/tests/ui/PlayControlsRowViewTest.java b/tests/func/src/com/android/tv/tests/ui/PlayControlsRowViewTest.java index bbc7aa81..82c6a810 100644 --- a/tests/func/src/com/android/tv/tests/ui/PlayControlsRowViewTest.java +++ b/tests/func/src/com/android/tv/tests/ui/PlayControlsRowViewTest.java @@ -16,11 +16,11 @@ package com.android.tv.tests.ui; +import static com.android.tv.testing.uihelper.Constants.CHANNEL_BANNER; import static com.android.tv.testing.uihelper.Constants.FOCUSED_VIEW; import static com.android.tv.testing.uihelper.Constants.MENU; import static com.android.tv.testing.uihelper.UiDeviceAsserts.assertWaitForCondition; -import android.support.test.filters.SdkSuppress; import android.support.test.filters.SmallTest; import android.support.test.uiautomator.BySelector; import android.support.test.uiautomator.UiObject2; @@ -32,9 +32,8 @@ import com.android.tv.testing.testinput.TvTestInputConstants; import com.android.tv.testing.uihelper.DialogHelper; @SmallTest -@SdkSuppress(minSdkVersion = 23) public class PlayControlsRowViewTest extends LiveChannelsTestCase { - private static final int BUTTON_INDEX_PLAY_PAUSE = 2; + private static final String BUTTON_ID_PLAY_PAUSE = "com.android.tv:id/play_pause"; private BySelector mBySettingsSidePanel; @@ -42,7 +41,9 @@ public class PlayControlsRowViewTest extends LiveChannelsTestCase { protected void setUp() throws Exception { super.setUp(); mLiveChannelsHelper.assertAppStarted(); - pressKeysForChannel(TvTestInputConstants.CH_1_DEFAULT_DONT_MODIFY); + pressKeysForChannel(TvTestInputConstants.CH_2); + // Wait until KeypadChannelSwitchView closes. + assertWaitForCondition(mDevice, Until.hasObject(CHANNEL_BANNER)); // Tune to a new channel to ensure that the channel is changed. mDevice.pressDPadUp(); getInstrumentation().waitForIdleSync(); @@ -56,7 +57,7 @@ public class PlayControlsRowViewTest extends LiveChannelsTestCase { public void testFocusedViewInNormalCase() { mMenuHelper.showMenu(); mMenuHelper.assertNavigateToPlayControlsRow(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); mDevice.pressBack(); } @@ -69,49 +70,30 @@ public class PlayControlsRowViewTest extends LiveChannelsTestCase { // Fast forward button mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD); mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); mDevice.pressBack(); // Next button mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_NEXT); mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); - mDevice.pressBack(); - } - - /** - * Tests the case when the rewinding action is disabled. - * In this case, the button corresponding to the action is disabled, so play/pause button should - * have the focus. - */ - public void testFocusedViewWithDisabledActionBackward() { - // Previous button - mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_PREVIOUS); - mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); - mDevice.pressBack(); - - // Rewind button - mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_REWIND); - mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); mDevice.pressBack(); } public void testFocusedViewInMenu() { mMenuHelper.showMenu(); mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_PLAY); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); mMenuHelper.assertNavigateToRow(R.string.menu_title_channels); mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_NEXT); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); } public void testKeepPausedWhileParentalControlChange() { // Pause the playback. mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_PAUSE); mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); // Show parental controls fragment. mMenuHelper.assertPressOptionsSettings(); assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel)); @@ -130,14 +112,14 @@ public class PlayControlsRowViewTest extends LiveChannelsTestCase { mDevice.pressBack(); // Return to the main menu. mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); } public void testKeepPausedAfterVisitingHome() { // Pause the playback. mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_PAUSE); mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); // Press HOME twice to visit the home screen and return to Live TV. mDevice.pressHome(); // Wait until home screen is shown. @@ -147,19 +129,15 @@ public class PlayControlsRowViewTest extends LiveChannelsTestCase { mDevice.waitForIdle(); // Return to the main menu. mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); } - private void assertButtonHasFocus(int expectedButtonIndex) { + private void assertButtonHasFocus(String buttonId) { UiObject2 menu = mDevice.findObject(MENU); UiObject2 focusedView = menu.findObject(FOCUSED_VIEW); assertNotNull("Play controls row doesn't have a focused child.", focusedView); UiObject2 focusedButtonGroup = focusedView.getParent(); assertNotNull("The focused item should have parent", focusedButtonGroup); - UiObject2 controlBar = focusedButtonGroup.getParent(); - assertNotNull("The focused item should have grandparent", controlBar); - assertTrue("The grandparent should have more than five children", - controlBar.getChildCount() >= 5); - assertEquals(controlBar.getChildren().get(expectedButtonIndex), focusedButtonGroup); + assertEquals(buttonId, focusedButtonGroup.getResourceName()); } } |