blob: 4cc0e20dd96493acadde0b55307dfe1a2cba012f [file] [log] [blame]
Jason Monkf6a3cf92016-02-29 13:01:08 -05001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui.qs;
16
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040017import android.support.test.runner.AndroidJUnit4;
Jason Monk0c6e0992016-03-29 15:49:02 -040018import android.test.suitebuilder.annotation.SmallTest;
Jason Monkf6a3cf92016-02-29 13:01:08 -050019import android.view.View;
Jason Monkf6a3cf92016-02-29 13:01:08 -050020import com.android.systemui.qs.TouchAnimator.Listener;
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040021import com.android.systemui.SysuiTestCase;
22import org.junit.Before;
23import org.junit.runner.RunWith;
24import org.junit.Test;
Jason Monkf6a3cf92016-02-29 13:01:08 -050025import org.mockito.Mockito;
26
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040027import static junit.framework.Assert.assertEquals;
28
Jason Monk0c6e0992016-03-29 15:49:02 -040029@SmallTest
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040030@RunWith(AndroidJUnit4.class)
Geoffrey Pitschfc2b64e2016-09-02 09:05:25 -040031public class TouchAnimatorTest extends SysuiTestCase {
Jason Monkf6a3cf92016-02-29 13:01:08 -050032
33 private Listener mTouchListener;
34 private View mTestView;
35
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040036 @Before
37 public void setUp() throws Exception {
Jason Monkf6a3cf92016-02-29 13:01:08 -050038 mTestView = new View(getContext());
39 mTouchListener = Mockito.mock(Listener.class);
40 }
41
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040042 @Test
Jason Monkf6a3cf92016-02-29 13:01:08 -050043 public void testSetValueFloat() {
44 TouchAnimator animator = new TouchAnimator.Builder()
45 .addFloat(mTestView, "x", 0, 50)
46 .build();
47
48 animator.setPosition(0);
49 assertEquals(0f, mTestView.getX());
50
51 animator.setPosition(.5f);
52 assertEquals(25f, mTestView.getX());
53
54 animator.setPosition(1);
55 assertEquals(50f, mTestView.getX());
56 }
57
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040058 @Test
Amin Shaikhd620def2018-02-27 16:52:53 -050059 public void testSetValueFloat_threeValues() {
60 TouchAnimator animator = new TouchAnimator.Builder()
61 .addFloat(mTestView, "x", 0, 20, 50)
62 .build();
63
64 animator.setPosition(0);
65 assertEquals(0f, mTestView.getX());
66
67 animator.setPosition(.25f);
68 assertEquals(10f, mTestView.getX());
69
70 animator.setPosition(.5f);
71 assertEquals(20f, mTestView.getX());
72
73 animator.setPosition(.75f);
74 assertEquals(35f, mTestView.getX());
75
76 animator.setPosition(1);
77 assertEquals(50f, mTestView.getX());
78 }
79
80 @Test
Jason Monkf6a3cf92016-02-29 13:01:08 -050081 public void testSetValueInt() {
82 TouchAnimator animator = new TouchAnimator.Builder()
83 .addInt(mTestView, "top", 0, 50)
84 .build();
85
86 animator.setPosition(0);
87 assertEquals(0, mTestView.getTop());
88
89 animator.setPosition(.5f);
90 assertEquals(25, mTestView.getTop());
91
92 animator.setPosition(1);
93 assertEquals(50, mTestView.getTop());
94 }
95
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040096 @Test
Jason Monkf6a3cf92016-02-29 13:01:08 -050097 public void testStartDelay() {
98 TouchAnimator animator = new TouchAnimator.Builder()
99 .addFloat(mTestView, "x", 0, 50)
100 .setStartDelay(.5f)
101 .build();
102
103 animator.setPosition(0);
104 assertEquals(0f, mTestView.getX());
105
106 animator.setPosition(.5f);
107 assertEquals(0f, mTestView.getX());
108
109 animator.setPosition(.75f);
110 assertEquals(25f, mTestView.getX());
111
112 animator.setPosition(1);
113 assertEquals(50f, mTestView.getX());
114 }
115
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400116 @Test
Jason Monkf6a3cf92016-02-29 13:01:08 -0500117 public void testEndDelay() {
118 TouchAnimator animator = new TouchAnimator.Builder()
119 .addFloat(mTestView, "x", 0, 50)
120 .setEndDelay(.5f)
121 .build();
122
123 animator.setPosition(0);
124 assertEquals(0f, mTestView.getX());
125
126 animator.setPosition(.25f);
127 assertEquals(25f, mTestView.getX());
128
129 animator.setPosition(.5f);
130 assertEquals(50f, mTestView.getX());
131
132 animator.setPosition(1);
133 assertEquals(50f, mTestView.getX());
134 }
135
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400136 @Test
Jason Monkf6a3cf92016-02-29 13:01:08 -0500137 public void testOnAnimationAtStartCallback() {
138 TouchAnimator animator = new TouchAnimator.Builder()
139 .setListener(mTouchListener)
140 .build();
141
142 // Called on init.
143 animator.setPosition(0);
144 verifyOnAnimationAtStart(1);
145
146 // Not called from same state.
147 animator.setPosition(0);
148 verifyOnAnimationAtStart(1);
149
150 // Called after starting and moving back to start.
151 animator.setPosition(.5f);
152 animator.setPosition(0);
153 verifyOnAnimationAtStart(2);
154
155 // Called when move from end to end.
156 animator.setPosition(1);
157 animator.setPosition(0);
158 verifyOnAnimationAtStart(3);
159 }
160
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400161 @Test
Jason Monkf6a3cf92016-02-29 13:01:08 -0500162 public void testOnAnimationAtEndCallback() {
163 TouchAnimator animator = new TouchAnimator.Builder()
164 .setListener(mTouchListener)
165 .build();
166
167 // Called on init.
168 animator.setPosition(1);
169 verifyOnAnimationAtEnd(1);
170
171 // Not called from same state.
172 animator.setPosition(1);
173 verifyOnAnimationAtEnd(1);
174
175 // Called after starting and moving back to end.
176 animator.setPosition(.5f);
177 animator.setPosition(1);
178 verifyOnAnimationAtEnd(2);
179
180 // Called when move from end to end.
181 animator.setPosition(0);
182 animator.setPosition(1);
183 verifyOnAnimationAtEnd(3);
184 }
185
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400186 @Test
Jason Monkf6a3cf92016-02-29 13:01:08 -0500187 public void testOnAnimationStartedCallback() {
188 TouchAnimator animator = new TouchAnimator.Builder()
189 .setListener(mTouchListener)
190 .build();
191
192 // Called on init.
193 animator.setPosition(.5f);
194 verifyOnAnimationStarted(1);
195
196 // Not called from same state.
197 animator.setPosition(.6f);
198 verifyOnAnimationStarted(1);
199
200 // Called after going to end then moving again.
201 animator.setPosition(1);
202 animator.setPosition(.5f);
203 verifyOnAnimationStarted(2);
204
205 // Called after moving to start then moving again.
206 animator.setPosition(0);
207 animator.setPosition(.5f);
208 verifyOnAnimationStarted(3);
209 }
210
211 // TODO: Add test for interpolator.
212
213 private void verifyOnAnimationAtStart(int times) {
214 Mockito.verify(mTouchListener, Mockito.times(times)).onAnimationAtStart();
215 }
216
217 private void verifyOnAnimationAtEnd(int times) {
218 Mockito.verify(mTouchListener, Mockito.times(times)).onAnimationAtEnd();
219 }
220
221 private void verifyOnAnimationStarted(int times) {
222 Mockito.verify(mTouchListener, Mockito.times(times)).onAnimationStarted();
223 }
224}