From daa063a0f8e15393f84e6857fa093c39ca7a0a70 Mon Sep 17 00:00:00 2001 From: christosts Date: Thu, 23 Jul 2020 12:17:39 +0100 Subject: [PATCH] Migrate MediaPeriodQueueTest to LooperMode.PAUSED PiperOrigin-RevId: 322760417 --- .../exoplayer2/MediaPeriodQueueTest.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/library/core/src/test/java/com/google/android/exoplayer2/MediaPeriodQueueTest.java b/library/core/src/test/java/com/google/android/exoplayer2/MediaPeriodQueueTest.java index 7ec39f9d72..80de5edfd9 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/MediaPeriodQueueTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/MediaPeriodQueueTest.java @@ -18,9 +18,11 @@ package com.google.android.exoplayer2; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertNull; import static org.mockito.Mockito.mock; -import static org.robolectric.annotation.LooperMode.Mode.LEGACY; +import static org.robolectric.Shadows.shadowOf; import android.net.Uri; +import android.os.Handler; +import android.os.Looper; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId; import com.google.android.exoplayer2.source.SinglePeriodTimeline; @@ -34,15 +36,12 @@ import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelectorResult; import com.google.android.exoplayer2.upstream.Allocator; -import com.google.android.exoplayer2.util.Util; import com.google.common.collect.ImmutableList; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.annotation.LooperMode; /** Unit tests for {@link MediaPeriodQueue}. */ -@LooperMode(LEGACY) @RunWith(AndroidJUnit4.class) public final class MediaPeriodQueueTest { @@ -75,13 +74,12 @@ public final class MediaPeriodQueueTest { @Before public void setUp() { mediaPeriodQueue = - new MediaPeriodQueue( - /* analyticsCollector= */ null, Util.createHandlerForCurrentOrMainLooper()); + new MediaPeriodQueue(/* analyticsCollector= */ null, new Handler(Looper.getMainLooper())); mediaSourceList = new MediaSourceList( mock(MediaSourceList.MediaSourceListInfoRefreshListener.class), /* analyticsCollector= */ null, - Util.createHandlerForCurrentOrMainLooper()); + new Handler(Looper.getMainLooper())); rendererCapabilities = new RendererCapabilities[0]; trackSelector = mock(TrackSelector.class); allocator = mock(Allocator.class); @@ -443,19 +441,6 @@ public final class MediaPeriodQueueTest { /* positionUs= */ 0); } - private void updateAdPlaybackStateAndTimeline(long... adGroupTimesUs) { - adPlaybackState = - new AdPlaybackState(adGroupTimesUs).withContentDurationUs(CONTENT_DURATION_US); - updateTimeline(); - } - - private void updateTimeline() { - SinglePeriodAdTimeline adTimeline = - new SinglePeriodAdTimeline(CONTENT_TIMELINE, adPlaybackState); - fakeMediaSource.setNewSourceInfo(adTimeline); - playbackInfo = playbackInfo.copyWithTimeline(mediaSourceList.createTimeline()); - } - private void advance() { enqueueNext(); if (mediaPeriodQueue.getLoadingPeriod() != mediaPeriodQueue.getPlayingPeriod()) { @@ -508,6 +493,21 @@ public final class MediaPeriodQueueTest { updateTimeline(); } + private void updateAdPlaybackStateAndTimeline(long... adGroupTimesUs) { + adPlaybackState = + new AdPlaybackState(adGroupTimesUs).withContentDurationUs(CONTENT_DURATION_US); + updateTimeline(); + } + + private void updateTimeline() { + SinglePeriodAdTimeline adTimeline = + new SinglePeriodAdTimeline(CONTENT_TIMELINE, adPlaybackState); + fakeMediaSource.setNewSourceInfo(adTimeline); + // Progress the looper so that the source info events have been executed. + shadowOf(Looper.getMainLooper()).idle(); + playbackInfo = playbackInfo.copyWithTimeline(mediaSourceList.createTimeline()); + } + private void assertGetNextMediaPeriodInfoReturnsContentMediaPeriod( Object periodUid, long startPositionUs,