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