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

Commit b765db59 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Adding a method for retching the root node in UiTestAutomationBridge

bug:5974791

Change-Id: I46a8b6a259ba31f27fcd6a71d06dc34efdb4de76
parent 064d2d65
Loading
Loading
Loading
Loading
+27 −1
Original line number Diff line number Diff line
@@ -63,6 +63,8 @@ public class UiTestAutomationBridge {

    private AccessibilityEvent mLastEvent;

    private AccessibilityEvent mLastWindowStateChangeEvent;

    private volatile boolean mWaitingForEventDelivery;

    private volatile boolean mUnprocessedEventAvailable;
@@ -138,12 +140,22 @@ public class UiTestAutomationBridge {
            public void onAccessibilityEvent(AccessibilityEvent event) {
                synchronized (mLock) {
                    while (true) {
                        mLastEvent = AccessibilityEvent.obtain(event);

                        final int eventType = event.getEventType();
                        if (eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
                                || eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
                            if (mLastWindowStateChangeEvent != null) {
                                mLastWindowStateChangeEvent.recycle();
                            }
                            mLastWindowStateChangeEvent = mLastEvent;
                        }

                        if (!mWaitingForEventDelivery) {
                            break;
                        }
                        if (!mUnprocessedEventAvailable) {
                            mUnprocessedEventAvailable = true;
                            mLastEvent = AccessibilityEvent.obtain(event);
                            mLock.notifyAll();
                            break;
                        }
@@ -409,6 +421,20 @@ public class UiTestAutomationBridge {
                accessibilityWindowId, accessibilityNodeId, action);
    }

    /**
     * Gets the root {@link AccessibilityNodeInfo} in the active window.
     *
     * @return The root info.
     */
    public AccessibilityNodeInfo getRootAccessibilityNodeInfoInActiveWindow() {
        synchronized (mLock) {
            if (mLastWindowStateChangeEvent != null) {
                return mLastWindowStateChangeEvent.getSource();
            }
        }
        return null;
    }

    private void ensureValidConnection(int connectionId) {
        if (connectionId == AccessibilityInteractionClient.NO_ID) {
            throw new IllegalStateException("UiAutomationService not connected."
+31 −0
Original line number Diff line number Diff line
@@ -430,4 +430,35 @@ public class InterrogationActivityTest
            }
        }
    }

    @LargeTest
    public void testGetRootAccessibilityNodeInfoInActiveWindow() throws Exception {
        final long startTimeMillis = SystemClock.uptimeMillis();
        try {
            // get the root via the designated API
            AccessibilityNodeInfo fetched = mUiTestAutomationBridge
                    .getRootAccessibilityNodeInfoInActiveWindow();
            assertNotNull(fetched);

            // get the root via traversal
            AccessibilityNodeInfo expected = mUiTestAutomationBridge
                    .findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.root);
            while (true) {
                AccessibilityNodeInfo parent = expected.getParent();
                if (parent == null) {
                    break;
                }
                expected = parent;
            }
            assertNotNull(expected);

            assertEquals("The node with id \"root\" should be the root.", expected, fetched);
        } finally {
            if (DEBUG) {
                final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
                Log.i(LOG_TAG, "testGetRootAccessibilityNodeInfoInActiveWindow: "
                        + elapsedTimeMillis + "ms");
            }
        }
    }
}