use of androidx.test.filters.LargeTest in project android_packages_apps_Settings by omnirom.
the class PrintJobSettingsActivityTest method viewPrintJobSettings.
@Test
@LargeTest
public void viewPrintJobSettings() throws Exception {
UUID uuid = UUID.randomUUID();
Object isWriteCalled = new Object();
// Create adapter that is good enough to start a print preview
PrintDocumentAdapter adapter = new PrintDocumentAdapter() {
@Override
public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras) {
callback.onLayoutFinished(new PrintDocumentInfo.Builder(uuid.toString()).build(), true);
}
@Override
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback) {
synchronized (isWriteCalled) {
isWriteCalled.notify();
}
callback.onWriteFailed(null);
}
};
Activity activity = mActivityRule.getActivity();
PrintManager pm = mActivityRule.getActivity().getSystemService(PrintManager.class);
// Start printing
PrintJob printJob = pm.print(uuid.toString(), adapter, null);
// Wait until print preview is up
synchronized (isWriteCalled) {
isWriteCalled.wait();
}
// Start print job settings
Intent intent = new Intent(android.provider.Settings.ACTION_PRINT_SETTINGS);
intent.putExtra(EXTRA_PRINT_JOB_ID, printJob.getId().flattenToString());
intent.setData(Uri.fromParts("printjob", printJob.getId().flattenToString(), null));
activity.startActivity(intent);
UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiObject2 printPrefTitle = uiDevice.wait(Until.findObject(By.text("Configuring " + uuid.toString())), 5000);
assertNotNull(printPrefTitle);
Log.i(LOG_TAG, "Found " + printPrefTitle.getText());
}
use of androidx.test.filters.LargeTest in project ExoPlayer by google.
the class SessionPlayerConnectorTest method cancelReturnedFuture_withSeekTo_cancelsPendingCommand.
@Test
@LargeTest
public void cancelReturnedFuture_withSeekTo_cancelsPendingCommand() throws Exception {
CountDownLatch readRequestedLatch = new CountDownLatch(1);
CountDownLatch readAllowedLatch = new CountDownLatch(1);
// Need to wait from prepare() to counting down readAllowedLatch.
playerTestRule.setDataSourceInstrumentation(dataSpec -> {
readRequestedLatch.countDown();
try {
assertThat(readAllowedLatch.await(PLAYER_STATE_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isTrue();
} catch (Exception e) {
assertWithMessage("Unexpected exception %s", e).fail();
}
});
assertPlayerResultSuccess(sessionPlayerConnector.setMediaItem(TestUtils.createMediaItem(R.raw.audio)));
// prepare() will be pending until readAllowed is countDowned.
ListenableFuture<PlayerResult> prepareFuture = sessionPlayerConnector.prepare();
ListenableFuture<PlayerResult> seekFuture = sessionPlayerConnector.seekTo(1000);
assertThat(readRequestedLatch.await(PLAYER_STATE_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isTrue();
// Cancel the pending commands while preparation is on hold.
seekFuture.cancel(false);
// Make the on-going prepare operation resumed and finished.
readAllowedLatch.countDown();
assertPlayerResultSuccess(prepareFuture);
// Check whether the canceled seek() didn't happened.
// Checking seekFuture.get() will be useless because it always throws CancellationException due
// to the CallbackToFuture implementation.
Thread.sleep(PLAYER_STATE_CHANGE_WAIT_TIME_MS);
assertThat(sessionPlayerConnector.getCurrentPosition()).isEqualTo(0);
}
use of androidx.test.filters.LargeTest in project ExoPlayer by google.
the class SessionPlayerConnectorTest method setPlaylist_byUnderlyingPlayerBeforePrepare_notifiesOnPlaylistChanged.
@Test
@LargeTest
public void setPlaylist_byUnderlyingPlayerBeforePrepare_notifiesOnPlaylistChanged() throws Exception {
List<MediaItem> playlistToExoPlayer = TestUtils.createPlaylist(4);
DefaultMediaItemConverter converter = new DefaultMediaItemConverter();
List<com.google.android.exoplayer2.MediaItem> exoMediaItems = new ArrayList<>();
for (MediaItem mediaItem : playlistToExoPlayer) {
exoMediaItems.add(converter.convertToExoPlayerMediaItem(mediaItem));
}
CountDownLatch onPlaylistChangedLatch = new CountDownLatch(1);
sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {
@Override
public void onPlaylistChanged(SessionPlayer player, @Nullable List<MediaItem> list, @Nullable MediaMetadata metadata) {
if (Util.areEqual(list, playlistToExoPlayer)) {
onPlaylistChangedLatch.countDown();
}
}
});
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> playerTestRule.getExoPlayer().setMediaItems(exoMediaItems));
assertThat(onPlaylistChangedLatch.await(PLAYLIST_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isTrue();
}
use of androidx.test.filters.LargeTest in project ExoPlayer by google.
the class SessionPlayerConnectorTest method seekTo_whenPrepared_notifiesOnSeekCompleted.
@Test
@LargeTest
public void seekTo_whenPrepared_notifiesOnSeekCompleted() throws Throwable {
long mp4DurationMs = 8_484L;
TestUtils.loadResource(R.raw.video_big_buck_bunny, sessionPlayerConnector);
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
CountDownLatch onSeekCompletedLatch = new CountDownLatch(1);
SessionPlayer.PlayerCallback callback = new SessionPlayer.PlayerCallback() {
@Override
public void onSeekCompleted(SessionPlayer player, long position) {
onSeekCompletedLatch.countDown();
}
};
sessionPlayerConnector.registerPlayerCallback(executor, callback);
sessionPlayerConnector.seekTo(mp4DurationMs >> 1);
assertThat(onSeekCompletedLatch.await(PLAYBACK_COMPLETED_WAIT_TIME_MS, MILLISECONDS)).isTrue();
}
use of androidx.test.filters.LargeTest in project ExoPlayer by google.
the class SessionPlayerConnectorTest method seekTo_byUnderlyingPlayer_notifiesOnSeekCompleted.
@Test
@LargeTest
public void seekTo_byUnderlyingPlayer_notifiesOnSeekCompleted() throws Exception {
TestUtils.loadResource(R.raw.video_big_buck_bunny, sessionPlayerConnector);
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
ExoPlayer exoPlayer = playerTestRule.getExoPlayer();
long testSeekPosition = 1023;
AtomicLong seekPosition = new AtomicLong();
CountDownLatch onSeekCompletedLatch = new CountDownLatch(1);
sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {
@Override
public void onSeekCompleted(SessionPlayer player, long position) {
// Do not assert here, because onSeekCompleted() can be called after the player is
// closed.
seekPosition.set(position);
onSeekCompletedLatch.countDown();
}
});
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> exoPlayer.seekTo(testSeekPosition));
assertThat(onSeekCompletedLatch.await(PLAYER_STATE_CHANGE_WAIT_TIME_MS, MILLISECONDS)).isTrue();
assertThat(seekPosition.get()).isEqualTo(testSeekPosition);
}
Aggregations