Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.statusbar.phone; |
| 16 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 17 | import static com.android.systemui.statusbar.phone.StatusBarIconHolder.TYPE_ICON; |
| 18 | import static com.android.systemui.statusbar.phone.StatusBarIconHolder.TYPE_MOBILE; |
| 19 | import static com.android.systemui.statusbar.phone.StatusBarIconHolder.TYPE_WIFI; |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 20 | |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 21 | import static junit.framework.Assert.assertTrue; |
| 22 | |
| 23 | import static org.mockito.Mockito.mock; |
| 24 | |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 25 | import android.testing.AndroidTestingRunner; |
| 26 | import android.testing.TestableLooper.RunWithLooper; |
| 27 | import android.view.ViewGroup; |
| 28 | import android.widget.LinearLayout; |
| 29 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 30 | import androidx.test.filters.SmallTest; |
| 31 | |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 32 | import com.android.internal.statusbar.StatusBarIcon; |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 33 | import com.android.systemui.plugins.DarkIconDispatcher; |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 34 | import com.android.systemui.statusbar.CommandQueue; |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 35 | import com.android.systemui.statusbar.StatusBarIconView; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 36 | import com.android.systemui.statusbar.StatusBarMobileView; |
| 37 | import com.android.systemui.statusbar.StatusBarWifiView; |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 38 | import com.android.systemui.statusbar.StatusIconDisplayable; |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 39 | import com.android.systemui.statusbar.phone.StatusBarIconController.DarkIconManager; |
| 40 | import com.android.systemui.statusbar.phone.StatusBarIconController.IconManager; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 41 | import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.MobileIconState; |
| 42 | import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.WifiIconState; |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 43 | import com.android.systemui.utils.leaks.LeakCheckedTest; |
| 44 | |
| 45 | import org.junit.Before; |
| 46 | import org.junit.Test; |
| 47 | import org.junit.runner.RunWith; |
| 48 | |
| 49 | @RunWith(AndroidTestingRunner.class) |
| 50 | @RunWithLooper |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 51 | @SmallTest |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 52 | public class StatusBarIconControllerTest extends LeakCheckedTest { |
| 53 | |
| 54 | @Before |
| 55 | public void setup() { |
| 56 | injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); |
| 57 | mDependency.injectMockDependency(DarkIconDispatcher.class); |
| 58 | } |
| 59 | |
| 60 | @Test |
| 61 | public void testSetCalledOnAdd_IconManager() { |
| 62 | LinearLayout layout = new LinearLayout(mContext); |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 63 | TestIconManager manager = new TestIconManager(layout, new CommandQueue(mContext)); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 64 | testCallOnAdd_forManager(manager); |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Test |
| 68 | public void testSetCalledOnAdd_DarkIconManager() { |
| 69 | LinearLayout layout = new LinearLayout(mContext); |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 70 | TestDarkIconManager manager = new TestDarkIconManager(layout, new CommandQueue(mContext)); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 71 | testCallOnAdd_forManager(manager); |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 74 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 75 | private <T extends IconManager & TestableIconManager> void testCallOnAdd_forManager(T manager) { |
| 76 | StatusBarIconHolder holder = holderForType(TYPE_ICON); |
| 77 | manager.onIconAdded(0, "test_slot", false, holder); |
| 78 | assertTrue("Expected StatusBarIconView", |
| 79 | (manager.getViewAt(0) instanceof StatusBarIconView)); |
| 80 | |
| 81 | holder = holderForType(TYPE_WIFI); |
| 82 | manager.onIconAdded(1, "test_wifi", false, holder); |
| 83 | assertTrue(manager.getViewAt(1) instanceof StatusBarWifiView); |
| 84 | |
| 85 | holder = holderForType(TYPE_MOBILE); |
| 86 | manager.onIconAdded(2, "test_mobile", false, holder); |
| 87 | assertTrue(manager.getViewAt(2) instanceof StatusBarMobileView); |
| 88 | } |
| 89 | |
| 90 | private StatusBarIconHolder holderForType(int type) { |
| 91 | switch (type) { |
| 92 | case TYPE_MOBILE: |
| 93 | return StatusBarIconHolder.fromMobileIconState(mock(MobileIconState.class)); |
| 94 | |
| 95 | case TYPE_WIFI: |
| 96 | return StatusBarIconHolder.fromWifiIconState(mock(WifiIconState.class)); |
| 97 | |
| 98 | case TYPE_ICON: |
| 99 | default: |
| 100 | return StatusBarIconHolder.fromIcon(mock(StatusBarIcon.class)); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | private static class TestDarkIconManager extends DarkIconManager |
| 105 | implements TestableIconManager { |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 106 | |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 107 | TestDarkIconManager(LinearLayout group, CommandQueue commandQueue) { |
| 108 | super(group, commandQueue); |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | @Override |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 112 | public StatusIconDisplayable getViewAt(int index) { |
| 113 | return (StatusIconDisplayable) mGroup.getChildAt(index); |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | protected StatusBarIconView addIcon(int index, String slot, boolean blocked, |
| 118 | StatusBarIcon icon) { |
| 119 | StatusBarIconView mock = mock(StatusBarIconView.class); |
| 120 | mGroup.addView(mock, index); |
| 121 | |
| 122 | return mock; |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | protected StatusBarWifiView addSignalIcon(int index, String slot, WifiIconState state) { |
| 127 | StatusBarWifiView mock = mock(StatusBarWifiView.class); |
| 128 | mGroup.addView(mock, index); |
| 129 | return mock; |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | protected StatusBarMobileView addMobileIcon(int index, String slot, MobileIconState state) { |
| 134 | StatusBarMobileView mock = mock(StatusBarMobileView.class); |
| 135 | mGroup.addView(mock, index); |
| 136 | |
| 137 | return mock; |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 141 | private static class TestIconManager extends IconManager implements TestableIconManager { |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 142 | TestIconManager(ViewGroup group, CommandQueue commandQueue) { |
| 143 | super(group, commandQueue); |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | @Override |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 147 | public StatusIconDisplayable getViewAt(int index) { |
| 148 | return (StatusIconDisplayable) mGroup.getChildAt(index); |
| 149 | } |
| 150 | |
| 151 | @Override |
| 152 | protected StatusBarIconView addIcon(int index, String slot, boolean blocked, |
| 153 | StatusBarIcon icon) { |
| 154 | StatusBarIconView mock = mock(StatusBarIconView.class); |
| 155 | mGroup.addView(mock, index); |
| 156 | |
| 157 | return mock; |
| 158 | } |
| 159 | |
| 160 | @Override |
| 161 | protected StatusBarWifiView addSignalIcon(int index, String slot, WifiIconState state) { |
| 162 | StatusBarWifiView mock = mock(StatusBarWifiView.class); |
| 163 | mGroup.addView(mock, index); |
| 164 | return mock; |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | protected StatusBarMobileView addMobileIcon(int index, String slot, MobileIconState state) { |
| 169 | StatusBarMobileView mock = mock(StatusBarMobileView.class); |
| 170 | mGroup.addView(mock, index); |
| 171 | |
| 172 | return mock; |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 176 | private interface TestableIconManager { |
| 177 | StatusIconDisplayable getViewAt(int index); |
| 178 | } |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 179 | } |