double_tap_test.dart 20.2 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Ian Hickson's avatar
Ian Hickson committed
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:fake_async/fake_async.dart';
6 7
import 'package:flutter/gestures.dart';
import 'package:flutter_test/flutter_test.dart';
8

9 10
import 'gesture_tester.dart';

11
class TestGestureArenaMember extends GestureArenaMember {
12
  @override
13
  void acceptGesture(int key) {
14 15
    accepted = true;
  }
16 17

  @override
18
  void rejectGesture(int key) {
19 20
    rejected = true;
  }
21

22 23
  bool accepted = false;
  bool rejected = false;
24 25 26
}

void main() {
27 28 29 30
  late DoubleTapGestureRecognizer tap;
  bool doubleTapRecognized = false;
  TapDownDetails? doubleTapDownDetails;
  bool doubleTapCanceled = false;
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

  setUp(() {
    ensureGestureBinding();
    tap = DoubleTapGestureRecognizer();

    doubleTapRecognized = false;
    tap.onDoubleTap = () {
      expect(doubleTapRecognized, isFalse);
      doubleTapRecognized = true;
    };

    doubleTapDownDetails = null;
    tap.onDoubleTapDown = (TapDownDetails details) {
      expect(doubleTapDownDetails, isNull);
      doubleTapDownDetails = details;
    };

    doubleTapCanceled = false;
    tap.onDoubleTapCancel = () {
      expect(doubleTapCanceled, isFalse);
      doubleTapCanceled = true;
    };
  });

  tearDown(() {
    tap.dispose();
  });
58 59

  // Down/up pair 1: normal tap sequence
60
  const PointerDownEvent down1 = PointerDownEvent(
61
    pointer: 1,
62
    position: Offset(10.0, 10.0),
63 64
  );

65
  const PointerUpEvent up1 = PointerUpEvent(
66
    pointer: 1,
67
    position: Offset(11.0, 9.0),
68 69 70
  );

  // Down/up pair 2: normal tap sequence close to pair 1
71
  const PointerDownEvent down2 = PointerDownEvent(
72
    pointer: 2,
73
    position: Offset(12.0, 12.0),
74 75
  );

76
  const PointerUpEvent up2 = PointerUpEvent(
77
    pointer: 2,
78
    position: Offset(13.0, 11.0),
79 80 81
  );

  // Down/up pair 3: normal tap sequence far away from pair 1
82
  const PointerDownEvent down3 = PointerDownEvent(
83
    pointer: 3,
84
    position: Offset(130.0, 130.0),
85 86
  );

87
  const PointerUpEvent up3 = PointerUpEvent(
88
    pointer: 3,
89
    position: Offset(131.0, 129.0),
90 91 92
  );

  // Down/move/up sequence 4: intervening motion
93
  const PointerDownEvent down4 = PointerDownEvent(
94
    pointer: 4,
95
    position: Offset(10.0, 10.0),
96 97
  );

98
  const PointerMoveEvent move4 = PointerMoveEvent(
99
    pointer: 4,
100
    position: Offset(25.0, 25.0),
101 102
  );

103
  const PointerUpEvent up4 = PointerUpEvent(
104
    pointer: 4,
105
    position: Offset(25.0, 25.0),
106 107
  );

108
  // Down/up pair 5: normal tap sequence identical to pair 1
109
  const PointerDownEvent down5 = PointerDownEvent(
110
    pointer: 5,
111
    position: Offset(10.0, 10.0),
112 113
  );

114
  const PointerUpEvent up5 = PointerUpEvent(
115
    pointer: 5,
116
    position: Offset(11.0, 9.0),
117 118
  );

119 120 121 122 123 124 125 126 127 128 129 130
  // Down/up pair 6: normal tap sequence close to pair 1 but on secondary button
  const PointerDownEvent down6 = PointerDownEvent(
    pointer: 6,
    position: Offset(10.0, 10.0),
    buttons: kSecondaryMouseButton,
  );

  const PointerUpEvent up6 = PointerUpEvent(
    pointer: 6,
    position: Offset(11.0, 9.0),
  );

131
  testGesture('Should recognize double tap', (GestureTester tester) {
132
    tap.addPointer(down1);
133 134 135
    tester.closeArena(1);
    tester.route(down1);
    tester.route(up1);
136
    GestureBinding.instance!.gestureArena.sweep(1);
137
    expect(doubleTapDownDetails, isNull);
138

139
    tester.async.elapse(const Duration(milliseconds: 100));
140
    tap.addPointer(down2);
141
    tester.closeArena(2);
142
    expect(doubleTapDownDetails, isNotNull);
143 144
    expect(doubleTapDownDetails!.globalPosition, down2.position);
    expect(doubleTapDownDetails!.localPosition, down2.localPosition);
145
    tester.route(down2);
146 147
    expect(doubleTapRecognized, isFalse);

148
    tester.route(up2);
149
    expect(doubleTapRecognized, isTrue);
150
    GestureBinding.instance!.gestureArena.sweep(2);
151
    expect(doubleTapCanceled, isFalse);
152 153
  });

154
  testGesture('Inter-tap distance cancels double tap', (GestureTester tester) {
155
    tap.addPointer(down1);
156 157 158
    tester.closeArena(1);
    tester.route(down1);
    tester.route(up1);
159
    GestureBinding.instance!.gestureArena.sweep(1);
160 161

    tap.addPointer(down3);
162 163 164
    tester.closeArena(3);
    tester.route(down3);
    tester.route(up3);
165
    GestureBinding.instance!.gestureArena.sweep(3);
166

167 168 169
    expect(doubleTapRecognized, isFalse);
    expect(doubleTapDownDetails, isNull);
    expect(doubleTapCanceled, isFalse);
170 171
  });

172
  testGesture('Intra-tap distance cancels double tap', (GestureTester tester) {
173
    tap.addPointer(down4);
174 175
    tester.closeArena(4);
    tester.route(down4);
176

177 178
    tester.route(move4);
    tester.route(up4);
179
    GestureBinding.instance!.gestureArena.sweep(4);
180 181

    tap.addPointer(down1);
182 183 184
    tester.closeArena(1);
    tester.route(down2);
    tester.route(up1);
185
    GestureBinding.instance!.gestureArena.sweep(1);
186

187 188 189
    expect(doubleTapRecognized, isFalse);
    expect(doubleTapDownDetails, isNull);
    expect(doubleTapCanceled, isFalse);
190 191
  });

192 193 194 195 196
  testGesture('Inter-tap delay cancels double tap', (GestureTester tester) {
    tap.addPointer(down1);
    tester.closeArena(1);
    tester.route(down1);
    tester.route(up1);
197
    GestureBinding.instance!.gestureArena.sweep(1);
198

199
    tester.async.elapse(const Duration(milliseconds: 5000));
200 201 202 203
    tap.addPointer(down2);
    tester.closeArena(2);
    tester.route(down2);
    tester.route(up2);
204
    GestureBinding.instance!.gestureArena.sweep(2);
205

206 207 208
    expect(doubleTapRecognized, isFalse);
    expect(doubleTapDownDetails, isNull);
    expect(doubleTapCanceled, isFalse);
209 210
  });

211 212 213 214 215
  testGesture('Inter-tap delay resets double tap, allowing third tap to be a double-tap', (GestureTester tester) {
    tap.addPointer(down1);
    tester.closeArena(1);
    tester.route(down1);
    tester.route(up1);
216
    GestureBinding.instance!.gestureArena.sweep(1);
217

218
    tester.async.elapse(const Duration(milliseconds: 5000));
219 220 221 222
    tap.addPointer(down2);
    tester.closeArena(2);
    tester.route(down2);
    tester.route(up2);
223
    GestureBinding.instance!.gestureArena.sweep(2);
224
    expect(doubleTapDownDetails, isNull);
225

226
    tester.async.elapse(const Duration(milliseconds: 100));
227 228 229 230
    tap.addPointer(down5);
    tester.closeArena(5);
    tester.route(down5);
    expect(doubleTapRecognized, isFalse);
231
    expect(doubleTapDownDetails, isNotNull);
232 233
    expect(doubleTapDownDetails!.globalPosition, down5.position);
    expect(doubleTapDownDetails!.localPosition, down5.localPosition);
234

235 236
    tester.route(up5);
    expect(doubleTapRecognized, isTrue);
237
    GestureBinding.instance!.gestureArena.sweep(5);
238
    expect(doubleTapCanceled, isFalse);
239 240
  });

241 242 243 244
  testGesture('Intra-tap delay does not cancel double tap', (GestureTester tester) {
    tap.addPointer(down1);
    tester.closeArena(1);
    tester.route(down1);
245
    tester.async.elapse(const Duration(milliseconds: 1000));
246
    tester.route(up1);
247
    GestureBinding.instance!.gestureArena.sweep(1);
248
    expect(doubleTapDownDetails, isNull);
249

250 251 252 253
    tap.addPointer(down2);
    tester.closeArena(2);
    tester.route(down2);
    expect(doubleTapRecognized, isFalse);
254
    expect(doubleTapDownDetails, isNotNull);
255 256
    expect(doubleTapDownDetails!.globalPosition, down2.position);
    expect(doubleTapDownDetails!.localPosition, down2.localPosition);
257

258 259
    tester.route(up2);
    expect(doubleTapRecognized, isTrue);
260
    GestureBinding.instance!.gestureArena.sweep(2);
261
    expect(doubleTapCanceled, isFalse);
262 263
  });

264
  testGesture('Should not recognize two overlapping taps', (GestureTester tester) {
265
    tap.addPointer(down1);
266 267
    tester.closeArena(1);
    tester.route(down1);
268 269

    tap.addPointer(down2);
270 271
    tester.closeArena(2);
    tester.route(down1);
272

273
    tester.route(up1);
274
    GestureBinding.instance!.gestureArena.sweep(1);
275

276
    tester.route(up2);
277
    GestureBinding.instance!.gestureArena.sweep(2);
278

279 280 281
    expect(doubleTapRecognized, isFalse);
    expect(doubleTapDownDetails, isNull);
    expect(doubleTapCanceled, isFalse);
282 283
  });

284
  testGesture('Should recognize one tap of group followed by second tap', (GestureTester tester) {
285
    tap.addPointer(down1);
286 287
    tester.closeArena(1);
    tester.route(down1);
288 289

    tap.addPointer(down2);
290 291
    tester.closeArena(2);
    tester.route(down1);
292

293
    tester.route(up1);
294
    GestureBinding.instance!.gestureArena.sweep(1);
295

296
    tester.route(up2);
297
    GestureBinding.instance!.gestureArena.sweep(2);
298
    expect(doubleTapDownDetails, isNull);
299

300
    tester.async.elapse(const Duration(milliseconds: 100));
301
    tap.addPointer(down1);
302 303
    tester.closeArena(1);
    tester.route(down1);
304
    expect(doubleTapRecognized, isFalse);
305
    expect(doubleTapDownDetails, isNotNull);
306 307
    expect(doubleTapDownDetails!.globalPosition, down1.position);
    expect(doubleTapDownDetails!.localPosition, down1.localPosition);
308

309
    tester.route(up1);
310
    expect(doubleTapRecognized, isTrue);
311
    GestureBinding.instance!.gestureArena.sweep(1);
312
    expect(doubleTapCanceled, isFalse);
313 314
  });

315
  testGesture('Should cancel on arena reject during first tap', (GestureTester tester) {
316
    tap.addPointer(down1);
317
    final TestGestureArenaMember member = TestGestureArenaMember();
318
    final GestureArenaEntry entry = GestureBinding.instance!.gestureArena.add(1, member);
319 320
    tester.closeArena(1);
    tester.route(down1);
321

322
    tester.route(up1);
323
    entry.resolve(GestureDisposition.accepted);
324
    expect(member.accepted, isTrue);
325
    GestureBinding.instance!.gestureArena.sweep(1);
326 327

    tap.addPointer(down2);
328 329 330
    tester.closeArena(2);
    tester.route(down2);
    tester.route(up2);
331
    GestureBinding.instance!.gestureArena.sweep(2);
332

333 334 335
    expect(doubleTapRecognized, isFalse);
    expect(doubleTapDownDetails, isNull);
    expect(doubleTapCanceled, isFalse);
336 337
  });

338
  testGesture('Should cancel on arena reject between taps', (GestureTester tester) {
339
    tap.addPointer(down1);
340
    final TestGestureArenaMember member = TestGestureArenaMember();
341
    final GestureArenaEntry entry = GestureBinding.instance!.gestureArena.add(1, member);
342 343 344
    tester.closeArena(1);
    tester.route(down1);
    tester.route(up1);
345
    GestureBinding.instance!.gestureArena.sweep(1);
346 347

    entry.resolve(GestureDisposition.accepted);
348
    expect(member.accepted, isTrue);
349 350

    tap.addPointer(down2);
351 352 353
    tester.closeArena(2);
    tester.route(down2);
    tester.route(up2);
354
    GestureBinding.instance!.gestureArena.sweep(2);
355

356 357 358
    expect(doubleTapRecognized, isFalse);
    expect(doubleTapDownDetails, isNull);
    expect(doubleTapCanceled, isFalse);
359 360
  });

361
  testGesture('Should cancel on arena reject during last tap', (GestureTester tester) {
362
    tap.addPointer(down1);
363
    final TestGestureArenaMember member = TestGestureArenaMember();
364
    final GestureArenaEntry entry = GestureBinding.instance!.gestureArena.add(1, member);
365 366 367
    tester.closeArena(1);
    tester.route(down1);
    tester.route(up1);
368
    GestureBinding.instance!.gestureArena.sweep(1);
369
    expect(doubleTapDownDetails, isNull);
370

371
    tester.async.elapse(const Duration(milliseconds: 100));
372
    tap.addPointer(down2);
373 374
    tester.closeArena(2);
    tester.route(down2);
375
    expect(doubleTapDownDetails, isNotNull);
376 377
    expect(doubleTapDownDetails!.globalPosition, down2.position);
    expect(doubleTapDownDetails!.localPosition, down2.localPosition);
378
    expect(doubleTapCanceled, isFalse);
379 380

    entry.resolve(GestureDisposition.accepted);
381
    expect(member.accepted, isTrue);
382
    expect(doubleTapCanceled, isTrue);
383

384
    tester.route(up2);
385
    GestureBinding.instance!.gestureArena.sweep(2);
386 387 388
    expect(doubleTapRecognized, isFalse);
  });

389
  testGesture('Passive gesture should trigger on double tap cancel', (GestureTester tester) {
390
    FakeAsync().run((FakeAsync async) {
391
      tap.addPointer(down1);
392
      final TestGestureArenaMember member = TestGestureArenaMember();
393
      GestureBinding.instance!.gestureArena.add(1, member);
394 395 396
      tester.closeArena(1);
      tester.route(down1);
      tester.route(up1);
397
      GestureBinding.instance!.gestureArena.sweep(1);
398 399

      expect(member.accepted, isFalse);
Ian Hickson's avatar
Ian Hickson committed
400
      async.elapse(const Duration(milliseconds: 5000));
401 402
      expect(member.accepted, isTrue);

403 404 405 406
      expect(doubleTapRecognized, isFalse);
      expect(doubleTapDownDetails, isNull);
      expect(doubleTapCanceled, isFalse);
    });
407 408
  });

409 410 411 412 413
  testGesture('Should not recognize two over-rapid taps', (GestureTester tester) {
    tap.addPointer(down1);
    tester.closeArena(1);
    tester.route(down1);
    tester.route(up1);
414
    GestureBinding.instance!.gestureArena.sweep(1);
415 416 417 418 419 420

    tester.async.elapse(const Duration(milliseconds: 10));
    tap.addPointer(down2);
    tester.closeArena(2);
    tester.route(down2);
    tester.route(up2);
421
    GestureBinding.instance!.gestureArena.sweep(2);
422

423 424 425
    expect(doubleTapRecognized, isFalse);
    expect(doubleTapDownDetails, isNull);
    expect(doubleTapCanceled, isFalse);
426 427 428 429 430 431 432
  });

  testGesture('Over-rapid taps resets double tap, allowing third tap to be a double-tap', (GestureTester tester) {
    tap.addPointer(down1);
    tester.closeArena(1);
    tester.route(down1);
    tester.route(up1);
433
    GestureBinding.instance!.gestureArena.sweep(1);
434 435 436 437 438 439

    tester.async.elapse(const Duration(milliseconds: 10));
    tap.addPointer(down2);
    tester.closeArena(2);
    tester.route(down2);
    tester.route(up2);
440
    GestureBinding.instance!.gestureArena.sweep(2);
441
    expect(doubleTapDownDetails, isNull);
442 443 444 445 446 447

    tester.async.elapse(const Duration(milliseconds: 100));
    tap.addPointer(down5);
    tester.closeArena(5);
    tester.route(down5);
    expect(doubleTapRecognized, isFalse);
448
    expect(doubleTapDownDetails, isNotNull);
449 450
    expect(doubleTapDownDetails!.globalPosition, down5.position);
    expect(doubleTapDownDetails!.localPosition, down5.localPosition);
451 452 453

    tester.route(up5);
    expect(doubleTapRecognized, isTrue);
454
    GestureBinding.instance!.gestureArena.sweep(5);
455
    expect(doubleTapCanceled, isFalse);
456
  });
457 458 459 460 461 462 463 464 465 466 467 468 469 470

  group('Enforce consistent-button restriction:', () {
    testGesture('Button change should interrupt existing sequence', (GestureTester tester) {
      // Down1 -> down6 (different button from 1) -> down2 (same button as 1)
      // Down1 and down2 could've been a double tap, but is interrupted by down 6.

      const Duration interval = Duration(milliseconds: 100);
      assert(interval * 2 < kDoubleTapTimeout);
      assert(interval > kDoubleTapMinTime);

      tap.addPointer(down1);
      tester.closeArena(1);
      tester.route(down1);
      tester.route(up1);
471
      GestureBinding.instance!.gestureArena.sweep(1);
472 473 474 475 476 477 478

      tester.async.elapse(interval);

      tap.addPointer(down6);
      tester.closeArena(6);
      tester.route(down6);
      tester.route(up6);
479
      GestureBinding.instance!.gestureArena.sweep(6);
480 481 482 483 484 485 486 487

      tester.async.elapse(interval);
      expect(doubleTapRecognized, isFalse);

      tap.addPointer(down2);
      tester.closeArena(2);
      tester.route(down2);
      tester.route(up2);
488
      GestureBinding.instance!.gestureArena.sweep(2);
489 490

      expect(doubleTapRecognized, isFalse);
491 492
      expect(doubleTapDownDetails, isNull);
      expect(doubleTapCanceled, isFalse);
493 494 495 496 497 498 499 500 501 502 503 504 505
    });

    testGesture('Button change should start a valid sequence', (GestureTester tester) {
      // Down6 -> down1 (different button from 6) -> down2 (same button as 1)

      const Duration interval = Duration(milliseconds: 100);
      assert(interval * 2 < kDoubleTapTimeout);
      assert(interval > kDoubleTapMinTime);

      tap.addPointer(down6);
      tester.closeArena(6);
      tester.route(down6);
      tester.route(up6);
506
      GestureBinding.instance!.gestureArena.sweep(6);
507 508 509 510 511 512 513

      tester.async.elapse(interval);

      tap.addPointer(down1);
      tester.closeArena(1);
      tester.route(down1);
      tester.route(up1);
514
      GestureBinding.instance!.gestureArena.sweep(1);
515 516

      expect(doubleTapRecognized, isFalse);
517
      expect(doubleTapDownDetails, isNull);
518 519 520 521 522
      tester.async.elapse(interval);

      tap.addPointer(down2);
      tester.closeArena(2);
      tester.route(down2);
523
      expect(doubleTapDownDetails, isNotNull);
524 525
      expect(doubleTapDownDetails!.globalPosition, down2.position);
      expect(doubleTapDownDetails!.localPosition, down2.localPosition);
526
      tester.route(up2);
527
      GestureBinding.instance!.gestureArena.sweep(2);
528 529

      expect(doubleTapRecognized, isTrue);
530
      expect(doubleTapCanceled, isFalse);
531 532 533 534 535 536 537 538 539 540 541 542
    });
  });

  group('Recognizers listening on different buttons do not form competition:', () {
    // This test is assisted by tap recognizers. If a tap gesture has
    // no competing recognizers, a pointer down event triggers its onTapDown
    // immediately; if there are competitors, onTapDown is triggered after a
    // timeout.
    // The following tests make sure that double tap recognizers do not form
    // competition with a tap gesture recognizer listening on a different button.

    final List<String> recognized = <String>[];
543 544 545
    late TapGestureRecognizer tapPrimary;
    late TapGestureRecognizer tapSecondary;
    late DoubleTapGestureRecognizer doubleTap;
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
    setUp(() {
      tapPrimary = TapGestureRecognizer()
        ..onTapDown = (TapDownDetails details) {
          recognized.add('tapPrimary');
        };
      tapSecondary = TapGestureRecognizer()
        ..onSecondaryTapDown = (TapDownDetails details) {
          recognized.add('tapSecondary');
        };
      doubleTap = DoubleTapGestureRecognizer()
        ..onDoubleTap = () {
          recognized.add('doubleTap');
        };
    });

    tearDown(() {
      recognized.clear();
      tapPrimary.dispose();
      tapSecondary.dispose();
      doubleTap.dispose();
    });

Chris Bracken's avatar
Chris Bracken committed
568
    testGesture('A primary double tap recognizer does not form competition with a secondary tap recognizer', (GestureTester tester) {
569 570 571 572 573 574 575 576
      doubleTap.addPointer(down6);
      tapSecondary.addPointer(down6);
      tester.closeArena(down6.pointer);

      tester.route(down6);
      expect(recognized, <String>['tapSecondary']);
    });

Chris Bracken's avatar
Chris Bracken committed
577
    testGesture('A primary double tap recognizer forms competition with a primary tap recognizer', (GestureTester tester) {
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
      doubleTap.addPointer(down1);
      tapPrimary.addPointer(down1);
      tester.closeArena(down1.pointer);

      tester.route(down1);
      expect(recognized, <String>[]);

      tester.async.elapse(const Duration(milliseconds: 300));
      expect(recognized, <String>['tapPrimary']);
    });
  });

  testGesture('A secondary double tap should not trigger primary', (GestureTester tester) {
    final List<String> recognized = <String>[];
    final DoubleTapGestureRecognizer doubleTap = DoubleTapGestureRecognizer()
      ..onDoubleTap = () {
        recognized.add('primary');
      };

    // Down/up pair 7: normal tap sequence close to pair 6
    const PointerDownEvent down7 = PointerDownEvent(
      pointer: 7,
      position: Offset(10.0, 10.0),
      buttons: kSecondaryMouseButton,
    );

    const PointerUpEvent up7 = PointerUpEvent(
      pointer: 7,
      position: Offset(11.0, 9.0),
    );

    doubleTap.addPointer(down6);
    tester.closeArena(6);
    tester.route(down6);
    tester.route(up6);
613
    GestureBinding.instance!.gestureArena.sweep(6);
614 615 616 617 618 619 620 621 622 623 624

    tester.async.elapse(const Duration(milliseconds: 100));
    doubleTap.addPointer(down7);
    tester.closeArena(7);
    tester.route(down7);
    tester.route(up7);
    expect(recognized, <String>[]);

    recognized.clear();
    doubleTap.dispose();
  });
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659

  // Regression test for https://github.com/flutter/flutter/issues/73667
  testGesture('Unfinished DoubleTap does not prevent competing Tap', (GestureTester tester) {
    int tapCount = 0;
    final DoubleTapGestureRecognizer doubleTap = DoubleTapGestureRecognizer()
      ..onDoubleTap = () {};
    final TapGestureRecognizer tap = TapGestureRecognizer()
      ..onTap = () => tapCount++;

    // Open a arena with 2 members and holding.
    doubleTap.addPointer(down1);
    tap.addPointer(down1);
    tester.closeArena(1);
    tester.route(down1);
    tester.route(up1);
    GestureBinding.instance!.gestureArena.sweep(1);

    // Open a new arena with only one TapGestureRecognizer.
    tester.async.elapse(const Duration(milliseconds: 100));
    tap.addPointer(down2);
    tester.closeArena(2);
    tester.route(down2);
    final PointerMoveEvent move2 = PointerMoveEvent(pointer: 2, position: down2.position);
    tester.route(move2);
    tester.route(up2);
    expect(tapCount, 1); // The second tap will win immediately.
    GestureBinding.instance!.gestureArena.sweep(2);

    // Finish the previous gesture arena.
    tester.async.elapse(const Duration(milliseconds: 300));
    expect(tapCount, 1); // The first tap should not trigger onTap callback though it wins the arena.

    tap.dispose();
    doubleTap.dispose();
  });
660
}