summaryrefslogtreecommitdiff
path: root/java/tests
diff options
context:
space:
mode:
author Andrey Epin <ayepin@google.com> 2023-09-20 15:01:40 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-09-20 15:01:40 +0000
commitc7bcd3858d5aa3b7750890abfec73f40e175357b (patch)
treee2093169fef72cf668f37d3b48bf7c7bc566139c /java/tests
parentdaffa5025a78ec34dc2016a7e833d4b00ef28e56 (diff)
parent928bc9858768b3697c64a2fd30b48e206768e7d3 (diff)
Merge "Add headline view argument to content preview UI" into main
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)
}
}