Search in sources :

Example 1 with InterstitialManager

use of org.prebid.mobile.rendering.views.interstitial.InterstitialManager in project prebid-mobile-android by prebid.

the class AdBrowserActivityTest method browserControlsTest.

@Test
public void browserControlsTest() throws IllegalAccessException {
    WebView mockWebView = mock(WebView.class);
    when(mockWebView.getUrl()).thenReturn("url");
    when(mockWebView.canGoForward()).thenReturn(true);
    when(mockWebView.canGoBack()).thenReturn(true);
    InterstitialManager mockManager = mock(InterstitialManager.class);
    when(mockManager.getInterstitialDisplayDelegate()).thenReturn(null);
    WhiteBox.field(AdBrowserActivity.class, "mShouldFireEvents").set(mAdBrowserActivity, true);
    WhiteBox.field(AdBrowserActivity.class, "mWebView").set(mAdBrowserActivity, mockWebView);
    BrowserControlsEventsListener eventsListener = ((BrowserControls) WhiteBox.field(AdBrowserActivity.class, "mBrowserControls").get(mAdBrowserActivity)).getBrowserControlsEventsListener();
    eventsListener.onRelaod();
    verify(mockWebView).reload();
    eventsListener.onGoForward();
    verify(mockWebView).goForward();
    eventsListener.onGoBack();
    verify(mockWebView).goBack();
    assertEquals("url", eventsListener.getCurrentURL());
    assertTrue(eventsListener.canGoBack());
    assertTrue(eventsListener.canGoForward());
    // TODO: 2/10/21 verify broadcast
    eventsListener.closeBrowser();
}
Also used : InterstitialManager(org.prebid.mobile.rendering.views.interstitial.InterstitialManager) WebView(android.webkit.WebView) Test(org.junit.Test)

Example 2 with InterstitialManager

use of org.prebid.mobile.rendering.views.interstitial.InterstitialManager in project prebid-mobile-android by prebid.

the class AdInterstitialDialogTest method handleCloseClick.

@Test
public void handleCloseClick() throws IllegalAccessException {
    InterstitialManager interstitialManager = mock(InterstitialManager.class);
    Field interstitialManagerField = WhiteBox.field(AdInterstitialDialog.class, "mInterstitialManager");
    interstitialManagerField.set(mAdInterstitialDialog, interstitialManager);
    mAdInterstitialDialog.handleCloseClick();
    verify(interstitialManager).interstitialClosed(mMockWebViewBase);
}
Also used : Field(java.lang.reflect.Field) InterstitialManager(org.prebid.mobile.rendering.views.interstitial.InterstitialManager) Test(org.junit.Test)

Example 3 with InterstitialManager

use of org.prebid.mobile.rendering.views.interstitial.InterstitialManager in project prebid-mobile-android by prebid.

the class TransactionTest method testTransactionInit.

@Test
public void testTransactionInit() throws Exception {
    List<CreativeModel> creativeModels = new ArrayList<>();
    CreativeModel mockCreativeModel = mock(CreativeModel.class);
    creativeModels.add(mockCreativeModel);
    Transaction.Listener mockOxTransactionListener = mock(Transaction.Listener.class);
    // Valid
    InterstitialManager mockInterstitialManager = mock(InterstitialManager.class);
    Transaction transaction = Transaction.createTransaction(mMockContext, createModelResult(creativeModels, "ts"), mockInterstitialManager, mockOxTransactionListener);
    assertNotNull(transaction);
    // No context
    boolean hasException = false;
    try {
        Transaction.createTransaction(null, createModelResult(creativeModels, "ts"), mockInterstitialManager, mockOxTransactionListener);
    } catch (AdException e) {
        hasException = true;
    }
    assertTrue(hasException);
    // No creative models
    hasException = false;
    try {
        Transaction.createTransaction(mMockContext, createModelResult(null, "ts"), mockInterstitialManager, mockOxTransactionListener);
    } catch (AdException e) {
        hasException = true;
    }
    assertTrue(hasException);
    // Empty creative models
    hasException = false;
    try {
        Transaction.createTransaction(mMockContext, createModelResult(new ArrayList<>(), "ts"), mockInterstitialManager, mockOxTransactionListener);
    } catch (AdException e) {
        hasException = true;
    }
    assertTrue(hasException);
    // No listener
    hasException = false;
    try {
        Transaction.createTransaction(mMockContext, createModelResult(creativeModels, "ts"), mockInterstitialManager, null);
    } catch (AdException e) {
        hasException = true;
    }
    assertTrue(hasException);
}
Also used : CreativeModel(org.prebid.mobile.rendering.models.CreativeModel) ArrayList(java.util.ArrayList) InterstitialManager(org.prebid.mobile.rendering.views.interstitial.InterstitialManager) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Example 4 with InterstitialManager

use of org.prebid.mobile.rendering.views.interstitial.InterstitialManager in project prebid-mobile-android by prebid.

the class PrebidWebViewBannerTest method preloadedTest.

