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

Commit c220ad62 authored by Phil Weaver's avatar Phil Weaver
Browse files

Update checks that AccessibilityNodeInfo is tested

We had a tests that detected when we added fields, but
there were existing fields that weren't tested, and a
couple that weren't even parceled. Updating the test
to make things more explicity, now that I've fixed
the cts test.

Also adding a similar check for boolean properties,
which were similarly lacking in coverage.

Bug: 77928402
Test: atest accessibility.AccessibilityNodeInfoTest
Change-Id: Ie8c52087343c3ccd2b8c86e5d7b9333b9294b138
parent 965f6aa5
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.view.accessibility;

import static junit.framework.Assert.assertEquals;

import static org.hamcrest.Matchers.emptyCollectionOf;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
@@ -33,6 +35,8 @@ import com.android.internal.util.CollectionUtils;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;

@LargeTest
@@ -41,13 +45,19 @@ public class AccessibilityNodeInfoTest {
    // The number of fields tested in the corresponding CTS AccessibilityNodeInfoTest:
    // See fullyPopulateAccessibilityNodeInfo, assertEqualsAccessibilityNodeInfo,
    // and assertAccessibilityNodeInfoCleared in that class.
    private static final int NUM_MARSHALLED_PROPERTIES = 35;
    private static final int NUM_MARSHALLED_PROPERTIES = 33;

    /**
     * The number of properties that are purposely not marshalled
     * mOriginalText - Used when resolving clickable spans; intentionally not parceled
     * mSealed - Unparceling sets the sealed bit
     * mConnectionId - Set after unparceling. Actually is parceled, but probably shouldn't be.
     */
    private static final int NUM_NONMARSHALLED_PROPERTIES = 1;
    private static final int NUM_NONMARSHALLED_PROPERTIES = 3;

    // The number of flags held in boolean properties. Their values should also be double-checked
    // in the methods above.
    private static final int NUM_BOOLEAN_PROPERTIES = 22;

    @Test
    public void testStandardActions_serializationFlagIsValid() {
@@ -130,4 +140,19 @@ public class AccessibilityNodeInfoTest {
        AccessibilityEventTest.assertNoNewNonStaticFieldsAdded(AccessibilityNodeInfo.class,
                NUM_MARSHALLED_PROPERTIES + NUM_NONMARSHALLED_PROPERTIES);
    }

    @Test
    public void updateCtsToTestNewBooleanProperties() {
        int booleanPropertiesCount = 0;

        for (Field field : AccessibilityNodeInfo.class.getDeclaredFields()) {
            if (((field.getModifiers() & Modifier.STATIC) != 0)
                    && (field.getName().contains("BOOLEAN_PROPERTY"))) {
                booleanPropertiesCount++;
            }
        }

        assertEquals("New boolean properties. Make sure you're testing them in CTS",
                NUM_BOOLEAN_PROPERTIES, booleanPropertiesCount);
    }
}