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();
}
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);
}
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));
}
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);
}
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));
}
Aggregations