Search in sources :

Example 31 with MoPubView

use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.

the class MoPubBannerFragment method setupBannerWithoutWait.

private void setupBannerWithoutWait() {
    adView = new MoPubView(this.getActivity());
    FrameLayout adFrame = (FrameLayout) root.findViewById(R.id.adFrame);
    adFrame.removeAllViews();
    adView.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_320x50);
    adView.setBannerAdListener(this);
    adView.setAutorefreshEnabled(true);
    adView.setMinimumWidth(320);
    adView.setMinimumHeight(50);
    adView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL));
    adFrame.addView(adView);
    Prebid.attachBids(adView, Constants.BANNER_320x50, this.getActivity());
    adView.loadAd();
}
Also used : FrameLayout(android.widget.FrameLayout) MoPubView(com.mopub.mobileads.MoPubView)

Example 32 with MoPubView

use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.

the class ExtraTests method testRubiconEmptyInvalidPrebidServerConfigId.

@Test
public void testRubiconEmptyInvalidPrebidServerConfigId() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("1001");
    PrebidMobile.setPrebidServerHost(Host.RUBICON);
    PrebidMobile.setShareGeoLocation(true);
    final OnCompleteListener[] listener = new OnCompleteListener[1];
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            final MoPubView adObject = new MoPubView(m.getActivity());
            adObject.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_RUBICON);
            adObject.setMinimumHeight(250);
            adObject.setMinimumWidth(300);
            BannerAdUnit adUnit = new BannerAdUnit("", 300, 250);
            OnCompleteListener l = new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
                    adFrame.addView(adObject);
                    adObject.loadAd();
                }
            };
            listener[0] = spy(l);
            adUnit.fetchDemand(adObject, listener[0]);
        }
    });
    Thread.sleep(2000);
    verify(listener[0], times(1)).onComplete(ResultCode.INVALID_CONFIG_ID);
}
Also used : OnCompleteListener(org.prebid.mobile.OnCompleteListener) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) BannerAdUnit(org.prebid.mobile.BannerAdUnit) Test(org.junit.Test)

Example 33 with MoPubView

use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.

the class ExtraTests method testRubiconEmptyInvalidPrebidServerAccountId.

@Test
public void testRubiconEmptyInvalidPrebidServerAccountId() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("");
    PrebidMobile.setPrebidServerHost(Host.RUBICON);
    PrebidMobile.setShareGeoLocation(true);
    final OnCompleteListener[] listener = new OnCompleteListener[1];
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            final MoPubView adObject = new MoPubView(m.getActivity());
            adObject.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_RUBICON);
            adObject.setMinimumHeight(250);
            adObject.setMinimumWidth(300);
            BannerAdUnit adUnit = new BannerAdUnit("1001-1", 300, 250);
            OnCompleteListener l = new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
                    adFrame.addView(adObject);
                    adObject.loadAd();
                }
            };
            listener[0] = spy(l);
            adUnit.fetchDemand(adObject, listener[0]);
        }
    });
    Thread.sleep(2000);
    verify(listener[0], times(1)).onComplete(ResultCode.INVALID_ACCOUNT_ID);
}
Also used : OnCompleteListener(org.prebid.mobile.OnCompleteListener) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) BannerAdUnit(org.prebid.mobile.BannerAdUnit) Test(org.junit.Test)

Example 34 with MoPubView

use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.

the class ExtraTests method testAppNexusAgeTargeting1.

