diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-18 17:39:46 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-18 17:39:46 -0700 |
commit | 105925376f8d0f6b318c9938c7b83ef7fef094da (patch) | |
tree | 3b19ee2bd8704cb9c6a0da7e42dec6759183de6d /media/tests | |
parent | ba87e3e6c985e7175152993b5efcc7dd2f0e1c93 (diff) | |
download | frameworks_base-105925376f8d0f6b318c9938c7b83ef7fef094da.zip frameworks_base-105925376f8d0f6b318c9938c7b83ef7fef094da.tar.gz frameworks_base-105925376f8d0f6b318c9938c7b83ef7fef094da.tar.bz2 |
auto import from //branches/cupcake_rel/...@140373
Diffstat (limited to 'media/tests')
2 files changed, 145 insertions, 4 deletions
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java index 3c449c9..6edc2cc 100755 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java @@ -16,12 +16,13 @@ package com.android.mediaframeworktest; -import com.android.mediaframeworktest.functional.MediaPlayerApiTest; -import com.android.mediaframeworktest.functional.SimTonesTest; -import com.android.mediaframeworktest.functional.MediaMetadataTest; import com.android.mediaframeworktest.functional.CameraTest; -import com.android.mediaframeworktest.functional.MediaRecorderTest; import com.android.mediaframeworktest.functional.MediaAudioTrackTest; +import com.android.mediaframeworktest.functional.MediaMetadataTest; +import com.android.mediaframeworktest.functional.MediaMimeTest; +import com.android.mediaframeworktest.functional.MediaPlayerApiTest; +import com.android.mediaframeworktest.functional.MediaRecorderTest; +import com.android.mediaframeworktest.functional.SimTonesTest; import junit.framework.TestSuite; @@ -50,6 +51,7 @@ public class MediaFrameworkTestRunner extends InstrumentationTestRunner { suite.addTestSuite(CameraTest.class); suite.addTestSuite(MediaRecorderTest.class); suite.addTestSuite(MediaAudioTrackTest.class); + suite.addTestSuite(MediaMimeTest.class); return suite; } diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaMimeTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaMimeTest.java new file mode 100644 index 0000000..d2809c1 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaMimeTest.java @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional; + +import java.io.File; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.net.Uri; +import android.test.ActivityInstrumentationTestCase2; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.Suppress; +import android.util.Log; +import com.android.mediaframeworktest.MediaFrameworkTest; + +/* + * System tests for the handling of mime type in the media framework. + * + * To run this test suite: + make frameworks/base/media/tests/MediaFrameworkTest + make mediaframeworktest + + adb install -r out/target/product/dream/data/app/mediaframeworktest.apk + + adb shell am instrument -e class \ + com.android.mediaframeworktest.functional.MediaMimeTest \ + -w com.android.mediaframeworktest/.MediaFrameworkTestRunner + * + */ +public class MediaMimeTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> { + private final String TAG = "MediaMimeTest"; + private Context mContext; + private final String MP3_FILE = "/sdcard/media_api/music/SHORTMP3.mp3"; + private final String MEDIA_PLAYBACK_NAME = "com.android.music.MediaPlaybackActivity"; + + public MediaMimeTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + mContext = getActivity(); + // Checks you have all the test files on your SDCARD. + assertTrue(new File(MP3_FILE).exists()); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + // ---------------------------------------------------------------------- + // AUDIO mime type resolution tests. + + @MediumTest + // Checks the MediaPlaybackActivity handles audio/mp3. + public void testCheckMediaPlaybackHandlesAudioMp3() throws Exception { + assertMediaPlaybackActivityHandles("audio/mp3"); + } + + @MediumTest + // Checks the MediaPlaybackActivity handles audio/*. + public void testCheckMediaPlaybackHandlesAudio() throws Exception { + assertMediaPlaybackActivityHandles("audio/*"); + } + + @MediumTest + // Checks the MediaPlaybackActivity handles application/itunes. Some servers + // set the Content-type header to application/iTunes (with capital T, but + // the download manager downcasts it) for their MP3 podcasts. This is non + // standard but we try to support it anyway. + // See bug 1401491 + public void testCheckMediaPlaybackHandlesApplicationItunes() throws Exception { + assertMediaPlaybackActivityHandles("application/itunes"); + } + + @MediumTest + // Checks the activity resolver handling of mime types is case sensitive. + // See bug 1710534 + public void testCheckActivityResolverMimeHandlingIsCaseSensitive() throws Exception { + assertNoActivityHandles("AUDIO/MP3"); // <--- look uppercase + } + + @MediumTest + // Checks the activity resolver does not trims leading whitespaces when + // resolving mime types. Trailing whitespaces seems to be non + // significant. + // See bug 1710534 + public void testCheckWhiteSpacesInMimeTypeHandling() throws Exception { + assertNoActivityHandles(" audio/mp3"); + assertNoActivityHandles(" audio/mp3 "); + assertMediaPlaybackActivityHandles("audio/mp3 "); + } + + // @return a ResolveInfo instance for the mime type or null if the type is + // not handled by any activity. + private ResolveInfo resolveMime(String mime) { + Intent viewIntent = new Intent(Intent.ACTION_VIEW); + Uri uri = Uri.fromParts("file", MP3_FILE, null); + + viewIntent.setDataAndType(uri, mime); + return mContext.getPackageManager().resolveActivity( + viewIntent, PackageManager.MATCH_DEFAULT_ONLY); + } + + // Helper method to check the media playback activity handles the given mime type. + // @param mime type to test for + private void assertMediaPlaybackActivityHandles(String mime) throws Exception { + ResolveInfo ri = resolveMime(mime); + + assertNotNull(ri); + assertEquals(MEDIA_PLAYBACK_NAME, ri.activityInfo.name.toString()); + } + + // Helper method to check that NO activity handles the given mime type. + // @param mime type to test for + private void assertNoActivityHandles(String mime) throws Exception { + assertNull(resolveMime(mime)); + } +} |