Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
Lucas Dupin | d2963f3 | 2017-05-26 15:27:36 -0700 | [diff] [blame] | 19 | import static junit.framework.Assert.assertEquals; |
| 20 | |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 21 | import android.graphics.Color; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 22 | import android.graphics.drawable.ColorDrawable; |
| 23 | import android.graphics.drawable.Drawable; |
Jason Monk | 31bac9c | 2017-07-06 15:06:36 -0400 | [diff] [blame] | 24 | import android.testing.AndroidTestingRunner; |
| 25 | import android.testing.TestableLooper; |
| 26 | import android.testing.TestableLooper.RunWithLooper; |
| 27 | import android.testing.ViewUtils; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 28 | import android.view.View; |
| 29 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 30 | import androidx.test.filters.SmallTest; |
| 31 | |
Lucas Dupin | 7224c1e | 2017-07-06 14:35:30 -0700 | [diff] [blame] | 32 | import com.android.internal.colorextraction.ColorExtractor; |
| 33 | import com.android.internal.colorextraction.drawable.GradientDrawable; |
Jason Monk | 31bac9c | 2017-07-06 15:06:36 -0400 | [diff] [blame] | 34 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 35 | import com.android.systemui.utils.leaks.LeakCheckedTest; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 36 | |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 37 | import org.junit.Before; |
| 38 | import org.junit.Test; |
| 39 | import org.junit.runner.RunWith; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 40 | |
| 41 | @RunWith(AndroidTestingRunner.class) |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 42 | @SmallTest |
Jason Monk | 31bac9c | 2017-07-06 15:06:36 -0400 | [diff] [blame] | 43 | public class ScrimViewTest extends LeakCheckedTest { |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 44 | |
| 45 | ScrimView mView; |
| 46 | |
| 47 | @Before |
| 48 | public void setUp() { |
Jason Monk | 31bac9c | 2017-07-06 15:06:36 -0400 | [diff] [blame] | 49 | injectLeakCheckedDependency(ConfigurationController.class); |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 50 | 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 Monk | 31bac9c | 2017-07-06 15:06:36 -0400 | [diff] [blame] | 56 | @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 Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 65 | 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 Dupin | d2963f3 | 2017-05-26 15:27:36 -0700 | [diff] [blame] | 72 | 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 Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 82 | public void testSetViewAlpha_propagatesToDrawable() { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 83 | final float alpha = 0.5f; |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 84 | mView.setViewAlpha(alpha); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 85 | assertEquals("View alpha did not propagate to drawable", alpha, mView.getViewAlpha()); |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | @Test |
Lucas Dupin | 8da8f2e9 | 2017-04-21 14:02:16 -0700 | [diff] [blame] | 89 | public void setTint_set() { |
| 90 | int tint = Color.BLUE; |
| 91 | mView.setTint(tint); |
| 92 | assertEquals(mView.getTint(), tint); |
| 93 | } |
| 94 | } |