Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | */ |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 16 | |
| 17 | package com.android.systemui.statusbar.policy; |
| 18 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 19 | import android.content.Intent; |
| 20 | import android.net.ConnectivityManager; |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 21 | import android.net.NetworkCapabilities; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 22 | import android.net.wifi.WifiManager; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 23 | import android.os.Looper; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 24 | import android.telephony.PhoneStateListener; |
| 25 | import android.telephony.ServiceState; |
| 26 | import android.telephony.SignalStrength; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 27 | import android.telephony.SubscriptionInfo; |
| 28 | import android.telephony.SubscriptionManager; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 29 | import android.telephony.TelephonyManager; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 30 | import android.util.Log; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 31 | import com.android.internal.telephony.cdma.EriInfo; |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 32 | import com.android.settingslib.net.DataUsageController; |
Chris Wren | 930ecca | 2014-11-12 17:43:41 -0500 | [diff] [blame] | 33 | import com.android.systemui.SysuiTestCase; |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 34 | import com.android.systemui.statusbar.policy.NetworkController.IconState; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 35 | import com.android.systemui.statusbar.policy.NetworkControllerImpl.Config; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 36 | import com.android.systemui.statusbar.policy.NetworkControllerImpl.SubscriptionDefaults; |
Jason Monk | da68f59 | 2015-01-07 10:55:58 -0500 | [diff] [blame] | 37 | import org.mockito.ArgumentCaptor; |
| 38 | import org.mockito.Mockito; |
| 39 | |
| 40 | import java.io.PrintWriter; |
| 41 | import java.io.StringWriter; |
| 42 | import java.util.ArrayList; |
| 43 | import java.util.List; |
| 44 | |
Jason Monk | f6a3cf9 | 2016-02-29 13:01:08 -0500 | [diff] [blame^] | 45 | import static org.mockito.Mockito.mock; |
| 46 | import static org.mockito.Mockito.when; |
| 47 | |
Chris Wren | 930ecca | 2014-11-12 17:43:41 -0500 | [diff] [blame] | 48 | public class NetworkControllerBaseTest extends SysuiTestCase { |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 49 | private static final String TAG = "NetworkControllerBaseTest"; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 50 | protected static final int DEFAULT_LEVEL = 2; |
| 51 | protected static final int DEFAULT_SIGNAL_STRENGTH = |
| 52 | TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH[1][DEFAULT_LEVEL]; |
| 53 | protected static final int DEFAULT_QS_SIGNAL_STRENGTH = |
| 54 | TelephonyIcons.QS_TELEPHONY_SIGNAL_STRENGTH[1][DEFAULT_LEVEL]; |
| 55 | protected static final int DEFAULT_ICON = TelephonyIcons.ICON_3G; |
| 56 | protected static final int DEFAULT_QS_ICON = TelephonyIcons.QS_ICON_3G; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 57 | |
| 58 | protected NetworkControllerImpl mNetworkController; |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 59 | protected MobileSignalController mMobileSignalController; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 60 | protected PhoneStateListener mPhoneStateListener; |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 61 | protected SignalStrength mSignalStrength; |
| 62 | protected ServiceState mServiceState; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 63 | protected ConnectivityManager mMockCm; |
| 64 | protected WifiManager mMockWm; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 65 | protected SubscriptionManager mMockSm; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 66 | protected TelephonyManager mMockTm; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 67 | protected Config mConfig; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 68 | protected CallbackHandler mCallbackHandler; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 69 | protected SubscriptionDefaults mMockSubDefaults; |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 70 | |
Jason Monk | 18985e0 | 2015-01-07 12:07:06 -0500 | [diff] [blame] | 71 | protected int mSubId; |
| 72 | |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 73 | private NetworkCapabilities mNetCapabilities; |
| 74 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 75 | @Override |
| 76 | protected void setUp() throws Exception { |
| 77 | super.setUp(); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 78 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 79 | mMockWm = mock(WifiManager.class); |
| 80 | mMockTm = mock(TelephonyManager.class); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 81 | mMockSm = mock(SubscriptionManager.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 82 | mMockCm = mock(ConnectivityManager.class); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 83 | mMockSubDefaults = mock(SubscriptionDefaults.class); |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 84 | mNetCapabilities = new NetworkCapabilities(); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 85 | when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(true); |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 86 | when(mMockCm.getDefaultNetworkCapabilitiesForUser(0)).thenReturn( |
| 87 | new NetworkCapabilities[] { mNetCapabilities }); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 88 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 89 | mSignalStrength = mock(SignalStrength.class); |
| 90 | mServiceState = mock(ServiceState.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 91 | |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 92 | mConfig = new Config(); |
| 93 | mConfig.hspaDataDistinguishable = true; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 94 | mCallbackHandler = mock(CallbackHandler.class); |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 95 | mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 96 | mConfig, Looper.getMainLooper(), mCallbackHandler, |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 97 | mock(AccessPointControllerImpl.class), mock(DataUsageController.class), |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 98 | mMockSubDefaults); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 99 | setupNetworkController(); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 100 | |
| 101 | // Trigger blank callbacks to always get the current state (some tests don't trigger |
| 102 | // changes from default state). |
| 103 | mNetworkController.addSignalCallback(null); |
| 104 | mNetworkController.addEmergencyListener(null); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | protected void setupNetworkController() { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 108 | // For now just pretend to be the data sim, so we can test that too. |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 109 | mSubId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; |
Jason Monk | f6a3cf9 | 2016-02-29 13:01:08 -0500 | [diff] [blame^] | 110 | when(mMockTm.getDataEnabled(mSubId)).thenReturn(true); |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 111 | setDefaultSubId(mSubId); |
| 112 | setSubscriptions(mSubId); |
Jason Monk | 18985e0 | 2015-01-07 12:07:06 -0500 | [diff] [blame] | 113 | mMobileSignalController = mNetworkController.mMobileSignalControllers.get(mSubId); |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 114 | mPhoneStateListener = mMobileSignalController.mPhoneStateListener; |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 115 | } |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 116 | |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 117 | protected void setDefaultSubId(int subId) { |
| 118 | when(mMockSubDefaults.getDefaultDataSubId()).thenReturn(subId); |
| 119 | when(mMockSubDefaults.getDefaultVoiceSubId()).thenReturn(subId); |
| 120 | } |
| 121 | |
| 122 | protected void setSubscriptions(int... subIds) { |
| 123 | List<SubscriptionInfo> subs = new ArrayList<SubscriptionInfo>(); |
| 124 | for (int subId : subIds) { |
| 125 | SubscriptionInfo subscription = mock(SubscriptionInfo.class); |
| 126 | when(subscription.getSubscriptionId()).thenReturn(subId); |
| 127 | subs.add(subscription); |
| 128 | } |
| 129 | when(mMockSm.getActiveSubscriptionInfoList()).thenReturn(subs); |
| 130 | mNetworkController.doUpdateMobileControllers(); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 131 | } |
| 132 | |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 133 | protected NetworkControllerImpl setUpNoMobileData() { |
| 134 | when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false); |
| 135 | NetworkControllerImpl networkControllerNoMobile |
| 136 | = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 137 | mConfig, Looper.getMainLooper(), mCallbackHandler, |
| 138 | mock(AccessPointControllerImpl.class), |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 139 | mock(DataUsageController.class), mMockSubDefaults); |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 140 | |
| 141 | setupNetworkController(); |
| 142 | |
| 143 | return networkControllerNoMobile; |
| 144 | |
| 145 | } |
| 146 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 147 | @Override |
| 148 | protected void tearDown() throws Exception { |
| 149 | StringWriter sw = new StringWriter(); |
| 150 | PrintWriter pw = new PrintWriter(sw); |
| 151 | mNetworkController.dump(null, pw, null); |
| 152 | pw.flush(); |
| 153 | Log.d(TAG, sw.toString()); |
| 154 | super.tearDown(); |
| 155 | } |
| 156 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 157 | // 2 Bars 3G GSM. |
| 158 | public void setupDefaultSignal() { |
| 159 | setIsGsm(true); |
| 160 | setVoiceRegState(ServiceState.STATE_IN_SERVICE); |
| 161 | setGsmRoaming(false); |
| 162 | setLevel(DEFAULT_LEVEL); |
| 163 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 164 | TelephonyManager.NETWORK_TYPE_UMTS); |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 165 | setConnectivity(NetworkCapabilities.TRANSPORT_CELLULAR, true, true); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 166 | } |
| 167 | |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 168 | public void setConnectivity(int networkType, boolean inetCondition, boolean isConnected) { |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 169 | Intent i = new Intent(ConnectivityManager.INET_CONDITION_ACTION); |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 170 | // TODO: Separate out into several NetworkCapabilities. |
| 171 | if (isConnected) { |
| 172 | mNetCapabilities.addTransportType(networkType); |
| 173 | } else { |
| 174 | mNetCapabilities.removeTransportType(networkType); |
| 175 | } |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 176 | if (inetCondition) { |
Jason Monk | d8e4bf4 | 2014-12-12 10:23:12 -0500 | [diff] [blame] | 177 | mNetCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); |
| 178 | } else { |
| 179 | mNetCapabilities.removeCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); |
| 180 | } |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 181 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 182 | mNetworkController.onReceive(mContext, i); |
| 183 | } |
| 184 | |
| 185 | public void setGsmRoaming(boolean isRoaming) { |
| 186 | when(mServiceState.getRoaming()).thenReturn(isRoaming); |
| 187 | updateServiceState(); |
| 188 | } |
| 189 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 190 | public void setCdmaRoaming(boolean isRoaming) { |
| 191 | when(mServiceState.getCdmaEriIconIndex()).thenReturn(isRoaming ? |
| 192 | EriInfo.ROAMING_INDICATOR_ON : EriInfo.ROAMING_INDICATOR_OFF); |
| 193 | when(mServiceState.getCdmaEriIconMode()).thenReturn(isRoaming ? |
| 194 | EriInfo.ROAMING_ICON_MODE_NORMAL : -1); |
| 195 | updateServiceState(); |
| 196 | } |
| 197 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 198 | public void setVoiceRegState(int voiceRegState) { |
| 199 | when(mServiceState.getVoiceRegState()).thenReturn(voiceRegState); |
| 200 | updateServiceState(); |
| 201 | } |
| 202 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 203 | public void setDataRegState(int dataRegState) { |
| 204 | when(mServiceState.getDataRegState()).thenReturn(dataRegState); |
| 205 | updateServiceState(); |
| 206 | } |
| 207 | |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 208 | public void setIsEmergencyOnly(boolean isEmergency) { |
| 209 | when(mServiceState.isEmergencyOnly()).thenReturn(isEmergency); |
| 210 | updateServiceState(); |
| 211 | } |
| 212 | |
| 213 | public void setCdmaLevel(int level) { |
| 214 | when(mSignalStrength.getCdmaLevel()).thenReturn(level); |
| 215 | updateSignalStrength(); |
| 216 | } |
| 217 | |
| 218 | public void setLevel(int level) { |
| 219 | when(mSignalStrength.getLevel()).thenReturn(level); |
| 220 | updateSignalStrength(); |
| 221 | } |
| 222 | |
| 223 | public void setIsGsm(boolean gsm) { |
| 224 | when(mSignalStrength.isGsm()).thenReturn(gsm); |
| 225 | updateSignalStrength(); |
| 226 | } |
| 227 | |
| 228 | public void setCdmaEri(int index, int mode) { |
| 229 | // TODO: Figure this out. |
| 230 | } |
| 231 | |
| 232 | private void updateSignalStrength() { |
| 233 | Log.d(TAG, "Sending Signal Strength: " + mSignalStrength); |
| 234 | mPhoneStateListener.onSignalStrengthsChanged(mSignalStrength); |
| 235 | } |
| 236 | |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 237 | protected void updateServiceState() { |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 238 | Log.d(TAG, "Sending Service State: " + mServiceState); |
| 239 | mPhoneStateListener.onServiceStateChanged(mServiceState); |
| 240 | } |
| 241 | |
| 242 | public void updateCallState(int state) { |
| 243 | // Inputs not currently used in NetworkControllerImpl. |
| 244 | mPhoneStateListener.onCallStateChanged(state, "0123456789"); |
| 245 | } |
| 246 | |
| 247 | public void updateDataConnectionState(int dataState, int dataNetType) { |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 248 | when(mServiceState.getDataNetworkType()).thenReturn(dataNetType); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 249 | mPhoneStateListener.onDataConnectionStateChanged(dataState, dataNetType); |
| 250 | } |
| 251 | |
| 252 | public void updateDataActivity(int dataActivity) { |
| 253 | mPhoneStateListener.onDataActivity(dataActivity); |
| 254 | } |
| 255 | |
Andrew Flynn | 5e75147 | 2015-05-01 11:50:07 -0400 | [diff] [blame] | 256 | public void setCarrierNetworkChange(boolean enable) { |
| 257 | Log.d(TAG, "setCarrierNetworkChange(" + enable + ")"); |
| 258 | mPhoneStateListener.onCarrierNetworkChange(enable); |
| 259 | } |
| 260 | |
Jason Monk | 21d05a0 | 2014-12-02 12:46:58 -0500 | [diff] [blame] | 261 | protected void verifyHasNoSims(boolean hasNoSimsVisible) { |
| 262 | ArgumentCaptor<Boolean> hasNoSimsArg = ArgumentCaptor.forClass(Boolean.class); |
| 263 | |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 264 | Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setNoSims(hasNoSimsArg.capture()); |
| 265 | assertEquals("No sims", hasNoSimsVisible, (boolean) hasNoSimsArg.getValue()); |
Jason Monk | 21d05a0 | 2014-12-02 12:46:58 -0500 | [diff] [blame] | 266 | } |
| 267 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 268 | protected void verifyLastQsMobileDataIndicators(boolean visible, int icon, int typeIcon, |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 269 | boolean dataIn, boolean dataOut) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 270 | ArgumentCaptor<IconState> iconArg = ArgumentCaptor.forClass(IconState.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 271 | ArgumentCaptor<Integer> typeIconArg = ArgumentCaptor.forClass(Integer.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 272 | ArgumentCaptor<Boolean> dataInArg = ArgumentCaptor.forClass(Boolean.class); |
| 273 | ArgumentCaptor<Boolean> dataOutArg = ArgumentCaptor.forClass(Boolean.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 274 | |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 275 | Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setMobileDataIndicators( |
| 276 | ArgumentCaptor.forClass(IconState.class).capture(), |
| 277 | iconArg.capture(), |
| 278 | ArgumentCaptor.forClass(Integer.class).capture(), |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 279 | typeIconArg.capture(), dataInArg.capture(), dataOutArg.capture(), |
| 280 | ArgumentCaptor.forClass(String.class).capture(), |
| 281 | ArgumentCaptor.forClass(String.class).capture(), |
| 282 | ArgumentCaptor.forClass(Boolean.class).capture(), |
| 283 | ArgumentCaptor.forClass(Integer.class).capture()); |
| 284 | IconState iconState = iconArg.getValue(); |
| 285 | assertEquals("Visibility in, quick settings", visible, iconState.visible); |
| 286 | assertEquals("Signal icon in, quick settings", icon, iconState.icon); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 287 | assertEquals("Data icon in, quick settings", typeIcon, (int) typeIconArg.getValue()); |
| 288 | assertEquals("Data direction in, in quick settings", dataIn, |
| 289 | (boolean) dataInArg.getValue()); |
| 290 | assertEquals("Data direction out, in quick settings", dataOut, |
| 291 | (boolean) dataOutArg.getValue()); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | protected void verifyLastMobileDataIndicators(boolean visible, int icon, int typeIcon) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 295 | ArgumentCaptor<IconState> iconArg = ArgumentCaptor.forClass(IconState.class); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 296 | ArgumentCaptor<Integer> typeIconArg = ArgumentCaptor.forClass(Integer.class); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 297 | |
| 298 | // TODO: Verify all fields. |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 299 | Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setMobileDataIndicators( |
| 300 | iconArg.capture(), |
| 301 | ArgumentCaptor.forClass(IconState.class).capture(), |
Andrew Flynn | 2fdbe12 | 2015-06-01 16:34:21 -0400 | [diff] [blame] | 302 | typeIconArg.capture(), |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 303 | ArgumentCaptor.forClass(Integer.class).capture(), |
| 304 | ArgumentCaptor.forClass(Boolean.class).capture(), |
| 305 | ArgumentCaptor.forClass(Boolean.class).capture(), |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 306 | ArgumentCaptor.forClass(String.class).capture(), |
| 307 | ArgumentCaptor.forClass(String.class).capture(), |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 308 | ArgumentCaptor.forClass(Boolean.class).capture(), |
| 309 | ArgumentCaptor.forClass(Integer.class).capture()); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 310 | IconState iconState = iconArg.getValue(); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 311 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 312 | assertEquals("Data icon in status bar", typeIcon, (int) typeIconArg.getValue()); |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 313 | assertEquals("Visibility in status bar", visible, iconState.visible); |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 314 | } |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 315 | |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 316 | protected void assertNetworkNameEquals(String expected) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 317 | assertEquals("Network name", expected, mMobileSignalController.getState().networkName); |
Leigh Anne | d0a6279 | 2014-11-13 14:27:10 -0800 | [diff] [blame] | 318 | } |
Jason Monk | e0cdb60 | 2014-11-05 12:39:45 -0500 | [diff] [blame] | 319 | } |