Search in sources :

Example 11 with PrebidWebViewBase

use of org.prebid.mobile.rendering.views.webview.PrebidWebViewBase in project prebid-mobile-android by prebid.

the class HTMLCreative method load.

@Override
public void load() throws AdException {
    if (mContextReference == null || mContextReference.get() == null) {
        throw new AdException(AdException.INTERNAL_ERROR, "Context is null. Could not load adHtml");
    }
    CreativeModel model = getCreativeModel();
    AdConfiguration.AdUnitIdentifierType adType = model.getAdConfiguration().getAdUnitIdentifierType();
    if (model.getAdConfiguration().isBuiltInVideo()) {
        adType = AdConfiguration.AdUnitIdentifierType.BANNER;
    }
    if (adType == null) {
        throw new AdException(AdException.INTERNAL_ERROR, "Can't create a WebView for a null adtype");
    }
    // create a webview here
    PrebidWebViewBase prebidWebView = null;
    if (adType == AdConfiguration.AdUnitIdentifierType.BANNER) {
        // do all banner
        prebidWebView = (PrebidWebViewBanner) ViewPool.getInstance().getUnoccupiedView(mContextReference.get(), null, adType, mInterstitialManager);
    } else if (adType == AdConfiguration.AdUnitIdentifierType.INTERSTITIAL) {
        // do all interstitials
        prebidWebView = (PrebidWebViewInterstitial) ViewPool.getInstance().getUnoccupiedView(mContextReference.get(), null, adType, mInterstitialManager);
    }
    if (prebidWebView == null) {
        throw new AdException(AdException.INTERNAL_ERROR, "PrebidWebView creation failed");
    }
    prebidWebView.setWebViewDelegate(this);
    prebidWebView.setCreative(this);
    String html = model.getHtml();
    int width = model.getWidth();
    int height = model.getHeight();
    if (TextUtils.isEmpty(html)) {
        String msg = "No HTML in creative data";
        LogUtil.error(TAG, msg);
        throw new AdException(AdException.SERVER_ERROR, msg);
    } else {
        html = injectingScriptContent(html);
        prebidWebView.loadHTML(html, width, height);
        setCreativeView(prebidWebView);
    }
    mIsEndCard = model.hasEndCard();
}
Also used : PrebidWebViewInterstitial(org.prebid.mobile.rendering.views.webview.PrebidWebViewInterstitial) PrebidWebViewBase(org.prebid.mobile.rendering.views.webview.PrebidWebViewBase) AdException(org.prebid.mobile.rendering.errors.AdException)

Example 12 with PrebidWebViewBase

use of org.prebid.mobile.rendering.views.webview.PrebidWebViewBase in project prebid-mobile-android by prebid.

the class MraidResizeTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    PrebidWebViewBase prebidWebViewBase = mock(PrebidWebViewBase.class);
    mMockContext = Robolectric.buildActivity(Activity.class).create().get().getApplicationContext();
    mSpyBaseJsInterface = spy(new BaseJSInterface(mMockContext, mMockWebViewBase, mMockJsExecutor));
    when(mSpyBaseJsInterface.getMraidVariableContainer()).thenReturn(mMockMraidVariableContainer);
    when(mMockWebViewBase.post(any(Runnable.class))).thenAnswer(invocation -> {
        Runnable runnable = invocation.getArgument(0);
        runnable.run();
        return null;
    });
    doAnswer(invocation -> {
        Handler handler = invocation.getArgument(0);
        Message message = new Message();
        Bundle data = new Bundle();
        data.putString(JSInterface.JSON_VALUE, "{\"width\":320,\"height\":250,\"customClosePosition\":\"top-right\",\"offsetX\":0,\"offsetY\":0,\"allowOffscreen\":true}");
        message.setData(data);
        handler.handleMessage(message);
        return null;
    }).when(mMockJsExecutor).executeGetResizeProperties(any(Handler.class));
    when(mMockWebViewBase.getParent()).thenReturn(prebidWebViewBase);
    when(mSpyBaseJsInterface.getDefaultAdContainer()).thenReturn(prebidWebViewBase);
    mMraidResize = new MraidResize(mMockContext, mSpyBaseJsInterface, mMockWebViewBase, mMockManager);
}
Also used : BaseJSInterface(org.prebid.mobile.rendering.views.webview.mraid.BaseJSInterface) PrebidWebViewBase(org.prebid.mobile.rendering.views.webview.PrebidWebViewBase) Message(android.os.Message) Bundle(android.os.Bundle) Handler(android.os.Handler) Before(org.junit.Before)

