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

Commit 01d64247 authored by Ben Reich's avatar Ben Reich
Browse files

Fix up error on testPasteIntoFolderOnRoot

The test SidebarUiTest#testPasteIntoFolderOnRoot is currently failing
as the view that appears needs to cover 90% of the screen. As the view
is the right click menu this is not true. This appears to be a bug so
let's create our own click action to remove the constraint and use that
to perform the action instead.

Fix: 406361706
Test: atest com.android.documentsui.SidebarUiTest
Flag: EXEMPT bug fix
Change-Id: Idf15f3fa7de4207e4b0401200bd2bbf13f0a4f64
parent 22bdd224
Loading
Loading
Loading
Loading
+39 −3
Original line number Diff line number Diff line
@@ -17,9 +17,12 @@
package com.android.documentsui.bots;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.swipeLeft;
import static androidx.test.espresso.action.ViewActions.swipeRight;
import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

import android.app.UiAutomation;
import android.content.Context;
@@ -29,6 +32,8 @@ import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject;
import androidx.test.uiautomator.UiObjectNotFoundException;
@@ -39,6 +44,8 @@ import com.android.documentsui.R;

import junit.framework.Assert;

import org.hamcrest.Matcher;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -142,9 +149,10 @@ public class SidebarBot extends Bots.BaseBot {
        assertHasFocus(mRootListId);
    }

    /** Right clicks a root with `label`. */
    public void rightClickRoot(String label) throws UiObjectNotFoundException {
        Rect point = findRoot(label).getVisibleBounds();
    /** Right clicks a root with `label` and then clicks the `menuOption`. */
    public void rightClickRootAndClickMenuOption(String rootLabel, String menuOption)
            throws UiObjectNotFoundException {
        Rect point = findRoot(rootLabel).getVisibleBounds();

        // The RootsFragment listens to right clicks in the GenericMotionListener. This is to allow
        // for a left and right click to be used interchangeably. This means to mock this behaviour,
@@ -171,5 +179,33 @@ public class SidebarBot extends Bots.BaseBot {
                getTestRightClickMotionEvent(
                        MotionEvent.ACTION_UP, point.centerX(), point.centerY());
        mAutomation.injectInputEvent(motionUp, true);

        onView(withText(menuOption)).perform(new ClickAction());
    }

    /**
     * A custom action to remove the constraints on requiring 90% of the views area to be covered.
     */
    static final class ClickAction implements ViewAction {
        private final ViewAction mWrappedClickAction;

        ClickAction() {
            mWrappedClickAction = click();
        }

        @Override
        public Matcher<View> getConstraints() {
            return isEnabled();
        }

        @Override
        public String getDescription() {
            return mWrappedClickAction.getDescription();
        }

        @Override
        public void perform(UiController uiController, View view) {
            mWrappedClickAction.perform(uiController, view);
        }
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -89,8 +89,7 @@ public class SidebarUiTest extends ActivityTestJunit4<FilesActivity> {
        onView(withText("Copy")).perform(click());

        // Right click a root and try to paste the copied file into it.
        bots.roots.rightClickRoot(ROOT_1_ID);
        onView(withText("Paste into folder")).perform(click());
        bots.roots.rightClickRootAndClickMenuOption(ROOT_1_ID, "Paste into folder");

        // Navigate to the root and ensure the file has been copied successfully.
        bots.roots.openRoot(ROOT_1_ID);