Merge "Add PowerSaveWhitelistExceptIdle as Optimizted modes condition"

This commit is contained in:
TreeHugger Robot
2021-09-22 02:09:41 +00:00
committed by Android (Google) Code Review
10 changed files with 76 additions and 5 deletions

View File

@@ -745,6 +745,16 @@ public class AdvancedPowerUsageDetailTest {
.isEqualTo("This app requires optimized battery usage.");
}
@Test
public void testInitPreferenceForTriState_isAllowlistedExceptIdleApp_hasCorrectString() {
when(mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).thenReturn(true);
mFragment.initPreferenceForTriState(mContext);
assertThat(mFooterPreference.getTitle().toString())
.isEqualTo("This app requires optimized battery usage.");
}
@Test
public void testInitPreferenceForTriState_isSystemOrDefaultApp_hasCorrectString() {
when(mBatteryOptimizeUtils.isValidPackageName()).thenReturn(true);

View File

@@ -124,6 +124,18 @@ public class BatteryOptimizeUtilsTest {
assertThat(mBatteryOptimizeUtils.isValidPackageName()).isTrue();
}
@Test
public void testIsAllowlistedExpectIdle_isAllowlistedExceptIdle_returnTrue() {
when(mMockBackend.isAllowlistedExceptIdle(anyString())).thenReturn(true);
assertThat(mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).isTrue();
}
@Test
public void testIsAllowlistedExpectIdle_notAllowlistedExpectIdle_returnFalse() {
assertThat(mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).isFalse();
}
@Test
public void testSetAppOptimizationMode_Restricted_verifyAction() {
// Sets the current mode as MODE_UNRESTRICTED.

View File

@@ -93,6 +93,16 @@ public class OptimizedPreferenceControllerTest {
assertThat(mPreference.isChecked()).isFalse();
}
@Test
public void testUpdateState_isAllowlistedExceptIdleApp_prefEnabled() {
when(mockBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).thenReturn(true);
mController.updateState(mPreference);
assertThat(mPreference.isEnabled()).isTrue();
assertThat(mPreference.isChecked()).isTrue();
}
@Test
public void testHandlePreferenceTreeClick_samePrefKey_verifyAction() {
mPreference.setKey(mController.KEY_OPTIMIZED_PREF);

View File

@@ -101,6 +101,16 @@ public class RestrictedPreferenceControllerTest {
assertThat(mPreference.isChecked()).isFalse();
}
@Test
public void testUpdateState_isAllowlistedExceptIdleApp_prefDisabled() {
when(mockBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).thenReturn(true);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse();
assertThat(mPreference.isEnabled()).isFalse();
}
@Test
public void testHandlePreferenceTreeClick_samePrefKey_verifyAction() {
mPreference.setKey(mController.KEY_RESTRICTED_PREF);

View File

@@ -101,6 +101,16 @@ public class UnrestrictedPreferenceControllerTest {
assertThat(mPreference.isChecked()).isFalse();
}
@Test
public void testUpdateState_isAllowlistedExceptIdleApp_prefDisabled() {
when(mockBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).thenReturn(true);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse();
assertThat(mPreference.isEnabled()).isFalse();
}
@Test
public void testHandlePreferenceTreeClick_samePrefKey_verifyAction() {
mPreference.setKey(mController.KEY_UNRESTRICTED_PREF);