diff options
Diffstat (limited to 'tests/func')
8 files changed, 358 insertions, 101 deletions
diff --git a/tests/func/Android.mk b/tests/func/Android.mk index b0c5ad1c..e89ba25b 100644 --- a/tests/func/Android.mk +++ b/tests/func/Android.mk @@ -14,8 +14,6 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ tv-test-common \ ub-uiautomator \ -LOCAL_JAVA_LIBRARIES := legacy-android-test - LOCAL_INSTRUMENTATION_FOR := LiveTv LOCAL_SDK_VERSION := current diff --git a/tests/func/OWNERS b/tests/func/OWNERS new file mode 100644 index 00000000..4aa5fe52 --- /dev/null +++ b/tests/func/OWNERS @@ -0,0 +1,2 @@ +nchalko@google.com +shubang@google.com diff --git a/tests/func/src/com/android/tv/tests/ui/ChannelSourcesTest.java b/tests/func/src/com/android/tv/tests/ui/ChannelSourcesTest.java index e4f612e3..cfa5eda7 100644 --- a/tests/func/src/com/android/tv/tests/ui/ChannelSourcesTest.java +++ b/tests/func/src/com/android/tv/tests/ui/ChannelSourcesTest.java @@ -23,6 +23,7 @@ import android.support.test.uiautomator.Until; import com.android.tv.R; import com.android.tv.testing.uihelper.ByResource; +import com.android.tv.testing.uihelper.UiDeviceUtils; /** * Tests for channel sources. @@ -60,8 +61,7 @@ public class ChannelSourcesTest extends LiveChannelsTestCase { assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel)); mSidePanelHelper.assertNavigateToItem(R.string.settings_channel_source_item_setup); - mDevice.pressDPadCenter(); - mDevice.pressDPadCenter(); + UiDeviceUtils.pressDPadCenter(getInstrumentation(), 2); assertWaitForCondition(mDevice, Until.hasObject(ByResource.text(mTargetResources, R.string.setup_sources_text))); diff --git a/tests/func/src/com/android/tv/tests/ui/LiveChannelsTestCase.java b/tests/func/src/com/android/tv/tests/ui/LiveChannelsTestCase.java index 25c7909b..e306e6c6 100644 --- a/tests/func/src/com/android/tv/tests/ui/LiveChannelsTestCase.java +++ b/tests/func/src/com/android/tv/tests/ui/LiveChannelsTestCase.java @@ -73,6 +73,8 @@ public abstract class LiveChannelsTestCase extends InstrumentationTestCase { .hasObject(Constants.PROGRAM_GUIDE)) { mDevice.pressBack(); } + // To destroy the activity to make sure next test case's activity launch check works well. + mDevice.pressBack(); super.tearDown(); } 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()); } } diff --git a/tests/func/src/com/android/tv/tests/ui/ProgramGuidePerformanceTest.java b/tests/func/src/com/android/tv/tests/ui/ProgramGuidePerformanceTest.java deleted file mode 100644 index 95921df9..00000000 --- a/tests/func/src/com/android/tv/tests/ui/ProgramGuidePerformanceTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.tv.tests.ui; - -import static com.android.tv.testing.uihelper.UiDeviceAsserts.assertWaitForCondition; - -import android.os.SystemClock; -import android.support.test.filters.LargeTest; -import android.support.test.uiautomator.Until; -import android.util.Log; - -import com.android.tv.R; -import com.android.tv.testing.uihelper.Constants; - -/** - * Tests for {@link com.android.tv.MainActivity}. - */ -@LargeTest -public class ProgramGuidePerformanceTest extends LiveChannelsTestCase { - private static final String TAG = "ProgramGuidePerformance"; - - public static final int SHOW_MENU_MAX_DURATION_MS = 1500; - public void testShowMenu() { - mLiveChannelsHelper.assertAppStarted(); - mMenuHelper.showMenu(); - mMenuHelper.assertNavigateToMenuItem(R.string.menu_title_channels, - R.string.channels_item_program_guide); - //TODO: build a simple performance framework like JankTest - long start = SystemClock.elapsedRealtime(); - Log.v(TAG, "start " + start + " milliSeconds"); - mDevice.pressDPadCenter(); - assertWaitForCondition(mDevice, Until.hasObject(Constants.PROGRAM_GUIDE)); - long end = SystemClock.elapsedRealtime(); - Log.v(TAG, "end " + end + " milliSeconds"); - long duration = end - start; - assertDuration("ShowMenu", SHOW_MENU_MAX_DURATION_MS, duration); - mDevice.pressBack(); - } - - private void assertDuration(String msg, long expectedMaxMilliSeconds, long actualMilliSeconds) { - Log.d(TAG, msg + " duration " + actualMilliSeconds + " milliSeconds"); - assertTrue(msg + " duration expected to be <= " + expectedMaxMilliSeconds - + " milliSeconds but was " + actualMilliSeconds + " milliSeconds.", - actualMilliSeconds <= expectedMaxMilliSeconds); - } -} 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 new file mode 100644 index 00000000..d88e67ad --- /dev/null +++ b/tests/func/src/com/android/tv/tests/ui/dvr/DvrLibraryTest.java @@ -0,0 +1,219 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +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; +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 java.util.regex.Pattern; + +@MediumTest +@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N) +public class DvrLibraryTest extends LiveChannelsTestCase { + private static final String PROGRAM_NAME_PREFIX = "Title("; + + 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(); + } + + 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); + } + + public void testEmptyLibrary() { + mMenuHelper.assertPressDvrLibrary(); + assertWaitForCondition(mDevice, 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); + + mDevice.pressDPadCenter(); + assertWaitUntilFocused(mDevice, mFullScheduleCard); + mDevice.pressDPadCenter(); + assertWaitForCondition(mDevice, 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), + true); + + // Close the DVR library. + mDevice.pressBack(); + assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY)); + mDevice.pressBack(); + assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY)); + } + + 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)); + + // 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(); + + // 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); + + // 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), + false); + assertHas(mDevice, 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); + + // 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); + + // 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); + + // 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); + + // 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); + + // 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); + + // DVR Library should be empty now. + assertHas(mDevice, mRecentRow, false); + assertHas(mDevice, mScheduledRow, true); + assertHas(mDevice, mSeriesRow, false); + + // Close the DVR library. + mDevice.pressBack(); + assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY)); + } +} diff --git a/tests/func/src/com/android/tv/tests/ui/sidepanel/CustomizeChannelListFragmentTest.java b/tests/func/src/com/android/tv/tests/ui/sidepanel/CustomizeChannelListFragmentTest.java new file mode 100644 index 00000000..deeb9bfd --- /dev/null +++ b/tests/func/src/com/android/tv/tests/ui/sidepanel/CustomizeChannelListFragmentTest.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.tv.tests.ui.sidepanel; + +import static com.android.tv.testing.uihelper.UiDeviceAsserts.assertWaitForCondition; + +import android.graphics.Point; +import android.support.test.filters.LargeTest; +import android.support.test.uiautomator.BySelector; +import android.support.test.uiautomator.Direction; +import android.support.test.uiautomator.UiObject2; +import android.support.test.uiautomator.Until; + +import com.android.tv.R; +import com.android.tv.testing.uihelper.Constants; +import com.android.tv.tests.ui.LiveChannelsTestCase; + +@LargeTest +public class CustomizeChannelListFragmentTest extends LiveChannelsTestCase { + private BySelector mBySettingsSidePanel; + private UiObject2 mTvView; + private Point mNormalTvViewCenter; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mLiveChannelsHelper.assertAppStarted(); + mTvView = mDevice.findObject(Constants.TV_VIEW); + mNormalTvViewCenter = mTvView.getVisibleCenter(); + assertNotNull(mNormalTvViewCenter); + pressKeysForChannel(com.android.tv.testing.testinput.TvTestInputConstants.CH_2); + // Wait until KeypadChannelSwitchView closes. + assertWaitForCondition(mDevice, Until.hasObject(Constants.CHANNEL_BANNER)); + mBySettingsSidePanel = mSidePanelHelper.bySidePanelTitled( + R.string.side_panel_title_settings); + } + + private void assertShrunkenTvView(boolean shrunkenExpected) { + Point currentTvViewCenter = mTvView.getVisibleCenter(); + if (shrunkenExpected) { + assertFalse(mNormalTvViewCenter.equals(currentTvViewCenter)); + } else { + assertTrue(mNormalTvViewCenter.equals(currentTvViewCenter)); + } + } + + public void testCustomizeChannelList_noraml() { + // Show customize channel list fragment + mMenuHelper.assertPressOptionsSettings(); + assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel)); + mSidePanelHelper.assertNavigateToItem( + R.string.settings_channel_source_item_customize_channels); + mDevice.pressDPadCenter(); + BySelector bySidePanel = mSidePanelHelper.bySidePanelTitled( + R.string.side_panel_title_edit_channels_for_an_input); + assertWaitForCondition(mDevice, Until.hasObject(bySidePanel)); + assertShrunkenTvView(true); + + // Show group by fragment + mSidePanelHelper.assertNavigateToItem(R.string.edit_channels_item_group_by, Direction.UP); + mDevice.pressDPadCenter(); + bySidePanel = mSidePanelHelper.bySidePanelTitled(R.string.side_panel_title_group_by); + assertWaitForCondition(mDevice, Until.hasObject(bySidePanel)); + assertShrunkenTvView(true); + + // Back to customize channel list fragment + mDevice.pressBack(); + bySidePanel = mSidePanelHelper.bySidePanelTitled( + R.string.side_panel_title_edit_channels_for_an_input); + assertWaitForCondition(mDevice, Until.hasObject(bySidePanel)); + assertShrunkenTvView(true); + + // Return to the main menu. + mDevice.pressBack(); + assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel)); + assertShrunkenTvView(false); + } + + public void testCustomizeChannelList_timeout() { + // Show customize channel list fragment + mMenuHelper.assertPressOptionsSettings(); + assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel)); + mSidePanelHelper.assertNavigateToItem( + R.string.settings_channel_source_item_customize_channels); + mDevice.pressDPadCenter(); + BySelector bySidePanel = mSidePanelHelper.bySidePanelTitled( + R.string.side_panel_title_edit_channels_for_an_input); + assertWaitForCondition(mDevice, Until.hasObject(bySidePanel)); + assertShrunkenTvView(true); + + // Show group by fragment + mSidePanelHelper.assertNavigateToItem(R.string.edit_channels_item_group_by, Direction.UP); + mDevice.pressDPadCenter(); + bySidePanel = mSidePanelHelper.bySidePanelTitled(R.string.side_panel_title_group_by); + assertWaitForCondition(mDevice, Until.hasObject(bySidePanel)); + assertShrunkenTvView(true); + + // Wait for time-out to return to the main menu. + assertWaitForCondition(mDevice, Until.gone(bySidePanel), + mTargetResources.getInteger(R.integer.side_panel_show_duration)); + assertShrunkenTvView(false); + } +} |