Example 13 with PrebidWebViewBase

use of org.prebid.mobile.rendering.views.webview.PrebidWebViewBase in project prebid-mobile-android by prebid.

the class MraidControllerTest method expandWhenHelperNotEmpty_NewWebViewSetEvent.

@Test
public void expandWhenHelperNotEmpty_NewWebViewSetEvent() {
    WebViewBase mockOldWebView = mock(WebViewBase.class);
    PrebidWebViewBase mockNewWebView = mock(PrebidWebViewBase.class);
    MraidEvent event = createMraidEvent(JSInterface.ACTION_EXPAND, "twoPart");
    WebViewBanner mockBanner = mock(WebViewBanner.class);
    when(mockNewWebView.getMraidWebView()).thenReturn(mockBanner);
    when(mockOldWebView.getMraidListener()).thenReturn(mock(MraidEventsManager.MraidListener.class));
    mMraidController.expand(mockOldWebView, mockNewWebView, event);
    verify(mockNewWebView, times(1)).getMraidWebView();
    verify(mockBanner).setMraidEvent(eq(event));
}
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) MraidEvent(org.prebid.mobile.rendering.models.internal.MraidEvent) WebViewBanner(org.prebid.mobile.rendering.views.webview.WebViewBanner) Test(org.junit.Test)

Example 14 with PrebidWebViewBase

use of org.prebid.mobile.rendering.views.webview.PrebidWebViewBase 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)

Example 15 with PrebidWebViewBase

use of org.prebid.mobile.rendering.views.webview.PrebidWebViewBase in project prebid-mobile-android by prebid.

the class HTMLCreativeTest method adSessionFailureInitializationTest.

@Test
public void adSessionFailureInitializationTest() throws Exception {
    PrebidWebViewBase prebidWebViewBase = new PrebidWebViewBase(mContext, mMockInterstitialManager);
    WhiteBox.setInternalState(prebidWebViewBase, "mWebView", mock(WebViewBase.class));
    mHtmlCreative.setCreativeView(prebidWebViewBase);
    HTMLCreative spyHtmlCreative = spy(mHtmlCreative);
    spyHtmlCreative.display();
    verify(spyHtmlCreative, never()).addOmFriendlyObstruction(any(InternalFriendlyObstruction.class));
}
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) InternalFriendlyObstruction(org.prebid.mobile.rendering.models.internal.InternalFriendlyObstruction) Test(org.junit.Test)

Aggregations

PrebidWebViewBase (org.prebid.mobile.rendering.views.webview.PrebidWebViewBase)19 Test (org.junit.Test)12 WebViewBase (org.prebid.mobile.rendering.views.webview.WebViewBase)8 HTMLCreative (org.prebid.mobile.rendering.models.HTMLCreative)3 View (android.view.View)2 MraidEvent (org.prebid.mobile.rendering.models.internal.MraidEvent)2 VisibilityTrackerResult (org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult)2 BaseJSInterface (org.prebid.mobile.rendering.views.webview.mraid.BaseJSInterface)2 Context (android.content.Context)1 Rect (android.graphics.Rect)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 Message (android.os.Message)1 FrameLayout (android.widget.FrameLayout)1 WeakReference (java.lang.ref.WeakReference)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Before (org.junit.Before)1 AdException (org.prebid.mobile.rendering.errors.AdException)1 AdBaseDialog (org.prebid.mobile.rendering.interstitial.AdBaseDialog)1