From 8b6023315eb62e28d3fb5861e3c5531ba1ed806b Mon Sep 17 00:00:00 2001 From: Roger Yang Date: Thu, 20 Aug 2020 14:52:50 -0400 Subject: [PATCH] Closes #8169: Immediately show redirect dialog fragment --- .../feature/app/links/AppLinksFeature.kt | 2 +- .../feature/app/links/AppLinksFeatureTest.kt | 21 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksFeature.kt b/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksFeature.kt index 18f63a200f3..1292220e796 100644 --- a/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksFeature.kt +++ b/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksFeature.kt @@ -78,7 +78,7 @@ class AppLinksFeature( dialog.onCancelRedirect = doNotOpenApp if (!isAlreadyADialogCreated()) { - dialog.show(fragmentManager, FRAGMENT_TAG) + dialog.showNow(fragmentManager, FRAGMENT_TAG) } return diff --git a/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksFeatureTest.kt b/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksFeatureTest.kt index 35bdfb7139e..d7066e58a0b 100644 --- a/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksFeatureTest.kt +++ b/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksFeatureTest.kt @@ -23,8 +23,10 @@ import org.mockito.ArgumentMatchers.anyBoolean import org.mockito.ArgumentMatchers.anyString import org.mockito.ArgumentMatchers.eq import org.mockito.Mockito.`when` +import org.mockito.Mockito.doReturn import org.mockito.Mockito.never import org.mockito.Mockito.spy +import org.mockito.Mockito.times import org.mockito.Mockito.verify import org.mockito.Mockito.verifyNoMoreInteractions @@ -73,13 +75,13 @@ class AppLinksFeatureTest { `when`(mockGetRedirect.invoke(intentUrl)).thenReturn(appRedirect) `when`(mockGetRedirect.invoke(webUrlWithAppLink)).thenReturn(appRedirectFromWebUrl) - feature = AppLinksFeature( + feature = spy(AppLinksFeature( context = mockContext, sessionManager = mockSessionManager, fragmentManager = mockFragmentManager, useCases = mockUseCases, dialog = mockDialog - ) + )) } private fun createSession(isPrivate: Boolean, url: String = "https://mozilla.com"): Session { @@ -152,7 +154,7 @@ class AppLinksFeatureTest { feature.start() userTapsOnSession(intentUrl, true) - verify(mockDialog).show(eq(mockFragmentManager), anyString()) + verify(mockDialog).showNow(eq(mockFragmentManager), anyString()) verify(mockOpenRedirect, never()).invoke(any(), anyBoolean(), any()) } @@ -164,4 +166,17 @@ class AppLinksFeatureTest { val dialog = feature.getOrCreateDialog() assertEquals(dialog, feature.getOrCreateDialog()) } + + @Test + fun `redirect dialog is only added once`() { + feature.start() + userTapsOnSession(intentUrl, true) + + verify(mockDialog).showNow(eq(mockFragmentManager), anyString()) + + doReturn(mockDialog).`when`(feature).getOrCreateDialog() + doReturn(mockDialog).`when`(mockFragmentManager).findFragmentByTag(RedirectDialogFragment.FRAGMENT_TAG) + userTapsOnSession(intentUrl, true) + verify(mockDialog, times(1)).showNow(mockFragmentManager, RedirectDialogFragment.FRAGMENT_TAG) + } }