Added test cases for new A11y action
1. Tests textview could expose this A11y action with correct
action label and id.
2. Tests textview could expose stored ime action id to editor
when performing this A11y action.
Bug: 139380257
Test: atest AccessibilityTextActionTest
Change-Id: I9dfc80bc2bf6aa0e29e1a29f957f0fdf9d8c2eec
diff --git a/tests/accessibilityservice/res/layout/accessibility_text_traversal_test.xml b/tests/accessibilityservice/res/layout/accessibility_text_traversal_test.xml
index 852a003..58824d4 100644
--- a/tests/accessibilityservice/res/layout/accessibility_text_traversal_test.xml
+++ b/tests/accessibilityservice/res/layout/accessibility_text_traversal_test.xml
@@ -57,4 +57,11 @@
android:visibility="gone"
/>
+ <EditText
+ android:id="@+id/editText"
+ android:singleLine="true"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ />
+
</LinearLayout>
diff --git a/tests/accessibilityservice/res/values/strings.xml b/tests/accessibilityservice/res/values/strings.xml
index 28dd9f4..dc6102e 100644
--- a/tests/accessibilityservice/res/values/strings.xml
+++ b/tests/accessibilityservice/res/values/strings.xml
@@ -184,4 +184,7 @@
<!-- String title of accessibility embedded display test activity -->
<string name="accessibility_embedded_display_test_activity">Embedded display test</string>
+ <!-- String the default label of AccessibilityAction ACTION_IME_ENTER -->
+ <string name="accessibility_action_ime_enter_label">Enter</string>
+
</resources>
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextActionTest.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextActionTest.java
index 3d013cb..afa68a9 100644
--- a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextActionTest.java
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextActionTest.java
@@ -29,6 +29,7 @@
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
import android.accessibility.cts.common.AccessibilityDumpOnFailureRule;
import android.accessibilityservice.cts.activities.AccessibilityTextTraversalActivity;
@@ -51,6 +52,7 @@
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeProvider;
import android.view.accessibility.AccessibilityRequestPreparer;
+import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
@@ -434,6 +436,47 @@
a11yManager.removeAccessibilityRequestPreparer(requestPreparer);
}
+ @Test
+ public void testEditableTextView_shouldExposeAndRespondToImeEnterAction() throws Throwable {
+ final TextView textView = (TextView) mActivity.findViewById(R.id.editText);
+ makeTextViewVisibleAndSetText(textView, mActivity.getString(R.string.a_b));
+ textView.requestFocus();
+ assertTrue(textView.isFocused());
+
+ final TextView.OnEditorActionListener mockOnEditorActionListener =
+ mock(TextView.OnEditorActionListener.class);
+ textView.setOnEditorActionListener(mockOnEditorActionListener);
+ verifyZeroInteractions(mockOnEditorActionListener);
+
+ final AccessibilityNodeInfo text = sUiAutomation.getRootInActiveWindow()
+ .findAccessibilityNodeInfosByText(mActivity.getString(R.string.a_b)).get(0);
+ final List<AccessibilityNodeInfo.AccessibilityAction> actionList = text.getActionList();
+ assertTrue("Editable and focused text view should support ACTION_IME_ENTER",
+ actionList.contains(AccessibilityNodeInfo.AccessibilityAction.ACTION_IME_ENTER));
+
+ final int actionCount = actionList.size();
+ for (int i = 0; i < actionCount; i++) {
+ AccessibilityNodeInfo.AccessibilityAction action = actionList.get(i);
+ if (action.getId() == TextView.ACCESSIBILITY_ACTION_IME_ENTER) {
+ assertEquals(action.getLabel().toString(),
+ sInstrumentation.getContext().getString(
+ R.string.accessibility_action_ime_enter_label));
+ break;
+ }
+ }
+ text.performAction(TextView.ACCESSIBILITY_ACTION_IME_ENTER);
+ verify(mockOnEditorActionListener, times(1)).onEditorAction(
+ textView, EditorInfo.IME_ACTION_UNSPECIFIED, null);
+
+ // Testing custom ime action : IME_ACTION_DONE.
+ textView.setImeActionLabel("pinyin", EditorInfo.IME_ACTION_DONE);
+ text.refresh();
+
+ text.performAction(TextView.ACCESSIBILITY_ACTION_IME_ENTER);
+ verify(mockOnEditorActionListener, times(1)).onEditorAction(
+ textView, EditorInfo.IME_ACTION_DONE, null);
+ }
+
private Bundle getTextLocationArguments(AccessibilityNodeInfo info) {
Bundle args = new Bundle();
args.putInt(EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_START_INDEX, 0);