Jason Monk | 2da4619 | 2017-03-27 15:18:23 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | package com.android.systemui.qs.tileimpl; |
| 16 | |
| 17 | import static org.mockito.ArgumentMatchers.any; |
Jason Monk | 2b48aa3 | 2017-03-27 16:41:24 -0400 | [diff] [blame] | 18 | import static org.mockito.ArgumentMatchers.argThat; |
Jason Monk | 2da4619 | 2017-03-27 15:18:23 -0400 | [diff] [blame] | 19 | import static org.mockito.Mockito.mock; |
| 20 | import static org.mockito.Mockito.never; |
| 21 | import static org.mockito.Mockito.verify; |
| 22 | import static org.mockito.Mockito.when; |
| 23 | |
Jason Monk | 2b48aa3 | 2017-03-27 16:41:24 -0400 | [diff] [blame] | 24 | import android.content.res.ColorStateList; |
Jason Monk | 2da4619 | 2017-03-27 15:18:23 -0400 | [diff] [blame] | 25 | import android.graphics.drawable.Drawable; |
Jason Monk | 2b48aa3 | 2017-03-27 16:41:24 -0400 | [diff] [blame] | 26 | import android.service.quicksettings.Tile; |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 27 | import android.support.test.filters.SmallTest; |
Jason Monk | 2da4619 | 2017-03-27 15:18:23 -0400 | [diff] [blame] | 28 | import android.testing.AndroidTestingRunner; |
| 29 | import android.testing.UiThreadTest; |
| 30 | import android.widget.ImageView; |
| 31 | |
| 32 | import com.android.systemui.SysuiTestCase; |
| 33 | import com.android.systemui.plugins.qs.QSTile.Icon; |
| 34 | import com.android.systemui.plugins.qs.QSTile.State; |
| 35 | |
| 36 | import org.junit.Before; |
| 37 | import org.junit.Test; |
| 38 | import org.junit.runner.RunWith; |
Jason Monk | 2b48aa3 | 2017-03-27 16:41:24 -0400 | [diff] [blame] | 39 | import org.mockito.ArgumentMatcher; |
Jason Monk | 2da4619 | 2017-03-27 15:18:23 -0400 | [diff] [blame] | 40 | |
| 41 | @RunWith(AndroidTestingRunner.class) |
| 42 | @UiThreadTest |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 43 | @SmallTest |
Jason Monk | 2da4619 | 2017-03-27 15:18:23 -0400 | [diff] [blame] | 44 | public 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 Shaikh | 32d786f | 2018-08-01 17:08:26 -0400 | [diff] [blame] | 62 | mIconView.updateIcon(iv, s, true); |
Jason Monk | 2da4619 | 2017-03-27 15:18:23 -0400 | [diff] [blame] | 63 | 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 Shaikh | 32d786f | 2018-08-01 17:08:26 -0400 | [diff] [blame] | 69 | mIconView.updateIcon(iv, s, true); |
Jason Monk | 2da4619 | 2017-03-27 15:18:23 -0400 | [diff] [blame] | 70 | verify(s.icon).getDrawable(any()); |
| 71 | verify(s.icon, never()).getInvisibleDrawable(any()); |
| 72 | } |
Jason Monk | 2b48aa3 | 2017-03-27 16:41:24 -0400 | [diff] [blame] | 73 | |
| 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 Shaikh | 32d786f | 2018-08-01 17:08:26 -0400 | [diff] [blame] | 82 | mIconView.setIcon(iv, s, true); |
Jason Monk | 2b48aa3 | 2017-03-27 16:41:24 -0400 | [diff] [blame] | 83 | verify(iv).setImageTintList(argThat(stateList -> stateList.getColors()[0] == desiredColor)); |
| 84 | } |
Jason Monk | 2da4619 | 2017-03-27 15:18:23 -0400 | [diff] [blame] | 85 | } |