Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [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.statusbar.phone; |
| 18 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 19 | import static org.mockito.Mockito.mock; |
| 20 | import static org.mockito.Mockito.never; |
| 21 | import static org.mockito.Mockito.verify; |
| 22 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 23 | import android.support.test.filters.SmallTest; |
| 24 | import android.testing.AndroidTestingRunner; |
| 25 | import android.testing.TestableLooper; |
| 26 | |
| 27 | import com.android.systemui.SysuiTestCase; |
| 28 | import com.android.systemui.doze.DozeHost; |
| 29 | |
| 30 | import org.junit.Before; |
| 31 | import org.junit.Test; |
| 32 | import org.junit.runner.RunWith; |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 33 | import org.mockito.Mock; |
| 34 | import org.mockito.MockitoAnnotations; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 35 | |
| 36 | @RunWith(AndroidTestingRunner.class) |
| 37 | @TestableLooper.RunWithLooper |
| 38 | @SmallTest |
| 39 | public class DozeScrimControllerTest extends SysuiTestCase { |
| 40 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 41 | @Mock |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 42 | private DozeParameters mDozeParameters; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 43 | private DozeScrimController mDozeScrimController; |
| 44 | |
| 45 | @Before |
| 46 | public void setup() { |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 47 | MockitoAnnotations.initMocks(this); |
Lucas Dupin | 61331ce | 2018-10-02 17:57:17 -0700 | [diff] [blame] | 48 | mDozeScrimController = new DozeScrimController(mDozeParameters); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 49 | mDozeScrimController.setDozing(true); |
| 50 | } |
| 51 | |
| 52 | @Test |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 53 | public void callsPulseCallback() { |
| 54 | DozeHost.PulseCallback callback = mock(DozeHost.PulseCallback.class); |
| 55 | mDozeScrimController.pulse(callback, 0); |
| 56 | |
Lucas Dupin | 61331ce | 2018-10-02 17:57:17 -0700 | [diff] [blame] | 57 | // Manually simulate a scrim lifecycle |
| 58 | mDozeScrimController.getScrimCallback().onStart(); |
| 59 | mDozeScrimController.getScrimCallback().onDisplayBlanked(); |
| 60 | mDozeScrimController.getScrimCallback().onFinished(); |
| 61 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 62 | verify(callback).onPulseStarted(); |
| 63 | mDozeScrimController.pulseOutNow(); |
| 64 | verify(callback).onPulseFinished(); |
| 65 | } |
| 66 | |
| 67 | @Test |
| 68 | public void secondPulseIsSuppressed() { |
| 69 | DozeHost.PulseCallback callback1 = mock(DozeHost.PulseCallback.class); |
| 70 | DozeHost.PulseCallback callback2 = mock(DozeHost.PulseCallback.class); |
| 71 | mDozeScrimController.pulse(callback1, 0); |
| 72 | mDozeScrimController.pulse(callback2, 0); |
| 73 | |
| 74 | verify(callback1, never()).onPulseFinished(); |
| 75 | verify(callback2).onPulseFinished(); |
| 76 | } |
| 77 | |
| 78 | @Test |
| 79 | public void suppressesPulseIfNotDozing() { |
| 80 | mDozeScrimController.setDozing(false); |
| 81 | DozeHost.PulseCallback callback = mock(DozeHost.PulseCallback.class); |
| 82 | mDozeScrimController.pulse(callback, 0); |
| 83 | |
| 84 | verify(callback).onPulseFinished(); |
| 85 | } |
| 86 | } |