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

Fixes #1970 - Guards the close listener #1972

Merged
merged 1 commit into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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