diff options
| author | 2023-03-22 01:55:56 +0000 | |
|---|---|---|
| committer | 2023-03-22 01:55:56 +0000 | |
| commit | 26fbf0fae96b7520961d44605486224ee83d8af2 (patch) | |
| tree | b2774335f92d7772ed2d2834a5eb4e0131954b23 /java/tests | |
| parent | a64f56c954910f72438bb58f2d86d8afa44b2b8d (diff) | |
| parent | 4fc75124fe90daff88f213ba204a157e40ba2b96 (diff) | |
Merge "Do not crash on reading URI metadata" into udc-dev
Diffstat (limited to 'java/tests')
| -rw-r--r-- | java/tests/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUiTest.kt | 50 |
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() } + } |