diff options
author | Roshan Pius <rpius@google.com> | 2020-02-24 16:39:15 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-02-24 16:39:15 +0000 |
commit | fbbcec04bf3bd46c00e8da1221c1ec8f3e971731 (patch) | |
tree | 40f84e342e09d9cfc7b41b5d8b28d877a98f810c /tests | |
parent | 78b26ab26b0d8dfe1c64a550c4902c2e83139938 (diff) | |
parent | 61282a6d2108c5d35fe699a049313525add5c8d2 (diff) |
Merge "wifi-service: Add a class for scan available settings compatibility" into rvc-dev
Diffstat (limited to 'tests')
3 files changed, 141 insertions, 3 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScanAlwaysAvailableSettingsCompatibilityTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScanAlwaysAvailableSettingsCompatibilityTest.java new file mode 100644 index 000000000..2caa813c6 --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/WifiScanAlwaysAvailableSettingsCompatibilityTest.java @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wifi; + +import static com.android.server.wifi.WifiScanAlwaysAvailableSettingsCompatibility.SETTINGS_GLOBAL_WIFI_SCAN_ALWAYS_AVAILABLE; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.validateMockitoUsage; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.content.ContentResolver; +import android.content.Context; +import android.database.ContentObserver; +import android.os.Handler; + +import androidx.test.filters.SmallTest; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Unit tests for {@link com.android.server.wifi.WifiScanAlwaysAvailableSettingsCompatibility}. + */ +@SmallTest +public class WifiScanAlwaysAvailableSettingsCompatibilityTest extends WifiBaseTest { + @Mock + private Context mContext; + @Mock + private Handler mHandler; + @Mock + private WifiSettingsStore mWifiSettingsStore; + @Mock + private ActiveModeWarden mActiveModeWarden; + @Mock + private FrameworkFacade mFrameworkFacade; + @Mock + private ContentResolver mContentResolver; + + private ArgumentCaptor<ContentObserver> mContentObserverArgumentCaptor = + ArgumentCaptor.forClass(ContentObserver.class); + + private WifiScanAlwaysAvailableSettingsCompatibility mScanAlwaysCompatibility; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + + when(mContext.getContentResolver()).thenReturn(mContentResolver); + mScanAlwaysCompatibility = + new WifiScanAlwaysAvailableSettingsCompatibility(mContext, mHandler, + mWifiSettingsStore, mActiveModeWarden, mFrameworkFacade); + } + + /** + * Called after each test + */ + @After + public void cleanup() { + validateMockitoUsage(); + } + + @Test + public void reactToContentObserverChanges() { + mScanAlwaysCompatibility.initialize(); + verify(mContentResolver).registerContentObserver( + any(), anyBoolean(), mContentObserverArgumentCaptor.capture()); + + ContentObserver contentObserver = mContentObserverArgumentCaptor.getValue(); + assertNotNull(contentObserver); + + when(mWifiSettingsStore.isScanAlwaysAvailable()).thenReturn(false); + when(mFrameworkFacade.getIntegerSetting( + any(ContentResolver.class), + eq(SETTINGS_GLOBAL_WIFI_SCAN_ALWAYS_AVAILABLE), + anyInt())) + .thenReturn(1); + contentObserver.onChange(false); + + verify(mWifiSettingsStore).handleWifiScanAlwaysAvailableToggled(true); + verify(mActiveModeWarden).scanAlwaysModeChanged(); + + when(mWifiSettingsStore.isScanAlwaysAvailable()).thenReturn(true); + when(mFrameworkFacade.getIntegerSetting( + any(ContentResolver.class), + eq(SETTINGS_GLOBAL_WIFI_SCAN_ALWAYS_AVAILABLE), + anyInt())) + .thenReturn(0); + contentObserver.onChange(false); + + verify(mWifiSettingsStore).handleWifiScanAlwaysAvailableToggled(false); + verify(mActiveModeWarden, times(2)).scanAlwaysModeChanged(); + } + + + @Test + public void changeSetting() { + mScanAlwaysCompatibility.initialize(); + + mScanAlwaysCompatibility.handleWifiScanAlwaysAvailableToggled(true); + verify(mFrameworkFacade).setIntegerSetting( + any(ContentResolver.class), + eq(SETTINGS_GLOBAL_WIFI_SCAN_ALWAYS_AVAILABLE), + eq(1)); + + mScanAlwaysCompatibility.handleWifiScanAlwaysAvailableToggled(false); + verify(mFrameworkFacade).setIntegerSetting( + any(ContentResolver.class), + eq(SETTINGS_GLOBAL_WIFI_SCAN_ALWAYS_AVAILABLE), + eq(0)); + } +} diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 08380614d..f1e515b9c 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -307,6 +307,7 @@ public class WifiServiceImplTest extends WifiBaseTest { @Mock IOnWifiActivityEnergyInfoListener mOnWifiActivityEnergyInfoListener; @Mock IWifiConnectedNetworkScorer mWifiConnectedNetworkScorer; @Mock WifiSettingsConfigStore mWifiSettingsConfigStore; + @Mock WifiScanAlwaysAvailableSettingsCompatibility mScanAlwaysAvailableSettingsCompatibility; WifiLog mLog = new LogcatLog(TAG); @@ -380,6 +381,8 @@ public class WifiServiceImplTest extends WifiBaseTest { when(mWifiInjector.getWifiThreadRunner()) .thenReturn(new WifiThreadRunner(new Handler(mLooper.getLooper()))); when(mWifiInjector.getSettingsConfigStore()).thenReturn(mWifiSettingsConfigStore); + when(mWifiInjector.getWifiScanAlwaysAvailableSettingsCompatibility()) + .thenReturn(mScanAlwaysAvailableSettingsCompatibility); when(mClientModeImpl.syncStartSubscriptionProvisioning(anyInt(), any(OsuProvider.class), any(IProvisioningCallback.class), any())).thenReturn(true); // Create an OSU provider that can be provisioned via an open OSU AP diff --git a/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java index 7f6e1e1cd..799df547b 100644 --- a/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java +++ b/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java @@ -1224,17 +1224,17 @@ public class WifiPermissionsUtilTest extends WifiBaseTest { doThrow(new RuntimeException()).when(mLocationManager).isLocationEnabledForUser(any()); when(mMockFrameworkFacade.getIntegerSetting( - any(), eq(Settings.Secure.LOCATION_MODE), anyInt())) + any(Context.class), eq(Settings.Secure.LOCATION_MODE), anyInt())) .thenReturn(Settings.Secure.LOCATION_MODE_OFF); assertFalse(codeUnderTest.isLocationModeEnabled()); when(mMockFrameworkFacade.getIntegerSetting( - any(), eq(Settings.Secure.LOCATION_MODE), anyInt())) + any(Context.class), eq(Settings.Secure.LOCATION_MODE), anyInt())) .thenReturn(Settings.Secure.LOCATION_MODE_ON); assertTrue(codeUnderTest.isLocationModeEnabled()); verify(mMockFrameworkFacade, times(2)).getIntegerSetting( - any(), eq(Settings.Secure.LOCATION_MODE), anyInt()); + any(Context.class), eq(Settings.Secure.LOCATION_MODE), anyInt()); } private Answer<Integer> createPermissionAnswer() { |