| @@ -725,6 +725,54 @@ class NativeNavigationTest { |
| 725 | 725 | } |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | + @Test |
| 729 | + fun nativeTestIdsRemainQueryableWithoutReplacingVisibleLabels() { |
| 730 | + val automation = instrumentation.uiAutomation |
| 731 | + val previousServiceInfo = automation.serviceInfo |
| 732 | + automation.serviceInfo = automation.serviceInfo.apply { |
| 733 | + flags = flags or android.accessibilityservice.AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS |
| 734 | + } |
| 735 | + val activity = instrumentation.startActivitySync( |
| 736 | + Intent(instrumentation.targetContext, MainActivity::class.java) |
| 737 | + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) |
| 738 | + ) as MainActivity |
| 739 | + fun matching(root: AccessibilityNodeInfo, id: String): AccessibilityNodeInfo? { |
| 740 | + if (root.viewIdResourceName == id) return root |
| 741 | + for (index in 0 until root.childCount) { |
| 742 | + val child = root.getChild(index) ?: continue |
| 743 | + matching(child, id)?.let { return it } |
| 744 | + } |
| 745 | + return null |
| 746 | + } |
| 747 | + fun node(id: String): AccessibilityNodeInfo { |
| 748 | + repeat(100) { |
| 749 | + |
| 750 | + |
| 751 | + |
| 752 | + automation.rootInActiveWindow?.let { matching(it, id) }?.let { return it } |
| 753 | + SystemClock.sleep(100) |
| 754 | + } |
| 755 | + throw AssertionError("The native accessibility tree did not expose STX testID $id") |
| 756 | + } |
| 757 | + try { |
| 758 | + awaitView(activity, "home-title") |
| 759 | + val title = node("home-title") |
| 760 | + assertEquals("Home", title.text.toString()) |
| 761 | + assertEquals("The test identity must not become a spoken label", null, title.contentDescription) |
| 762 | + val toggle = node("toggle-safe-area") |
| 763 | + assertEquals("Toggle safe edges", toggle.text.toString()) |
| 764 | + assertTrue("The identified native button did not accept its accessibility click", |
| 765 | + toggle.performAction(AccessibilityNodeInfo.ACTION_CLICK)) |
| 766 | + awaitText(activity, "safe-area-status", "Safe edges: bottom") |
| 767 | + assertEquals("The identity disappeared after native reconciliation", "Toggle safe edges", |
| 768 | + node("toggle-safe-area").text.toString()) |
| 769 | + } finally { |
| 770 | + instrumentation.runOnMainSync { activity.finishAndRemoveTask() } |
| 771 | + automation.serviceInfo = previousServiceInfo |
| 772 | + instrumentation.waitForIdleSync() |
| 773 | + } |
| 774 | + } |
| 775 | + |
| 728 | 776 | @Test |
| 729 | 777 | fun outgoingTabTapWinsOverSettlingSwipe() { |
| 730 | 778 | assertTabTapInterruptsSettlingSwipe(0, "navigation-home-state", "Home state: Ada/1") |