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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
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.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 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 DaltonizerRadioButtonPreferenceControllerTest implements
|
||||
DaltonizerRadioButtonPreferenceController.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";
|
||||
|
||||
private DaltonizerRadioButtonPreferenceController mController;
|
||||
|
||||
@Mock
|
||||
private RadioButtonPreference mMockPref;
|
||||
private Context mContext;
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new DaltonizerRadioButtonPreferenceController(mContext, mock(Lifecycle.class),
|
||||
PREF_KEY);
|
||||
mController.setOnChangeListener(this);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_notChecked() {
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, PREF_FAKE_VALUE);
|
||||
|
||||
mController.updateState(mMockPref);
|
||||
|
||||
// the first checked state is set to false by control
|
||||
verify(mMockPref, atLeastOnce()).setChecked(false);
|
||||
verify(mMockPref, never()).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_checked() {
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, PREF_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(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER);
|
||||
|
||||
assertThat(accessibilityDaltonizerValue).isEqualTo(PREF_VALUE);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user