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 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() { public PlaybackSonicTest() {
super(MainActivity.class); super(MainActivity.class);
} }
@ -158,9 +66,6 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
.putBoolean(UserPreferences.PREF_SONIC, true) .putBoolean(UserPreferences.PREF_SONIC, true)
.commit(); .commit();
controller = createController(getActivity());
controller.init();
solo = new Solo(getInstrumentation(), getActivity()); solo = new Solo(getInstrumentation(), getActivity());
uiTestUtils = new UITestUtils(context); uiTestUtils = new UITestUtils(context);
@ -174,7 +79,6 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
@Override @Override
public void tearDown() throws Exception { public void tearDown() throws Exception {
controller.release();
solo.finishOpenedActivities(); solo.finishOpenedActivities();
uiTestUtils.tearDown(); uiTestUtils.tearDown();
@ -218,8 +122,8 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
solo.clickOnView(solo.getView(R.id.butSecondaryAction)); solo.clickOnView(solo.getView(R.id.butSecondaryAction));
long mediaId = episodes.get(0).getMedia().getId(); long mediaId = episodes.get(0).getMedia().getId();
boolean playing = solo.waitForCondition(() -> { boolean playing = solo.waitForCondition(() -> {
if (currentMedia != null) { if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return currentMedia.getId() == mediaId; return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else { } else {
return false; return false;
} }
@ -238,15 +142,15 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
View targetView = drawerView.getChildAt(QUEUE_DRAWER_LIST_INDEX); View targetView = drawerView.getChildAt(QUEUE_DRAWER_LIST_INDEX);
solo.waitForView(targetView); solo.waitForView(targetView);
solo.clickOnView(targetView); solo.clickOnView(targetView);
assertTrue(solo.waitForView(solo.getView(R.id.butSecondaryAction))); assertTrue(solo.waitForView(solo.getView(R.id.butSecondaryAction)));
final List<FeedItem> queue = DBReader.getQueue(); final List<FeedItem> queue = DBReader.getQueue();
solo.clickOnImageButton(1); solo.clickOnImageButton(1);
assertTrue(solo.waitForView(solo.getView(R.id.butPlay))); assertTrue(solo.waitForView(solo.getView(R.id.butPlay)));
long mediaId = queue.get(0).getMedia().getId(); long mediaId = queue.get(0).getMedia().getId();
boolean playing = solo.waitForCondition(() -> { boolean playing = solo.waitForCondition(() -> {
if(currentMedia != null) { if(uiTestUtils.getCurrentMedia(getActivity()) != null) {
return currentMedia.getId() == mediaId; return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else { } else {
return false; return false;
} }
@ -276,15 +180,19 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
startLocalPlaybackFromQueue(); startLocalPlaybackFromQueue();
boolean stopped = solo.waitForCondition(() -> { boolean stopped = solo.waitForCondition(() -> {
if (currentMedia != null) { if (uiTestUtils.getPlaybackController(getActivity()).getStatus()
return currentMedia.getId() != first.getMedia().getId(); != PlayerStatus.PLAYING) {
return true;
} else if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return uiTestUtils.getCurrentMedia(getActivity()).getId()
!= first.getMedia().getId();
} else { } else {
return false; return true;
} }
}, Timeout.getSmallTimeout()); }, Timeout.getSmallTimeout());
assertTrue(stopped); assertTrue(stopped);
Thread.sleep(1000); Thread.sleep(1000);
PlayerStatus status = controller.getStatus(); PlayerStatus status = uiTestUtils.getPlaybackController(getActivity()).getStatus();
assertFalse(status.equals(PlayerStatus.PLAYING)); assertFalse(status.equals(PlayerStatus.PLAYING));
} }
@ -298,16 +206,18 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
startLocalPlaybackFromQueue(); startLocalPlaybackFromQueue();
boolean firstPlaying = solo.waitForCondition(() -> { boolean firstPlaying = solo.waitForCondition(() -> {
if (currentMedia != null) { if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return currentMedia.getId() == first.getMedia().getId(); return uiTestUtils.getCurrentMedia(getActivity()).getId()
== first.getMedia().getId();
} else { } else {
return false; return false;
} }
}, Timeout.getSmallTimeout()); }, Timeout.getSmallTimeout());
assertTrue(firstPlaying); assertTrue(firstPlaying);
boolean secondPlaying = solo.waitForCondition(() -> { boolean secondPlaying = solo.waitForCondition(() -> {
if (currentMedia != null) { if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return currentMedia.getId() == second.getMedia().getId(); return uiTestUtils.getCurrentMedia(getActivity()).getId()
== second.getMedia().getId();
} else { } else {
return false; return false;
} }
@ -327,8 +237,8 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
startLocalPlayback(); startLocalPlayback();
long mediaId = episodes.get(0).getMedia().getId(); long mediaId = episodes.get(0).getMedia().getId();
boolean startedPlaying = solo.waitForCondition(() -> { boolean startedPlaying = solo.waitForCondition(() -> {
if (currentMedia != null) { if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return currentMedia.getId() == mediaId; return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else { } else {
return false; return false;
} }
@ -336,14 +246,15 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
assertTrue(startedPlaying); assertTrue(startedPlaying);
boolean stoppedPlaying = solo.waitForCondition(() -> { boolean stoppedPlaying = solo.waitForCondition(() -> {
return currentMedia == null || currentMedia.getId() != mediaId; return uiTestUtils.getCurrentMedia(getActivity()) == null
|| uiTestUtils.getCurrentMedia(getActivity()).getId() != mediaId;
}, Timeout.getLargeTimeout()); }, Timeout.getLargeTimeout());
assertTrue(stoppedPlaying); assertTrue(stoppedPlaying);
startLocalPlayback(); startLocalPlayback();
boolean startedReplay = solo.waitForCondition(() -> { boolean startedReplay = solo.waitForCondition(() -> {
if(currentMedia != null) { if(uiTestUtils.getCurrentMedia(getActivity()) != null) {
return currentMedia.getId() == mediaId; return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else { } else {
return false; return false;
} }

View File

@ -17,15 +17,12 @@ import java.util.List;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.core.feed.FeedItem; 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.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.service.playback.PlayerStatus; import de.danoeh.antennapod.core.service.playback.PlayerStatus;
import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.PodDBAdapter; 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 * 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 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() { public PlaybackTest() {
super(MainActivity.class); super(MainActivity.class);
} }
@ -125,12 +113,12 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
solo.clickOnView(solo.getView(R.id.butSecondaryAction)); solo.clickOnView(solo.getView(R.id.butSecondaryAction));
long mediaId = episodes.get(0).getMedia().getId(); long mediaId = episodes.get(0).getMedia().getId();
boolean playing = solo.waitForCondition(() -> { boolean playing = solo.waitForCondition(() -> {
if (getCurrentMedia() != null) { if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return getCurrentMedia().getId() == mediaId; return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else { } else {
return false; return false;
} }
}, Timeout.getLargeTimeout()); }, Timeout.getSmallTimeout());
assertTrue(playing); assertTrue(playing);
} }
@ -145,17 +133,18 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
solo.waitForView(targetView); solo.waitForView(targetView);
solo.clickOnView(targetView); solo.clickOnView(targetView);
assertTrue(solo.waitForView(solo.getView(R.id.butSecondaryAction))); assertTrue(solo.waitForView(solo.getView(R.id.butSecondaryAction)));
final List<FeedItem> queue = DBReader.getQueue(); final List<FeedItem> queue = DBReader.getQueue();
solo.clickOnImageButton(1); solo.clickOnImageButton(1);
assertTrue(solo.waitForView(solo.getView(R.id.butPlay))); assertTrue(solo.waitForView(solo.getView(R.id.butPlay)));
long mediaId = queue.get(0).getMedia().getId(); long mediaId = queue.get(0).getMedia().getId();
boolean playing = solo.waitForCondition(() -> { boolean playing = solo.waitForCondition(() -> {
if(getCurrentMedia() != null) { if(uiTestUtils.getCurrentMedia(getActivity()) != null) {
return getCurrentMedia().getId() == mediaId; return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else { } else {
return false; return false;
} }
}, Timeout.getLargeTimeout()); }, Timeout.getSmallTimeout());
assertTrue(playing); assertTrue(playing);
} }
@ -181,19 +170,19 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
final FeedItem first = queue.get(0); final FeedItem first = queue.get(0);
startLocalPlaybackFromQueue(); startLocalPlaybackFromQueue();
boolean stopped = solo.waitForCondition(() -> { boolean stopped = solo.waitForCondition(() -> {
// the condition is met when playback ends and we're not playing if (uiTestUtils.getPlaybackController(getActivity()).getStatus()
// anything else. When playback ends, currentMedia is set to null. != PlayerStatus.PLAYING) {
if (getPlaybackController().getStatus() != PlayerStatus.PLAYING) {
return true; return true;
} else if (getCurrentMedia() != null) { } else if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return getCurrentMedia().getId() != first.getMedia().getId(); return uiTestUtils.getCurrentMedia(getActivity()).getId()
!= first.getMedia().getId();
} else { } else {
return true; return true;
} }
}, Timeout.getLargeTimeout()); }, Timeout.getSmallTimeout());
assertTrue(stopped); assertTrue(stopped);
Thread.sleep(1000); Thread.sleep(1000);
PlayerStatus status = getPlaybackController().getStatus(); PlayerStatus status = uiTestUtils.getPlaybackController(getActivity()).getStatus();
assertFalse(status.equals(PlayerStatus.PLAYING)); assertFalse(status.equals(PlayerStatus.PLAYING));
} }
@ -207,16 +196,18 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
startLocalPlaybackFromQueue(); startLocalPlaybackFromQueue();
boolean firstPlaying = solo.waitForCondition(() -> { boolean firstPlaying = solo.waitForCondition(() -> {
if (getCurrentMedia() != null) { if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return getCurrentMedia().getId() == first.getMedia().getId(); return uiTestUtils.getCurrentMedia(getActivity()).getId()
== first.getMedia().getId();
} else { } else {
return false; return false;
} }
}, Timeout.getLargeTimeout()); }, Timeout.getSmallTimeout());
assertTrue(firstPlaying); assertTrue(firstPlaying);
boolean secondPlaying = solo.waitForCondition(() -> { boolean secondPlaying = solo.waitForCondition(() -> {
if (getCurrentMedia() != null) { if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return getCurrentMedia().getId() == second.getMedia().getId(); return uiTestUtils.getCurrentMedia(getActivity()).getId()
== second.getMedia().getId();
} else { } else {
return false; return false;
} }
@ -236,23 +227,24 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
startLocalPlayback(); startLocalPlayback();
long mediaId = episodes.get(0).getMedia().getId(); long mediaId = episodes.get(0).getMedia().getId();
boolean startedPlaying = solo.waitForCondition(() -> { boolean startedPlaying = solo.waitForCondition(() -> {
if (getCurrentMedia() != null) { if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
return getCurrentMedia().getId() == mediaId; return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else { } else {
return false; return false;
} }
}, Timeout.getLargeTimeout()); }, Timeout.getSmallTimeout());
assertTrue(startedPlaying); assertTrue(startedPlaying);
boolean stoppedPlaying = solo.waitForCondition(() -> { boolean stoppedPlaying = solo.waitForCondition(() -> {
return getCurrentMedia() == null || getCurrentMedia().getId() != mediaId; return uiTestUtils.getCurrentMedia(getActivity()) == null
|| uiTestUtils.getCurrentMedia(getActivity()).getId() != mediaId;
}, Timeout.getLargeTimeout()); }, Timeout.getLargeTimeout());
assertTrue(stoppedPlaying); assertTrue(stoppedPlaying);
startLocalPlayback(); startLocalPlayback();
boolean startedReplay = solo.waitForCondition(() -> { boolean startedReplay = solo.waitForCondition(() -> {
if(getCurrentMedia() != null) { if(uiTestUtils.getCurrentMedia(getActivity()) != null) {
return getCurrentMedia().getId() == mediaId; return uiTestUtils.getCurrentMedia(getActivity()).getId() == mediaId;
} else { } else {
return false; return false;
} }

View File

@ -21,6 +21,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.EventDistributor;
import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedImage; 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.feed.FeedMedia;
import de.danoeh.antennapod.core.event.QueueEvent; import de.danoeh.antennapod.core.event.QueueEvent;
import de.danoeh.antennapod.core.storage.PodDBAdapter; 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.greenrobot.event.EventBus;
import de.test.antennapod.util.service.download.HTTPBin; import de.test.antennapod.util.service.download.HTTPBin;
import de.test.antennapod.util.syndication.feedgenerator.RSS2Generator; import de.test.antennapod.util.syndication.feedgenerator.RSS2Generator;
@ -219,4 +222,13 @@ public class UITestUtils {
EventDistributor.getInstance().sendFeedUpdateBroadcast(); EventDistributor.getInstance().sendFeedUpdateBroadcast();
EventBus.getDefault().post(new QueueEvent(QueueEvent.Action.ADDED_ITEMS, queue)); 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();
}
} }