blob: f6f4eb489603bf3a91b935166a3f4808fcf173ad [file] [log] [blame]
Adrian Roos5753f052016-07-13 10:30:37 -07001/*
2 * Copyright (C) 2016 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
Geoffrey Pitschfc2b64e2016-09-02 09:05:25 -040017package com.android.systemui.statusbar.phone;
Adrian Roos5753f052016-07-13 10:30:37 -070018
Brett Chabot84151d92019-02-27 15:37:59 -080019import static junit.framework.Assert.assertFalse;
20import static junit.framework.Assert.assertTrue;
21import static junit.framework.Assert.fail;
22
23import static org.mockito.ArgumentMatchers.eq;
24import static org.mockito.Mockito.mock;
25import static org.mockito.Mockito.reset;
26import static org.mockito.Mockito.verify;
27
Lucas Dupin16cfe452018-02-08 13:14:50 -080028import android.content.Context;
29import android.os.PowerManager;
Adrian Roos5753f052016-07-13 10:30:37 -070030import android.test.suitebuilder.annotation.SmallTest;
Jason Monkfba8faf2017-05-23 10:42:59 -040031
Brett Chabot84151d92019-02-27 15:37:59 -080032import androidx.test.runner.AndroidJUnit4;
33
Jason Monkfba8faf2017-05-23 10:42:59 -040034import com.android.systemui.SysuiTestCase;
Lucas Dupincbe05962018-04-26 16:44:05 -070035import com.android.systemui.doze.DozeScreenState;
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040036import com.android.systemui.statusbar.phone.DozeParameters.IntInOutMatcher;
Lucas Dupin16cfe452018-02-08 13:14:50 -080037
38import org.junit.Assert;
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040039import org.junit.Test;
40import org.junit.runner.RunWith;
41
Adrian Roos5753f052016-07-13 10:30:37 -070042@SmallTest
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040043@RunWith(AndroidJUnit4.class)
Jason Monkfba8faf2017-05-23 10:42:59 -040044public class DozeParametersTest extends SysuiTestCase {
Adrian Roos5753f052016-07-13 10:30:37 -070045
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040046 @Test
Adrian Roos5753f052016-07-13 10:30:37 -070047 public void test_inOutMatcher_defaultIn() {
48 IntInOutMatcher intInOutMatcher = new IntInOutMatcher("*");
49
50 assertTrue(intInOutMatcher.isIn(1));
51 assertTrue(intInOutMatcher.isIn(-1));
52 assertTrue(intInOutMatcher.isIn(0));
53 }
54
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040055 @Test
Adrian Roos5753f052016-07-13 10:30:37 -070056 public void test_inOutMatcher_defaultOut() {
57 IntInOutMatcher intInOutMatcher = new IntInOutMatcher("!*");
58
59 assertFalse(intInOutMatcher.isIn(1));
60 assertFalse(intInOutMatcher.isIn(-1));
61 assertFalse(intInOutMatcher.isIn(0));
62 }
63
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040064 @Test
Adrian Roos5753f052016-07-13 10:30:37 -070065 public void test_inOutMatcher_someIn() {
66 IntInOutMatcher intInOutMatcher = new IntInOutMatcher("1,2,3,!*");
67
68 assertTrue(intInOutMatcher.isIn(1));
69 assertTrue(intInOutMatcher.isIn(2));
70 assertTrue(intInOutMatcher.isIn(3));
71
72 assertFalse(intInOutMatcher.isIn(0));
73 assertFalse(intInOutMatcher.isIn(4));
74 }
75
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040076 @Test
Adrian Roos5753f052016-07-13 10:30:37 -070077 public void test_inOutMatcher_someOut() {
78 IntInOutMatcher intInOutMatcher = new IntInOutMatcher("!1,!2,!3,*");
79
80 assertFalse(intInOutMatcher.isIn(1));
81 assertFalse(intInOutMatcher.isIn(2));
82 assertFalse(intInOutMatcher.isIn(3));
83
84 assertTrue(intInOutMatcher.isIn(0));
85 assertTrue(intInOutMatcher.isIn(4));
86 }
87
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040088 @Test
Adrian Roos5753f052016-07-13 10:30:37 -070089 public void test_inOutMatcher_mixed() {
90 IntInOutMatcher intInOutMatcher = new IntInOutMatcher("!1,2,!3,*");
91
92 assertFalse(intInOutMatcher.isIn(1));
93 assertTrue(intInOutMatcher.isIn(2));
94 assertFalse(intInOutMatcher.isIn(3));
95
96 assertTrue(intInOutMatcher.isIn(0));
97 assertTrue(intInOutMatcher.isIn(4));
98 }
99
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400100 @Test
Adrian Roos5753f052016-07-13 10:30:37 -0700101 public void test_inOutMatcher_failEmpty() {
102 try {
103 new IntInOutMatcher("");
104 fail("Expected IllegalArgumentException");
105 } catch (IllegalArgumentException e) {
106 // expected
107 }
108 }
109
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400110 @Test
Adrian Roos5753f052016-07-13 10:30:37 -0700111 public void test_inOutMatcher_failNull() {
112 try {
113 new IntInOutMatcher(null);
114 fail("Expected IllegalArgumentException");
115 } catch (IllegalArgumentException e) {
116 // expected
117 }
118 }
119
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400120 @Test
Adrian Roos5753f052016-07-13 10:30:37 -0700121 public void test_inOutMatcher_failEmptyClause() {
122 try {
123 new IntInOutMatcher("!1,*,");
124 fail("Expected IllegalArgumentException");
125 } catch (IllegalArgumentException e) {
126 // expected
127 }
128 }
129
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400130 @Test
Adrian Roos5753f052016-07-13 10:30:37 -0700131 public void test_inOutMatcher_failDuplicate() {
132 try {
133 new IntInOutMatcher("!1,*,!1");
134 fail("Expected IllegalArgumentException");
135 } catch (IllegalArgumentException e) {
136 // expected
137 }
138 }
139
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400140 @Test
Adrian Roos5753f052016-07-13 10:30:37 -0700141 public void test_inOutMatcher_failDuplicateDefault() {
142 try {
143 new IntInOutMatcher("!1,*,*");
144 fail("Expected IllegalArgumentException");
145 } catch (IllegalArgumentException e) {
146 // expected
147 }
148 }
149
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400150 @Test
Adrian Roos5753f052016-07-13 10:30:37 -0700151 public void test_inOutMatcher_failMalformedNot() {
152 try {
153 new IntInOutMatcher("!,*");
154 fail("Expected IllegalArgumentException");
155 } catch (IllegalArgumentException e) {
156 // expected
157 }
158 }
159
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400160 @Test
Adrian Roos5753f052016-07-13 10:30:37 -0700161 public void test_inOutMatcher_failText() {
162 try {
163 new IntInOutMatcher("!abc,*");
164 fail("Expected IllegalArgumentException");
165 } catch (IllegalArgumentException e) {
166 // expected
167 }
168 }
169
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400170 @Test
Adrian Roos5753f052016-07-13 10:30:37 -0700171 public void test_inOutMatcher_failContradiction() {
172 try {
173 new IntInOutMatcher("1,!1,*");
174 fail("Expected IllegalArgumentException");
175 } catch (IllegalArgumentException e) {
176 // expected
177 }
178 }
179
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400180 @Test
Adrian Roos5753f052016-07-13 10:30:37 -0700181 public void test_inOutMatcher_failContradictionDefault() {
182 try {
183 new IntInOutMatcher("1,*,!*");
184 fail("Expected IllegalArgumentException");
185 } catch (IllegalArgumentException e) {
186 // expected
187 }
188 }
189
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400190 @Test
Adrian Roos5753f052016-07-13 10:30:37 -0700191 public void test_inOutMatcher_failMissingDefault() {
192 try {
193 new IntInOutMatcher("1");
194 fail("Expected IllegalArgumentException");
195 } catch (IllegalArgumentException e) {
196 // expected
197 }
198 }
199
Lucas Dupin16cfe452018-02-08 13:14:50 -0800200 @Test
201 public void test_setControlScreenOffAnimation_setsDozeAfterScreenOff_false() {
202 TestableDozeParameters dozeParameters = new TestableDozeParameters(getContext());
203 PowerManager mockedPowerManager = dozeParameters.getPowerManager();
204 dozeParameters.setControlScreenOffAnimation(true);
205 reset(mockedPowerManager);
206 dozeParameters.setControlScreenOffAnimation(false);
207 verify(mockedPowerManager).setDozeAfterScreenOff(eq(true));
208 }
209
210 @Test
211 public void test_setControlScreenOffAnimation_setsDozeAfterScreenOff_true() {
212 TestableDozeParameters dozeParameters = new TestableDozeParameters(getContext());
213 PowerManager mockedPowerManager = dozeParameters.getPowerManager();
214 dozeParameters.setControlScreenOffAnimation(false);
215 reset(mockedPowerManager);
216 dozeParameters.setControlScreenOffAnimation(true);
217 verify(dozeParameters.getPowerManager()).setDozeAfterScreenOff(eq(false));
218 }
219
Lucas Dupincbe05962018-04-26 16:44:05 -0700220 @Test
221 public void test_getWallpaperAodDuration_when_shouldControlScreenOff() {
222 TestableDozeParameters dozeParameters = new TestableDozeParameters(getContext());
223 dozeParameters.setControlScreenOffAnimation(true);
224 Assert.assertEquals("wallpaper hides faster when controlling screen off",
225 dozeParameters.getWallpaperAodDuration(),
226 DozeScreenState.ENTER_DOZE_HIDE_WALLPAPER_DELAY);
227 }
228
Lucas Dupin16cfe452018-02-08 13:14:50 -0800229 private class TestableDozeParameters extends DozeParameters {
230 private PowerManager mPowerManager;
231
232 TestableDozeParameters(Context context) {
233 super(context);
234 mPowerManager = mock(PowerManager.class);
235 }
236
237 @Override
238 protected PowerManager getPowerManager() {
239 return mPowerManager;
240 }
241 }
242
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400243}