• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.providers.media.photopicker;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.content.Context;
22 import android.content.Intent;
23 
24 import androidx.test.InstrumentationRegistry;
25 import androidx.test.runner.AndroidJUnit4;
26 
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 
30 import java.util.Arrays;
31 
32 @RunWith(AndroidJUnit4.class)
33 public class PhotoPickerActivityTest {
34 
35     private static final int INTENT_FORWARDING_FLAGS =
36             Intent.FLAG_ACTIVITY_FORWARD_RESULT | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP;
37     private static final String[] MEDIA_MIME_TYPES = new String[] {"image/*", "video/*"};
38 
39     @Test
testGetDocumentsUiForwardingIntent()40     public void testGetDocumentsUiForwardingIntent() {
41         final Context context = InstrumentationRegistry.getTargetContext();
42         final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
43         final String mimeType = "image/*";
44         intent.setType(mimeType);
45         intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
46         intent.putExtra(Intent.EXTRA_MIME_TYPES, MEDIA_MIME_TYPES);
47 
48         Intent getContentIntent = PhotoPickerActivity.getDocumentsUiForwardingIntent(context,
49                 intent);
50 
51         assertThat(getContentIntent.getAction().equals(Intent.ACTION_GET_CONTENT)).isTrue();
52         assertThat(getContentIntent.getType().equals(mimeType)).isTrue();
53         final String[] actualMimeType = getContentIntent.getStringArrayExtra(
54                 Intent.EXTRA_MIME_TYPES);
55         assertThat(Arrays.equals(actualMimeType, MEDIA_MIME_TYPES)).isTrue();
56         assertThat(getContentIntent.getBooleanExtra(Intent.EXTRA_LOCAL_ONLY, false)).isTrue();
57         assertThat(getContentIntent.getFlags()).isEqualTo(INTENT_FORWARDING_FLAGS);
58     }
59 }
60