Amend WaitForTimelineChange action to allow waiting for arbitrary timeline.

In some situations, the timeline can't be specified because it is created
internally by the media source under test. If the test still needs to wait for
a timeline update, this change allows to do that by specifying an expected
timeline of null.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=190768386
This commit is contained in:
tonihei 2018-03-28 07:18:17 -07:00 committed by Oliver Woodman
parent e228947831
commit a71a87af5c
2 changed files with 21 additions and 15 deletions

View File

@ -544,12 +544,16 @@ public abstract class Action {
*/ */
public static final class WaitForTimelineChanged extends Action { public static final class WaitForTimelineChanged extends Action {
private final Timeline expectedTimeline; private final @Nullable Timeline expectedTimeline;
/** /**
* Creates action waiting for a timeline change.
*
* @param tag A tag to use for logging. * @param tag A tag to use for logging.
* @param expectedTimeline The expected timeline to wait for. If null, wait for any timeline
* change.
*/ */
public WaitForTimelineChanged(String tag, Timeline expectedTimeline) { public WaitForTimelineChanged(String tag, @Nullable Timeline expectedTimeline) {
super(tag, "WaitForTimelineChanged"); super(tag, "WaitForTimelineChanged");
this.expectedTimeline = expectedTimeline; this.expectedTimeline = expectedTimeline;
} }
@ -564,18 +568,19 @@ public abstract class Action {
if (nextAction == null) { if (nextAction == null) {
return; return;
} }
Player.EventListener listener = new Player.DefaultEventListener() { Player.EventListener listener =
new Player.DefaultEventListener() {
@Override @Override
public void onTimelineChanged(Timeline timeline, Object manifest, public void onTimelineChanged(
@Player.TimelineChangeReason int reason) { Timeline timeline, Object manifest, @Player.TimelineChangeReason int reason) {
if (timeline.equals(expectedTimeline)) { if (expectedTimeline == null || timeline.equals(expectedTimeline)) {
player.removeListener(this); player.removeListener(this);
nextAction.schedule(player, trackSelector, surface, handler); nextAction.schedule(player, trackSelector, surface, handler);
} }
} }
}; };
player.addListener(listener); player.addListener(listener);
if (player.getCurrentTimeline().equals(expectedTimeline)) { if (expectedTimeline != null && player.getCurrentTimeline().equals(expectedTimeline)) {
player.removeListener(listener); player.removeListener(listener);
nextAction.schedule(player, trackSelector, surface, handler); nextAction.schedule(player, trackSelector, surface, handler);
} }

View File

@ -378,10 +378,11 @@ public final class ActionSchedule {
/** /**
* Schedules a delay until the timeline changed to a specified expected timeline. * Schedules a delay until the timeline changed to a specified expected timeline.
* *
* @param expectedTimeline The expected timeline to wait for. * @param expectedTimeline The expected timeline to wait for. If null, wait for any timeline
* change.
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
public Builder waitForTimelineChanged(Timeline expectedTimeline) { public Builder waitForTimelineChanged(@Nullable Timeline expectedTimeline) {
return apply(new WaitForTimelineChanged(tag, expectedTimeline)); return apply(new WaitForTimelineChanged(tag, expectedTimeline));
} }