Adrian Roos | 26d8184 | 2017-02-21 15:42:20 +0100 | [diff] [blame] | 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 | |
| 17 | package com.android.systemui.doze; |
| 18 | |
| 19 | import static org.junit.Assert.assertEquals; |
| 20 | import static org.junit.Assert.assertSame; |
| 21 | import static org.mockito.Mockito.mock; |
| 22 | import static org.mockito.Mockito.verify; |
| 23 | import static org.mockito.Mockito.when; |
| 24 | |
Adrian Roos | 26d8184 | 2017-02-21 15:42:20 +0100 | [diff] [blame] | 25 | import android.view.Display; |
| 26 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 27 | import androidx.test.filters.SmallTest; |
| 28 | |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 29 | import com.android.systemui.SysuiTestCase; |
Adrian Roos | 26d8184 | 2017-02-21 15:42:20 +0100 | [diff] [blame] | 30 | import com.android.systemui.statusbar.phone.DozeParameters; |
| 31 | |
| 32 | import org.junit.Before; |
| 33 | import org.junit.Test; |
| 34 | |
| 35 | @SmallTest |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 36 | public class DozeScreenStatePreventingAdapterTest extends SysuiTestCase { |
Adrian Roos | 26d8184 | 2017-02-21 15:42:20 +0100 | [diff] [blame] | 37 | |
| 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 Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 74 | verify(mInner).setDozeScreenState(Display.STATE_ON_SUSPEND); |
Adrian Roos | 26d8184 | 2017-02-21 15:42:20 +0100 | [diff] [blame] | 75 | } |
| 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 Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 99 | } |