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 | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 25 | import android.support.test.filters.SmallTest; |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 26 | import android.testing.AndroidTestingRunner; |
| 27 | import android.testing.TestableLooper.RunWithLooper; |
| 28 | import android.view.ViewGroup; |
| 29 | import android.widget.LinearLayout; |
| 30 | |
| 31 | import com.android.internal.statusbar.StatusBarIcon; |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 32 | import com.android.systemui.plugins.DarkIconDispatcher; |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 33 | import com.android.systemui.statusbar.StatusBarIconView; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 34 | import com.android.systemui.statusbar.StatusBarMobileView; |
| 35 | import com.android.systemui.statusbar.StatusBarWifiView; |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 36 | import com.android.systemui.statusbar.StatusIconDisplayable; |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 37 | import com.android.systemui.statusbar.phone.StatusBarIconController.DarkIconManager; |
| 38 | import com.android.systemui.statusbar.phone.StatusBarIconController.IconManager; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 39 | import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.MobileIconState; |
| 40 | import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.WifiIconState; |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 41 | import com.android.systemui.utils.leaks.LeakCheckedTest; |
| 42 | |
| 43 | import org.junit.Before; |
| 44 | import org.junit.Test; |
| 45 | import org.junit.runner.RunWith; |
| 46 | |
| 47 | @RunWith(AndroidTestingRunner.class) |
| 48 | @RunWithLooper |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 49 | @SmallTest |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 50 | public class StatusBarIconControllerTest extends LeakCheckedTest { |
| 51 | |
| 52 | @Before |
| 53 | public void setup() { |
| 54 | injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); |
| 55 | mDependency.injectMockDependency(DarkIconDispatcher.class); |
| 56 | } |
| 57 | |
| 58 | @Test |
| 59 | public void testSetCalledOnAdd_IconManager() { |
| 60 | LinearLayout layout = new LinearLayout(mContext); |
| 61 | TestIconManager manager = new TestIconManager(layout); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 62 | testCallOnAdd_forManager(manager); |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Test |
| 66 | public void testSetCalledOnAdd_DarkIconManager() { |
| 67 | LinearLayout layout = new LinearLayout(mContext); |
| 68 | TestDarkIconManager manager = new TestDarkIconManager(layout); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 69 | testCallOnAdd_forManager(manager); |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 70 | } |
| 71 | |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 72 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 73 | private <T extends IconManager & TestableIconManager> void testCallOnAdd_forManager(T manager) { |
| 74 | StatusBarIconHolder holder = holderForType(TYPE_ICON); |
| 75 | manager.onIconAdded(0, "test_slot", false, holder); |
| 76 | assertTrue("Expected StatusBarIconView", |
| 77 | (manager.getViewAt(0) instanceof StatusBarIconView)); |
| 78 | |
| 79 | holder = holderForType(TYPE_WIFI); |
| 80 | manager.onIconAdded(1, "test_wifi", false, holder); |
| 81 | assertTrue(manager.getViewAt(1) instanceof StatusBarWifiView); |
| 82 | |
| 83 | holder = holderForType(TYPE_MOBILE); |
| 84 | manager.onIconAdded(2, "test_mobile", false, holder); |
| 85 | assertTrue(manager.getViewAt(2) instanceof StatusBarMobileView); |
| 86 | } |
| 87 | |
| 88 | private StatusBarIconHolder holderForType(int type) { |
| 89 | switch (type) { |
| 90 | case TYPE_MOBILE: |
| 91 | return StatusBarIconHolder.fromMobileIconState(mock(MobileIconState.class)); |
| 92 | |
| 93 | case TYPE_WIFI: |
| 94 | return StatusBarIconHolder.fromWifiIconState(mock(WifiIconState.class)); |
| 95 | |
| 96 | case TYPE_ICON: |
| 97 | default: |
| 98 | return StatusBarIconHolder.fromIcon(mock(StatusBarIcon.class)); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | private static class TestDarkIconManager extends DarkIconManager |
| 103 | implements TestableIconManager { |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 104 | |
| 105 | public TestDarkIconManager(LinearLayout group) { |
| 106 | super(group); |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | @Override |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 110 | public StatusIconDisplayable getViewAt(int index) { |
| 111 | return (StatusIconDisplayable) mGroup.getChildAt(index); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | protected StatusBarIconView addIcon(int index, String slot, boolean blocked, |
| 116 | StatusBarIcon icon) { |
| 117 | StatusBarIconView mock = mock(StatusBarIconView.class); |
| 118 | mGroup.addView(mock, index); |
| 119 | |
| 120 | return mock; |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | protected StatusBarWifiView addSignalIcon(int index, String slot, WifiIconState state) { |
| 125 | StatusBarWifiView mock = mock(StatusBarWifiView.class); |
| 126 | mGroup.addView(mock, index); |
| 127 | return mock; |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | protected StatusBarMobileView addMobileIcon(int index, String slot, MobileIconState state) { |
| 132 | StatusBarMobileView mock = mock(StatusBarMobileView.class); |
| 133 | mGroup.addView(mock, index); |
| 134 | |
| 135 | return mock; |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 139 | private static class TestIconManager extends IconManager implements TestableIconManager { |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 140 | public TestIconManager(ViewGroup group) { |
| 141 | super(group); |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | @Override |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 145 | public StatusIconDisplayable getViewAt(int index) { |
| 146 | return (StatusIconDisplayable) mGroup.getChildAt(index); |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | protected StatusBarIconView addIcon(int index, String slot, boolean blocked, |
| 151 | StatusBarIcon icon) { |
| 152 | StatusBarIconView mock = mock(StatusBarIconView.class); |
| 153 | mGroup.addView(mock, index); |
| 154 | |
| 155 | return mock; |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | protected StatusBarWifiView addSignalIcon(int index, String slot, WifiIconState state) { |
| 160 | StatusBarWifiView mock = mock(StatusBarWifiView.class); |
| 161 | mGroup.addView(mock, index); |
| 162 | return mock; |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | protected StatusBarMobileView addMobileIcon(int index, String slot, MobileIconState state) { |
| 167 | StatusBarMobileView mock = mock(StatusBarMobileView.class); |
| 168 | mGroup.addView(mock, index); |
| 169 | |
| 170 | return mock; |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 174 | private interface TestableIconManager { |
| 175 | StatusIconDisplayable getViewAt(int index); |
| 176 | } |
Jason Monk | 6eb906e | 2017-03-29 15:04:25 -0400 | [diff] [blame] | 177 | } |