diff options
author | 2025-02-19 15:54:14 -0800 | |
---|---|---|
committer | 2025-02-19 15:54:14 -0800 | |
commit | 73286339c750daba99a74f87f2062a242a2fd06a (patch) | |
tree | 58b6417143f0fa872903c635e4860f6852e3e983 /tests | |
parent | a628f56d387035d12588ac8f694bfd335bf4b767 (diff) | |
parent | 2f4e8343ada40a5c09753f69cfba7e7716f7ced0 (diff) |
Merge "Ensure root tests consider the hide_roots_on_desktop flag" into main
Diffstat (limited to 'tests')
3 files changed, 103 insertions, 14 deletions
diff --git a/tests/functional/com/android/documentsui/ActivityTestJunit4.kt b/tests/functional/com/android/documentsui/ActivityTestJunit4.kt index daab0cdb4..8f1d4f860 100644 --- a/tests/functional/com/android/documentsui/ActivityTestJunit4.kt +++ b/tests/functional/com/android/documentsui/ActivityTestJunit4.kt @@ -47,11 +47,16 @@ import java.util.Objects abstract class ActivityTestJunit4<T : Activity?> { @JvmField var bots: Bots? = null + + @JvmField var device: UiDevice? = null + + @JvmField var context: Context? = null var userId: UserId? = null var automation: UiAutomation? = null + @JvmField var features: Features? = null /** @@ -60,7 +65,12 @@ abstract class ActivityTestJunit4<T : Activity?> { * Override the method if you want to open different root on start. * @return Root that will be opened. Return null if you want to open activity's default root. */ - protected var initialRoot: RootInfo? = null + protected open var initialRoot: RootInfo? = null + + @JvmField + var rootDir0: RootInfo? = null + + @JvmField var rootDir1: RootInfo? = null protected var mResolver: ContentResolver? = null @@ -83,8 +93,9 @@ abstract class ActivityTestJunit4<T : Activity?> { */ @Throws(RemoteException::class) protected fun setupTestingRoots() { - this.initialRoot = mDocsHelper!!.getRoot(StubProvider.ROOT_0_ID) + rootDir0 = mDocsHelper!!.getRoot(StubProvider.ROOT_0_ID) rootDir1 = mDocsHelper!!.getRoot(StubProvider.ROOT_1_ID) + this.initialRoot = rootDir0 } @Throws(Exception::class) @@ -154,7 +165,7 @@ abstract class ActivityTestJunit4<T : Activity?> { } @Throws(RemoteException::class) - protected fun initTestFiles() { + protected open fun initTestFiles() { mDocsHelper!!.createFolder(this.initialRoot, dirName1) mDocsHelper!!.createDocument(this.initialRoot, "text/plain", fileName1) mDocsHelper!!.createDocument(this.initialRoot, "image/png", fileName2) @@ -201,6 +212,7 @@ abstract class ActivityTestJunit4<T : Activity?> { companion object { // Testing files. For custom ones, override initTestFiles(). const val dirName1 = "Dir1" + const val childDir1 = "ChildDir1" const val fileName1 = "file1.log" const val fileName2 = "file12.png" const val fileName3 = "anotherFile0.log" diff --git a/tests/functional/com/android/documentsui/FilesActivityDefaultsUiTest.java b/tests/functional/com/android/documentsui/FilesActivityDefaultsUiTest.java index a33cca37a..2cea176ba 100644 --- a/tests/functional/com/android/documentsui/FilesActivityDefaultsUiTest.java +++ b/tests/functional/com/android/documentsui/FilesActivityDefaultsUiTest.java @@ -18,24 +18,46 @@ package com.android.documentsui; import static com.android.documentsui.StubProvider.ROOT_0_ID; import static com.android.documentsui.StubProvider.ROOT_1_ID; +import static com.android.documentsui.flags.Flags.FLAG_HIDE_ROOTS_ON_DESKTOP; -import android.os.RemoteException; +import android.content.pm.PackageManager; +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; +import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; import com.android.documentsui.base.RootInfo; import com.android.documentsui.files.FilesActivity; import com.android.documentsui.filters.HugeLongTest; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + @LargeTest -public class FilesActivityDefaultsUiTest extends ActivityTest<FilesActivity> { +@RunWith(AndroidJUnit4.class) +public class FilesActivityDefaultsUiTest extends ActivityTestJunit4<FilesActivity> { + + @Rule + public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); + + @Before + public void setUp() throws Exception { + super.setUp(); + } - public FilesActivityDefaultsUiTest() { - super(FilesActivity.class); + @After + public void tearDown() throws Exception { + super.tearDown(); } @Override - protected void initTestFiles() throws RemoteException { + protected void initTestFiles() { // Overriding to init with no items in test roots } @@ -44,6 +66,7 @@ public class FilesActivityDefaultsUiTest extends ActivityTest<FilesActivity> { return null; // test the default, unaffected state of the app. } + @Test @HugeLongTest public void testNavigate_FromEmptyDirectory() throws Exception { device.waitForIdle(); @@ -57,8 +80,10 @@ public class FilesActivityDefaultsUiTest extends ActivityTest<FilesActivity> { device.pressBack(); } + @Test @HugeLongTest - public void testDefaultRoots() throws Exception { + @RequiresFlagsDisabled(FLAG_HIDE_ROOTS_ON_DESKTOP) + public void testDefaultRoots_hideRootsOnDesktopFlagDisabled() throws Exception { device.waitForIdle(); // Should also have Drive, but that requires pre-configuration of devices @@ -71,4 +96,29 @@ public class FilesActivityDefaultsUiTest extends ActivityTest<FilesActivity> { ROOT_0_ID, ROOT_1_ID); } + + @Test + @HugeLongTest + @RequiresFlagsEnabled(FLAG_HIDE_ROOTS_ON_DESKTOP) + public void testDefaultRoots_hideRootsOnDesktopFlagEnabled() throws Exception { + device.waitForIdle(); + + String[] expectedRoots; + if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PC)) { + expectedRoots = new String[]{"Downloads", + ROOT_0_ID, + ROOT_1_ID}; + } else { + expectedRoots = new String[]{ + "Images", + "Videos", + "Audio", + "Downloads", + ROOT_0_ID, + ROOT_1_ID}; + } + // Should also have Drive, but that requires pre-configuration of devices + // We omit for now. + bots.roots.assertRootsPresent(expectedRoots); + } } diff --git a/tests/functional/com/android/documentsui/FilesActivityUiTest.java b/tests/functional/com/android/documentsui/FilesActivityUiTest.java index 697dee6df..1a160c130 100644 --- a/tests/functional/com/android/documentsui/FilesActivityUiTest.java +++ b/tests/functional/com/android/documentsui/FilesActivityUiTest.java @@ -16,29 +16,46 @@ package com.android.documentsui; +import static com.android.documentsui.flags.Flags.FLAG_HIDE_ROOTS_ON_DESKTOP; + import android.app.Instrumentation; import android.net.Uri; import android.os.RemoteException; +import android.platform.test.annotations.RequiresFlagsDisabled; +import android.platform.test.flag.junit.CheckFlagsRule; +import android.platform.test.flag.junit.DeviceFlagsValueProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; import com.android.documentsui.files.FilesActivity; import com.android.documentsui.filters.HugeLongTest; import com.android.documentsui.inspector.InspectorActivity; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + @LargeTest -public class FilesActivityUiTest extends ActivityTest<FilesActivity> { +@RunWith(AndroidJUnit4.class) +public class FilesActivityUiTest extends ActivityTestJunit4<FilesActivity> { - public FilesActivityUiTest() { - super(FilesActivity.class); - } + @Rule + public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); - @Override + @Before public void setUp() throws Exception { super.setUp(); initTestFiles(); } + @After + public void tearDown() throws Exception { + super.tearDown(); + } + @Override public void initTestFiles() throws RemoteException { Uri uri = mDocsHelper.createFolder(rootDir0, dirName1); @@ -55,6 +72,7 @@ public class FilesActivityUiTest extends ActivityTest<FilesActivity> { // Recents is a strange meta root that gathers entries from other providers. // It is special cased in a variety of ways, which is why we just want // to be able to click on it. + @Test public void testClickRecent() throws Exception { bots.roots.openRoot("Recent"); @@ -67,15 +85,19 @@ public class FilesActivityUiTest extends ActivityTest<FilesActivity> { } } + @Test + @RequiresFlagsDisabled(FLAG_HIDE_ROOTS_ON_DESKTOP) public void testRootClick_SetsWindowTitle() throws Exception { bots.roots.openRoot("Images"); bots.main.assertWindowTitle("Images"); } + @Test public void testFilesListed() throws Exception { bots.directory.assertDocumentsPresent("file0.log", "file1.png", "file2.csv"); } + @Test public void testFilesList_LiveUpdate() throws Exception { mDocsHelper.createDocument(rootDir0, "yummers/sandwich", "Ham & Cheese.sandwich"); @@ -84,6 +106,7 @@ public class FilesActivityUiTest extends ActivityTest<FilesActivity> { "file0.log", "file1.png", "file2.csv", "Ham & Cheese.sandwich"); } + @Test public void testNavigate_byBreadcrumb() throws Exception { bots.directory.openDocument(dirName1); bots.directory.waitForDocument(childDir1); // wait for known content @@ -96,6 +119,7 @@ public class FilesActivityUiTest extends ActivityTest<FilesActivity> { bots.directory.waitForDocument(dirName1); } + @Test public void testNavigate_inFixedLayout_whileHasSelection() throws Exception { if (bots.main.inFixedLayout()) { bots.roots.openRoot(rootDir0.title); @@ -107,6 +131,7 @@ public class FilesActivityUiTest extends ActivityTest<FilesActivity> { } } + @Test public void testNavigationToInspector() throws Exception { if(!features.isInspectorEnabled()) { return; @@ -118,7 +143,9 @@ public class FilesActivityUiTest extends ActivityTest<FilesActivity> { monitor.waitForActivityWithTimeout(TIMEOUT); } + @Test @HugeLongTest + @RequiresFlagsDisabled(FLAG_HIDE_ROOTS_ON_DESKTOP) public void testRootChange_UpdatesSortHeader() throws Exception { // switch to separate display modes for two separate roots. Each |