Merge "Split the string resource id for non-generic accessibility preference." into main

This commit is contained in:
Treehugger Robot
2023-08-09 17:58:35 +00:00
committed by Android (Google) Code Review
17 changed files with 81 additions and 452 deletions

View File

@@ -200,7 +200,7 @@ public class AccessibilitySettingsTest {
}
@Test
public void getServiceSummary_enableServiceShortcutOn_showsServiceEnabledShortcutOn() {
public void getServiceSummary_enableServiceShortcutOnWithEmptyDescription_showsServiceEnabled() {
doReturn(EMPTY_STRING).when(mServiceInfo).loadSummary(any());
setShortcutEnabled(mServiceInfo.getComponentName(), true);
@@ -208,27 +208,23 @@ public class AccessibilitySettingsTest {
mServiceInfo, SERVICE_ENABLED).toString();
assertThat(summary).isEqualTo(
mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.generic_accessibility_service_on),
mContext.getString(R.string.accessibility_summary_shortcut_enabled)));
mContext.getString(R.string.generic_accessibility_service_on));
}
@Test
public void getServiceSummary_enableServiceShortcutOff_showsServiceEnabledShortcutOff() {
public void getServiceSummary_enableServiceShortcutOffWithEmptyDescription_showsServiceEnabled() {
doReturn(EMPTY_STRING).when(mServiceInfo).loadSummary(any());
setShortcutEnabled(mServiceInfo.getComponentName(), false);
String summary = AccessibilitySettings.getServiceSummary(mContext,
mServiceInfo, SERVICE_ENABLED).toString();
String summary = AccessibilitySettings.getServiceSummary(
mContext, mServiceInfo, SERVICE_ENABLED).toString();
assertThat(summary).isEqualTo(
mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.generic_accessibility_service_on),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off)));
mContext.getString(R.string.generic_accessibility_service_on));
}
@Test
public void getServiceSummary_disableServiceShortcutOff_showsDisabledShortcutOff() {
public void getServiceSummary_disableServiceShortcutOffWithEmptyDescription_showsServiceDisabled() {
doReturn(EMPTY_STRING).when(mServiceInfo).loadSummary(any());
setShortcutEnabled(mServiceInfo.getComponentName(), false);
@@ -236,13 +232,11 @@ public class AccessibilitySettingsTest {
mServiceInfo, SERVICE_DISABLED).toString();
assertThat(summary).isEqualTo(
mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.generic_accessibility_service_off),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off)));
mContext.getString(R.string.generic_accessibility_service_off));
}
@Test
public void getServiceSummary_disableServiceShortcutOn_showsDisabledShortcutOn() {
public void getServiceSummary_disableServiceShortcutOnWithEmptyDescription_showsServiceDisabled() {
doReturn(EMPTY_STRING).when(mServiceInfo).loadSummary(any());
setShortcutEnabled(mServiceInfo.getComponentName(), true);
@@ -250,13 +244,11 @@ public class AccessibilitySettingsTest {
mServiceInfo, SERVICE_DISABLED).toString();
assertThat(summary).isEqualTo(
mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.generic_accessibility_service_off),
mContext.getString(R.string.accessibility_summary_shortcut_enabled)));
mContext.getString(R.string.generic_accessibility_service_off));
}
@Test
public void getServiceSummary_enableServiceShortcutOffAndHasSummary_showsEnabledShortcutOffSummary() {
public void getServiceSummary_enableServiceShortcutOffAndHasSummary_showsEnabledSummary() {
setShortcutEnabled(mServiceInfo.getComponentName(), false);
doReturn(DEFAULT_SUMMARY).when(mServiceInfo).loadSummary(any());
@@ -264,14 +256,13 @@ public class AccessibilitySettingsTest {
mServiceInfo, SERVICE_ENABLED).toString();
assertThat(summary).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.generic_accessibility_service_on),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
DEFAULT_SUMMARY));
}
@Test
public void getServiceSummary_enableServiceShortcutOnAndHasSummary_showsEnabledShortcutOnSummary() {
public void getServiceSummary_enableServiceShortcutOnAndHasSummary_showsEnabledSummary() {
doReturn(DEFAULT_SUMMARY).when(mServiceInfo).loadSummary(any());
setShortcutEnabled(mServiceInfo.getComponentName(), true);
@@ -279,14 +270,13 @@ public class AccessibilitySettingsTest {
mServiceInfo, SERVICE_ENABLED).toString();
assertThat(summary).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.generic_accessibility_service_on),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
DEFAULT_SUMMARY));
}
@Test
public void getServiceSummary_disableServiceShortcutOnAndHasSummary_showsDisabledShortcutOnSummary() {
public void getServiceSummary_disableServiceShortcutOnAndHasSummary_showsDisabledSummary() {
doReturn(DEFAULT_SUMMARY).when(mServiceInfo).loadSummary(any());
setShortcutEnabled(mServiceInfo.getComponentName(), true);
@@ -294,14 +284,13 @@ public class AccessibilitySettingsTest {
mServiceInfo, SERVICE_DISABLED).toString();
assertThat(summary).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.generic_accessibility_service_off),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
DEFAULT_SUMMARY));
}
@Test
public void getServiceSummary_disableServiceShortcutOffAndHasSummary_showsDisabledShortcutOffSummary() {
public void getServiceSummary_disableServiceShortcutOffAndHasSummary_showsDisabledSummary() {
setShortcutEnabled(mServiceInfo.getComponentName(), false);
doReturn(DEFAULT_SUMMARY).when(mServiceInfo).loadSummary(any());
@@ -309,9 +298,8 @@ public class AccessibilitySettingsTest {
mServiceInfo, SERVICE_DISABLED).toString();
assertThat(summary).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.generic_accessibility_service_off),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
DEFAULT_SUMMARY));
}
@@ -336,36 +324,6 @@ public class AccessibilitySettingsTest {
assertThat(description).isEqualTo(DEFAULT_DESCRIPTION);
}
@Test
public void getA11yShortcutInfoPreferenceSummary_shortcutOn_showsShortcutOnSummary() {
doReturn(DEFAULT_SUMMARY).when(mShortcutInfo).loadSummary(any());
setShortcutEnabled(COMPONENT_NAME, true);
String summary = AccessibilitySettings.getA11yShortcutInfoPreferenceSummary(
mContext,
mShortcutInfo).toString();
assertThat(summary).isEqualTo(
mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
DEFAULT_SUMMARY));
}
@Test
public void getA11yShortcutInfoPreferenceSummary_shortcutOff_showsShortcutOffSummary() {
doReturn(DEFAULT_SUMMARY).when(mShortcutInfo).loadSummary(any());
setShortcutEnabled(COMPONENT_NAME, false);
String summary = AccessibilitySettings.getA11yShortcutInfoPreferenceSummary(
mContext,
mShortcutInfo).toString();
assertThat(summary).isEqualTo(
mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
DEFAULT_SUMMARY));
}
@Test
@Config(shadows = {ShadowFragment.class, ShadowUserManager.class})
public void onCreate_haveRegisterToSpecificUrisAndActions() {

View File

@@ -248,82 +248,6 @@ public final class AccessibilityUtilTest {
MOCK_COMPONENT_NAME.flattenToString());
}
@Test
public void getFeatureFullStateSummary_featureOffShortcutOff_showsOffShortcutOffAndSummary() {
setSettingsFeatureEnabled(PLACEHOLDER_SETTING_FEATURE, false);
clearShortcuts();
String expectedText = mContext.getString(
R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.color_inversion_state_off),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
mContext.getString(R.string.color_inversion_feature_summary));
String observerText = AccessibilityUtil.getFeatureFullStateSummary(
mContext, MOCK_COMPONENT_NAME,
PLACEHOLDER_SETTING_FEATURE,
R.string.color_inversion_state_on, R.string.color_inversion_state_off,
R.string.color_inversion_feature_summary).toString();
assertThat(observerText).isEqualTo(expectedText);
}
@Test
public void getFeatureFullStateSummary_featureOnShortcutOff_showsOnShortcutOffAndSummary() {
setSettingsFeatureEnabled(PLACEHOLDER_SETTING_FEATURE, true);
clearShortcuts();
String expectedText = mContext.getString(
R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.color_inversion_state_on),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
mContext.getString(R.string.color_inversion_feature_summary));
String observerText = AccessibilityUtil.getFeatureFullStateSummary(
mContext, MOCK_COMPONENT_NAME,
PLACEHOLDER_SETTING_FEATURE,
R.string.color_inversion_state_on, R.string.color_inversion_state_off,
R.string.color_inversion_feature_summary).toString();
assertThat(observerText).isEqualTo(expectedText);
}
@Test
public void getFeatureFullStateSummary_featureOffShortcutOn_showsOffShortcutOnAndSummary() {
setSettingsFeatureEnabled(PLACEHOLDER_SETTING_FEATURE, false);
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
String expectedText = mContext.getString(
R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.color_inversion_state_off),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
mContext.getString(R.string.color_inversion_feature_summary));
String observerText = AccessibilityUtil.getFeatureFullStateSummary(
mContext, MOCK_COMPONENT_NAME,
PLACEHOLDER_SETTING_FEATURE,
R.string.color_inversion_state_on, R.string.color_inversion_state_off,
R.string.color_inversion_feature_summary).toString();
assertThat(observerText).isEqualTo(expectedText);
}
@Test
public void getFeatureFullStateSummary_featureOnShortcutOn_showsOnShortcutOnAndSummary() {
setSettingsFeatureEnabled(PLACEHOLDER_SETTING_FEATURE, true);
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
String expectedText = mContext.getString(
R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.color_inversion_state_on),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
mContext.getString(R.string.color_inversion_feature_summary));
String observerText = AccessibilityUtil.getFeatureFullStateSummary(
mContext, MOCK_COMPONENT_NAME,
PLACEHOLDER_SETTING_FEATURE,
R.string.color_inversion_state_on, R.string.color_inversion_state_off,
R.string.color_inversion_feature_summary).toString();
assertThat(observerText).isEqualTo(expectedText);
}
private AccessibilityServiceInfo getMockAccessibilityServiceInfo() {
final ApplicationInfo applicationInfo = new ApplicationInfo();
final ServiceInfo serviceInfo = new ServiceInfo();

View File

@@ -52,51 +52,39 @@ public class ColorInversionPreferenceControllerTest {
}
@Test
public void getSummary_enabledColorInversionShortcutOff_shouldReturnOnShortcutOffSummary() {
public void getSummary_enabledColorInversionShortcutOff_shouldReturnOnSummary() {
setColorInversionEnabled(true);
setColorInversionShortcutEnabled(false);
assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.color_inversion_state_on),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
mColorInversionSummary));
mContext.getString(R.string.color_inversion_state_on));
}
@Test
public void getSummary_enabledColorInversionShortcutOn_shouldReturnOnShortcutOnSummary() {
public void getSummary_enabledColorInversionShortcutOn_shouldReturnOnSummary() {
setColorInversionEnabled(true);
setColorInversionShortcutEnabled(true);
assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.color_inversion_state_on),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
mColorInversionSummary));
mContext.getString(R.string.color_inversion_state_on));
}
@Test
public void getSummary_disabledColorInversionShortcutOff_shouldReturnOffShortcutOffSummary() {
public void getSummary_disabledColorInversionShortcutOff_shouldReturnOffSummary() {
setColorInversionEnabled(false);
setColorInversionShortcutEnabled(false);
assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.color_inversion_state_off),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
mColorInversionSummary));
mContext.getString(R.string.color_inversion_state_off));
}
@Test
public void getSummary_disabledColorInversionShortcutOn_shouldReturnOffShortcutOnSummary() {
public void getSummary_disabledColorInversionShortcutOn_shouldReturnOffSummary() {
setColorInversionEnabled(false);
setColorInversionShortcutEnabled(true);
assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.color_inversion_state_off),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
mColorInversionSummary));
mContext.getString(R.string.color_inversion_state_off));
}
private void setColorInversionShortcutEnabled(boolean enabled) {

View File

@@ -50,51 +50,39 @@ public class DaltonizerPreferenceControllerTest {
}
@Test
public void getSummary_enabledColorCorrectionShortcutOff_shouldReturnOnShortcutOffSummary() {
public void getSummary_enabledColorCorrectionShortcutOff_shouldReturnOnSummary() {
setColorCorrectionEnabled(true);
setColorCorrectionShortcutEnabled(false);
assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.daltonizer_state_on),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
mDaltonizerSummary));
mContext.getString(R.string.daltonizer_state_on));
}
@Test
public void getSummary_enabledColorCorrectionShortcutOn_shouldReturnOnShortcutOnSummary() {
public void getSummary_enabledColorCorrectionShortcutOn_shouldReturnOnSummary() {
setColorCorrectionEnabled(true);
setColorCorrectionShortcutEnabled(true);
assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.daltonizer_state_on),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
mDaltonizerSummary));
mContext.getString(R.string.daltonizer_state_on));
}
@Test
public void getSummary_disabledColorCorrectionShortcutOff_shouldReturnOffShortcutOffSummary() {
public void getSummary_disabledColorCorrectionShortcutOff_shouldReturnOffSummary() {
setColorCorrectionEnabled(false);
setColorCorrectionShortcutEnabled(false);
assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.daltonizer_state_off),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
mDaltonizerSummary));
mContext.getString(R.string.daltonizer_state_off));
}
@Test
public void getSummary_disabledColorCorrectionShortcutOn_shouldReturnOffShortcutOnSummary() {
public void getSummary_disabledColorCorrectionShortcutOn_shouldReturnOffSummary() {
setColorCorrectionEnabled(false);
setColorCorrectionShortcutEnabled(true);
assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.daltonizer_state_off),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
mDaltonizerSummary));
mContext.getString(R.string.daltonizer_state_off));
}
private void setColorCorrectionEnabled(boolean enabled) {

View File

@@ -51,6 +51,7 @@ public class LiveCaptionPreferenceControllerTest {
mContext = ApplicationProvider.getApplicationContext();
mController = new LiveCaptionPreferenceController(mContext, "test_key");
mLiveCaptionPreference = new Preference(mContext);
mLiveCaptionPreference.setSummary(R.string.live_caption_summary);
}
@Test
@@ -78,10 +79,7 @@ public class LiveCaptionPreferenceControllerTest {
mController.updateState(mLiveCaptionPreference);
assertThat(mLiveCaptionPreference.getSummary().toString()).isEqualTo(
mContext.getString(
R.string.preference_summary_default_combination,
mContext.getString(R.string.live_caption_enabled),
mContext.getText(R.string.live_caption_summary))
mContext.getString(R.string.live_caption_summary)
);
}
@@ -92,10 +90,7 @@ public class LiveCaptionPreferenceControllerTest {
mController.updateState(mLiveCaptionPreference);
assertThat(mLiveCaptionPreference.getSummary()).isEqualTo(
mContext.getString(
R.string.preference_summary_default_combination,
mContext.getString(R.string.live_caption_disabled),
mContext.getText(R.string.live_caption_summary))
mContext.getString(R.string.live_caption_summary)
);
}

View File

@@ -494,28 +494,23 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
}
@Test
public void getSummary_magnificationEnabled_returnShortcutOnWithSummary() {
public void getSummary_magnificationEnabled_returnShortcutOn() {
setMagnificationTripleTapEnabled(true);
assertThat(
ToggleScreenMagnificationPreferenceFragment.getServiceSummary(mContext).toString())
.isEqualTo(
mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
mContext.getText(R.string.magnification_feature_summary)));
mContext.getString(R.string.accessibility_summary_shortcut_enabled));
}
@Test
public void getSummary_magnificationDisabled_returnShortcutOffWithSummary() {
public void getSummary_magnificationDisabled_returnShortcutOff() {
setMagnificationTripleTapEnabled(false);
assertThat(
ToggleScreenMagnificationPreferenceFragment.getServiceSummary(mContext).toString())
.isEqualTo(
mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(
R.string.generic_accessibility_feature_shortcut_off),
mContext.getText(R.string.magnification_feature_summary)));
mContext.getString(R.string.generic_accessibility_feature_shortcut_off));
}
private void putStringIntoSettings(String key, String componentName) {