VastVideoViewController extends BaseVideoViewController implements DownloadTask.DownloadTaskListener { @Override protected void onResume() { mVideoRetries = 0; startProgressChecker(); mVideoView.seekTo(mSeekerPositionOnPause); if (!mIsVideoFinishedPlaying) { mVideoView.start(); } } VastVideoViewController(final Context context,
            final Bundle bundle,
            final long broadcastIdentifier,
            final BaseVideoViewControllerListener baseVideoViewControllerListener); @Override boolean backButtonEnabled(); @Override void onComplete(String url, DownloadResponse downloadResponse);  }
@Test public void onTouch_withTouchUp_whenVideoLongerThan16Seconds_andClickBefore5Seconds_shouldDoNothing() throws Exception { stub(mediaPlayer.getDuration()).toReturn(100000); stub(mediaPlayer.getCurrentPosition()).toReturn(4999); initializeSubject(); subject.onResume(); setMediaPlayer(mediaPlayer); getShadowVideoView().getOnPreparedListener().onPrepared(null); Robolectric.getUiThreadScheduler().unPause(); getShadowVideoView().getOnTouchListener().onTouch(null, GestureUtils.createActionUp(0, 0)); Intent nextStartedActivity = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(nextStartedActivity).isNull(); }
@Test public void onTouch_withTouchUp_whenVideoLongerThan16Seconds_andClickAfter5Seconds_shouldStartMoPubBrowser() throws Exception { stub(mediaPlayer.getDuration()).toReturn(100000); stub(mediaPlayer.getCurrentPosition()).toReturn(5001); initializeSubject(); subject.onResume(); setMediaPlayer(mediaPlayer); getShadowVideoView().getOnPreparedListener().onPrepared(null); Robolectric.getUiThreadScheduler().unPause(); getShadowVideoView().getOnTouchListener().onTouch(null, GestureUtils.createActionUp(0, 0)); ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class); verify(baseVideoViewControllerListener).onStartActivityForResult( eq(MoPubBrowser.class), eq(expectedBrowserRequestCode), bundleCaptor.capture() ); assertThat(bundleCaptor.getValue().get(DESTINATION_URL_KEY)).isEqualTo("clickThrough"); }
@Test public void onCompletion_shouldPreventOnResumeFromStartingVideo() throws Exception { initializeSubject(); getShadowVideoView().getOnCompletionListener().onCompletion(null); subject.onResume(); assertThat(getShadowVideoView().isPlaying()).isFalse(); }
@Test public void videoProgressCheckerRunnableRun_shouldFireOffAllProgressTrackers() throws Exception { stub(mediaPlayer.getDuration()).toReturn(9001); stub(mediaPlayer.getCurrentPosition()).toReturn(9002); VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration(); vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path"); vastVideoConfiguration.addFirstQuartileTrackers(Arrays.asList("first")); vastVideoConfiguration.addMidpointTrackers(Arrays.asList("second")); vastVideoConfiguration.addThirdQuartileTrackers(Arrays.asList("third")); bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration); initializeSubject(); subject.onResume(); setMediaPlayer(mediaPlayer); Robolectric.getUiThreadScheduler().unPause(); Robolectric.getBackgroundScheduler().unPause(); Thread.sleep(NETWORK_DELAY); assertHttpRequestsMade(expectedUserAgent, "first", "second", "third"); }
@Test public void videoProgressCheckerRunnableRun_whenDurationIsInvalid_shouldNotMakeAnyNetworkCalls() throws Exception { stub(mediaPlayer.getDuration()).toReturn(0); stub(mediaPlayer.getCurrentPosition()).toReturn(100); VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration(); vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path"); bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration); initializeSubject(); setMediaPlayer(mediaPlayer); subject.onResume(); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); Robolectric.getUiThreadScheduler().runOneTask(); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(1); Thread.sleep(NETWORK_DELAY); assertThat(Robolectric.httpRequestWasMade()).isFalse(); }
@Test public void videoProgressCheckerRunnableRun_whenCurrentTimeLessThanOneSecond_shouldNotFireStartTracker() throws Exception { VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration(); vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path"); vastVideoConfiguration.addStartTrackers(Arrays.asList("start")); bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration); stub(mediaPlayer.getDuration()).toReturn(100000); stub(mediaPlayer.getCurrentPosition()).toReturn(999); initializeSubject(); subject.onResume(); setMediaPlayer(mediaPlayer); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); Robolectric.getUiThreadScheduler().runOneTask(); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(1); Thread.sleep(NETWORK_DELAY); assertHttpRequestsMade(expectedUserAgent); Robolectric.getFakeHttpLayer().clearRequestInfos(); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(1); Robolectric.getUiThreadScheduler().runOneTask(); Thread.sleep(NETWORK_DELAY); assertThat(Robolectric.httpRequestWasMade()).isFalse(); }
@Test public void videoProgressCheckerRunnableRun_whenCurrentTimeGreaterThanOneSecond_shouldFireStartTracker() throws Exception { VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration(); vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path"); vastVideoConfiguration.addStartTrackers(Arrays.asList("start")); bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration); stub(mediaPlayer.getDuration()).toReturn(100000); stub(mediaPlayer.getCurrentPosition()).toReturn(1000); initializeSubject(); subject.onResume(); setMediaPlayer(mediaPlayer); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); Robolectric.getUiThreadScheduler().unPause(); Robolectric.getBackgroundScheduler().unPause(); Thread.sleep(NETWORK_DELAY); assertHttpRequestsMade(expectedUserAgent, "start"); Robolectric.getFakeHttpLayer().clearRequestInfos(); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(1); Robolectric.getUiThreadScheduler().runOneTask(); Thread.sleep(NETWORK_DELAY); assertThat(Robolectric.httpRequestWasMade()).isFalse(); }
@Test public void videoProgressCheckerRunnableRun_whenProgressIsPastFirstQuartile_shouldOnlyPingFirstQuartileTrackersOnce() throws Exception { stub(mediaPlayer.getDuration()).toReturn(100); stub(mediaPlayer.getCurrentPosition()).toReturn(26); VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration(); vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path"); vastVideoConfiguration.addFirstQuartileTrackers(Arrays.asList("first")); bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration); initializeSubject(); subject.onResume(); setMediaPlayer(mediaPlayer); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); Robolectric.getUiThreadScheduler().unPause(); Robolectric.getBackgroundScheduler().unPause(); Thread.sleep(NETWORK_DELAY); assertHttpRequestsMade(expectedUserAgent, "first"); Robolectric.getFakeHttpLayer().clearRequestInfos(); Robolectric.getUiThreadScheduler().runOneTask(); Thread.sleep(NETWORK_DELAY); assertThat(Robolectric.httpRequestWasMade()).isFalse(); }
@Test public void videoProgressCheckerRunnableRun_whenProgressIsPastMidQuartile_shouldPingFirstQuartileTrackers_andMidQuartileTrackersBothOnlyOnce() throws Exception { stub(mediaPlayer.getDuration()).toReturn(100); stub(mediaPlayer.getCurrentPosition()).toReturn(51); VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration(); vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path"); vastVideoConfiguration.addFirstQuartileTrackers(Arrays.asList("first")); vastVideoConfiguration.addMidpointTrackers(Arrays.asList("second")); bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration); initializeSubject(); subject.onResume(); setMediaPlayer(mediaPlayer); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); Robolectric.getUiThreadScheduler().unPause(); Robolectric.getBackgroundScheduler().unPause(); Thread.sleep(NETWORK_DELAY); assertHttpRequestsMade(expectedUserAgent, "first", "second"); Robolectric.getFakeHttpLayer().clearRequestInfos(); Robolectric.getUiThreadScheduler().runOneTask(); Thread.sleep(NETWORK_DELAY); assertThat(Robolectric.httpRequestWasMade()).isFalse(); }
@Test public void videoProgressCheckerRunnableRun_whenProgressIsPastThirdQuartile_shouldPingFirstQuartileTrackers_andMidQuartileTrackers_andThirdQuartileTrackersAllOnlyOnce() throws Exception { stub(mediaPlayer.getDuration()).toReturn(100); stub(mediaPlayer.getCurrentPosition()).toReturn(76); VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration(); vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path"); vastVideoConfiguration.addFirstQuartileTrackers(Arrays.asList("first")); vastVideoConfiguration.addMidpointTrackers(Arrays.asList("second")); vastVideoConfiguration.addThirdQuartileTrackers(Arrays.asList("third")); bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration); initializeSubject(); subject.onResume(); setMediaPlayer(mediaPlayer); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); Robolectric.getUiThreadScheduler().unPause(); Robolectric.getBackgroundScheduler().unPause(); Thread.sleep(NETWORK_DELAY); assertHttpRequestsMade(expectedUserAgent, "first", "second", "third"); Robolectric.getFakeHttpLayer().clearRequestInfos(); Robolectric.getUiThreadScheduler().runOneTask(); Thread.sleep(NETWORK_DELAY); assertThat(Robolectric.httpRequestWasMade()).isFalse(); }
@Test public void videoProgressCheckerRunnableRun_asVideoPlays_shouldPingAllThreeTrackersIndividuallyOnce() throws Exception { stub(mediaPlayer.getDuration()).toReturn(100); VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration(); vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path"); vastVideoConfiguration.addFirstQuartileTrackers(Arrays.asList("first")); vastVideoConfiguration.addMidpointTrackers(Arrays.asList("second")); vastVideoConfiguration.addThirdQuartileTrackers(Arrays.asList("third")); bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration); initializeSubject(); subject.onResume(); setMediaPlayer(mediaPlayer); fastForwardMediaPlayerAndAssertRequestMade(1); fastForwardMediaPlayerAndAssertRequestMade(24); fastForwardMediaPlayerAndAssertRequestMade(26, "first"); fastForwardMediaPlayerAndAssertRequestMade(49); fastForwardMediaPlayerAndAssertRequestMade(51, "second"); fastForwardMediaPlayerAndAssertRequestMade(74); fastForwardMediaPlayerAndAssertRequestMade(76, "third"); fastForwardMediaPlayerAndAssertRequestMade(99); }
@Test public void onResume_shouldSetVideoViewStateToStarted() throws Exception { initializeSubject(); subject.onResume(); assertThat(getShadowVideoView().getCurrentVideoState()).isEqualTo(ShadowVideoView.START); assertThat(getShadowVideoView().getPrevVideoState()).isNotEqualTo(ShadowVideoView.START); }
@Test public void onTouch_withTouchUp_whenVideoLessThan16Seconds_andClickAfterEnd_shouldStartMoPubBrowser() throws Exception { stub(mediaPlayer.getDuration()).toReturn(15999); stub(mediaPlayer.getCurrentPosition()).toReturn(16000); initializeSubject(); subject.onResume(); setMediaPlayer(mediaPlayer); getShadowVideoView().getOnPreparedListener().onPrepared(null); Robolectric.getUiThreadScheduler().unPause(); getShadowVideoView().getOnTouchListener().onTouch(null, GestureUtils.createActionUp(0, 0)); ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class); verify(baseVideoViewControllerListener).onStartActivityForResult( eq(MoPubBrowser.class), eq(expectedBrowserRequestCode), bundleCaptor.capture() ); assertThat(bundleCaptor.getValue().get(DESTINATION_URL_KEY)).isEqualTo("clickThrough"); }