// Passing year 1855 is invalid yob, should not send yob and get back a no bid
@Test
public void testAppNexusAgeTargeting1() throws Exception {
    boolean errorThrown = false;
    try {
        TargetingParams.setYearOfBirth(1855);
    } catch (Exception e) {
        errorThrown = true;
        assertEquals(0, TargetingParams.getYearOfBirth());
    }
    assertTrue(errorThrown);
    server.setDispatcher(new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            if (request.getPath().equals("/")) {
                String postData = request.getBody().readUtf8();
                assertTrue("Post data should not contain yob: " + postData, !postData.contains("yob"));
                return getAppNexusDemand(postData);
            }
            return new MockResponse().setResponseCode(404);
        }
    });
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-31c6bb888df0");
    Host.CUSTOM.setHostUrl(server.url("/").toString());
    PrebidMobile.setPrebidServerHost(Host.CUSTOM);
    PrebidMobile.setShareGeoLocation(true);
    final OnCompleteListener[] listener = new OnCompleteListener[1];
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            final MoPubView adObject = new MoPubView(m.getActivity());
            adObject.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_APPNEXUS);
            adObject.setMinimumHeight(250);
            adObject.setMinimumWidth(300);
            BannerAdUnit adUnit = new BannerAdUnit("47706260-ee91-4cd7-b656-2185aca89f59", 300, 250);
            OnCompleteListener l = new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
                    adFrame.addView(adObject);
                    adObject.loadAd();
                }
            };
            listener[0] = spy(l);
            adUnit.fetchDemand(adObject, listener[0]);
        }
    });
    Thread.sleep(10000);
    verify(listener[0], times(1)).onComplete(ResultCode.NO_BIDS);
    onView(withId(R.id.adFrame)).check(matches(isDisplayed()));
    onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com")));
    onWebView().check(webContent(containingTextInBody("Hello, I'm not a Prebid ad.")));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Dispatcher(okhttp3.mockwebserver.Dispatcher) JSONException(org.json.JSONException) IOException(java.io.IOException) BannerAdUnit(org.prebid.mobile.BannerAdUnit) OnCompleteListener(org.prebid.mobile.OnCompleteListener) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) Test(org.junit.Test)

Example 35 with MoPubView

use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.

the class ExtraTests method testAppNexusInvalidPrebidServerAccountId.

@Test
public void testAppNexusInvalidPrebidServerAccountId() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-ffffffffffff");
    PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
    PrebidMobile.setShareGeoLocation(true);
    final OnCompleteListener[] listener = new OnCompleteListener[1];
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            final MoPubView adObject = new MoPubView(m.getActivity());
            adObject.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_APPNEXUS);
            adObject.setMinimumHeight(250);
            adObject.setMinimumWidth(300);
            BannerAdUnit adUnit = new BannerAdUnit("6ace8c7d-88c0-4623-8117-75bc3f0a2e45", 300, 250);
            OnCompleteListener l = new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
                    adFrame.addView(adObject);
                    adObject.loadAd();
                }
            };
            listener[0] = spy(l);
            adUnit.fetchDemand(adObject, listener[0]);
        }
    });
    Thread.sleep(10000);
    verify(listener[0], times(1)).onComplete(ResultCode.INVALID_ACCOUNT_ID);
}
Also used : OnCompleteListener(org.prebid.mobile.OnCompleteListener) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) BannerAdUnit(org.prebid.mobile.BannerAdUnit) Test(org.junit.Test)

Aggregations

MoPubView (com.mopub.mobileads.MoPubView)48 Test (org.junit.Test)38 FrameLayout (android.widget.FrameLayout)26 BannerAdUnit (org.prebid.mobile.BannerAdUnit)23 OnCompleteListener (org.prebid.mobile.OnCompleteListener)23 ResultCode (org.prebid.mobile.ResultCode)23 MockResponse (okhttp3.mockwebserver.MockResponse)15 HttpUrl (okhttp3.HttpUrl)8 Dispatcher (okhttp3.mockwebserver.Dispatcher)8 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)8 Matchers.containsString (org.hamcrest.Matchers.containsString)7 BackgroundThreadExecutor (org.prebid.mobile.tasksmanager.BackgroundThreadExecutor)7 ShadowLooper (org.robolectric.shadows.ShadowLooper)7 MoPubInterstitial (com.mopub.mobileads.MoPubInterstitial)5 JSONException (org.json.JSONException)5 ArrayList (java.util.ArrayList)4 JSONObject (org.json.JSONObject)4 AdUnit (org.prebid.mobile.AdUnit)4 InterstitialAdUnit (org.prebid.mobile.InterstitialAdUnit)4 MoPubErrorCode (com.mopub.mobileads.MoPubErrorCode)3