blob: c5e404385f8bbd14ade82e57225ff05d6534e799 [file] [log] [blame]
Jason Monk2da46192017-03-27 15:18:23 -04001/*
2 * Copyright (C) 2017 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.tileimpl;
16
17import static org.mockito.ArgumentMatchers.any;
Jason Monk2b48aa32017-03-27 16:41:24 -040018import static org.mockito.ArgumentMatchers.argThat;
Jason Monk2da46192017-03-27 15:18:23 -040019import static org.mockito.Mockito.mock;
20import static org.mockito.Mockito.never;
21import static org.mockito.Mockito.verify;
22import static org.mockito.Mockito.when;
23
Jason Monk2b48aa32017-03-27 16:41:24 -040024import android.content.res.ColorStateList;
Jason Monk2da46192017-03-27 15:18:23 -040025import android.graphics.drawable.Drawable;
Jason Monk2b48aa32017-03-27 16:41:24 -040026import android.service.quicksettings.Tile;
Jason Monkfba8faf2017-05-23 10:42:59 -040027import android.support.test.filters.SmallTest;
Jason Monk2da46192017-03-27 15:18:23 -040028import android.testing.AndroidTestingRunner;
29import android.testing.UiThreadTest;
30import android.widget.ImageView;
31
32import com.android.systemui.SysuiTestCase;
33import com.android.systemui.plugins.qs.QSTile.Icon;
34import com.android.systemui.plugins.qs.QSTile.State;
35
36import org.junit.Before;
37import org.junit.Test;
38import org.junit.runner.RunWith;
Jason Monk2b48aa32017-03-27 16:41:24 -040039import org.mockito.ArgumentMatcher;
Jason Monk2da46192017-03-27 15:18:23 -040040
41@RunWith(AndroidTestingRunner.class)
42@UiThreadTest
Jason Monkfba8faf2017-05-23 10:42:59 -040043@SmallTest
Jason Monk2da46192017-03-27 15:18:23 -040044public class QSIconViewImplTest extends SysuiTestCase {
45
46 private QSIconViewImpl mIconView;
47
48 @Before
49 public void setup() {
50 mIconView = new QSIconViewImpl(mContext);
51 }
52
53 @Test
54 public void testNoFirstAnimation() {
55 ImageView iv = mock(ImageView.class);
56 State s = new State();
57 when(iv.isShown()).thenReturn(true);
58
59 // No current icon, only the static drawable should be used.
60 s.icon = mock(Icon.class);
61 when(iv.getDrawable()).thenReturn(null);
Amin Shaikh32d786f2018-08-01 17:08:26 -040062 mIconView.updateIcon(iv, s, true);
Jason Monk2da46192017-03-27 15:18:23 -040063 verify(s.icon, never()).getDrawable(any());
64 verify(s.icon).getInvisibleDrawable(any());
65
66 // Has icon, should use the standard (animated) form.
67 s.icon = mock(Icon.class);
68 when(iv.getDrawable()).thenReturn(mock(Drawable.class));
Amin Shaikh32d786f2018-08-01 17:08:26 -040069 mIconView.updateIcon(iv, s, true);
Jason Monk2da46192017-03-27 15:18:23 -040070 verify(s.icon).getDrawable(any());
71 verify(s.icon, never()).getInvisibleDrawable(any());
72 }
Jason Monk2b48aa32017-03-27 16:41:24 -040073
74 @Test
75 public void testNoFirstFade() {
76 ImageView iv = mock(ImageView.class);
77 State s = new State();
78 s.state = Tile.STATE_ACTIVE;
79 int desiredColor = mIconView.getColor(s.state);
80 when(iv.isShown()).thenReturn(true);
81
Amin Shaikh32d786f2018-08-01 17:08:26 -040082 mIconView.setIcon(iv, s, true);
Jason Monk2b48aa32017-03-27 16:41:24 -040083 verify(iv).setImageTintList(argThat(stateList -> stateList.getColors()[0] == desiredColor));
84 }
Jason Monk2da46192017-03-27 15:18:23 -040085}