Jason Monk | cd74f69 | 2017-03-27 11:17:04 -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.qs; |
| 16 | |
| 17 | import static org.mockito.ArgumentMatchers.any; |
| 18 | import static org.mockito.ArgumentMatchers.anyBoolean; |
Fabian Kozynski | bf6fef3 | 2019-02-04 09:21:38 -0500 | [diff] [blame] | 19 | import static org.mockito.ArgumentMatchers.anyInt; |
| 20 | import static org.mockito.Mockito.mock; |
Jason Monk | cd74f69 | 2017-03-27 11:17:04 -0400 | [diff] [blame] | 21 | import static org.mockito.Mockito.never; |
| 22 | import static org.mockito.Mockito.verify; |
| 23 | import static org.mockito.Mockito.when; |
| 24 | |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 25 | import android.support.test.filters.SmallTest; |
Fabian Kozynski | bf6fef3 | 2019-02-04 09:21:38 -0500 | [diff] [blame] | 26 | import android.telephony.SubscriptionManager; |
Jason Monk | cd74f69 | 2017-03-27 11:17:04 -0400 | [diff] [blame] | 27 | import android.testing.AndroidTestingRunner; |
| 28 | import android.testing.TestableLooper; |
| 29 | import android.testing.TestableLooper.RunWithLooper; |
| 30 | import android.view.LayoutInflater; |
| 31 | import android.view.View; |
| 32 | |
Fabian Kozynski | bf6fef3 | 2019-02-04 09:21:38 -0500 | [diff] [blame] | 33 | import com.android.keyguard.CarrierTextController.CarrierTextCallbackInfo; |
Jason Monk | cd74f69 | 2017-03-27 11:17:04 -0400 | [diff] [blame] | 34 | import com.android.systemui.R; |
| 35 | import com.android.systemui.R.id; |
| 36 | import com.android.systemui.plugins.ActivityStarter; |
| 37 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Fabian Kozynski | bf6fef3 | 2019-02-04 09:21:38 -0500 | [diff] [blame] | 38 | import com.android.systemui.statusbar.policy.NetworkController; |
Jason Monk | cd74f69 | 2017-03-27 11:17:04 -0400 | [diff] [blame] | 39 | import com.android.systemui.utils.leaks.LeakCheckedTest; |
| 40 | |
| 41 | import org.junit.Before; |
Geoffrey Pitsch | 351a321 | 2017-05-22 15:20:20 -0400 | [diff] [blame] | 42 | import org.junit.Ignore; |
Jason Monk | cd74f69 | 2017-03-27 11:17:04 -0400 | [diff] [blame] | 43 | import org.junit.Test; |
| 44 | import org.junit.runner.RunWith; |
Fabian Kozynski | bf6fef3 | 2019-02-04 09:21:38 -0500 | [diff] [blame] | 45 | import org.mockito.Mockito; |
| 46 | import org.mockito.invocation.InvocationOnMock; |
| 47 | import org.mockito.stubbing.Answer; |
Jason Monk | cd74f69 | 2017-03-27 11:17:04 -0400 | [diff] [blame] | 48 | |
| 49 | @RunWith(AndroidTestingRunner.class) |
| 50 | @RunWithLooper |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 51 | @SmallTest |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 52 | public class QSFooterImplTest extends LeakCheckedTest { |
Jason Monk | cd74f69 | 2017-03-27 11:17:04 -0400 | [diff] [blame] | 53 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 54 | private QSFooterImpl mFooter; |
Jason Monk | cd74f69 | 2017-03-27 11:17:04 -0400 | [diff] [blame] | 55 | private ActivityStarter mActivityStarter; |
| 56 | private DeviceProvisionedController mDeviceProvisionedController; |
| 57 | |
| 58 | @Before |
| 59 | public void setup() throws Exception { |
| 60 | injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); |
| 61 | mActivityStarter = mDependency.injectMockDependency(ActivityStarter.class); |
| 62 | mDeviceProvisionedController = mDependency.injectMockDependency( |
| 63 | DeviceProvisionedController.class); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 64 | TestableLooper.get(this).runWithLooper( |
| 65 | () -> mFooter = (QSFooterImpl) LayoutInflater.from(mContext).inflate( |
| 66 | R.layout.qs_footer_impl, null)); |
Jason Monk | cd74f69 | 2017-03-27 11:17:04 -0400 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Test |
Alison Cichowlas | 5d7d959 | 2018-07-17 15:30:28 -0400 | [diff] [blame] | 70 | @Ignore("failing") |
Jason Monk | cd74f69 | 2017-03-27 11:17:04 -0400 | [diff] [blame] | 71 | public void testSettings_UserNotSetup() { |
| 72 | View settingsButton = mFooter.findViewById(id.settings_button); |
| 73 | when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(false); |
| 74 | |
| 75 | mFooter.onClick(settingsButton); |
| 76 | // Verify Settings wasn't launched. |
| 77 | verify(mActivityStarter, never()).startActivity(any(), anyBoolean()); |
| 78 | } |
Fabian Kozynski | bf6fef3 | 2019-02-04 09:21:38 -0500 | [diff] [blame] | 79 | |
| 80 | @Test // throws no Exception |
| 81 | public void testUpdateCarrierText_sameLengts() { |
| 82 | QSFooterImpl spiedFooter = Mockito.spy(mFooter); |
| 83 | when(spiedFooter.getSlotIndex(anyInt())).thenAnswer( |
| 84 | new Answer<Integer>() { |
| 85 | @Override |
| 86 | public Integer answer(InvocationOnMock invocationOnMock) throws Throwable { |
| 87 | return invocationOnMock.getArgument(0); |
| 88 | } |
| 89 | }); |
| 90 | |
| 91 | // listOfCarriers length 1, subscriptionIds length 1, anySims false |
| 92 | CarrierTextCallbackInfo c1 = new CarrierTextCallbackInfo( |
| 93 | "", |
| 94 | new CharSequence[]{""}, |
| 95 | false, |
| 96 | new int[]{0}); |
| 97 | spiedFooter.updateCarrierInfo(c1); |
| 98 | |
| 99 | // listOfCarriers length 1, subscriptionIds length 1, anySims true |
| 100 | CarrierTextCallbackInfo c2 = new CarrierTextCallbackInfo( |
| 101 | "", |
| 102 | new CharSequence[]{""}, |
| 103 | true, |
| 104 | new int[]{0}); |
| 105 | spiedFooter.updateCarrierInfo(c2); |
| 106 | |
| 107 | // listOfCarriers length 2, subscriptionIds length 2, anySims false |
| 108 | CarrierTextCallbackInfo c3 = new CarrierTextCallbackInfo( |
| 109 | "", |
| 110 | new CharSequence[]{"", ""}, |
| 111 | false, |
| 112 | new int[]{0, 1}); |
| 113 | spiedFooter.updateCarrierInfo(c3); |
| 114 | |
| 115 | // listOfCarriers length 2, subscriptionIds length 2, anySims true |
| 116 | CarrierTextCallbackInfo c4 = new CarrierTextCallbackInfo( |
| 117 | "", |
| 118 | new CharSequence[]{"", ""}, |
| 119 | true, |
| 120 | new int[]{0, 1}); |
| 121 | spiedFooter.updateCarrierInfo(c4); |
| 122 | } |
| 123 | |
| 124 | @Test // throws no Exception |
| 125 | public void testUpdateCarrierText_differentLength() { |
| 126 | QSFooterImpl spiedFooter = Mockito.spy(mFooter); |
| 127 | when(spiedFooter.getSlotIndex(anyInt())).thenAnswer( |
| 128 | new Answer<Integer>() { |
| 129 | @Override |
| 130 | public Integer answer(InvocationOnMock invocationOnMock) throws Throwable { |
| 131 | return invocationOnMock.getArgument(0); |
| 132 | } |
| 133 | }); |
| 134 | |
| 135 | // listOfCarriers length 2, subscriptionIds length 1, anySims false |
| 136 | CarrierTextCallbackInfo c1 = new CarrierTextCallbackInfo( |
| 137 | "", |
| 138 | new CharSequence[]{"", ""}, |
| 139 | false, |
| 140 | new int[]{0}); |
| 141 | spiedFooter.updateCarrierInfo(c1); |
| 142 | |
| 143 | // listOfCarriers length 2, subscriptionIds length 1, anySims true |
| 144 | CarrierTextCallbackInfo c2 = new CarrierTextCallbackInfo( |
| 145 | "", |
| 146 | new CharSequence[]{"", ""}, |
| 147 | true, |
| 148 | new int[]{0}); |
| 149 | spiedFooter.updateCarrierInfo(c2); |
| 150 | |
| 151 | // listOfCarriers length 1, subscriptionIds length 2, anySims false |
| 152 | CarrierTextCallbackInfo c3 = new CarrierTextCallbackInfo( |
| 153 | "", |
| 154 | new CharSequence[]{""}, |
| 155 | false, |
| 156 | new int[]{0, 1}); |
| 157 | spiedFooter.updateCarrierInfo(c3); |
| 158 | |
| 159 | // listOfCarriers length 1, subscriptionIds length 2, anySims true |
| 160 | CarrierTextCallbackInfo c4 = new CarrierTextCallbackInfo( |
| 161 | "", |
| 162 | new CharSequence[]{""}, |
| 163 | true, |
| 164 | new int[]{0, 1}); |
| 165 | spiedFooter.updateCarrierInfo(c4); |
| 166 | } |
| 167 | |
| 168 | @Test // throws no Exception |
| 169 | public void testUpdateCarrierText_invalidSim() { |
| 170 | QSFooterImpl spiedFooter = Mockito.spy(mFooter); |
| 171 | when(spiedFooter.getSlotIndex(anyInt())).thenReturn( |
| 172 | SubscriptionManager.INVALID_SIM_SLOT_INDEX); |
| 173 | CarrierTextCallbackInfo c4 = new CarrierTextCallbackInfo( |
| 174 | "", |
| 175 | new CharSequence[]{"", ""}, |
| 176 | true, |
| 177 | new int[]{0, 1}); |
| 178 | spiedFooter.updateCarrierInfo(c4); |
| 179 | } |
| 180 | |
| 181 | @Test // throws no Exception |
| 182 | public void testSetMobileDataIndicators_invalidSim() { |
| 183 | QSFooterImpl spiedFooter = Mockito.spy(mFooter); |
| 184 | when(spiedFooter.getSlotIndex(anyInt())).thenReturn( |
| 185 | SubscriptionManager.INVALID_SIM_SLOT_INDEX); |
| 186 | spiedFooter.setMobileDataIndicators( |
| 187 | mock(NetworkController.IconState.class), |
| 188 | mock(NetworkController.IconState.class), |
| 189 | 0, 0, true, true, "", "", true, 0, true); |
| 190 | } |
| 191 | |
Jason Monk | cd74f69 | 2017-03-27 11:17:04 -0400 | [diff] [blame] | 192 | } |