Home | History | Annotate | Download | only in tileimpl
      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;
     18 import static org.mockito.ArgumentMatchers.argThat;
     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 
     24 import android.content.res.ColorStateList;
     25 import android.graphics.drawable.Drawable;
     26 import android.service.quicksettings.Tile;
     27 import android.support.test.filters.SmallTest;
     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;
     39 import org.mockito.ArgumentMatcher;
     40 
     41 @RunWith(AndroidTestingRunner.class)
     42 @UiThreadTest
     43 @SmallTest
     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);
     62         mIconView.updateIcon(iv, s);
     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));
     69         mIconView.updateIcon(iv, s);
     70         verify(s.icon).getDrawable(any());
     71         verify(s.icon, never()).getInvisibleDrawable(any());
     72     }
     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 
     82         mIconView.setIcon(iv, s);
     83         verify(iv).setImageTintList(argThat(stateList -> stateList.getColors()[0] == desiredColor));
     84     }
     85 }
     86