summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
author Cassy Chun-Crogan <cassycc@google.com> 2025-02-19 01:36:45 +0000
committer Cassy Chun-Crogan <cassycc@google.com> 2025-02-19 22:40:48 +0000
commit2f4e8343ada40a5c09753f69cfba7e7716f7ced0 (patch)
tree748ebbc6d73ab617c3022be66cc3a3e204a93ac2 /tests
parentddabc5d71cc47ce611122457fbb12cdcae0778e9 (diff)
Ensure root tests consider the hide_roots_on_desktop flag
Tests in FilesActivityDefaultsUiTest and FilesActivityUiTest that should only be run when the hide_roots_on_desktop flag is disabled are failing when it is enabled. Fix this by using @RequiresFlagsDisabled to skip these tests when the flag is enabled. Also add complement tests for behaviour when the flag is enabled with @RequiresFlagsEnabled where appropriate. Also use ActivityTestJunit4 instead of ActivityTest for the tests to ensure that @RequiresFlagsDisabled works. See ag/31583362 for more details. Bug: 397256734 Test: atest FilesActivityDefaultsUiTest Test: atest FilesActivityUiTest Flag: EXEMPT test change Change-Id: Idb651c0574146167579ef317a8b5426199148a52
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/com/android/documentsui/ActivityTestJunit4.kt18
-rw-r--r--tests/functional/com/android/documentsui/FilesActivityDefaultsUiTest.java62
-rw-r--r--tests/functional/com/android/documentsui/FilesActivityUiTest.java37
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