Skip to content

Commit

Permalink
Fixes mozilla-mobile#1970 - Guards the close listener
Browse files Browse the repository at this point in the history
  • Loading branch information
boek committed Feb 6, 2019
1 parent 44d0ab1 commit 069b5be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class CustomTabsToolbarFeature(
* Should be called when the back button is pressed.
*/
fun onBackPressed(): Boolean {
if (!initialized) {
return false
}

val result = sessionManager.runWithSession(sessionId) {
remove(it)
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,22 @@ class CustomTabsToolbarFeatureTest {
assertTrue(result)
assertTrue(closeExecuted)
}

@Test
fun `onBackPressed without a session does nothing`() {
val sessionId = null
val session: Session = mock()
val toolbar = BrowserToolbar(RuntimeEnvironment.application)
val sessionManager: SessionManager = mock()
var closeExecuted = false
`when`(session.customTabConfig).thenReturn(mock())
`when`(sessionManager.findSessionById(anyString())).thenReturn(session)

val feature = spy(CustomTabsToolbarFeature(sessionManager, toolbar, sessionId) { closeExecuted = true })

val result = feature.onBackPressed()

assertFalse(result)
assertFalse(closeExecuted)
}
}

0 comments on commit 069b5be

Please sign in to comment.