Skip to content

Commit

Permalink
Closes mozilla-mobile#8169: Immediately show redirect dialog fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketsroger committed Aug 20, 2020
1 parent 296a015 commit 8b60233
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class AppLinksFeature(
dialog.onCancelRedirect = doNotOpenApp

if (!isAlreadyADialogCreated()) {
dialog.show(fragmentManager, FRAGMENT_TAG)
dialog.showNow(fragmentManager, FRAGMENT_TAG)
}

return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
}

Expand All @@ -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)
}
}

0 comments on commit 8b60233

Please sign in to comment.