diff options
Diffstat (limited to 'tests/func/src/com/android/tv/tests/ui/dvr/DvrLibraryTest.java')
-rw-r--r-- | tests/func/src/com/android/tv/tests/ui/dvr/DvrLibraryTest.java | 377 |
1 files changed, 241 insertions, 136 deletions
diff --git a/tests/func/src/com/android/tv/tests/ui/dvr/DvrLibraryTest.java b/tests/func/src/com/android/tv/tests/ui/dvr/DvrLibraryTest.java index d88e67ad..d0ebed91 100644 --- a/tests/func/src/com/android/tv/tests/ui/dvr/DvrLibraryTest.java +++ b/tests/func/src/com/android/tv/tests/ui/dvr/DvrLibraryTest.java @@ -16,8 +16,6 @@ package com.android.tv.tests.ui.dvr; -import static com.android.tv.testing.uihelper.UiDeviceAsserts.assertHas; -import static com.android.tv.testing.uihelper.UiDeviceAsserts.assertWaitForCondition; import static com.android.tv.testing.uihelper.UiDeviceAsserts.assertWaitUntilFocused; import android.os.Build; @@ -25,195 +23,302 @@ import android.support.test.filters.MediumTest; import android.support.test.filters.SdkSuppress; import android.support.test.uiautomator.By; import android.support.test.uiautomator.BySelector; -import android.support.test.uiautomator.UiObject2; import android.support.test.uiautomator.Until; - import com.android.tv.R; import com.android.tv.testing.uihelper.ByResource; import com.android.tv.testing.uihelper.Constants; -import com.android.tv.tests.ui.LiveChannelsTestCase; - +import com.android.tv.tests.ui.LiveChannelsTestController; import java.util.regex.Pattern; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +/** Test the DVR library UI */ @MediumTest +@RunWith(JUnit4.class) @SdkSuppress(minSdkVersion = Build.VERSION_CODES.N) -public class DvrLibraryTest extends LiveChannelsTestCase { +public class DvrLibraryTest { private static final String PROGRAM_NAME_PREFIX = "Title("; + @Rule public final LiveChannelsTestController controller = new LiveChannelsTestController(); + private BySelector mRecentRow; private BySelector mScheduledRow; private BySelector mSeriesRow; private BySelector mFullScheduleCard; - @Override - protected void setUp() throws Exception { - super.setUp(); - mRecentRow = By.hasDescendant(ByResource.text(mTargetResources, R.string.dvr_main_recent)); - mScheduledRow = By.hasDescendant( - ByResource.text(mTargetResources, R.string.dvr_main_scheduled)); - mSeriesRow = By.hasDescendant(ByResource.text(mTargetResources, R.string.dvr_main_series)); - mFullScheduleCard = By.focusable(true).hasDescendant( - ByResource.text(mTargetResources, R.string.dvr_full_schedule_card_view_title)); - mLiveChannelsHelper.assertAppStarted(); + @Before + public void setUp() throws Exception { + + mRecentRow = + By.hasDescendant( + ByResource.text(controller.getTargetResources(), R.string.dvr_main_recent)); + mScheduledRow = + By.hasDescendant( + ByResource.text( + controller.getTargetResources(), R.string.dvr_main_scheduled)); + mSeriesRow = + By.hasDescendant( + ByResource.text(controller.getTargetResources(), R.string.dvr_main_series)); + mFullScheduleCard = + By.focusable(true) + .hasDescendant( + ByResource.text( + controller.getTargetResources(), + R.string.dvr_full_schedule_card_view_title)); + controller.liveChannelsHelper.assertAppStarted(); } + @Test + public void placeholder() { + // TODO(b/72153742): three must be at least one test + } + + @Ignore("b/72153742") + @Test public void testCancel() { - mMenuHelper.assertPressDvrLibrary(); - assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY)); - mDevice.pressBack(); - assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY)); - assertHas(mDevice, Constants.MENU, false); + controller.menuHelper.assertPressDvrLibrary(); + controller.assertWaitForCondition(Until.hasObject(Constants.DVR_LIBRARY)); + controller.pressBack(); + controller.assertWaitForCondition(Until.gone(Constants.DVR_LIBRARY)); + controller.assertHas(Constants.MENU, false); } + @Ignore("b/72153742") + @Test public void testEmptyLibrary() { - mMenuHelper.assertPressDvrLibrary(); - assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY)); + controller.menuHelper.assertPressDvrLibrary(); + controller.assertWaitForCondition(Until.hasObject(Constants.DVR_LIBRARY)); // DVR Library is empty, only Scheduled row and Full schedule card should be displayed. - assertHas(mDevice, mRecentRow, false); - assertHas(mDevice, mScheduledRow, true); - assertHas(mDevice, mSeriesRow, false); + controller.assertHas(mRecentRow, false); + controller.assertHas(mScheduledRow, true); + controller.assertHas(mSeriesRow, false); - mDevice.pressDPadCenter(); - assertWaitUntilFocused(mDevice, mFullScheduleCard); - mDevice.pressDPadCenter(); - assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY)); + controller.pressDPadCenter(); + assertWaitUntilFocused(controller.getUiDevice(), mFullScheduleCard); + controller.pressDPadCenter(); + controller.assertWaitForCondition(Until.gone(Constants.DVR_LIBRARY)); // Empty schedules screen should be shown. - assertHas(mDevice, Constants.DVR_SCHEDULES, true); - assertHas(mDevice, ByResource.text(mTargetResources, R.string.dvr_schedules_empty_state), + controller.assertHas(Constants.DVR_SCHEDULES, true); + controller.assertHas( + ByResource.text( + controller.getTargetResources(), R.string.dvr_schedules_empty_state), true); // Close the DVR library. - mDevice.pressBack(); - assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY)); - mDevice.pressBack(); - assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY)); + controller.pressBack(); + controller.assertWaitForCondition(Until.hasObject(Constants.DVR_LIBRARY)); + controller.pressBack(); + controller.assertWaitForCondition(Until.gone(Constants.DVR_LIBRARY)); } + @Ignore("b/72153742") + @Test public void testScheduleRecordings() { - BySelector newScheduleCard = By.focusable(true).hasDescendant( - By.textStartsWith(PROGRAM_NAME_PREFIX)).hasDescendant(By.textEndsWith("today")); - BySelector seriesCardWithOneSchedule = By.focusable(true).hasDescendant( - By.textStartsWith(PROGRAM_NAME_PREFIX)).hasDescendant(By.text(mTargetResources - .getQuantityString(R.plurals.dvr_count_scheduled_recordings, 1, 1))); - BySelector seriesCardWithOneRecordedProgram = By.focusable(true).hasDescendant( - By.textStartsWith(PROGRAM_NAME_PREFIX)).hasDescendant(By.text(mTargetResources - .getQuantityString(R.plurals.dvr_count_new_recordings, 1, 1))); - Pattern watchButton = Pattern.compile("^" + mTargetResources - .getString(R.string.dvr_detail_watch).toUpperCase() + "\n.*$"); - - mMenuHelper.showMenu(); - mMenuHelper.assertNavigateToPlayControlsRow(); - mDevice.pressDPadRight(); - mDevice.pressDPadCenter(); - assertWaitForCondition(mDevice, Until.hasObject( - ByResource.text(mTargetResources, R.string.dvr_action_record_episode))); - mDevice.pressDPadCenter(); - assertWaitForCondition(mDevice, Until.gone( - ByResource.text(mTargetResources, R.string.dvr_action_record_episode))); - - mMenuHelper.assertPressDvrLibrary(); - assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY)); + BySelector newScheduleCard = + By.focusable(true) + .hasDescendant(By.textStartsWith(PROGRAM_NAME_PREFIX)) + .hasDescendant(By.textEndsWith("today")); + BySelector seriesCardWithOneSchedule = + By.focusable(true) + .hasDescendant(By.textStartsWith(PROGRAM_NAME_PREFIX)) + .hasDescendant( + By.text( + controller + .getTargetResources() + .getQuantityString( + R.plurals.dvr_count_scheduled_recordings, + 1, + 1))); + BySelector seriesCardWithOneRecordedProgram = + By.focusable(true) + .hasDescendant(By.textStartsWith(PROGRAM_NAME_PREFIX)) + .hasDescendant( + By.text( + controller + .getTargetResources() + .getQuantityString( + R.plurals.dvr_count_new_recordings, 1, 1))); + Pattern watchButton = + Pattern.compile( + "^" + + controller + .getTargetResources() + .getString(R.string.dvr_detail_watch) + .toUpperCase() + + "\n.*$"); + + controller.menuHelper.showMenu(); + controller.menuHelper.assertNavigateToPlayControlsRow(); + controller.pressDPadRight(); + controller.pressDPadCenter(); + controller.assertWaitForCondition( + Until.hasObject( + ByResource.text( + controller.getTargetResources(), + R.string.dvr_action_record_episode))); + controller.pressDPadCenter(); + controller.assertWaitForCondition( + Until.gone( + ByResource.text( + controller.getTargetResources(), + R.string.dvr_action_record_episode))); + + controller.menuHelper.assertPressDvrLibrary(); + controller.assertWaitForCondition(Until.hasObject(Constants.DVR_LIBRARY)); // Schedule should be automatically added to the series. - assertHas(mDevice, mRecentRow, false); - assertHas(mDevice, mScheduledRow, true); - assertHas(mDevice, mSeriesRow, true); - String programName = mDevice.findObject(By.textStartsWith(PROGRAM_NAME_PREFIX)).getText(); + controller.assertHas(mRecentRow, false); + controller.assertHas(mScheduledRow, true); + controller.assertHas(mSeriesRow, true); + String programName = + controller + .getUiDevice() + .findObject(By.textStartsWith(PROGRAM_NAME_PREFIX)) + .getText(); // Move to scheduled row, there should be one new schedule and one full schedule card. - mDevice.pressDPadRight(); - assertWaitUntilFocused(mDevice, newScheduleCard); - mDevice.pressDPadRight(); - assertWaitUntilFocused(mDevice, mFullScheduleCard); + controller.pressDPadRight(); + controller.assertWaitUntilFocused(newScheduleCard); + controller.pressDPadRight(); + controller.assertWaitUntilFocused(mFullScheduleCard); // Enters the full schedule, there should be one schedule in the full schedule. - mDevice.pressDPadCenter(); - assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY)); - assertHas(mDevice, Constants.DVR_SCHEDULES, true); - assertHas(mDevice, ByResource.text(mTargetResources, R.string.dvr_schedules_empty_state), + controller.pressDPadCenter(); + controller.assertWaitForCondition(Until.gone(Constants.DVR_LIBRARY)); + controller.assertHas(Constants.DVR_SCHEDULES, true); + controller.assertHas( + ByResource.text( + controller.getTargetResources(), R.string.dvr_schedules_empty_state), false); - assertHas(mDevice, By.textStartsWith(programName), true); + controller.assertHas(By.textStartsWith(programName), true); // Moves to the series card, clicks it, the detail page should be shown with "View schedule" // button. - mDevice.pressBack(); - assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY)); - mDevice.pressDPadLeft(); - assertWaitUntilFocused(mDevice, newScheduleCard); - mDevice.pressDPadDown(); - assertWaitUntilFocused(mDevice, seriesCardWithOneSchedule); - mDevice.pressDPadCenter(); - assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY)); - assertHas(mDevice, By.text(mTargetResources - .getString(R.string.dvr_detail_view_schedule).toUpperCase()), true); - assertHas(mDevice, By.text(watchButton), false); - assertHas(mDevice, By.text(mTargetResources - .getString(R.string.dvr_detail_series_delete).toUpperCase()), false); + controller.pressBack(); + controller.assertWaitForCondition(Until.hasObject(Constants.DVR_LIBRARY)); + controller.pressDPadLeft(); + controller.assertWaitUntilFocused(newScheduleCard); + controller.pressDPadDown(); + controller.assertWaitUntilFocused(seriesCardWithOneSchedule); + controller.pressDPadCenter(); + controller.assertWaitForCondition(Until.gone(Constants.DVR_LIBRARY)); + controller.assertHas( + By.text( + controller + .getTargetResources() + .getString(R.string.dvr_detail_view_schedule) + .toUpperCase()), + true); + controller.assertHas(By.text(watchButton), false); + controller.assertHas( + By.text( + controller + .getTargetResources() + .getString(R.string.dvr_detail_series_delete) + .toUpperCase()), + false); // Clicks the new schedule, the detail page should be shown with "Stop recording" button. - mDevice.pressBack(); - assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY)); - assertWaitUntilFocused(mDevice, seriesCardWithOneSchedule); - mDevice.pressDPadUp(); - assertWaitUntilFocused(mDevice, newScheduleCard); - mDevice.pressDPadCenter(); - assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY)); - assertHas(mDevice, By.text(mTargetResources - .getString(R.string.dvr_detail_stop_recording).toUpperCase()), true); + controller.pressBack(); + controller.assertWaitForCondition(Until.hasObject(Constants.DVR_LIBRARY)); + controller.assertWaitUntilFocused(seriesCardWithOneSchedule); + controller.pressDPadUp(); + controller.assertWaitUntilFocused(newScheduleCard); + controller.pressDPadCenter(); + controller.assertWaitForCondition(Until.gone(Constants.DVR_LIBRARY)); + controller.assertHas( + By.text( + controller + .getTargetResources() + .getString(R.string.dvr_detail_stop_recording) + .toUpperCase()), + true); // Stops the recording - mDevice.pressDPadCenter(); - assertWaitForCondition(mDevice, Until.hasObject( - ByResource.text(mTargetResources, R.string.dvr_action_stop))); - mDevice.pressDPadCenter(); - assertWaitForCondition(mDevice, Until.gone( - ByResource.text(mTargetResources, R.string.dvr_action_stop))); - assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY)); - assertWaitUntilFocused(mDevice, mFullScheduleCard); + controller.pressDPadCenter(); + controller.assertWaitForCondition( + Until.hasObject( + ByResource.text( + controller.getTargetResources(), R.string.dvr_action_stop))); + controller.pressDPadCenter(); + controller.assertWaitForCondition( + Until.gone( + ByResource.text( + controller.getTargetResources(), R.string.dvr_action_stop))); + controller.assertWaitForCondition(Until.hasObject(Constants.DVR_LIBRARY)); + controller.assertWaitUntilFocused(mFullScheduleCard); // Moves to series' detail page again, now it should have two more buttons - mDevice.pressDPadDown(); - assertWaitUntilFocused(mDevice, seriesCardWithOneRecordedProgram); - mDevice.pressDPadCenter(); - assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY)); - assertHas(mDevice, By.text(watchButton), true); - assertHas(mDevice, By.text(mTargetResources - .getString(R.string.dvr_detail_view_schedule).toUpperCase()), true); - assertHas(mDevice, By.text(mTargetResources - .getString(R.string.dvr_detail_series_delete).toUpperCase()), true); + controller.pressDPadDown(); + controller.assertWaitUntilFocused(seriesCardWithOneRecordedProgram); + controller.pressDPadCenter(); + controller.assertWaitForCondition(Until.gone(Constants.DVR_LIBRARY)); + controller.assertHas(By.text(watchButton), true); + controller.assertHas( + By.text( + controller + .getTargetResources() + .getString(R.string.dvr_detail_view_schedule) + .toUpperCase()), + true); + controller.assertHas( + By.text( + controller + .getTargetResources() + .getString(R.string.dvr_detail_series_delete) + .toUpperCase()), + true); // Moves to the recent row and clicks the recent recorded program. - mDevice.pressBack(); - assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY)); - assertWaitUntilFocused(mDevice, seriesCardWithOneRecordedProgram); - mDevice.pressDPadUp(); - assertWaitUntilFocused(mDevice, mFullScheduleCard); - mDevice.pressDPadUp(); - assertWaitUntilFocused(mDevice, By.focusable(true).hasDescendant(By.text(programName))); - mDevice.pressDPadCenter(); - assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY)); - assertHas(mDevice, By.text(mTargetResources - .getString(R.string.dvr_detail_watch).toUpperCase()), true); - assertHas(mDevice, By.text(mTargetResources - .getString(R.string.dvr_detail_delete).toUpperCase()), true); + controller.pressBack(); + controller.assertWaitForCondition(Until.hasObject(Constants.DVR_LIBRARY)); + controller.assertWaitUntilFocused(seriesCardWithOneRecordedProgram); + controller.pressDPadUp(); + controller.assertWaitUntilFocused(mFullScheduleCard); + controller.pressDPadUp(); + controller.assertWaitUntilFocused(By.focusable(true).hasDescendant(By.text(programName))); + controller.pressDPadCenter(); + controller.assertWaitForCondition(Until.gone(Constants.DVR_LIBRARY)); + controller.assertHas( + By.text( + controller + .getTargetResources() + .getString(R.string.dvr_detail_watch) + .toUpperCase()), + true); + controller.assertHas( + By.text( + controller + .getTargetResources() + .getString(R.string.dvr_detail_delete) + .toUpperCase()), + true); // Moves to the delete button and clicks to remove the recorded program. - mDevice.pressDPadRight(); - assertWaitUntilFocused(mDevice, By.text(mTargetResources - .getString(R.string.dvr_detail_delete).toUpperCase())); - mDevice.pressDPadCenter(); - assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY)); - assertWaitUntilFocused(mDevice, mFullScheduleCard); + controller.pressDPadRight(); + controller.assertWaitUntilFocused( + By.text( + controller + .getTargetResources() + .getString(R.string.dvr_detail_delete) + .toUpperCase())); + controller.pressDPadCenter(); + controller.assertWaitForCondition(Until.hasObject(Constants.DVR_LIBRARY)); + controller.assertWaitUntilFocused(mFullScheduleCard); // DVR Library should be empty now. - assertHas(mDevice, mRecentRow, false); - assertHas(mDevice, mScheduledRow, true); - assertHas(mDevice, mSeriesRow, false); + controller.assertHas(mRecentRow, false); + controller.assertHas(mScheduledRow, true); + controller.assertHas(mSeriesRow, false); // Close the DVR library. - mDevice.pressBack(); - assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY)); + controller.pressBack(); + controller.assertWaitForCondition(Until.gone(Constants.DVR_LIBRARY)); } } |