For #6857 - Replace BackHandler with UserInteractionHandler in InflationAwareFeature and InflationAwareFeatureTest
parent
1b1f9348dc
commit
85111f538a
|
@ -59,7 +59,8 @@ abstract class InflationAwareFeature(
|
||||||
/**
|
/**
|
||||||
* Called when the feature gets the option to handle the user pressing the back key.
|
* Called when the feature gets the option to handle the user pressing the back key.
|
||||||
*
|
*
|
||||||
* @return true if the feature also implements [BackHandler] and the feature has been initiated.
|
* @return true if the feature also implements [UserInteractionHandler] and the feature has
|
||||||
|
* been initiated.
|
||||||
*/
|
*/
|
||||||
override fun onBackPressed(): Boolean {
|
override fun onBackPressed(): Boolean {
|
||||||
return (feature as? UserInteractionHandler)?.onBackPressed() ?: false
|
return (feature as? UserInteractionHandler)?.onBackPressed() ?: false
|
||||||
|
|
|
@ -2,7 +2,7 @@ package org.mozilla.fenix.components
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewStub
|
import android.view.ViewStub
|
||||||
import mozilla.components.support.base.feature.BackHandler
|
import mozilla.components.support.base.feature.UserInteractionHandler
|
||||||
import mozilla.components.support.base.feature.LifecycleAwareFeature
|
import mozilla.components.support.base.feature.LifecycleAwareFeature
|
||||||
import mozilla.components.support.test.any
|
import mozilla.components.support.test.any
|
||||||
import mozilla.components.support.test.mock
|
import mozilla.components.support.test.mock
|
||||||
|
@ -68,11 +68,11 @@ class InflationAwareFeatureTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `if feature has implemented BackHandler invoke it`() {
|
fun `if feature has implemented UserInteractionHandler invoke it`() {
|
||||||
val stub: ViewStub = mock()
|
val stub: ViewStub = mock()
|
||||||
val inflationFeature: InflationAwareFeature = spy(TestableInflationAwareFeature(stub))
|
val inflationFeature: InflationAwareFeature = spy(TestableInflationAwareFeature(stub))
|
||||||
val innerFeature: LifecycleAwareFeature = mock()
|
val innerFeature: LifecycleAwareFeature = mock()
|
||||||
val backHandlerFeature = object : LifecycleAwareFeature, BackHandler {
|
val userInteractionHandlerFeature = object : LifecycleAwareFeature, UserInteractionHandler {
|
||||||
override fun onBackPressed() = true
|
override fun onBackPressed() = true
|
||||||
|
|
||||||
override fun start() {}
|
override fun start() {}
|
||||||
|
@ -86,7 +86,7 @@ class InflationAwareFeatureTest {
|
||||||
|
|
||||||
assert(!inflationFeature.onBackPressed())
|
assert(!inflationFeature.onBackPressed())
|
||||||
|
|
||||||
inflationFeature.feature = backHandlerFeature
|
inflationFeature.feature = userInteractionHandlerFeature
|
||||||
|
|
||||||
assert(inflationFeature.onBackPressed())
|
assert(inflationFeature.onBackPressed())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue