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 f7cd3c0
Show file tree
Hide file tree
Showing 3 changed files with 25 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)
}
}
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ permalink: /changelog/
* **feature-session**
* Fixed an issue causing `EngineViewPresenter` to render a selected `Session` even though it was configured to show a fixed `Session`. This issue caused a crash (`IllegalStateException: Display already acquired`) in the [Reference Browser](https://github.com/mozilla-mobile/reference-browser) when a "Custom Tab" and the "Browser" tried to render the same `Session`.

* **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 f7cd3c0

Please sign in to comment.