Search in sources :

Example 21 with LargeTest

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());
}
Also used : PrintJob(android.print.PrintJob) Bundle(android.os.Bundle) UiDevice(android.support.test.uiautomator.UiDevice) Activity(android.app.Activity) Intent(android.content.Intent) PrintAttributes(android.print.PrintAttributes) PrintManager(android.print.PrintManager) ParcelFileDescriptor(android.os.ParcelFileDescriptor) UUID(java.util.UUID) PrintDocumentAdapter(android.print.PrintDocumentAdapter) CancellationSignal(android.os.CancellationSignal) UiObject2(android.support.test.uiautomator.UiObject2) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Example 22 with LargeTest

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);
}
Also used : TestUtils.assertPlayerResult(com.google.android.exoplayer2.ext.media2.TestUtils.assertPlayerResult) PlayerResult(androidx.media2.common.SessionPlayer.PlayerResult) CountDownLatch(java.util.concurrent.CountDownLatch) MediumTest(androidx.test.filters.MediumTest) LargeTest(androidx.test.filters.LargeTest) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Example 23 with LargeTest

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();
}
Also used : UriMediaItem(androidx.media2.common.UriMediaItem) MediaItem(androidx.media2.common.MediaItem) SessionPlayer(androidx.media2.common.SessionPlayer) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MediaMetadata(androidx.media2.common.MediaMetadata) CountDownLatch(java.util.concurrent.CountDownLatch) MediumTest(androidx.test.filters.MediumTest) LargeTest(androidx.test.filters.LargeTest) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Example 24 with LargeTest

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();
}
Also used : SessionPlayer(androidx.media2.common.SessionPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) MediumTest(androidx.test.filters.MediumTest) LargeTest(androidx.test.filters.LargeTest) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Example 25 with LargeTest

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);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) SessionPlayer(androidx.media2.common.SessionPlayer) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) MediumTest(androidx.test.filters.MediumTest) LargeTest(androidx.test.filters.LargeTest) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Aggregations

LargeTest (androidx.test.filters.LargeTest)36 Test (org.junit.Test)36 MediumTest (androidx.test.filters.MediumTest)29 SmallTest (androidx.test.filters.SmallTest)29 SessionPlayer (androidx.media2.common.SessionPlayer)24 CountDownLatch (java.util.concurrent.CountDownLatch)23 MediaItem (androidx.media2.common.MediaItem)13 UriMediaItem (androidx.media2.common.UriMediaItem)13 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)12 ArrayList (java.util.ArrayList)9 MediaMetadata (androidx.media2.common.MediaMetadata)7 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)7 AudioAttributesCompat (androidx.media.AudioAttributesCompat)3 PlayerResult (androidx.media2.common.SessionPlayer.PlayerResult)3 ViewInteraction (androidx.test.espresso.ViewInteraction)3 TestUtils.assertPlayerResult (com.google.android.exoplayer2.ext.media2.TestUtils.assertPlayerResult)3 Activity (android.app.Activity)2 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 CancellationSignal (android.os.CancellationSignal)2