For #18617 - Use the new EngineView#getInputResultDetail()

All functionality should remain the same.
upstream-sync
Mugurell 3 years ago
parent e03ffff3b8
commit 304e471801

@ -50,7 +50,8 @@ class DynamicDownloadDialogBehavior<V : View>(
/** /**
* Reference to [EngineView] used to check user's [android.view.MotionEvent]s. * 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, * Depending on how user's touch was consumed by EngineView / current website,
@ -64,7 +65,9 @@ class DynamicDownloadDialogBehavior<V : View>(
*/ */
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal val shouldScroll: Boolean internal val shouldScroll: Boolean
get() = engineView?.getInputResult() == EngineView.InputResult.INPUT_RESULT_HANDLED get() = engineView?.getInputResultDetail()?.let {
(it.canScrollToBottom() || it.canScrollToTop())
} ?: false
override fun onStartNestedScroll( override fun onStartNestedScroll(
coordinatorLayout: CoordinatorLayout, coordinatorLayout: CoordinatorLayout,
@ -78,7 +81,7 @@ class DynamicDownloadDialogBehavior<V : View>(
shouldSnapAfterScroll = type == ViewCompat.TYPE_TOUCH shouldSnapAfterScroll = type == ViewCompat.TYPE_TOUCH
snapAnimator.cancel() snapAnimator.cancel()
true 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 // Force expand the notification dialog if event is unhandled, otherwise user could get stuck in a
// state where they cannot show it // state where they cannot show it
forceExpand(child) forceExpand(child)

@ -7,10 +7,14 @@ package org.mozilla.fenix.downloads
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.view.View import android.view.View
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import io.mockk.Runs
import io.mockk.every import io.mockk.every
import io.mockk.just
import io.mockk.mockk import io.mockk.mockk
import io.mockk.spyk import io.mockk.spyk
import io.mockk.verify import io.mockk.verify
import mozilla.components.concept.engine.EngineView
import mozilla.components.concept.engine.InputResultDetail
import mozilla.components.support.test.robolectric.testContext import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertFalse import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
object AndroidComponents { object AndroidComponents {
const val VERSION = "75.0.20210329143119" const val VERSION = "75.0.20210330143044"
} }

Loading…
Cancel
Save