mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
MediaControllerListenerTest: use local MediaController instances
Replace the instance-field MediaController with a local instance created in each test. PiperOrigin-RevId: 480039768
This commit is contained in:
parent
5d6d069e4e
commit
ba1ecafb8f
@ -123,7 +123,6 @@ public class MediaControllerListenerTest {
|
|||||||
Context context;
|
Context context;
|
||||||
private RemoteMediaSession remoteSession;
|
private RemoteMediaSession remoteSession;
|
||||||
private List<RemoteMediaSession> sessions;
|
private List<RemoteMediaSession> sessions;
|
||||||
private MediaController controller;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@ -200,15 +199,16 @@ public class MediaControllerListenerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void connection_sessionReleased() throws Exception {
|
public void connection_sessionReleased() throws Exception {
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
controllerTestRule.createController(
|
MediaController controller =
|
||||||
remoteSession.getToken(),
|
controllerTestRule.createController(
|
||||||
/* connectionHints= */ null,
|
remoteSession.getToken(),
|
||||||
new MediaController.Listener() {
|
/* connectionHints= */ null,
|
||||||
@Override
|
new MediaController.Listener() {
|
||||||
public void onDisconnected(MediaController controller) {
|
@Override
|
||||||
latch.countDown();
|
public void onDisconnected(MediaController controller) {
|
||||||
}
|
latch.countDown();
|
||||||
});
|
}
|
||||||
|
});
|
||||||
remoteSession.release();
|
remoteSession.release();
|
||||||
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
||||||
}
|
}
|
||||||
@ -246,7 +246,7 @@ public class MediaControllerListenerTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
public void noInteractionAfterSessionClose_session() throws Exception {
|
public void noInteractionAfterSessionClose_session() throws Exception {
|
||||||
SessionToken token = remoteSession.getToken();
|
SessionToken token = remoteSession.getToken();
|
||||||
controller = controllerTestRule.createController(token);
|
MediaController controller = controllerTestRule.createController(token);
|
||||||
testControllerAfterSessionIsClosed(DEFAULT_TEST_NAME);
|
testControllerAfterSessionIsClosed(DEFAULT_TEST_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,11 +254,11 @@ public class MediaControllerListenerTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
public void noInteractionAfterControllerClose_session() throws Exception {
|
public void noInteractionAfterControllerClose_session() throws Exception {
|
||||||
SessionToken token = remoteSession.getToken();
|
SessionToken token = remoteSession.getToken();
|
||||||
controller = controllerTestRule.createController(token);
|
MediaController controller = controllerTestRule.createController(token);
|
||||||
|
|
||||||
threadTestRule.getHandler().postAndSync(controller::release);
|
threadTestRule.getHandler().postAndSync(controller::release);
|
||||||
// release is done immediately for session.
|
// release is done immediately for session.
|
||||||
testNoInteraction();
|
testNoInteraction(controller);
|
||||||
|
|
||||||
// Test whether the controller is notified about later release of the session or
|
// Test whether the controller is notified about later release of the session or
|
||||||
// re-creation.
|
// re-creation.
|
||||||
@ -337,7 +337,7 @@ public class MediaControllerListenerTest {
|
|||||||
AtomicBoolean shuffleModeEnabledRef = new AtomicBoolean();
|
AtomicBoolean shuffleModeEnabledRef = new AtomicBoolean();
|
||||||
AtomicInteger repeatModeRef = new AtomicInteger();
|
AtomicInteger repeatModeRef = new AtomicInteger();
|
||||||
CountDownLatch latch = new CountDownLatch(7);
|
CountDownLatch latch = new CountDownLatch(7);
|
||||||
controller = controllerTestRule.createController(remoteSession.getToken());
|
MediaController controller = controllerTestRule.createController(remoteSession.getToken());
|
||||||
threadTestRule
|
threadTestRule
|
||||||
.getHandler()
|
.getHandler()
|
||||||
.postAndSync(
|
.postAndSync(
|
||||||
@ -435,7 +435,7 @@ public class MediaControllerListenerTest {
|
|||||||
int testMediaItemIndex = 1;
|
int testMediaItemIndex = 1;
|
||||||
int testPeriodIndex = 2;
|
int testPeriodIndex = 2;
|
||||||
|
|
||||||
controller = controllerTestRule.createController(remoteSession.getToken());
|
MediaController controller = controllerTestRule.createController(remoteSession.getToken());
|
||||||
|
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
AtomicLong currentPositionMsRef = new AtomicLong();
|
AtomicLong currentPositionMsRef = new AtomicLong();
|
||||||
@ -642,7 +642,7 @@ public class MediaControllerListenerTest {
|
|||||||
long testCurrentLiveOffsetMs = 10;
|
long testCurrentLiveOffsetMs = 10;
|
||||||
long testContentBufferedPositionMs = 240;
|
long testContentBufferedPositionMs = 240;
|
||||||
|
|
||||||
controller = controllerTestRule.createController(remoteSession.getToken());
|
MediaController controller = controllerTestRule.createController(remoteSession.getToken());
|
||||||
|
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
AtomicReference<PlaybackParameters> playbackParametersRef = new AtomicReference<>();
|
AtomicReference<PlaybackParameters> playbackParametersRef = new AtomicReference<>();
|
||||||
@ -1189,7 +1189,7 @@ public class MediaControllerListenerTest {
|
|||||||
long testCurrentLiveOffsetMs = 10;
|
long testCurrentLiveOffsetMs = 10;
|
||||||
long testContentBufferedPositionMs = 240;
|
long testContentBufferedPositionMs = 240;
|
||||||
|
|
||||||
controller = controllerTestRule.createController(remoteSession.getToken());
|
MediaController controller = controllerTestRule.createController(remoteSession.getToken());
|
||||||
|
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
AtomicBoolean playWhenReadyRef = new AtomicBoolean();
|
AtomicBoolean playWhenReadyRef = new AtomicBoolean();
|
||||||
@ -1693,8 +1693,9 @@ public class MediaControllerListenerTest {
|
|||||||
latch.countDown();
|
latch.countDown();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
controllerTestRule.createController(
|
MediaController controller =
|
||||||
remoteSession.getToken(), /* connectionHints= */ null, listener);
|
controllerTestRule.createController(
|
||||||
|
remoteSession.getToken(), /* connectionHints= */ null, listener);
|
||||||
|
|
||||||
SessionCommands commands =
|
SessionCommands commands =
|
||||||
new SessionCommands.Builder()
|
new SessionCommands.Builder()
|
||||||
@ -1896,8 +1897,9 @@ public class MediaControllerListenerTest {
|
|||||||
return Futures.immediateFuture(new SessionResult(RESULT_SUCCESS));
|
return Futures.immediateFuture(new SessionResult(RESULT_SUCCESS));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
controllerTestRule.createController(
|
MediaController controller =
|
||||||
remoteSession.getToken(), /* connectionHints= */ null, listener);
|
controllerTestRule.createController(
|
||||||
|
remoteSession.getToken(), /* connectionHints= */ null, listener);
|
||||||
|
|
||||||
// TODO(b/245724167): Test with multiple controllers
|
// TODO(b/245724167): Test with multiple controllers
|
||||||
remoteSession.broadcastCustomCommand(testCommand, testArgs);
|
remoteSession.broadcastCustomCommand(testCommand, testArgs);
|
||||||
@ -1951,7 +1953,9 @@ public class MediaControllerListenerTest {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
RemoteMediaSession session = createRemoteMediaSession(TEST_WITH_CUSTOM_COMMANDS);
|
RemoteMediaSession session = createRemoteMediaSession(TEST_WITH_CUSTOM_COMMANDS);
|
||||||
controllerTestRule.createController(session.getToken(), /* connectionHints= */ null, listener);
|
MediaController controller =
|
||||||
|
controllerTestRule.createController(
|
||||||
|
session.getToken(), /* connectionHints= */ null, listener);
|
||||||
|
|
||||||
session.setCustomLayout(buttons);
|
session.setCustomLayout(buttons);
|
||||||
|
|
||||||
@ -1979,8 +1983,9 @@ public class MediaControllerListenerTest {
|
|||||||
latch.countDown();
|
latch.countDown();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
controllerTestRule.createController(
|
MediaController controller =
|
||||||
remoteSession.getToken(), /* connectionHints= */ null, listener);
|
controllerTestRule.createController(
|
||||||
|
remoteSession.getToken(), /* connectionHints= */ null, listener);
|
||||||
|
|
||||||
remoteSession.setSessionExtras(sessionExtras);
|
remoteSession.setSessionExtras(sessionExtras);
|
||||||
|
|
||||||
@ -2005,7 +2010,8 @@ public class MediaControllerListenerTest {
|
|||||||
};
|
};
|
||||||
Bundle connectionHints = new Bundle();
|
Bundle connectionHints = new Bundle();
|
||||||
connectionHints.putString(KEY_CONTROLLER, "controller_key_1");
|
connectionHints.putString(KEY_CONTROLLER, "controller_key_1");
|
||||||
controllerTestRule.createController(remoteSession.getToken(), connectionHints, listener);
|
MediaController controller =
|
||||||
|
controllerTestRule.createController(remoteSession.getToken(), connectionHints, listener);
|
||||||
|
|
||||||
remoteSession.setSessionExtras("controller_key_1", sessionExtras);
|
remoteSession.setSessionExtras("controller_key_1", sessionExtras);
|
||||||
|
|
||||||
@ -2593,22 +2599,23 @@ public class MediaControllerListenerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void testControllerAfterSessionIsClosed(String id) throws Exception {
|
private void testControllerAfterSessionIsClosed(String id) throws Exception {
|
||||||
// This cause session service to be died.
|
MediaController controller = controllerTestRule.createController(remoteSession.getToken());
|
||||||
|
// This causes the session service to die.
|
||||||
remoteSession.release();
|
remoteSession.release();
|
||||||
// controllerTestRule.waitForDisconnect(controller, true);
|
// controllerTestRule.waitForDisconnect(controller, true);
|
||||||
testNoInteraction();
|
testNoInteraction(controller);
|
||||||
|
|
||||||
// Ensure that the controller cannot use newly create session with the same ID.
|
// Ensure that the controller cannot use newly create session with the same ID.
|
||||||
// Recreated session has different session stub, so previously created controller
|
// Recreated session has different session stub, so previously created controller
|
||||||
// shouldn't be available.
|
// shouldn't be available.
|
||||||
remoteSession = createRemoteMediaSession(id);
|
remoteSession = createRemoteMediaSession(id);
|
||||||
testNoInteraction();
|
testNoInteraction(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that session and controller doesn't interact.
|
// Test that session and controller doesn't interact.
|
||||||
// Note that this method can be called after the session is died, so session may not have
|
// Note that this method can be called after the session is died, so session may not have
|
||||||
// valid player.
|
// valid player.
|
||||||
private void testNoInteraction() throws Exception {
|
private void testNoInteraction(MediaController controller) throws Exception {
|
||||||
// TODO: check that calls from the controller to session shouldn't be delivered.
|
// TODO: check that calls from the controller to session shouldn't be delivered.
|
||||||
|
|
||||||
// Calls from the session to controller shouldn't be delivered.
|
// Calls from the session to controller shouldn't be delivered.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user