diff options
Diffstat (limited to 'tests')
6 files changed, 163 insertions, 1 deletions
diff --git a/tests/Android.bp b/tests/Android.bp index 95418bdde..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: [], 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/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/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/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); } } |