Adrian Roos | 540b528 | 2017-05-15 13:29:49 -0700 | [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 | |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 19 | import static com.android.systemui.doze.DozeMachine.State.DOZE; |
Adrian Roos | 540b528 | 2017-05-15 13:29:49 -0700 | [diff] [blame] | 20 | import static com.android.systemui.doze.DozeMachine.State.DOZE_AOD; |
| 21 | import static com.android.systemui.doze.DozeMachine.State.DOZE_AOD_PAUSED; |
| 22 | import static com.android.systemui.doze.DozeMachine.State.INITIALIZED; |
| 23 | import static com.android.systemui.doze.DozeMachine.State.UNINITIALIZED; |
| 24 | |
| 25 | import static org.mockito.ArgumentMatchers.any; |
| 26 | import static org.mockito.ArgumentMatchers.anyInt; |
| 27 | import static org.mockito.ArgumentMatchers.anyLong; |
| 28 | import static org.mockito.ArgumentMatchers.eq; |
| 29 | import static org.mockito.Mockito.clearInvocations; |
| 30 | import static org.mockito.Mockito.mock; |
| 31 | import static org.mockito.Mockito.verify; |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 32 | import static org.mockito.Mockito.when; |
Adrian Roos | 540b528 | 2017-05-15 13:29:49 -0700 | [diff] [blame] | 33 | |
| 34 | import android.app.AlarmManager; |
Adrian Roos | 540b528 | 2017-05-15 13:29:49 -0700 | [diff] [blame] | 35 | import android.os.Handler; |
| 36 | import android.os.HandlerThread; |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 37 | import android.support.test.filters.SmallTest; |
Adrian Roos | 540b528 | 2017-05-15 13:29:49 -0700 | [diff] [blame] | 38 | import android.support.test.runner.AndroidJUnit4; |
| 39 | |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 40 | import com.android.systemui.SysuiTestCase; |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 41 | import com.android.systemui.statusbar.phone.DozeParameters; |
Adrian Roos | 540b528 | 2017-05-15 13:29:49 -0700 | [diff] [blame] | 42 | import com.android.systemui.util.wakelock.WakeLockFake; |
| 43 | |
| 44 | import org.junit.After; |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 45 | import org.junit.Assert; |
Adrian Roos | 540b528 | 2017-05-15 13:29:49 -0700 | [diff] [blame] | 46 | import org.junit.Before; |
| 47 | import org.junit.Test; |
| 48 | import org.junit.runner.RunWith; |
| 49 | |
| 50 | @RunWith(AndroidJUnit4.class) |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 51 | @SmallTest |
| 52 | public class DozeUiTest extends SysuiTestCase { |
Adrian Roos | 540b528 | 2017-05-15 13:29:49 -0700 | [diff] [blame] | 53 | |
Adrian Roos | 540b528 | 2017-05-15 13:29:49 -0700 | [diff] [blame] | 54 | private AlarmManager mAlarmManager; |
| 55 | private DozeMachine mMachine; |
| 56 | private WakeLockFake mWakeLock; |
| 57 | private DozeHostFake mHost; |
| 58 | private Handler mHandler; |
| 59 | private HandlerThread mHandlerThread; |
| 60 | private DozeUi mDozeUi; |
| 61 | |
| 62 | @Before |
| 63 | public void setUp() throws Exception { |
| 64 | mHandlerThread = new HandlerThread("DozeUiTest"); |
| 65 | mHandlerThread.start(); |
Adrian Roos | 540b528 | 2017-05-15 13:29:49 -0700 | [diff] [blame] | 66 | mAlarmManager = mock(AlarmManager.class); |
| 67 | mMachine = mock(DozeMachine.class); |
| 68 | mWakeLock = new WakeLockFake(); |
| 69 | mHost = new DozeHostFake(); |
| 70 | mHandler = mHandlerThread.getThreadHandler(); |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 71 | DozeParameters params = mock(DozeParameters.class); |
| 72 | when(params.getCanControlScreenOffAnimation()).thenReturn(true); |
| 73 | when(params.getDisplayNeedsBlanking()).thenReturn(false); |
Adrian Roos | 540b528 | 2017-05-15 13:29:49 -0700 | [diff] [blame] | 74 | |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 75 | mDozeUi = new DozeUi(mContext, mAlarmManager, mMachine, mWakeLock, mHost, mHandler, params); |
Adrian Roos | 540b528 | 2017-05-15 13:29:49 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @After |
| 79 | public void tearDown() throws Exception { |
| 80 | mHandlerThread.quit(); |
| 81 | mHandler = null; |
| 82 | mHandlerThread = null; |
| 83 | } |
| 84 | |
| 85 | @Test |
| 86 | public void pausingAndUnpausingAod_registersTimeTickAfterUnpausing() throws Exception { |
| 87 | mDozeUi.transitionTo(UNINITIALIZED, INITIALIZED); |
| 88 | mDozeUi.transitionTo(INITIALIZED, DOZE_AOD); |
| 89 | mDozeUi.transitionTo(DOZE_AOD, DOZE_AOD_PAUSED); |
| 90 | |
| 91 | clearInvocations(mAlarmManager); |
| 92 | |
| 93 | mDozeUi.transitionTo(DOZE_AOD_PAUSED, DOZE_AOD); |
| 94 | |
| 95 | verify(mAlarmManager).setExact(anyInt(), anyLong(), eq("doze_time_tick"), any(), any()); |
| 96 | } |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 97 | |
| 98 | @Test |
| 99 | public void propagatesAnimateScreenOff() { |
| 100 | Assert.assertTrue("animateScreenOff should be true", mHost.animateScreenOff); |
| 101 | |
| 102 | DozeParameters params = mock(DozeParameters.class); |
| 103 | new DozeUi(mContext, mAlarmManager, mMachine, mWakeLock, mHost, mHandler, params); |
| 104 | Assert.assertFalse("animateScreenOff should be false", mHost.animateScreenOff); |
| 105 | } |
| 106 | |
| 107 | @Test |
| 108 | public void transitionSetsAnimateWakeup() { |
| 109 | mHost.animateWakeup = false; |
| 110 | mDozeUi.transitionTo(UNINITIALIZED, DOZE); |
| 111 | Assert.assertTrue("animateScreenOff should be true", mHost.animateWakeup); |
| 112 | } |
Adrian Roos | 540b528 | 2017-05-15 13:29:49 -0700 | [diff] [blame] | 113 | } |