shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package androidx.ui.core.gesture |
| 18 | |
| 19 | import androidx.ui.core.Direction |
| 20 | import androidx.ui.core.Duration |
| 21 | import androidx.ui.core.PointerEventPass |
| 22 | import androidx.ui.core.consumeDownChange |
| 23 | import androidx.ui.core.ipx |
| 24 | import androidx.ui.core.milliseconds |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 25 | import androidx.ui.core.px |
| 26 | import androidx.ui.testutils.consume |
| 27 | import androidx.ui.testutils.down |
| 28 | import androidx.ui.testutils.invokeOverAllPasses |
| 29 | import androidx.ui.testutils.invokeOverPasses |
| 30 | import androidx.ui.testutils.moveBy |
| 31 | import androidx.ui.testutils.moveTo |
| 32 | import androidx.ui.testutils.up |
| 33 | import com.google.common.truth.Truth.assertThat |
| 34 | import org.junit.Before |
| 35 | import org.junit.Test |
| 36 | import org.junit.runner.RunWith |
| 37 | import org.junit.runners.JUnit4 |
| 38 | |
| 39 | // TODO(shepshapard): Write the following tests. |
| 40 | // Verify correct shape of slop area (should it be a square or circle)? |
| 41 | // Test for cases with more than one pointer |
| 42 | // Test for cases where things are reset when last pointer goes up |
| 43 | // Verify all methods called during onPostUp |
| 44 | // Verify default behavior when no callback provided for recognizer or canDrag |
| 45 | |
| 46 | // Changing this value will break tests that expect the value to be 10. |
| 47 | private const val TestTouchSlop = 10 |
| 48 | |
| 49 | @RunWith(JUnit4::class) |
| 50 | class TouchSlopExceededGestureDetectorTest { |
| 51 | |
| 52 | private val onTouchSlopExceeded: () -> Unit = { onTouchSlopExceededCallCount++ } |
| 53 | private val canDrag: (Direction) -> Boolean = { direction -> |
| 54 | canDragDirections.add(direction) |
| 55 | canDragReturn |
| 56 | } |
| 57 | private var onTouchSlopExceededCallCount: Int = 0 |
| 58 | private var canDragReturn = false |
| 59 | private var canDragDirections: MutableList<Direction> = mutableListOf() |
| 60 | private lateinit var mRecognizer: TouchSlopExceededGestureRecognizer |
| 61 | |
| 62 | @Before |
| 63 | fun setup() { |
| 64 | onTouchSlopExceededCallCount = 0 |
| 65 | canDragReturn = true |
| 66 | canDragDirections.clear() |
| 67 | mRecognizer = |
| 68 | TouchSlopExceededGestureRecognizer(TestTouchSlop.ipx) |
| 69 | mRecognizer.canDrag = canDrag |
| 70 | mRecognizer.onTouchSlopExceeded = onTouchSlopExceeded |
| 71 | } |
| 72 | |
| 73 | // Verify the circumstances under which canDrag should not be called. |
| 74 | |
| 75 | @Test |
| 76 | fun onPointerInputChanges_down_canDragNotCalled() { |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 77 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down()) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 78 | assertThat(canDragDirections).isEmpty() |
| 79 | } |
| 80 | |
| 81 | @Test |
| 82 | fun onPointerInputChanges_downUp_canDragNotCalled() { |
Shep Shapard | e261df9 | 2019-11-15 11:24:31 -0800 | [diff] [blame^] | 83 | val down = down(duration = 0.milliseconds) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 84 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down()) |
Shep Shapard | e261df9 | 2019-11-15 11:24:31 -0800 | [diff] [blame^] | 85 | val up = down.up(10.milliseconds) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 86 | mRecognizer.pointerInputHandler.invokeOverAllPasses(up) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 87 | |
| 88 | assertThat(canDragDirections).isEmpty() |
| 89 | } |
| 90 | |
| 91 | @Test |
| 92 | fun onPointerInputChanges_downMoveFullyConsumed_canDragNotCalled() { |
| 93 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 94 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 95 | val move = down.moveBy(Duration(milliseconds = 10), 3f, 5f).consume(3f, 5f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 96 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 97 | |
| 98 | assertThat(canDragDirections).isEmpty() |
| 99 | } |
| 100 | |
| 101 | // Verify the circumstances under which canDrag should be called. |
| 102 | |
| 103 | @Test |
| 104 | fun onPointerInputChanges_downMove1Dimension_canDragCalledOnce() { |
| 105 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 106 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 107 | val move = down.moveBy(Duration(milliseconds = 10), 3f, 0f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 108 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 109 | |
| 110 | // Twice because while under touch slop, TouchSlopExceededGestureDetector checks during PostUp and PostDown |
| 111 | assertThat(canDragDirections).hasSize(2) |
| 112 | } |
| 113 | |
| 114 | @Test |
| 115 | fun onPointerInputChanges_downMove2Dimensions_canDragCalledTwice() { |
| 116 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 117 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 118 | val move = down.moveBy(Duration(milliseconds = 10), 3f, 5f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 119 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 120 | |
| 121 | // 4 times because while under touch slop, TouchSlopExceededGestureDetector checks during PostUp and |
| 122 | // PostDown |
| 123 | assertThat(canDragDirections).hasSize(4) |
| 124 | } |
| 125 | |
| 126 | @Test |
| 127 | fun onPointerInputChanges_downMoveOneDimensionPartiallyConsumed_canDragCalledOnce() { |
| 128 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 129 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 130 | val move = down.moveBy(Duration(milliseconds = 10), 0f, 5f).consume(0f, 4f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 131 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 132 | |
| 133 | // Twice because while under touch slop, DragGestureDetector checks during PostUp and |
| 134 | // PostDown |
| 135 | assertThat(canDragDirections).hasSize(2) |
| 136 | } |
| 137 | |
| 138 | @Test |
| 139 | fun onPointerInputChanges_downMoveTwoDimensionPartiallyConsumed_canDragCalledTwice() { |
| 140 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 141 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 142 | val move = down.moveBy(Duration(milliseconds = 10), 3f, 5f).consume(2f, 4f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 143 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 144 | |
| 145 | // 4 times because while under touch slop, DragGestureDetector checks during PostUp and |
| 146 | // PostDown |
| 147 | assertThat(canDragDirections).hasSize(4) |
| 148 | } |
| 149 | |
| 150 | @Test |
| 151 | fun onPointerInputChanges_dragPastTouchSlopOneDimensionAndDrag3MoreTimes_canDragCalledOnce() { |
| 152 | val justBeyondSlop = (TestTouchSlop + 1).toFloat() |
| 153 | |
| 154 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 155 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
Shep Shapard | e261df9 | 2019-11-15 11:24:31 -0800 | [diff] [blame^] | 156 | var move = down.moveTo(10.milliseconds, 0f, justBeyondSlop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 157 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 158 | repeat(3) { |
| 159 | move = move.moveBy(Duration(milliseconds = 10), 0f, 1f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 160 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | // Once because although DragGestureDetector checks during PostUp and PostDown, slop is |
| 164 | // surpassed during PostUp, and thus isn't checked again. |
| 165 | assertThat(canDragDirections).hasSize(1) |
| 166 | } |
| 167 | |
| 168 | @Test |
| 169 | fun onPointerInputChanges_downMoveUnderSlop3Times_canDragCalled3Times() { |
| 170 | val thirdSlop = TestTouchSlop.toFloat() / 3 |
| 171 | |
| 172 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 173 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 174 | var move = down |
| 175 | repeat(3) { |
| 176 | move = move.moveBy(Duration(milliseconds = 10), 0f, thirdSlop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 177 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | // 6 times because while under touch slop, DragGestureDetector checks during PostUp and |
| 181 | // PostDown |
| 182 | assertThat(canDragDirections).hasSize(6) |
| 183 | } |
| 184 | |
| 185 | @Test |
| 186 | fun onPointerInputChanges_moveBeyondSlopThenIntoTouchSlopAreaAndOutAgain_canDragCalledOnce() { |
| 187 | val beyondTouchSlop = (TestTouchSlop + 1).toFloat() |
| 188 | |
| 189 | var event = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 190 | mRecognizer.pointerInputHandler.invokeOverAllPasses(event) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 191 | // Out of touch slop region |
| 192 | event = event.moveBy(Duration(milliseconds = 10), 0f, beyondTouchSlop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 193 | mRecognizer.pointerInputHandler.invokeOverAllPasses(event) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 194 | // Back into touch slop region |
| 195 | event = event.moveBy(Duration(milliseconds = 10), 0f, -beyondTouchSlop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 196 | mRecognizer.pointerInputHandler.invokeOverAllPasses(event) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 197 | // Out of touch slop region again |
| 198 | event = event.moveBy(Duration(milliseconds = 10), 0f, beyondTouchSlop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 199 | mRecognizer.pointerInputHandler.invokeOverAllPasses(event) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 200 | |
| 201 | // Once because although DragGestureDetector checks during PostUp and PostDown, slop is |
| 202 | // surpassed during PostUp, and thus isn't checked again. |
| 203 | assertThat(canDragDirections).hasSize(1) |
| 204 | } |
| 205 | |
| 206 | // Verification of correctness of values passed to canDrag. |
| 207 | |
| 208 | @Test |
| 209 | fun onPointerInputChanges_canDragCalledWithCorrectDirection() { |
| 210 | onPointerInputChanges_canDragCalledWithCorrectDirection( |
| 211 | -1f, 0f, arrayOf(Direction.LEFT) |
| 212 | ) |
| 213 | onPointerInputChanges_canDragCalledWithCorrectDirection( |
| 214 | 0f, -1f, arrayOf(Direction.UP) |
| 215 | ) |
| 216 | onPointerInputChanges_canDragCalledWithCorrectDirection( |
| 217 | 1f, 0f, arrayOf(Direction.RIGHT) |
| 218 | ) |
| 219 | onPointerInputChanges_canDragCalledWithCorrectDirection( |
| 220 | 0f, 1f, arrayOf(Direction.DOWN) |
| 221 | ) |
| 222 | onPointerInputChanges_canDragCalledWithCorrectDirection( |
| 223 | -1f, -1f, arrayOf(Direction.LEFT, Direction.UP) |
| 224 | ) |
| 225 | onPointerInputChanges_canDragCalledWithCorrectDirection( |
| 226 | -1f, 1f, arrayOf(Direction.LEFT, Direction.DOWN) |
| 227 | ) |
| 228 | onPointerInputChanges_canDragCalledWithCorrectDirection( |
| 229 | 1f, -1f, arrayOf(Direction.RIGHT, Direction.UP) |
| 230 | ) |
| 231 | onPointerInputChanges_canDragCalledWithCorrectDirection( |
| 232 | 1f, 1f, arrayOf(Direction.RIGHT, Direction.DOWN) |
| 233 | ) |
| 234 | } |
| 235 | |
| 236 | private fun onPointerInputChanges_canDragCalledWithCorrectDirection( |
| 237 | dx: Float, |
| 238 | dy: Float, |
| 239 | expectedDirections: Array<Direction> |
| 240 | ) { |
| 241 | canDragDirections.clear() |
| 242 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 243 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 244 | val move = down.moveBy(Duration(milliseconds = 10), dx, dy) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 245 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 246 | |
| 247 | // Everything here is twice because DragGestureDetector checks during PostUp and PostDown. |
| 248 | assertThat(canDragDirections).hasSize(expectedDirections.size * 2) |
| 249 | expectedDirections.forEach { direction -> |
| 250 | assertThat(canDragDirections.count { it == direction }) |
| 251 | .isEqualTo(2) |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | // Verify the circumstances under which onTouchSlopExceeded should not be called. |
| 256 | |
| 257 | // TODO(b/129701831): This test assumes that if a pointer moves by slop in both x and y, we are |
| 258 | // still under slop even though sqrt(slop^2 + slop^2) > slop. This may be inaccurate and this |
| 259 | // test may therefore need to be updated. |
| 260 | @Test |
| 261 | fun onPointerInputChanges_downMoveWithinSlop_onTouchSlopExceededNotCalled() { |
| 262 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 263 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 264 | val move = down.moveBy( |
| 265 | Duration(milliseconds = 10), |
| 266 | TestTouchSlop.toFloat(), |
| 267 | TestTouchSlop.toFloat() |
| 268 | ) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 269 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 270 | |
| 271 | assertThat(onTouchSlopExceededCallCount).isEqualTo(0) |
| 272 | } |
| 273 | |
| 274 | @Test |
| 275 | fun onPointerInputChanges_moveBeyondSlopInUnsupportedDirection_onTouchSlopExceededNotCalled() { |
| 276 | val beyondSlop = (TestTouchSlop + 1).toFloat() |
| 277 | canDragReturn = false |
| 278 | |
| 279 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 280 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 281 | val move = down.moveBy( |
| 282 | Duration(milliseconds = 10), |
| 283 | beyondSlop, |
| 284 | beyondSlop |
| 285 | ) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 286 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 287 | |
| 288 | assertThat(onTouchSlopExceededCallCount).isEqualTo(0) |
| 289 | } |
| 290 | |
| 291 | @Test |
| 292 | fun onPointerInputChanges_moveBeyondSlopButConsumeUnder_onTouchSlopExceededNotCalled() { |
| 293 | |
| 294 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 295 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 296 | |
| 297 | val move = down().moveBy(10.milliseconds, TestTouchSlop + 1f, 0f).consume(dx = 1f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 298 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 299 | |
| 300 | // Assert |
| 301 | |
| 302 | assertThat(onTouchSlopExceededCallCount).isEqualTo(0) |
| 303 | } |
| 304 | |
| 305 | @Test |
| 306 | fun onPointerInputChanges_moveUnderToPostUpThenModOverInOppDir_onTouchSlopExceededNotCalled() { |
| 307 | |
| 308 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 309 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 310 | |
| 311 | val move = down().moveBy(10.milliseconds, TestTouchSlop.toFloat(), 0f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 312 | mRecognizer.pointerInputHandler.invokeOverPasses( |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 313 | listOf(move), |
| 314 | PointerEventPass.InitialDown, |
| 315 | PointerEventPass.PreUp, |
| 316 | PointerEventPass.PreDown, |
| 317 | PointerEventPass.PostUp |
| 318 | ) |
| 319 | val move2 = move.consume(dx = (TestTouchSlop * 2f + 1)) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 320 | mRecognizer.pointerInputHandler.invokeOverPasses( |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 321 | listOf(move2), |
| 322 | PointerEventPass.PostDown |
| 323 | ) |
| 324 | |
| 325 | // Assert |
| 326 | |
| 327 | assertThat(onTouchSlopExceededCallCount).isEqualTo(1) |
| 328 | } |
| 329 | |
| 330 | // TODO(b/129701831): This test assumes that if a pointer moves by slop in both x and y, we are |
| 331 | // still under slop even though sqrt(slop^2 + slop^2) > slop. This may be inaccurate and this |
| 332 | // test may therefore need to be updated. |
| 333 | @Test |
| 334 | fun onPointerInputChanges_moveAroundWithinSlop_onTouchSlopExceededNotCalled() { |
| 335 | val slop = TestTouchSlop.toFloat() |
| 336 | |
| 337 | var change = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 338 | mRecognizer.pointerInputHandler.invokeOverAllPasses(change) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 339 | |
| 340 | // Go around the border of the touch slop area |
| 341 | |
| 342 | // To top left |
Shep Shapard | e261df9 | 2019-11-15 11:24:31 -0800 | [diff] [blame^] | 343 | change = change.moveTo(10.milliseconds, -slop, -slop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 344 | mRecognizer.pointerInputHandler.invokeOverAllPasses(change) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 345 | // To bottom left |
Shep Shapard | e261df9 | 2019-11-15 11:24:31 -0800 | [diff] [blame^] | 346 | change = change.moveTo(20.milliseconds, -slop, slop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 347 | mRecognizer.pointerInputHandler.invokeOverAllPasses(change) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 348 | // To bottom right |
Shep Shapard | e261df9 | 2019-11-15 11:24:31 -0800 | [diff] [blame^] | 349 | change = change.moveTo(30.milliseconds, slop, slop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 350 | mRecognizer.pointerInputHandler.invokeOverAllPasses(change) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 351 | // To top right |
Shep Shapard | e261df9 | 2019-11-15 11:24:31 -0800 | [diff] [blame^] | 352 | change = change.moveTo(40.milliseconds, slop, -slop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 353 | mRecognizer.pointerInputHandler.invokeOverAllPasses(change) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 354 | |
| 355 | // Jump from corner to opposite corner and back |
| 356 | |
| 357 | // To bottom left |
Shep Shapard | e261df9 | 2019-11-15 11:24:31 -0800 | [diff] [blame^] | 358 | change = change.moveTo(50.milliseconds, -slop, slop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 359 | mRecognizer.pointerInputHandler.invokeOverAllPasses(change) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 360 | // To top right |
Shep Shapard | e261df9 | 2019-11-15 11:24:31 -0800 | [diff] [blame^] | 361 | change = change.moveTo(60.milliseconds, slop, -slop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 362 | mRecognizer.pointerInputHandler.invokeOverAllPasses(change) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 363 | |
| 364 | // Move the other diagonal |
| 365 | |
| 366 | // To top left |
Shep Shapard | e261df9 | 2019-11-15 11:24:31 -0800 | [diff] [blame^] | 367 | change = change.moveTo(70.milliseconds, -slop, -slop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 368 | mRecognizer.pointerInputHandler.invokeOverAllPasses(change) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 369 | |
| 370 | // Jump from corner to opposite corner and back |
| 371 | |
| 372 | // To bottom right |
Shep Shapard | e261df9 | 2019-11-15 11:24:31 -0800 | [diff] [blame^] | 373 | change = change.moveTo(80.milliseconds, slop, slop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 374 | mRecognizer.pointerInputHandler.invokeOverAllPasses(change) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 375 | // To top left |
Shep Shapard | e261df9 | 2019-11-15 11:24:31 -0800 | [diff] [blame^] | 376 | change = change.moveTo(90.milliseconds, -slop, -slop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 377 | mRecognizer.pointerInputHandler.invokeOverAllPasses(change) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 378 | |
| 379 | assertThat(onTouchSlopExceededCallCount).isEqualTo(0) |
| 380 | } |
| 381 | |
| 382 | // Verify the circumstances under which onTouchSlopExceeded should be called. |
| 383 | |
| 384 | @Test |
| 385 | fun onPointerInputChanges_movePassedSlop_onTouchSlopExceededCallOnce() { |
| 386 | val beyondTouchSlop = (TestTouchSlop + 1).toFloat() |
| 387 | |
| 388 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 389 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 390 | val move = down.moveBy( |
| 391 | Duration(milliseconds = 100), |
| 392 | beyondTouchSlop, |
| 393 | 0f |
| 394 | ) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 395 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 396 | |
| 397 | assertThat(onTouchSlopExceededCallCount).isEqualTo(1) |
| 398 | } |
| 399 | |
| 400 | @Test |
| 401 | fun onPointerInputChanges_movePassedSlopIn2Events_onTouchSlopExceededCallOnce() { |
| 402 | |
| 403 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 404 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 405 | val move = down.moveBy( |
| 406 | Duration(milliseconds = 100), |
| 407 | TestTouchSlop.toFloat(), |
| 408 | 0f |
| 409 | ) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 410 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 411 | val move2 = down.moveBy( |
| 412 | Duration(milliseconds = 100), |
| 413 | 1f, |
| 414 | 0f |
| 415 | ) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 416 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move2) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 417 | |
| 418 | assertThat(onTouchSlopExceededCallCount).isEqualTo(1) |
| 419 | } |
| 420 | |
| 421 | @Test |
| 422 | fun onPointerInputChanges_passSlopThenInSlopAreaThenOut_onTouchSlopExceededCallOnce() { |
| 423 | val beyondTouchSlop = (TestTouchSlop + 1).toFloat() |
| 424 | |
| 425 | var event = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 426 | mRecognizer.pointerInputHandler.invokeOverAllPasses(event) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 427 | // Out of touch slop region |
| 428 | event = event.moveBy(Duration(milliseconds = 10), 0f, beyondTouchSlop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 429 | mRecognizer.pointerInputHandler.invokeOverAllPasses(event) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 430 | // Back into touch slop region |
| 431 | event = event.moveBy(Duration(milliseconds = 10), 0f, -beyondTouchSlop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 432 | mRecognizer.pointerInputHandler.invokeOverAllPasses(event) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 433 | // Out of touch slop region again |
| 434 | event = event.moveBy(Duration(milliseconds = 10), 0f, beyondTouchSlop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 435 | mRecognizer.pointerInputHandler.invokeOverAllPasses(event) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 436 | |
| 437 | assertThat(onTouchSlopExceededCallCount).isEqualTo(1) |
| 438 | } |
| 439 | |
| 440 | @Test |
| 441 | fun onPointerInputChanges_downConsumedMovePassedSlop_onTouchSlopExceededCallOnce() { |
| 442 | val beyondTouchSlop = (TestTouchSlop + 1).toFloat() |
| 443 | |
| 444 | val down = down().consumeDownChange() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 445 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 446 | val move = down.moveBy(Duration(milliseconds = 100), beyondTouchSlop, 0f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 447 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 448 | |
| 449 | assertThat(onTouchSlopExceededCallCount).isEqualTo(1) |
| 450 | } |
| 451 | |
| 452 | @Test |
| 453 | fun onPointerInputChanges_beyondInUnsupportThenBeyondInSupport_onTouchSlopExceededCallOnce() { |
| 454 | val doubleTouchSlop = (TestTouchSlop * 2).toFloat() |
| 455 | val beyondTouchSlop = (TestTouchSlop + 1).toFloat() |
| 456 | |
| 457 | var change = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 458 | mRecognizer.pointerInputHandler.invokeOverAllPasses(change) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 459 | canDragReturn = false |
| 460 | change = change.moveBy( |
| 461 | Duration(milliseconds = 10), |
| 462 | 0f, |
| 463 | doubleTouchSlop |
| 464 | ) |
| 465 | // Sanity check that onTouchSlopExceeded has not been called. |
| 466 | assertThat(onTouchSlopExceededCallCount).isEqualTo(0) |
| 467 | |
| 468 | canDragReturn = true |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 469 | mRecognizer.pointerInputHandler.invokeOverAllPasses(change) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 470 | change = change.moveBy( |
| 471 | Duration(milliseconds = 10), |
| 472 | 0f, |
| 473 | -beyondTouchSlop |
| 474 | ) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 475 | mRecognizer.pointerInputHandler.invokeOverAllPasses(change) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 476 | |
| 477 | assertThat(onTouchSlopExceededCallCount).isEqualTo(1) |
| 478 | } |
| 479 | |
| 480 | @Test |
| 481 | fun onPointerInputChanges_2PointsMoveInOpposite_onTouchSlopExceededCallOnce() { |
| 482 | |
| 483 | // Arrange |
| 484 | |
| 485 | val beyondTouchSlop = (TestTouchSlop + 1).toFloat() |
| 486 | |
| 487 | var pointer1 = down(1) |
| 488 | var pointer2 = down(2) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 489 | mRecognizer.pointerInputHandler.invokeOverAllPasses(pointer1, pointer2) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 490 | |
| 491 | // Act |
| 492 | |
| 493 | pointer1 = pointer1.moveBy( |
| 494 | Duration(milliseconds = 100), |
| 495 | beyondTouchSlop, |
| 496 | 0f |
| 497 | ) |
| 498 | pointer2 = pointer2.moveBy( |
| 499 | Duration(milliseconds = 100), |
| 500 | -beyondTouchSlop, |
| 501 | 0f |
| 502 | ) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 503 | mRecognizer.pointerInputHandler.invokeOverAllPasses(pointer1, pointer2) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 504 | |
| 505 | // Assert |
| 506 | |
| 507 | assertThat(onTouchSlopExceededCallCount).isEqualTo(1) |
| 508 | } |
| 509 | |
| 510 | @Test |
| 511 | fun onPointerInputChanges_3PointsMoveAverage0_onTouchSlopExceededCallOnce() { |
| 512 | |
| 513 | // Arrange |
| 514 | |
| 515 | val beyondTouchSlop = (TestTouchSlop + 1).toFloat() |
| 516 | |
| 517 | val pointers = arrayListOf(down(0), down(1), down(2)) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 518 | mRecognizer.pointerInputHandler.invokeOverAllPasses(pointers) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 519 | |
| 520 | // Act |
| 521 | |
| 522 | // These movements average to no movement. |
| 523 | pointers[0] = |
| 524 | pointers[0].moveBy( |
| 525 | Duration(milliseconds = 100), |
| 526 | beyondTouchSlop * -1, |
| 527 | beyondTouchSlop * -1 |
| 528 | ) |
| 529 | pointers[1] = |
| 530 | pointers[1].moveBy( |
| 531 | Duration(milliseconds = 100), |
| 532 | beyondTouchSlop * 1, |
| 533 | beyondTouchSlop * -1 |
| 534 | ) |
| 535 | pointers[2] = |
| 536 | pointers[2].moveBy( |
| 537 | Duration(milliseconds = 100), |
| 538 | 0f, |
| 539 | beyondTouchSlop * 2 |
| 540 | ) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 541 | mRecognizer.pointerInputHandler.invokeOverAllPasses(pointers) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 542 | |
| 543 | // Assert |
| 544 | |
| 545 | assertThat(onTouchSlopExceededCallCount).isEqualTo(1) |
| 546 | } |
| 547 | |
| 548 | @Test |
| 549 | fun onPointerInputChanges_5Points1MoveBeyondSlop_onTouchSlopExceededCallOnce() { |
| 550 | |
| 551 | // Arrange |
| 552 | |
| 553 | val beyondTouchSlop = (TestTouchSlop + 1).toFloat() |
| 554 | |
| 555 | val pointers = arrayListOf(down(0), down(1), down(2), down(3), down(4)) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 556 | mRecognizer.pointerInputHandler.invokeOverAllPasses(pointers) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 557 | |
| 558 | // Act |
| 559 | |
| 560 | // These movements average to no movement. |
| 561 | for (i in 0..3) { |
| 562 | pointers[i] = pointers[i].moveBy( |
| 563 | Duration(milliseconds = 100), |
| 564 | 0f, |
| 565 | 0f |
| 566 | ) |
| 567 | } |
| 568 | pointers[4] = |
| 569 | pointers[4].moveBy( |
| 570 | Duration(milliseconds = 100), |
| 571 | beyondTouchSlop * -1, |
| 572 | 0f |
| 573 | ) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 574 | mRecognizer.pointerInputHandler.invokeOverAllPasses(pointers) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 575 | |
| 576 | // Assert |
| 577 | |
| 578 | assertThat(onTouchSlopExceededCallCount).isEqualTo(1) |
| 579 | } |
| 580 | |
| 581 | @Test |
| 582 | fun onPointerInputChanges_1PointMovesBeyondSlopAndThenManyTimes_onTouchSlopExceededCallOnce() { |
| 583 | |
| 584 | // Arrange |
| 585 | |
| 586 | val beyondTouchSlop = (TestTouchSlop + 1).toFloat() |
| 587 | |
| 588 | var pointer = down(0) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 589 | mRecognizer.pointerInputHandler.invokeOverAllPasses(pointer) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 590 | |
| 591 | // Act |
| 592 | |
| 593 | repeat(5) { |
| 594 | pointer = pointer.moveBy(100.milliseconds, beyondTouchSlop, beyondTouchSlop) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 595 | mRecognizer.pointerInputHandler.invokeOverAllPasses(pointer) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | // Assert |
| 599 | |
| 600 | assertThat(onTouchSlopExceededCallCount).isEqualTo(1) |
| 601 | } |
| 602 | |
| 603 | @Test |
| 604 | fun onPointerInputChanges_1ModifiedToMoveBeyondSlopBeforePostUp_onTouchSlopExceededCallOnce() { |
| 605 | |
| 606 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 607 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 608 | |
| 609 | val move = down().moveBy(10.milliseconds, 0f, 0f).consume(dx = TestTouchSlop + 1f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 610 | mRecognizer.pointerInputHandler.invokeOverPasses( |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 611 | listOf(move), |
| 612 | PointerEventPass.InitialDown, |
| 613 | PointerEventPass.PreUp, |
| 614 | PointerEventPass.PreDown, |
| 615 | PointerEventPass.PostUp |
| 616 | ) |
| 617 | |
| 618 | // Assert |
| 619 | |
| 620 | assertThat(onTouchSlopExceededCallCount).isEqualTo(1) |
| 621 | } |
| 622 | |
| 623 | @Test |
| 624 | fun onPointerInputChanges_1ModedToMoveBeyondSlopBeforePostDown_onTouchSlopExceededCallOnce() { |
| 625 | |
| 626 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 627 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 628 | |
| 629 | val move = down().moveBy(10.milliseconds, 0f, 0f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 630 | mRecognizer.pointerInputHandler.invokeOverPasses( |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 631 | listOf(move), |
| 632 | PointerEventPass.InitialDown, |
| 633 | PointerEventPass.PreUp, |
| 634 | PointerEventPass.PreDown, |
| 635 | PointerEventPass.PostUp |
| 636 | ) |
| 637 | |
| 638 | val moveConsumed = move.consume(dx = TestTouchSlop + 1f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 639 | mRecognizer.pointerInputHandler.invokeOverPasses( |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 640 | listOf(moveConsumed), |
| 641 | PointerEventPass.PostDown |
| 642 | ) |
| 643 | |
| 644 | // Assert |
| 645 | |
| 646 | assertThat(onTouchSlopExceededCallCount).isEqualTo(1) |
| 647 | } |
| 648 | |
| 649 | @Test |
| 650 | fun onPointerInputChanges_moveUnderToPostUpThenModOverToPostDown_onTouchSlopExceededCallOnce() { |
| 651 | |
| 652 | val halfSlop = TestTouchSlop / 2 |
| 653 | val restOfSlopAndBeyond = TestTouchSlop - halfSlop + 1 |
| 654 | |
| 655 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 656 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 657 | |
| 658 | val move = down().moveBy(10.milliseconds, halfSlop.toFloat(), 0f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 659 | mRecognizer.pointerInputHandler.invokeOverPasses( |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 660 | listOf(move), |
| 661 | PointerEventPass.InitialDown, |
| 662 | PointerEventPass.PreUp, |
| 663 | PointerEventPass.PreDown, |
| 664 | PointerEventPass.PostUp |
| 665 | ) |
| 666 | |
| 667 | val moveConsumed = move.consume(dx = -restOfSlopAndBeyond.toFloat()) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 668 | mRecognizer.pointerInputHandler.invokeOverPasses( |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 669 | listOf(moveConsumed), |
| 670 | PointerEventPass.PostDown |
| 671 | ) |
| 672 | |
| 673 | // Assert |
| 674 | |
| 675 | assertThat(onTouchSlopExceededCallCount).isEqualTo(1) |
| 676 | } |
| 677 | |
| 678 | @Test |
| 679 | fun onPointerInputChanges_moveBeyondSlopAllPassesUpToPostUp_onTouchSlopExceededCallOnce() { |
| 680 | |
| 681 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 682 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 683 | |
| 684 | val move = down().moveBy(10.milliseconds, TestTouchSlop + 1f, 0f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 685 | mRecognizer.pointerInputHandler.invokeOverPasses( |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 686 | listOf(move), |
| 687 | PointerEventPass.InitialDown, |
| 688 | PointerEventPass.PreUp, |
| 689 | PointerEventPass.PreDown, |
| 690 | PointerEventPass.PostUp |
| 691 | ) |
| 692 | |
| 693 | // Assert |
| 694 | |
| 695 | assertThat(onTouchSlopExceededCallCount).isEqualTo(1) |
| 696 | } |
| 697 | |
| 698 | // Verification that TouchSlopExceededGestureDetector does not consume any changes. |
| 699 | |
| 700 | @Test |
| 701 | fun onPointerInputChanges_1Down_nothingConsumed() { |
| 702 | |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 703 | val result = mRecognizer.pointerInputHandler.invokeOverAllPasses(down()) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 704 | |
| 705 | // Assert |
| 706 | |
| 707 | assertThat(result[0].consumed.downChange).isFalse() |
| 708 | assertThat(result[0].consumed.positionChange.x).isEqualTo(0.px) |
| 709 | assertThat(result[0].consumed.positionChange.y).isEqualTo(0.px) |
| 710 | } |
| 711 | |
| 712 | @Test |
| 713 | fun onPointerInputChanges_1MoveUnderSlop_nothingConsumed() { |
| 714 | |
| 715 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 716 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 717 | |
| 718 | val move = down().moveBy(10.milliseconds, TestTouchSlop.toFloat(), TestTouchSlop.toFloat()) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 719 | val result = mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 720 | |
| 721 | // Assert |
| 722 | |
| 723 | assertThat(result[0].consumed.downChange).isFalse() |
| 724 | assertThat(result[0].consumed.positionChange.x).isEqualTo(0.px) |
| 725 | assertThat(result[0].consumed.positionChange.y).isEqualTo(0.px) |
| 726 | } |
| 727 | |
| 728 | @Test |
| 729 | fun onPointerInputChanges_1MoveUnderSlopThenUp_nothingConsumed() { |
| 730 | |
| 731 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 732 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 733 | |
| 734 | val move = down().moveBy(10.milliseconds, TestTouchSlop.toFloat(), TestTouchSlop.toFloat()) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 735 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 736 | |
Shep Shapard | e261df9 | 2019-11-15 11:24:31 -0800 | [diff] [blame^] | 737 | val up = move.up(20.milliseconds) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 738 | val result = mRecognizer.pointerInputHandler.invokeOverAllPasses(up) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 739 | |
| 740 | // Assert |
| 741 | |
| 742 | assertThat(result[0].consumed.downChange).isFalse() |
| 743 | assertThat(result[0].consumed.positionChange.x).isEqualTo(0.px) |
| 744 | assertThat(result[0].consumed.positionChange.y).isEqualTo(0.px) |
| 745 | } |
| 746 | |
| 747 | @Test |
| 748 | fun onPointerInputChanges_1MoveOverSlop_nothingConsumed() { |
| 749 | |
| 750 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 751 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 752 | |
| 753 | val move = down().moveBy(10.milliseconds, TestTouchSlop + 1f, TestTouchSlop + 1f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 754 | val result = mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 755 | |
| 756 | // Assert |
| 757 | |
| 758 | assertThat(result[0].consumed.downChange).isFalse() |
| 759 | assertThat(result[0].consumed.positionChange.x).isEqualTo(0.px) |
| 760 | assertThat(result[0].consumed.positionChange.y).isEqualTo(0.px) |
| 761 | } |
| 762 | |
| 763 | @Test |
| 764 | fun onPointerInputChanges_1MoveOverSlopThenUp_nothingConsumed() { |
| 765 | |
| 766 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 767 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 768 | |
| 769 | val move = down().moveBy(10.milliseconds, TestTouchSlop + 1f, TestTouchSlop + 1f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 770 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 771 | |
Shep Shapard | e261df9 | 2019-11-15 11:24:31 -0800 | [diff] [blame^] | 772 | val up = move.up(20.milliseconds) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 773 | val result = mRecognizer.pointerInputHandler.invokeOverAllPasses(up) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 774 | |
| 775 | // Assert |
| 776 | |
| 777 | assertThat(result[0].consumed.downChange).isFalse() |
| 778 | assertThat(result[0].consumed.positionChange.x).isEqualTo(0.px) |
| 779 | assertThat(result[0].consumed.positionChange.y).isEqualTo(0.px) |
| 780 | } |
| 781 | |
| 782 | // Verification that TouchSlopExceededGestureDetector resets after up correctly. |
| 783 | |
| 784 | @Test |
| 785 | fun onPointerInputChanges_MoveBeyondUpDownMoveBeyond_onTouchSlopExceededCalledTwice() { |
| 786 | |
| 787 | repeat(2) { |
| 788 | val down = down() |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 789 | mRecognizer.pointerInputHandler.invokeOverAllPasses(down) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 790 | |
| 791 | val move = down().moveBy(10.milliseconds, TestTouchSlop + 1f, 0f) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 792 | mRecognizer.pointerInputHandler.invokeOverAllPasses(move) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 793 | |
Shep Shapard | e261df9 | 2019-11-15 11:24:31 -0800 | [diff] [blame^] | 794 | val up = move.up(20.milliseconds) |
shepshapard | 6351290 | 2019-10-02 14:44:51 -0700 | [diff] [blame] | 795 | mRecognizer.pointerInputHandler.invokeOverAllPasses(up) |
shepshapard | 648840f | 2019-07-17 14:28:50 -0700 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | assertThat(onTouchSlopExceededCallCount).isEqualTo(2) |
| 799 | } |
| 800 | } |