Migrate ExoPlayerTest.playEmptyTimeline to TestExoPlayer
PiperOrigin-RevId: 323544694
This commit is contained in:
parent
437275caed
commit
ce0f814b77
@ -17,13 +17,18 @@ package com.google.android.exoplayer2;
|
|||||||
|
|
||||||
import static com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM;
|
import static com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM;
|
||||||
import static com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.oneByteSample;
|
import static com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.oneByteSample;
|
||||||
|
import static com.google.android.exoplayer2.testutil.TestExoPlayer.runUntilPlaybackState;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertThrows;
|
import static org.junit.Assert.assertThrows;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.ArgumentMatchers.argThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.inOrder;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.robolectric.Shadows.shadowOf;
|
import static org.robolectric.Shadows.shadowOf;
|
||||||
@ -82,6 +87,7 @@ import com.google.android.exoplayer2.testutil.FakeTimeline;
|
|||||||
import com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition;
|
import com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition;
|
||||||
import com.google.android.exoplayer2.testutil.FakeTrackSelection;
|
import com.google.android.exoplayer2.testutil.FakeTrackSelection;
|
||||||
import com.google.android.exoplayer2.testutil.FakeTrackSelector;
|
import com.google.android.exoplayer2.testutil.FakeTrackSelector;
|
||||||
|
import com.google.android.exoplayer2.testutil.NoUidTimeline;
|
||||||
import com.google.android.exoplayer2.testutil.TestExoPlayer;
|
import com.google.android.exoplayer2.testutil.TestExoPlayer;
|
||||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
||||||
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||||
@ -110,6 +116,8 @@ import org.junit.Before;
|
|||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentMatcher;
|
||||||
|
import org.mockito.InOrder;
|
||||||
import org.robolectric.shadows.ShadowAudioManager;
|
import org.robolectric.shadows.ShadowAudioManager;
|
||||||
|
|
||||||
/** Unit test for {@link ExoPlayer}. */
|
/** Unit test for {@link ExoPlayer}. */
|
||||||
@ -146,18 +154,27 @@ public final class ExoPlayerTest {
|
|||||||
Timeline expectedMaskingTimeline =
|
Timeline expectedMaskingTimeline =
|
||||||
new MaskingMediaSource.PlaceholderTimeline(FakeMediaSource.FAKE_MEDIA_ITEM);
|
new MaskingMediaSource.PlaceholderTimeline(FakeMediaSource.FAKE_MEDIA_ITEM);
|
||||||
FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_UNKNOWN);
|
FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_UNKNOWN);
|
||||||
ExoPlayerTestRunner testRunner =
|
|
||||||
new ExoPlayerTestRunner.Builder(context)
|
SimpleExoPlayer player = new TestExoPlayer.Builder(context).setRenderers(renderer).build();
|
||||||
.setTimeline(timeline)
|
EventListener mockEventListener = mock(EventListener.class);
|
||||||
.setRenderers(renderer)
|
player.addListener(mockEventListener);
|
||||||
.build()
|
|
||||||
.start()
|
player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT));
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
player.prepare();
|
||||||
testRunner.assertNoPositionDiscontinuities();
|
player.play();
|
||||||
testRunner.assertTimelinesSame(expectedMaskingTimeline, Timeline.EMPTY);
|
runUntilPlaybackState(player, Player.STATE_ENDED);
|
||||||
testRunner.assertTimelineChangeReasonsEqual(
|
|
||||||
Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED,
|
InOrder inOrder = inOrder(mockEventListener);
|
||||||
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
|
inOrder
|
||||||
|
.verify(mockEventListener)
|
||||||
|
.onTimelineChanged(
|
||||||
|
argThat(noUid(expectedMaskingTimeline)),
|
||||||
|
eq(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED));
|
||||||
|
inOrder
|
||||||
|
.verify(mockEventListener)
|
||||||
|
.onTimelineChanged(
|
||||||
|
argThat(noUid(timeline)), eq(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE));
|
||||||
|
inOrder.verify(mockEventListener, never()).onPositionDiscontinuity(anyInt());
|
||||||
assertThat(renderer.getFormatsRead()).isEmpty();
|
assertThat(renderer.getFormatsRead()).isEmpty();
|
||||||
assertThat(renderer.sampleBufferReadCount).isEqualTo(0);
|
assertThat(renderer.sampleBufferReadCount).isEqualTo(0);
|
||||||
assertThat(renderer.isEnded).isFalse();
|
assertThat(renderer.isEnded).isFalse();
|
||||||
@ -2525,7 +2542,7 @@ public final class ExoPlayerTest {
|
|||||||
// indices are non-zero.
|
// indices are non-zero.
|
||||||
player.prepare();
|
player.prepare();
|
||||||
player.play();
|
player.play();
|
||||||
TestExoPlayer.runUntilPlaybackState(player, Player.STATE_ENDED);
|
runUntilPlaybackState(player, Player.STATE_ENDED);
|
||||||
verify(secondMediaItemTarget).handleMessage(anyInt(), any());
|
verify(secondMediaItemTarget).handleMessage(anyInt(), any());
|
||||||
|
|
||||||
// Remove first item and play second item again to check if message is triggered again.
|
// Remove first item and play second item again to check if message is triggered again.
|
||||||
@ -2534,7 +2551,7 @@ public final class ExoPlayerTest {
|
|||||||
// See https://github.com/google/ExoPlayer/issues/7278.
|
// See https://github.com/google/ExoPlayer/issues/7278.
|
||||||
player.removeMediaItem(/* index= */ 0);
|
player.removeMediaItem(/* index= */ 0);
|
||||||
player.seekTo(/* positionMs= */ 0);
|
player.seekTo(/* positionMs= */ 0);
|
||||||
TestExoPlayer.runUntilPlaybackState(player, Player.STATE_ENDED);
|
runUntilPlaybackState(player, Player.STATE_ENDED);
|
||||||
|
|
||||||
assertThat(player.getPlayerError()).isNull();
|
assertThat(player.getPlayerError()).isNull();
|
||||||
verify(secondMediaItemTarget, times(2)).handleMessage(anyInt(), any());
|
verify(secondMediaItemTarget, times(2)).handleMessage(anyInt(), any());
|
||||||
@ -8344,4 +8361,16 @@ public final class ExoPlayerTest {
|
|||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an argument matcher for {@link Timeline} instances that ignores period and window uids.
|
||||||
|
*/
|
||||||
|
private static ArgumentMatcher<Timeline> noUid(Timeline timeline) {
|
||||||
|
return new ArgumentMatcher<Timeline>() {
|
||||||
|
@Override
|
||||||
|
public boolean matches(Timeline argument) {
|
||||||
|
return new NoUidTimeline(timeline).equals(new NoUidTimeline(argument));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import com.google.android.exoplayer2.source.ForwardingTimeline;
|
|||||||
* A timeline which wraps another timeline and overrides all window and period uids to 0. This is
|
* A timeline which wraps another timeline and overrides all window and period uids to 0. This is
|
||||||
* useful for testing timeline equality without taking uids into account.
|
* useful for testing timeline equality without taking uids into account.
|
||||||
*/
|
*/
|
||||||
/* package */ class NoUidTimeline extends ForwardingTimeline {
|
public class NoUidTimeline extends ForwardingTimeline {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance.
|
* Creates an instance.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user