Color correction improvement (3/n)

1. Add summary in accessibility settings page by controller
2. Fix "XmlControllerAttributeTest" for ColorCorrection

Bug: 145968068
Bug: 146319816
Test: make RunSettingsRoboTests2
Change-Id: Ia4dfb2290953eea33c266bd9f7c825c956bcc93a
This commit is contained in:
menghanli
2019-12-16 21:49:53 +08:00
parent 458d5e81cc
commit 657189062f
6 changed files with 358 additions and 211 deletions

View File

@@ -18,100 +18,57 @@ package com.android.settings.accessibility;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.RadioButtonPreference;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class DaltonizerPreferenceControllerTest implements
DaltonizerPreferenceController.OnChangeListener {
private static final String PREF_KEY = "daltonizer_mode_protanomaly";
private static final String PREF_VALUE = "11";
private static final String PREF_FAKE_VALUE = "-1";
public class DaltonizerPreferenceControllerTest {
private static final String PREF_KEY = "daltonizer_preference";
private static final int ON = 1;
private static final int OFF = 0;
private static final String DALTONIZER_VALUE = "11";
private DaltonizerPreferenceController mController;
@Mock
private RadioButtonPreference mMockPref;
private Context mContext;
private ContentResolver mContentResolver;
@Mock
private PreferenceScreen mScreen;
private DaltonizerPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new DaltonizerPreferenceController(mContext, mock(Lifecycle.class), PREF_KEY);
mController.setOnChangeListener(this);
mContentResolver = mContext.getContentResolver();
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mMockPref);
when(mMockPref.getKey()).thenReturn(PREF_KEY);
mController.displayPreference(mScreen);
}
@Override
public void onCheckedChanged(Preference preference) {
mController.updateState(preference);
mController = new DaltonizerPreferenceController(mContext, PREF_KEY);
}
@Test
public void isAvailable() {
assertThat(mController.isAvailable()).isTrue();
public void getSummary_enabledColorCorrection_shouldReturnOnSummary() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, ON);
assertThat(mController.getSummary().toString().contains(
mContext.getText(R.string.accessibility_feature_state_on))).isTrue();
}
@Test
public void updateState_notChecked() {
Settings.Secure.putString(mContentResolver,
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, PREF_FAKE_VALUE);
public void getSummary_disabledColorCorrection_shouldReturnOffSummary() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, OFF);
mController.updateState(mMockPref);
// the first checked state is set to false by control
verify(mMockPref, atLeastOnce()).setChecked(false);
verify(mMockPref, never()).setChecked(true);
assertThat(mController.getSummary().toString().contains(
mContext.getText(R.string.accessibility_feature_state_off))).isTrue();
}
@Test
public void updateState_checked() {
Settings.Secure.putString(mContentResolver,
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, PREF_VALUE);
public void getSummary_selectProtanomaly_shouldReturnProtanomalySummary() {
Settings.Secure.putString(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, DALTONIZER_VALUE);
mController.updateState(mMockPref);
// the first checked state is set to false by control
verify(mMockPref, atLeastOnce()).setChecked(false);
verify(mMockPref, atLeastOnce()).setChecked(true);
}
@Test
public void onRadioButtonClick_shouldReturnDaltonizerValue() {
mController.onRadioButtonClicked(mMockPref);
final String accessibilityDaltonizerValue = Settings.Secure.getString(mContentResolver,
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER);
assertThat(accessibilityDaltonizerValue).isEqualTo(PREF_VALUE);
assertThat(mController.getSummary().toString().contains(
mContext.getText(R.string.daltonizer_mode_protanomaly))).isTrue();
}
}