Battery saver mode should disable dark mode modification
disable toggle options and disable the dark theme drop down selection Test: make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.display.DarkUIPreferenceControllerTest" && \ make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.display.darkmode.DarkModeActivationPreferenceControllerTest" && \ make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.display.darkmode.DarkModeObserverTest" && \ make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.display.darkmode.DarkModeScheduleSelectorControllerTest" Fixes: 145098277 Fixes: 145297188 Fixes: 145254016 Change-Id: I5c81a295810cc2d9a45657978104647e9c15da46
This commit is contained in:
@@ -19,6 +19,7 @@ import android.app.UiModeManager;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.PowerManager;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -57,6 +58,8 @@ public class DarkModeActivationPreferenceControllerTest {
|
||||
private Button mTurnOffButton;
|
||||
@Mock
|
||||
private Button mTurnOnButton;
|
||||
@Mock
|
||||
private PowerManager mPM;
|
||||
|
||||
private Configuration configNightYes = new Configuration();
|
||||
private Configuration configNightNo = new Configuration();;
|
||||
@@ -67,6 +70,7 @@ public class DarkModeActivationPreferenceControllerTest {
|
||||
mService = mock(UiModeManager.class);
|
||||
when(mContext.getResources()).thenReturn(res);
|
||||
when(mContext.getSystemService(UiModeManager.class)).thenReturn(mService);
|
||||
when(mContext.getSystemService(PowerManager.class)).thenReturn(mPM);
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
when(mPreference.findViewById(
|
||||
eq(R.id.dark_ui_turn_on_button))).thenReturn(mTurnOnButton);
|
||||
@@ -152,4 +156,12 @@ public class DarkModeActivationPreferenceControllerTest {
|
||||
assertEquals(mController.getSummary(), mContext.getString(
|
||||
R.string.dark_ui_summary_off_auto_mode_auto));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buttonVisisbility_hideButton_offWhenInPowerSaveMode() {
|
||||
when(mPM.isPowerSaveMode()).thenReturn(true);
|
||||
mController.updateState(mPreference);
|
||||
verify(mTurnOffButton).setVisibility(eq(View.GONE));
|
||||
verify(mTurnOnButton).setVisibility(eq(View.GONE));
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@ package com.android.settings.display.darkmode;
|
||||
|
||||
import android.app.UiModeManager;
|
||||
import android.content.Context;
|
||||
import android.os.PowerManager;
|
||||
import androidx.preference.DropDownPreference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import org.junit.Before;
|
||||
@@ -31,6 +32,7 @@ import static junit.framework.TestCase.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -45,24 +47,27 @@ public class DarkModeScheduleSelectorControllerTest {
|
||||
private PreferenceScreen mScreen;
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private UiModeManager mService;
|
||||
private UiModeManager mUiService;
|
||||
@Mock
|
||||
private PowerManager mPM;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(UiModeManager.class)).thenReturn(mService);
|
||||
when(mContext.getSystemService(UiModeManager.class)).thenReturn(mUiService);
|
||||
when(mContext.getSystemService(PowerManager.class)).thenReturn(mPM);
|
||||
when(mContext.getString(R.string.dark_ui_auto_mode_never)).thenReturn("never");
|
||||
when(mContext.getString(R.string.dark_ui_auto_mode_auto)).thenReturn("auto");
|
||||
mPreference = spy(new DropDownPreference(mContext));
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
when(mService.setNightModeActivated(anyBoolean())).thenReturn(true);
|
||||
when(mUiService.setNightModeActivated(anyBoolean())).thenReturn(true);
|
||||
mController = new DarkModeScheduleSelectorController(mContext, mPreferenceKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nightMode_preferenceChange_preferenceChangeTrueWhenChangedOnly() {
|
||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES);
|
||||
when(mUiService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES);
|
||||
mController.displayPreference(mScreen);
|
||||
boolean changed = mController
|
||||
.onPreferenceChange(mScreen, mContext.getString(R.string.dark_ui_auto_mode_auto));
|
||||
@@ -74,7 +79,7 @@ public class DarkModeScheduleSelectorControllerTest {
|
||||
|
||||
@Test
|
||||
public void nightMode_updateStateNone_dropDownValueChangedToNone() {
|
||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES);
|
||||
when(mUiService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setValue(mContext.getString(R.string.dark_ui_auto_mode_never));
|
||||
@@ -82,9 +87,17 @@ public class DarkModeScheduleSelectorControllerTest {
|
||||
|
||||
@Test
|
||||
public void nightMode_updateStateNone_dropDownValueChangedToAuto() {
|
||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_AUTO);
|
||||
when(mUiService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_AUTO);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setValue(mContext.getString(R.string.dark_ui_auto_mode_auto));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void batterySaver_dropDown_disabledSelector() {
|
||||
when(mPM.isPowerSaveMode()).thenReturn(true);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setEnabled(eq(false));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user