Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 658459de authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix for broken tests in Accessibility Settings" into main

parents 6a6a3efe 62449dd6
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -28,6 +28,10 @@ import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Flags;

import androidx.fragment.app.FragmentActivity;
import androidx.preference.PreferenceManager;
@@ -56,6 +60,8 @@ import java.util.List;
@RunWith(RobolectricTestRunner.class)
public class AccessibilityButtonFragmentTest {

    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
    @Rule
    public MockitoRule mMockitoRule = MockitoJUnit.rule();
    @Spy
@@ -84,6 +90,7 @@ public class AccessibilityButtonFragmentTest {
    }

    @Test
    @DisableFlags(Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void onCreate_navigationGestureEnabled_setCorrectTitle() {
        when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
                .thenReturn(NAV_BAR_MODE_GESTURAL);
@@ -96,7 +103,20 @@ public class AccessibilityButtonFragmentTest {
    }

    @Test
    public void onCreate_navigationGestureDisabled_setCorrectTitle() {
    @EnableFlags(Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void onCreate_navigationGestureEnabled_gestureFlag_setCorrectTitle() {
        when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
                .thenReturn(NAV_BAR_MODE_GESTURAL);

        mFragment.onAttach(mContext);
        mFragment.onCreate(Bundle.EMPTY);

        assertThat(mFragment.getActivity().getTitle().toString()).isEqualTo(
                mContext.getString(R.string.accessibility_button_title));
    }

    @Test
    public void onCreate_navigationBarEnabled_setCorrectTitle() {
        when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
                .thenReturn(NAV_BAR_MODE_2BUTTON);

+17 −0
Original line number Diff line number Diff line
@@ -30,6 +30,10 @@ import static org.mockito.Mockito.when;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Flags;
import android.provider.Settings;

import androidx.preference.ListPreference;
@@ -48,6 +52,8 @@ import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class AccessibilityButtonGesturePreferenceControllerTest {

    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
    @Rule
    public final MockitoRule mockito = MockitoJUnit.rule();

@@ -67,6 +73,7 @@ public class AccessibilityButtonGesturePreferenceControllerTest {
    }

    @Test
    @DisableFlags(Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void getAvailabilityStatus_navigationGestureEnabled_returnAvailable() {
        when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
                .thenReturn(NAV_BAR_MODE_GESTURAL);
@@ -74,6 +81,16 @@ public class AccessibilityButtonGesturePreferenceControllerTest {
        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
    }

    @Test
    @EnableFlags(Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void
            getAvailabilityStatus_navigationGestureEnabled_gestureFlag_conditionallyUnavailable() {
        when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
                .thenReturn(NAV_BAR_MODE_GESTURAL);

        assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
    }

    @Test
    public void getAvailabilityStatus_navigationGestureDisabled_returnConditionallyUnavailable() {
        when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
+66 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settings.accessibility.shortcuts;

import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_COMPONENT_NAME;
import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.SOFTWARE;
import static com.android.settings.accessibility.shortcuts.EditShortcutsPreferenceFragment.SHORTCUT_SETTINGS;

import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_DEFERRED_SETUP;
@@ -36,6 +37,7 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
@@ -240,6 +242,7 @@ public class EditShortcutsPreferenceFragmentTest {
    }

    @Test
    @DisableFlags(android.provider.Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void onSoftwareShortcutSettingChanged_softwareControllersUpdated() {
        mFragmentScenario = createFragScenario(/* isInSuw= */ false, TARGET);
        mFragmentScenario.moveToState(Lifecycle.State.CREATED);
@@ -256,6 +259,27 @@ public class EditShortcutsPreferenceFragmentTest {
    }

    @Test
    @EnableFlags(android.provider.Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void onSoftwareShortcutSettingsChanged_softwareControllersUpdated() {
        mFragmentScenario = createFragScenario(/* isInSuw= */ false, TARGET);
        mFragmentScenario.moveToState(Lifecycle.State.CREATED);

        ShortcutUtils.optInValueToSettings(
                mContext, ShortcutConstants.UserShortcutType.SOFTWARE, TARGET);
        ShadowLooper.runUiThreadTasksIncludingDelayedTasks();

        mFragmentScenario.onFragment(fragment -> {
            TwoStatePreference preference = fragment.findPreference(
                    mContext.getString(R.string.accessibility_shortcut_fab_pref));
            assertThat(preference.isChecked()).isTrue();
            preference = fragment.findPreference(
                    mContext.getString(R.string.accessibility_shortcut_gesture_pref));
            assertThat(preference.isChecked()).isFalse();
        });
    }

    @Test
    @DisableFlags(android.provider.Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void onSoftwareShortcutModeChanged_softwareControllersUpdated() {
        mFragmentScenario = createFragScenario(/* isInSuw= */ false, TARGET);
        mFragmentScenario.moveToState(Lifecycle.State.CREATED);
@@ -309,6 +333,7 @@ public class EditShortcutsPreferenceFragmentTest {
    }

    @Test
    @DisableFlags(android.provider.Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void fragmentResumed_enableTouchExploration_gestureShortcutOptionSummaryUpdated() {
        String expectedSummary = StringUtil.getIcuPluralsString(mContext, 3,
                R.string.accessibility_shortcut_edit_dialog_summary_gesture)
@@ -330,6 +355,26 @@ public class EditShortcutsPreferenceFragmentTest {
    }

    @Test
    @EnableFlags(android.provider.Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void fragmentResumed_enableTouchExploration_gestureFlag_gestureSummaryUpdated() {
        String expectedSummary = StringUtil.getIcuPluralsString(mContext, 3,
                R.string.accessibility_shortcut_edit_dialog_summary_gesture);
        mFragmentScenario = createFragScenario(/* isInSuw= */ false, TARGET);
        mFragmentScenario.moveToState(Lifecycle.State.RESUMED);

        ShadowAccessibilityManager am = shadowOf(
                mContext.getSystemService(AccessibilityManager.class));
        am.setTouchExplorationEnabled(true);

        mFragmentScenario.onFragment(fragment -> {
            Preference preference = fragment.findPreference(
                    mContext.getString(R.string.accessibility_shortcut_gesture_pref));
            assertThat(preference.getSummary().toString()).isEqualTo(expectedSummary);
        });
    }

    @Test
    @DisableFlags(android.provider.Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void fragmentPaused_enableTouchExploration_gestureShortcutOptionSummaryNotUpdated() {
        String expectedSummary = StringUtil.getIcuPluralsString(mContext, 2,
                R.string.accessibility_shortcut_edit_dialog_summary_gesture)
@@ -350,6 +395,25 @@ public class EditShortcutsPreferenceFragmentTest {
        });
    }

    @Test
    @EnableFlags(android.provider.Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void fragmentPaused_enableTouchExploration_gestureFlag_gestureSummaryNotUpdated() {
        String expectedSummary = StringUtil.getIcuPluralsString(mContext, 2,
                R.string.accessibility_shortcut_edit_dialog_summary_gesture);
        mFragmentScenario = createFragScenario(/* isInSuw= */ false, TARGET);
        mFragmentScenario.moveToState(Lifecycle.State.RESUMED).moveToState(Lifecycle.State.STARTED);

        ShadowAccessibilityManager am = shadowOf(
                mContext.getSystemService(AccessibilityManager.class));
        am.setTouchExplorationEnabled(true);

        mFragmentScenario.onFragment(fragment -> {
            Preference preference = fragment.findPreference(
                    mContext.getString(R.string.accessibility_shortcut_gesture_pref));
            assertThat(preference.getSummary().toString()).isEqualTo(expectedSummary);
        });
    }

    @Test
    @EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
    public void fragmentResumed_enableTouchExploration_qsShortcutOptionSummaryUpdated() {
@@ -441,7 +505,7 @@ public class EditShortcutsPreferenceFragmentTest {
        assertThat(
                PreferredShortcuts.retrieveUserShortcutType(
                        mContext, TARGET)
        ).isEqualTo(ShortcutConstants.UserShortcutType.SOFTWARE);
        ).isEqualTo(SOFTWARE);
        // Update the chosen shortcut type to Volume keys while the fragment is in the background
        ShortcutUtils.optInValueToSettings(
                mContext, ShortcutConstants.UserShortcutType.HARDWARE, TARGET);
@@ -461,7 +525,7 @@ public class EditShortcutsPreferenceFragmentTest {
        assertThat(
                PreferredShortcuts.retrieveUserShortcutType(
                        mContext, TARGET)
        ).isEqualTo(ShortcutConstants.UserShortcutType.SOFTWARE);
        ).isEqualTo(SOFTWARE);

        ShortcutUtils.optInValueToSettings(
                mContext, ShortcutConstants.UserShortcutType.HARDWARE, TARGET);
+14 −0
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ public class GestureShortcutOptionControllerTest {
    }

    @Test
    @DisableFlags(Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void getSummary_touchExplorationEnabled_notInSuw_verifySummary() {
        enableTouchExploration(true);
        mController.setInSetupWizard(false);
@@ -133,6 +134,19 @@ public class GestureShortcutOptionControllerTest {
        assertThat(mController.getSummary().toString()).isEqualTo(expected);
    }

    @Test
    @EnableFlags(Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void getSummary_touchExplorationEnabled_notInSuw_gestureFlag_verifySummary() {
        enableTouchExploration(true);
        mController.setInSetupWizard(false);
        String expected = StringUtil.getIcuPluralsString(
                mContext,
                /* count= */ 3,
                R.string.accessibility_shortcut_edit_dialog_summary_gesture);

        assertThat(mController.getSummary().toString()).isEqualTo(expected);
    }

    @Test
    public void getSummary_touchExplorationEnabled_inSuw_verifySummary() {
        enableTouchExploration(true);