Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Fixes #1970 - Guards the close listener
Browse files Browse the repository at this point in the history
  • Loading branch information
boek authored and pocmo committed Feb 6, 2019
1 parent 91bfcf5 commit a540d32
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ class CustomTabsToolbarFeature(
*/
fun onBackPressed(): Boolean {
val result = sessionManager.runWithSession(sessionId) {
closeListener.invoke()
remove(it)
true
}
closeListener.invoke()

return result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,27 @@ class CustomTabsToolbarFeatureTest {
`when`(sessionManager.findSessionById(anyString())).thenReturn(session)

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

val result = feature.onBackPressed()

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)
}
}
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ permalink: /changelog/
* **browser-engine-system**
* Added support for [JavaScript prompt alerts](https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt) on WebView.

* **feature-customtabs**
* Fixed an issue causing the `closeListener` to be invoked even when the current session isn't a Custom Tab.

# 0.41.0

* [Commits](https://github.com/mozilla-mobile/android-components/compare/v0.40.0...v0.41.0)
Expand Down

0 comments on commit a540d32

Please sign in to comment.