DozeScreenStateTest.java revision 2981eb0d59f3568bfe84ce905c82fc17d62d21c5
1/*
2 * Copyright (C) 2017 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.systemui.doze;
18
19import static com.android.systemui.doze.DozeMachine.State.DOZE;
20import static com.android.systemui.doze.DozeMachine.State.DOZE_AOD;
21import static com.android.systemui.doze.DozeMachine.State.DOZE_PULSING;
22import static com.android.systemui.doze.DozeMachine.State.DOZE_REQUEST_PULSE;
23import static com.android.systemui.doze.DozeMachine.State.INITIALIZED;
24import static com.android.systemui.doze.DozeMachine.State.UNINITIALIZED;
25
26import static org.junit.Assert.assertEquals;
27
28import android.support.test.filters.SmallTest;
29import android.support.test.runner.AndroidJUnit4;
30import android.view.Display;
31
32import com.android.systemui.SysuiTestCase;
33
34import org.junit.Before;
35import org.junit.Test;
36import org.junit.runner.RunWith;
37
38@RunWith(AndroidJUnit4.class)
39@SmallTest
40public class DozeScreenStateTest extends SysuiTestCase {
41
42    DozeServiceFake mServiceFake;
43    DozeScreenState mScreen;
44
45    @Before
46    public void setUp() throws Exception {
47        mServiceFake = new DozeServiceFake();
48        mScreen = new DozeScreenState(mServiceFake);
49    }
50
51    @Test
52    public void testScreen_offInDoze() {
53        mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
54        mScreen.transitionTo(INITIALIZED, DOZE);
55
56        assertEquals(Display.STATE_OFF, mServiceFake.screenState);
57    }
58
59    @Test
60    public void testScreen_onInAod() {
61        mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
62        mScreen.transitionTo(INITIALIZED, DOZE_AOD);
63
64        assertEquals(Display.STATE_DOZE_SUSPEND, mServiceFake.screenState);
65    }
66
67    @Test
68    public void testScreen_onInPulse() {
69        mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
70        mScreen.transitionTo(INITIALIZED, DOZE);
71
72        mScreen.transitionTo(DOZE, DOZE_REQUEST_PULSE);
73        mScreen.transitionTo(DOZE_REQUEST_PULSE, DOZE_PULSING);
74
75        assertEquals(Display.STATE_ON, mServiceFake.screenState);
76    }
77
78    @Test
79    public void testScreen_offInRequestPulseWithoutAoD() {
80        mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
81        mScreen.transitionTo(INITIALIZED, DOZE);
82
83        mScreen.transitionTo(DOZE, DOZE_REQUEST_PULSE);
84
85        assertEquals(Display.STATE_OFF, mServiceFake.screenState);
86    }
87
88    @Test
89    public void testScreen_onInRequestPulseWithAoD() {
90        mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
91        mScreen.transitionTo(INITIALIZED, DOZE_AOD);
92
93        mScreen.transitionTo(DOZE, DOZE_REQUEST_PULSE);
94
95        assertEquals(Display.STATE_DOZE_SUSPEND, mServiceFake.screenState);
96    }
97
98}