1 /* 2 * Copyright (C) 2013 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 android.provider.cts; 18 19 import android.content.Intent; 20 import android.content.pm.ResolveInfo; 21 import android.net.Uri; 22 import android.provider.MediaStore; 23 import android.test.AndroidTestCase; 24 25 import java.util.List; 26 27 /** 28 * Tests to verify that common actions on {@link MediaStore} content are 29 * available. 30 */ 31 public class MediaStoreIntentsTest extends AndroidTestCase { 32 public void assertCanBeHandled(Intent intent) { 33 List<ResolveInfo> resolveInfoList = getContext() 34 .getPackageManager().queryIntentActivities(intent, 0); 35 assertNotNull("Missing ResolveInfo", resolveInfoList); 36 assertTrue("No ResolveInfo found for " + intent.toInsecureString(), 37 resolveInfoList.size() > 0); 38 } 39 40 public void testPickImageDir() { 41 Intent intent = new Intent(Intent.ACTION_PICK); 42 intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 43 assertCanBeHandled(intent); 44 } 45 46 public void testPickVideoDir() { 47 Intent intent = new Intent(Intent.ACTION_PICK); 48 intent.setData(MediaStore.Video.Media.EXTERNAL_CONTENT_URI); 49 assertCanBeHandled(intent); 50 } 51 52 public void testPickAudioDir() { 53 Intent intent = new Intent(Intent.ACTION_PICK); 54 intent.setData(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI); 55 assertCanBeHandled(intent); 56 } 57 58 public void testViewImageDir() { 59 Intent intent = new Intent(Intent.ACTION_VIEW); 60 intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 61 assertCanBeHandled(intent); 62 } 63 64 public void testViewVideoDir() { 65 Intent intent = new Intent(Intent.ACTION_VIEW); 66 intent.setData(MediaStore.Video.Media.EXTERNAL_CONTENT_URI); 67 assertCanBeHandled(intent); 68 } 69 70 public void testViewImageFile() { 71 final String[] schemes = new String[] { 72 "file", "http", "https", "content" }; 73 final String[] mimes = new String[] { 74 "image/bmp", "image/jpeg", "image/png", "image/gif", "image/webp", 75 "image/x-adobe-dng", "image/x-canon-cr2", "image/x-nikon-nef", "image/x-nikon-nrw", 76 "image/x-sony-arw", "image/x-panasonic-rw2", "image/x-olympus-orf", 77 "image/x-fuji-raf", "image/x-pentax-pef", "image/x-samsung-srw" }; 78 79 for (String scheme : schemes) { 80 for (String mime : mimes) { 81 Intent intent = new Intent(Intent.ACTION_VIEW); 82 final Uri uri = new Uri.Builder().scheme(scheme) 83 .authority("example.com").path("image").build(); 84 intent.setDataAndType(uri, mime); 85 assertCanBeHandled(intent); 86 } 87 } 88 } 89 90 public void testViewVideoFile() { 91 final String[] schemes = new String[] { 92 "file", "http", "https", "content" }; 93 final String[] mimes = new String[] { 94 "video/mpeg4", "video/mp4", "video/3gp", "video/3gpp", "video/3gpp2", 95 "video/webm" }; 96 97 for (String scheme : schemes) { 98 for (String mime : mimes) { 99 Intent intent = new Intent(Intent.ACTION_VIEW); 100 final Uri uri = new Uri.Builder().scheme(scheme) 101 .authority("example.com").path("video").build(); 102 intent.setDataAndType(uri, mime); 103 assertCanBeHandled(intent); 104 } 105 } 106 } 107 108 public void testViewAudioFile() { 109 final String[] schemes = new String[] { 110 "file", "http", "content" }; 111 final String[] mimes = new String[] { 112 "audio/mpeg", "audio/mp4", "audio/ogg", "audio/webm", "application/ogg", 113 "application/x-ogg" }; 114 115 for (String scheme : schemes) { 116 for (String mime : mimes) { 117 Intent intent = new Intent(Intent.ACTION_VIEW); 118 final Uri uri = new Uri.Builder().scheme(scheme) 119 .authority("example.com").path("audio").build(); 120 intent.setDataAndType(uri, mime); 121 assertCanBeHandled(intent); 122 } 123 } 124 } 125 } 126