diff options
| author | 2023-04-20 12:56:37 -0700 | |
|---|---|---|
| committer | 2023-04-20 12:58:42 -0700 | |
| commit | 48e2fb5a89691a6bc43d578f42a2df090bcf756c (patch) | |
| tree | d3a5801fb7d9209943f7fb3aa8a91babc7e6b70c | |
| parent | 9188aa60688692d205e85a2131c396e8669f0f4e (diff) | |
Fix flakiness in AccessibilityShortcutChooserActivityTest.
Use more precise waiting based on expected view changes instead of
waiting for idle sync.
Also includes a retry for the double-click action. I haven't yet
figured out why this is flaky, but at least the retry seems to address
it for now.
Bug: 277331877
Test: AccessibilityShortcutChooserActivityTest,
using atest and go/abtd to run many iterations
Change-Id: I9ad5549947941de144e8bbdec7ebe387d4161976
| -rw-r--r-- | core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutChooserActivityTest.java | 96 |
1 files changed, 50 insertions, 46 deletions
diff --git a/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutChooserActivityTest.java b/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutChooserActivityTest.java index 03d366e6e552..57a1376a6cd1 100644 --- a/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutChooserActivityTest.java +++ b/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutChooserActivityTest.java @@ -46,6 +46,10 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.os.Handler; +import android.support.test.uiautomator.By; +import android.support.test.uiautomator.UiDevice; +import android.support.test.uiautomator.UiObject2; +import android.support.test.uiautomator.Until; import android.view.accessibility.AccessibilityManager; import android.view.accessibility.IAccessibilityManager; @@ -57,6 +61,7 @@ import androidx.test.runner.AndroidJUnit4; import com.android.internal.R; import com.android.internal.accessibility.dialog.AccessibilityShortcutChooserActivity; +import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -73,8 +78,14 @@ import java.util.Collections; @RunWith(AndroidJUnit4.class) public class AccessibilityShortcutChooserActivityTest { private static final String ONE_HANDED_MODE = "One-Handed mode"; + private static final String DENY_LABEL = "Deny"; + private static final String EDIT_LABEL = "Edit shortcuts"; + private static final String LIST_TITLE_LABEL = "Choose features to use"; private static final String TEST_LABEL = "TEST_LABEL"; private static final ComponentName TEST_COMPONENT_NAME = new ComponentName("package", "class"); + private static final long UI_TIMEOUT_MS = 1000; + private UiDevice mDevice; + private ActivityScenario<TestAccessibilityShortcutChooserActivity> mScenario; private TestAccessibilityShortcutChooserActivity mActivity; @Rule @@ -92,6 +103,8 @@ public class AccessibilityShortcutChooserActivityTest { @Before public void setUp() throws Exception { + mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + mDevice.wakeUp(); when(mAccessibilityServiceInfo.getResolveInfo()).thenReturn(mResolveInfo); mResolveInfo.serviceInfo = mServiceInfo; mServiceInfo.applicationInfo = mApplicationInfo; @@ -102,27 +115,36 @@ public class AccessibilityShortcutChooserActivityTest { when(mAccessibilityManagerService.isAccessibilityTargetAllowed( anyString(), anyInt(), anyInt())).thenReturn(true); TestAccessibilityShortcutChooserActivity.setupForTesting(mAccessibilityManagerService); + mScenario = ActivityScenario.launch(TestAccessibilityShortcutChooserActivity.class); + mScenario.onActivity(activity -> mActivity = activity); + mScenario.moveToState(Lifecycle.State.CREATED); + mScenario.moveToState(Lifecycle.State.STARTED); + mScenario.moveToState(Lifecycle.State.RESUMED); + InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + } + + @After + public void cleanUp() { + mScenario.moveToState(Lifecycle.State.DESTROYED); } @Test public void doubleClickTestServiceAndClickDenyButton_permissionDialogDoesNotExist() { - final ActivityScenario<TestAccessibilityShortcutChooserActivity> scenario = - ActivityScenario.launch(TestAccessibilityShortcutChooserActivity.class); - scenario.moveToState(Lifecycle.State.CREATED); - scenario.moveToState(Lifecycle.State.STARTED); - scenario.moveToState(Lifecycle.State.RESUMED); - - onView(withText(R.string.accessibility_select_shortcut_menu_title)).inRoot( - isDialog()).check(matches(isDisplayed())); - onView(withText(R.string.edit_accessibility_shortcut_menu_button)).perform(click()); - onView(withText(TEST_LABEL)).perform(scrollTo(), doubleClick()); - onView(withId(R.id.accessibility_permission_enable_deny_button)).perform(scrollTo(), - click()); + openShortcutsList(); + + // Performing the double-click is flaky so retry if needed. + for (int attempt = 1; attempt <= 2; attempt++) { + onView(withText(TEST_LABEL)).perform(scrollTo(), doubleClick()); + if (mDevice.wait(Until.hasObject(By.text(DENY_LABEL)), UI_TIMEOUT_MS)) { + break; + } + } + + onView(withText(DENY_LABEL)).perform(scrollTo(), click()); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); onView(withId(R.id.accessibility_permissionDialog_title)).inRoot(isDialog()).check( doesNotExist()); - scenario.moveToState(Lifecycle.State.DESTROYED); } @Test @@ -130,60 +152,42 @@ public class AccessibilityShortcutChooserActivityTest { throws Exception { when(mAccessibilityManagerService.isAccessibilityTargetAllowed( eq(TEST_COMPONENT_NAME.getPackageName()), anyInt(), anyInt())).thenReturn(false); - final ActivityScenario<TestAccessibilityShortcutChooserActivity> scenario = - ActivityScenario.launch(TestAccessibilityShortcutChooserActivity.class); - scenario.onActivity(activity -> mActivity = activity); - scenario.moveToState(Lifecycle.State.CREATED); - scenario.moveToState(Lifecycle.State.STARTED); - scenario.moveToState(Lifecycle.State.RESUMED); - - onView(withText(R.string.accessibility_select_shortcut_menu_title)).inRoot( - isDialog()).check(matches(isDisplayed())); - onView(withText(R.string.edit_accessibility_shortcut_menu_button)).perform(click()); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + openShortcutsList(); onView(withText(TEST_LABEL)).perform(scrollTo(), click()); + verify(mAccessibilityManagerService).sendRestrictedDialogIntent( eq(TEST_COMPONENT_NAME.getPackageName()), anyInt(), anyInt()); - scenario.moveToState(Lifecycle.State.DESTROYED); } @Test public void popEditShortcutMenuList_oneHandedModeEnabled_shouldBeInListView() { TestUtils.setOneHandedModeEnabled(this, /* enabled= */ true); - final ActivityScenario<TestAccessibilityShortcutChooserActivity> scenario = - ActivityScenario.launch(TestAccessibilityShortcutChooserActivity.class); - scenario.moveToState(Lifecycle.State.CREATED); - scenario.moveToState(Lifecycle.State.STARTED); - scenario.moveToState(Lifecycle.State.RESUMED); - - onView(withText(R.string.accessibility_select_shortcut_menu_title)).inRoot( - isDialog()).check(matches(isDisplayed())); - onView(withText(R.string.edit_accessibility_shortcut_menu_button)).perform(click()); + openShortcutsList(); + onView(allOf(withClassName(endsWith("ListView")), isDisplayed())).perform(swipeUp()); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + mDevice.wait(Until.hasObject(By.text(ONE_HANDED_MODE)), UI_TIMEOUT_MS); onView(withText(ONE_HANDED_MODE)).inRoot(isDialog()).check(matches(isDisplayed())); - scenario.moveToState(Lifecycle.State.DESTROYED); } @Test public void popEditShortcutMenuList_oneHandedModeDisabled_shouldNotBeInListView() { TestUtils.setOneHandedModeEnabled(this, /* enabled= */ false); - final ActivityScenario<TestAccessibilityShortcutChooserActivity> scenario = - ActivityScenario.launch(TestAccessibilityShortcutChooserActivity.class); - scenario.moveToState(Lifecycle.State.CREATED); - scenario.moveToState(Lifecycle.State.STARTED); - scenario.moveToState(Lifecycle.State.RESUMED); - - onView(withText(R.string.accessibility_select_shortcut_menu_title)).inRoot( - isDialog()).check(matches(isDisplayed())); - onView(withText(R.string.edit_accessibility_shortcut_menu_button)).perform(click()); + openShortcutsList(); + onView(allOf(withClassName(endsWith("ListView")), isDisplayed())).perform(swipeUp()); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); onView(withText(ONE_HANDED_MODE)).inRoot(isDialog()).check(doesNotExist()); - scenario.moveToState(Lifecycle.State.DESTROYED); + } + + private void openShortcutsList() { + UiObject2 editButton = mDevice.findObject(By.text(EDIT_LABEL)); + if (editButton != null) { + editButton.click(); + } + mDevice.wait(Until.hasObject(By.textStartsWith(LIST_TITLE_LABEL)), UI_TIMEOUT_MS); } /** |