summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-10-24 02:25:37 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-10-24 02:25:37 +0000
commitd56913d0ab487af2447fbf50fcfb741a7cadc882 (patch)
treefbec61861ddb68574cb2755b1e9869e44beb0fee /tests
parent65c0f2bdef15ce2c7e370d55cc304799bb860323 (diff)
parenta8b1db884447aeba2a720e525216b6392715080a (diff)
Merge "Optimize ignore connection to same network"
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java48
1 files changed, 30 insertions, 18 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
index 7671076c0..efd45b184 100644
--- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
@@ -443,6 +443,8 @@ public class ClientModeImplTest extends WifiBaseTest {
when(mWifiInjector.getWifiScoreCard()).thenReturn(mWifiScoreCard);
when(mWifiInjector.getWifiLockManager()).thenReturn(mWifiLockManager);
when(mWifiInjector.getCarrierNetworkConfig()).thenReturn(mCarrierNetworkConfig);
+ when(mWifiInjector.getWifiThreadRunner())
+ .thenReturn(new WifiThreadRunner(new Handler(mLooper.getLooper())));
when(mWifiNetworkFactory.getSpecificNetworkRequestUidAndPackageName(any()))
.thenReturn(Pair.create(Process.INVALID_UID, ""));
when(mWifiNative.initialize()).thenReturn(true);
@@ -1335,32 +1337,44 @@ public class ClientModeImplTest extends WifiBaseTest {
* that connection request returns with CONNECT_NETWORK_SUCCEEDED.
*/
@Test
- public void reconnectToConnectedNetwork() throws Exception {
- initializeAndAddNetworkAndVerifySuccess();
-
- verify(mWifiNative).removeAllNetworks(WIFI_IFACE_NAME);
+ public void reconnectToConnectedNetworkWithNetworkId() throws Exception {
+ connect();
+ // try to reconnect
IActionListener connectActionListener = mock(IActionListener.class);
- mCmi.connect(null, 0, mock(Binder.class), connectActionListener, 0, Binder.getCallingUid());
+ mCmi.connect(null, FRAMEWORK_NETWORK_ID, mock(Binder.class), connectActionListener, 0,
+ Binder.getCallingUid());
mLooper.dispatchAll();
verify(connectActionListener).onSuccess();
- verify(mWifiConfigManager).enableNetwork(eq(0), eq(true), anyInt(), any());
-
- mCmi.sendMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, sBSSID);
- mLooper.dispatchAll();
-
- mCmi.sendMessage(WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT, 0, 0,
- new StateChangeResult(0, sWifiSsid, sBSSID, SupplicantState.COMPLETED));
- mLooper.dispatchAll();
+ // Verify that we didn't trigger a second connection.
+ verify(mWifiNative, times(1)).connectToNetwork(eq(WIFI_IFACE_NAME), any());
+ }
- assertEquals("ObtainingIpState", getCurrentState().getName());
+ /**
+ * If caller tries to connect to a network that is already connected, the connection request
+ * should succeed.
+ *
+ * Test: Create and connect to a network, then try to reconnect to the same network. Verify
+ * that connection request returns with CONNECT_NETWORK_SUCCEEDED.
+ */
+ @Test
+ public void reconnectToConnectedNetworkWithConfig() throws Exception {
+ connect();
// try to reconnect
- reset(connectActionListener);
- mCmi.connect(null, 0, mock(Binder.class), connectActionListener, 0, Binder.getCallingUid());
+ WifiConfiguration config = new WifiConfiguration();
+ config.networkId = FRAMEWORK_NETWORK_ID;
+ when(mWifiConfigManager.addOrUpdateNetwork(eq(config), anyInt()))
+ .thenReturn(new NetworkUpdateResult(FRAMEWORK_NETWORK_ID));
+ IActionListener connectActionListener = mock(IActionListener.class);
+ mCmi.connect(config, WifiConfiguration.INVALID_NETWORK_ID, mock(Binder.class),
+ connectActionListener, 0, Binder.getCallingUid());
mLooper.dispatchAll();
verify(connectActionListener).onSuccess();
+
+ // Verify that we didn't trigger a second connection.
+ verify(mWifiNative, times(1)).connectToNetwork(eq(WIFI_IFACE_NAME), any());
}
/**
@@ -1398,8 +1412,6 @@ public class ClientModeImplTest extends WifiBaseTest {
mCmi.connect(null, TEST_NETWORK_ID, mock(Binder.class), null, 0, Binder.getCallingUid());
mLooper.dispatchAll();
- verify(mWifiNative).disconnect(any());
-
mCmi.sendMessage(WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT, 0, 0,
new StateChangeResult(0, sWifiSsid, sBSSID, SupplicantState.DISCONNECTED));
mLooper.dispatchAll();