diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2017-07-24 20:25:23 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-07-24 20:25:23 +0000 |
commit | a305257d7c3b3421d47fb8f00799749aae9645a2 (patch) | |
tree | 7e21226ea611aa5af7f751207bfd19b2b4b6e9b9 /tests | |
parent | f289d0be14c14fa1f332e62471565bbc4c725fa0 (diff) | |
parent | 06dcab2ee1a5d1293c9142f40cb65b52ffa2a5d6 (diff) |
Merge "WifiStateMachine: Dont repeatedly call sendExplicitlySelected" into oc-dr1-dev
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index fc2cda443..10d6460ab 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -345,6 +345,7 @@ public class WifiStateMachineTest { @Mock IpManager mIpManager; @Mock TelephonyManager mTelephonyManager; @Mock WrongPasswordNotifier mWrongPasswordNotifier; + @Mock Clock mClock; public WifiStateMachineTest() throws Exception { } @@ -386,6 +387,7 @@ public class WifiStateMachineTest { when(mWifiInjector.getWifiNative()).thenReturn(mWifiNative); when(mWifiInjector.getSelfRecovery()).thenReturn(mSelfRecovery); when(mWifiInjector.makeTelephonyManager()).thenReturn(mTelephonyManager); + when(mWifiInjector.getClock()).thenReturn(mClock); when(mWifiNative.setupForClientMode()) .thenReturn(Pair.create(WifiNative.SETUP_SUCCESS, mClientInterface)); @@ -2026,7 +2028,7 @@ public class WifiStateMachineTest { verify(mWifiNative, never()).resetTxPowerLimit(); } - /* + /** * Verifies that a network disconnection event will result in WifiStateMachine invoking * {@link WifiConfigManager#removeAllEphemeralOrPasspointConfiguredNetworks()} to remove * any ephemeral or passpoint networks from it's internal database. @@ -2036,4 +2038,69 @@ public class WifiStateMachineTest { disconnect(); verify(mWifiConfigManager).removeAllEphemeralOrPasspointConfiguredNetworks(); } + + /** + * Test that the helper method + * {@link WifiStateMachine#shouldEvaluateWhetherToSendExplicitlySelected(WifiConfiguration)} + * returns true when we connect to the last selected network before expiration of + * {@link WifiStateMachine#LAST_SELECTED_NETWORK_EXPIRATION_AGE_MILLIS}. + */ + @Test + public void testShouldEvaluateWhetherToSendExplicitlySelected_SameNetworkNotExpired() { + long lastSelectedTimestamp = 45666743454L; + int lastSelectedNetworkId = 5; + + when(mClock.getElapsedSinceBootMillis()).thenReturn( + lastSelectedTimestamp + + WifiStateMachine.LAST_SELECTED_NETWORK_EXPIRATION_AGE_MILLIS - 1); + when(mWifiConfigManager.getLastSelectedTimeStamp()).thenReturn(lastSelectedTimestamp); + when(mWifiConfigManager.getLastSelectedNetwork()).thenReturn(lastSelectedNetworkId); + + WifiConfiguration currentConfig = new WifiConfiguration(); + currentConfig.networkId = lastSelectedNetworkId; + assertTrue(mWsm.shouldEvaluateWhetherToSendExplicitlySelected(currentConfig)); + } + + /** + * Test that the helper method + * {@link WifiStateMachine#shouldEvaluateWhetherToSendExplicitlySelected(WifiConfiguration)} + * returns false when we connect to the last selected network after expiration of + * {@link WifiStateMachine#LAST_SELECTED_NETWORK_EXPIRATION_AGE_MILLIS}. + */ + @Test + public void testShouldEvaluateWhetherToSendExplicitlySelected_SameNetworkExpired() { + long lastSelectedTimestamp = 45666743454L; + int lastSelectedNetworkId = 5; + + when(mClock.getElapsedSinceBootMillis()).thenReturn( + lastSelectedTimestamp + + WifiStateMachine.LAST_SELECTED_NETWORK_EXPIRATION_AGE_MILLIS + 1); + when(mWifiConfigManager.getLastSelectedTimeStamp()).thenReturn(lastSelectedTimestamp); + when(mWifiConfigManager.getLastSelectedNetwork()).thenReturn(lastSelectedNetworkId); + + WifiConfiguration currentConfig = new WifiConfiguration(); + currentConfig.networkId = lastSelectedNetworkId; + assertFalse(mWsm.shouldEvaluateWhetherToSendExplicitlySelected(currentConfig)); + } + + /** + * Test that the helper method + * {@link WifiStateMachine#shouldEvaluateWhetherToSendExplicitlySelected(WifiConfiguration)} + * returns false when we connect to a different network to the last selected network. + */ + @Test + public void testShouldEvaluateWhetherToSendExplicitlySelected_DifferentNetwork() { + long lastSelectedTimestamp = 45666743454L; + int lastSelectedNetworkId = 5; + + when(mClock.getElapsedSinceBootMillis()).thenReturn( + lastSelectedTimestamp + + WifiStateMachine.LAST_SELECTED_NETWORK_EXPIRATION_AGE_MILLIS - 1); + when(mWifiConfigManager.getLastSelectedTimeStamp()).thenReturn(lastSelectedTimestamp); + when(mWifiConfigManager.getLastSelectedNetwork()).thenReturn(lastSelectedNetworkId); + + WifiConfiguration currentConfig = new WifiConfiguration(); + currentConfig.networkId = lastSelectedNetworkId - 1; + assertFalse(mWsm.shouldEvaluateWhetherToSendExplicitlySelected(currentConfig)); + } } |