ClickDestinationResolutionListener implements UrlResolutionTask.UrlResolutionListener { @Override public void onSuccess(@NonNull final String resolvedUrl) { new UrlHandler.Builder() .withSupportedUrlActions( UrlAction.IGNORE_ABOUT_SCHEME, UrlAction.OPEN_NATIVE_BROWSER, UrlAction.OPEN_APP_MARKET, UrlAction.OPEN_IN_APP_BROWSER, UrlAction.HANDLE_SHARE_TWEET, UrlAction.FOLLOW_DEEP_LINK) .withResultActions(new UrlHandler.ResultActions() { @Override public void urlHandlingSucceeded(@NonNull String url, @NonNull UrlAction urlAction) { } @Override public void urlHandlingFailed(@NonNull String url, @NonNull UrlAction lastFailedUrlAction) { if (mUrlIterator.hasNext()) { UrlResolutionTask.getResolvedUrl(mUrlIterator.next(), ClickDestinationResolutionListener.this); } } }) .build().handleUrl(mContext, resolvedUrl); removeSpinningProgressView(); } ClickDestinationResolutionListener(@NonNull final Context context,
            @NonNull final Iterator<String> urlIterator,
            @NonNull final SpinningProgressView spinningProgressView); @Override void onSuccess(@NonNull final String resolvedUrl); @Override void onFailure();  }
@Test public void onSuccess_withMoPubNativeBrowserUrl_shouldOpenExternalBrowserAndHideProgressView() { subject.onSuccess("mopubnativebrowser: Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getDataString()).isEqualTo("https: assertThat(intent.getAction()).isEqualTo(Intent.ACTION_VIEW); verify(mockSpinningProgressView).removeFromRoot(); }
@Test public void onSuccess_withMalformedMoPubNativeBrowserUrl_shouldHideProgressViewButNotOpenExternalBrowser() { subject.onSuccess("mopubnativebrowser: assertThat(Robolectric.getShadowApplication().getNextStartedActivity()).isNull(); verify(mockSpinningProgressView).removeFromRoot(); }
@Test public void onSuccess_withDeepLinkThatIsResolvable_shouldStartActionViewIntent_shouldRemoveSpinningProgressView() { String deepLinkUrl = "appscheme: Robolectric.packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(deepLinkUrl)), new ResolveInfo()); subject.onSuccess(deepLinkUrl); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getAction()).isEqualTo(Intent.ACTION_VIEW); assertThat(intent.getDataString()).isEqualTo("appscheme: verify(mockSpinningProgressView).removeFromRoot(); }
@Test public void onSuccess_withDeepLinkThatIsUnresolvable_shouldNotStartNewIntent_shouldRemoveSpinningProgressView() { String deepLinkUrl = "appscheme: subject.onSuccess(deepLinkUrl); assertThat(Robolectric.getShadowApplication().getNextStartedActivity()).isNull(); verify(mockSpinningProgressView).removeFromRoot(); }
@Test public void onSuccess_withAppStoreUrl_shouldStartAppStoreIntent_shouldRemoveSpinningProgressView() { final String appStoreUrl = "play.google.com/"; Robolectric.packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(appStoreUrl)), new ResolveInfo()); subject.onSuccess(appStoreUrl); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getAction()).isEqualTo(Intent.ACTION_VIEW); assertThat(intent.getDataString()).isEqualTo(appStoreUrl); verify(mockSpinningProgressView).removeFromRoot(); }
@Test public void onSuccess_withHttpUrl_showOpenInMoPubBrowser_shouldRemoveSpinningProgressViewFromRoot() { String httpUrl = "http: subject.onSuccess(httpUrl); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(context).startActivity(intentCaptor.capture()); Intent intent = intentCaptor.getValue(); assertThat(intent.getComponent().getPackageName()).isEqualTo("testPackageName"); assertThat(intent.getComponent().getClassName()).isEqualTo("com.mopub.common.MoPubBrowser"); assertThat(intent.getStringExtra(MoPubBrowser.DESTINATION_URL_KEY)).isEqualTo(httpUrl); verify(mockSpinningProgressView).removeFromRoot(); }
@Test public void onSuccess_withHttpsUrl_showOpenInMoPubBrowser_shouldRemoveSpinningProgressViewFromRoot() { String httpsUrl = "https: subject.onSuccess(httpsUrl); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(context).startActivity(intentCaptor.capture()); Intent intent = intentCaptor.getValue(); assertThat(intent.getComponent().getPackageName()).isEqualTo("testPackageName"); assertThat(intent.getComponent().getClassName()).isEqualTo("com.mopub.common.MoPubBrowser"); assertThat(intent.getStringExtra(MoPubBrowser.DESTINATION_URL_KEY)).isEqualTo(httpsUrl); verify(mockSpinningProgressView).removeFromRoot(); }
@Test public void onSuccess_withAboutBlankUrl_shouldFailSilently_shouldRemoveSpinningProgressView() { String url = "about:blank"; subject.onSuccess(url); assertThat(Robolectric.getShadowApplication().getNextStartedActivity()).isNull(); verify(mockSpinningProgressView).removeFromRoot(); }