diff options
author | ByteHamster <info@bytehamster.com> | 2019-10-20 23:47:47 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2019-10-20 23:49:14 +0200 |
commit | fea84424e34b35a60a7cb0ed91d86571ad3b23e7 (patch) | |
tree | 3b13da96a57535c463ffbf54fcd0e6f2226665b6 /app/src | |
parent | 6e35861a614cebc1eec317366793a5436a8510f9 (diff) | |
download | AntennaPod-fea84424e34b35a60a7cb0ed91d86571ad3b23e7.zip |
Removed code duplication from playback tests, added test for ExoPlayer
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/androidTest/java/de/test/antennapod/playback/PlaybackBuiltinTest.java | 17 | ||||
-rw-r--r-- | app/src/androidTest/java/de/test/antennapod/playback/PlaybackExoplayerTest.java | 17 | ||||
-rw-r--r-- | app/src/androidTest/java/de/test/antennapod/playback/PlaybackSonicTest.java | 17 | ||||
-rw-r--r-- | app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java (renamed from app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java) | 282 | ||||
-rw-r--r-- | app/src/androidTest/java/de/test/antennapod/ui/PlaybackSonicTest.java | 277 | ||||
-rw-r--r-- | app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java | 2 |
6 files changed, 191 insertions, 421 deletions
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 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,14 +1,21 @@ -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.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 de.test.antennapod.ui.UITestUtils; import org.awaitility.Awaitility; import org.junit.After; import org.junit.Before; @@ -18,15 +25,6 @@ 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; -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 static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.matcher.ViewMatchers.isRoot; @@ -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<MainActivity> activityTestRule = new ActivityTestRule<>(MainActivity.class, false, false); private UITestUtils uiTestUtils; - private Context context; + protected Context context; @Before public void setUp() throws Exception { @@ -77,21 +73,139 @@ public class PlaybackTest { context.sendBroadcast(new Intent(PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE)); } - private MainActivity getActivity() { + @Test + public void testContinousPlaybackOffMultipleEpisodes() throws Exception { + setContinuousPlaybackPreference(false); + uiTestUtils.addLocalFeedData(true); + activityTestRule.launchActivity(new Intent()); + List<FeedItem> queue = DBReader.getQueue(); + final FeedItem first = queue.get(0); + playFromQueue(0); + Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> { + 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; + } + }); + + Thread.sleep(1000); + assertNotEquals(PlayerStatus.PLAYING, uiTestUtils.getPlaybackController(getActivity()).getStatus()); + } + + @Test + public void testContinuousPlaybackOnMultipleEpisodes() throws Exception { + setContinuousPlaybackPreference(true); + uiTestUtils.addLocalFeedData(true); + activityTestRule.launchActivity(new Intent()); + + List<FeedItem> queue = DBReader.getQueue(); + final FeedItem first = queue.get(0); + final FeedItem second = queue.get(1); + + playFromQueue(0); + Awaitility.await().atMost(2, TimeUnit.SECONDS).until(() -> { + if (uiTestUtils.getCurrentMedia(getActivity()) != null) { + return uiTestUtils.getCurrentMedia(getActivity()).getId() + == first.getMedia().getId(); + } else { + return false; + } + }); + Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> { + if (uiTestUtils.getCurrentMedia(getActivity()) != null) { + return uiTestUtils.getCurrentMedia(getActivity()).getId() + == second.getMedia().getId(); + } else { + return false; + } + }); + } + + + @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(); } - private void setContinuousPlaybackPreference(boolean value) { + protected void setContinuousPlaybackPreference(boolean value) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); prefs.edit().putBoolean(UserPreferences.PREF_FOLLOW_QUEUE, value).commit(); } - private void setSkipKeepsEpisodePreference(boolean value) { + protected void setSkipKeepsEpisodePreference(boolean value) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); prefs.edit().putBoolean(UserPreferences.PREF_SKIP_KEEPS_EPISODE, value).commit(); } - private void setSmartMarkAsPlayedPreference(int smartMarkAsPlayedSecs) { + protected void setSmartMarkAsPlayedPreference(int smartMarkAsPlayedSecs) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); prefs.edit().putString(UserPreferences.PREF_SMART_MARK_AS_PLAYED_SECS, Integer.toString(smartMarkAsPlayedSecs, 10)) @@ -103,12 +217,12 @@ public class PlaybackTest { context.sendBroadcast(skipIntent); } - private void pauseEpisode() { + protected void pauseEpisode() { Intent pauseIntent = new Intent(PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE); context.sendBroadcast(pauseIntent); } - private void startLocalPlayback() { + protected void startLocalPlayback() { openNavDrawer(); onDrawerItem(withText(R.string.episodes_label)).perform(click()); onView(isRoot()).perform(waitForView(withId(R.id.emptyViewTitle), 1000)); @@ -132,7 +246,7 @@ public class PlaybackTest { * * @param itemIdx The 0-based index of the episode to be played in the queue. */ - private void playFromQueue(int itemIdx) { + protected void playFromQueue(int itemIdx) { final List<FeedItem> queue = DBReader.getQueue(); onView(nth(withId(R.id.butSecondaryAction), itemIdx + 1)).perform(click()); @@ -147,80 +261,10 @@ public class PlaybackTest { }); } - @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); - uiTestUtils.addLocalFeedData(true); - activityTestRule.launchActivity(new Intent()); - List<FeedItem> queue = DBReader.getQueue(); - final FeedItem first = queue.get(0); - playFromQueue(0); - Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> { - 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; - } - }); - - Thread.sleep(1000); - assertNotEquals(PlayerStatus.PLAYING, uiTestUtils.getPlaybackController(getActivity()).getStatus()); - } - - @Test - public void testContinuousPlaybackOnMultipleEpisodes() throws Exception { - setContinuousPlaybackPreference(true); - uiTestUtils.addLocalFeedData(true); - activityTestRule.launchActivity(new Intent()); - - List<FeedItem> queue = DBReader.getQueue(); - final FeedItem first = queue.get(0); - final FeedItem second = queue.get(1); - - playFromQueue(0); - Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> { - if (uiTestUtils.getCurrentMedia(getActivity()) != null) { - return uiTestUtils.getCurrentMedia(getActivity()).getId() - == first.getMedia().getId(); - } else { - return false; - } - }); - Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> { - if (uiTestUtils.getCurrentMedia(getActivity()) != null) { - return uiTestUtils.getCurrentMedia(getActivity()).getId() - == second.getMedia().getId(); - } 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<MainActivity> 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<FeedItem> 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<FeedItem> 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<FeedItem> 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<FeedItem> 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<FeedItem> 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(); |