diff options
Diffstat (limited to 'tests')
3 files changed, 84 insertions, 23 deletions
diff --git a/tests/functional/com/android/documentsui/FilesActivityUiTest.java b/tests/functional/com/android/documentsui/FilesActivityUiTest.java index f1f505235..6c2397068 100644 --- a/tests/functional/com/android/documentsui/FilesActivityUiTest.java +++ b/tests/functional/com/android/documentsui/FilesActivityUiTest.java @@ -17,11 +17,14 @@ package com.android.documentsui; import static com.android.documentsui.flags.Flags.FLAG_HIDE_ROOTS_ON_DESKTOP_RO; +import static com.android.documentsui.flags.Flags.FLAG_USE_SEARCH_V2_READ_ONLY; +import static com.android.documentsui.flags.Flags.FLAG_USE_MATERIAL3; import android.app.Instrumentation; import android.net.Uri; import android.os.RemoteException; import android.platform.test.annotations.RequiresFlagsDisabled; +import android.platform.test.annotations.RequiresFlagsEnabled; import android.platform.test.flag.junit.CheckFlagsRule; import android.platform.test.flag.junit.DeviceFlagsValueProvider; @@ -92,13 +95,23 @@ public class FilesActivityUiTest extends ActivityTestJunit4<FilesActivity> { bots.main.assertWindowTitle("Images"); } + private void filesListed() throws Exception { + bots.directory.assertDocumentsPresent("file0.log", "file1.png", "file2.csv"); + } + @Test + @RequiresFlagsDisabled(FLAG_USE_SEARCH_V2_READ_ONLY) public void testFilesListed() throws Exception { - bots.directory.assertDocumentsPresent("file0.log", "file1.png", "file2.csv"); + filesListed(); } @Test - public void testFilesList_LiveUpdate() throws Exception { + @RequiresFlagsEnabled({FLAG_USE_SEARCH_V2_READ_ONLY, FLAG_USE_MATERIAL3}) + public void testFilesListed_searchV2() throws Exception { + filesListed(); + } + + private void filesListed_LiveUpdates() throws Exception { mDocsHelper.createDocument(rootDir0, "yummers/sandwich", "Ham & Cheese.sandwich"); bots.directory.waitForDocument("Ham & Cheese.sandwich"); @@ -107,6 +120,18 @@ public class FilesActivityUiTest extends ActivityTestJunit4<FilesActivity> { } @Test + @RequiresFlagsDisabled(FLAG_USE_SEARCH_V2_READ_ONLY) + public void testFilesList_LiveUpdate() throws Exception { + filesListed_LiveUpdates(); + } + + @Test + @RequiresFlagsEnabled({FLAG_USE_SEARCH_V2_READ_ONLY, FLAG_USE_MATERIAL3}) + public void testFilesList_LiveUpdate_searchV2() throws Exception { + filesListed_LiveUpdates(); + } + + @Test public void testNavigate_byBreadcrumb() throws Exception { bots.directory.openDocument(dirName1); bots.directory.waitForDocument(childDir1); // wait for known content diff --git a/tests/functional/com/android/documentsui/TrampolineActivityTest.kt b/tests/functional/com/android/documentsui/TrampolineActivityTest.kt index 6bf0975ad..10b31d1eb 100644 --- a/tests/functional/com/android/documentsui/TrampolineActivityTest.kt +++ b/tests/functional/com/android/documentsui/TrampolineActivityTest.kt @@ -15,10 +15,8 @@ */ package com.android.documentsui -import android.app.Instrumentation import android.content.Intent import android.content.Intent.ACTION_GET_CONTENT -import android.content.IntentFilter import android.os.Build.VERSION_CODES import android.platform.test.annotations.RequiresFlagsEnabled import android.platform.test.flag.junit.CheckFlagsRule @@ -34,7 +32,6 @@ import com.android.documentsui.flags.Flags.FLAG_REDIRECT_GET_CONTENT_RO import com.android.documentsui.picker.TrampolineActivity import java.util.Optional import java.util.regex.Pattern -import org.junit.After import org.junit.Assert.assertNotNull import org.junit.Before import org.junit.BeforeClass @@ -56,25 +53,28 @@ class TrampolineActivityTest() { const val UI_TIMEOUT = 5000L val PHOTOPICKER_PACKAGE_REGEX: Pattern = Pattern.compile(".*(photopicker|media\\.module).*") val DOCUMENTSUI_PACKAGE_REGEX: Pattern = Pattern.compile(".*documentsui.*") + val STACK_LIST_REGEX: Pattern = Pattern.compile( + "taskId=(?<taskId>[0-9]+):(.+?)(photopicker|media\\.module|documentsui)", + Pattern.MULTILINE + ) private lateinit var device: UiDevice - private lateinit var monitor: Instrumentation.ActivityMonitor + fun removePhotopickerAndDocumentsUITasks() { + // Get the current list of tasks that are visible. + val result = device.executeShellCommand("am stack list") + + // Identify any that are from DocumentsUI or Photopicker and close them. + val matcher = STACK_LIST_REGEX.matcher(result) + while (matcher.find()) { + device.executeShellCommand("am stack remove ${matcher.group("taskId")}") + } + } @BeforeClass @JvmStatic fun setUp() { device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - - // Monitor to wait for the activity that starts with the `ACTION_GET_CONTENT` intent. - val intentFilter = IntentFilter().apply { addAction(ACTION_GET_CONTENT) } - monitor = - Instrumentation.ActivityMonitor( - intentFilter, - null, // Expected result from startActivityForResult. - true, // Whether to block until activity started or not. - ) - InstrumentationRegistry.getInstrumentation().addMonitor(monitor) } } @@ -157,24 +157,20 @@ class TrampolineActivityTest() { @Before fun setUp() { + removePhotopickerAndDocumentsUITasks() + val context = InstrumentationRegistry.getInstrumentation().targetContext val intent = Intent(ACTION_GET_CONTENT) intent.setClass(context, TrampolineActivity::class.java) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) intent.setType(testData.mimeType) if (testData.extraMimeTypes.isPresent) { - testData.extraMimeTypes.get() - .forEach { intent.putExtra(Intent.EXTRA_MIME_TYPES, it) } + intent.putExtra(Intent.EXTRA_MIME_TYPES, testData.extraMimeTypes.get()) } context.startActivity(intent) } - @After - fun tearDown() { - monitor.waitForActivityWithTimeout(UI_TIMEOUT)?.finish() - } - @Test fun testCorrectAppIsLaunched() { val bySelector = when (testData.expectedApp) { @@ -208,6 +204,11 @@ class TrampolineActivityTest() { @get:Rule val checkFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule() + @Before + fun setUp() { + removePhotopickerAndDocumentsUITasks() + } + @Test fun testReferredGetContentFromPhotopickerShouldNotRedirectBack() { val context = InstrumentationRegistry.getInstrumentation().targetContext diff --git a/tests/unit/com/android/documentsui/queries/SearchChipViewManagerTest.java b/tests/unit/com/android/documentsui/queries/SearchChipViewManagerTest.java index 6d20447dd..02e24a329 100644 --- a/tests/unit/com/android/documentsui/queries/SearchChipViewManagerTest.java +++ b/tests/unit/com/android/documentsui/queries/SearchChipViewManagerTest.java @@ -18,6 +18,7 @@ package com.android.documentsui.queries; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.spy; @@ -35,6 +36,9 @@ import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.provider.DocumentsContract; import android.view.View; import android.view.ViewGroup; +import android.view.ViewParent; +import android.widget.FrameLayout; +import android.widget.HorizontalScrollView; import android.widget.LinearLayout; import androidx.test.ext.junit.runners.AndroidJUnit4; @@ -235,6 +239,37 @@ public final class SearchChipViewManagerTest { assertThat(View.VISIBLE).isEqualTo(mirror.getVisibility()); } + @Test + public void testChipChecked_resetScroll() { + // Mock chip group's parent chain according to search_chip_row.xml. + FrameLayout parent = spy(new FrameLayout(mContext)); + HorizontalScrollView grandparent = spy(new HorizontalScrollView(mContext)); + parent.addView(mChipGroup); + grandparent.addView(parent); + // Verify that getParent().getParent() returns the HorizontalScrollView mock. + ViewParent result = mChipGroup.getParent().getParent(); + assertEquals(grandparent, result); + + mSearchChipViewManager.initChipSets( + new String[] {"image/*", "audio/*", "video/*", "text/*"}); + mSearchChipViewManager.updateChips(new String[] {"*/*"}); + + // Manually set HorizontalScrollView's scrollX to something larger than 0. + grandparent.scrollTo(100, 0); + assertTrue(grandparent.getScaleX() > 0); + + assertEquals(6, mChipGroup.getChildCount()); + Chip lastChip = (Chip) mChipGroup.getChildAt(5); + + // chip.setChecked will trigger reorder animation, which needs to be run inside + // the looper thread. + InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { + // Check last chip will move it to the first child and reset scroll view. + lastChip.setChecked(true); + assertEquals(0, grandparent.getScrollX()); + }); + } + private static Set<SearchChipData> getFakeSearchChipDataList() { final Set<SearchChipData> chipDataList = new HashSet<>(); chipDataList.add(new SearchChipData(CHIP_TYPE, 0 /* titleRes */, TEST_MIME_TYPES)); |