updated sonic tests, still have an intermittent error

This commit is contained in:
Tom Hennen 2015-10-10 05:38:18 -04:00
parent 83e56a334c
commit 113f8c55c3
3 changed files with 65 additions and 150 deletions

View File

@ -46,98 +46,6 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
private Context context;
private PlaybackController controller;
protected FeedMedia currentMedia;
private PlaybackController createController(Activity activity) {
return new PlaybackController(activity, false) {
@Override
public void setupGUI() {
}
@Override
public void onPositionObserverUpdate() {
}
@Override
public void onBufferStart() {
}
@Override
public void onBufferEnd() {
}
@Override
public void onBufferUpdate(float progress) {
}
@Override
public void handleError(int code) {
}
@Override
public void onReloadNotification(int code) {
}
@Override
public void onSleepTimerUpdate() {
}
@Override
public ImageButton getPlayButton() {
return null;
}
@Override
public void postStatusMsg(int msg) {
}
@Override
public void clearStatusMsg() {
}
@Override
public boolean loadMediaInfo() {
Playable playable = controller.getMedia();
if(playable == null) {
currentMedia = null;
return true;
} else if(playable instanceof FeedMedia) {
currentMedia = (FeedMedia) playable;
return true;
} else {
return false;
}
}
@Override
public void onAwaitingVideoSurface() {
}
@Override
public void onServiceQueried() {
}
@Override
public void onShutdownNotification() {
}
@Override
public void onPlaybackEnd() {
currentMedia = null;
}
@Override
public void onPlaybackSpeedChange() {
}
@Override
protected void setScreenOn(boolean enable) {
}
};
}
public PlaybackSonicTest() {
super(MainActivity.class);
}
@ -158,9 +66,6 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
.putBoolean(UserPreferences.PREF_SONIC, true)
.commit();
controller = createController(getActivity());
controller.init();
solo = new Solo(getInstrumentation(), getActivity());
uiTestUtils = new UITestUtils(context);
@ -174,7 +79,6 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
@Override
public void tearDown() throws Exception {
controller.release();
solo.finishOpenedActivities();
uiTestUtils.tearDown();
@ -218,8 +122,8 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
solo.clickOnView(solo.getView(R.id.butSecondaryAction));
long mediaId = episodes.get(0).getMedia().getId();
boolean playing = solo.waitForCondition(() -> {
if (currentMedia != null) {
return currentMedia.getId() == mediaId;
if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else {
return false;
}
@ -238,15 +142,15 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
View targetView = drawerView.getChildAt(QUEUE_DRAWER_LIST_INDEX);
solo.waitForView(targetView);
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(currentMedia != null) {
return currentMedia.getId() == mediaId;
if(uiTestUtils.getCurrentMedia(getActivity()) != null) {
return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else {
return false;
}
@ -276,15 +180,19 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
startLocalPlaybackFromQueue();
boolean stopped = solo.waitForCondition(() -> {
if (currentMedia != null) {
return currentMedia.getId() != first.getMedia().getId();
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 false;
return true;
}
}, Timeout.getSmallTimeout());
assertTrue(stopped);
Thread.sleep(1000);
PlayerStatus status = controller.getStatus();
PlayerStatus status = uiTestUtils.getPlaybackController(getActivity()).getStatus();
assertFalse(status.equals(PlayerStatus.PLAYING));
}
@ -298,16 +206,18 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
startLocalPlaybackFromQueue();
boolean firstPlaying = solo.waitForCondition(() -> {
if (currentMedia != null) {
return currentMedia.getId() == first.getMedia().getId();
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 (currentMedia != null) {
return currentMedia.getId() == second.getMedia().getId();
if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return uiTestUtils.getCurrentMedia(getActivity()).getId()
== second.getMedia().getId();
} else {
return false;
}
@ -327,8 +237,8 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
startLocalPlayback();
long mediaId = episodes.get(0).getMedia().getId();
boolean startedPlaying = solo.waitForCondition(() -> {
if (currentMedia != null) {
return currentMedia.getId() == mediaId;
if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else {
return false;
}
@ -336,14 +246,15 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
assertTrue(startedPlaying);
boolean stoppedPlaying = solo.waitForCondition(() -> {
return currentMedia == null || currentMedia.getId() != mediaId;
return uiTestUtils.getCurrentMedia(getActivity()) == null
|| uiTestUtils.getCurrentMedia(getActivity()).getId() != mediaId;
}, Timeout.getLargeTimeout());
assertTrue(stoppedPlaying);
startLocalPlayback();
boolean startedReplay = solo.waitForCondition(() -> {
if(currentMedia != null) {
return currentMedia.getId() == mediaId;
if(uiTestUtils.getCurrentMedia(getActivity()) != null) {
return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else {
return false;
}

View File

@ -17,15 +17,12 @@ 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.feed.FeedMedia;
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.danoeh.antennapod.core.storage.PodDBAdapter;
import de.danoeh.antennapod.core.util.playback.PlaybackController;
import de.danoeh.antennapod.fragment.ExternalPlayerFragment;
/**
* test cases for starting and ending playback from the MainActivity and AudioPlayerActivity
@ -41,15 +38,6 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
private Context context;
private PlaybackController getPlaybackController() {
ExternalPlayerFragment fragment = (ExternalPlayerFragment)getActivity().getSupportFragmentManager().findFragmentByTag(ExternalPlayerFragment.TAG);
return fragment.getPlaybackControllerTestingOnly();
}
private FeedMedia getCurrentMedia() {
return (FeedMedia)getPlaybackController().getMedia();
}
public PlaybackTest() {
super(MainActivity.class);
}
@ -125,12 +113,12 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
solo.clickOnView(solo.getView(R.id.butSecondaryAction));
long mediaId = episodes.get(0).getMedia().getId();
boolean playing = solo.waitForCondition(() -> {
if (getCurrentMedia() != null) {
return getCurrentMedia().getId() == mediaId;
if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else {
return false;
}
}, Timeout.getLargeTimeout());
}, Timeout.getSmallTimeout());
assertTrue(playing);
}
@ -145,17 +133,18 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
solo.waitForView(targetView);
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(getCurrentMedia() != null) {
return getCurrentMedia().getId() == mediaId;
if(uiTestUtils.getCurrentMedia(getActivity()) != null) {
return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else {
return false;
}
}, Timeout.getLargeTimeout());
}, Timeout.getSmallTimeout());
assertTrue(playing);
}
@ -181,19 +170,19 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
final FeedItem first = queue.get(0);
startLocalPlaybackFromQueue();
boolean stopped = solo.waitForCondition(() -> {
// the condition is met when playback ends and we're not playing
// anything else. When playback ends, currentMedia is set to null.
if (getPlaybackController().getStatus() != PlayerStatus.PLAYING) {
if (uiTestUtils.getPlaybackController(getActivity()).getStatus()
!= PlayerStatus.PLAYING) {
return true;
} else if (getCurrentMedia() != null) {
return getCurrentMedia().getId() != first.getMedia().getId();
} else if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return uiTestUtils.getCurrentMedia(getActivity()).getId()
!= first.getMedia().getId();
} else {
return true;
}
}, Timeout.getLargeTimeout());
}, Timeout.getSmallTimeout());
assertTrue(stopped);
Thread.sleep(1000);
PlayerStatus status = getPlaybackController().getStatus();
PlayerStatus status = uiTestUtils.getPlaybackController(getActivity()).getStatus();
assertFalse(status.equals(PlayerStatus.PLAYING));
}
@ -207,16 +196,18 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
startLocalPlaybackFromQueue();
boolean firstPlaying = solo.waitForCondition(() -> {
if (getCurrentMedia() != null) {
return getCurrentMedia().getId() == first.getMedia().getId();
if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return uiTestUtils.getCurrentMedia(getActivity()).getId()
== first.getMedia().getId();
} else {
return false;
}
}, Timeout.getLargeTimeout());
}, Timeout.getSmallTimeout());
assertTrue(firstPlaying);
boolean secondPlaying = solo.waitForCondition(() -> {
if (getCurrentMedia() != null) {
return getCurrentMedia().getId() == second.getMedia().getId();
if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return uiTestUtils.getCurrentMedia(getActivity()).getId()
== second.getMedia().getId();
} else {
return false;
}
@ -236,23 +227,24 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
startLocalPlayback();
long mediaId = episodes.get(0).getMedia().getId();
boolean startedPlaying = solo.waitForCondition(() -> {
if (getCurrentMedia() != null) {
return getCurrentMedia().getId() == mediaId;
if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else {
return false;
}
}, Timeout.getLargeTimeout());
}, Timeout.getSmallTimeout());
assertTrue(startedPlaying);
boolean stoppedPlaying = solo.waitForCondition(() -> {
return getCurrentMedia() == null || getCurrentMedia().getId() != mediaId;
return uiTestUtils.getCurrentMedia(getActivity()) == null
|| uiTestUtils.getCurrentMedia(getActivity()).getId() != mediaId;
}, Timeout.getLargeTimeout());
assertTrue(stoppedPlaying);
startLocalPlayback();
boolean startedReplay = solo.waitForCondition(() -> {
if(getCurrentMedia() != null) {
return getCurrentMedia().getId() == mediaId;
if(uiTestUtils.getCurrentMedia(getActivity()) != null) {
return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else {
return false;
}

View File

@ -21,6 +21,7 @@ import java.util.Date;
import java.util.List;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.core.feed.EventDistributor;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedImage;
@ -28,6 +29,8 @@ import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.event.QueueEvent;
import de.danoeh.antennapod.core.storage.PodDBAdapter;
import de.danoeh.antennapod.core.util.playback.PlaybackController;
import de.danoeh.antennapod.fragment.ExternalPlayerFragment;
import de.greenrobot.event.EventBus;
import de.test.antennapod.util.service.download.HTTPBin;
import de.test.antennapod.util.syndication.feedgenerator.RSS2Generator;
@ -219,4 +222,13 @@ public class UITestUtils {
EventDistributor.getInstance().sendFeedUpdateBroadcast();
EventBus.getDefault().post(new QueueEvent(QueueEvent.Action.ADDED_ITEMS, queue));
}
public PlaybackController getPlaybackController(MainActivity mainActivity) {
ExternalPlayerFragment fragment = (ExternalPlayerFragment)mainActivity.getSupportFragmentManager().findFragmentByTag(ExternalPlayerFragment.TAG);
return fragment.getPlaybackControllerTestingOnly();
}
public FeedMedia getCurrentMedia(MainActivity mainActivity) {
return (FeedMedia)getPlaybackController(mainActivity).getMedia();
}
}