refactor(A11yFeedback): Simply feedback logic into menu controller
Bug: 393980229 Test: atest FeedbackMenuControllerTest Flag: com.android.server.accessibility.enable_low_vision_generic_feedback Change-Id: I03af00957c2bcca1d1cc81970eccad6dd69bb4ac
This commit is contained in:
@@ -23,8 +23,6 @@ import static com.android.internal.accessibility.common.ShortcutConstants.UserSh
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -38,16 +36,14 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.icu.text.CaseMap;
|
||||
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;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
@@ -107,19 +103,10 @@ public class ToggleFeaturePreferenceFragmentTest {
|
||||
PLACEHOLDER_PACKAGE_NAME + "tile.placeholder";
|
||||
private static final ComponentName PLACEHOLDER_TILE_COMPONENT_NAME = new ComponentName(
|
||||
PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME);
|
||||
private static final String PLACEHOLDER_TILE_TOOLTIP_CONTENT =
|
||||
PLACEHOLDER_PACKAGE_NAME + "tooltip_content";
|
||||
private static final String PLACEHOLDER_CATEGORY = "category";
|
||||
private static final String PLACEHOLDER_DIALOG_TITLE = "title";
|
||||
private static final String DEFAULT_SUMMARY = "default summary";
|
||||
private static final String DEFAULT_DESCRIPTION = "default description";
|
||||
private static final String DEFAULT_TOP_INTRO = "default top intro";
|
||||
|
||||
private static final String SOFTWARE_SHORTCUT_KEY =
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
|
||||
private static final String HARDWARE_SHORTCUT_KEY =
|
||||
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
|
||||
|
||||
private TestToggleFeaturePreferenceFragment mFragment;
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@@ -135,9 +122,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private Menu mMenu;
|
||||
@Mock
|
||||
private MenuItem mMenuItem;
|
||||
private Resources mResources;
|
||||
|
||||
@Before
|
||||
public void setUpTestFragment() {
|
||||
@@ -150,6 +135,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
||||
when(mFragment.getContext()).thenReturn(mContext);
|
||||
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
|
||||
when(mActivity.getResources()).thenReturn(mResources);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
final PreferenceScreen screen = spy(new PreferenceScreen(mContext, null));
|
||||
when(screen.getPreferenceManager()).thenReturn(mPreferenceManager);
|
||||
@@ -186,61 +172,6 @@ public class ToggleFeaturePreferenceFragmentTest {
|
||||
any(AccessibilitySettingsContentObserver.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_LOW_VISION_GENERIC_FEEDBACK)
|
||||
public void onCreateOptionsMenu_enableLowVisionGenericFeedback_shouldAddSendFeedbackMenu() {
|
||||
mFragment.setFeedbackManager(
|
||||
new FeedbackManager(mActivity, PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_CATEGORY));
|
||||
|
||||
mFragment.onCreateOptionsMenu(mMenu, /* inflater= */ null);
|
||||
|
||||
verify(mMenu).add(anyInt(), eq(ToggleFeaturePreferenceFragment.MENU_ID_SEND_FEEDBACK),
|
||||
anyInt(), eq(R.string.accessibility_send_feedback_title));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_LOW_VISION_GENERIC_FEEDBACK)
|
||||
public void onCreateOptionsMenu_disableLowVisionGenericFeedback_shouldNotAddSendFeedbackMenu() {
|
||||
mFragment.setFeedbackManager(
|
||||
new FeedbackManager(mActivity, PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_CATEGORY));
|
||||
|
||||
mFragment.onCreateOptionsMenu(mMenu, /* inflater= */ null);
|
||||
|
||||
verify(mMenu, never()).add(anyInt(),
|
||||
eq(ToggleFeaturePreferenceFragment.MENU_ID_SEND_FEEDBACK), anyInt(),
|
||||
eq(R.string.accessibility_send_feedback_title));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_LOW_VISION_GENERIC_FEEDBACK)
|
||||
public void onOptionsItemSelected_enableLowVisionGenericFeedback_shouldStartSendFeedback() {
|
||||
mFragment.setFeedbackManager(
|
||||
new FeedbackManager(mActivity, PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_CATEGORY));
|
||||
when(mMenuItem.getItemId()).thenReturn(
|
||||
ToggleFeaturePreferenceFragment.MENU_ID_SEND_FEEDBACK);
|
||||
|
||||
mFragment.onOptionsItemSelected(mMenuItem);
|
||||
|
||||
verify(mActivity).startActivityForResult(
|
||||
argThat(intent -> intent != null
|
||||
&& Intent.ACTION_BUG_REPORT.equals(intent.getAction())), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_LOW_VISION_GENERIC_FEEDBACK)
|
||||
public void onOptionsItemSelected_disableLowVisionGenericFeedback_shouldNotStartSendFeedback() {
|
||||
mFragment.setFeedbackManager(
|
||||
new FeedbackManager(mActivity, PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_CATEGORY));
|
||||
when(mMenuItem.getItemId()).thenReturn(
|
||||
ToggleFeaturePreferenceFragment.MENU_ID_SEND_FEEDBACK);
|
||||
|
||||
mFragment.onOptionsItemSelected(mMenuItem);
|
||||
|
||||
verify(mActivity, never()).startActivityForResult(
|
||||
argThat(intent -> intent != null
|
||||
&& Intent.ACTION_BUG_REPORT.equals(intent.getAction())), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateShortcutPreferenceData_assignDefaultValueToVariable() {
|
||||
mFragment.mComponentName = PLACEHOLDER_COMPONENT_NAME;
|
||||
|
Reference in New Issue
Block a user