DO NOT MERGE - qt-qpr1-dev-plus-aosp-without-vendor@5915889 into stage-aosp-master
Bug: 142003500 Change-Id: Ibae6b218a616a93cfda05dd77a5ea6f3a2dc4cea
This commit is contained in:
@@ -19,8 +19,8 @@ package com.android.settings.applications.appinfo;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
@@ -39,8 +39,8 @@ import android.app.admin.DevicePolicyManager;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.om.OverlayManager;
|
||||
import android.content.om.OverlayInfo;
|
||||
import android.content.om.OverlayManager;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -49,6 +49,8 @@ import android.os.UserManager;
|
||||
import android.util.ArraySet;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
@@ -59,7 +61,6 @@ import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.widget.ActionButtonsPreference;
|
||||
|
||||
import java.util.Set;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -70,12 +71,15 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AppButtonsPreferenceControllerTest {
|
||||
|
||||
@@ -112,10 +116,9 @@ public class AppButtonsPreferenceControllerTest {
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private Application mApplication;
|
||||
@Mock
|
||||
private PackageInfo mPackageInfo;
|
||||
|
||||
private Context mContext;
|
||||
private Intent mUninstallIntent;
|
||||
private ActionButtonsPreference mButtonPrefs;
|
||||
private AppButtonsPreferenceController mController;
|
||||
@@ -125,14 +128,15 @@ public class AppButtonsPreferenceControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
FakeFeatureFactory.setupForTest();
|
||||
mContext = RuntimeEnvironment.application;
|
||||
doReturn(mDpm).when(mSettingsActivity).getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
doReturn(mUserManager).when(mSettingsActivity).getSystemService(Context.USER_SERVICE);
|
||||
doReturn(mPackageManger).when(mSettingsActivity).getPackageManager();
|
||||
doReturn(mAm).when(mSettingsActivity).getSystemService(Context.ACTIVITY_SERVICE);
|
||||
doReturn(mOverlayManager).when(mSettingsActivity).
|
||||
getSystemService(OverlayManager.class);
|
||||
getSystemService(OverlayManager.class);
|
||||
doReturn(mAppEntry).when(mState).getEntry(anyString(), anyInt());
|
||||
when(mSettingsActivity.getApplication()).thenReturn(mApplication);
|
||||
doReturn(mContext).when(mSettingsActivity).getApplicationContext();
|
||||
when(mSettingsActivity.getResources().getString(anyInt())).thenReturn(RESOURCE_STRING);
|
||||
|
||||
mController = spy(new AppButtonsPreferenceController(mSettingsActivity, mFragment,
|
||||
@@ -161,6 +165,21 @@ public class AppButtonsPreferenceControllerTest {
|
||||
ShadowAppUtils.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAppUtils.class)
|
||||
public void isAvailable_validPackageName_isTrue() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_nullPackageName_isFalse() {
|
||||
final AppButtonsPreferenceController controller = spy(
|
||||
new AppButtonsPreferenceController(mSettingsActivity, mFragment,
|
||||
mLifecycle, null, mState, REQUEST_UNINSTALL, REQUEST_REMOVE_DEVICE_ADMIN));
|
||||
|
||||
assertThat(controller.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retrieveAppEntry_hasAppEntry_notNull()
|
||||
throws PackageManager.NameNotFoundException {
|
||||
@@ -306,10 +325,10 @@ public class AppButtonsPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateUninstallButton_isNonSystemRro_setButtonDisable()
|
||||
throws RemoteException {
|
||||
throws RemoteException {
|
||||
when(mAppInfo.isResourceOverlay()).thenReturn(true);
|
||||
when(mOverlayManager.getOverlayInfo(anyString(), any()))
|
||||
.thenReturn(OVERLAY_ENABLED);
|
||||
.thenReturn(OVERLAY_ENABLED);
|
||||
|
||||
mController.updateUninstallButton();
|
||||
|
||||
@@ -318,10 +337,10 @@ public class AppButtonsPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateUninstallButton_isNonSystemRro_setButtonEnable()
|
||||
throws RemoteException {
|
||||
throws RemoteException {
|
||||
when(mAppInfo.isResourceOverlay()).thenReturn(true);
|
||||
when(mOverlayManager.getOverlayInfo(anyString(), any()))
|
||||
.thenReturn(OVERLAY_DISABLED);
|
||||
.thenReturn(OVERLAY_DISABLED);
|
||||
|
||||
mController.updateUninstallButton();
|
||||
|
||||
@@ -423,7 +442,7 @@ public class AppButtonsPreferenceControllerTest {
|
||||
@Test
|
||||
public void onPackageListChanged_available_shouldRefreshUi() {
|
||||
doReturn(AppButtonsPreferenceController.AVAILABLE)
|
||||
.when(mController).getAvailabilityStatus();
|
||||
.when(mController).getAvailabilityStatus();
|
||||
doReturn(true).when(mController).refreshUi();
|
||||
|
||||
mController.onPackageListChanged();
|
||||
@@ -434,7 +453,7 @@ public class AppButtonsPreferenceControllerTest {
|
||||
@Test
|
||||
public void onPackageListChanged_notAvailable_shouldNotRefreshUiAndNoCrash() {
|
||||
doReturn(AppButtonsPreferenceController.DISABLED_FOR_USER)
|
||||
.when(mController).getAvailabilityStatus();
|
||||
.when(mController).getAvailabilityStatus();
|
||||
|
||||
mController.onPackageListChanged();
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
|
||||
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
|
||||
|
||||
import static com.android.settings.development.BubbleGlobalPreferenceController.OFF;
|
||||
import static com.android.settings.development.BubbleGlobalPreferenceController.ON;
|
||||
@@ -77,7 +77,7 @@ public class BubbleGlobalPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_settingEnabled_preferenceShouldBeChecked() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_BUBBLES, 1 /* enabled */);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -86,7 +86,7 @@ public class BubbleGlobalPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_settingReset_defaultDisabled_preferenceShouldNotBeChecked() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_BUBBLES, 0 /* enabled */);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -104,7 +104,7 @@ public class BubbleGlobalPreferenceControllerTest {
|
||||
}
|
||||
|
||||
private boolean isSettingEnabled() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
||||
return Settings.Global.getInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
||||
OFF /* default off */) == ON;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.slice.Slice;
|
||||
import androidx.slice.SliceProvider;
|
||||
@@ -65,6 +66,7 @@ public class ContextualAdaptiveSleepSliceTest {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mContextualAdaptiveSleepSlice = spy(new ContextualAdaptiveSleepSlice(mContext));
|
||||
|
||||
Settings.System.putInt(mContext.getContentResolver(), Settings.System.ADAPTIVE_SLEEP, 0);
|
||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||
doReturn(mSharedPreferences).when(mContext).getSharedPreferences(eq(PREF), anyInt());
|
||||
doReturn(true).when(mContextualAdaptiveSleepSlice).isSettingsAvailable();
|
||||
@@ -112,4 +114,20 @@ public class ContextualAdaptiveSleepSliceTest {
|
||||
|
||||
assertThat(slice).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_ShowIfNotTurnedOn() {
|
||||
final Slice slice = mContextualAdaptiveSleepSlice.getSlice();
|
||||
|
||||
assertThat(slice).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_DoNotShowIfTurnedOn() {
|
||||
Settings.System.putInt(mContext.getContentResolver(), Settings.System.ADAPTIVE_SLEEP, 1);
|
||||
|
||||
final Slice slice = mContextualAdaptiveSleepSlice.getSlice();
|
||||
|
||||
assertThat(slice).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.slice.Slice;
|
||||
import androidx.slice.SliceProvider;
|
||||
@@ -59,26 +60,58 @@ public class FaceSetupSliceTest {
|
||||
public void getSlice_noFaceManager_shouldReturnNull() {
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(false);
|
||||
final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext);
|
||||
|
||||
assertThat(setupSlice.getSlice()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_faceEnrolled_shouldReturnNull() {
|
||||
public void getSlice_faceEnrolled_noReEnroll_shouldReturnNull() {
|
||||
final FaceManager faceManager = mock(FaceManager.class);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
|
||||
when(faceManager.hasEnrolledTemplates(UserHandle.myUserId())).thenReturn(true);
|
||||
when(mContext.getSystemService(Context.FACE_SERVICE)).thenReturn(faceManager);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.FACE_UNLOCK_RE_ENROLL,
|
||||
0);
|
||||
final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext);
|
||||
|
||||
assertThat(setupSlice.getSlice()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_faceNotEnrolled_shouldReturnNonNull() {
|
||||
public void getSlice_faceNotEnrolled_shouldReturnSlice() {
|
||||
final FaceManager faceManager = mock(FaceManager.class);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
|
||||
when(faceManager.hasEnrolledTemplates(UserHandle.myUserId())).thenReturn(false);
|
||||
when(mContext.getSystemService(Context.FACE_SERVICE)).thenReturn(faceManager);
|
||||
final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext);
|
||||
|
||||
assertThat(setupSlice.getSlice()).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_faceEnrolled_shouldReEnroll_shouldReturnSlice() {
|
||||
final FaceManager faceManager = mock(FaceManager.class);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
|
||||
when(faceManager.hasEnrolledTemplates(UserHandle.myUserId())).thenReturn(true);
|
||||
when(mContext.getSystemService(Context.FACE_SERVICE)).thenReturn(faceManager);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.FACE_UNLOCK_RE_ENROLL,
|
||||
1);
|
||||
final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext);
|
||||
|
||||
assertThat(setupSlice.getSlice()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_faceEnrolled_musteEnroll_shouldReturnSlice() {
|
||||
final FaceManager faceManager = mock(FaceManager.class);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
|
||||
when(faceManager.hasEnrolledTemplates(UserHandle.myUserId())).thenReturn(true);
|
||||
when(mContext.getSystemService(Context.FACE_SERVICE)).thenReturn(faceManager);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.FACE_UNLOCK_RE_ENROLL,
|
||||
3);
|
||||
final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext);
|
||||
|
||||
assertThat(setupSlice.getSlice()).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,6 +463,43 @@ public class ApnEditorTest {
|
||||
verify(mApnEditorUT).finish();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUserEnteredApnType_emptyApnType_shouldReturnDefault() {
|
||||
// case 1
|
||||
// GIVEN read only APN types with DUN
|
||||
String[] readOnlyApnTypes = {"dun"};
|
||||
mApnEditorUT.mReadOnlyApnTypes = readOnlyApnTypes;
|
||||
// GIVEN read specificApnTypeForEmptyInput with DEFAULT,DUN
|
||||
String[] defaultApnTypes = {"default", "dun"};
|
||||
mApnEditorUT.mDefaultApnTypes = defaultApnTypes;
|
||||
|
||||
// Input empty in TYPE
|
||||
final FakeApnData apnData = new FakeApnData(APN_DATA);
|
||||
apnData.mData[ApnEditor.TYPE_INDEX] = "";
|
||||
mApnEditorUT.mApnData = apnData;
|
||||
mApnEditorUT.fillUI(true /* firstTime */);
|
||||
|
||||
// THEN APN type should be default
|
||||
assertThat(mApnEditorUT.getUserEnteredApnType()).isEqualTo("default");
|
||||
|
||||
// case 2
|
||||
// GIVEN read only APN types with DUN
|
||||
String[] readOnlyApnTypesCase2 = {"dun"};
|
||||
mApnEditorUT.mReadOnlyApnTypes = readOnlyApnTypesCase2;
|
||||
// GIVEN read specificApnTypeForEmptyInput with DEFAULT
|
||||
String[] defaultApnTypesCase2 = {"default"};
|
||||
mApnEditorUT.mDefaultApnTypes = defaultApnTypesCase2;
|
||||
|
||||
// Input empty in TYPE
|
||||
final FakeApnData apnDataCase2 = new FakeApnData(APN_DATA);
|
||||
apnDataCase2.mData[ApnEditor.TYPE_INDEX] = "";
|
||||
mApnEditorUT.mApnData = apnDataCase2;
|
||||
mApnEditorUT.fillUI(true /* firstTime */);
|
||||
|
||||
// THEN APN type should be default
|
||||
assertThat(mApnEditorUT.getUserEnteredApnType()).isEqualTo("default");
|
||||
}
|
||||
|
||||
private void initCursor() {
|
||||
doReturn(2).when(mCursor).getColumnCount();
|
||||
doReturn(2).when(mCursor).getInt(CURSOR_INTEGER_INDEX);
|
||||
|
||||
@@ -22,6 +22,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -58,6 +59,10 @@ public class MobileNetworkUtilsTest {
|
||||
private static final String PACKAGE_NAME = "com.android.app";
|
||||
private static final int SUB_ID_1 = 1;
|
||||
private static final int SUB_ID_2 = 2;
|
||||
private static final int SUB_ID_INVALID = -1;
|
||||
private static final String PLMN_FROM_TELEPHONY_MANAGER_API = "testPlmn";
|
||||
private static final String PLMN_FROM_SUB_ID_1 = "testPlmnSub1";
|
||||
private static final String PLMN_FROM_SUB_ID_2 = "testPlmnSub2";
|
||||
|
||||
@Mock
|
||||
private TelephonyManager mTelephonyManager;
|
||||
@@ -89,6 +94,7 @@ public class MobileNetworkUtilsTest {
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||
when(mTelephonyManager.createForSubscriptionId(SUB_ID_1)).thenReturn(mTelephonyManager);
|
||||
when(mTelephonyManager.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2);
|
||||
@@ -102,10 +108,17 @@ public class MobileNetworkUtilsTest {
|
||||
when(mCarrierConfigManager.getConfigForSubId(SUB_ID_1)).thenReturn(mCarrierConfig);
|
||||
|
||||
when(mSubscriptionInfo1.getSubscriptionId()).thenReturn(SUB_ID_1);
|
||||
when(mSubscriptionInfo1.getCarrierName()).thenReturn(PLMN_FROM_SUB_ID_1);
|
||||
when(mSubscriptionInfo2.getSubscriptionId()).thenReturn(SUB_ID_2);
|
||||
when(mSubscriptionInfo2.getCarrierName()).thenReturn(PLMN_FROM_SUB_ID_2);
|
||||
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfoList(eq(true))).thenReturn(
|
||||
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
|
||||
when(mSubscriptionManager.getAccessibleSubscriptionInfoList()).thenReturn(
|
||||
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
|
||||
|
||||
when(mTelephonyManager.getNetworkOperatorName()).thenReturn(
|
||||
PLMN_FROM_TELEPHONY_MANAGER_API);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -301,4 +314,24 @@ public class MobileNetworkUtilsTest {
|
||||
TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
|
||||
assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCurrentCarrierNameForDisplay_withoutValidSubId_returnNetworkOperatorName() {
|
||||
assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay(
|
||||
mContext, SUB_ID_INVALID)).isEqualTo(PLMN_FROM_TELEPHONY_MANAGER_API);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCurrentCarrierNameForDisplay_withValidSubId_returnCurrentCarrierName() {
|
||||
assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay(
|
||||
mContext, SUB_ID_1)).isEqualTo(PLMN_FROM_SUB_ID_1);
|
||||
assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay(
|
||||
mContext, SUB_ID_2)).isEqualTo(PLMN_FROM_SUB_ID_2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCurrentCarrierNameForDisplay_withoutSubId_returnNotNull() {
|
||||
assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay(
|
||||
mContext)).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.android.settings.network.telephony.gsm;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -26,12 +26,15 @@ import android.content.Context;
|
||||
import android.os.PersistableBundle;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.ServiceState;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -54,6 +57,8 @@ public class OpenNetworkSelectPagePreferenceControllerTest {
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
@Mock
|
||||
private ServiceState mServiceState;
|
||||
@Mock
|
||||
private SubscriptionInfo mSubscriptionInfo;
|
||||
|
||||
private PersistableBundle mCarrierConfig;
|
||||
private OpenNetworkSelectPagePreferenceController mController;
|
||||
@@ -75,6 +80,16 @@ public class OpenNetworkSelectPagePreferenceControllerTest {
|
||||
mCarrierConfig = new PersistableBundle();
|
||||
when(mCarrierConfigManager.getConfigForSubId(SUB_ID)).thenReturn(mCarrierConfig);
|
||||
|
||||
when(mSubscriptionInfo.getSubscriptionId()).thenReturn(SUB_ID);
|
||||
when(mSubscriptionInfo.getCarrierName()).thenReturn(OPERATOR_NAME);
|
||||
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfoList(eq(true))).thenReturn(
|
||||
Arrays.asList(mSubscriptionInfo));
|
||||
when(mSubscriptionManager.getAccessibleSubscriptionInfoList()).thenReturn(
|
||||
Arrays.asList(mSubscriptionInfo));
|
||||
|
||||
when(mTelephonyManager.getNetworkOperatorName()).thenReturn(OPERATOR_NAME);
|
||||
|
||||
mPreference = new Preference(mContext);
|
||||
mController = new OpenNetworkSelectPagePreferenceController(mContext,
|
||||
"open_network_select");
|
||||
@@ -94,7 +109,6 @@ public class OpenNetworkSelectPagePreferenceControllerTest {
|
||||
@Test
|
||||
public void getSummary_inService_returnOperatorName() {
|
||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
|
||||
doReturn(OPERATOR_NAME).when(mTelephonyManager).getNetworkOperatorName();
|
||||
|
||||
assertThat(mController.getSummary()).isEqualTo(OPERATOR_NAME);
|
||||
}
|
||||
@@ -102,7 +116,6 @@ public class OpenNetworkSelectPagePreferenceControllerTest {
|
||||
@Test
|
||||
public void getSummary_notInService_returnDisconnect() {
|
||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
||||
doReturn(OPERATOR_NAME).when(mTelephonyManager).getNetworkOperatorName();
|
||||
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
mContext.getString(R.string.network_disconnected));
|
||||
|
||||
@@ -20,7 +20,7 @@ import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
|
||||
import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
||||
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
|
||||
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
|
||||
|
||||
import static com.android.settings.notification.BubblePreferenceController.SYSTEM_WIDE_OFF;
|
||||
import static com.android.settings.notification.BubblePreferenceController.SYSTEM_WIDE_ON;
|
||||
@@ -103,7 +103,7 @@ public class BubblePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_notIfAppBlocked() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.banned = true;
|
||||
mController.onResume(appRow, mock(NotificationChannel.class), null, null);
|
||||
@@ -112,7 +112,7 @@ public class BubblePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_notIfChannelBlocked() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
NotificationChannel channel = mock(NotificationChannel.class);
|
||||
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
||||
@@ -122,7 +122,7 @@ public class BubblePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_channel_notIfAppOff() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.allowBubbles = false;
|
||||
NotificationChannel channel = mock(NotificationChannel.class);
|
||||
@@ -136,7 +136,7 @@ public class BubblePreferenceControllerTest {
|
||||
public void testIsNotAvailable_ifOffGlobally_app() {
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
mController.onResume(appRow, null, null, null);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
|
||||
|
||||
assertFalse(mController.isAvailable());
|
||||
@@ -148,7 +148,7 @@ public class BubblePreferenceControllerTest {
|
||||
NotificationChannel channel = mock(NotificationChannel.class);
|
||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||
mController.onResume(appRow, channel, null, null);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
|
||||
|
||||
assertFalse(mController.isAvailable());
|
||||
@@ -158,7 +158,7 @@ public class BubblePreferenceControllerTest {
|
||||
public void testIsAvailable_app_evenIfOffGlobally() {
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
mAppPageController.onResume(appRow, null, null, null);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
|
||||
|
||||
assertTrue(mAppPageController.isAvailable());
|
||||
@@ -168,7 +168,7 @@ public class BubblePreferenceControllerTest {
|
||||
public void testIsAvailable_app() {
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
mController.onResume(appRow, null, null, null);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
|
||||
assertTrue(mController.isAvailable());
|
||||
}
|
||||
@@ -181,7 +181,7 @@ public class BubblePreferenceControllerTest {
|
||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
||||
mController.onResume(appRow, channel, null, null);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
|
||||
assertTrue(mController.isAvailable());
|
||||
}
|
||||
@@ -193,7 +193,7 @@ public class BubblePreferenceControllerTest {
|
||||
NotificationChannel channel = mock(NotificationChannel.class);
|
||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||
mController.onResume(appRow, channel, null, null);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
|
||||
assertTrue(mController.isAvailable());
|
||||
}
|
||||
@@ -205,7 +205,7 @@ public class BubblePreferenceControllerTest {
|
||||
NotificationChannel channel = mock(NotificationChannel.class);
|
||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||
mController.onResume(appRow, channel, null, null);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
|
||||
assertFalse(mController.isAvailable());
|
||||
}
|
||||
@@ -225,7 +225,7 @@ public class BubblePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateState_channelNotBlockable() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
NotificationChannel channel = mock(NotificationChannel.class);
|
||||
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
||||
@@ -239,7 +239,7 @@ public class BubblePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateState_channel() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
NotificationChannel channel = mock(NotificationChannel.class);
|
||||
when(channel.canBubble()).thenReturn(true);
|
||||
@@ -259,7 +259,7 @@ public class BubblePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateState_app() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.label = "App!";
|
||||
appRow.allowBubbles = true;
|
||||
@@ -281,7 +281,7 @@ public class BubblePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateState_app_offGlobally() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.label = "App!";
|
||||
@@ -295,7 +295,7 @@ public class BubblePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange_on_channel() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.allowBubbles = true;
|
||||
NotificationChannel channel =
|
||||
@@ -315,7 +315,7 @@ public class BubblePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange_off_channel() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.allowBubbles = true;
|
||||
NotificationChannel channel =
|
||||
@@ -335,7 +335,7 @@ public class BubblePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange_on_app() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.allowBubbles = false;
|
||||
mController.onResume(appRow, null, null, null);
|
||||
@@ -353,7 +353,7 @@ public class BubblePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange_off_app() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.allowBubbles = true;
|
||||
mController.onResume(appRow, null, null, null);
|
||||
@@ -371,7 +371,7 @@ public class BubblePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange_on_app_offGlobally() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
||||
SYSTEM_WIDE_OFF);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.allowBubbles = false;
|
||||
|
||||
@@ -20,7 +20,7 @@ import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
|
||||
import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
||||
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
|
||||
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
|
||||
|
||||
import static com.android.settings.notification.BubbleSummaryPreferenceController.SYSTEM_WIDE_OFF;
|
||||
import static com.android.settings.notification.BubbleSummaryPreferenceController.SYSTEM_WIDE_ON;
|
||||
@@ -98,7 +98,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
||||
NotificationChannel channel = mock(NotificationChannel.class);
|
||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||
mController.onResume(appRow, channel, null, null);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
||||
SYSTEM_WIDE_OFF);
|
||||
|
||||
assertFalse(mController.isAvailable());
|
||||
@@ -108,7 +108,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
||||
public void testIsAvailable_app() {
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
mController.onResume(appRow, null, null, null);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
|
||||
assertTrue(mController.isAvailable());
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
||||
public void testIsNotAvailable_app_globalOff() {
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
mController.onResume(appRow, null, null, null);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
||||
SYSTEM_WIDE_OFF);
|
||||
|
||||
assertFalse(mController.isAvailable());
|
||||
@@ -131,7 +131,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
||||
mController.onResume(appRow, channel, null, null);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
|
||||
assertTrue(mController.isAvailable());
|
||||
}
|
||||
@@ -149,18 +149,18 @@ public class BubbleSummaryPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testGetSummary() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.allowBubbles = true;
|
||||
mController.onResume(appRow, null, null, null);
|
||||
|
||||
assertEquals("On", mController.getSummary());
|
||||
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
||||
SYSTEM_WIDE_OFF);
|
||||
assertEquals("Off", mController.getSummary());
|
||||
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||
appRow.allowBubbles = false;
|
||||
mController.onResume(appRow, null, null, null);
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
|
||||
|
||||
import static com.android.settings.notification.BadgingNotificationPreferenceController.OFF;
|
||||
import static com.android.settings.notification.BadgingNotificationPreferenceController.ON;
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||
import com.android.settingslib.wifi.WifiTracker;
|
||||
import com.android.settingslib.wifi.WifiTrackerFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
@@ -36,15 +37,18 @@ import org.robolectric.annotation.Config;
|
||||
@Config(shadows = ShadowAlertDialogCompat.class)
|
||||
public class NetworkRequestDialogActivityTest {
|
||||
|
||||
@Test
|
||||
public void LaunchActivity_shouldShowNetworkRequestDialog() {
|
||||
@Before
|
||||
public void setUp() {
|
||||
// Mocks fake WifiTracker, in case of exception in NetworkRequestDialogFragment.onResume().
|
||||
WifiTracker wifiTracker = mock(WifiTracker.class);
|
||||
WifiTrackerFactory.setTestingWifiTracker(wifiTracker);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchActivity_shouldShowNetworkRequestDialog() {
|
||||
Robolectric.setupActivity(NetworkRequestDialogActivity.class);
|
||||
|
||||
AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
final AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
|
||||
assertThat(alertDialog.isShowing()).isTrue();
|
||||
}
|
||||
|
||||
@@ -18,11 +18,13 @@ package com.android.settings.wifi;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.internal.verification.VerificationModeFactory.times;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.net.wifi.WifiManager.NetworkRequestUserSelectionCallback;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Button;
|
||||
|
||||
@@ -32,6 +34,8 @@ import androidx.fragment.app.FragmentActivity;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||
import com.android.settings.wifi.NetworkRequestErrorDialogFragment.ERROR_DIALOG_TYPE;
|
||||
import com.android.settingslib.wifi.WifiTracker;
|
||||
import com.android.settingslib.wifi.WifiTrackerFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -47,12 +51,17 @@ public class NetworkRequestErrorDialogFragmentTest {
|
||||
|
||||
private FragmentActivity mActivity;
|
||||
private NetworkRequestErrorDialogFragment mFragment;
|
||||
private WifiTracker mWifiTracker;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mActivity = Robolectric.setupActivity(FragmentActivity.class);
|
||||
mFragment = spy(NetworkRequestErrorDialogFragment.newInstance());
|
||||
mFragment.show(mActivity.getSupportFragmentManager(), null);
|
||||
|
||||
// Prevents NPE when calling up NetworkRequestDialogFragment.
|
||||
mWifiTracker = mock(WifiTracker.class);
|
||||
WifiTrackerFactory.setTestingWifiTracker(mWifiTracker);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,4 +120,17 @@ public class NetworkRequestErrorDialogFragmentTest {
|
||||
negativeButton.performClick();
|
||||
assertThat(alertDialog.isShowing()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickNegativeButton_shouldCallReject() {
|
||||
final NetworkRequestUserSelectionCallback rejectCallback =
|
||||
mock(NetworkRequestUserSelectionCallback.class);
|
||||
mFragment.setRejectCallback(rejectCallback);
|
||||
|
||||
final AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
final Button negativeButton = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
|
||||
negativeButton.performClick();
|
||||
|
||||
verify(rejectCallback, times(1)).reject();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiEnterpriseConfig;
|
||||
import android.net.wifi.WifiEnterpriseConfig.Eap;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.ServiceSpecificException;
|
||||
import android.security.KeyStore;
|
||||
@@ -445,4 +447,46 @@ public class WifiConfigControllerTest {
|
||||
WifiConfiguration config = mController.getConfig();
|
||||
assertThat(config.macRandomizationSetting).isEqualTo(WifiConfiguration.RANDOMIZATION_NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectSecurity_wpa3Eap192bit_eapMethodTls() {
|
||||
final WifiManager wifiManager = mock(WifiManager.class);
|
||||
when(wifiManager.isWpa3SuiteBSupported()).thenReturn(true);
|
||||
mController = new TestWifiConfigController(mConfigUiBase, mView, null /* accessPoint */,
|
||||
WifiConfigUiBase.MODE_MODIFY, wifiManager);
|
||||
final Spinner securitySpinner = mView.findViewById(R.id.security);
|
||||
final Spinner eapMethodSpinner = mView.findViewById(R.id.method);
|
||||
int wpa3Eap192bitPosition = -1;
|
||||
final int securityCount = mController.mSecurityInPosition.length;
|
||||
for (int i = 0; i < securityCount; i++) {
|
||||
if (mController.mSecurityInPosition[i] != null &&
|
||||
mController.mSecurityInPosition[i] == AccessPoint.SECURITY_EAP_SUITE_B) {
|
||||
wpa3Eap192bitPosition = i;
|
||||
}
|
||||
}
|
||||
|
||||
mController.onItemSelected(securitySpinner, null /* view */, wpa3Eap192bitPosition,
|
||||
0 /* id */);
|
||||
|
||||
final int selectedItemPosition = eapMethodSpinner.getSelectedItemPosition();
|
||||
assertThat(eapMethodSpinner.getSelectedItem().toString()).isEqualTo("TLS");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectEapMethod_savedAccessPoint_shouldGetCorrectPosition() {
|
||||
when(mAccessPoint.isSaved()).thenReturn(true);
|
||||
when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_EAP);
|
||||
final WifiConfiguration mockWifiConfig = mock(WifiConfiguration.class);
|
||||
final WifiEnterpriseConfig mockWifiEnterpriseConfig = mock(WifiEnterpriseConfig.class);
|
||||
when(mockWifiEnterpriseConfig.getEapMethod()).thenReturn(Eap.PEAP);
|
||||
mockWifiConfig.enterpriseConfig = mockWifiEnterpriseConfig ;
|
||||
when(mAccessPoint.getConfig()).thenReturn(mockWifiConfig);
|
||||
mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint,
|
||||
WifiConfigUiBase.MODE_MODIFY);
|
||||
final Spinner eapMethodSpinner = mView.findViewById(R.id.method);
|
||||
|
||||
eapMethodSpinner.setSelection(Eap.TLS);
|
||||
|
||||
assertThat(eapMethodSpinner.getSelectedItemPosition()).isEqualTo(Eap.TLS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.settings.wifi.dpp;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WifiDppUtilsTest {
|
||||
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
|
||||
@Mock
|
||||
private AccessPoint mAccessPoint;
|
||||
|
||||
@Mock
|
||||
private WifiConfiguration mWifiConfiguration;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||
shadowApplication.setSystemService(Context.WIFI_SERVICE, mWifiManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getConfiguratorQrCodeScannerIntentOrNull_hiddenSsidNetwork_hasHiddenSsidExtra() {
|
||||
when(mWifiManager.isEasyConnectSupported()).thenReturn(true);
|
||||
when(mAccessPoint.isPasspoint()).thenReturn(false);
|
||||
when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_PSK);
|
||||
when(mAccessPoint.getConfig()).thenReturn(mWifiConfiguration);
|
||||
mWifiConfiguration.SSID = "GuestNetwork";
|
||||
mWifiConfiguration.allowedKeyManagement = new BitSet();
|
||||
mWifiConfiguration.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
|
||||
mWifiConfiguration.hiddenSSID = true;
|
||||
|
||||
Intent intent = WifiDppUtils
|
||||
.getConfiguratorQrCodeScannerIntentOrNull(mContext, mWifiManager, mAccessPoint);
|
||||
|
||||
assertThat(intent.getBooleanExtra(WifiDppUtils.EXTRA_WIFI_HIDDEN_SSID, false))
|
||||
.isEqualTo(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user