Loading tests/common/com/android/documentsui/bots/SidebarBot.java +39 −3 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading Loading @@ -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, Loading @@ -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); } } } tests/functional/com/android/documentsui/SidebarUiTest.java +1 −2 Original line number Diff line number Diff line Loading @@ -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); Loading Loading
tests/common/com/android/documentsui/bots/SidebarBot.java +39 −3 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading Loading @@ -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, Loading @@ -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); } } }
tests/functional/com/android/documentsui/SidebarUiTest.java +1 −2 Original line number Diff line number Diff line Loading @@ -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); Loading