fix(ReduceBrightColorsPreferenceController) Different feature configs
This change updates the tests for ReduceBrightColorsPreferenceController to account for different combinations of feature flags and configurations, specifically related to the "Even Dimmer" flag and the availability of Reduce Bright Colors. The updated tests ensure that the preference controller correctly determines its availability based on these factors, improving test coverage and reliability. This addresses inconsistencies between the code and test cases, ensuring accurate behavior across various device configurations. Bug: 383076111 Test: atest ReduceBrightColorsPreferenceControllerTest Flag: com.android.server.display.feature.flags.even_dimmer Change-Id: Iec53b416ec69a74f1f353f684358f265b022456f
This commit is contained in:
@@ -24,20 +24,29 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.platform.test.annotations.DisableFlags;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.server.display.feature.flags.Flags;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/** Tests for {@link ReduceBrightColorsIntensityPreferenceController} */
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ReduceBrightColorsIntensityPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
private ReduceBrightColorsIntensityPreferenceController mPreferenceController;
|
||||
@@ -52,27 +61,119 @@ public class ReduceBrightColorsIntensityPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_configuredRbcAvailable_enabledRbc_shouldReturnTrue() {
|
||||
@DisableFlags(Flags.FLAG_EVEN_DIMMER)
|
||||
public void isAvailable_whenEvenDimmerOffAndDisabled_RbcOnAndAvailable_returnTrue() {
|
||||
doReturn(false).when(mResources).getBoolean(
|
||||
com.android.internal.R.bool.config_evenDimmerEnabled);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
|
||||
doReturn(true).when(mResources).getBoolean(
|
||||
R.bool.config_reduceBrightColorsAvailable);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_configuredRbcAvailable_disabledRbc_shouldReturnTrue() {
|
||||
@DisableFlags(Flags.FLAG_EVEN_DIMMER)
|
||||
public void isAvailable_whenEvenDimmerOffAndDisabled_RbcOffAndAvailable_returnTrue() {
|
||||
doReturn(false).when(mResources).getBoolean(
|
||||
com.android.internal.R.bool.config_evenDimmerEnabled);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0);
|
||||
doReturn(true).when(mResources).getBoolean(
|
||||
R.bool.config_reduceBrightColorsAvailable);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_configuredRbcUnavailable_enabledRbc_shouldReturnFalse() {
|
||||
@DisableFlags(Flags.FLAG_EVEN_DIMMER)
|
||||
public void isAvailable_whenEvenDimmerOffAndDisabled_RbcOnAndUnavailable_returnFalse() {
|
||||
doReturn(false).when(mResources).getBoolean(
|
||||
com.android.internal.R.bool.config_evenDimmerEnabled);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
|
||||
doReturn(false).when(mResources).getBoolean(
|
||||
R.bool.config_reduceBrightColorsAvailable);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_EVEN_DIMMER)
|
||||
public void isAvailable_whenEvenDimmerOnAndDisabled_RbcOnAndAvailable_returnTrue() {
|
||||
doReturn(false).when(mResources).getBoolean(
|
||||
com.android.internal.R.bool.config_evenDimmerEnabled);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
|
||||
doReturn(true).when(mResources).getBoolean(
|
||||
R.bool.config_reduceBrightColorsAvailable);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_EVEN_DIMMER)
|
||||
public void isAvailable_whenEvenDimmerOnAndDisabled_RbcOffAndAvailable_returnTrue() {
|
||||
doReturn(false).when(mResources).getBoolean(
|
||||
com.android.internal.R.bool.config_evenDimmerEnabled);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0);
|
||||
doReturn(true).when(mResources).getBoolean(
|
||||
R.bool.config_reduceBrightColorsAvailable);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_EVEN_DIMMER)
|
||||
public void isAvailable_whenEvenDimmerOnAndDisabled_RbcOnAndUnavailable_returnFalse() {
|
||||
doReturn(false).when(mResources).getBoolean(
|
||||
com.android.internal.R.bool.config_evenDimmerEnabled);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
|
||||
doReturn(false).when(mResources).getBoolean(
|
||||
R.bool.config_reduceBrightColorsAvailable);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_EVEN_DIMMER)
|
||||
public void isAvailable_whenEvenDimmerOnAndEnabled_RbcOnAndAvailable_returnFalse() {
|
||||
doReturn(true).when(mResources).getBoolean(
|
||||
com.android.internal.R.bool.config_evenDimmerEnabled);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
|
||||
doReturn(true).when(mResources).getBoolean(
|
||||
R.bool.config_reduceBrightColorsAvailable);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_EVEN_DIMMER)
|
||||
public void isAvailable_whenEvenDimmerOnAndEnabled_RbcOffAndAvailable_returnFalse() {
|
||||
doReturn(true).when(mResources).getBoolean(
|
||||
com.android.internal.R.bool.config_evenDimmerEnabled);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0);
|
||||
doReturn(true).when(mResources).getBoolean(
|
||||
R.bool.config_reduceBrightColorsAvailable);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_EVEN_DIMMER)
|
||||
public void isAvailable_whenEvenDimmerOnAndEnabled_RbcOnAndUnavailable_returnFalse() {
|
||||
doReturn(true).when(mResources).getBoolean(
|
||||
com.android.internal.R.bool.config_evenDimmerEnabled);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
|
||||
doReturn(false).when(mResources).getBoolean(
|
||||
R.bool.config_reduceBrightColorsAvailable);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user