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