diff options
Diffstat (limited to 'tests/func/src/com/android/tv/tests/ui/ParentalControlsTest.java')
-rw-r--r-- | tests/func/src/com/android/tv/tests/ui/ParentalControlsTest.java | 172 |
1 files changed, 101 insertions, 71 deletions
diff --git a/tests/func/src/com/android/tv/tests/ui/ParentalControlsTest.java b/tests/func/src/com/android/tv/tests/ui/ParentalControlsTest.java index 93d14bde..ee039d7c 100644 --- a/tests/func/src/com/android/tv/tests/ui/ParentalControlsTest.java +++ b/tests/func/src/com/android/tv/tests/ui/ParentalControlsTest.java @@ -16,139 +16,169 @@ package com.android.tv.tests.ui; -import static com.android.tv.testing.uihelper.UiDeviceAsserts.assertWaitForCondition; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; -import android.support.test.filters.SmallTest; +import android.support.test.filters.MediumTest; 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.DialogHelper; +import org.junit.After; +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; -@SmallTest -public class ParentalControlsTest extends LiveChannelsTestCase { - +/** Tests for {@link com.android.tv.ui.sidepanel.parentalcontrols.ParentalControlsFragment} */ +@MediumTest +@RunWith(JUnit4.class) +public class ParentalControlsTest { + @Rule public final LiveChannelsTestController controller = new LiveChannelsTestController(); private BySelector mBySettingsSidePanel; - @Override - protected void setUp() throws Exception { - super.setUp(); - mLiveChannelsHelper.assertAppStarted(); - mBySettingsSidePanel = mSidePanelHelper.bySidePanelTitled( - R.string.side_panel_title_settings); - prepareParentalControl(); + @Before + public void setUp() throws Exception { + + controller.liveChannelsHelper.assertAppStarted(); + mBySettingsSidePanel = + controller.sidePanelHelper.bySidePanelTitled(R.string.side_panel_title_settings); + // TODO(b/72154681): prepareParentalControl(); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { switchParentalControl(R.string.option_toggle_parental_controls_on); - super.tearDown(); } + @Test + public void placeHolder() { + // there must be at least one test. + } + + @Ignore("b/72154681") + @Test public void testRatingDependentSelect() { // Show ratings fragment. - BySelector bySidePanel = mSidePanelHelper.bySidePanelTitled( - R.string.option_program_restrictions); - assertWaitForCondition(mDevice, Until.hasObject(bySidePanel)); - mSidePanelHelper.assertNavigateToItem(R.string.option_ratings); - mDevice.pressDPadCenter(); + BySelector bySidePanel = + controller.sidePanelHelper.bySidePanelTitled(R.string.option_program_restrictions); + controller.assertWaitForCondition(Until.hasObject(bySidePanel)); + controller.sidePanelHelper.assertNavigateToItem(R.string.option_ratings); + controller.pressDPadCenter(); // Block rating 6 and rating 12. Check if dependent select works well. - bySidePanel = mSidePanelHelper.bySidePanelTitled(R.string.option_ratings); - assertWaitForCondition(mDevice, Until.hasObject(bySidePanel)); + bySidePanel = controller.sidePanelHelper.bySidePanelTitled(R.string.option_ratings); + controller.assertWaitForCondition(Until.hasObject(bySidePanel)); // Test on blocking and unblocking Japanese rating. int blockAge = 6; int unBlockAge = 12; int maxAge = 20; int minAge = 4; for (int age = minAge; age <= maxAge; age++) { - UiObject2 ratingCheckBox = mSidePanelHelper.assertNavigateToItem(String.valueOf(age)) - .findObject(ByResource.id(mTargetResources, R.id.check_box)); + UiObject2 ratingCheckBox = + controller + .sidePanelHelper + .assertNavigateToItem(String.valueOf(age)) + .findObject( + ByResource.id(controller.getTargetResources(), R.id.check_box)); if (ratingCheckBox.isChecked()) { - mDevice.pressDPadCenter(); + controller.pressDPadCenter(); } } - mSidePanelHelper.assertNavigateToItem(String.valueOf(blockAge)); - mDevice.pressDPadCenter(); + controller.sidePanelHelper.assertNavigateToItem(String.valueOf(blockAge)); + controller.pressDPadCenter(); assertRatingViewIsChecked(minAge, maxAge, blockAge, true); - mSidePanelHelper.assertNavigateToItem(String.valueOf(unBlockAge)); - mDevice.pressDPadCenter(); + controller.sidePanelHelper.assertNavigateToItem(String.valueOf(unBlockAge)); + controller.pressDPadCenter(); assertRatingViewIsChecked(minAge, maxAge, unBlockAge, false); - mDevice.pressBack(); - mDevice.pressBack(); - getInstrumentation().waitForIdleSync(); + controller.pressBack(); + controller.pressBack(); + controller.waitForIdleSync(); } - private void assertRatingViewIsChecked(int minAge, int maxAge, int selectedAge, - boolean expectedValue) { + private void assertRatingViewIsChecked( + int minAge, int maxAge, int selectedAge, boolean expectedValue) { for (int age = minAge; age <= maxAge; age++) { - UiObject2 ratingCheckBox = mSidePanelHelper.assertNavigateToItem(String.valueOf(age)) - .findObject(ByResource.id(mTargetResources, R.id.check_box)); + UiObject2 ratingCheckBox = + controller + .sidePanelHelper + .assertNavigateToItem(String.valueOf(age)) + .findObject( + ByResource.id(controller.getTargetResources(), R.id.check_box)); if (age < selectedAge) { assertTrue("The lower rating age should be unblocked", !ratingCheckBox.isChecked()); } else if (age > selectedAge) { assertTrue("The higher rating age should be blocked", ratingCheckBox.isChecked()); } else { - assertEquals("The rating for age " + selectedAge + " isBlocked ", expectedValue, + assertEquals( + "The rating for age " + selectedAge + " isBlocked ", + expectedValue, ratingCheckBox.isChecked()); } } } /** - * Prepare the need for testRatingDependentSelect. - * 1. Turn on parental control if it's off. - * 2. Make sure Japan rating system is selected. + * Prepare the need for testRatingDependentSelect. 1. Turn on parental control if it's off. 2. + * Make sure Japan rating system is selected. */ private void prepareParentalControl() { showParentalControl(); switchParentalControl(R.string.option_toggle_parental_controls_off); // Show all rating systems. - mSidePanelHelper.assertNavigateToItem(R.string.option_program_restrictions); - mDevice.pressDPadCenter(); - BySelector bySidePanel = mSidePanelHelper.bySidePanelTitled( - R.string.option_program_restrictions); - assertWaitForCondition(mDevice, Until.hasObject(bySidePanel)); - mSidePanelHelper.assertNavigateToItem(R.string.option_country_rating_systems); - mDevice.pressDPadCenter(); - bySidePanel = mSidePanelHelper.bySidePanelTitled(R.string.option_country_rating_systems); - assertWaitForCondition(mDevice,Until.hasObject(bySidePanel)); - mSidePanelHelper.assertNavigateToItem(R.string.option_see_all_rating_systems); - mDevice.pressDPadCenter(); + controller.sidePanelHelper.assertNavigateToItem(R.string.option_program_restrictions); + controller.pressDPadCenter(); + BySelector bySidePanel = + controller.sidePanelHelper.bySidePanelTitled(R.string.option_program_restrictions); + controller.assertWaitForCondition(Until.hasObject(bySidePanel)); + controller.sidePanelHelper.assertNavigateToItem(R.string.option_country_rating_systems); + controller.pressDPadCenter(); + bySidePanel = + controller.sidePanelHelper.bySidePanelTitled( + R.string.option_country_rating_systems); + controller.assertWaitForCondition(Until.hasObject(bySidePanel)); + controller.sidePanelHelper.assertNavigateToItem(R.string.option_see_all_rating_systems); + controller.pressDPadCenter(); // Make sure Japan rating system is selected. - UiObject2 ratingSystemCheckBox = mSidePanelHelper.assertNavigateToItem("Japan") - .findObject(ByResource.id(mTargetResources, R.id.check_box)); + UiObject2 ratingSystemCheckBox = + controller + .sidePanelHelper + .assertNavigateToItem("Japan") + .findObject(ByResource.id(controller.getTargetResources(), R.id.check_box)); if (!ratingSystemCheckBox.isChecked()) { - mDevice.pressDPadCenter(); - getInstrumentation().waitForIdleSync(); + controller.pressDPadCenter(); + controller.waitForIdleSync(); } - mDevice.pressBack(); + controller.pressBack(); } private void switchParentalControl(int oppositeStateResId) { - BySelector bySidePanel = mSidePanelHelper.byViewText(oppositeStateResId); - if (mDevice.hasObject(bySidePanel)) { - mSidePanelHelper.assertNavigateToItem(oppositeStateResId); - mDevice.pressDPadCenter(); - getInstrumentation().waitForIdleSync(); + BySelector bySidePanel = controller.sidePanelHelper.byViewText(oppositeStateResId); + if (controller.getUiDevice().hasObject(bySidePanel)) { + controller.sidePanelHelper.assertNavigateToItem(oppositeStateResId); + controller.pressDPadCenter(); + controller.waitForIdleSync(); } } private void showParentalControl() { // Show menu and select parental controls. - mMenuHelper.showMenu(); - mMenuHelper.assertPressOptionsSettings(); - assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel)); - mSidePanelHelper.assertNavigateToItem(R.string.settings_parental_controls); - mDevice.pressDPadCenter(); + controller.menuHelper.showMenu(); + controller.menuHelper.assertPressOptionsSettings(); + controller.assertWaitForCondition(Until.hasObject(mBySettingsSidePanel)); + controller.sidePanelHelper.assertNavigateToItem(R.string.settings_parental_controls); + controller.pressDPadCenter(); // Enter pin code. - DialogHelper dialogHelper = new DialogHelper(mDevice, mTargetResources); + DialogHelper dialogHelper = + new DialogHelper(controller.getUiDevice(), controller.getTargetResources()); dialogHelper.assertWaitForPinDialogOpen(); dialogHelper.enterPinCodes(); dialogHelper.assertWaitForPinDialogClose(); - BySelector bySidePanel = mSidePanelHelper.bySidePanelTitled( - R.string.menu_parental_controls); - assertWaitForCondition(mDevice, Until.hasObject(bySidePanel)); + BySelector bySidePanel = + controller.sidePanelHelper.bySidePanelTitled(R.string.menu_parental_controls); + controller.assertWaitForCondition(Until.hasObject(bySidePanel)); } } |