Skip to content

Commit

Permalink
Closes mozilla-mobile#11488: Add a long press listener to nav bar
Browse files Browse the repository at this point in the history
  • Loading branch information
mike a committed Jan 6, 2022
1 parent da14d39 commit 4b6b1d4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,30 @@ class DisplayToolbar internal constructor(
}
}

/**
* Sets a listener to be invoked when the site security indicator icon is clicked and held.
*/
fun setOnSiteSecurityLongClickListener(listener: (() -> Unit)?) {
if (listener == null) {
views.securityIndicator.setOnLongClickListener(null)
views.securityIndicator.background = null
} else {
views.securityIndicator.setOnLongClickListener {
listener.invoke()
true
}

val outValue = TypedValue()
context.theme.resolveAttribute(
android.R.attr.selectableItemBackgroundBorderless,
outValue,
true
)

views.securityIndicator.setBackgroundResource(outValue.resourceId)
}
}

/**
* Sets a listener to be invoked when the site tracking protection indicator icon is clicked.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,39 @@ class DisplayToolbarTest {
assertNull(displayToolbar.views.securityIndicator.background)
}

@Test
fun `clicking and holding the site security indicator invokes listener`() {
var listenerInvoked = false

val (_, displayToolbar) = createDisplayToolbar()

assertNull(displayToolbar.views.securityIndicator.background)

displayToolbar.setOnSiteSecurityLongClickListener {
listenerInvoked = true
}

assertNotNull(displayToolbar.views.securityIndicator.background)

displayToolbar.views.securityIndicator.performLongClick()

assertTrue(listenerInvoked)

listenerInvoked = false

displayToolbar.setOnSiteSecurityLongClickListener { }

assertNotNull(displayToolbar.views.securityIndicator.background)

displayToolbar.views.securityIndicator.performLongClick()

assertFalse(listenerInvoked)

displayToolbar.setOnSiteSecurityLongClickListener(null)

assertNull(displayToolbar.views.securityIndicator.background)
}

@Test
fun `Security icon has proper content description`() {
val (_, displayToolbar) = createDisplayToolbar()
Expand Down

0 comments on commit 4b6b1d4

Please sign in to comment.