mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
For #18617 - Use the new EngineView#getInputResultDetail()
All functionality should remain the same.
This commit is contained in:
parent
e03ffff3b8
commit
304e471801
@ -50,7 +50,8 @@ class DynamicDownloadDialogBehavior<V : View>(
|
||||
/**
|
||||
* Reference to [EngineView] used to check user's [android.view.MotionEvent]s.
|
||||
*/
|
||||
private var engineView: EngineView? = null
|
||||
@VisibleForTesting
|
||||
internal var engineView: EngineView? = null
|
||||
|
||||
/**
|
||||
* Depending on how user's touch was consumed by EngineView / current website,
|
||||
@ -64,7 +65,9 @@ class DynamicDownloadDialogBehavior<V : View>(
|
||||
*/
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
internal val shouldScroll: Boolean
|
||||
get() = engineView?.getInputResult() == EngineView.InputResult.INPUT_RESULT_HANDLED
|
||||
get() = engineView?.getInputResultDetail()?.let {
|
||||
(it.canScrollToBottom() || it.canScrollToTop())
|
||||
} ?: false
|
||||
|
||||
override fun onStartNestedScroll(
|
||||
coordinatorLayout: CoordinatorLayout,
|
||||
@ -78,7 +81,7 @@ class DynamicDownloadDialogBehavior<V : View>(
|
||||
shouldSnapAfterScroll = type == ViewCompat.TYPE_TOUCH
|
||||
snapAnimator.cancel()
|
||||
true
|
||||
} else if (engineView?.getInputResult() == EngineView.InputResult.INPUT_RESULT_UNHANDLED) {
|
||||
} else if (engineView?.getInputResultDetail()?.isTouchUnhandled() == true) {
|
||||
// Force expand the notification dialog if event is unhandled, otherwise user could get stuck in a
|
||||
// state where they cannot show it
|
||||
forceExpand(child)
|
||||
|
@ -7,10 +7,14 @@ package org.mozilla.fenix.downloads
|
||||
import android.animation.ValueAnimator
|
||||
import android.view.View
|
||||
import androidx.core.view.ViewCompat
|
||||
import io.mockk.Runs
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
import io.mockk.mockk
|
||||
import io.mockk.spyk
|
||||
import io.mockk.verify
|
||||
import mozilla.components.concept.engine.EngineView
|
||||
import mozilla.components.concept.engine.InputResultDetail
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
@ -180,4 +184,65 @@ class DynamicDownloadDialogBehaviorTest {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN a null InputResultDetail from the EngineView WHEN shouldScroll is called THEN it returns false`() {
|
||||
val behavior = DynamicDownloadDialogBehavior<View>(testContext, null, 10f)
|
||||
|
||||
behavior.engineView = null
|
||||
assertFalse(behavior.shouldScroll)
|
||||
|
||||
behavior.engineView = mockk()
|
||||
every { behavior.engineView?.getInputResultDetail() } returns null
|
||||
assertFalse(behavior.shouldScroll)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN an InputResultDetail with the right values WHEN shouldScroll is called THEN it returns true`() {
|
||||
val behavior = DynamicDownloadDialogBehavior<View>(testContext, null, 10f)
|
||||
val engineView: EngineView = mockk()
|
||||
behavior.engineView = engineView
|
||||
val validInputResultDetail: InputResultDetail = mockk()
|
||||
every { engineView.getInputResultDetail() } returns validInputResultDetail
|
||||
|
||||
every { validInputResultDetail.canScrollToBottom() } returns true
|
||||
every { validInputResultDetail.canScrollToTop() } returns false
|
||||
assertTrue(behavior.shouldScroll)
|
||||
|
||||
every { validInputResultDetail.canScrollToBottom() } returns false
|
||||
every { validInputResultDetail.canScrollToTop() } returns true
|
||||
assertTrue(behavior.shouldScroll)
|
||||
|
||||
every { validInputResultDetail.canScrollToBottom() } returns true
|
||||
every { validInputResultDetail.canScrollToTop() } returns true
|
||||
assertTrue(behavior.shouldScroll)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN a gesture that doesn't scroll the toolbar WHEN startNestedScroll THEN toolbar is expanded and nested scroll not accepted`() {
|
||||
val behavior = spyk(DynamicDownloadDialogBehavior<View>(testContext, null, 10f))
|
||||
val engineView: EngineView = mockk()
|
||||
behavior.engineView = engineView
|
||||
val inputResultDetail: InputResultDetail = mockk()
|
||||
val animator: ValueAnimator = mockk(relaxed = true)
|
||||
behavior.snapAnimator = animator
|
||||
every { behavior.shouldScroll } returns false
|
||||
every { behavior.forceExpand(any()) } just Runs
|
||||
every { engineView.getInputResultDetail() } returns inputResultDetail
|
||||
every { inputResultDetail.isTouchUnhandled() } returns true
|
||||
|
||||
val childView: View = mockk()
|
||||
val acceptsNestedScroll = behavior.onStartNestedScroll(
|
||||
coordinatorLayout = mockk(),
|
||||
child = childView,
|
||||
directTargetChild = mockk(),
|
||||
target = mockk(),
|
||||
axes = ViewCompat.SCROLL_AXIS_VERTICAL,
|
||||
type = ViewCompat.TYPE_TOUCH
|
||||
)
|
||||
|
||||
verify { behavior.forceExpand(childView) }
|
||||
verify { animator.cancel() }
|
||||
assertFalse(acceptsNestedScroll)
|
||||
}
|
||||
}
|
||||
|
@ -3,5 +3,5 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
object AndroidComponents {
|
||||
const val VERSION = "75.0.20210329143119"
|
||||
const val VERSION = "75.0.20210330143044"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user