diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index f3d967e73..6a248161c 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -2739,6 +2739,57 @@ public class WifiServiceImplTest { verify(mWifiStateMachine, never()).removeUserConfigs(userHandle); } + /** + * Test for needs5GHzToAnyApBandConversion returns true. Requires the NETWORK_SETTINGS + * permission. + */ + @Test + public void testNeeds5GHzToAnyApBandConversionReturnedTrue() { + when(mResources.getBoolean( + eq(com.android.internal.R.bool.config_wifi_convert_apband_5ghz_to_any))) + .thenReturn(true); + assertTrue(mWifiServiceImpl.needs5GHzToAnyApBandConversion()); + + verify(mContext).enforceCallingOrSelfPermission( + eq(android.Manifest.permission.NETWORK_SETTINGS), eq("WifiService")); + } + + /** + * Test for needs5GHzToAnyApBandConversion returns false. Requires the NETWORK_SETTINGS + * permission. + */ + @Test + public void testNeeds5GHzToAnyApBandConversionReturnedFalse() { + when(mResources.getBoolean( + eq(com.android.internal.R.bool.config_wifi_convert_apband_5ghz_to_any))) + .thenReturn(false); + + assertFalse(mWifiServiceImpl.needs5GHzToAnyApBandConversion()); + + verify(mContext).enforceCallingOrSelfPermission( + eq(android.Manifest.permission.NETWORK_SETTINGS), eq("WifiService")); + } + + /** + * The API impl for needs5GHzToAnyApBandConversion requires the NETWORK_SETTINGS permission, + * verify an exception is thrown without holding the permission. + */ + @Test + public void testNeeds5GHzToAnyApBandConversionThrowsWithoutProperPermissions() { + doThrow(new SecurityException()).when(mContext) + .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_SETTINGS), + eq("WifiService")); + + try { + mWifiServiceImpl.needs5GHzToAnyApBandConversion(); + // should have thrown an exception - fail test + fail(); + } catch (SecurityException e) { + // expected + } + } + + private class IdleModeIntentMatcher implements ArgumentMatcher<IntentFilter> { @Override public boolean matches(IntentFilter filter) { |