@Test public void onPageStarted_whenLoadedUrlStartsWithRedirectAndHasClickthrough_withUserClick_whenMoPubBrowserCannotHandleIntent_shouldFailSilently() throws Exception { Context mockContext = mock(Context.class); stub(htmlWebView.wasClicked()).toReturn(true); stub(htmlWebView.getContext()).toReturn(mockContext); String url = "redirectUrlToLoad"; doThrow(new ActivityNotFoundException()) .doNothing() .when(mockContext).startActivity(any(Intent.class)); subject = new HtmlWebViewClient(htmlWebViewListener, htmlWebView, CLICKTHROUGH_URL, "redirect"); subject.onPageStarted(htmlWebView, url, null); ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mockContext).startActivity(intentArgumentCaptor.capture()); Intent intent = intentArgumentCaptor.getValue(); assertThat(intent.getData()).isNull(); verify(htmlWebViewListener, never()).onClicked(); verify(htmlWebView, never()).onResetUserClick(); }
@Override public void onPageStarted(WebView view, String url, Bitmap favicon) { if (mRedirectUrl != null && url.startsWith(mRedirectUrl)) { view.stopLoading(); if (mHtmlWebView.wasClicked()) { try { Intents.showMoPubBrowserForUrl(mContext, Uri.parse(url)); } catch (IntentNotResolvableException e) { MoPubLog.d(e.getMessage()); } } else { MoPubLog.d("Attempted to redirect without user interaction"); } } }
HtmlWebViewClient extends WebViewClient { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { if (mRedirectUrl != null && url.startsWith(mRedirectUrl)) { view.stopLoading(); if (mHtmlWebView.wasClicked()) { try { Intents.showMoPubBrowserForUrl(mContext, Uri.parse(url)); } catch (IntentNotResolvableException e) { MoPubLog.d(e.getMessage()); } } else { MoPubLog.d("Attempted to redirect without user interaction"); } } } }
HtmlWebViewClient extends WebViewClient { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { if (mRedirectUrl != null && url.startsWith(mRedirectUrl)) { view.stopLoading(); if (mHtmlWebView.wasClicked()) { try { Intents.showMoPubBrowserForUrl(mContext, Uri.parse(url)); } catch (IntentNotResolvableException e) { MoPubLog.d(e.getMessage()); } } else { MoPubLog.d("Attempted to redirect without user interaction"); } } } HtmlWebViewClient(HtmlWebViewListener htmlWebViewListener, BaseHtmlWebView htmlWebView, String clickthrough, String redirect); }
HtmlWebViewClient extends WebViewClient { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { if (mRedirectUrl != null && url.startsWith(mRedirectUrl)) { view.stopLoading(); if (mHtmlWebView.wasClicked()) { try { Intents.showMoPubBrowserForUrl(mContext, Uri.parse(url)); } catch (IntentNotResolvableException e) { MoPubLog.d(e.getMessage()); } } else { MoPubLog.d("Attempted to redirect without user interaction"); } } } HtmlWebViewClient(HtmlWebViewListener htmlWebViewListener, BaseHtmlWebView htmlWebView, String clickthrough, String redirect); @Override boolean shouldOverrideUrlLoading(final WebView view, final String url); @Override void onPageStarted(WebView view, String url, Bitmap favicon); }
HtmlWebViewClient extends WebViewClient { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { if (mRedirectUrl != null && url.startsWith(mRedirectUrl)) { view.stopLoading(); if (mHtmlWebView.wasClicked()) { try { Intents.showMoPubBrowserForUrl(mContext, Uri.parse(url)); } catch (IntentNotResolvableException e) { MoPubLog.d(e.getMessage()); } } else { MoPubLog.d("Attempted to redirect without user interaction"); } } } HtmlWebViewClient(HtmlWebViewListener htmlWebViewListener, BaseHtmlWebView htmlWebView, String clickthrough, String redirect); @Override boolean shouldOverrideUrlLoading(final WebView view, final String url); @Override void onPageStarted(WebView view, String url, Bitmap favicon);  }