jackqdyulei | 76471a5 | 2016-12-05 15:03:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | package com.android.systemui.qs.external; |
| 17 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 18 | import static junit.framework.Assert.assertEquals; |
| 19 | |
jackqdyulei | 76471a5 | 2016-12-05 15:03:56 -0800 | [diff] [blame] | 20 | import android.content.res.ColorStateList; |
| 21 | import android.service.quicksettings.Tile; |
jackqdyulei | 76471a5 | 2016-12-05 15:03:56 -0800 | [diff] [blame] | 22 | import android.test.suitebuilder.annotation.SmallTest; |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 23 | |
| 24 | import androidx.test.runner.AndroidJUnit4; |
| 25 | |
| 26 | import com.android.systemui.R; |
jackqdyulei | 76471a5 | 2016-12-05 15:03:56 -0800 | [diff] [blame] | 27 | import com.android.systemui.SysuiTestCase; |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 28 | |
jackqdyulei | 76471a5 | 2016-12-05 15:03:56 -0800 | [diff] [blame] | 29 | import org.junit.Before; |
| 30 | import org.junit.Test; |
| 31 | import org.junit.runner.RunWith; |
jackqdyulei | 76471a5 | 2016-12-05 15:03:56 -0800 | [diff] [blame] | 32 | |
| 33 | @SmallTest |
| 34 | @RunWith(AndroidJUnit4.class) |
| 35 | public class TileColorPickerTest extends SysuiTestCase { |
| 36 | private static final int DEFAULT_COLOR = 0; |
| 37 | |
| 38 | private TileColorPicker mTileColorPicker; |
| 39 | private ColorStateList mTintColorStateList; |
| 40 | |
| 41 | @Before |
| 42 | public void setUp() { |
| 43 | mTileColorPicker = TileColorPicker.getInstance(mContext); |
| 44 | mTintColorStateList = mContext.getResources(). |
| 45 | getColorStateList(R.color.tint_color_selector, mContext.getTheme()); |
| 46 | } |
| 47 | |
| 48 | @Test |
| 49 | public void testGetColor_StateUnavailable_ReturnUnavailableColor() { |
| 50 | final int color = mTileColorPicker.getColor(Tile.STATE_UNAVAILABLE); |
| 51 | final int expectedColor = mTintColorStateList.getColorForState( |
| 52 | TileColorPicker.DISABLE_STATE_SET, DEFAULT_COLOR); |
| 53 | |
| 54 | assertEquals(expectedColor, color); |
| 55 | } |
| 56 | |
| 57 | @Test |
| 58 | public void testGetColor_StateInactive_ReturnInactiveColor() { |
| 59 | final int color = mTileColorPicker.getColor(Tile.STATE_INACTIVE); |
| 60 | final int expectedColor = mTintColorStateList.getColorForState( |
| 61 | TileColorPicker.INACTIVE_STATE_SET, DEFAULT_COLOR); |
| 62 | |
| 63 | assertEquals(expectedColor, color); |
| 64 | } |
| 65 | |
| 66 | @Test |
| 67 | public void testGetColor_StateActive_ReturnActiveColor() { |
| 68 | final int color = mTileColorPicker.getColor(Tile.STATE_ACTIVE); |
| 69 | final int expectedColor = mTintColorStateList.getColorForState( |
| 70 | TileColorPicker.ENABLE_STATE_SET, DEFAULT_COLOR); |
| 71 | |
| 72 | assertEquals(expectedColor, color); |
| 73 | } |
| 74 | } |