summaryrefslogtreecommitdiff
path: root/java/tests/src
diff options
context:
space:
mode:
author Andrey Epin <ayepin@google.com> 2023-03-13 16:39:23 -0700
committer Andrey Epin <ayepin@google.com> 2023-03-14 16:07:49 -0700
commit4649ef1769d53727d59423f184cb3ee068ce40db (patch)
tree07420a85e880c372e0341f38deb89df9d0be0c20 /java/tests/src
parente7f8555d956c8bf5f338a182d8023b2740edc389 (diff)
Add unified preview UI
ChooserContentPreviewUi applies various heuristic to determine if each shared URI has a preview and, if any, displays a scrollable preview list. Each preview item in the list is badge accroding ot its type: no badge for images, a video-file badge for videos and a generic-file badge for all others. All URIs without a previwe are groupped under a single item at list end (+N files). Collateral changes: * FileContentPreviewUi$FileInfo is moved into the package level; * ChooserContentPreviewUi$ImageMimeTypeClassifier internface is moved into the package level, renamted to MimeTypeClassifier and defines a new method, isVideoType(); * ScrollableImagePreviewView is modified to support badges and the "+N" item; * A new class, UnfifiedContentPreviewUi is clonned from ImageContentPreviewUi class, and is reponsible for drawing the new unified preview ui, ImageContentPreviewUi is used only with the legacy image content preview. Bug: 271613784 Test: manual testing Change-Id: Ia25f5a1565226ac679cc8ecefd58acb95cb60142
Diffstat (limited to 'java/tests/src')
-rw-r--r--java/tests/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUiTest.kt91
1 files changed, 87 insertions, 4 deletions
diff --git a/java/tests/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUiTest.kt b/java/tests/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUiTest.kt
index d870a8c2..ba89c367 100644
--- a/java/tests/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUiTest.kt
+++ b/java/tests/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUiTest.kt
@@ -39,7 +39,7 @@ import java.util.function.Consumer
private const val PROVIDER_NAME = "org.pkg.app"
class ChooserContentPreviewUiTest {
private val contentResolver = mock<ContentInterface>()
- private val imageClassifier = ChooserContentPreviewUi.ImageMimeTypeClassifier { mimeType ->
+ private val imageClassifier = MimeTypeClassifier { mimeType ->
mimeType != null && ClipDescription.compareMimeTypes(mimeType, "image/*")
}
private val imageLoader = object : ImageLoader {
@@ -123,7 +123,7 @@ class ChooserContentPreviewUiTest {
}
@Test
- fun test_ChooserContentPreview_single_non_image_uri_to_file_preview() {
+ fun test_ChooserContentPreview_single_uri_without_preview_to_file_preview() {
val uri = Uri.parse("content://$PROVIDER_NAME/test.pdf")
val targetIntent = Intent(Intent.ACTION_SEND).apply {
putExtra(Intent.EXTRA_STREAM, uri)
@@ -144,6 +144,29 @@ class ChooserContentPreviewUiTest {
}
@Test
+ fun test_ChooserContentPreview_single_uri_with_preview_to_image_preview() {
+ val uri = Uri.parse("content://$PROVIDER_NAME/test.pdf")
+ val targetIntent = Intent(Intent.ACTION_SEND).apply {
+ putExtra(Intent.EXTRA_STREAM, uri)
+ }
+ whenever(contentResolver.getType(uri)).thenReturn("application/pdf")
+ whenever(contentResolver.getStreamTypes(uri, "*/*"))
+ .thenReturn(arrayOf("application/pdf", "image/png"))
+ val testSubject = ChooserContentPreviewUi(
+ targetIntent,
+ contentResolver,
+ imageClassifier,
+ imageLoader,
+ actionFactory,
+ transitionCallback,
+ featureFlagRepository
+ )
+ assertThat(testSubject.preferredContentPreview)
+ .isEqualTo(ContentPreviewType.CONTENT_PREVIEW_IMAGE)
+ verify(transitionCallback, never()).onAllTransitionElementsReady()
+ }
+
+ @Test
fun test_ChooserContentPreview_multiple_image_uri_to_image_preview() {
val uri1 = Uri.parse("content://$PROVIDER_NAME/test.png")
val uri2 = Uri.parse("content://$PROVIDER_NAME/test.jpg")
@@ -173,7 +196,7 @@ class ChooserContentPreviewUiTest {
}
@Test
- fun test_ChooserContentPreview_some_non_image_uri_to_file_preview() {
+ fun test_ChooserContentPreview_some_non_image_uri_to_image_preview() {
val uri1 = Uri.parse("content://$PROVIDER_NAME/test.png")
val uri2 = Uri.parse("content://$PROVIDER_NAME/test.pdf")
val targetIntent = Intent(Intent.ACTION_SEND_MULTIPLE).apply {
@@ -197,7 +220,67 @@ class ChooserContentPreviewUiTest {
featureFlagRepository
)
assertThat(testSubject.preferredContentPreview)
- .isEqualTo(ContentPreviewType.CONTENT_PREVIEW_FILE)
+ .isEqualTo(ContentPreviewType.CONTENT_PREVIEW_IMAGE)
+ verify(transitionCallback, never()).onAllTransitionElementsReady()
+ }
+
+ @Test
+ fun test_ChooserContentPreview_some_non_image_uri_with_preview_to_image_preview() {
+ val uri1 = Uri.parse("content://$PROVIDER_NAME/test.mp4")
+ val uri2 = Uri.parse("content://$PROVIDER_NAME/test.pdf")
+ val targetIntent = Intent(Intent.ACTION_SEND_MULTIPLE).apply {
+ putExtra(
+ Intent.EXTRA_STREAM,
+ ArrayList<Uri>().apply {
+ add(uri1)
+ add(uri2)
+ }
+ )
+ }
+ whenever(contentResolver.getType(uri1)).thenReturn("video/mpeg4")
+ whenever(contentResolver.getStreamTypes(uri1, "*/*"))
+ .thenReturn(arrayOf("image/png"))
+ whenever(contentResolver.getType(uri2)).thenReturn("application/pdf")
+ val testSubject = ChooserContentPreviewUi(
+ targetIntent,
+ contentResolver,
+ imageClassifier,
+ imageLoader,
+ actionFactory,
+ transitionCallback,
+ featureFlagRepository
+ )
+ assertThat(testSubject.preferredContentPreview)
+ .isEqualTo(ContentPreviewType.CONTENT_PREVIEW_IMAGE)
+ verify(transitionCallback, never()).onAllTransitionElementsReady()
+ }
+
+ @Test
+ fun test_ChooserContentPreview_all_non_image_uris_without_preview_to_file_preview() {
+ val uri1 = Uri.parse("content://$PROVIDER_NAME/test.html")
+ val uri2 = Uri.parse("content://$PROVIDER_NAME/test.pdf")
+ val targetIntent = Intent(Intent.ACTION_SEND_MULTIPLE).apply {
+ putExtra(
+ Intent.EXTRA_STREAM,
+ ArrayList<Uri>().apply {
+ add(uri1)
+ add(uri2)
+ }
+ )
+ }
+ whenever(contentResolver.getType(uri1)).thenReturn("text/html")
+ whenever(contentResolver.getType(uri2)).thenReturn("application/pdf")
+ val testSubject = ChooserContentPreviewUi(
+ targetIntent,
+ contentResolver,
+ imageClassifier,
+ imageLoader,
+ actionFactory,
+ transitionCallback,
+ featureFlagRepository
+ )
+ assertThat(testSubject.preferredContentPreview)
+ .isEqualTo(ContentPreviewType.CONTENT_PREVIEW_FILE)
verify(transitionCallback, times(1)).onAllTransitionElementsReady()
}
}