summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
author Ben Reich <benreich@google.com> 2025-02-14 13:50:03 +1100
committer Ben Reich <benreich@google.com> 2025-02-24 17:13:33 +1100
commit0462a2886768777846561c9d0e8305d412661533 (patch)
tree352ff43422744ed98266b4f24cf212b941363ffc /tests
parent315018fac100f9043183fd61f001f60afd79ff17 (diff)
Move the selection menu from the ActionBar to NavigationView
In the >600dp layout, the MaterialToolbar has been moved to be adjacent to the sidebar. Previously the ActionBar was used to replace the existing toolbar, unfortunately on the new layout this doesn't work as it spans the full width. To get around this (and maintain compatibility when the flag is on or off) we instead inflate the activity menu OR the action mode menu depending on whether there is a selection. This is a temporary measure to not have to refactor the click handlers too much. In the final product the ActionModeController will be removed and the click handlers consolidated into a single place. Bug: 383669583 Test: atest DocumentsUIGoogleTests Flag: com.android.documentsui.flags.use_material3 Change-Id: Ida4675dafbc2096c986067ba4fbe5a695a8e243b
Diffstat (limited to 'tests')
-rw-r--r--tests/common/com/android/documentsui/bots/UiBot.java52
-rw-r--r--tests/unit/com/android/documentsui/files/ActionHandlerTest.java25
2 files changed, 47 insertions, 30 deletions
diff --git a/tests/common/com/android/documentsui/bots/UiBot.java b/tests/common/com/android/documentsui/bots/UiBot.java
index f30cb93b8..4ec75bdc6 100644
--- a/tests/common/com/android/documentsui/bots/UiBot.java
+++ b/tests/common/com/android/documentsui/bots/UiBot.java
@@ -25,6 +25,8 @@ import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
+import static com.android.documentsui.flags.Flags.useMaterial3;
+
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
@@ -68,37 +70,48 @@ import java.util.List;
*/
public class UiBot extends Bots.BaseBot {
- public static String targetPackageName;
-
@SuppressWarnings("unchecked")
private static final Matcher<View> TOOLBAR = allOf(
isAssignableFrom(Toolbar.class),
withId(R.id.toolbar));
-
@SuppressWarnings("unchecked")
private static final Matcher<View> ACTIONBAR = allOf(
withClassName(endsWith("ActionBarContextView")));
-
@SuppressWarnings("unchecked")
private static final Matcher<View> TEXT_ENTRY = allOf(
withClassName(endsWith("EditText")));
-
@SuppressWarnings("unchecked")
private static final Matcher<View> TOOLBAR_OVERFLOW = allOf(
withClassName(endsWith("OverflowMenuButton")),
ViewMatchers.isDescendantOfA(TOOLBAR));
-
@SuppressWarnings("unchecked")
private static final Matcher<View> ACTIONBAR_OVERFLOW = allOf(
withClassName(endsWith("OverflowMenuButton")),
ViewMatchers.isDescendantOfA(ACTIONBAR));
+ public static String targetPackageName;
+
public UiBot(UiDevice device, Context context, int timeout) {
super(device, context, timeout);
targetPackageName =
InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName();
}
+ private static Matcher<Object> withToolbarTitle(final Matcher<CharSequence> textMatcher) {
+ return new BoundedMatcher<Object, Toolbar>(Toolbar.class) {
+ @Override
+ public boolean matchesSafely(Toolbar toolbar) {
+ return textMatcher.matches(toolbar.getTitle());
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("with toolbar title: ");
+ textMatcher.describeTo(description);
+ }
+ };
+ }
+
public void assertWindowTitle(String expected) {
onView(TOOLBAR)
.check(matches(withToolbarTitle(is(expected))));
@@ -198,7 +211,11 @@ public class UiBot extends Bots.BaseBot {
}
public void clickActionbarOverflowItem(String label) {
- onView(ACTIONBAR_OVERFLOW).perform(click());
+ if (useMaterial3()) {
+ onView(TOOLBAR_OVERFLOW).perform(click());
+ } else {
+ onView(ACTIONBAR_OVERFLOW).perform(click());
+ }
// Click the item by label, since Espresso doesn't support lookup by id on overflow.
onView(withText(label)).perform(click());
}
@@ -214,9 +231,10 @@ public class UiBot extends Bots.BaseBot {
}
public boolean waitForActionModeBarToAppear() {
+ String actionModeId = useMaterial3() ? "toolbar" : "action_mode_bar";
UiObject2 bar =
- mDevice.wait(Until.findObject(
- By.res(mTargetPackage + ":id/action_mode_bar")), mTimeout);
+ mDevice.wait(
+ Until.findObject(By.res(mTargetPackage + ":id/" + actionModeId)), mTimeout);
return (bar != null);
}
@@ -307,20 +325,4 @@ public class UiBot extends Bots.BaseBot {
// TODO: use the system string ? android.R.string.action_menu_overflow_description
return mDevice.findObject(selector);
}
-
- private static Matcher<Object> withToolbarTitle(
- final Matcher<CharSequence> textMatcher) {
- return new BoundedMatcher<Object, Toolbar>(Toolbar.class) {
- @Override
- public boolean matchesSafely(Toolbar toolbar) {
- return textMatcher.matches(toolbar.getTitle());
- }
-
- @Override
- public void describeTo(Description description) {
- description.appendText("with toolbar title: ");
- textMatcher.describeTo(description);
- }
- };
- }
}
diff --git a/tests/unit/com/android/documentsui/files/ActionHandlerTest.java b/tests/unit/com/android/documentsui/files/ActionHandlerTest.java
index 3d9cba6bf..01dfa1c76 100644
--- a/tests/unit/com/android/documentsui/files/ActionHandlerTest.java
+++ b/tests/unit/com/android/documentsui/files/ActionHandlerTest.java
@@ -16,6 +16,7 @@
package com.android.documentsui.files;
+import static com.android.documentsui.flags.Flags.useMaterial3;
import static com.android.documentsui.testing.IntentAsserts.assertHasAction;
import static com.android.documentsui.testing.IntentAsserts.assertHasData;
import static com.android.documentsui.testing.IntentAsserts.assertHasExtra;
@@ -31,6 +32,8 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import android.app.Activity;
import android.app.DownloadManager;
@@ -89,6 +92,8 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.Arrays;
@@ -108,6 +113,7 @@ public class ActionHandlerTest {
private TestFeatures mFeatures;
private TestConfigStore mTestConfigStore;
private boolean refreshAnswer = false;
+ @Mock private Runnable mMockCloseSelectionBar;
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
@@ -126,6 +132,7 @@ public class ActionHandlerTest {
@Before
public void setUp() {
+ MockitoAnnotations.initMocks(this);
mFeatures = new TestFeatures();
mEnv = TestEnv.create(mFeatures);
mActivity = TestActivity.create(mEnv);
@@ -152,6 +159,14 @@ public class ActionHandlerTest {
mEnv.selectDocument(TestEnv.FILE_GIF);
}
+ private void assertSelectionContainerClosed() {
+ if (useMaterial3()) {
+ verify(mMockCloseSelectionBar, times(1)).run();
+ } else {
+ assertTrue(mActionModeAddons.finishActionModeCalled);
+ }
+ }
+
@Test
public void testOpenSelectedInNewWindow() {
mHandler.openSelectedInNewWindow();
@@ -195,7 +210,7 @@ public class ActionHandlerTest {
@Test
public void testSpringOpenDirectory() {
mHandler.springOpenDirectory(TestEnv.FOLDER_0);
- assertTrue(mActionModeAddons.finishActionModeCalled);
+ assertSelectionContainerClosed();
assertEquals(TestEnv.FOLDER_0, mEnv.state.stack.peek());
}
@@ -250,7 +265,7 @@ public class ActionHandlerTest {
mHandler.deleteSelectedDocuments(docs, mEnv.state.stack.peek());
mActivity.startService.assertCalled();
- assertTrue(mActionModeAddons.finishActionModeCalled);
+ assertSelectionContainerClosed();
}
@Test
@@ -845,10 +860,10 @@ public class ActionHandlerTest {
mEnv.searchViewManager,
mEnv::lookupExecutor,
mActionModeAddons,
+ mMockCloseSelectionBar,
mClipper,
- null, // clip storage, not utilized unless we venture into *jumbo* clip territory.
+ null, // clip storage, not utilized unless we venture into *jumbo* clip territory.
mDragAndDropManager,
- mEnv.injector
- );
+ mEnv.injector);
}
}