blob: 8a36cfbc4e2e174c7049aca54b425b6da32c1feb [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
24import android.graphics.drawable.Drawable;
Jason Monk2b48aa32017-03-27 16:41:24 -040025import android.service.quicksettings.Tile;
Jason Monk2da46192017-03-27 15:18:23 -040026import android.testing.AndroidTestingRunner;
27import android.testing.UiThreadTest;
28import android.widget.ImageView;
29
Brett Chabot84151d92019-02-27 15:37:59 -080030import androidx.test.filters.SmallTest;
31
Jason Monk2da46192017-03-27 15:18:23 -040032import 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;
39
40@RunWith(AndroidTestingRunner.class)
41@UiThreadTest
Jason Monkfba8faf2017-05-23 10:42:59 -040042@SmallTest
Jason Monk2da46192017-03-27 15:18:23 -040043public class QSIconViewImplTest extends SysuiTestCase {
44
45 private QSIconViewImpl mIconView;
46
47 @Before
48 public void setup() {
49 mIconView = new QSIconViewImpl(mContext);
50 }
51
52 @Test
53 public void testNoFirstAnimation() {
54 ImageView iv = mock(ImageView.class);
55 State s = new State();
56 when(iv.isShown()).thenReturn(true);
57
58 // No current icon, only the static drawable should be used.
59 s.icon = mock(Icon.class);
60 when(iv.getDrawable()).thenReturn(null);
Amin Shaikh32d786f2018-08-01 17:08:26 -040061 mIconView.updateIcon(iv, s, true);
Jason Monk2da46192017-03-27 15:18:23 -040062 verify(s.icon, never()).getDrawable(any());
63 verify(s.icon).getInvisibleDrawable(any());
64
65 // Has icon, should use the standard (animated) form.
66 s.icon = mock(Icon.class);
67 when(iv.getDrawable()).thenReturn(mock(Drawable.class));
Amin Shaikh32d786f2018-08-01 17:08:26 -040068 mIconView.updateIcon(iv, s, true);
Jason Monk2da46192017-03-27 15:18:23 -040069 verify(s.icon).getDrawable(any());
70 verify(s.icon, never()).getInvisibleDrawable(any());
71 }
Jason Monk2b48aa32017-03-27 16:41:24 -040072
73 @Test
74 public void testNoFirstFade() {
75 ImageView iv = mock(ImageView.class);
76 State s = new State();
77 s.state = Tile.STATE_ACTIVE;
78 int desiredColor = mIconView.getColor(s.state);
79 when(iv.isShown()).thenReturn(true);
80
Amin Shaikh32d786f2018-08-01 17:08:26 -040081 mIconView.setIcon(iv, s, true);
Jason Monk2b48aa32017-03-27 16:41:24 -040082 verify(iv).setImageTintList(argThat(stateList -> stateList.getColors()[0] == desiredColor));
83 }
Jason Monk2da46192017-03-27 15:18:23 -040084}