Support multiple transitions to STATE_ENDED in ExoPlayerTestRunner.

Currently testRunner.blockUntilEnded waits for the first transition to
STATE_ENDED or _IDLE before returning. In order to support tests with
player repreparations after one playback finished, this change adds an
option to specifiy the number of expected transitions to ended.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176484047
This commit is contained in:
tonihei 2017-11-21 02:44:09 -08:00 committed by Oliver Woodman
parent e1d960db68
commit a8d867be37

View file

@ -100,6 +100,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener {
private RenderersFactory renderersFactory;
private ActionSchedule actionSchedule;
private Player.EventListener eventListener;
private Integer expectedPlayerEndedCount;
/**
* Sets a {@link Timeline} to be used by a {@link FakeMediaSource} in the test runner. The
@ -255,6 +256,20 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener {
return this;
}
/**
* Sets the number of times the test runner is expected to reach the {@link Player#STATE_ENDED}
* or {@link Player#STATE_IDLE}. The default is 1. This affects how long
* {@link ExoPlayerTestRunner#blockUntilEnded(long)} waits.
*
* @param expectedPlayerEndedCount The number of times the player is expected to reach the ended
* or idle state.
* @return This builder.
*/
public Builder setExpectedPlayerEndedCount(int expectedPlayerEndedCount) {
this.expectedPlayerEndedCount = expectedPlayerEndedCount;
return this;
}
/**
* Builds an {@link ExoPlayerTestRunner} using the provided values or their defaults.
*
@ -299,8 +314,11 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener {
}
mediaSource = new FakeMediaSource(timeline, manifest, supportedFormats);
}
if (expectedPlayerEndedCount == null) {
expectedPlayerEndedCount = 1;
}
return new ExoPlayerTestRunner(playerFactory, mediaSource, renderersFactory, trackSelector,
loadControl, actionSchedule, eventListener);
loadControl, actionSchedule, eventListener, expectedPlayerEndedCount);
}
}
@ -328,7 +346,8 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener {
private ExoPlayerTestRunner(PlayerFactory playerFactory, MediaSource mediaSource,
RenderersFactory renderersFactory, MappingTrackSelector trackSelector,
LoadControl loadControl, ActionSchedule actionSchedule, Player.EventListener eventListener) {
LoadControl loadControl, ActionSchedule actionSchedule, Player.EventListener eventListener,
int expectedPlayerEndedCount) {
this.playerFactory = playerFactory;
this.mediaSource = mediaSource;
this.renderersFactory = renderersFactory;
@ -341,7 +360,7 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener {
this.timelineChangeReasons = new ArrayList<>();
this.periodIndices = new ArrayList<>();
this.discontinuityReasons = new ArrayList<>();
this.endedCountDownLatch = new CountDownLatch(1);
this.endedCountDownLatch = new CountDownLatch(expectedPlayerEndedCount);
this.playerThread = new HandlerThread("ExoPlayerTest thread");
playerThread.start();
this.handler = new Handler(playerThread.getLooper());
@ -514,7 +533,9 @@ public final class ExoPlayerTestRunner extends Player.DefaultEventListener {
if (this.exception == null) {
this.exception = exception;
}
endedCountDownLatch.countDown();
while (endedCountDownLatch.getCount() > 0) {
endedCountDownLatch.countDown();
}
}
// Player.EventListener