blob: ea8c64ac53bb5b98abfd239b2ba61cbd4a8d9b85 [file] [log] [blame]
Evan Laird418ffe42017-06-13 15:09:21 -04001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.systemui.qs;
18
Evan Laird418ffe42017-06-13 15:09:21 -040019import static org.junit.Assert.assertTrue;
Jason Monk1fc931a2017-12-14 13:22:58 -050020import static org.mockito.ArgumentMatchers.eq;
Evan Laird418ffe42017-06-13 15:09:21 -040021import static org.mockito.Mockito.mock;
Jason Monk1fc931a2017-12-14 13:22:58 -050022import static org.mockito.Mockito.verify;
23import static org.mockito.Mockito.when;
Evan Laird418ffe42017-06-13 15:09:21 -040024
Brett Chabot84151d92019-02-27 15:37:59 -080025import android.content.Context;
26import android.graphics.drawable.Drawable;
27import android.testing.AndroidTestingRunner;
28import android.testing.TestableLooper.RunWithLooper;
29
30import androidx.test.filters.SmallTest;
31
32import com.android.systemui.SysuiTestCase;
33import com.android.systemui.plugins.qs.QSTile.SlashState;
34import com.android.systemui.qs.tileimpl.SlashImageView;
35
36import org.junit.Test;
37import org.junit.runner.RunWith;
Evan Laird418ffe42017-06-13 15:09:21 -040038
39@SmallTest
40@RunWith(AndroidTestingRunner.class)
41@RunWithLooper
42public class SlashImageViewTest extends SysuiTestCase {
43 private TestableSlashImageView mSlashView;
44
45 @Test
Evan Laird929bd542017-07-12 16:36:06 -040046 public void testSetNonNullSlashStateCreatesSlashDrawable() {
Evan Laird418ffe42017-06-13 15:09:21 -040047 SlashState mockState = mock(SlashState.class);
48 Drawable mockDrawable = mock(Drawable.class);
49 mSlashView = new TestableSlashImageView(mContext);
50 assertTrue(mSlashView.getSlashDrawable() == null);
51
Evan Laird929bd542017-07-12 16:36:06 -040052 mSlashView.setState(mockState, mockDrawable);
Evan Laird418ffe42017-06-13 15:09:21 -040053
54 assertTrue(mSlashView.getSlashDrawable() != null);
55 }
56
57 @Test
Evan Laird929bd542017-07-12 16:36:06 -040058 public void testSetNullSlashStateRemovesSlashDrawable() {
59 SlashState mockState = mock(SlashState.class);
60 Drawable mockDrawable = mock(Drawable.class);
61 mSlashView = new TestableSlashImageView(mContext);
62 mSlashView.setState(mockState, mockDrawable);
63
64 assertTrue(mSlashView.getSlashDrawable() != null);
65
66 mSlashView.setState(null, mockDrawable);
67
68 assertTrue(mSlashView.getSlashDrawable() == null);
69 }
70
71 @Test
Evan Laird418ffe42017-06-13 15:09:21 -040072 public void testSetNullDrawableRemovesSlashDrawable() {
73 SlashState mockState = mock(SlashState.class);
74 Drawable mockDrawable = mock(Drawable.class);
75
76 mSlashView = new TestableSlashImageView(mContext);
77 mSlashView.setImageDrawable(mockDrawable);
Evan Laird929bd542017-07-12 16:36:06 -040078 mSlashView.setState(mockState, mockDrawable);
Evan Laird418ffe42017-06-13 15:09:21 -040079 mSlashView.setImageDrawable(null);
80
81 assertTrue(mSlashView.getSlashDrawable() == null);
82 }
83
Evan Laird9d4d73b2017-09-12 11:03:15 -040084 @Test
85 public void testSetImageDrawableUsesDrawableLevel() {
86 SlashImageView iv = new SlashImageView(mContext);
87 Drawable mockDrawable = mock(Drawable.class);
Jason Monk1fc931a2017-12-14 13:22:58 -050088 when(mockDrawable.getLevel()).thenReturn(2);
Evan Laird9d4d73b2017-09-12 11:03:15 -040089
90 iv.setImageDrawable(mockDrawable);
91
92 // Make sure setting the drawable didn't reset its level to 0
Jason Monk1fc931a2017-12-14 13:22:58 -050093 verify(mockDrawable).setLevel(eq(2));
Evan Laird9d4d73b2017-09-12 11:03:15 -040094 }
95
Evan Laird418ffe42017-06-13 15:09:21 -040096 // Expose getSlashDrawable
97 private static class TestableSlashImageView extends SlashImageView {
98 TestableSlashImageView(Context c) {
99 super(c);
100 }
101
102 private SlashDrawable getSlashDrawable() {
103 return mSlash;
104 }
105 }
106}