From 304e47180119c08710f7d8e898dc763b09d29bab Mon Sep 17 00:00:00 2001 From: Mugurell Date: Wed, 24 Mar 2021 16:41:31 +0200 Subject: [PATCH] For #18617 - Use the new EngineView#getInputResultDetail() All functionality should remain the same. --- .../DynamicDownloadDialogBehavior.kt | 9 ++- .../DynamicDownloadDialogBehaviorTest.kt | 65 +++++++++++++++++++ buildSrc/src/main/java/AndroidComponents.kt | 2 +- 3 files changed, 72 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/downloads/DynamicDownloadDialogBehavior.kt b/app/src/main/java/org/mozilla/fenix/downloads/DynamicDownloadDialogBehavior.kt index a5d640baea..6fc09d2779 100644 --- a/app/src/main/java/org/mozilla/fenix/downloads/DynamicDownloadDialogBehavior.kt +++ b/app/src/main/java/org/mozilla/fenix/downloads/DynamicDownloadDialogBehavior.kt @@ -50,7 +50,8 @@ class DynamicDownloadDialogBehavior( /** * 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( */ @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( 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) diff --git a/app/src/test/java/org/mozilla/fenix/downloads/DynamicDownloadDialogBehaviorTest.kt b/app/src/test/java/org/mozilla/fenix/downloads/DynamicDownloadDialogBehaviorTest.kt index 6b55b53d55..5e99904c8c 100644 --- a/app/src/test/java/org/mozilla/fenix/downloads/DynamicDownloadDialogBehaviorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/downloads/DynamicDownloadDialogBehaviorTest.kt @@ -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(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(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(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) + } } diff --git a/buildSrc/src/main/java/AndroidComponents.kt b/buildSrc/src/main/java/AndroidComponents.kt index 12121dccea..80861589b3 100644 --- a/buildSrc/src/main/java/AndroidComponents.kt +++ b/buildSrc/src/main/java/AndroidComponents.kt @@ -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" }