Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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.phone; |
| 18 | |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 19 | import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 20 | |
| 21 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_TRANSPARENT; |
| 22 | |
| 23 | import static org.mockito.ArgumentMatchers.anyBoolean; |
| 24 | import static org.mockito.ArgumentMatchers.eq; |
| 25 | import static org.mockito.Mockito.mock; |
| 26 | import static org.mockito.Mockito.verify; |
| 27 | import static org.mockito.Mockito.when; |
| 28 | |
| 29 | import android.graphics.Rect; |
| 30 | import android.testing.AndroidTestingRunner; |
| 31 | import android.testing.TestableLooper; |
| 32 | |
| 33 | import androidx.test.filters.SmallTest; |
| 34 | |
| 35 | import com.android.internal.view.AppearanceRegion; |
| 36 | import com.android.systemui.SysuiTestCase; |
| 37 | import com.android.systemui.statusbar.policy.BatteryController; |
| 38 | |
| 39 | import org.junit.Before; |
| 40 | import org.junit.Test; |
| 41 | import org.junit.runner.RunWith; |
| 42 | |
| 43 | @SmallTest |
| 44 | @RunWith(AndroidTestingRunner.class) |
| 45 | @TestableLooper.RunWithLooper |
| 46 | public class LightBarControllerTest extends SysuiTestCase { |
| 47 | |
| 48 | private LightBarTransitionsController mLightBarTransitionsController; |
| 49 | private SysuiDarkIconDispatcher mStatusBarIconController; |
| 50 | private LightBarController mLightBarController; |
| 51 | |
| 52 | @Before |
| 53 | public void setup() { |
| 54 | mStatusBarIconController = mock(SysuiDarkIconDispatcher.class); |
| 55 | mLightBarTransitionsController = mock(LightBarTransitionsController.class); |
| 56 | when(mStatusBarIconController.getTransitionsController()).thenReturn( |
| 57 | mLightBarTransitionsController); |
| 58 | mLightBarController = new LightBarController(mContext, mStatusBarIconController, |
| 59 | mock(BatteryController.class)); |
| 60 | } |
| 61 | |
| 62 | @Test |
| 63 | public void testOnStatusBarAppearanceChanged_multipleStacks_allStacksLight() { |
| 64 | final Rect firstBounds = new Rect(0, 0, 1, 1); |
| 65 | final Rect secondBounds = new Rect(1, 0, 2, 1); |
| 66 | final AppearanceRegion[] appearanceRegions = new AppearanceRegion[]{ |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 67 | new AppearanceRegion(APPEARANCE_LIGHT_STATUS_BARS, firstBounds), |
| 68 | new AppearanceRegion(APPEARANCE_LIGHT_STATUS_BARS, secondBounds) |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 69 | }; |
| 70 | mLightBarController.onStatusBarAppearanceChanged( |
| 71 | appearanceRegions, true /* sbModeChanged */, MODE_TRANSPARENT, |
| 72 | false /* navbarColorManagedByIme */); |
| 73 | verify(mStatusBarIconController).setIconsDarkArea(eq(null)); |
| 74 | verify(mLightBarTransitionsController).setIconsDark(eq(true), anyBoolean()); |
| 75 | } |
| 76 | |
| 77 | @Test |
| 78 | public void testOnStatusBarAppearanceChanged_multipleStacks_oneStackLightOneStackDark() { |
| 79 | final Rect firstBounds = new Rect(0, 0, 1, 1); |
| 80 | final Rect secondBounds = new Rect(1, 0, 2, 1); |
| 81 | final AppearanceRegion[] appearanceRegions = new AppearanceRegion[]{ |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 82 | new AppearanceRegion(APPEARANCE_LIGHT_STATUS_BARS, firstBounds), |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 83 | new AppearanceRegion(0 /* appearance */, secondBounds) |
| 84 | }; |
| 85 | mLightBarController.onStatusBarAppearanceChanged( |
| 86 | appearanceRegions, true /* sbModeChanged */, MODE_TRANSPARENT, |
| 87 | false /* navbarColorManagedByIme */); |
| 88 | verify(mStatusBarIconController).setIconsDarkArea(eq(firstBounds)); |
| 89 | verify(mLightBarTransitionsController).setIconsDark(eq(true), anyBoolean()); |
| 90 | } |
| 91 | |
| 92 | @Test |
| 93 | public void testOnStatusBarAppearanceChanged_multipleStacks_oneStackDarkOneStackLight() { |
| 94 | final Rect firstBounds = new Rect(0, 0, 1, 1); |
| 95 | final Rect secondBounds = new Rect(1, 0, 2, 1); |
| 96 | final AppearanceRegion[] appearanceRegions = new AppearanceRegion[]{ |
| 97 | new AppearanceRegion(0 /* appearance */, firstBounds), |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 98 | new AppearanceRegion(APPEARANCE_LIGHT_STATUS_BARS, secondBounds) |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 99 | }; |
| 100 | mLightBarController.onStatusBarAppearanceChanged( |
| 101 | appearanceRegions, true /* sbModeChanged */, MODE_TRANSPARENT, |
| 102 | false /* navbarColorManagedByIme */); |
| 103 | verify(mStatusBarIconController).setIconsDarkArea(eq(secondBounds)); |
| 104 | verify(mLightBarTransitionsController).setIconsDark(eq(true), anyBoolean()); |
| 105 | } |
| 106 | |
| 107 | @Test |
| 108 | public void testOnStatusBarAppearanceChanged_multipleStacks_allStacksDark() { |
| 109 | final Rect firstBounds = new Rect(0, 0, 1, 1); |
| 110 | final Rect secondBounds = new Rect(1, 0, 2, 1); |
| 111 | final AppearanceRegion[] appearanceRegions = new AppearanceRegion[]{ |
| 112 | new AppearanceRegion(0 /* appearance */, firstBounds), |
| 113 | new AppearanceRegion(0 /* appearance */, secondBounds) |
| 114 | }; |
| 115 | mLightBarController.onStatusBarAppearanceChanged( |
| 116 | appearanceRegions, true /* sbModeChanged */, MODE_TRANSPARENT, |
| 117 | false /* navbarColorManagedByIme */); |
| 118 | verify(mLightBarTransitionsController).setIconsDark(eq(false), anyBoolean()); |
| 119 | } |
| 120 | |
| 121 | @Test |
| 122 | public void testOnStatusBarAppearanceChanged_singleStack_light() { |
| 123 | final AppearanceRegion[] appearanceRegions = new AppearanceRegion[]{ |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 124 | new AppearanceRegion(APPEARANCE_LIGHT_STATUS_BARS, new Rect(0, 0, 1, 1)) |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 125 | }; |
| 126 | mLightBarController.onStatusBarAppearanceChanged( |
| 127 | appearanceRegions, true /* sbModeChanged */, MODE_TRANSPARENT, |
| 128 | false /* navbarColorManagedByIme */); |
| 129 | verify(mStatusBarIconController).setIconsDarkArea(eq(null)); |
| 130 | verify(mLightBarTransitionsController).setIconsDark(eq(true), anyBoolean()); |
| 131 | } |
| 132 | |
| 133 | @Test |
| 134 | public void testOnStatusBarAppearanceChanged_singleStack_dark() { |
| 135 | final AppearanceRegion[] appearanceRegions = new AppearanceRegion[]{ |
| 136 | new AppearanceRegion(0, new Rect(0, 0, 1, 1)) |
| 137 | }; |
| 138 | mLightBarController.onStatusBarAppearanceChanged( |
| 139 | appearanceRegions, true /* sbModeChanged */, MODE_TRANSPARENT, |
| 140 | false /* navbarColorManagedByIme */); |
| 141 | verify(mLightBarTransitionsController).setIconsDark(eq(false), anyBoolean()); |
| 142 | } |
| 143 | } |