blob: 903e4a1efa5375fbad71790e4f4de2bbdd935ddf [file] [log] [blame]
Adrian Roos26d81842017-02-21 15:42:20 +01001/*
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 org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertSame;
21import static org.mockito.Mockito.mock;
22import static org.mockito.Mockito.verify;
23import static org.mockito.Mockito.when;
24
Adrian Roos26d81842017-02-21 15:42:20 +010025import android.view.Display;
26
Brett Chabot84151d92019-02-27 15:37:59 -080027import androidx.test.filters.SmallTest;
28
Jason Monkfba8faf2017-05-23 10:42:59 -040029import com.android.systemui.SysuiTestCase;
Adrian Roos26d81842017-02-21 15:42:20 +010030import com.android.systemui.statusbar.phone.DozeParameters;
31
32import org.junit.Before;
33import org.junit.Test;
34
35@SmallTest
Jason Monkfba8faf2017-05-23 10:42:59 -040036public class DozeScreenStatePreventingAdapterTest extends SysuiTestCase {
Adrian Roos26d81842017-02-21 15:42:20 +010037
38 private DozeMachine.Service mInner;
39 private DozeScreenStatePreventingAdapter mWrapper;
40
41 @Before
42 public void setup() throws Exception {
43 mInner = mock(DozeMachine.Service.class);
44 mWrapper = new DozeScreenStatePreventingAdapter(mInner);
45 }
46
47 @Test
48 public void forwards_finish() throws Exception {
49 mWrapper.finish();
50 verify(mInner).finish();
51 }
52
53 @Test
54 public void forwards_setDozeScreenState_on() throws Exception {
55 mWrapper.setDozeScreenState(Display.STATE_ON);
56 verify(mInner).setDozeScreenState(Display.STATE_ON);
57 }
58
59 @Test
60 public void forwards_setDozeScreenState_off() throws Exception {
61 mWrapper.setDozeScreenState(Display.STATE_OFF);
62 verify(mInner).setDozeScreenState(Display.STATE_OFF);
63 }
64
65 @Test
66 public void forwards_setDozeScreenState_doze() throws Exception {
67 mWrapper.setDozeScreenState(Display.STATE_DOZE);
68 verify(mInner).setDozeScreenState(Display.STATE_ON);
69 }
70
71 @Test
72 public void forwards_setDozeScreenState_doze_suspend() throws Exception {
73 mWrapper.setDozeScreenState(Display.STATE_DOZE_SUSPEND);
Chris Phoenix10a4a642017-09-25 13:21:00 -070074 verify(mInner).setDozeScreenState(Display.STATE_ON_SUSPEND);
Adrian Roos26d81842017-02-21 15:42:20 +010075 }
76
77 @Test
78 public void forwards_requestWakeUp() throws Exception {
79 mWrapper.requestWakeUp();
80 verify(mInner).requestWakeUp();
81 }
82
83 @Test
84 public void wrapIfNeeded_needed() throws Exception {
85 DozeParameters params = mock(DozeParameters.class);
86 when(params.getDisplayStateSupported()).thenReturn(false);
87
88 assertEquals(DozeScreenStatePreventingAdapter.class,
89 DozeScreenStatePreventingAdapter.wrapIfNeeded(mInner, params).getClass());
90 }
91
92 @Test
93 public void wrapIfNeeded_not_needed() throws Exception {
94 DozeParameters params = mock(DozeParameters.class);
95 when(params.getDisplayStateSupported()).thenReturn(true);
96
97 assertSame(mInner, DozeScreenStatePreventingAdapter.wrapIfNeeded(mInner, params));
98 }
Chris Phoenix10a4a642017-09-25 13:21:00 -070099}