summaryrefslogtreecommitdiff
path: root/java/tests
diff options
context:
space:
mode:
author Andrey Epin <ayepin@google.com> 2023-07-26 15:07:53 -0700
committer Andrey Epin <ayepin@google.com> 2023-09-16 22:42:21 -0700
commit928bc9858768b3697c64a2fd30b48e206768e7d3 (patch)
tree3b76fe7ea516ef9d11e5cab5021cfdc6bde8411b /java/tests
parentc7d61dc6a727ffad6e6d26f312e6d5928c93bd6b (diff)
Add headline view argument to content preview UI
"Sticky" headline is one of the requirements of the scrollable preview feature. Currently headling row is included in every preview type we have and to be "sticky" it should be moved out of all of them. This change is a preparation work that makes all of the preview UI controllers aware of a possible external headline row (but no actual external headline view is used). Bug: 287102904 Test: manual testing of all preivew types checking that there are no regressions Test: atest com.android.intentresolver.contentpreview Change-Id: Ib6110aaa82246e3354fdce18f431ab1c116e7b73
Diffstat (limited to 'java/tests')
-rw-r--r--java/tests/src/com/android/intentresolver/contentpreview/FileContentPreviewUiTest.kt76
-rw-r--r--java/tests/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUiTest.kt9
-rw-r--r--java/tests/src/com/android/intentresolver/contentpreview/TextContentPreviewUiTest.kt82
-rw-r--r--java/tests/src/com/android/intentresolver/contentpreview/UnifiedContentPreviewUiTest.kt7
4 files changed, 171 insertions, 3 deletions
diff --git a/java/tests/src/com/android/intentresolver/contentpreview/FileContentPreviewUiTest.kt b/java/tests/src/com/android/intentresolver/contentpreview/FileContentPreviewUiTest.kt
new file mode 100644
index 00000000..6409da8a
--- /dev/null
+++ b/java/tests/src/com/android/intentresolver/contentpreview/FileContentPreviewUiTest.kt
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2023 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.intentresolver.contentpreview
+
+import android.view.LayoutInflater
+import android.view.ViewGroup
+import android.widget.TextView
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.platform.app.InstrumentationRegistry
+import com.android.intentresolver.R
+import com.android.intentresolver.mock
+import com.android.intentresolver.whenever
+import com.android.intentresolver.widget.ActionRow
+import com.google.common.truth.Truth
+import java.util.function.Consumer
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class FileContentPreviewUiTest {
+ private val fileCount = 2
+ private val text = "Sharing 2 files"
+ private val actionFactory =
+ object : ChooserContentPreviewUi.ActionFactory {
+ override fun getEditButtonRunnable(): Runnable? = null
+ override fun getCopyButtonRunnable(): Runnable? = null
+ override fun createCustomActions(): List<ActionRow.Action> = emptyList()
+ override fun getModifyShareAction(): ActionRow.Action? = null
+ override fun getExcludeSharedTextAction(): Consumer<Boolean> = Consumer<Boolean> {}
+ }
+ private val headlineGenerator =
+ mock<HeadlineGenerator> { whenever(getFilesHeadline(fileCount)).thenReturn(text) }
+
+ private val context
+ get() = InstrumentationRegistry.getInstrumentation().context
+
+ @Test
+ fun test_display_titleIsDisplayed() {
+ val testSubject =
+ FileContentPreviewUi(
+ fileCount,
+ actionFactory,
+ headlineGenerator,
+ )
+
+ val layoutInflater = LayoutInflater.from(context)
+ val gridLayout = layoutInflater.inflate(R.layout.chooser_grid, null, false) as ViewGroup
+
+ val previewView =
+ testSubject.display(
+ context.resources,
+ layoutInflater,
+ gridLayout,
+ /*headlineViewParent=*/ null
+ )
+
+ Truth.assertThat(previewView).isNotNull()
+ val headlineView = previewView?.findViewById<TextView>(R.id.headline)
+ Truth.assertThat(headlineView).isNotNull()
+ Truth.assertThat(headlineView?.text).isEqualTo(text)
+ }
+}
diff --git a/java/tests/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUiTest.kt b/java/tests/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUiTest.kt
index fe13a215..1144e3c9 100644
--- a/java/tests/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUiTest.kt
+++ b/java/tests/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUiTest.kt
@@ -167,7 +167,7 @@ class FilesPlusTextContentPreviewUiTest {
val gridLayout = layoutInflater.inflate(R.layout.chooser_grid, null, false) as ViewGroup
val previewView =
- testSubject.display(context.resources, LayoutInflater.from(context), gridLayout)
+ testSubject.display(context.resources, LayoutInflater.from(context), gridLayout, null)
verify(headlineGenerator, times(1)).getFilesHeadline(sharedFileCount)
verify(headlineGenerator, never()).getImagesHeadline(sharedFileCount)
@@ -201,7 +201,12 @@ class FilesPlusTextContentPreviewUiTest {
val gridLayout = layoutInflater.inflate(R.layout.chooser_grid, null, false) as ViewGroup
loadedFileMetadata?.let(testSubject::updatePreviewMetadata)
- return testSubject.display(context.resources, LayoutInflater.from(context), gridLayout)
+ return testSubject.display(
+ context.resources,
+ LayoutInflater.from(context),
+ gridLayout,
+ /*headlineViewParent=*/ null
+ )
}
private fun createFileInfosWithMimeTypes(vararg mimeTypes: String): List<FileInfo> {
diff --git a/java/tests/src/com/android/intentresolver/contentpreview/TextContentPreviewUiTest.kt b/java/tests/src/com/android/intentresolver/contentpreview/TextContentPreviewUiTest.kt
new file mode 100644
index 00000000..69053f73
--- /dev/null
+++ b/java/tests/src/com/android/intentresolver/contentpreview/TextContentPreviewUiTest.kt
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2023 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.intentresolver.contentpreview
+
+import android.view.LayoutInflater
+import android.view.ViewGroup
+import android.widget.TextView
+import androidx.lifecycle.testing.TestLifecycleOwner
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.platform.app.InstrumentationRegistry
+import com.android.intentresolver.R
+import com.android.intentresolver.mock
+import com.android.intentresolver.whenever
+import com.android.intentresolver.widget.ActionRow
+import com.google.common.truth.Truth.assertThat
+import java.util.function.Consumer
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class TextContentPreviewUiTest {
+ private val text = "Shared Text"
+ private val title = "Preview Title"
+ private val lifecycleOwner = TestLifecycleOwner()
+ private val actionFactory =
+ object : ChooserContentPreviewUi.ActionFactory {
+ override fun getEditButtonRunnable(): Runnable? = null
+ override fun getCopyButtonRunnable(): Runnable? = null
+ override fun createCustomActions(): List<ActionRow.Action> = emptyList()
+ override fun getModifyShareAction(): ActionRow.Action? = null
+ override fun getExcludeSharedTextAction(): Consumer<Boolean> = Consumer<Boolean> {}
+ }
+ private val imageLoader = mock<ImageLoader>()
+ private val headlineGenerator =
+ mock<HeadlineGenerator> { whenever(getTextHeadline(text)).thenReturn(text) }
+
+ private val context
+ get() = InstrumentationRegistry.getInstrumentation().context
+
+ @Test
+ fun test_display_headlineIsDisplayed() {
+ val testSubject =
+ TextContentPreviewUi(
+ lifecycleOwner.lifecycle,
+ text,
+ title,
+ /*previewThumbnail=*/ null,
+ actionFactory,
+ imageLoader,
+ headlineGenerator,
+ )
+ val layoutInflater = LayoutInflater.from(context)
+ val gridLayout = layoutInflater.inflate(R.layout.chooser_grid, null, false) as ViewGroup
+
+ val previewView =
+ testSubject.display(
+ context.resources,
+ layoutInflater,
+ gridLayout,
+ /*headlineViewParent=*/ null
+ )
+
+ assertThat(previewView).isNotNull()
+ val headlineView = previewView?.findViewById<TextView>(R.id.headline)
+ assertThat(headlineView).isNotNull()
+ assertThat(headlineView?.text).isEqualTo(text)
+ }
+}
diff --git a/java/tests/src/com/android/intentresolver/contentpreview/UnifiedContentPreviewUiTest.kt b/java/tests/src/com/android/intentresolver/contentpreview/UnifiedContentPreviewUiTest.kt
index e7de0b7b..6b22b850 100644
--- a/java/tests/src/com/android/intentresolver/contentpreview/UnifiedContentPreviewUiTest.kt
+++ b/java/tests/src/com/android/intentresolver/contentpreview/UnifiedContentPreviewUiTest.kt
@@ -159,7 +159,12 @@ class UnifiedContentPreviewUiTest {
val layoutInflater = LayoutInflater.from(context)
val gridLayout = layoutInflater.inflate(chooser_grid, null, false) as ViewGroup
- testSubject.display(context.resources, LayoutInflater.from(context), gridLayout)
+ testSubject.display(
+ context.resources,
+ LayoutInflater.from(context),
+ gridLayout,
+ /*headlineViewParent=*/ null
+ )
emptySourceFlow.tryEmit(endMarker)
}
}