blob: 2020d4b9562f7f7347ae4158f2b39725eaa9cf11 [file] [log] [blame]
Lucas Dupin8da8f2e92017-04-21 14:02:16 -07001/*
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.statusbar;
18
Lucas Dupind2963f32017-05-26 15:27:36 -070019import static junit.framework.Assert.assertEquals;
20
Lucas Dupin8da8f2e92017-04-21 14:02:16 -070021import android.graphics.Color;
Lucas Dupin8da8f2e92017-04-21 14:02:16 -070022import android.graphics.drawable.ColorDrawable;
23import android.graphics.drawable.Drawable;
Jason Monk31bac9c2017-07-06 15:06:36 -040024import android.testing.AndroidTestingRunner;
25import android.testing.TestableLooper;
26import android.testing.TestableLooper.RunWithLooper;
27import android.testing.ViewUtils;
Lucas Dupin8da8f2e92017-04-21 14:02:16 -070028import android.view.View;
29
Brett Chabot84151d92019-02-27 15:37:59 -080030import androidx.test.filters.SmallTest;
31
Lucas Dupin7224c1e2017-07-06 14:35:30 -070032import com.android.internal.colorextraction.ColorExtractor;
33import com.android.internal.colorextraction.drawable.GradientDrawable;
Jason Monk31bac9c2017-07-06 15:06:36 -040034import com.android.systemui.statusbar.policy.ConfigurationController;
35import com.android.systemui.utils.leaks.LeakCheckedTest;
Lucas Dupin8da8f2e92017-04-21 14:02:16 -070036
Lucas Dupin8da8f2e92017-04-21 14:02:16 -070037import org.junit.Before;
38import org.junit.Test;
39import org.junit.runner.RunWith;
Lucas Dupin8da8f2e92017-04-21 14:02:16 -070040
41@RunWith(AndroidTestingRunner.class)
Jason Monkfba8faf2017-05-23 10:42:59 -040042@SmallTest
Jason Monk31bac9c2017-07-06 15:06:36 -040043public class ScrimViewTest extends LeakCheckedTest {
Lucas Dupin8da8f2e92017-04-21 14:02:16 -070044
45 ScrimView mView;
46
47 @Before
48 public void setUp() {
Jason Monk31bac9c2017-07-06 15:06:36 -040049 injectLeakCheckedDependency(ConfigurationController.class);
Lucas Dupin8da8f2e92017-04-21 14:02:16 -070050 mView = new ScrimView(getContext());
51 mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
52 mView.layout(0, 0, 1920, 1080);
53 }
54
55 @Test
Jason Monk31bac9c2017-07-06 15:06:36 -040056 @RunWithLooper
57 public void testAttachDetach() {
58 ViewUtils.attachView(mView);
59 TestableLooper.get(this).processAllMessages();
60 ViewUtils.detachView(mView);
61 TestableLooper.get(this).processAllMessages();
62 }
63
64 @Test
Lucas Dupin8da8f2e92017-04-21 14:02:16 -070065 public void testSetDrawable_UpdateDrawable() {
66 Drawable drawable = new ColorDrawable(Color.GREEN);
67 mView.setDrawable(drawable);
68 assertEquals(drawable, mView.getDrawable());
69 }
70
71 @Test
Lucas Dupind2963f32017-05-26 15:27:36 -070072 public void testCreation_initialColor() {
73 GradientDrawable drawable = (GradientDrawable) mView.getDrawable();
74 ColorExtractor.GradientColors colors = mView.getColors();
75 assertEquals("Main color should be set upon creation",
76 drawable.getMainColor(), colors.getMainColor());
77 assertEquals("Secondary color should be set upon creation",
78 drawable.getSecondaryColor(), colors.getSecondaryColor());
79 }
80
81 @Test
Lucas Dupin8da8f2e92017-04-21 14:02:16 -070082 public void testSetViewAlpha_propagatesToDrawable() {
Lucas Dupin9e3fa102017-11-08 17:16:55 -080083 final float alpha = 0.5f;
Lucas Dupin8da8f2e92017-04-21 14:02:16 -070084 mView.setViewAlpha(alpha);
Lucas Dupin9e3fa102017-11-08 17:16:55 -080085 assertEquals("View alpha did not propagate to drawable", alpha, mView.getViewAlpha());
Lucas Dupin8da8f2e92017-04-21 14:02:16 -070086 }
87
88 @Test
Lucas Dupin8da8f2e92017-04-21 14:02:16 -070089 public void setTint_set() {
90 int tint = Color.BLUE;
91 mView.setTint(tint);
92 assertEquals(mView.getTint(), tint);
93 }
94}