Use MainSwitchPreference on Bubbles, Screen Saver and
One-Handed mode pages. Fixes: 178679876 Fixes: 177968619 Test: robotest and see the UIs. Change-Id: Ic62c7464a71e5410ece5d1db7578c522e1babedc
This commit is contained in:
@@ -26,17 +26,15 @@ import static com.android.settings.notification.BadgingNotificationPreferenceCon
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settingslib.widget.MainSwitchPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -57,7 +55,7 @@ public class BubbleNotificationPreferenceControllerTest {
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private BubbleNotificationPreferenceController mController;
|
||||
private Preference mPreference;
|
||||
private MainSwitchPreference mPreference;
|
||||
|
||||
private static final String KEY_NOTIFICATION_BUBBLES = "notification_bubbles";
|
||||
|
||||
@@ -67,15 +65,16 @@ public class BubbleNotificationPreferenceControllerTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new BubbleNotificationPreferenceController(mContext,
|
||||
KEY_NOTIFICATION_BUBBLES);
|
||||
mPreference = new Preference(RuntimeEnvironment.application);
|
||||
mPreference = new MainSwitchPreference(RuntimeEnvironment.application);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_lowRam_returnsUnsupported() {
|
||||
final ShadowActivityManager activityManager =
|
||||
Shadow.extract(mContext.getSystemService(ActivityManager.class));
|
||||
Shadow.extract(mContext.getSystemService(ActivityManager.class));
|
||||
activityManager.setIsLowRamDevice(true);
|
||||
assertEquals(UNSUPPORTED_ON_DEVICE, mController.getAvailabilityStatus());
|
||||
}
|
||||
@@ -83,45 +82,40 @@ public class BubbleNotificationPreferenceControllerTest {
|
||||
@Test
|
||||
public void isAvailable_notLowRam_returnsAvailable() {
|
||||
final ShadowActivityManager activityManager =
|
||||
Shadow.extract(mContext.getSystemService(ActivityManager.class));
|
||||
Shadow.extract(mContext.getSystemService(ActivityManager.class));
|
||||
activityManager.setIsLowRamDevice(false);
|
||||
assertEquals(AVAILABLE, mController.getAvailabilityStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_settingIsOn_preferenceSetChecked() {
|
||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON);
|
||||
|
||||
mController.updateState(preference);
|
||||
|
||||
verify(preference).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_settingIsOff_preferenceSetUnchecked() {
|
||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
|
||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_BUBBLES, ON)).isEqualTo(OFF);
|
||||
|
||||
mController.updateState(preference);
|
||||
mPreference.updateStatus(false);
|
||||
|
||||
verify(preference).setChecked(false);
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_settingIsOff_shouldReturnFalse() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
|
||||
public void onSwitchChanged_true_settingIsOff_flagShouldOn() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
mController.onSwitchChanged(null, true);
|
||||
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_BUBBLES, OFF)).isEqualTo(ON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_settingIsOn_shouldReturnTrue() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON);
|
||||
public void onSwitchChanged_false_settingIsOn_flagShouldOff() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON);
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
mController.onSwitchChanged(null, false);
|
||||
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_BUBBLES, ON)).isEqualTo(OFF);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,8 +123,8 @@ public class BubbleNotificationPreferenceControllerTest {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON);
|
||||
|
||||
mController.setChecked(false);
|
||||
int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_BUBBLES, -1);
|
||||
int updatedValue = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_BUBBLES, ON);
|
||||
|
||||
assertThat(updatedValue).isEqualTo(OFF);
|
||||
}
|
||||
@@ -140,8 +134,8 @@ public class BubbleNotificationPreferenceControllerTest {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
|
||||
|
||||
mController.setChecked(true);
|
||||
int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_BUBBLES, -1);
|
||||
int updatedValue = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_BUBBLES, OFF);
|
||||
|
||||
assertThat(updatedValue).isEqualTo(ON);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user