1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.tv; 18 19 import static com.android.tv.TimeShiftManager.TIME_SHIFT_ACTION_ID_FAST_FORWARD; 20 import static com.android.tv.TimeShiftManager.TIME_SHIFT_ACTION_ID_JUMP_TO_NEXT; 21 import static com.android.tv.TimeShiftManager.TIME_SHIFT_ACTION_ID_JUMP_TO_PREVIOUS; 22 import static com.android.tv.TimeShiftManager.TIME_SHIFT_ACTION_ID_PAUSE; 23 import static com.android.tv.TimeShiftManager.TIME_SHIFT_ACTION_ID_PLAY; 24 import static com.android.tv.TimeShiftManager.TIME_SHIFT_ACTION_ID_REWIND; 25 import static com.google.common.truth.Truth.assertWithMessage; 26 27 import androidx.test.filters.MediumTest; 28 import androidx.test.runner.AndroidJUnit4; 29 import com.android.tv.testing.activities.BaseMainActivityTestCase; 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 34 @MediumTest 35 @RunWith(AndroidJUnit4.class) 36 public class TimeShiftManagerTest extends BaseMainActivityTestCase { 37 private TimeShiftManager mTimeShiftManager; 38 39 @Override 40 @Before setUp()41 public void setUp() { 42 super.setUp(); 43 mTimeShiftManager = mActivity.getTimeShiftManager(); 44 } 45 46 @Test testDisableActions()47 public void testDisableActions() { 48 enableAllActions(true); 49 assertActionState(true, true, true, true, true, true); 50 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_PLAY, false); 51 assertActionState(false, true, true, true, true, true); 52 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_PAUSE, false); 53 assertActionState(false, false, true, true, true, true); 54 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_REWIND, false); 55 assertActionState(false, false, false, true, true, true); 56 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_FAST_FORWARD, false); 57 assertActionState(false, false, false, false, true, true); 58 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_JUMP_TO_PREVIOUS, false); 59 assertActionState(false, false, false, false, false, true); 60 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_JUMP_TO_NEXT, false); 61 assertActionState(false, false, false, false, false, false); 62 } 63 64 @Test testEnableActions()65 public void testEnableActions() { 66 enableAllActions(false); 67 assertActionState(false, false, false, false, false, false); 68 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_PLAY, true); 69 assertActionState(true, false, false, false, false, false); 70 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_PAUSE, true); 71 assertActionState(true, true, false, false, false, false); 72 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_REWIND, true); 73 assertActionState(true, true, true, false, false, false); 74 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_FAST_FORWARD, true); 75 assertActionState(true, true, true, true, false, false); 76 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_JUMP_TO_PREVIOUS, true); 77 assertActionState(true, true, true, true, true, false); 78 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_JUMP_TO_NEXT, true); 79 assertActionState(true, true, true, true, true, true); 80 } 81 enableAllActions(boolean enabled)82 private void enableAllActions(boolean enabled) { 83 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_PLAY, enabled); 84 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_PAUSE, enabled); 85 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_REWIND, enabled); 86 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_FAST_FORWARD, enabled); 87 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_JUMP_TO_PREVIOUS, enabled); 88 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_JUMP_TO_NEXT, enabled); 89 } 90 assertActionState( boolean playEnabled, boolean pauseEnabled, boolean rewindEnabled, boolean fastForwardEnabled, boolean jumpToPreviousEnabled, boolean jumpToNextEnabled)91 private void assertActionState( 92 boolean playEnabled, 93 boolean pauseEnabled, 94 boolean rewindEnabled, 95 boolean fastForwardEnabled, 96 boolean jumpToPreviousEnabled, 97 boolean jumpToNextEnabled) { 98 assertWithMessage("Play Action") 99 .that(mTimeShiftManager.isActionEnabled(TIME_SHIFT_ACTION_ID_PLAY)) 100 .isEqualTo(playEnabled); 101 assertWithMessage("Pause Action") 102 .that(mTimeShiftManager.isActionEnabled(TIME_SHIFT_ACTION_ID_PAUSE)) 103 .isEqualTo(pauseEnabled); 104 assertWithMessage("Rewind Action") 105 .that(mTimeShiftManager.isActionEnabled(TIME_SHIFT_ACTION_ID_REWIND)) 106 .isEqualTo(rewindEnabled); 107 assertWithMessage("Fast Forward Action") 108 .that(mTimeShiftManager.isActionEnabled(TIME_SHIFT_ACTION_ID_FAST_FORWARD)) 109 .isEqualTo(fastForwardEnabled); 110 assertWithMessage("Jump To Previous Action") 111 .that(mTimeShiftManager.isActionEnabled(TIME_SHIFT_ACTION_ID_JUMP_TO_PREVIOUS)) 112 .isEqualTo(jumpToPreviousEnabled); 113 assertWithMessage("Jump To Next Action") 114 .that(mTimeShiftManager.isActionEnabled(TIME_SHIFT_ACTION_ID_JUMP_TO_NEXT)) 115 .isEqualTo(jumpToNextEnabled); 116 } 117 } 118