Search in sources :

Example 1 with VisibilityTrackerResult

use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult in project prebid-mobile-android by prebid.

the class CreativeVisibilityTrackerTest method visibilityRunnable_runWithViewVisibleForAtLeastMinDuration_CallOnVisibilityChanged_ImpTrackerFiredTrue_IsVisibilityScheduledFalse.

// VisibilityRunnable Tests
@Test
public void visibilityRunnable_runWithViewVisibleForAtLeastMinDuration_CallOnVisibilityChanged_ImpTrackerFiredTrue_IsVisibilityScheduledFalse() throws Exception {
    ViewExposure viewExposure = new ViewExposure(100, new Rect(0, 0, 100, 100), null);
    when(mSpyVisibilityChecker.isVisible(any(View.class))).thenReturn(true);
    when(mSpyVisibilityChecker.checkViewExposure(any(View.class))).thenReturn(viewExposure);
    when(mSpyVisibilityChecker.hasBeenVisible()).thenReturn(true);
    when(mSpyVisibilityChecker.hasRequiredTimeElapsed()).thenReturn(true);
    mCreativeVisibilityTracker.mVisibilityRunnable.run();
    VisibilityTrackerResult result = new VisibilityTrackerResult(NativeEventTracker.EventType.IMPRESSION, viewExposure, true, true);
    verify(mMockVisibilityTrackerListener).onVisibilityChanged(result);
    final VisibilityTrackerOption visibilityTrackerOption = mSpyVisibilityChecker.getVisibilityTrackerOption();
    assertTrue(visibilityTrackerOption.isImpressionTracked());
    assertFalse((Boolean) getFieldValue("mIsVisibilityScheduled"));
}
Also used : Rect(android.graphics.Rect) VisibilityTrackerResult(org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult) ViewExposure(org.prebid.mobile.rendering.utils.exposure.ViewExposure) View(android.view.View) VisibilityTrackerOption(org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption) Test(org.junit.Test)

Example 2 with VisibilityTrackerResult

use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult in project prebid-mobile-android by prebid.

the class CreativeVisibilityTrackerTest method visibilityRunnable_runWithMultipleTrackingOptions_CallOnVisibilityChangedIndependently_NoTrackForVideo.

@Test
public void visibilityRunnable_runWithMultipleTrackingOptions_CallOnVisibilityChangedIndependently_NoTrackForVideo() {
    mockView();
    VisibilityTrackerOption trackerOptionImpression = new VisibilityTrackerOption(NativeEventTracker.EventType.IMPRESSION);
    VisibilityTrackerOption trackerOptionMrc50 = new VisibilityTrackerOption(NativeEventTracker.EventType.VIEWABLE_MRC50);
    VisibilityTrackerOption trackerOptionMrc100 = new VisibilityTrackerOption(NativeEventTracker.EventType.VIEWABLE_MRC100);
    VisibilityTrackerOption trackerOptionViewableVideo50 = new VisibilityTrackerOption(NativeEventTracker.EventType.VIEWABLE_VIDEO50);
    final ViewExposure viewExposure = new ViewExposure(1.0f, new Rect(), new ArrayList<>());
    Set<VisibilityTrackerOption> visibilityTrackerOptionSet = new HashSet<>();
    visibilityTrackerOptionSet.add(trackerOptionImpression);
    visibilityTrackerOptionSet.add(trackerOptionMrc50);
    visibilityTrackerOptionSet.add(trackerOptionMrc100);
    visibilityTrackerOptionSet.add(trackerOptionViewableVideo50);
    CreativeVisibilityTracker creativeVisibilityTracker = new CreativeVisibilityTracker(mMockView, visibilityTrackerOptionSet);
    creativeVisibilityTracker.setVisibilityTrackerListener(mMockVisibilityTrackerListener);
    mockVisibilityChecker(creativeVisibilityTracker, viewExposure, visibilityTrackerOptionSet);
    creativeVisibilityTracker.mVisibilityRunnable.run();
    // 0 sec visibility duration
    assertTrue(trackerOptionImpression.isImpressionTracked());
    ShadowSystemClock.advanceBy(Duration.ofMillis(1000));
    // 1 sec visibility duration
    assertTrue(trackerOptionMrc50.isImpressionTracked());
    assertTrue(trackerOptionMrc100.isImpressionTracked());
    // 2 sec visibility duration
    assertFalse(trackerOptionViewableVideo50.isImpressionTracked());
    VisibilityTrackerResult impressionResult = new VisibilityTrackerResult(NativeEventTracker.EventType.IMPRESSION, viewExposure, true, true);
    VisibilityTrackerResult mrc50Result = new VisibilityTrackerResult(NativeEventTracker.EventType.VIEWABLE_MRC50, viewExposure, true, true);
    VisibilityTrackerResult mrc100Result = new VisibilityTrackerResult(NativeEventTracker.EventType.VIEWABLE_MRC100, viewExposure, true, true);
    VisibilityTrackerResult videoResult = new VisibilityTrackerResult(NativeEventTracker.EventType.VIEWABLE_VIDEO50, viewExposure, true, true);
    verify(mMockVisibilityTrackerListener, times(1)).onVisibilityChanged(eq(impressionResult));
    verify(mMockVisibilityTrackerListener, times(1)).onVisibilityChanged(eq(mrc50Result));
    verify(mMockVisibilityTrackerListener, times(1)).onVisibilityChanged(eq(mrc100Result));
    verify(mMockVisibilityTrackerListener, times(0)).onVisibilityChanged(eq(videoResult));
}
Also used : Rect(android.graphics.Rect) VisibilityTrackerResult(org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult) VisibilityTrackerOption(org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption) ViewExposure(org.prebid.mobile.rendering.utils.exposure.ViewExposure) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with VisibilityTrackerResult

