MoPubActivity extends BaseInterstitialActivity { static void preRenderHtml(final Context context, final CustomEventInterstitialListener customEventInterstitialListener, String htmlData) { HtmlInterstitialWebView dummyWebView = HtmlInterstitialWebViewFactory.create(context, customEventInterstitialListener, false, null, null, null); dummyWebView.enablePlugins(false); dummyWebView.addMoPubUriJavascriptInterface(new HtmlInterstitialWebView.MoPubUriJavascriptFireFinishLoadListener() { @Override public void onInterstitialLoaded() { customEventInterstitialListener.onInterstitialLoaded(); } }); dummyWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.equals(MOPUB_FINISH_LOAD)) { customEventInterstitialListener.onInterstitialLoaded(); } else if (url.equals(MOPUB_FAIL_LOAD)) { customEventInterstitialListener.onInterstitialFailed(null); } return true; } }); dummyWebView.loadHtmlResponse(htmlData); }  static void start(Context context, String htmlData, boolean isScrollable, String redirectUrl, String clickthroughUrl, AdConfiguration adConfiguration); @Override View getAdView();  }
@Test public void preRenderHtml_shouldPreloadTheHtml() throws Exception { String htmlData = "this is nonsense"; MoPubActivity.preRenderHtml(subject, customEventInterstitialListener, htmlData); verify(htmlInterstitialWebView).enablePlugins(eq(false)); verify(htmlInterstitialWebView).addMoPubUriJavascriptInterface(any(MoPubUriJavascriptFireFinishLoadListener.class)); verify(htmlInterstitialWebView).loadHtmlResponse(htmlData); }
@Test public void preRenderHtml_shouldHaveAWebViewClientThatForwardsFinishLoad() throws Exception { MoPubActivity.preRenderHtml(subject, customEventInterstitialListener, null); ArgumentCaptor<WebViewClient> webViewClientCaptor = ArgumentCaptor.forClass(WebViewClient.class); verify(htmlInterstitialWebView).setWebViewClient(webViewClientCaptor.capture()); WebViewClient webViewClient = webViewClientCaptor.getValue(); webViewClient.shouldOverrideUrlLoading(null, "mopub: verify(customEventInterstitialListener).onInterstitialLoaded(); verify(customEventInterstitialListener, never()).onInterstitialFailed(any(MoPubErrorCode.class)); }
@Test public void preRenderHtml_shouldHaveAWebViewClientThatForwardsFailLoad() throws Exception { MoPubActivity.preRenderHtml(subject, customEventInterstitialListener, null); ArgumentCaptor<WebViewClient> webViewClientCaptor = ArgumentCaptor.forClass(WebViewClient.class); verify(htmlInterstitialWebView).setWebViewClient(webViewClientCaptor.capture()); WebViewClient webViewClient = webViewClientCaptor.getValue(); webViewClient.shouldOverrideUrlLoading(null, "mopub: verify(customEventInterstitialListener, never()).onInterstitialLoaded(); verify(customEventInterstitialListener).onInterstitialFailed(any(MoPubErrorCode.class)); }
@Test public void preRenderHtml_shouldHaveAMoPubUriInterfaceThatForwardsOnInterstitialLoaded() throws Exception { MoPubActivity.preRenderHtml(subject, customEventInterstitialListener, null); ArgumentCaptor<MoPubUriJavascriptFireFinishLoadListener> moPubUriJavascriptFireFinishLoadListenerCaptor = ArgumentCaptor.forClass(MoPubUriJavascriptFireFinishLoadListener.class); verify(htmlInterstitialWebView).addMoPubUriJavascriptInterface(moPubUriJavascriptFireFinishLoadListenerCaptor.capture()); MoPubUriJavascriptFireFinishLoadListener moPubUriJavascriptFireFinishLoadListener = moPubUriJavascriptFireFinishLoadListenerCaptor.getValue(); moPubUriJavascriptFireFinishLoadListener.onInterstitialLoaded(); verify(customEventInterstitialListener).onInterstitialLoaded(); }