VastVideoViewController extends BaseVideoViewController implements DownloadTask.DownloadTaskListener { @Override protected void onResume() { mVideoRetries = 0; startRunnables(); 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_whenVideoLessThan16Seconds_andClickAfterEnd_shouldStartMoPubBrowser() throws Exception { initializeSubject(); spyOnVideoView(); setVideoViewParams(15999, 15999); subject.onResume(); 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_URL); }
@Test public void onTouch_withTouchUp_whenVideoLongerThan16Seconds_andClickBefore5Seconds_shouldDoNothing() throws Exception { initializeSubject(); spyOnVideoView(); setVideoViewParams(4999, 100000); subject.onResume(); 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 { initializeSubject(); spyOnVideoView(); setVideoViewParams(5001, 100000); subject.onResume(); 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_URL); }
@Test public void onCompletion_shouldPreventOnResumeFromStartingVideo() throws Exception { initializeSubject(); getShadowVideoView().getOnCompletionListener().onCompletion(null); subject.onResume(); assertThat(getShadowVideoView().isPlaying()).isFalse(); }
@Test public void onCompletion_shouldStopProgressCheckerAndCountdown() throws Exception { initializeSubject(); subject.onResume(); reset(spyCountdownRunnable, spyCountdownRunnable); getShadowVideoView().getOnCompletionListener().onCompletion(null); verify(spyCountdownRunnable).stop(); verify(spyProgressRunnable).stop(); }
@Test public void onError_shouldStopProgressChecker() throws Exception { initializeSubject(); subject.onResume(); verify(spyProgressRunnable).startRepeating(anyLong()); verify(spyCountdownRunnable).startRepeating(anyLong()); reset(spyProgressRunnable, spyCountdownRunnable); getShadowVideoView().getOnErrorListener().onError(null, 0, 0); verify(spyProgressRunnable).stop(); verify(spyCountdownRunnable).stop(); }
@Test public void videoRunnablesRun_shouldFireOffAllProgressTrackers() throws Exception { VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration(); vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path"); vastVideoConfiguration.addFractionalTrackers(Arrays.asList(new VastFractionalProgressTracker("first", 0.25f), new VastFractionalProgressTracker("second", 0.5f), new VastFractionalProgressTracker("third", 0.75f))); bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration); initializeSubject(); spyOnVideoView(); setVideoViewParams(9002, 9002); subject.onResume(); Robolectric.getUiThreadScheduler().unPause(); verify(mockRequestQueue).add(argThat(isUrl("first"))); verify(mockRequestQueue).add(argThat(isUrl("second"))); verify(mockRequestQueue).add(argThat(isUrl("third"))); }
@Test public void videoRunnablesRun_whenDurationIsInvalid_shouldNotMakeAnyNetworkCalls() throws Exception { VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration(); vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path"); bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration); initializeSubject(); spyOnVideoView(); setVideoViewParams(0, 100); subject.onResume(); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); Robolectric.getUiThreadScheduler().runTasks(2); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); verifyZeroInteractions(mockRequestQueue); }
@Test public void videoRunnablesRun_whenCurrentTimeLessThanTwoSeconds_shouldNotFireStartTracker() throws Exception { VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration(); vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path"); vastVideoConfiguration.addAbsoluteTrackers(Arrays.asList(new VastAbsoluteProgressTracker("start", 2000))); bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration); initializeSubject(); spyOnVideoView(); setVideoViewParams(1999, 100000); subject.onResume(); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); Robolectric.getUiThreadScheduler().runTasks(2); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); verifyZeroInteractions(mockRequestQueue); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); Robolectric.getUiThreadScheduler().runTasks(2); verifyZeroInteractions(mockRequestQueue); }
@Test public void videoRunnablesRun_whenCurrentTimeGreaterThanTwoSeconds_shouldFireStartTracker() throws Exception { VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration(); vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path"); vastVideoConfiguration.addAbsoluteTrackers(Arrays.asList(new VastAbsoluteProgressTracker("start", 2000))); vastVideoConfiguration.addAbsoluteTrackers(Arrays.asList(new VastAbsoluteProgressTracker("later", 3000))); bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration); initializeSubject(); spyOnVideoView(); setVideoViewParams(2000, 100000); subject.onResume(); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); Robolectric.getUiThreadScheduler().unPause(); verify(mockRequestQueue).add(argThat(isUrl("start"))); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); Robolectric.getUiThreadScheduler().runTasks(2); verifyNoMoreInteractions(mockRequestQueue); }
@Test public void videoRunnablesRun_whenProgressIsPastFirstQuartile_shouldOnlyPingFirstQuartileTrackersOnce() throws Exception { VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration(); vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path"); vastVideoConfiguration.addFractionalTrackers(Arrays.asList(new VastFractionalProgressTracker("first", 0.25f))); vastVideoConfiguration.addFractionalTrackers(Arrays.asList(new VastFractionalProgressTracker("don't call", 0.28f))); bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration); initializeSubject(); spyOnVideoView(); setVideoViewParams(26, 100); subject.onResume(); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); Robolectric.getUiThreadScheduler().unPause(); verify(mockRequestQueue).add(argThat(isUrl("first"))); Robolectric.getUiThreadScheduler().runTasks(2); verifyNoMoreInteractions(mockRequestQueue); }
@Test public void videoRunnablesRun_whenProgressIsPastMidQuartile_shouldPingFirstQuartileTrackers_andMidQuartileTrackersBothOnlyOnce() throws Exception { VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration(); vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path"); vastVideoConfiguration.addFractionalTrackers(Arrays.asList(new VastFractionalProgressTracker("first", 0.25f))); vastVideoConfiguration.addFractionalTrackers(Arrays.asList(new VastFractionalProgressTracker("second", 0.5f))); bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration); initializeSubject(); spyOnVideoView(); setVideoViewParams(51, 100); subject.onResume(); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); Robolectric.getUiThreadScheduler().unPause(); verify(mockRequestQueue).add(argThat(isUrl("first"))); verify(mockRequestQueue).add(argThat(isUrl("second"))); Robolectric.getUiThreadScheduler().runTasks(2); verifyNoMoreInteractions(mockRequestQueue); }
@Test public void videoRunnablesRun_whenProgressIsPastThirdQuartile_shouldPingFirstQuartileTrackers_andMidQuartileTrackers_andThirdQuartileTrackersAllOnlyOnce() throws Exception { VastVideoConfiguration vastVideoConfiguration = new VastVideoConfiguration(); vastVideoConfiguration.setDiskMediaFileUrl("disk_video_path"); vastVideoConfiguration.addFractionalTrackers(Arrays.asList(new VastFractionalProgressTracker("first", 0.25f))); vastVideoConfiguration.addFractionalTrackers(Arrays.asList(new VastFractionalProgressTracker("second", 0.5f))); vastVideoConfiguration.addFractionalTrackers(Arrays.asList(new VastFractionalProgressTracker("third", 0.75f))); bundle.putSerializable(VAST_VIDEO_CONFIGURATION, vastVideoConfiguration); initializeSubject(); spyOnVideoView(); setVideoViewParams(76, 100); subject.onResume(); assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(2); Robolectric.getUiThreadScheduler().unPause(); verify(mockRequestQueue).add(argThat(isUrl("first"))); verify(mockRequestQueue).add(argThat(isUrl("second"))); verify(mockRequestQueue).add(argThat(isUrl("third"))); Robolectric.getUiThreadScheduler().runTasks(2); verifyNoMoreInteractions(mockRequestQueue); }
@Test public void onResume_shouldSetVideoViewStateToStarted() throws Exception { initializeSubject(); subject.onResume(); assertThat(getShadowVideoView().getCurrentVideoState()).isEqualTo(ShadowVideoView.START); assertThat(getShadowVideoView().getPrevVideoState()).isNotEqualTo(ShadowVideoView.START); }