blob: e2159d24ad85414b601a1f0c62f7759dfc82f7d3 [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
19import android.content.Context;
20import android.graphics.drawable.Drawable;
21import android.support.test.filters.SmallTest;
22import android.testing.AndroidTestingRunner;
23import android.testing.TestableLooper.RunWithLooper;
24import com.android.systemui.SysuiTestCase;
25import com.android.systemui.plugins.qs.QSTile.SlashState;
26import com.android.systemui.qs.tileimpl.SlashImageView;
27import org.junit.Test;
28import org.junit.runner.RunWith;
29
Jason Monk1fc931a2017-12-14 13:22:58 -050030import static org.junit.Assert.assertEquals;
Evan Laird418ffe42017-06-13 15:09:21 -040031import static org.junit.Assert.assertTrue;
Jason Monk1fc931a2017-12-14 13:22:58 -050032import static org.mockito.ArgumentMatchers.anyInt;
33import static org.mockito.ArgumentMatchers.eq;
Evan Laird418ffe42017-06-13 15:09:21 -040034import static org.mockito.Mockito.mock;
Jason Monk1fc931a2017-12-14 13:22:58 -050035import static org.mockito.Mockito.never;
36import static org.mockito.Mockito.verify;
37import static org.mockito.Mockito.when;
Evan Laird418ffe42017-06-13 15:09:21 -040038
39
40@SmallTest
41@RunWith(AndroidTestingRunner.class)
42@RunWithLooper
43public class SlashImageViewTest extends SysuiTestCase {
44 private TestableSlashImageView mSlashView;
45
46 @Test
Evan Laird929bd542017-07-12 16:36:06 -040047 public void testSetNonNullSlashStateCreatesSlashDrawable() {
Evan Laird418ffe42017-06-13 15:09:21 -040048 SlashState mockState = mock(SlashState.class);
49 Drawable mockDrawable = mock(Drawable.class);
50 mSlashView = new TestableSlashImageView(mContext);
51 assertTrue(mSlashView.getSlashDrawable() == null);
52
Evan Laird929bd542017-07-12 16:36:06 -040053 mSlashView.setState(mockState, mockDrawable);
Evan Laird418ffe42017-06-13 15:09:21 -040054
55 assertTrue(mSlashView.getSlashDrawable() != null);
56 }
57
58 @Test
Evan Laird929bd542017-07-12 16:36:06 -040059 public void testSetNullSlashStateRemovesSlashDrawable() {
60 SlashState mockState = mock(SlashState.class);
61 Drawable mockDrawable = mock(Drawable.class);
62 mSlashView = new TestableSlashImageView(mContext);
63 mSlashView.setState(mockState, mockDrawable);
64
65 assertTrue(mSlashView.getSlashDrawable() != null);
66
67 mSlashView.setState(null, mockDrawable);
68
69 assertTrue(mSlashView.getSlashDrawable() == null);
70 }
71
72 @Test
Evan Laird418ffe42017-06-13 15:09:21 -040073 public void testSetNullDrawableRemovesSlashDrawable() {
74 SlashState mockState = mock(SlashState.class);
75 Drawable mockDrawable = mock(Drawable.class);
76
77 mSlashView = new TestableSlashImageView(mContext);
78 mSlashView.setImageDrawable(mockDrawable);
Evan Laird929bd542017-07-12 16:36:06 -040079 mSlashView.setState(mockState, mockDrawable);
Evan Laird418ffe42017-06-13 15:09:21 -040080 mSlashView.setImageDrawable(null);
81
82 assertTrue(mSlashView.getSlashDrawable() == null);
83 }
84
Evan Laird9d4d73b2017-09-12 11:03:15 -040085 @Test
86 public void testSetImageDrawableUsesDrawableLevel() {
87 SlashImageView iv = new SlashImageView(mContext);
88 Drawable mockDrawable = mock(Drawable.class);
Jason Monk1fc931a2017-12-14 13:22:58 -050089 when(mockDrawable.getLevel()).thenReturn(2);
Evan Laird9d4d73b2017-09-12 11:03:15 -040090
91 iv.setImageDrawable(mockDrawable);
92
93 // Make sure setting the drawable didn't reset its level to 0
Jason Monk1fc931a2017-12-14 13:22:58 -050094 verify(mockDrawable).setLevel(eq(2));
Evan Laird9d4d73b2017-09-12 11:03:15 -040095 }
96
Evan Laird418ffe42017-06-13 15:09:21 -040097 // Expose getSlashDrawable
98 private static class TestableSlashImageView extends SlashImageView {
99 TestableSlashImageView(Context c) {
100 super(c);
101 }
102
103 private SlashDrawable getSlashDrawable() {
104 return mSlash;
105 }
106 }
107}