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 org.junit.Assert.assertEquals; 26 27 import android.support.test.filters.MediumTest; 28 29 import org.junit.Before; 30 import org.junit.Test; 31 32 @MediumTest 33 public class TimeShiftManagerTest extends BaseMainActivityTestCase { 34 private TimeShiftManager mTimeShiftManager; 35 36 @Override 37 @Before 38 public void setUp() { 39 super.setUp(); 40 mTimeShiftManager = mActivity.getTimeShiftManager(); 41 } 42 43 @Test 44 public void testDisableActions() { 45 enableAllActions(true); 46 assertActionState(true, true, true, true, true, true); 47 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_PLAY, false); 48 assertActionState(false, true, true, true, true, true); 49 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_PAUSE, false); 50 assertActionState(false, false, true, true, true, true); 51 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_REWIND, false); 52 assertActionState(false, false, false, true, true, true); 53 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_FAST_FORWARD, false); 54 assertActionState(false, false, false, false, true, true); 55 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_JUMP_TO_PREVIOUS, false); 56 assertActionState(false, false, false, false, false, true); 57 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_JUMP_TO_NEXT, false); 58 assertActionState(false, false, false, false, false, false); 59 } 60 61 @Test 62 public void testEnableActions() { 63 enableAllActions(false); 64 assertActionState(false, false, false, false, false, false); 65 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_PLAY, true); 66 assertActionState(true, false, false, false, false, false); 67 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_PAUSE, true); 68 assertActionState(true, true, false, false, false, false); 69 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_REWIND, true); 70 assertActionState(true, true, true, false, false, false); 71 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_FAST_FORWARD, true); 72 assertActionState(true, true, true, true, false, false); 73 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_JUMP_TO_PREVIOUS, true); 74 assertActionState(true, true, true, true, true, false); 75 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_JUMP_TO_NEXT, true); 76 assertActionState(true, true, true, true, true, true); 77 } 78 79 private void enableAllActions(boolean enabled) { 80 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_PLAY, enabled); 81 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_PAUSE, enabled); 82 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_REWIND, enabled); 83 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_FAST_FORWARD, enabled); 84 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_JUMP_TO_PREVIOUS, enabled); 85 mTimeShiftManager.enableAction(TIME_SHIFT_ACTION_ID_JUMP_TO_NEXT, enabled); 86 } 87 88 private void assertActionState(boolean playEnabled, boolean pauseEnabled, boolean rewindEnabled, 89 boolean fastForwardEnabled, boolean jumpToPreviousEnabled, boolean jumpToNextEnabled) { 90 assertEquals("Play Action", playEnabled, 91 mTimeShiftManager.isActionEnabled(TIME_SHIFT_ACTION_ID_PLAY)); 92 assertEquals("Pause Action", pauseEnabled, 93 mTimeShiftManager.isActionEnabled(TIME_SHIFT_ACTION_ID_PAUSE)); 94 assertEquals("Rewind Action", rewindEnabled, 95 mTimeShiftManager.isActionEnabled(TIME_SHIFT_ACTION_ID_REWIND)); 96 assertEquals("Fast Forward Action", fastForwardEnabled, 97 mTimeShiftManager.isActionEnabled(TIME_SHIFT_ACTION_ID_FAST_FORWARD)); 98 assertEquals("Jump To Previous Action", jumpToPreviousEnabled, 99 mTimeShiftManager.isActionEnabled(TIME_SHIFT_ACTION_ID_JUMP_TO_PREVIOUS)); 100 assertEquals("Jump To Next Action", jumpToNextEnabled, 101 mTimeShiftManager.isActionEnabled(TIME_SHIFT_ACTION_ID_JUMP_TO_NEXT)); 102 } 103 } 104