@Test
public void preloadedTest() {
    WebViewDelegate mockDelegate = mock(WebViewDelegate.class);
    InterstitialManager mockManager = mock(InterstitialManager.class);
    mBanner.mWebViewDelegate = mockDelegate;
    mBanner.mInterstitialManager = mockManager;
    MraidEvent mockEvent = mock(MraidEvent.class);
    when(mMockWebViewBanner.getMraidEvent()).thenReturn(mockEvent);
    mBanner.preloaded(null);
    verify(mockDelegate).webViewFailedToLoad(any(AdException.class));
    mMockWebViewBanner.mMRAIDBridgeName = "twopart";
    mBanner.preloaded(mMockWebViewBanner);
    verify(mockManager).displayPrebidWebViewForMraid(eq(mMockWebViewBanner), eq(true));
    mMockWebViewBanner.mMRAIDBridgeName = "else";
    mBanner.preloaded(mMockWebViewBanner);
    // verify render
    verify(mMockWebViewBanner).setAdWidth(anyInt());
    when(mMockWebViewBanner.getParent()).thenReturn(mock(ViewGroup.class));
    mBanner.preloaded(mMockWebViewBanner);
    verify(mMockWebViewBanner).bringToFront();
    verify(mockDelegate, times(3)).webViewReadyToDisplay();
}
Also used : WebViewDelegate(org.prebid.mobile.rendering.listeners.WebViewDelegate) ViewGroup(android.view.ViewGroup) InterstitialManager(org.prebid.mobile.rendering.views.interstitial.InterstitialManager) MraidEvent(org.prebid.mobile.rendering.models.internal.MraidEvent) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Example 5 with InterstitialManager

use of org.prebid.mobile.rendering.views.interstitial.InterstitialManager in project prebid-mobile-android by prebid.

the class ViewPoolTest method getUnoccupiedViewTest.

@Test
public void getUnoccupiedViewTest() throws AdException {
    VideoCreativeViewListener mockVideoCreativeViewListener = mock(VideoCreativeViewListener.class);
    AdConfiguration.AdUnitIdentifierType adType = AdConfiguration.AdUnitIdentifierType.BANNER;
    InterstitialManager mockInterstitialManager = mock(InterstitialManager.class);
    View result = mViewPool.getUnoccupiedView(mContext, mockVideoCreativeViewListener, adType, mockInterstitialManager);
    assertEquals(mUnoccupiedView, result);
    assertEquals(2, mViewPool.sizeOfOccupied());
    assertEquals(0, mViewPool.sizeOfUnoccupied());
    result = mViewPool.getUnoccupiedView(mContext, mockVideoCreativeViewListener, adType, mockInterstitialManager);
    assertThat(result, instanceOf(PrebidWebViewBanner.class));
    assertEquals(3, mViewPool.sizeOfOccupied());
    assertEquals(0, mViewPool.sizeOfUnoccupied());
    adType = AdConfiguration.AdUnitIdentifierType.VAST;
    result = mViewPool.getUnoccupiedView(mContext, mock(VideoCreative.class), adType, mockInterstitialManager);
    assertThat(result, instanceOf(ExoPlayerView.class));
    assertEquals(4, mViewPool.sizeOfOccupied());
    assertEquals(0, mViewPool.sizeOfUnoccupied());
    adType = AdConfiguration.AdUnitIdentifierType.INTERSTITIAL;
    result = mViewPool.getUnoccupiedView(mContext, mockVideoCreativeViewListener, adType, mockInterstitialManager);
    assertThat(result, instanceOf(PrebidWebViewInterstitial.class));
    assertEquals(5, mViewPool.sizeOfOccupied());
    assertEquals(0, mViewPool.sizeOfUnoccupied());
}
Also used : PrebidWebViewInterstitial(org.prebid.mobile.rendering.views.webview.PrebidWebViewInterstitial) VideoCreativeViewListener(org.prebid.mobile.rendering.listeners.VideoCreativeViewListener) InterstitialManager(org.prebid.mobile.rendering.views.interstitial.InterstitialManager) PrebidWebViewBanner(org.prebid.mobile.rendering.views.webview.PrebidWebViewBanner) ExoPlayerView(org.prebid.mobile.rendering.video.ExoPlayerView) ExoPlayerView(org.prebid.mobile.rendering.video.ExoPlayerView) View(android.view.View) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 InterstitialManager (org.prebid.mobile.rendering.views.interstitial.InterstitialManager)7 AdException (org.prebid.mobile.rendering.errors.AdException)3 Field (java.lang.reflect.Field)2 CreativeModel (org.prebid.mobile.rendering.models.CreativeModel)2 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 WebView (android.webkit.WebView)1 ArrayList (java.util.ArrayList)1 VideoCreativeViewListener (org.prebid.mobile.rendering.listeners.VideoCreativeViewListener)1 WebViewDelegate (org.prebid.mobile.rendering.listeners.WebViewDelegate)1 MraidEvent (org.prebid.mobile.rendering.models.internal.MraidEvent)1 ExoPlayerView (org.prebid.mobile.rendering.video.ExoPlayerView)1 PrebidWebViewBanner (org.prebid.mobile.rendering.views.webview.PrebidWebViewBanner)1 PrebidWebViewInterstitial (org.prebid.mobile.rendering.views.webview.PrebidWebViewInterstitial)1