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
17package com.android.tv;
18
19import static com.android.tv.TimeShiftManager.TIME_SHIFT_ACTION_ID_FAST_FORWARD;
20import static com.android.tv.TimeShiftManager.TIME_SHIFT_ACTION_ID_JUMP_TO_NEXT;
21import static com.android.tv.TimeShiftManager.TIME_SHIFT_ACTION_ID_JUMP_TO_PREVIOUS;
22import static com.android.tv.TimeShiftManager.TIME_SHIFT_ACTION_ID_PAUSE;
23import static com.android.tv.TimeShiftManager.TIME_SHIFT_ACTION_ID_PLAY;
24import static com.android.tv.TimeShiftManager.TIME_SHIFT_ACTION_ID_REWIND;
25
26import android.test.suitebuilder.annotation.MediumTest;
27
28@MediumTest
29public class TimeShiftManagerTest extends BaseMainActivityTestCase {
30    private TimeShiftManager mTimeShiftManager;
31
32    public TimeShiftManagerTest() {
33        super(MainActivity.class);
34    }
35
36    @Override
37    protected void setUp() throws Exception {
38        super.setUp();
39        mTimeShiftManager = mActivity.getTimeShiftManager();
40    }
41
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
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
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
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