use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult in project prebid-mobile-android by prebid.

the class HTMLCreativeTest method viewabilityTrackListenerExecutionIsViewable_trackImpression.

@Test
public void viewabilityTrackListenerExecutionIsViewable_trackImpression() {
    ViewExposure viewExposure = new ViewExposure();
    PrebidWebViewBase mockPrebidWebViewBase = mock(PrebidWebViewBase.class);
    when(mockPrebidWebViewBase.getWebView()).thenReturn(mock(WebViewBase.class));
    mHtmlCreative.setCreativeView(mockPrebidWebViewBase);
    VisibilityTrackerResult result = new VisibilityTrackerResult(NativeEventTracker.EventType.IMPRESSION, viewExposure, true, true);
    mHtmlCreative.onVisibilityEvent(result);
    verify(mMockModel, times(1)).trackDisplayAdEvent(TrackingEvent.Events.IMPRESSION);
    verify(mockPrebidWebViewBase, times(1)).onWindowFocusChanged(true);
    verify(mockPrebidWebViewBase, times(1)).onViewExposureChange(viewExposure);
}
Also used : PrebidWebViewBase(org.prebid.mobile.rendering.views.webview.PrebidWebViewBase) WebViewBase(org.prebid.mobile.rendering.views.webview.WebViewBase) PrebidWebViewBase(org.prebid.mobile.rendering.views.webview.PrebidWebViewBase) VisibilityTrackerResult(org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult) ViewExposure(org.prebid.mobile.rendering.utils.exposure.ViewExposure) Test(org.junit.Test)

Example 4 with VisibilityTrackerResult

use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult in project prebid-mobile-android by prebid.

the class VideoViewTest method handleVisibilityChange_visible_validPlayState_ExecutePlay.

@Test
public void handleVisibilityChange_visible_validPlayState_ExecutePlay() {
    changeVideoViewState(PLAYBACK_NOT_STARTED);
    VisibilityTrackerResult result = new VisibilityTrackerResult(NativeEventTracker.EventType.IMPRESSION, new ViewExposure(), true, true);
    mVisibilityTrackerListener.onVisibilityChanged(result);
    verify(mMockAdViewManager).show();
    assertEquals(PLAYING, getVideoViewState());
}
Also used : VisibilityTrackerResult(org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult) ViewExposure(org.prebid.mobile.rendering.utils.exposure.ViewExposure) Test(org.junit.Test)

Example 5 with VisibilityTrackerResult

use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult in project prebid-mobile-android by prebid.

the class HTMLCreativeTest method viewabilityTrackListenerExecution_TrackOnWindowFocusChangeAndOnViewExposureChange.

@Test
public void viewabilityTrackListenerExecution_TrackOnWindowFocusChangeAndOnViewExposureChange() throws Exception {
    PrebidWebViewBase mockPrebidWebViewBase = mock(PrebidWebViewBase.class);
    when(mockPrebidWebViewBase.getWebView()).thenReturn(mock(WebViewBase.class));
    mHtmlCreative.setCreativeView(mockPrebidWebViewBase);
    VisibilityTrackerResult result = new VisibilityTrackerResult(NativeEventTracker.EventType.IMPRESSION, null, false, false);
    doAnswer(invocation -> {
        CreativeVisibilityTracker.VisibilityTrackerListener listener = invocation.getArgument(0);
        listener.onVisibilityChanged(result);
        return null;
    }).when(mMockCreativeVisibilityTracker).setVisibilityTrackerListener(any(CreativeVisibilityTracker.VisibilityTrackerListener.class));
    mHtmlCreative.onVisibilityEvent(result);
    verify(mMockModel, never()).trackDisplayAdEvent(TrackingEvent.Events.IMPRESSION);
    verify(mockPrebidWebViewBase, times(1)).onWindowFocusChanged(false);
    verify(mockPrebidWebViewBase, times(1)).onViewExposureChange(null);
}
Also used : PrebidWebViewBase(org.prebid.mobile.rendering.views.webview.PrebidWebViewBase) WebViewBase(org.prebid.mobile.rendering.views.webview.WebViewBase) PrebidWebViewBase(org.prebid.mobile.rendering.views.webview.PrebidWebViewBase) VisibilityTrackerResult(org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 VisibilityTrackerResult (org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult)7 ViewExposure (org.prebid.mobile.rendering.utils.exposure.ViewExposure)5 VisibilityTrackerOption (org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption)4 View (android.view.View)3 Rect (android.graphics.Rect)2 PrebidWebViewBase (org.prebid.mobile.rendering.views.webview.PrebidWebViewBase)2 WebViewBase (org.prebid.mobile.rendering.views.webview.WebViewBase)2 HashSet (java.util.HashSet)1