mirror of
https://github.com/androidx/media.git
synced 2025-05-06 23:20:42 +08:00
Fix ImaPlaybackTest
This test is not run in presubmit as it was too flaky, and is currently broken due to assets moving. Also migrate off ImaPlaybackTest off deprecated APIs. #minor-release PiperOrigin-RevId: 340405666
This commit is contained in:
parent
c9683195c0
commit
3f9488b7cd
@ -47,8 +47,10 @@ import com.google.android.exoplayer2.testutil.HostActivity;
|
|||||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||||
import com.google.android.exoplayer2.trackselection.MappingTrackSelector;
|
import com.google.android.exoplayer2.trackselection.MappingTrackSelector;
|
||||||
import com.google.android.exoplayer2.upstream.DataSource;
|
import com.google.android.exoplayer2.upstream.DataSource;
|
||||||
|
import com.google.android.exoplayer2.upstream.DataSpec;
|
||||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -78,7 +80,7 @@ public final class ImaPlaybackTest {
|
|||||||
@Test
|
@Test
|
||||||
public void playbackWithPrerollAdTag_playsAdAndContent() throws Exception {
|
public void playbackWithPrerollAdTag_playsAdAndContent() throws Exception {
|
||||||
String adsResponse =
|
String adsResponse =
|
||||||
TestUtil.getString(/* context= */ testRule.getActivity(), "ad-responses/preroll.xml");
|
TestUtil.getString(/* context= */ testRule.getActivity(), "media/ad-responses/preroll.xml");
|
||||||
AdId[] expectedAdIds = new AdId[] {ad(0), CONTENT};
|
AdId[] expectedAdIds = new AdId[] {ad(0), CONTENT};
|
||||||
ImaHostedTest hostedTest =
|
ImaHostedTest hostedTest =
|
||||||
new ImaHostedTest(Uri.parse(CONTENT_URI_SHORT), adsResponse, expectedAdIds);
|
new ImaHostedTest(Uri.parse(CONTENT_URI_SHORT), adsResponse, expectedAdIds);
|
||||||
@ -90,7 +92,8 @@ public final class ImaPlaybackTest {
|
|||||||
public void playbackWithMidrolls_playsAdAndContent() throws Exception {
|
public void playbackWithMidrolls_playsAdAndContent() throws Exception {
|
||||||
String adsResponse =
|
String adsResponse =
|
||||||
TestUtil.getString(
|
TestUtil.getString(
|
||||||
/* context= */ testRule.getActivity(), "ad-responses/preroll_midroll6s_postroll.xml");
|
/* context= */ testRule.getActivity(),
|
||||||
|
"media/ad-responses/preroll_midroll6s_postroll.xml");
|
||||||
AdId[] expectedAdIds = new AdId[] {ad(0), CONTENT, ad(1), CONTENT, ad(2), CONTENT};
|
AdId[] expectedAdIds = new AdId[] {ad(0), CONTENT, ad(1), CONTENT, ad(2), CONTENT};
|
||||||
ImaHostedTest hostedTest =
|
ImaHostedTest hostedTest =
|
||||||
new ImaHostedTest(Uri.parse(CONTENT_URI_SHORT), adsResponse, expectedAdIds);
|
new ImaHostedTest(Uri.parse(CONTENT_URI_SHORT), adsResponse, expectedAdIds);
|
||||||
@ -102,7 +105,7 @@ public final class ImaPlaybackTest {
|
|||||||
public void playbackWithMidrolls1And7_playsAdsAndContent() throws Exception {
|
public void playbackWithMidrolls1And7_playsAdsAndContent() throws Exception {
|
||||||
String adsResponse =
|
String adsResponse =
|
||||||
TestUtil.getString(
|
TestUtil.getString(
|
||||||
/* context= */ testRule.getActivity(), "ad-responses/midroll1s_midroll7s.xml");
|
/* context= */ testRule.getActivity(), "media/ad-responses/midroll1s_midroll7s.xml");
|
||||||
AdId[] expectedAdIds = new AdId[] {CONTENT, ad(0), CONTENT, ad(1), CONTENT};
|
AdId[] expectedAdIds = new AdId[] {CONTENT, ad(0), CONTENT, ad(1), CONTENT};
|
||||||
ImaHostedTest hostedTest =
|
ImaHostedTest hostedTest =
|
||||||
new ImaHostedTest(Uri.parse(CONTENT_URI_SHORT), adsResponse, expectedAdIds);
|
new ImaHostedTest(Uri.parse(CONTENT_URI_SHORT), adsResponse, expectedAdIds);
|
||||||
@ -114,7 +117,7 @@ public final class ImaPlaybackTest {
|
|||||||
public void playbackWithMidrolls10And20WithSeekTo12_playsAdsAndContent() throws Exception {
|
public void playbackWithMidrolls10And20WithSeekTo12_playsAdsAndContent() throws Exception {
|
||||||
String adsResponse =
|
String adsResponse =
|
||||||
TestUtil.getString(
|
TestUtil.getString(
|
||||||
/* context= */ testRule.getActivity(), "ad-responses/midroll10s_midroll20s.xml");
|
/* context= */ testRule.getActivity(), "media/ad-responses/midroll10s_midroll20s.xml");
|
||||||
AdId[] expectedAdIds = new AdId[] {CONTENT, ad(0), CONTENT, ad(1), CONTENT};
|
AdId[] expectedAdIds = new AdId[] {CONTENT, ad(0), CONTENT, ad(1), CONTENT};
|
||||||
ImaHostedTest hostedTest =
|
ImaHostedTest hostedTest =
|
||||||
new ImaHostedTest(Uri.parse(CONTENT_URI_LONG), adsResponse, expectedAdIds);
|
new ImaHostedTest(Uri.parse(CONTENT_URI_LONG), adsResponse, expectedAdIds);
|
||||||
@ -131,7 +134,7 @@ public final class ImaPlaybackTest {
|
|||||||
public void playbackWithMidrolls10And20WithSeekTo18_playsAdsAndContent() throws Exception {
|
public void playbackWithMidrolls10And20WithSeekTo18_playsAdsAndContent() throws Exception {
|
||||||
String adsResponse =
|
String adsResponse =
|
||||||
TestUtil.getString(
|
TestUtil.getString(
|
||||||
/* context= */ testRule.getActivity(), "ad-responses/midroll10s_midroll20s.xml");
|
/* context= */ testRule.getActivity(), "media/ad-responses/midroll10s_midroll20s.xml");
|
||||||
AdId[] expectedAdIds = new AdId[] {CONTENT, ad(0), CONTENT, ad(1), CONTENT};
|
AdId[] expectedAdIds = new AdId[] {CONTENT, ad(0), CONTENT, ad(1), CONTENT};
|
||||||
ImaHostedTest hostedTest =
|
ImaHostedTest hostedTest =
|
||||||
new ImaHostedTest(Uri.parse(CONTENT_URI_LONG), adsResponse, expectedAdIds);
|
new ImaHostedTest(Uri.parse(CONTENT_URI_LONG), adsResponse, expectedAdIds);
|
||||||
@ -190,7 +193,7 @@ public final class ImaPlaybackTest {
|
|||||||
private static final class ImaHostedTest extends ExoHostedTest implements EventListener {
|
private static final class ImaHostedTest extends ExoHostedTest implements EventListener {
|
||||||
|
|
||||||
private final Uri contentUri;
|
private final Uri contentUri;
|
||||||
private final String adsResponse;
|
private final DataSpec adTagDataSpec;
|
||||||
private final List<AdId> expectedAdIds;
|
private final List<AdId> expectedAdIds;
|
||||||
private final List<AdId> seenAdIds;
|
private final List<AdId> seenAdIds;
|
||||||
private @MonotonicNonNull ImaAdsLoader imaAdsLoader;
|
private @MonotonicNonNull ImaAdsLoader imaAdsLoader;
|
||||||
@ -201,7 +204,9 @@ public final class ImaPlaybackTest {
|
|||||||
// duration due to ad playback, so the hosted test shouldn't assert the playing duration.
|
// duration due to ad playback, so the hosted test shouldn't assert the playing duration.
|
||||||
super(ImaPlaybackTest.class.getSimpleName(), /* fullPlaybackNoSeeking= */ false);
|
super(ImaPlaybackTest.class.getSimpleName(), /* fullPlaybackNoSeeking= */ false);
|
||||||
this.contentUri = contentUri;
|
this.contentUri = contentUri;
|
||||||
this.adsResponse = adsResponse;
|
this.adTagDataSpec =
|
||||||
|
new DataSpec(
|
||||||
|
Util.getDataUriForString(/* mimeType= */ "text/xml", /* data= */ adsResponse));
|
||||||
this.expectedAdIds = Arrays.asList(expectedAdIds);
|
this.expectedAdIds = Arrays.asList(expectedAdIds);
|
||||||
seenAdIds = new ArrayList<>();
|
seenAdIds = new ArrayList<>();
|
||||||
}
|
}
|
||||||
@ -226,7 +231,7 @@ public final class ImaPlaybackTest {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
Context context = host.getApplicationContext();
|
Context context = host.getApplicationContext();
|
||||||
imaAdsLoader = new ImaAdsLoader.Builder(context).buildForAdsResponse(adsResponse);
|
imaAdsLoader = new ImaAdsLoader.Builder(context).build();
|
||||||
imaAdsLoader.setPlayer(player);
|
imaAdsLoader.setPlayer(player);
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
@ -242,7 +247,8 @@ public final class ImaPlaybackTest {
|
|||||||
new DefaultMediaSourceFactory(context).createMediaSource(MediaItem.fromUri(contentUri));
|
new DefaultMediaSourceFactory(context).createMediaSource(MediaItem.fromUri(contentUri));
|
||||||
return new AdsMediaSource(
|
return new AdsMediaSource(
|
||||||
contentMediaSource,
|
contentMediaSource,
|
||||||
dataSourceFactory,
|
adTagDataSpec,
|
||||||
|
new DefaultMediaSourceFactory(dataSourceFactory),
|
||||||
Assertions.checkNotNull(imaAdsLoader),
|
Assertions.checkNotNull(imaAdsLoader),
|
||||||
new AdViewProvider() {
|
new AdViewProvider() {
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<MediaFiles>
|
<MediaFiles>
|
||||||
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
file:///android_asset/mp4/midroll-5s.mp4
|
file:///android_asset/media/mp4/midroll-5s.mp4
|
||||||
]]>
|
]]>
|
||||||
</MediaFile>
|
</MediaFile>
|
||||||
</MediaFiles>
|
</MediaFiles>
|
||||||
@ -48,7 +48,7 @@ file:///android_asset/mp4/midroll-5s.mp4
|
|||||||
<MediaFiles>
|
<MediaFiles>
|
||||||
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
file:///android_asset/mp4/midroll-5s.mp4
|
file:///android_asset/media/mp4/midroll-5s.mp4
|
||||||
]]>
|
]]>
|
||||||
</MediaFile>
|
</MediaFile>
|
||||||
</MediaFiles>
|
</MediaFiles>
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<MediaFiles>
|
<MediaFiles>
|
||||||
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
file:///android_asset/mp4/midroll-5s.mp4
|
file:///android_asset/media/mp4/midroll-5s.mp4
|
||||||
]]>
|
]]>
|
||||||
</MediaFile>
|
</MediaFile>
|
||||||
</MediaFiles>
|
</MediaFiles>
|
||||||
@ -48,7 +48,7 @@ file:///android_asset/mp4/midroll-5s.mp4
|
|||||||
<MediaFiles>
|
<MediaFiles>
|
||||||
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
file:///android_asset/mp4/midroll-5s.mp4
|
file:///android_asset/media/mp4/midroll-5s.mp4
|
||||||
]]>
|
]]>
|
||||||
</MediaFile>
|
</MediaFile>
|
||||||
</MediaFiles>
|
</MediaFiles>
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<MediaFiles>
|
<MediaFiles>
|
||||||
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
file:///android_asset/mp4/preroll-5s.mp4
|
file:///android_asset/media/mp4/preroll-5s.mp4
|
||||||
]]>
|
]]>
|
||||||
</MediaFile>
|
</MediaFile>
|
||||||
</MediaFiles>
|
</MediaFiles>
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<MediaFiles>
|
<MediaFiles>
|
||||||
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
file:///android_asset/mp4/preroll-5s.mp4
|
file:///android_asset/media/mp4/preroll-5s.mp4
|
||||||
]]>
|
]]>
|
||||||
</MediaFile>
|
</MediaFile>
|
||||||
</MediaFiles>
|
</MediaFiles>
|
||||||
@ -48,7 +48,7 @@ file:///android_asset/mp4/preroll-5s.mp4
|
|||||||
<MediaFiles>
|
<MediaFiles>
|
||||||
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
file:///android_asset/mp4/midroll-5s.mp4
|
file:///android_asset/media/mp4/midroll-5s.mp4
|
||||||
]]>
|
]]>
|
||||||
</MediaFile>
|
</MediaFile>
|
||||||
</MediaFiles>
|
</MediaFiles>
|
||||||
@ -79,7 +79,7 @@ file:///android_asset/mp4/midroll-5s.mp4
|
|||||||
<MediaFiles>
|
<MediaFiles>
|
||||||
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
<MediaFile id="GDFP" delivery="progressive" width="640" height="360" type="video/mp4" bitrate="450" scalable="true" maintainAspectRatio="true">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
file:///android_asset/mp4/postroll-5s.mp4
|
file:///android_asset/media/mp4/postroll-5s.mp4
|
||||||
]]>
|
]]>
|
||||||
</MediaFile>
|
</MediaFile>
|
||||||
</MediaFiles>
|
</MediaFiles>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user