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

Commit c28cba10 authored by Felipe Leme's avatar Felipe Leme
Browse files

Added new test for AssistStructure.

Test: atest app.assist.AssistStructureTest#testParcelizationForAutofill_oneSmallView
Bug: 37567426

Change-Id: I169a1605107b1da62f7d7363cd7ffb93554ba4ee
parent 2e8c7670
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -620,7 +620,7 @@ public class AssistStructure implements Parcelable {
        String mIdType;
        String mIdEntry;

        // TODO: once we have more flags, it might be better to store the individual
        // TODO(b/37567426): once we have more flags, it might be better to store the individual
        // fields (viewId and childId) of the field.
        AutofillId mAutofillId;
        @View.AutofillType int mAutofillType = View.AUTOFILL_TYPE_NONE;
@@ -664,7 +664,7 @@ public class AssistStructure implements Parcelable {
        static final int FLAGS_CONTEXT_CLICKABLE = 0x00004000;
        static final int FLAGS_OPAQUE = 0x00008000;

        // TODO: autofill data is made of many fields and ideally we should verify
        // TODO(b/37567426): autofill data is made of many fields and ideally we should verify
        // one-by-one to optimize what's sent over, but there isn't enough flag bits for that, we'd
        // need to create a 'flags2' or 'autoFillFlags' field and add these flags there.
        // So, to keep thinkg simpler for now, let's just use on flag for all of them...
+21 −5
Original line number Diff line number Diff line
@@ -80,6 +80,22 @@ public class AssistStructureTest {
        mActivity = mActivityTestRule.launchActivity(null);
    }

    @Test
    public void testParcelizationForAutofill_oneSmallView() {
        mActivity.addView(newSmallView());

        waitUntilViewsAreLaidOff();

        AssistStructure structure = new AssistStructure(mActivity, FOR_AUTOFILL, NO_FLAGS);

        // Check properties on "original" structure
        assertStructureWithManySmallViews(structure, 1);

        // Check properties on "cloned" structure
        AssistStructure clone = cloneThroughParcel(structure);
        assertStructureWithManySmallViews(clone, 1);
    }

    @Test
    public void testParcelizationForAutofill_manySmallViews() {
        Log.d(TAG, "Adding " + NUMBER_SMALL_VIEWS + " small views");
@@ -93,14 +109,14 @@ public class AssistStructureTest {
        AssistStructure structure = new AssistStructure(mActivity, FOR_AUTOFILL, NO_FLAGS);

        // Check properties on "original" structure
        assertStructureWithManySmallViews(structure);
        assertStructureWithManySmallViews(structure, NUMBER_SMALL_VIEWS);

        // Check properties on "cloned" structure
        AssistStructure clone = cloneThroughParcel(structure);
        assertStructureWithManySmallViews(clone);
        assertStructureWithManySmallViews(clone, NUMBER_SMALL_VIEWS);
    }

    private void assertStructureWithManySmallViews(AssistStructure structure) {
    private void assertStructureWithManySmallViews(AssistStructure structure, int expectedSize) {
        int i = 0;
        try {
            assertPackageName(structure);
@@ -123,12 +139,12 @@ public class AssistStructureTest {
            // Parent
            ViewNode parent = rootView.getChildAt(1);
            assertThat(parent.getClassName()).isEqualTo(LinearLayout.class.getName());
            assertThat(parent.getChildCount()).isEqualTo(NUMBER_SMALL_VIEWS);
            assertThat(parent.getChildCount()).isEqualTo(expectedSize);
            assertThat(parent.getIdEntry()).isEqualTo("parent");
            assertThat(parent.getAutofillId()).isNotNull();

            // Children
            for (i = 0; i < NUMBER_SMALL_VIEWS; i++) {
            for (i = 0; i < expectedSize; i++) {
                ViewNode smallView = parent.getChildAt(i);
                assertSmallView(smallView);
            }