summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2016-04-05 16:18:34 -0700
committerRoshan Pius <rpius@google.com>2016-04-18 10:47:34 -0700
commita6b66a48b231f5729b8015d3446feb4c2fa0a9d1 (patch)
treec83017fa428249c26e53c7bee9a2ec7c251f6da6 /tests
parent752bd0ed137ccc42cdfd911611f2d5f8d33be53c (diff)
QNS: Skip ephemeral networks deleted by user
Skip ephemeral networks which were explicitly deleted by the user. This was missed in migration from autojoin to QNS. BUG: 28026676 Change-Id: Ib663183b29774b851e492ddd170c4b4bef03ae61 TEST: Compiles & unit-test passes
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiQualifiedNetworkSelectorTest.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiQualifiedNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiQualifiedNetworkSelectorTest.java
index 5af267b19..a7a73f171 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiQualifiedNetworkSelectorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiQualifiedNetworkSelectorTest.java
@@ -1808,4 +1808,70 @@ public class WifiQualifiedNetworkSelectorTest {
assertEquals(mWifiQualifiedNetworkSelector.getFilteredScanDetails().get(0).first.toString(),
scanDetails.get(0).toString());
}
+
+ /**
+ * Case #36 Ignore an ephemeral network if it was previously deleted.
+ *
+ * In this test. we simulate following scenario:
+ * WifiStateMachine is not connected to any network.
+ * selectQualifiedNetwork() is called with 2 scan results, test1 and test2.
+ * test1 is an open network with a low score. Additionally it's a metered network.
+ * test2 is an open network with a good score but was previously deleted.
+ * isUntrustedConnectionsAllowed is set to true.
+ *
+ * expected result: return test1 with meteredHint set to True.
+ */
+ @Test
+ public void selectQualifiedNetworkDoesNotChooseDeletedEphemeral() {
+ String[] ssids = DEFAULT_SSIDS;
+ String[] bssids = DEFAULT_BSSIDS;
+ int[] frequencies = {5200, 5200};
+ String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[ESS]"};
+ int[] levels = {-70, -70};
+ Integer[] scores = {20, 120};
+ boolean[] meteredHints = {true, false};
+
+ List<ScanDetail> scanDetails = getScanDetails(ssids, bssids, frequencies, caps, levels);
+ configureScoreCache(scanDetails, scores, meteredHints);
+
+ // No saved networks.
+ when(mWifiConfigManager.updateSavedNetworkWithNewScanDetail(any(ScanDetail.class)))
+ .thenReturn(null);
+
+ WifiConfiguration unTrustedNetworkCandidate = mock(WifiConfiguration.class);
+ // Setup the config as an invalid candidate. This is done to workaround a Mockito issue.
+ // Basically Mockito is unable to mock package-private methods in classes loaded from a
+ // different Jar (like all of the framework code) which results in the actual saveNetwork()
+ // method being invoked in this case. Because the config is invalid it quickly returns.
+ unTrustedNetworkCandidate.SSID = null;
+ unTrustedNetworkCandidate.networkId = WifiConfiguration.INVALID_NETWORK_ID;
+ ScanResult untrustedScanResult = scanDetails.get(0).getScanResult();
+ when(mWifiConfigManager
+ .wifiConfigurationFromScanResult(untrustedScanResult))
+ .thenReturn(unTrustedNetworkCandidate);
+
+ // The second scan result is for an ephemeral network which was previously deleted
+ when(mWifiConfigManager
+ .wasEphemeralNetworkDeleted(scanDetails.get(0).getScanResult().SSID))
+ .thenReturn(false);
+ when(mWifiConfigManager
+ .wasEphemeralNetworkDeleted(scanDetails.get(1).getScanResult().SSID))
+ .thenReturn(true);
+
+ WifiConfiguration.NetworkSelectionStatus selectionStatus =
+ mock(WifiConfiguration.NetworkSelectionStatus.class);
+ when(unTrustedNetworkCandidate.getNetworkSelectionStatus()).thenReturn(selectionStatus);
+
+ WifiConfiguration candidate = mWifiQualifiedNetworkSelector.selectQualifiedNetwork(
+ false /* forceSelectNetwork */,
+ true /* isUntrustedConnectionsAllowed */,
+ scanDetails,
+ false, /* isLinkDebouncing */
+ false, /* isConnected */
+ true, /* isDisconnected */
+ false /* isSupplicantTransient */);
+ verify(selectionStatus).setCandidate(untrustedScanResult);
+ assertSame(candidate, unTrustedNetworkCandidate);
+ assertEquals(meteredHints[0], candidate.meteredHint);
+ }
}