summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2020-02-12 12:53:51 -0800
committerRoshan Pius <rpius@google.com>2020-02-18 07:27:31 -0800
commit6600bfdcff3069b9522e8ad37b6a8e1a02afc2b1 (patch)
tree81163d4f81095c649d0886bb79006618a31420af /tests
parentdf01391f63407ea6611a02befd600efe4dd80c0f (diff)
WifiService: Add API for scan always available toggle
We still use the Settings.Global value to persist state. Will migrate to SharedPreferences in a follow up CL. Bug: 148514485 Test: atest com.android.server.wifi Test: Verified wifi wifi scan toggle in location settings. Change-Id: Id81c775f0ab252b1d41a7b66308502d71efee3e0
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java27
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java25
2 files changed, 40 insertions, 12 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java
index 4275518a9..f3317fdd6 100644
--- a/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
@@ -140,11 +141,21 @@ public class SoftApStoreDataTest extends WifiBaseTest {
@Mock private Context mContext;
@Mock SoftApStoreData.DataSource mDataSource;
@Mock WifiOemConfigStoreMigrationDataHolder mWifiOemConfigStoreMigrationDataHolder;
+ @Mock private WifiOemMigrationHook.SettingsMigrationData mOemMigrationData;
+ MockitoSession mSession;
SoftApStoreData mSoftApStoreData;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
+ mSession = ExtendedMockito.mockitoSession()
+ .mockStatic(WifiOemMigrationHook.class, withSettings().lenient())
+ .strictness(Strictness.LENIENT)
+ .startMocking();
+ when(WifiOemMigrationHook.loadFromSettings(any(Context.class)))
+ .thenReturn(mOemMigrationData);
+ when(mOemMigrationData.isSoftApTimeoutEnabled()).thenReturn(true);
+
mSoftApStoreData =
new SoftApStoreData(mContext, mDataSource, mWifiOemConfigStoreMigrationDataHolder);
TEST_BLOCKEDLIST.add(MacAddress.fromString(TEST_BLOCKED_CLIENT));
@@ -158,6 +169,7 @@ public class SoftApStoreDataTest extends WifiBaseTest {
public void cleanup() {
TEST_BLOCKEDLIST.clear();
TEST_ALLOWEDLIST.clear();
+ mSession.finishMocking();
}
/**
@@ -463,16 +475,9 @@ public class SoftApStoreDataTest extends WifiBaseTest {
*/
@Test
public void deserializeSoftApWithNoAutoShutdownTag() throws Exception {
- MockitoSession session = ExtendedMockito.mockitoSession()
- .mockStatic(WifiConfigStore.class, withSettings().lenient())
- .strictness(Strictness.LENIENT)
- .startMocking();
- WifiOemMigrationHook.SettingsMigrationData migrationData = mock(
- WifiOemMigrationHook.SettingsMigrationData.class);
- when(WifiOemMigrationHook.loadFromSettings(any())).thenReturn(migrationData);
// Toggle on when migrating.
- when(migrationData.isSoftApTimeoutEnabled()).thenReturn(true);
+ when(mOemMigrationData.isSoftApTimeoutEnabled()).thenReturn(true);
deserializeData(
TEST_SOFTAP_CONFIG_XML_STRING_WITH_ALL_CONFIG_EXCEPT_AUTO_SHUTDOWN.getBytes());
ArgumentCaptor<SoftApConfiguration> softapConfigCaptor =
@@ -484,16 +489,14 @@ public class SoftApStoreDataTest extends WifiBaseTest {
assertTrue(softApConfig.isAutoShutdownEnabled());
// Toggle off when migrating.
- when(migrationData.isSoftApTimeoutEnabled()).thenReturn(false);
+ when(mOemMigrationData.isSoftApTimeoutEnabled()).thenReturn(false);
deserializeData(
TEST_SOFTAP_CONFIG_XML_STRING_WITH_ALL_CONFIG_EXCEPT_AUTO_SHUTDOWN.getBytes());
- verify(mDataSource).fromDeserialized(softapConfigCaptor.capture());
+ verify(mDataSource, times(2)).fromDeserialized(softapConfigCaptor.capture());
softApConfig = softapConfigCaptor.getValue();
assertNotNull(softApConfig);
assertEquals(softApConfig.getSsid(), TEST_SSID);
assertFalse(softApConfig.isAutoShutdownEnabled());
-
- session.finishMocking();
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index a289171b4..7601850eb 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -5580,4 +5580,29 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.stopAutoDispatchAndIgnoreExceptions();
verify(mWakeupController).isEnabled();
}
+
+ @Test
+ public void testSetScanAlwaysAvailableWithNetworkSettingsPermission() {
+ doNothing().when(mContext)
+ .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_SETTINGS),
+ eq("WifiService"));
+ mWifiServiceImpl.setScanAlwaysAvailable(true);
+ verify(mSettingsStore).handleWifiScanAlwaysAvailableToggled(true);
+ verify(mActiveModeWarden).scanAlwaysModeChanged();
+
+ mWifiServiceImpl.setScanAlwaysAvailable(false);
+ verify(mSettingsStore).handleWifiScanAlwaysAvailableToggled(false);
+ verify(mActiveModeWarden, times(2)).scanAlwaysModeChanged();
+ }
+
+ @Test(expected = SecurityException.class)
+ public void testSetScanAlwaysAvailableWithNoNetworkSettingsPermission() {
+ doThrow(new SecurityException()).when(mContext)
+ .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_SETTINGS),
+ eq("WifiService"));
+
+ mWifiServiceImpl.setScanAlwaysAvailable(true);
+ verify(mSettingsStore, never()).handleWifiScanAlwaysAvailableToggled(anyBoolean());
+ verify(mActiveModeWarden, never()).scanAlwaysModeChanged();
+ }
}