summaryrefslogtreecommitdiff
path: root/java/tests
diff options
context:
space:
mode:
author Andrey Epin <ayepin@google.com> 2023-03-21 10:56:58 -0700
committer Andrey Epin <ayepin@google.com> 2023-03-21 14:11:13 -0700
commit4fc75124fe90daff88f213ba204a157e40ba2b96 (patch)
treeba8f344f2cf2c1eb1b58d6c426cfad2e7c6bbfc5 /java/tests
parent3c3755b4ea535df1b5f2a9f3e57b235b660e1fcd (diff)
Do not crash on reading URI metadata
Do not crash if content resolver throws an exception while trying to read an URI metadata. Bug: 273890881 Test: check that the Chooser is not failing Change-Id: I161e29246bfcb1081a500b90c88c8c06c1d0df72
Diffstat (limited to 'java/tests')
-rw-r--r--java/tests/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUiTest.kt50
1 files changed, 50 insertions, 0 deletions
diff --git a/java/tests/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUiTest.kt b/java/tests/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUiTest.kt
index 04a136b4..58b8a21d 100644
--- a/java/tests/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUiTest.kt
+++ b/java/tests/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUiTest.kt
@@ -23,6 +23,8 @@ import android.graphics.Bitmap
import android.net.Uri
import com.android.intentresolver.ImageLoader
import com.android.intentresolver.TestFeatureFlagRepository
+import com.android.intentresolver.any
+import com.android.intentresolver.anyOrNull
import com.android.intentresolver.contentpreview.ChooserContentPreviewUi.ActionFactory
import com.android.intentresolver.flags.Flags
import com.android.intentresolver.mock
@@ -144,6 +146,53 @@ class ChooserContentPreviewUiTest {
}
@Test
+ fun test_ChooserContentPreview_single_uri_crashing_getType_to_file_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(any()))
+ .thenThrow(SecurityException("Test getType() exception"))
+ val testSubject = ChooserContentPreviewUi(
+ targetIntent,
+ contentResolver,
+ imageClassifier,
+ imageLoader,
+ actionFactory,
+ transitionCallback,
+ featureFlagRepository
+ )
+ assertThat(testSubject.preferredContentPreview)
+ .isEqualTo(ContentPreviewType.CONTENT_PREVIEW_FILE)
+ verify(transitionCallback, times(1)).onAllTransitionElementsReady()
+ }
+
+ @Test
+ fun test_ChooserContentPreview_single_uri_crashing_metadata_to_file_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(any())).thenReturn("application/pdf")
+ whenever(contentResolver.query(any(), anyOrNull(), anyOrNull(), anyOrNull()))
+ .thenThrow(SecurityException("Test query() exception"))
+ whenever(contentResolver.getStreamTypes(any(), any()))
+ .thenThrow(SecurityException("Test getStreamType() exception"))
+ val testSubject = ChooserContentPreviewUi(
+ targetIntent,
+ contentResolver,
+ imageClassifier,
+ imageLoader,
+ actionFactory,
+ transitionCallback,
+ featureFlagRepository
+ )
+ assertThat(testSubject.preferredContentPreview)
+ .isEqualTo(ContentPreviewType.CONTENT_PREVIEW_FILE)
+ verify(transitionCallback, times(1)).onAllTransitionElementsReady()
+ }
+
+ @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 {
@@ -283,4 +332,5 @@ class ChooserContentPreviewUiTest {
.isEqualTo(ContentPreviewType.CONTENT_PREVIEW_FILE)
verify(transitionCallback, times(1)).onAllTransitionElementsReady()
}
+
}