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

Commit 4e1be03d authored by Wenbo Jie's avatar Wenbo Jie
Browse files

[DocsUI M3] Remove the tab cycle UI test

When the first tab is pressed the focus should go to the side
navigation bar ideally but it can not be guaranteed due to the
existence of the grey overlay on the main coordinator_layout,
which causes the flakiness. Several efforts have been tried to
de-flake it, e.g. focus on the coordinator_layout before pressing
tab, or focus on the navigation root list first before pressing the
tab, unfortunately they don't actually help: for one it's still
flaky after these mitigations, for two, it now skips the first
tab press and only tests the tab cycle in navigation roots (the
test only covers 2 roots) which doesn't cover much.
Given all these reason, remove the test and we will revisit the test
after removing the grey overlay in b/417871278.

Bug: 432508904
Test: EXEMPT remove test
Flag: com.android.documentsui.flags.use_material3
Change-Id: I464ae7fd63d762d55de4bab859e9ea8881445ee4
parent 49afeb9e
Loading
Loading
Loading
Loading
+0 −24
Original line number Diff line number Diff line
@@ -37,8 +37,6 @@ import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.IdRes;
import androidx.recyclerview.widget.RecyclerView;
import androidx.test.espresso.ViewInteraction;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject;
@@ -247,26 +245,4 @@ public class SidebarBot extends Bots.BaseBot {
        assertNotNull("Context menu item " + menuOption + " not found", menuItem);
        menuItem.perform(new RelaxedClickAction());
    }

    /**
     * Check if the specified position inside the root lists has focus or not.
     * @param containerId the root list container id, the root list must be a recycler view.
     * @param position the item position in
     */
    public void assertPositionFocused(@IdRes int containerId, int position) {
        onView(allOf(withId(R.id.roots_list), isDescendantOfA(withId(containerId)))).check(
                (view, noViewFoundException) -> {
                    if (noViewFoundException != null) {
                        throw noViewFoundException;
                    }
                    RecyclerView recyclerView = (RecyclerView) view;
                    RecyclerView.ViewHolder viewHolder =
                            recyclerView.findViewHolderForAdapterPosition(position);
                    if (!viewHolder.itemView.isFocused()) {
                        throw new AssertionError(
                                "Expect item at position " + position
                                        + " to be focused but it's not.");
                    }
                });
    }
}
+0 −46
Original line number Diff line number Diff line
@@ -16,19 +16,11 @@

package com.android.documentsui;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.hasFocus;
import static androidx.test.espresso.matcher.ViewMatchers.withId;

import static com.android.documentsui.StubProvider.ROOT_0_ID;
import static com.android.documentsui.flags.Flags.FLAG_USE_MATERIAL3;
import static com.android.documentsui.util.Material3Config.getRes;

import android.platform.test.annotations.EnableFlags;
import android.view.KeyEvent;

import androidx.annotation.IdRes;
import androidx.test.filters.LargeTest;

import com.android.documentsui.base.RootInfo;
@@ -111,42 +103,4 @@ public class KeyboardNavigationUiTest extends ActivityTestJunit4<FilesActivity>
            bots.roots.assertHasFocus();
        }
    }

    @Test
    @EnableFlags({FLAG_USE_MATERIAL3})
    public void testKeyboard_tabCycleInRootsList() throws Exception {
        // Focus the root CoordinatorLayout explicitly before the test to avoid the first
        // Tab press accidentally focus on the root CoordinatorLayout.
        // TODO(b/417871278): remove this after removing the grey overlay.
        onView(withId(R.id.coordinator_layout)).check((view, noViewFoundException) -> {
            if (view != null) {
                view.post(view::requestFocus);
            }
        }).check(matches(hasFocus()));

        // We want to explicitly check the focus inside the nav rail root list in nav rail layout,
        // otherwise, check it in the drawer (container_roots).
        final @IdRes int containerId =
                bots.main.inNavRailLayout()
                        ? getRes(R.id.nav_rail_container_roots)
                        : getRes(R.id.container_roots);

        if (bots.main.inDrawerLayout()) {
            // If drawer layout is used, we need to open drawer first to show all the nav roots.
            bots.roots.openDrawer();
        } else if (bots.main.inNavRailLayout()) {
            // If nav rail layout is used, the first Tab will move the focus to the burger menu
            // inside the nav rail root list.
            bots.keyboard.pressKey(KeyEvent.KEYCODE_TAB);
            onView(withId(R.id.nav_rail_burger_menu)).check(matches(hasFocus()));
        }

        // Only check the first 2 items here because we don't want to deal with the divider item
        // (which is also a child of the root list), the first 2 items are guaranteed not to be
        // divider items.
        for (int i = 0; i <= 1; i++) {
            bots.keyboard.pressKey(KeyEvent.KEYCODE_TAB);
            bots.roots.assertPositionFocused(containerId, i);
        }
    }
}