summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-08-22 03:29:15 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-08-22 03:29:15 +0000
commitf6e0f26cc0823b628f887c651a906fa3ebbab070 (patch)
tree8c1dbd620ddb08df5e9393d0fb43dc1e61b51697 /tests
parentc2775146944350a720acbf33942a583540094246 (diff)
parentd27716a747d9cf2d86153aa9ec1b55b663808b28 (diff)
Merge "Update NETWORK_CONNECTION_EVENT netId after WPS" into oc-mr1-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java89
1 files changed, 76 insertions, 13 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index be5892196..4623fe7d4 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -1571,31 +1571,29 @@ public class WifiStateMachineTest {
}
/**
- * Verify successful Wps PBC network connection.
+ * Sunny-day scenario for WPS connections. Verifies that after a START_WPS and
+ * NETWORK_CONNECTION_EVENT command, WifiStateMachine will have transitioned to ObtainingIpState
*/
@Test
public void wpsPbcConnectSuccess() throws Exception {
loadComponentsInStaMode();
mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
mLooper.dispatchAll();
+ assertEquals("DisconnectedState", getCurrentState().getName());
- when(mWifiNative.startWpsPbc(eq(sBSSID))).thenReturn(true);
WpsInfo wpsInfo = new WpsInfo();
wpsInfo.setup = WpsInfo.PBC;
wpsInfo.BSSID = sBSSID;
-
+ when(mWifiNative.removeAllNetworks()).thenReturn(true);
+ when(mWifiNative.startWpsPbc(anyString())).thenReturn(true);
mWsm.sendMessage(WifiManager.START_WPS, 0, 0, wpsInfo);
mLooper.dispatchAll();
- verify(mWifiNative).startWpsPbc(eq(sBSSID));
-
assertEquals("WpsRunningState", getCurrentState().getName());
setupMocksForWpsNetworkMigration();
-
mWsm.sendMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, null);
mLooper.dispatchAll();
-
- assertEquals("DisconnectedState", getCurrentState().getName());
+ assertEquals("ObtainingIpState", getCurrentState().getName());
verifyMocksForWpsNetworkMigration();
}
@@ -1621,6 +1619,68 @@ public class WifiStateMachineTest {
}
/**
+ * Verify that if Supplicant generates multiple networks for a WPS configuration,
+ * WifiStateMachine cycles into DisconnectedState
+ */
+ @Test
+ public void wpsPbcConnectFailure_tooManyConfigs() throws Exception {
+ loadComponentsInStaMode();
+ mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
+ mLooper.dispatchAll();
+ assertEquals("DisconnectedState", getCurrentState().getName());
+
+ WpsInfo wpsInfo = new WpsInfo();
+ wpsInfo.setup = WpsInfo.PBC;
+ wpsInfo.BSSID = sBSSID;
+ when(mWifiNative.removeAllNetworks()).thenReturn(true);
+ when(mWifiNative.startWpsPbc(anyString())).thenReturn(true);
+ mWsm.sendMessage(WifiManager.START_WPS, 0, 0, wpsInfo);
+ mLooper.dispatchAll();
+ assertEquals("WpsRunningState", getCurrentState().getName());
+
+ setupMocksForWpsNetworkMigration();
+ doAnswer(new AnswerWithArguments() {
+ public boolean answer(Map<String, WifiConfiguration> configs,
+ SparseArray<Map<String, String>> networkExtras) throws Exception {
+ configs.put("dummy1", new WifiConfiguration());
+ configs.put("dummy2", new WifiConfiguration());
+ return true;
+ }
+ }).when(mWifiNative).migrateNetworksFromSupplicant(any(Map.class), any(SparseArray.class));
+ mWsm.sendMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, null);
+ mLooper.dispatchAll();
+ assertTrue("DisconnectedState".equals(getCurrentState().getName()));
+ }
+
+ /**
+ * Verify that when supplicant fails to load networks during WPS, WifiStateMachine cycles into
+ * DisconnectedState
+ */
+ @Test
+ public void wpsPbcConnectFailure_migrateNetworksFailure() throws Exception {
+ loadComponentsInStaMode();
+ mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
+ mLooper.dispatchAll();
+ assertEquals("DisconnectedState", getCurrentState().getName());
+
+ WpsInfo wpsInfo = new WpsInfo();
+ wpsInfo.setup = WpsInfo.PBC;
+ wpsInfo.BSSID = sBSSID;
+ when(mWifiNative.removeAllNetworks()).thenReturn(true);
+ when(mWifiNative.startWpsPbc(anyString())).thenReturn(true);
+ mWsm.sendMessage(WifiManager.START_WPS, 0, 0, wpsInfo);
+ mLooper.dispatchAll();
+ assertEquals("WpsRunningState", getCurrentState().getName());
+
+ setupMocksForWpsNetworkMigration();
+ when(mWifiNative.migrateNetworksFromSupplicant(any(Map.class), any(SparseArray.class)))
+ .thenReturn(false);
+ mWsm.sendMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, null);
+ mLooper.dispatchAll();
+ assertEquals("DisconnectedState", getCurrentState().getName());
+ }
+
+ /**
* Verify successful Wps Pin Display network connection.
*/
@Test
@@ -1645,7 +1705,7 @@ public class WifiStateMachineTest {
mWsm.sendMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, null);
mLooper.dispatchAll();
- assertEquals("DisconnectedState", getCurrentState().getName());
+ assertEquals("ObtainingIpState", getCurrentState().getName());
verifyMocksForWpsNetworkMigration();
}
@@ -1718,13 +1778,12 @@ public class WifiStateMachineTest {
}
private void setupMocksForWpsNetworkMigration() {
- // Now trigger the network connection event for adding the WPS network.
+ WifiConfiguration config = new WifiConfiguration();
+ config.networkId = WPS_SUPPLICANT_NETWORK_ID;
+ config.SSID = DEFAULT_TEST_SSID;
doAnswer(new AnswerWithArguments() {
public boolean answer(Map<String, WifiConfiguration> configs,
SparseArray<Map<String, String>> networkExtras) throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.networkId = WPS_SUPPLICANT_NETWORK_ID;
- config.SSID = DEFAULT_TEST_SSID;
configs.put("dummy", config);
return true;
}
@@ -1733,6 +1792,10 @@ public class WifiStateMachineTest {
.thenReturn(new NetworkUpdateResult(WPS_FRAMEWORK_NETWORK_ID));
when(mWifiConfigManager.enableNetwork(eq(WPS_FRAMEWORK_NETWORK_ID), anyBoolean(), anyInt()))
.thenReturn(true);
+ when(mWifiNative.getFrameworkNetworkId(eq(WPS_FRAMEWORK_NETWORK_ID))).thenReturn(
+ WPS_FRAMEWORK_NETWORK_ID);
+ when(mWifiConfigManager.getConfiguredNetwork(eq(WPS_FRAMEWORK_NETWORK_ID))).thenReturn(
+ config);
}
private void verifyMocksForWpsNetworkMigration() {