From fea84424e34b35a60a7cb0ed91d86571ad3b23e7 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sun, 20 Oct 2019 23:47:47 +0200 Subject: [PATCH] Removed code duplication from playback tests, added test for ExoPlayer --- .../playback/PlaybackBuiltinTest.java | 17 + .../playback/PlaybackExoplayerTest.java | 17 + .../playback/PlaybackSonicTest.java | 17 + .../{ui => playback}/PlaybackTest.java | 306 +++++++++--------- .../test/antennapod/ui/PlaybackSonicTest.java | 277 ---------------- .../de/test/antennapod/ui/UITestUtils.java | 2 +- .../core/preferences/UserPreferences.java | 11 +- 7 files changed, 213 insertions(+), 434 deletions(-) create mode 100644 app/src/androidTest/java/de/test/antennapod/playback/PlaybackBuiltinTest.java create mode 100644 app/src/androidTest/java/de/test/antennapod/playback/PlaybackExoplayerTest.java create mode 100644 app/src/androidTest/java/de/test/antennapod/playback/PlaybackSonicTest.java rename app/src/androidTest/java/de/test/antennapod/{ui => playback}/PlaybackTest.java (93%) delete mode 100644 app/src/androidTest/java/de/test/antennapod/ui/PlaybackSonicTest.java diff --git a/app/src/androidTest/java/de/test/antennapod/playback/PlaybackBuiltinTest.java b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackBuiltinTest.java new file mode 100644 index 000000000..a80ee41d7 --- /dev/null +++ b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackBuiltinTest.java @@ -0,0 +1,17 @@ +package de.test.antennapod.playback; + +import androidx.test.filters.LargeTest; +import de.danoeh.antennapod.core.preferences.UserPreferences; +import org.junit.Before; + +/** + * Test cases for starting and ending playback from the MainActivity and AudioPlayerActivity. + */ +@LargeTest +public class PlaybackBuiltinTest extends PlaybackTest { + @Before + public void setUp() throws Exception { + super.setUp(); + UserPreferences.enableBuiltin(); + } +} diff --git a/app/src/androidTest/java/de/test/antennapod/playback/PlaybackExoplayerTest.java b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackExoplayerTest.java new file mode 100644 index 000000000..0cf73f069 --- /dev/null +++ b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackExoplayerTest.java @@ -0,0 +1,17 @@ +package de.test.antennapod.playback; + +import androidx.test.filters.LargeTest; +import de.danoeh.antennapod.core.preferences.UserPreferences; +import org.junit.Before; + +/** + * Test cases for starting and ending playback from the MainActivity and AudioPlayerActivity. + */ +@LargeTest +public class PlaybackExoplayerTest extends PlaybackTest { + @Before + public void setUp() throws Exception { + super.setUp(); + UserPreferences.enableExoplayer(); + } +} diff --git a/app/src/androidTest/java/de/test/antennapod/playback/PlaybackSonicTest.java b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackSonicTest.java new file mode 100644 index 000000000..a0fb74809 --- /dev/null +++ b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackSonicTest.java @@ -0,0 +1,17 @@ +package de.test.antennapod.playback; + +import androidx.test.filters.LargeTest; +import de.danoeh.antennapod.core.preferences.UserPreferences; +import org.junit.Before; + +/** + * Test cases for starting and ending playback from the MainActivity and AudioPlayerActivity. + */ +@LargeTest +public class PlaybackSonicTest extends PlaybackTest { + @Before + public void setUp() throws Exception { + super.setUp(); + UserPreferences.enableSonic(); + } +} diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java similarity index 93% rename from app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java rename to app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java index 938a244f3..78f1ba7c4 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java +++ b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java @@ -1,23 +1,11 @@ -package de.test.antennapod.ui; +package de.test.antennapod.playback; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; -import androidx.test.filters.LargeTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.rule.ActivityTestRule; - -import de.test.antennapod.EspressoTestUtils; -import org.awaitility.Awaitility; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -import java.util.List; -import java.util.concurrent.TimeUnit; - import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.feed.FeedItem; @@ -26,6 +14,16 @@ import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.service.playback.PlayerStatus; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; +import de.test.antennapod.EspressoTestUtils; +import de.test.antennapod.ui.UITestUtils; +import org.awaitility.Awaitility; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.util.List; +import java.util.concurrent.TimeUnit; import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; @@ -41,21 +39,19 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertThat; /** * test cases for starting and ending playback from the MainActivity and AudioPlayerActivity */ -@LargeTest -public class PlaybackTest { +public abstract class PlaybackTest { @Rule public ActivityTestRule activityTestRule = new ActivityTestRule<>(MainActivity.class, false, false); private UITestUtils uiTestUtils; - private Context context; + protected Context context; @Before public void setUp() throws Exception { @@ -77,93 +73,6 @@ public class PlaybackTest { context.sendBroadcast(new Intent(PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE)); } - private MainActivity getActivity() { - return activityTestRule.getActivity(); - } - - private void setContinuousPlaybackPreference(boolean value) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs.edit().putBoolean(UserPreferences.PREF_FOLLOW_QUEUE, value).commit(); - } - - private void setSkipKeepsEpisodePreference(boolean value) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs.edit().putBoolean(UserPreferences.PREF_SKIP_KEEPS_EPISODE, value).commit(); - } - - private void setSmartMarkAsPlayedPreference(int smartMarkAsPlayedSecs) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs.edit().putString(UserPreferences.PREF_SMART_MARK_AS_PLAYED_SECS, - Integer.toString(smartMarkAsPlayedSecs, 10)) - .commit(); - } - - private void skipEpisode() { - Intent skipIntent = new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE); - context.sendBroadcast(skipIntent); - } - - private void pauseEpisode() { - Intent pauseIntent = new Intent(PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE); - context.sendBroadcast(pauseIntent); - } - - private void startLocalPlayback() { - openNavDrawer(); - onDrawerItem(withText(R.string.episodes_label)).perform(click()); - onView(isRoot()).perform(waitForView(withId(R.id.emptyViewTitle), 1000)); - onView(withText(R.string.all_episodes_short_label)).perform(click()); - - final List episodes = DBReader.getRecentlyPublishedEpisodes(0, 10); - onView(isRoot()).perform(waitForView(withId(R.id.butSecondaryAction), 1000)); - - onView(first(withId(R.id.butSecondaryAction))).perform(click()); - long mediaId = episodes.get(0).getMedia().getId(); - Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> { - if (uiTestUtils.getCurrentMedia(getActivity()) != null) { - return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId; - } else { - return false; - } - }); - } - - /** - * - * @param itemIdx The 0-based index of the episode to be played in the queue. - */ - private void playFromQueue(int itemIdx) { - final List queue = DBReader.getQueue(); - - onView(nth(withId(R.id.butSecondaryAction), itemIdx + 1)).perform(click()); - onView(isRoot()).perform(waitForView(withId(R.id.butPlay), 1000)); - long mediaId = queue.get(itemIdx).getMedia().getId(); - Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> { - if (uiTestUtils.getCurrentMedia(getActivity()) != null) { - return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId; - } else { - return false; - } - }); - } - - @Test - public void testStartLocal() throws Exception { - uiTestUtils.addLocalFeedData(true); - activityTestRule.launchActivity(new Intent()); - DBWriter.clearQueue().get(); - startLocalPlayback(); - } - - @Test - public void testContinousPlaybackOffSingleEpisode() throws Exception { - setContinuousPlaybackPreference(false); - uiTestUtils.addLocalFeedData(true); - activityTestRule.launchActivity(new Intent()); - DBWriter.clearQueue().get(); - startLocalPlayback(); - } - @Test public void testContinousPlaybackOffMultipleEpisodes() throws Exception { setContinuousPlaybackPreference(false); @@ -199,7 +108,7 @@ public class PlaybackTest { final FeedItem second = queue.get(1); playFromQueue(0); - Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> { + Awaitility.await().atMost(2, TimeUnit.SECONDS).until(() -> { if (uiTestUtils.getCurrentMedia(getActivity()) != null) { return uiTestUtils.getCurrentMedia(getActivity()).getId() == first.getMedia().getId(); @@ -217,10 +126,145 @@ public class PlaybackTest { }); } + + @Test + public void testReplayEpisodeContinuousPlaybackOn() throws Exception { + replayEpisodeCheck(true); + } + + @Test + public void testReplayEpisodeContinuousPlaybackOff() throws Exception { + replayEpisodeCheck(false); + } + + @Test + public void testSmartMarkAsPlayed_Skip_Average() throws Exception { + doTestSmartMarkAsPlayed_Skip_ForEpisode(0); + } + + @Test + public void testSmartMarkAsPlayed_Skip_LastEpisodeInQueue() throws Exception { + doTestSmartMarkAsPlayed_Skip_ForEpisode(-1); + } + + @Test + public void testSmartMarkAsPlayed_Pause_WontAffectItem() throws Exception { + setSmartMarkAsPlayedPreference(60); + + uiTestUtils.addLocalFeedData(true); + activityTestRule.launchActivity(new Intent()); + + final int fiIdx = 0; + final FeedItem feedItem = DBReader.getQueue().get(fiIdx); + + playFromQueue(fiIdx); + + // let playback run a bit then pause + Awaitility.await() + .atMost(1000, MILLISECONDS) + .until(() -> PlayerStatus.PLAYING == uiTestUtils.getPlaybackController(getActivity()).getStatus()); + pauseEpisode(); + Awaitility.await() + .atMost(1000, MILLISECONDS) + .until(() -> PlayerStatus.PAUSED == uiTestUtils.getPlaybackController(getActivity()).getStatus()); + + assertThat("Ensure even with smart mark as play, after pause, the item remains in the queue.", + DBReader.getQueue(), hasItems(feedItem)); + assertThat("Ensure even with smart mark as play, after pause, the item played status remains false.", + DBReader.getFeedItem(feedItem.getId()).isPlayed(), is(false)); + } + + @Test + public void testStartLocal() throws Exception { + uiTestUtils.addLocalFeedData(true); + activityTestRule.launchActivity(new Intent()); + DBWriter.clearQueue().get(); + startLocalPlayback(); + } + + @Test + public void testContinousPlaybackOffSingleEpisode() throws Exception { + setContinuousPlaybackPreference(false); + uiTestUtils.addLocalFeedData(true); + activityTestRule.launchActivity(new Intent()); + DBWriter.clearQueue().get(); + startLocalPlayback(); + } + + protected MainActivity getActivity() { + return activityTestRule.getActivity(); + } + + protected void setContinuousPlaybackPreference(boolean value) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + prefs.edit().putBoolean(UserPreferences.PREF_FOLLOW_QUEUE, value).commit(); + } + + protected void setSkipKeepsEpisodePreference(boolean value) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + prefs.edit().putBoolean(UserPreferences.PREF_SKIP_KEEPS_EPISODE, value).commit(); + } + + protected void setSmartMarkAsPlayedPreference(int smartMarkAsPlayedSecs) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + prefs.edit().putString(UserPreferences.PREF_SMART_MARK_AS_PLAYED_SECS, + Integer.toString(smartMarkAsPlayedSecs, 10)) + .commit(); + } + + private void skipEpisode() { + Intent skipIntent = new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE); + context.sendBroadcast(skipIntent); + } + + protected void pauseEpisode() { + Intent pauseIntent = new Intent(PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE); + context.sendBroadcast(pauseIntent); + } + + protected void startLocalPlayback() { + openNavDrawer(); + onDrawerItem(withText(R.string.episodes_label)).perform(click()); + onView(isRoot()).perform(waitForView(withId(R.id.emptyViewTitle), 1000)); + onView(withText(R.string.all_episodes_short_label)).perform(click()); + + final List episodes = DBReader.getRecentlyPublishedEpisodes(0, 10); + onView(isRoot()).perform(waitForView(withId(R.id.butSecondaryAction), 1000)); + + onView(first(withId(R.id.butSecondaryAction))).perform(click()); + long mediaId = episodes.get(0).getMedia().getId(); + Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> { + if (uiTestUtils.getCurrentMedia(getActivity()) != null) { + return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId; + } else { + return false; + } + }); + } + + /** + * + * @param itemIdx The 0-based index of the episode to be played in the queue. + */ + protected void playFromQueue(int itemIdx) { + final List queue = DBReader.getQueue(); + + onView(nth(withId(R.id.butSecondaryAction), itemIdx + 1)).perform(click()); + onView(isRoot()).perform(waitForView(withId(R.id.butPlay), 1000)); + long mediaId = queue.get(itemIdx).getMedia().getId(); + Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> { + if (uiTestUtils.getCurrentMedia(getActivity()) != null) { + return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId; + } else { + return false; + } + }); + } + /** * Check if an episode can be played twice without problems. */ - private void replayEpisodeCheck(boolean followQueue) throws Exception { + protected void replayEpisodeCheck(boolean followQueue) throws Exception { setContinuousPlaybackPreference(followQueue); uiTestUtils.addLocalFeedData(true); DBWriter.clearQueue().get(); @@ -251,27 +295,7 @@ public class PlaybackTest { }); } - @Test - public void testReplayEpisodeContinuousPlaybackOn() throws Exception { - replayEpisodeCheck(true); - } - - @Test - public void testReplayEpisodeContinuousPlaybackOff() throws Exception { - replayEpisodeCheck(false); - } - - @Test - public void testSmartMarkAsPlayed_Skip_Average() throws Exception { - doTestSmartMarkAsPlayed_Skip_ForEpisode(0); - } - - @Test - public void testSmartMarkAsPlayed_Skip_LastEpisodeInQueue() throws Exception { - doTestSmartMarkAsPlayed_Skip_ForEpisode(-1); - } - - private void doTestSmartMarkAsPlayed_Skip_ForEpisode(int itemIdxNegAllowed) throws Exception { + protected void doTestSmartMarkAsPlayed_Skip_ForEpisode(int itemIdxNegAllowed) throws Exception { setSmartMarkAsPlayedPreference(60); // ensure when an episode is skipped, it is removed due to smart as played setSkipKeepsEpisodePreference(false); @@ -299,32 +323,4 @@ public class PlaybackTest { }); assertThat(DBReader.getFeedItem(feedItem.getId()).isPlayed(), is(true)); } - - @Test - public void testSmartMarkAsPlayed_Pause_WontAffectItem() throws Exception { - setSmartMarkAsPlayedPreference(60); - - uiTestUtils.addLocalFeedData(true); - activityTestRule.launchActivity(new Intent()); - - final int fiIdx = 0; - final FeedItem feedItem = DBReader.getQueue().get(fiIdx); - - playFromQueue(fiIdx); - - // let playback run a bit then pause - Awaitility.await() - .atMost(1000, MILLISECONDS) - .until(() -> PlayerStatus.PLAYING == uiTestUtils.getPlaybackController(getActivity()).getStatus()); - pauseEpisode(); - Awaitility.await() - .atMost(1000, MILLISECONDS) - .until(() -> PlayerStatus.PAUSED == uiTestUtils.getPlaybackController(getActivity()).getStatus()); - - assertThat("Ensure even with smart mark as play, after pause, the item remains in the queue.", - DBReader.getQueue(), hasItems(feedItem)); - assertThat("Ensure even with smart mark as play, after pause, the item played status remains false.", - DBReader.getFeedItem(feedItem.getId()).isPlayed(), is(false)); - } - } diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PlaybackSonicTest.java b/app/src/androidTest/java/de/test/antennapod/ui/PlaybackSonicTest.java deleted file mode 100644 index 5b3530ea8..000000000 --- a/app/src/androidTest/java/de/test/antennapod/ui/PlaybackSonicTest.java +++ /dev/null @@ -1,277 +0,0 @@ -package de.test.antennapod.ui; - -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; -import androidx.test.InstrumentationRegistry; -import androidx.test.filters.LargeTest; -import androidx.test.rule.ActivityTestRule; -import android.view.View; -import android.widget.ListView; - -import com.robotium.solo.Solo; -import com.robotium.solo.Timeout; - -import java.util.List; - -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.MainActivity; -import de.danoeh.antennapod.core.feed.FeedItem; -import de.danoeh.antennapod.core.preferences.UserPreferences; -import de.danoeh.antennapod.core.service.playback.PlaybackService; -import de.danoeh.antennapod.core.service.playback.PlayerStatus; -import de.danoeh.antennapod.core.storage.DBReader; -import de.danoeh.antennapod.core.storage.DBWriter; -import de.test.antennapod.EspressoTestUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -import static androidx.test.InstrumentationRegistry.getInstrumentation; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * test cases for starting and ending playback from the MainActivity and AudioPlayerActivity - */ -@LargeTest -public class PlaybackSonicTest { - private static final int EPISODES_DRAWER_LIST_INDEX = 1; - private static final int QUEUE_DRAWER_LIST_INDEX = 0; - - private Solo solo; - private UITestUtils uiTestUtils; - - private Context context; - - @Rule - public ActivityTestRule activityTestRule = new ActivityTestRule<>(MainActivity.class, false, false); - - @Before - public void setUp() throws Exception { - EspressoTestUtils.clearPreferences(); - EspressoTestUtils.makeNotFirstRun(); - EspressoTestUtils.clearDatabase(); - context = InstrumentationRegistry.getTargetContext(); - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs.edit() - .clear() - .putBoolean(UserPreferences.PREF_UNPAUSE_ON_HEADSET_RECONNECT, false) - .putBoolean(UserPreferences.PREF_PAUSE_ON_HEADSET_DISCONNECT, false) - .putString(UserPreferences.PREF_MEDIA_PLAYER, "sonic") - .commit(); - - activityTestRule.launchActivity(new Intent()); - solo = new Solo(getInstrumentation(), activityTestRule.getActivity()); - - uiTestUtils = new UITestUtils(context); - uiTestUtils.setup(); - } - - @After - public void tearDown() throws Exception { - solo.finishOpenedActivities(); - uiTestUtils.tearDown(); - - // shut down playback service - skipEpisode(); - context.sendBroadcast(new Intent(PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE)); - } - - private MainActivity getActivity() { - return activityTestRule.getActivity(); - } - - private void openNavDrawer() { - solo.clickOnImageButton(0); - getInstrumentation().waitForIdleSync(); - } - - private void setContinuousPlaybackPreference(boolean value) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs.edit().putBoolean(UserPreferences.PREF_FOLLOW_QUEUE, value).commit(); - } - - private void skipEpisode() { - Intent skipIntent = new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE); - context.sendBroadcast(skipIntent); - } - - private void startLocalPlayback() { - openNavDrawer(); - // if we try to just click on plain old text then - // we might wind up clicking on the fragment title and not - // the drawer element like we want. - ListView drawerView = (ListView)solo.getView(R.id.nav_list); - // this should be 'Episodes' - View targetView = drawerView.getChildAt(EPISODES_DRAWER_LIST_INDEX); - solo.waitForView(targetView); - solo.clickOnView(targetView); - getInstrumentation().waitForIdleSync(); - solo.waitForText(solo.getString(R.string.all_episodes_short_label)); - solo.clickOnText(solo.getString(R.string.all_episodes_short_label)); - getInstrumentation().waitForIdleSync(); - - final List episodes = DBReader.getRecentlyPublishedEpisodes(0, 10); - assertTrue(solo.waitForView(solo.getView(R.id.butSecondaryAction))); - - solo.clickOnView(solo.getView(R.id.butSecondaryAction)); - long mediaId = episodes.get(0).getMedia().getId(); - boolean playing = solo.waitForCondition(() -> { - if (uiTestUtils.getCurrentMedia(getActivity()) != null) { - return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId; - } else { - return false; - } - }, Timeout.getSmallTimeout()); - assertTrue(playing); - } - - private void startLocalPlaybackFromQueue() { - openNavDrawer(); - - // if we try to just click on plain old text then - // we might wind up clicking on the fragment title and not - // the drawer element like we want. - ListView drawerView = (ListView)solo.getView(R.id.nav_list); - // this should be 'Queue' - View targetView = drawerView.getChildAt(QUEUE_DRAWER_LIST_INDEX); - solo.waitForView(targetView); - getInstrumentation().waitForIdleSync(); - solo.clickOnView(targetView); - assertTrue(solo.waitForView(solo.getView(R.id.butSecondaryAction))); - - final List queue = DBReader.getQueue(); - solo.clickOnImageButton(1); - assertTrue(solo.waitForView(solo.getView(R.id.butPlay))); - long mediaId = queue.get(0).getMedia().getId(); - boolean playing = solo.waitForCondition(() -> { - if(uiTestUtils.getCurrentMedia(getActivity()) != null) { - return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId; - } else { - return false; - } - }, Timeout.getSmallTimeout()); - assertTrue(playing); - } - - @Test - public void testStartLocal() throws Exception { - uiTestUtils.addLocalFeedData(true); - DBWriter.clearQueue().get(); - startLocalPlayback(); - } - - @Test - public void testContinousPlaybackOffSingleEpisode() throws Exception { - setContinuousPlaybackPreference(false); - uiTestUtils.addLocalFeedData(true); - DBWriter.clearQueue().get(); - startLocalPlayback(); - } - - @Test - public void testContinousPlaybackOffMultipleEpisodes() throws Exception { - setContinuousPlaybackPreference(false); - uiTestUtils.addLocalFeedData(true); - List queue = DBReader.getQueue(); - final FeedItem first = queue.get(0); - - startLocalPlaybackFromQueue(); - boolean stopped = solo.waitForCondition(() -> { - if (uiTestUtils.getPlaybackController(getActivity()).getStatus() - != PlayerStatus.PLAYING) { - return true; - } else if (uiTestUtils.getCurrentMedia(getActivity()) != null) { - return uiTestUtils.getCurrentMedia(getActivity()).getId() - != first.getMedia().getId(); - } else { - return true; - } - }, Timeout.getSmallTimeout()); - assertTrue(stopped); - Thread.sleep(1000); - PlayerStatus status = uiTestUtils.getPlaybackController(getActivity()).getStatus(); - assertFalse(status.equals(PlayerStatus.PLAYING)); - } - - @Test - public void testContinuousPlaybackOnMultipleEpisodes() throws Exception { - setContinuousPlaybackPreference(true); - uiTestUtils.addLocalFeedData(true); - List queue = DBReader.getQueue(); - final FeedItem first = queue.get(0); - final FeedItem second = queue.get(1); - - startLocalPlaybackFromQueue(); - boolean firstPlaying = solo.waitForCondition(() -> { - if (uiTestUtils.getCurrentMedia(getActivity()) != null) { - return uiTestUtils.getCurrentMedia(getActivity()).getId() - == first.getMedia().getId(); - } else { - return false; - } - }, Timeout.getSmallTimeout()); - assertTrue(firstPlaying); - boolean secondPlaying = solo.waitForCondition(() -> { - if (uiTestUtils.getCurrentMedia(getActivity()) != null) { - return uiTestUtils.getCurrentMedia(getActivity()).getId() - == second.getMedia().getId(); - } else { - return false; - } - }, Timeout.getLargeTimeout()); - assertTrue(secondPlaying); - } - - /** - * Check if an episode can be played twice without problems. - */ - private void replayEpisodeCheck(boolean followQueue) throws Exception { - setContinuousPlaybackPreference(followQueue); - uiTestUtils.addLocalFeedData(true); - DBWriter.clearQueue().get(); - final List episodes = DBReader.getRecentlyPublishedEpisodes(0, 10); - - startLocalPlayback(); - long mediaId = episodes.get(0).getMedia().getId(); - boolean startedPlaying = solo.waitForCondition(() -> { - if (uiTestUtils.getCurrentMedia(getActivity()) != null) { - return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId; - } else { - return false; - } - }, Timeout.getSmallTimeout()); - assertTrue(startedPlaying); - - boolean stoppedPlaying = solo.waitForCondition(() -> - uiTestUtils.getCurrentMedia(getActivity()) == null - || uiTestUtils.getCurrentMedia(getActivity()).getId() != mediaId - , Timeout.getLargeTimeout()); - assertTrue(stoppedPlaying); - - startLocalPlayback(); - boolean startedReplay = solo.waitForCondition(() -> { - if(uiTestUtils.getCurrentMedia(getActivity()) != null) { - return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId; - } else { - return false; - } - }, Timeout.getLargeTimeout()); - assertTrue(startedReplay); - } - - @Test - public void testReplayEpisodeContinuousPlaybackOn() throws Exception { - replayEpisodeCheck(true); - } - - @Test - public void testReplayEpisodeContinuousPlaybackOff() throws Exception { - replayEpisodeCheck(false); - } - -} diff --git a/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java b/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java index 905c65c34..82dc63d68 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java @@ -34,7 +34,7 @@ import org.junit.Assert; * Utility methods for UI tests. * Starts a web server that hosts feeds, episodes and images. */ -class UITestUtils { +public class UITestUtils { private static final String TAG = UITestUtils.class.getSimpleName(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index 6e73d581f..be130c00f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -741,7 +741,8 @@ public class UserPreferences { } public static String getMediaPlayer() { - return prefs.getString(PREF_MEDIA_PLAYER, PREF_MEDIA_PLAYER_EXOPLAYER); + String s = prefs.getString(PREF_MEDIA_PLAYER, "blaah"); + return s; } public static boolean useSonic() { @@ -756,6 +757,14 @@ public class UserPreferences { prefs.edit().putString(PREF_MEDIA_PLAYER, "sonic").apply(); } + public static void enableExoplayer() { + prefs.edit().putString(PREF_MEDIA_PLAYER, PREF_MEDIA_PLAYER_EXOPLAYER).apply(); + } + + public static void enableBuiltin() { + prefs.edit().putString(PREF_MEDIA_PLAYER, "builtin").apply(); + } + public static boolean stereoToMono() { return prefs.getBoolean(PREF_STEREO_TO_MONO, false); }