summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Android.bp3
-rw-r--r--tests/common/com/android/documentsui/bots/Bots.java4
-rw-r--r--tests/common/com/android/documentsui/bots/PeekBot.kt50
-rw-r--r--tests/common/com/android/documentsui/testing/MutableJobProgress.kt32
-rw-r--r--tests/common/com/android/documentsui/testing/TestPeekViewManager.kt34
-rw-r--r--tests/functional/com/android/documentsui/JobPanelUiTest.kt93
-rw-r--r--tests/functional/com/android/documentsui/peek/PeekUiTest.kt68
-rw-r--r--tests/unit/com/android/documentsui/JobPanelControllerTest.kt14
-rw-r--r--tests/unit/com/android/documentsui/files/ActionHandlerTest.java7
9 files changed, 291 insertions, 14 deletions
diff --git a/tests/Android.bp b/tests/Android.bp
index 41ccc1ab1..65e3f259f 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -42,6 +42,7 @@ android_library {
name: "DocumentsUIPerfTests-lib",
srcs: [
"common/com/android/documentsui/**/*.java",
+ "common/com/android/documentsui/**/*.kt",
"functional/com/android/documentsui/ActivityTest.java",
],
resource_dirs: [],
@@ -70,6 +71,7 @@ android_library {
srcs: [
"common/**/*.java",
+ "common/**/*.kt",
"unit/**/*.java",
"unit/**/*.kt",
],
@@ -94,6 +96,7 @@ android_library {
srcs: [
"common/**/*.java",
+ "common/**/*.kt",
"functional/**/*.java",
"functional/**/*.kt",
"unit/**/*.java",
diff --git a/tests/common/com/android/documentsui/bots/Bots.java b/tests/common/com/android/documentsui/bots/Bots.java
index 8cc00ac7a..f0f69b9cf 100644
--- a/tests/common/com/android/documentsui/bots/Bots.java
+++ b/tests/common/com/android/documentsui/bots/Bots.java
@@ -48,6 +48,7 @@ public final class Bots {
public final UiBot main;
public final InspectorBot inspector;
public final NotificationsBot notifications;
+ public final PeekBot peek;
public Bots(UiDevice device, UiAutomation automation, Context context, int timeout) {
main = new UiBot(device, context, TIMEOUT);
@@ -61,13 +62,14 @@ public final class Bots {
menu = new MenuBot(device, context, TIMEOUT);
inspector = new InspectorBot(device, context, TIMEOUT);
notifications = new NotificationsBot(device, context, TIMEOUT);
+ peek = new PeekBot(device, context, TIMEOUT);
}
/**
* A test helper class that provides support for controlling directory list
* and making assertions against the state of it.
*/
- static abstract class BaseBot {
+ public static abstract class BaseBot {
public final UiDevice mDevice;
final Context mContext;
final int mTimeout;
diff --git a/tests/common/com/android/documentsui/bots/PeekBot.kt b/tests/common/com/android/documentsui/bots/PeekBot.kt
new file mode 100644
index 000000000..6906d5a1a
--- /dev/null
+++ b/tests/common/com/android/documentsui/bots/PeekBot.kt
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.documentsui.bots
+
+import android.content.Context
+import androidx.test.uiautomator.UiDevice
+import androidx.test.uiautomator.UiObject
+import junit.framework.Assert.assertFalse
+import junit.framework.Assert.assertTrue
+
+/**
+ * A test helper class that provides support for controlling the peek overlay
+ * and making assertions against the state of it.
+ */
+class PeekBot(
+ device: UiDevice,
+ context: Context,
+ timeout: Int
+) : Bots.BaseBot(device, context, timeout) {
+
+ private val mOverlayId: String = "$mTargetPackage:id/peek_overlay"
+ private val mContainerId: String = "$mTargetPackage:id/peek_container"
+
+ fun assertPeekActive() {
+ val peekContainer = findPeekContainer()
+ assertTrue(peekContainer.exists())
+ }
+
+ fun assertPeekHidden() {
+ val peekContainer = findPeekContainer()
+ assertFalse(peekContainer.exists())
+ }
+
+ fun findPeekContainer(): UiObject {
+ return findObject(mOverlayId, mContainerId)
+ }
+}
diff --git a/tests/common/com/android/documentsui/testing/MutableJobProgress.kt b/tests/common/com/android/documentsui/testing/MutableJobProgress.kt
new file mode 100644
index 000000000..b2dd595f9
--- /dev/null
+++ b/tests/common/com/android/documentsui/testing/MutableJobProgress.kt
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.documentsui.testing
+
+import com.android.documentsui.services.Job
+import com.android.documentsui.services.JobProgress
+
+data class MutableJobProgress(
+ var id: String,
+ @Job.State var state: Int,
+ var msg: String?,
+ var hasFailures: Boolean,
+ var currentBytes: Long = -1,
+ var requiredBytes: Long = -1,
+ var msRemaining: Long = -1,
+) {
+ fun toJobProgress() =
+ JobProgress(id, state, msg, hasFailures, currentBytes, requiredBytes, msRemaining)
+}
diff --git a/tests/common/com/android/documentsui/testing/TestPeekViewManager.kt b/tests/common/com/android/documentsui/testing/TestPeekViewManager.kt
new file mode 100644
index 000000000..e3ad6033c
--- /dev/null
+++ b/tests/common/com/android/documentsui/testing/TestPeekViewManager.kt
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.documentsui.testing
+
+import android.app.Activity
+import androidx.fragment.app.FragmentManager
+import com.android.documentsui.base.DocumentInfo
+import com.android.documentsui.peek.PeekViewManager
+
+class TestPeekViewManager(mActivity: Activity) : PeekViewManager(mActivity) {
+
+ val peekDocument = TestEventListener<DocumentInfo>()
+
+ override fun initFragment(fm: FragmentManager) {
+ throw UnsupportedOperationException()
+ }
+
+ override fun peekDocument(doc: DocumentInfo) {
+ peekDocument.accept(doc)
+ }
+} \ No newline at end of file
diff --git a/tests/functional/com/android/documentsui/JobPanelUiTest.kt b/tests/functional/com/android/documentsui/JobPanelUiTest.kt
new file mode 100644
index 000000000..5b28b1f5d
--- /dev/null
+++ b/tests/functional/com/android/documentsui/JobPanelUiTest.kt
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.documentsui
+
+import android.content.Intent
+import android.platform.test.annotations.RequiresFlagsEnabled
+import android.platform.test.flag.junit.CheckFlagsRule
+import android.platform.test.flag.junit.DeviceFlagsValueProvider
+import androidx.test.espresso.Espresso.onView
+import androidx.test.espresso.action.ViewActions.click
+import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
+import androidx.test.espresso.assertion.ViewAssertions.matches
+import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
+import androidx.test.espresso.matcher.ViewMatchers.withId
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.platform.app.InstrumentationRegistry
+import com.android.documentsui.files.FilesActivity
+import com.android.documentsui.flags.Flags.FLAG_USE_MATERIAL3
+import com.android.documentsui.flags.Flags.FLAG_VISUAL_SIGNALS_RO
+import com.android.documentsui.services.FileOperationService.ACTION_PROGRESS
+import com.android.documentsui.services.FileOperationService.EXTRA_PROGRESS
+import com.android.documentsui.services.Job
+import com.android.documentsui.services.JobProgress
+import com.android.documentsui.testing.MutableJobProgress
+import org.junit.After
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RequiresFlagsEnabled(FLAG_USE_MATERIAL3, FLAG_VISUAL_SIGNALS_RO)
+@RunWith(AndroidJUnit4::class)
+class JobPanelUiTest : ActivityTestJunit4<FilesActivity>() {
+ @get:Rule
+ val mCheckFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule()
+
+ private var mLastId = 0L
+
+ private fun sendProgress(progresses: ArrayList<JobProgress>, id: Long = mLastId++) {
+ val context = InstrumentationRegistry.getInstrumentation().targetContext
+ var intent = Intent(ACTION_PROGRESS).apply {
+ `package` = context.packageName
+ putExtra("id", id)
+ putParcelableArrayListExtra(EXTRA_PROGRESS, progresses)
+ }
+ context.sendBroadcast(intent)
+ }
+
+ @Before
+ override fun setUp() {
+ super.setUp()
+ }
+
+ @After
+ override fun tearDown() {
+ super.tearDown()
+ }
+
+ @Test
+ fun testJobPanelAppearsOnClick() {
+ onView(withId(R.id.option_menu_job_progress)).check(doesNotExist())
+ onView(withId(R.id.job_progress_panel_title)).check(doesNotExist())
+
+ val progress = MutableJobProgress(
+ id = "jobId1",
+ state = Job.STATE_SET_UP,
+ msg = "Job started",
+ hasFailures = false,
+ currentBytes = 4,
+ requiredBytes = 10,
+ msRemaining = -1
+ )
+ sendProgress(arrayListOf(progress.toJobProgress()))
+
+ onView(withId(R.id.option_menu_job_progress))
+ .check(matches(isDisplayed()))
+ .perform(click())
+ onView(withId(R.id.job_progress_panel_title)).check(matches(isDisplayed()))
+ }
+}
diff --git a/tests/functional/com/android/documentsui/peek/PeekUiTest.kt b/tests/functional/com/android/documentsui/peek/PeekUiTest.kt
new file mode 100644
index 000000000..a7624df2f
--- /dev/null
+++ b/tests/functional/com/android/documentsui/peek/PeekUiTest.kt
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.documentsui.peek
+
+import android.os.RemoteException
+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.ActivityTestJunit4
+import com.android.documentsui.files.FilesActivity
+import com.android.documentsui.flags.Flags
+import org.junit.After
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@LargeTest
+@RunWith(AndroidJUnit4::class)
+@RequiresFlagsEnabled(Flags.FLAG_USE_MATERIAL3, Flags.FLAG_USE_PEEK_PREVIEW_RO)
+class PeekUiTest : ActivityTestJunit4<FilesActivity?>() {
+ @get:Rule
+ val mCheckFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule()
+
+ @Before
+ @Throws(Exception::class)
+ override fun setUp() {
+ super.setUp()
+ initTestFiles()
+ }
+
+ @After
+ @Throws(Exception::class)
+ override fun tearDown() {
+ super.tearDown()
+ }
+
+ @Throws(RemoteException::class)
+ override fun initTestFiles() {
+ mDocsHelper!!.createDocument(rootDir0, "image/png", "image.png")
+ }
+
+ @Test
+ @Throws(
+ Exception::class
+ )
+ fun testShowPeek() {
+ bots!!.peek.assertPeekHidden()
+ bots!!.directory.selectDocument("image.png")
+ bots!!.main.clickActionItem("Get info")
+ bots!!.peek.assertPeekActive()
+ }
+}
diff --git a/tests/unit/com/android/documentsui/JobPanelControllerTest.kt b/tests/unit/com/android/documentsui/JobPanelControllerTest.kt
index be0c9adbd..3e510edd9 100644
--- a/tests/unit/com/android/documentsui/JobPanelControllerTest.kt
+++ b/tests/unit/com/android/documentsui/JobPanelControllerTest.kt
@@ -30,6 +30,7 @@ import com.android.documentsui.services.FileOperationService.ACTION_PROGRESS
import com.android.documentsui.services.FileOperationService.EXTRA_PROGRESS
import com.android.documentsui.services.Job
import com.android.documentsui.services.JobProgress
+import com.android.documentsui.testing.MutableJobProgress
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue
@@ -38,19 +39,6 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
-private data class MutableJobProgress(
- var id: String,
- @Job.State var state: Int,
- var msg: String?,
- var hasFailures: Boolean,
- var currentBytes: Long = -1,
- var requiredBytes: Long = -1,
- var msRemaining: Long = -1,
-) {
- fun toJobProgress() =
- JobProgress(id, state, msg, hasFailures, currentBytes, requiredBytes, msRemaining)
-}
-
@SmallTest
@RequiresFlagsEnabled(FLAG_USE_MATERIAL3, FLAG_VISUAL_SIGNALS_RO)
@RunWith(AndroidJUnit4::class)
diff --git a/tests/unit/com/android/documentsui/files/ActionHandlerTest.java b/tests/unit/com/android/documentsui/files/ActionHandlerTest.java
index 1d6ef1fd6..5b19fcdc2 100644
--- a/tests/unit/com/android/documentsui/files/ActionHandlerTest.java
+++ b/tests/unit/com/android/documentsui/files/ActionHandlerTest.java
@@ -76,6 +76,7 @@ import com.android.documentsui.testing.TestDocumentClipper;
import com.android.documentsui.testing.TestDragAndDropManager;
import com.android.documentsui.testing.TestEnv;
import com.android.documentsui.testing.TestFeatures;
+import com.android.documentsui.testing.TestPeekViewManager;
import com.android.documentsui.testing.TestProvidersAccess;
import com.android.documentsui.testing.UserManagers;
import com.android.documentsui.ui.TestDialogController;
@@ -110,6 +111,7 @@ public class ActionHandlerTest {
private ActionHandler<TestActivity> mHandler;
private TestDocumentClipper mClipper;
private TestDragAndDropManager mDragAndDropManager;
+ private TestPeekViewManager mPeekViewManager;
private TestFeatures mFeatures;
private TestConfigStore mTestConfigStore;
private boolean refreshAnswer = false;
@@ -141,6 +143,7 @@ public class ActionHandlerTest {
mDialogs = new TestDialogController();
mClipper = new TestDocumentClipper();
mDragAndDropManager = new TestDragAndDropManager();
+ mPeekViewManager = new TestPeekViewManager(mActivity);
mTestConfigStore = new TestConfigStore();
mEnv.state.configStore = mTestConfigStore;
@@ -744,6 +747,8 @@ public class ActionHandlerTest {
mHandler.showPreview(TestEnv.FILE_GIF);
// The inspector activity is not called.
mActivity.startActivity.assertNotCalled();
+ mPeekViewManager.getPeekDocument().assertCalled();
+ mPeekViewManager.getPeekDocument().assertLastArgument(TestEnv.FILE_GIF);
}
@Test
@@ -751,6 +756,7 @@ public class ActionHandlerTest {
public void testShowInspector() throws Exception {
mHandler.showPreview(TestEnv.FILE_GIF);
+ mPeekViewManager.getPeekDocument().assertNotCalled();
mActivity.startActivity.assertCalled();
Intent intent = mActivity.startActivity.getLastValue();
assertTargetsComponent(intent, InspectorActivity.class);
@@ -864,6 +870,7 @@ public class ActionHandlerTest {
mClipper,
null, // clip storage, not utilized unless we venture into *jumbo* clip territory.
mDragAndDropManager,
+ mPeekViewManager,
mEnv.injector);
}
}