Merge "Apply SettingsLib SeekBarPreference to Settings" into sc-dev
This commit is contained in:
@@ -20,19 +20,20 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doCallRealMethod;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.accounts.AccountRestrictionHelper;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.RestrictedSeekBarPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -46,9 +47,11 @@ import org.robolectric.RuntimeEnvironment;
|
||||
public class AdjustVolumeRestrictedPreferenceControllerTest {
|
||||
|
||||
private static final String KEY = "key";
|
||||
@Mock
|
||||
private AccountRestrictionHelper mAccountHelper;
|
||||
|
||||
@Mock
|
||||
UserManager mUserManager;
|
||||
|
||||
private Context mContext;
|
||||
private AdjustVolumeRestrictedPreferenceControllerTestable mController;
|
||||
|
||||
@@ -56,15 +59,17 @@ public class AdjustVolumeRestrictedPreferenceControllerTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
mAccountHelper = new AccountRestrictionHelper(mContext);
|
||||
mController =
|
||||
new AdjustVolumeRestrictedPreferenceControllerTestable(mContext, mAccountHelper, KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_hasBaseRestriction_shouldDisable() {
|
||||
RestrictedPreference preference = mock(RestrictedPreference.class);
|
||||
when(mAccountHelper.hasBaseUserRestriction(
|
||||
eq(UserManager.DISALLOW_ADJUST_VOLUME), anyInt())).thenReturn(true);
|
||||
RestrictedSeekBarPreference preference = mock(RestrictedSeekBarPreference.class);
|
||||
when(RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext,
|
||||
UserManager.DISALLOW_ADJUST_VOLUME, UserHandle.myUserId())).thenReturn(true);
|
||||
|
||||
mController.updateState(preference);
|
||||
|
||||
@@ -73,13 +78,11 @@ public class AdjustVolumeRestrictedPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_NoBaseRestriction_shouldCheckRestriction() {
|
||||
RestrictedPreference preference = spy(new RestrictedPreference(mContext));
|
||||
RestrictedSeekBarPreference preference = spy(new RestrictedSeekBarPreference(mContext));
|
||||
|
||||
when(mContext.getSystemService(Context.DEVICE_POLICY_SERVICE)).thenReturn(null);
|
||||
when(mAccountHelper.hasBaseUserRestriction(
|
||||
eq(UserManager.DISALLOW_ADJUST_VOLUME), anyInt())).thenReturn(false);
|
||||
doCallRealMethod().when(mAccountHelper).enforceRestrictionOnPreference(
|
||||
eq(preference), eq(UserManager.DISALLOW_ADJUST_VOLUME), anyInt());
|
||||
when(RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext,
|
||||
UserManager.DISALLOW_ADJUST_VOLUME, UserHandle.myUserId())).thenReturn(false);
|
||||
|
||||
mController.updateState(preference);
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ import androidx.preference.PreferenceScreen;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settings.widget.SeekBarPreference;
|
||||
import com.android.settingslib.media.LocalMediaManager;
|
||||
import com.android.settingslib.widget.SeekBarPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
Reference in New Issue
Block a user