wifi: add test for tracking Passpoint AP on devices with Passpoint disabled

On a device with Passspoint disabled (config_wifi_hotspot2_enabled build config
set to false), calls to WifiManager#getMatchingWifiConfig will throw
an UnsupportedOperationException.  So add a test to verify that exception
is being caught in WifiTracker#udpateAccessPoints.

Bug: 36649203
Test: runtest --path
      frameworks/base/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java

Change-Id: If7d3d4122c36b1b98c24abf703d6492771918125
This commit is contained in:
Peter Qiu
2017-03-28 13:24:34 -07:00
parent d686e9c26e
commit f562838125

View File

@@ -20,9 +20,11 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -580,4 +582,40 @@ public class WifiTrackerTest {
mWorkerThread.quit();
updateScores();
}
/**
* Verify that tracking a Passpoint AP on a device with Passpoint disabled doesn't cause
* any crash.
*
* @throws Exception
*/
@Test
public void trackPasspointApWithPasspointDisabled() throws Exception {
WifiTracker tracker = createMockedWifiTracker();
// Add a Passpoint AP to the scan results.
List<ScanResult> results = new ArrayList<>();
ScanResult passpointAp = new ScanResult(
WifiSsid.createFromAsciiEncoded(SSID_1),
BSSID_1,
0, // hessid
0, //anqpDomainId
null, // osuProviders
"", // capabilities
RSSI_1,
0, // frequency
SystemClock.elapsedRealtime() * 1000 /* microsecond timestamp */);
passpointAp.setFlag(ScanResult.FLAG_PASSPOINT_NETWORK);
results.add(passpointAp);
// Update access point and verify UnsupportedOperationException is being caught for
// call to WifiManager#getMatchingWifiConfig.
when(mockWifiManager.getConfiguredNetworks())
.thenReturn(new ArrayList<WifiConfiguration>());
when(mockWifiManager.getScanResults()).thenReturn(results);
doThrow(new UnsupportedOperationException())
.when(mockWifiManager).getMatchingWifiConfig(any(ScanResult.class));
tracker.forceUpdate();
verify(mockWifiManager).getMatchingWifiConfig(any(ScanResult.class));
}
}