From 5c2dd9ca42839d36430f0868c5d297d0a91f2e1e Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Mon, 20 Aug 2018 07:13:26 -0700 Subject: [PATCH] Move all tests to JUnit 4 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=209412403 --- extensions/flac/build.gradle | 2 + .../flac/src/androidTest/AndroidManifest.xml | 2 +- .../exoplayer2/ext/flac/FlacPlaybackTest.java | 25 ++++--- extensions/opus/build.gradle | 2 + .../opus/src/androidTest/AndroidManifest.xml | 2 +- .../exoplayer2/ext/opus/OpusPlaybackTest.java | 25 ++++--- extensions/vp9/build.gradle | 2 + .../vp9/src/androidTest/AndroidManifest.xml | 2 +- .../exoplayer2/ext/vp9/VpxPlaybackTest.java | 27 +++++--- library/core/build.gradle | 12 ++-- .../core/src/androidTest/AndroidManifest.xml | 2 +- playbacktests/build.gradle | 3 + .../src/androidTest/AndroidManifest.xml | 2 +- .../gts/CommonEncryptionDrmTest.java | 50 ++++++++------ .../playbacktests/gts/DashDownloadTest.java | 48 +++++++------ .../playbacktests/gts/DashStreamingTest.java | 69 ++++++++++++++----- .../gts/DashWidevineOfflineTest.java | 53 ++++++++------ .../gts/EnumerateDecodersTest.java | 16 +++-- 18 files changed, 215 insertions(+), 129 deletions(-) diff --git a/extensions/flac/build.gradle b/extensions/flac/build.gradle index 98b81d911a..e5261902c6 100644 --- a/extensions/flac/build.gradle +++ b/extensions/flac/build.gradle @@ -27,6 +27,7 @@ android { minSdkVersion project.ext.minSdkVersion targetSdkVersion project.ext.targetSdkVersion consumerProguardFiles 'proguard-rules.txt' + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } sourceSets.main { @@ -38,6 +39,7 @@ android { dependencies { implementation 'com.android.support:support-annotations:' + supportLibraryVersion implementation project(modulePrefix + 'library-core') + androidTestImplementation 'androidx.test:runner:' + testRunnerVersion androidTestImplementation project(modulePrefix + 'testutils') testImplementation project(modulePrefix + 'testutils-robolectric') } diff --git a/extensions/flac/src/androidTest/AndroidManifest.xml b/extensions/flac/src/androidTest/AndroidManifest.xml index 4e3925d8e3..cfc90117ac 100644 --- a/extensions/flac/src/androidTest/AndroidManifest.xml +++ b/extensions/flac/src/androidTest/AndroidManifest.xml @@ -26,6 +26,6 @@ + android:name="androidx.test.runner.AndroidJUnitRunner"/> diff --git a/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacPlaybackTest.java b/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacPlaybackTest.java index 07b7a0ccdb..a78556b6c7 100644 --- a/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacPlaybackTest.java +++ b/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacPlaybackTest.java @@ -15,10 +15,13 @@ */ package com.google.android.exoplayer2.ext.flac; +import static androidx.test.InstrumentationRegistry.getContext; +import static org.junit.Assert.fail; + import android.content.Context; import android.net.Uri; import android.os.Looper; -import android.test.InstrumentationTestCase; +import androidx.test.runner.AndroidJUnit4; import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayerFactory; @@ -29,29 +32,31 @@ import com.google.android.exoplayer2.source.ExtractorMediaSource; import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; -/** - * Playback tests using {@link LibflacAudioRenderer}. - */ -public class FlacPlaybackTest extends InstrumentationTestCase { +/** Playback tests using {@link LibflacAudioRenderer}. */ +@RunWith(AndroidJUnit4.class) +public class FlacPlaybackTest { private static final String BEAR_FLAC_URI = "asset:///bear-flac.mka"; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() { if (!FlacLibrary.isAvailable()) { fail("Flac library not available."); } } + @Test public void testBasicPlayback() throws ExoPlaybackException { playUri(BEAR_FLAC_URI); } private void playUri(String uri) throws ExoPlaybackException { - TestPlaybackRunnable testPlaybackRunnable = new TestPlaybackRunnable(Uri.parse(uri), - getInstrumentation().getContext()); + TestPlaybackRunnable testPlaybackRunnable = + new TestPlaybackRunnable(Uri.parse(uri), getContext()); Thread thread = new Thread(testPlaybackRunnable); thread.start(); try { diff --git a/extensions/opus/build.gradle b/extensions/opus/build.gradle index dc530d05aa..cb12442de8 100644 --- a/extensions/opus/build.gradle +++ b/extensions/opus/build.gradle @@ -27,6 +27,7 @@ android { minSdkVersion project.ext.minSdkVersion targetSdkVersion project.ext.targetSdkVersion consumerProguardFiles 'proguard-rules.txt' + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } sourceSets.main { @@ -37,6 +38,7 @@ android { dependencies { implementation project(modulePrefix + 'library-core') + androidTestImplementation 'androidx.test:runner:' + testRunnerVersion } ext { diff --git a/extensions/opus/src/androidTest/AndroidManifest.xml b/extensions/opus/src/androidTest/AndroidManifest.xml index 9e7f05051e..5ba0f3c0f4 100644 --- a/extensions/opus/src/androidTest/AndroidManifest.xml +++ b/extensions/opus/src/androidTest/AndroidManifest.xml @@ -26,6 +26,6 @@ + android:name="androidx.test.runner.AndroidJUnitRunner"/> diff --git a/extensions/opus/src/androidTest/java/com/google/android/exoplayer2/ext/opus/OpusPlaybackTest.java b/extensions/opus/src/androidTest/java/com/google/android/exoplayer2/ext/opus/OpusPlaybackTest.java index 8e3a213af1..cad63f84df 100644 --- a/extensions/opus/src/androidTest/java/com/google/android/exoplayer2/ext/opus/OpusPlaybackTest.java +++ b/extensions/opus/src/androidTest/java/com/google/android/exoplayer2/ext/opus/OpusPlaybackTest.java @@ -15,10 +15,13 @@ */ package com.google.android.exoplayer2.ext.opus; +import static androidx.test.InstrumentationRegistry.getContext; +import static org.junit.Assert.fail; + import android.content.Context; import android.net.Uri; import android.os.Looper; -import android.test.InstrumentationTestCase; +import androidx.test.runner.AndroidJUnit4; import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayerFactory; @@ -29,29 +32,31 @@ import com.google.android.exoplayer2.source.ExtractorMediaSource; import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; -/** - * Playback tests using {@link LibopusAudioRenderer}. - */ -public class OpusPlaybackTest extends InstrumentationTestCase { +/** Playback tests using {@link LibopusAudioRenderer}. */ +@RunWith(AndroidJUnit4.class) +public class OpusPlaybackTest { private static final String BEAR_OPUS_URI = "asset:///bear-opus.webm"; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() { if (!OpusLibrary.isAvailable()) { fail("Opus library not available."); } } + @Test public void testBasicPlayback() throws ExoPlaybackException { playUri(BEAR_OPUS_URI); } private void playUri(String uri) throws ExoPlaybackException { - TestPlaybackRunnable testPlaybackRunnable = new TestPlaybackRunnable(Uri.parse(uri), - getInstrumentation().getContext()); + TestPlaybackRunnable testPlaybackRunnable = + new TestPlaybackRunnable(Uri.parse(uri), getContext()); Thread thread = new Thread(testPlaybackRunnable); thread.start(); try { diff --git a/extensions/vp9/build.gradle b/extensions/vp9/build.gradle index 3fb627fd77..96c58d7a57 100644 --- a/extensions/vp9/build.gradle +++ b/extensions/vp9/build.gradle @@ -27,6 +27,7 @@ android { minSdkVersion project.ext.minSdkVersion targetSdkVersion project.ext.targetSdkVersion consumerProguardFiles 'proguard-rules.txt' + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } sourceSets.main { @@ -38,6 +39,7 @@ android { dependencies { implementation project(modulePrefix + 'library-core') implementation 'com.android.support:support-annotations:' + supportLibraryVersion + androidTestImplementation 'androidx.test:runner:' + testRunnerVersion androidTestImplementation 'com.google.truth:truth:' + truthVersion } diff --git a/extensions/vp9/src/androidTest/AndroidManifest.xml b/extensions/vp9/src/androidTest/AndroidManifest.xml index c7ed3d7fb2..214427c4f0 100644 --- a/extensions/vp9/src/androidTest/AndroidManifest.xml +++ b/extensions/vp9/src/androidTest/AndroidManifest.xml @@ -26,6 +26,6 @@ + android:name="androidx.test.runner.AndroidJUnitRunner"/> diff --git a/extensions/vp9/src/androidTest/java/com/google/android/exoplayer2/ext/vp9/VpxPlaybackTest.java b/extensions/vp9/src/androidTest/java/com/google/android/exoplayer2/ext/vp9/VpxPlaybackTest.java index bab7cb6fd7..119347ccbf 100644 --- a/extensions/vp9/src/androidTest/java/com/google/android/exoplayer2/ext/vp9/VpxPlaybackTest.java +++ b/extensions/vp9/src/androidTest/java/com/google/android/exoplayer2/ext/vp9/VpxPlaybackTest.java @@ -15,13 +15,15 @@ */ package com.google.android.exoplayer2.ext.vp9; +import static androidx.test.InstrumentationRegistry.getContext; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.fail; import android.content.Context; import android.net.Uri; import android.os.Looper; -import android.test.InstrumentationTestCase; import android.util.Log; +import androidx.test.runner.AndroidJUnit4; import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayerFactory; @@ -32,11 +34,13 @@ import com.google.android.exoplayer2.source.ExtractorMediaSource; import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; -/** - * Playback tests using {@link LibvpxVideoRenderer}. - */ -public class VpxPlaybackTest extends InstrumentationTestCase { +/** Playback tests using {@link LibvpxVideoRenderer}. */ +@RunWith(AndroidJUnit4.class) +public class VpxPlaybackTest { private static final String BEAR_URI = "asset:///bear-vp9.webm"; private static final String BEAR_ODD_DIMENSIONS_URI = "asset:///bear-vp9-odd-dimensions.webm"; @@ -45,22 +49,24 @@ public class VpxPlaybackTest extends InstrumentationTestCase { private static final String TAG = "VpxPlaybackTest"; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() { if (!VpxLibrary.isAvailable()) { fail("Vpx library not available."); } } + @Test public void testBasicPlayback() throws ExoPlaybackException { playUri(BEAR_URI); } + @Test public void testOddDimensionsPlayback() throws ExoPlaybackException { playUri(BEAR_ODD_DIMENSIONS_URI); } + @Test public void test10BitProfile2Playback() throws ExoPlaybackException { if (VpxLibrary.isHighBitDepthSupported()) { Log.d(TAG, "High Bit Depth supported."); @@ -70,6 +76,7 @@ public class VpxPlaybackTest extends InstrumentationTestCase { Log.d(TAG, "High Bit Depth not supported."); } + @Test public void testInvalidBitstream() { try { playUri(INVALID_BITSTREAM_URI); @@ -81,8 +88,8 @@ public class VpxPlaybackTest extends InstrumentationTestCase { } private void playUri(String uri) throws ExoPlaybackException { - TestPlaybackRunnable testPlaybackRunnable = new TestPlaybackRunnable(Uri.parse(uri), - getInstrumentation().getContext()); + TestPlaybackRunnable testPlaybackRunnable = + new TestPlaybackRunnable(Uri.parse(uri), getContext()); Thread thread = new Thread(testPlaybackRunnable); thread.start(); try { diff --git a/library/core/build.gradle b/library/core/build.gradle index 947972392f..606033fdea 100644 --- a/library/core/build.gradle +++ b/library/core/build.gradle @@ -28,7 +28,7 @@ android { targetSdkVersion project.ext.targetSdkVersion consumerProguardFiles 'proguard-rules.txt' - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' // The following argument makes the Android Test Orchestrator run its // "pm clear" command after each test invocation. This command ensures @@ -39,11 +39,11 @@ android { // Workaround to prevent circular dependency on project :testutils. sourceSets { androidTest { - java.srcDirs += "../../testutils/src/main/java/" + java.srcDirs += '../../testutils/src/main/java/' } test { - java.srcDirs += "../../testutils/src/main/java/" - java.srcDirs += "../../testutils_robolectric/src/main/java/" + java.srcDirs += '../../testutils/src/main/java/' + java.srcDirs += '../../testutils_robolectric/src/main/java/' } } @@ -60,12 +60,12 @@ dependencies { implementation 'com.android.support:support-annotations:' + supportLibraryVersion compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion compileOnly 'org.checkerframework:checker-compat-qual:' + checkerframeworkVersion + androidTestImplementation 'androidx.test:runner:' + testRunnerVersion + androidTestImplementation 'com.google.auto.value:auto-value-annotations:' + autoValueVersion androidTestImplementation 'com.google.dexmaker:dexmaker:' + dexmakerVersion androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:' + dexmakerVersion androidTestImplementation 'com.google.truth:truth:' + truthVersion androidTestImplementation 'org.mockito:mockito-core:' + mockitoVersion - androidTestImplementation 'androidx.test:runner:' + testRunnerVersion - androidTestImplementation 'com.google.auto.value:auto-value-annotations:' + autoValueVersion androidTestAnnotationProcessor 'com.google.auto.value:auto-value:' + autoValueVersion testImplementation 'com.google.truth:truth:' + truthVersion testImplementation 'junit:junit:' + junitVersion diff --git a/library/core/src/androidTest/AndroidManifest.xml b/library/core/src/androidTest/AndroidManifest.xml index 1aa47c10f6..d9104b1077 100644 --- a/library/core/src/androidTest/AndroidManifest.xml +++ b/library/core/src/androidTest/AndroidManifest.xml @@ -29,6 +29,6 @@ + android:name="androidx.test.runner.AndroidJUnitRunner"/> diff --git a/playbacktests/build.gradle b/playbacktests/build.gradle index f40d30f331..a06a3160f1 100644 --- a/playbacktests/build.gradle +++ b/playbacktests/build.gradle @@ -26,10 +26,13 @@ android { defaultConfig { minSdkVersion project.ext.minSdkVersion targetSdkVersion project.ext.targetSdkVersion + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } } dependencies { + androidTestImplementation 'androidx.test:rules:' + testRunnerVersion + androidTestImplementation 'androidx.test:runner:' + testRunnerVersion androidTestImplementation project(modulePrefix + 'library-core') androidTestImplementation project(modulePrefix + 'library-dash') androidTestImplementation project(modulePrefix + 'library-hls') diff --git a/playbacktests/src/androidTest/AndroidManifest.xml b/playbacktests/src/androidTest/AndroidManifest.xml index d4fd0b61f1..d458df55bb 100644 --- a/playbacktests/src/androidTest/AndroidManifest.xml +++ b/playbacktests/src/androidTest/AndroidManifest.xml @@ -34,6 +34,6 @@ + android:name="androidx.test.runner.AndroidJUnitRunner"/> diff --git a/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/CommonEncryptionDrmTest.java b/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/CommonEncryptionDrmTest.java index a4cd35911b..1f8337355b 100644 --- a/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/CommonEncryptionDrmTest.java +++ b/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/CommonEncryptionDrmTest.java @@ -15,17 +15,24 @@ */ package com.google.android.exoplayer2.playbacktests.gts; -import android.test.ActivityInstrumentationTestCase2; +import static androidx.test.InstrumentationRegistry.getInstrumentation; + +import androidx.test.rule.ActivityTestRule; +import androidx.test.runner.AndroidJUnit4; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.testutil.ActionSchedule; import com.google.android.exoplayer2.testutil.HostActivity; import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.Util; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; -/** - * Test playback of encrypted DASH streams using different CENC scheme types. - */ -public final class CommonEncryptionDrmTest extends ActivityInstrumentationTestCase2 { +/** Test playback of encrypted DASH streams using different CENC scheme types. */ +@RunWith(AndroidJUnit4.class) +public final class CommonEncryptionDrmTest { private static final String TAG = "CencDrmTest"; @@ -44,29 +51,26 @@ public final class CommonEncryptionDrmTest extends ActivityInstrumentationTestCa .seekAndWait(270000).delay(10000).seekAndWait(200000).delay(10000).seekAndWait(732000) .build(); + @Rule public ActivityTestRule testRule = new ActivityTestRule<>(HostActivity.class); + private DashTestRunner testRunner; - public CommonEncryptionDrmTest() { - super(HostActivity.class); + @Before + public void setUp() { + testRunner = + new DashTestRunner(TAG, testRule.getActivity(), getInstrumentation()) + .setWidevineInfo(MimeTypes.VIDEO_H264, false) + .setActionSchedule(ACTION_SCHEDULE_WITH_SEEKS) + .setAudioVideoFormats(ID_AUDIO, IDS_VIDEO) + .setCanIncludeAdditionalVideoFormats(true); } - @Override - protected void setUp() throws Exception { - super.setUp(); - - testRunner = new DashTestRunner(TAG, getActivity(), getInstrumentation()) - .setWidevineInfo(MimeTypes.VIDEO_H264, false) - .setActionSchedule(ACTION_SCHEDULE_WITH_SEEKS) - .setAudioVideoFormats(ID_AUDIO, IDS_VIDEO) - .setCanIncludeAdditionalVideoFormats(true); - } - - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() { testRunner = null; - super.tearDown(); } + @Test public void testCencSchemeTypeV18() { if (Util.SDK_INT < 18) { // Pass. @@ -75,6 +79,7 @@ public final class CommonEncryptionDrmTest extends ActivityInstrumentationTestCa testRunner.setStreamName("test_widevine_h264_scheme_cenc").setManifestUrl(URL_cenc).run(); } + @Test public void testCbc1SchemeTypeV25() { if (Util.SDK_INT < 25) { // cbc1 support was added in API 24, but it is stable from API 25 onwards. @@ -85,6 +90,7 @@ public final class CommonEncryptionDrmTest extends ActivityInstrumentationTestCa testRunner.setStreamName("test_widevine_h264_scheme_cbc1").setManifestUrl(URL_cbc1).run(); } + @Test public void testCbcsSchemeTypeV25() { if (Util.SDK_INT < 25) { // cbcs support was added in API 24, but it is stable from API 25 onwards. @@ -95,8 +101,8 @@ public final class CommonEncryptionDrmTest extends ActivityInstrumentationTestCa testRunner.setStreamName("test_widevine_h264_scheme_cbcs").setManifestUrl(URL_cbcs).run(); } + @Test public void testCensSchemeTypeV25() { // TODO: Implement once content is available. Track [internal: b/31219813]. } - } diff --git a/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DashDownloadTest.java b/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DashDownloadTest.java index 79d39096c5..0dd05e7fd3 100644 --- a/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DashDownloadTest.java +++ b/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DashDownloadTest.java @@ -15,10 +15,12 @@ */ package com.google.android.exoplayer2.playbacktests.gts; +import static androidx.test.InstrumentationRegistry.getInstrumentation; import static com.google.common.truth.Truth.assertWithMessage; import android.net.Uri; -import android.test.ActivityInstrumentationTestCase2; +import androidx.test.rule.ActivityTestRule; +import androidx.test.runner.AndroidJUnit4; import com.google.android.exoplayer2.offline.DownloaderConstructorHelper; import com.google.android.exoplayer2.offline.StreamKey; import com.google.android.exoplayer2.source.dash.DashUtil; @@ -37,36 +39,38 @@ import com.google.android.exoplayer2.util.Util; import java.io.File; import java.util.ArrayList; import java.util.List; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; -/** - * Tests downloaded DASH playbacks. - */ -public final class DashDownloadTest extends ActivityInstrumentationTestCase2 { +/** Tests downloaded DASH playbacks. */ +@RunWith(AndroidJUnit4.class) +public final class DashDownloadTest { private static final String TAG = "DashDownloadTest"; private static final Uri MANIFEST_URI = Uri.parse(DashTestData.H264_MANIFEST); + @Rule public ActivityTestRule testRule = new ActivityTestRule<>(HostActivity.class); + private DashTestRunner testRunner; private File tempFolder; private SimpleCache cache; private DefaultHttpDataSourceFactory httpDataSourceFactory; private CacheDataSourceFactory offlineDataSourceFactory; - public DashDownloadTest() { - super(HostActivity.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - testRunner = new DashTestRunner(TAG, getActivity(), getInstrumentation()) - .setManifestUrl(DashTestData.H264_MANIFEST) - .setFullPlaybackNoSeeking(true) - .setCanIncludeAdditionalVideoFormats(false) - .setAudioVideoFormats(DashTestData.AAC_AUDIO_REPRESENTATION_ID, - DashTestData.H264_CDD_FIXED); - tempFolder = Util.createTempDirectory(getActivity(), "ExoPlayerTest"); + @Before + public void setUp() throws Exception { + testRunner = + new DashTestRunner(TAG, testRule.getActivity(), getInstrumentation()) + .setManifestUrl(DashTestData.H264_MANIFEST) + .setFullPlaybackNoSeeking(true) + .setCanIncludeAdditionalVideoFormats(false) + .setAudioVideoFormats( + DashTestData.AAC_AUDIO_REPRESENTATION_ID, DashTestData.H264_CDD_FIXED); + tempFolder = Util.createTempDirectory(testRule.getActivity(), "ExoPlayerTest"); cache = new SimpleCache(tempFolder, new NoOpCacheEvictor()); httpDataSourceFactory = new DefaultHttpDataSourceFactory("ExoPlayer", null); offlineDataSourceFactory = @@ -74,16 +78,16 @@ public final class DashDownloadTest extends ActivityInstrumentationTestCase2 { +/** Tests DASH playbacks using {@link ExoPlayer}. */ +@RunWith(AndroidJUnit4.class) +public final class DashStreamingTest { private static final String TAG = "DashStreamingTest"; @@ -78,27 +84,24 @@ public final class DashStreamingTest extends ActivityInstrumentationTestCase2 testRule = new ActivityTestRule<>(HostActivity.class); + private DashTestRunner testRunner; - public DashStreamingTest() { - super(HostActivity.class); + @Before + public void setUp() { + testRunner = new DashTestRunner(TAG, testRule.getActivity(), getInstrumentation()); } - @Override - protected void setUp() throws Exception { - super.setUp(); - testRunner = new DashTestRunner(TAG, getActivity(), getInstrumentation()); - } - - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() { testRunner = null; - super.tearDown(); } // H264 CDD. + @Test public void testH264Fixed() { if (Util.SDK_INT < 16) { // Pass. @@ -113,6 +116,7 @@ public final class DashStreamingTest extends ActivityInstrumentationTestCase2 { +/** Tests Widevine encrypted DASH playbacks using offline keys. */ +@RunWith(AndroidJUnit4.class) +public final class DashWidevineOfflineTest { private static final String TAG = "DashWidevineOfflineTest"; private static final String USER_AGENT = "ExoPlayerPlaybackTests"; @@ -50,21 +57,20 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa private OfflineLicenseHelper offlineLicenseHelper; private byte[] offlineLicenseKeySetId; - public DashWidevineOfflineTest() { - super(HostActivity.class); - } + @Rule public ActivityTestRule testRule = new ActivityTestRule<>(HostActivity.class); - @Override - protected void setUp() throws Exception { - super.setUp(); - testRunner = new DashTestRunner(TAG, getActivity(), getInstrumentation()) - .setStreamName("test_widevine_h264_fixed_offline") - .setManifestUrl(DashTestData.WIDEVINE_H264_MANIFEST) - .setWidevineInfo(MimeTypes.VIDEO_H264, true) - .setFullPlaybackNoSeeking(true) - .setCanIncludeAdditionalVideoFormats(false) - .setAudioVideoFormats(DashTestData.WIDEVINE_AAC_AUDIO_REPRESENTATION_ID, - DashTestData.WIDEVINE_H264_CDD_FIXED); + @Before + public void setUp() throws Exception { + testRunner = + new DashTestRunner(TAG, testRule.getActivity(), getInstrumentation()) + .setStreamName("test_widevine_h264_fixed_offline") + .setManifestUrl(DashTestData.WIDEVINE_H264_MANIFEST) + .setWidevineInfo(MimeTypes.VIDEO_H264, true) + .setFullPlaybackNoSeeking(true) + .setCanIncludeAdditionalVideoFormats(false) + .setAudioVideoFormats( + DashTestData.WIDEVINE_AAC_AUDIO_REPRESENTATION_ID, + DashTestData.WIDEVINE_H264_CDD_FIXED); boolean useL1Widevine = DashTestRunner.isL1WidevineAvailable(MimeTypes.VIDEO_H264); String widevineLicenseUrl = DashTestData.getWidevineLicenseUrl(true, useL1Widevine); @@ -75,8 +81,8 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa } } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { testRunner = null; if (offlineLicenseKeySetId != null) { releaseLicense(); @@ -86,11 +92,11 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa } offlineLicenseHelper = null; httpDataSourceFactory = null; - super.tearDown(); } // Offline license tests + @Test public void testWidevineOfflineLicenseV22() throws Exception { if (Util.SDK_INT < 22) { return; // Pass. @@ -103,6 +109,7 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa assertThat(offlineLicenseKeySetId).isNotNull(); } + @Test public void testWidevineOfflineReleasedLicenseV22() throws Throwable { if (Util.SDK_INT < 22) { return; // Pass. @@ -129,6 +136,7 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa } } + @Test public void testWidevineOfflineExpiredLicenseV22() throws Exception { if (Util.SDK_INT < 22) { return; // Pass. @@ -158,6 +166,7 @@ public final class DashWidevineOfflineTest extends ActivityInstrumentationTestCa testRunner.run(); } + @Test public void testWidevineOfflineLicenseExpiresOnPauseV22() throws Exception { if (Util.SDK_INT < 22) { return; // Pass. diff --git a/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/EnumerateDecodersTest.java b/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/EnumerateDecodersTest.java index 5157ab672c..669a5a5a0d 100644 --- a/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/EnumerateDecodersTest.java +++ b/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/EnumerateDecodersTest.java @@ -15,11 +15,13 @@ */ package com.google.android.exoplayer2.playbacktests.gts; +import static androidx.test.InstrumentationRegistry.getInstrumentation; + import android.media.MediaCodecInfo.AudioCapabilities; import android.media.MediaCodecInfo.CodecCapabilities; import android.media.MediaCodecInfo.CodecProfileLevel; import android.media.MediaCodecInfo.VideoCapabilities; -import android.test.InstrumentationTestCase; +import androidx.test.runner.AndroidJUnit4; import com.google.android.exoplayer2.mediacodec.MediaCodecInfo; import com.google.android.exoplayer2.mediacodec.MediaCodecUtil; import com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException; @@ -29,9 +31,13 @@ import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.Util; import java.util.Arrays; import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; /** Tests enumeration of decoders using {@link MediaCodecUtil}. */ -public class EnumerateDecodersTest extends InstrumentationTestCase { +@RunWith(AndroidJUnit4.class) +public class EnumerateDecodersTest { private static final String TAG = "EnumerateDecodersTest"; @@ -40,14 +46,14 @@ public class EnumerateDecodersTest extends InstrumentationTestCase { private MetricsLogger metricsLogger; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() { metricsLogger = MetricsLogger.Factory.createDefault( getInstrumentation(), TAG, REPORT_NAME, REPORT_OBJECT_NAME); } + @Test public void testEnumerateDecoders() throws Exception { enumerateDecoders(MimeTypes.VIDEO_H263); enumerateDecoders(MimeTypes.VIDEO_H264);