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

5 6
// @dart = 2.8

7 8 9 10 11 12 13 14 15 16 17
import 'dart:ui';

import 'package:flutter/rendering.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';

import 'semantics_tester.dart';

void main() {
  testWidgets('Traversal Order of SliverList', (WidgetTester tester) async {
18
    final SemanticsTester semantics = SemanticsTester(tester);
19

20 21
    final List<Widget> listChildren = List<Widget>.generate(30, (int i) {
      return Container(
22
        height: 200.0,
23
        child: Row(
24 25
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
26
            Semantics(
27
              container: true,
28
              child: Text('Item ${i}a'),
29
            ),
30
            Semantics(
31
              container: true,
32
              child: Text('item ${i}b'),
33 34 35 36 37 38
            ),
          ],
        ),
      );
    });
    await tester.pumpWidget(
39
      Semantics(
40
        textDirection: TextDirection.ltr,
41
        child: Directionality(
42
          textDirection: TextDirection.ltr,
43
          child: MediaQuery(
44
            data: const MediaQueryData(),
45 46
            child: CustomScrollView(
              controller: ScrollController(initialScrollOffset: 3000.0),
47
              semanticChildCount: 30,
48
              slivers: <Widget>[
49 50
                SliverList(
                  delegate: SliverChildListDelegate(listChildren),
51 52 53 54 55 56 57 58 59
                ),
              ],
            ),
          ),
        ),
      ),
    );

    expect(semantics, hasSemantics(
60
      TestSemantics.root(
61
        children: <TestSemantics>[
62
          TestSemantics(
63 64
            textDirection: TextDirection.ltr,
            children: <TestSemantics>[
65
              TestSemantics(
66
                children: <TestSemantics>[
67
                  TestSemantics(
68 69
                    scrollIndex: 15,
                    scrollChildren: 30,
70 71 72
                    flags: <SemanticsFlag>[
                      SemanticsFlag.hasImplicitScrolling,
                    ],
73 74 75 76 77
                    actions: <SemanticsAction>[
                      SemanticsAction.scrollUp,
                      SemanticsAction.scrollDown,
                    ],
                    children: <TestSemantics>[
78
                      TestSemantics(
79
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
80 81 82 83 84 85 86 87 88 89 90 91
                        children: <TestSemantics>[
                          TestSemantics(
                            flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                            label: 'Item 13a',
                            textDirection: TextDirection.ltr,
                          ),
                          TestSemantics(
                            flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                            label: 'item 13b',
                            textDirection: TextDirection.ltr,
                          ),
                        ],
92
                      ),
93
                      TestSemantics(
94
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
95 96 97 98 99 100 101 102 103 104 105
                        children: <TestSemantics>[
                          TestSemantics(
                            flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                            label: 'Item 14a',
                            textDirection: TextDirection.ltr,
                          ),
                          TestSemantics(
                            flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                            label: 'item 14b',
                            textDirection: TextDirection.ltr,
                          ),
106
                        ],
107
                      ),
108
                      TestSemantics(
109 110 111 112 113 114 115 116 117 118
                        children: <TestSemantics>[
                          TestSemantics(
                            label: 'Item 15a',
                            textDirection: TextDirection.ltr,
                          ),
                          TestSemantics(
                            label: 'item 15b',
                            textDirection: TextDirection.ltr,
                          ),
                        ],
119
                      ),
120
                      TestSemantics(
121 122 123 124 125 126 127 128 129 130
                        children: <TestSemantics>[
                          TestSemantics(
                            label: 'Item 16a',
                            textDirection: TextDirection.ltr,
                          ),
                          TestSemantics(
                            label: 'item 16b',
                            textDirection: TextDirection.ltr,
                          ),
                        ],
131
                      ),
132
                      TestSemantics(
133 134 135 136 137 138 139 140 141 142
                        children: <TestSemantics>[
                          TestSemantics(
                            label: 'Item 17a',
                            textDirection: TextDirection.ltr,
                          ),
                          TestSemantics(
                            label: 'item 17b',
                            textDirection: TextDirection.ltr,
                          ),
                        ],
143
                      ),
144
                      TestSemantics(
145
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
146 147 148 149 150 151 152 153 154 155 156 157
                        children: <TestSemantics>[
                          TestSemantics(
                            flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                            label: 'Item 18a',
                            textDirection: TextDirection.ltr,
                          ),
                          TestSemantics(
                            flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                            label: 'item 18b',
                            textDirection: TextDirection.ltr,
                          ),
                        ],
158
                      ),
159
                      TestSemantics(
160
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
161 162 163 164 165 166 167 168 169 170 171 172
                        children: <TestSemantics>[
                          TestSemantics(
                            flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                            label: 'Item 19a',
                            textDirection: TextDirection.ltr,
                          ),
                          TestSemantics(
                            flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                            label: 'item 19b',
                            textDirection: TextDirection.ltr,
                          ),
                        ],
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ),
        ],
      ),
      childOrder: DebugSemanticsDumpOrder.traversalOrder,
      ignoreId: true,
      ignoreTransform: true,
      ignoreRect: true,
    ));

    semantics.dispose();
  });

  testWidgets('Traversal Order of SliverFixedExtentList', (WidgetTester tester) async {
192
    final SemanticsTester semantics = SemanticsTester(tester);
193

194 195
    final List<Widget> listChildren = List<Widget>.generate(30, (int i) {
      return Container(
196
        height: 200.0,
197
        child: Row(
198 199
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
200
            Semantics(
201
              container: true,
202
              child: Text('Item ${i}a'),
203
            ),
204
            Semantics(
205
              container: true,
206
              child: Text('item ${i}b'),
207 208 209 210 211 212
            ),
          ],
        ),
      );
    });
    await tester.pumpWidget(
213
      Semantics(
214
        textDirection: TextDirection.ltr,
215
        child: Directionality(
216
          textDirection: TextDirection.ltr,
217
          child: MediaQuery(
218
            data: const MediaQueryData(),
219 220
            child: CustomScrollView(
              controller: ScrollController(initialScrollOffset: 3000.0),
221
              slivers: <Widget>[
222
                SliverFixedExtentList(
223
                  itemExtent: 200.0,
224
                  delegate: SliverChildListDelegate(listChildren, addSemanticIndexes: false),
225 226 227 228 229 230 231 232 233
                ),
              ],
            ),
          ),
        ),
      ),
    );

    expect(semantics, hasSemantics(
234
      TestSemantics.root(
235
        children: <TestSemantics>[
236
          TestSemantics(
237 238
            textDirection: TextDirection.ltr,
            children: <TestSemantics>[
239
              TestSemantics(
240
                children: <TestSemantics>[
241
                  TestSemantics(
242 243 244
                    flags: <SemanticsFlag>[
                      SemanticsFlag.hasImplicitScrolling,
                    ],
245 246 247 248 249
                    actions: <SemanticsAction>[
                      SemanticsAction.scrollUp,
                      SemanticsAction.scrollDown,
                    ],
                    children: <TestSemantics>[
250
                      TestSemantics(
251 252 253 254
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 13a',
                        textDirection: TextDirection.ltr,
                      ),
255
                      TestSemantics(
256 257 258 259
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'item 13b',
                        textDirection: TextDirection.ltr,
                      ),
260
                      TestSemantics(
261 262 263 264
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 14a',
                        textDirection: TextDirection.ltr,
                      ),
265
                      TestSemantics(
266 267 268 269
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'item 14b',
                        textDirection: TextDirection.ltr,
                      ),
270
                      TestSemantics(
271 272 273
                        label: 'Item 15a',
                        textDirection: TextDirection.ltr,
                      ),
274
                      TestSemantics(
275 276 277
                        label: 'item 15b',
                        textDirection: TextDirection.ltr,
                      ),
278
                      TestSemantics(
279 280 281
                        label: 'Item 16a',
                        textDirection: TextDirection.ltr,
                      ),
282
                      TestSemantics(
283 284 285
                        label: 'item 16b',
                        textDirection: TextDirection.ltr,
                      ),
286
                      TestSemantics(
287 288 289
                        label: 'Item 17a',
                        textDirection: TextDirection.ltr,
                      ),
290
                      TestSemantics(
291 292 293
                        label: 'item 17b',
                        textDirection: TextDirection.ltr,
                      ),
294
                      TestSemantics(
295 296 297 298
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 18a',
                        textDirection: TextDirection.ltr,
                      ),
299
                      TestSemantics(
300 301 302 303
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'item 18b',
                        textDirection: TextDirection.ltr,
                      ),
304
                      TestSemantics(
305 306 307 308
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 19a',
                        textDirection: TextDirection.ltr,
                      ),
309
                      TestSemantics(
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'item 19b',
                        textDirection: TextDirection.ltr,
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ),
        ],
      ),
      childOrder: DebugSemanticsDumpOrder.traversalOrder,
      ignoreId: true,
      ignoreTransform: true,
      ignoreRect: true,
    ));

    semantics.dispose();
  });

  testWidgets('Traversal Order of SliverGrid', (WidgetTester tester) async {
332
    final SemanticsTester semantics = SemanticsTester(tester);
333

334 335
    final List<Widget> listChildren = List<Widget>.generate(30, (int i) {
      return Container(
336
        height: 200.0,
337
        child: Text('Item $i'),
338 339 340
      );
    });
    await tester.pumpWidget(
341
      Semantics(
342
        textDirection: TextDirection.ltr,
343
        child: Directionality(
344
          textDirection: TextDirection.ltr,
345
          child: MediaQuery(
346
            data: const MediaQueryData(),
347 348
            child: CustomScrollView(
              controller: ScrollController(initialScrollOffset: 1600.0),
349
              slivers: <Widget>[
350
                SliverGrid.count(
351 352 353 354 355 356 357 358 359 360 361 362
                  crossAxisCount: 2,
                  crossAxisSpacing: 400.0,
                  children: listChildren,
                ),
              ],
            ),
          ),
        ),
      ),
    );

    expect(semantics, hasSemantics(
363
      TestSemantics.root(
364
        children: <TestSemantics>[
365
          TestSemantics(
366 367
            textDirection: TextDirection.ltr,
            children: <TestSemantics>[
368
              TestSemantics(
369
                children: <TestSemantics>[
370
                  TestSemantics(
371 372 373 374 375 376 377
                    flags: <SemanticsFlag>[
                      SemanticsFlag.hasImplicitScrolling,
                    ],
                    actions: <SemanticsAction>[
                      SemanticsAction.scrollUp,
                      SemanticsAction.scrollDown,
                    ],
378
                    children: <TestSemantics>[
379
                      TestSemantics(
380 381 382 383
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 12',
                        textDirection: TextDirection.ltr,
                      ),
384
                      TestSemantics(
385 386 387 388
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 13',
                        textDirection: TextDirection.ltr,
                      ),
389
                      TestSemantics(
390 391 392 393
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 14',
                        textDirection: TextDirection.ltr,
                      ),
394
                      TestSemantics(
395 396 397 398
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 15',
                        textDirection: TextDirection.ltr,
                      ),
399
                      TestSemantics(
400 401 402
                        label: 'Item 16',
                        textDirection: TextDirection.ltr,
                      ),
403
                      TestSemantics(
404 405 406
                        label: 'Item 17',
                        textDirection: TextDirection.ltr,
                      ),
407
                      TestSemantics(
408 409 410
                        label: 'Item 18',
                        textDirection: TextDirection.ltr,
                      ),
411
                      TestSemantics(
412 413 414
                        label: 'Item 19',
                        textDirection: TextDirection.ltr,
                      ),
415
                      TestSemantics(
416 417 418
                        label: 'Item 20',
                        textDirection: TextDirection.ltr,
                      ),
419
                      TestSemantics(
420 421 422
                        label: 'Item 21',
                        textDirection: TextDirection.ltr,
                      ),
423
                      TestSemantics(
424 425 426 427
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 22',
                        textDirection: TextDirection.ltr,
                      ),
428
                      TestSemantics(
429 430 431 432
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 23',
                        textDirection: TextDirection.ltr,
                      ),
433
                      TestSemantics(
434 435 436 437
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 24',
                        textDirection: TextDirection.ltr,
                      ),
438
                      TestSemantics(
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 25',
                        textDirection: TextDirection.ltr,
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ),
        ],
      ),
      childOrder: DebugSemanticsDumpOrder.traversalOrder,
      ignoreId: true,
      ignoreTransform: true,
      ignoreRect: true,
    ));

    semantics.dispose();
  });

  testWidgets('Traversal Order of List of individual slivers', (WidgetTester tester) async {
461
    final SemanticsTester semantics = SemanticsTester(tester);
462

463 464 465
    final List<Widget> listChildren = List<Widget>.generate(30, (int i) {
      return SliverToBoxAdapter(
        child: Container(
466
          height: 200.0,
467
          child: Row(
468 469
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
470
              Semantics(
471
                container: true,
472
                child: Text('Item ${i}a'),
473
              ),
474
              Semantics(
475
                container: true,
476
                child: Text('item ${i}b'),
477 478 479 480 481 482 483
              ),
            ],
          ),
        ),
      );
    });
    await tester.pumpWidget(
484
      Semantics(
485
        textDirection: TextDirection.ltr,
486
        child: Directionality(
487
          textDirection: TextDirection.ltr,
488
          child: MediaQuery(
489
            data: const MediaQueryData(),
490 491
            child: CustomScrollView(
              controller: ScrollController(initialScrollOffset: 3000.0),
492 493 494 495 496 497 498 499
              slivers: listChildren,
            ),
          ),
        ),
      ),
    );

    expect(semantics, hasSemantics(
500
      TestSemantics.root(
501
        children: <TestSemantics>[
502
          TestSemantics(
503 504
            textDirection: TextDirection.ltr,
            children: <TestSemantics>[
505
              TestSemantics(
506
                children: <TestSemantics>[
507
                  TestSemantics(
508 509 510
                    flags: <SemanticsFlag>[
                      SemanticsFlag.hasImplicitScrolling,
                    ],
511 512 513 514 515
                    actions: <SemanticsAction>[
                      SemanticsAction.scrollUp,
                      SemanticsAction.scrollDown,
                    ],
                    children: <TestSemantics>[
516
                      TestSemantics(
517 518 519 520
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 13a',
                        textDirection: TextDirection.ltr,
                      ),
521
                      TestSemantics(
522 523 524 525
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'item 13b',
                        textDirection: TextDirection.ltr,
                      ),
526
                      TestSemantics(
527 528 529 530
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 14a',
                        textDirection: TextDirection.ltr,
                      ),
531
                      TestSemantics(
532 533 534 535
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'item 14b',
                        textDirection: TextDirection.ltr,
                      ),
536
                      TestSemantics(
537 538 539
                        label: 'Item 15a',
                        textDirection: TextDirection.ltr,
                      ),
540
                      TestSemantics(
541 542 543
                        label: 'item 15b',
                        textDirection: TextDirection.ltr,
                      ),
544
                      TestSemantics(
545 546 547
                        label: 'Item 16a',
                        textDirection: TextDirection.ltr,
                      ),
548
                      TestSemantics(
549 550 551
                        label: 'item 16b',
                        textDirection: TextDirection.ltr,
                      ),
552
                      TestSemantics(
553 554 555
                        label: 'Item 17a',
                        textDirection: TextDirection.ltr,
                      ),
556
                      TestSemantics(
557 558 559
                        label: 'item 17b',
                        textDirection: TextDirection.ltr,
                      ),
560
                      TestSemantics(
561 562 563 564
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 18a',
                        textDirection: TextDirection.ltr,
                      ),
565
                      TestSemantics(
566 567 568 569
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'item 18b',
                        textDirection: TextDirection.ltr,
                      ),
570
                      TestSemantics(
571 572 573 574
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'Item 19a',
                        textDirection: TextDirection.ltr,
                      ),
575
                      TestSemantics(
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: 'item 19b',
                        textDirection: TextDirection.ltr,
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ),
        ],
      ),
      childOrder: DebugSemanticsDumpOrder.traversalOrder,
      ignoreId: true,
      ignoreTransform: true,
      ignoreRect: true,
    ));

    semantics.dispose();
  });

  testWidgets('Traversal Order of in a SingleChildScrollView', (WidgetTester tester) async {
598
    final SemanticsTester semantics = SemanticsTester(tester);
599

600 601
    final List<Widget> listChildren = List<Widget>.generate(30, (int i) {
      return Container(
602
        height: 200.0,
603
        child: Row(
604 605
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
606
            Semantics(
607
              container: true,
608
              child: Text('Item ${i}a'),
609
            ),
610
            Semantics(
611
              container: true,
612
              child: Text('item ${i}b'),
613 614 615 616 617 618
            ),
          ],
        ),
      );
    });
    await tester.pumpWidget(
619
      Semantics(
620
        textDirection: TextDirection.ltr,
621
        child: Directionality(
622
          textDirection: TextDirection.ltr,
623
          child: MediaQuery(
624
            data: const MediaQueryData(),
625 626 627
            child: SingleChildScrollView(
              controller: ScrollController(initialScrollOffset: 3000.0),
              child: Column(
628 629 630 631 632 633 634 635 636
                children: listChildren,
              ),
            ),
          ),
        ),
      ),
    );

    expect(semantics, hasSemantics(
637
      TestSemantics.root(
638
        children: <TestSemantics>[
639
          TestSemantics(
640 641
            textDirection: TextDirection.ltr,
            children: <TestSemantics>[
642
              TestSemantics(
643 644 645
                flags: <SemanticsFlag>[
                  SemanticsFlag.hasImplicitScrolling,
                ],
646 647 648 649 650
                actions: <SemanticsAction>[
                  SemanticsAction.scrollUp,
                  SemanticsAction.scrollDown,
                ],
                children: <TestSemantics>[
651
                  TestSemantics(
652 653 654 655
                    flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                    label: 'Item 13a',
                    textDirection: TextDirection.ltr,
                  ),
656
                  TestSemantics(
657 658 659 660
                    flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                    label: 'item 13b',
                    textDirection: TextDirection.ltr,
                  ),
661
                  TestSemantics(
662 663 664 665
                    flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                    label: 'Item 14a',
                    textDirection: TextDirection.ltr,
                  ),
666
                  TestSemantics(
667 668 669 670
                    flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                    label: 'item 14b',
                    textDirection: TextDirection.ltr,
                  ),
671
                  TestSemantics(
672 673 674
                    label: 'Item 15a',
                    textDirection: TextDirection.ltr,
                  ),
675
                  TestSemantics(
676 677 678
                    label: 'item 15b',
                    textDirection: TextDirection.ltr,
                  ),
679
                  TestSemantics(
680 681 682
                    label: 'Item 16a',
                    textDirection: TextDirection.ltr,
                  ),
683
                  TestSemantics(
684 685 686
                    label: 'item 16b',
                    textDirection: TextDirection.ltr,
                  ),
687
                  TestSemantics(
688 689 690
                    label: 'Item 17a',
                    textDirection: TextDirection.ltr,
                  ),
691
                  TestSemantics(
692 693 694
                    label: 'item 17b',
                    textDirection: TextDirection.ltr,
                  ),
695
                  TestSemantics(
696 697 698 699
                    flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                    label: 'Item 18a',
                    textDirection: TextDirection.ltr,
                  ),
700
                  TestSemantics(
701 702 703 704
                    flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                    label: 'item 18b',
                    textDirection: TextDirection.ltr,
                  ),
705
                  TestSemantics(
706 707 708 709
                    flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                    label: 'Item 19a',
                    textDirection: TextDirection.ltr,
                  ),
710
                  TestSemantics(
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
                    flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                    label: 'item 19b',
                    textDirection: TextDirection.ltr,
                  ),
                ],
              ),
            ],
          ),
        ],
      ),
      childOrder: DebugSemanticsDumpOrder.traversalOrder,
      ignoreId: true,
      ignoreTransform: true,
      ignoreRect: true,
    ));

    semantics.dispose();
  });

  testWidgets('Traversal Order with center child', (WidgetTester tester) async {
731
    final SemanticsTester semantics = SemanticsTester(tester);
732

733
    await tester.pumpWidget(Semantics(
734
      textDirection: TextDirection.ltr,
735
      child: Directionality(
736
        textDirection: TextDirection.ltr,
737
        child: MediaQuery(
738
          data: const MediaQueryData(),
739
          child: Scrollable(
740
            viewportBuilder: (BuildContext context, ViewportOffset offset) {
741
              return Viewport(
742 743
                offset: offset,
                center: const ValueKey<int>(0),
744
                slivers: List<Widget>.generate(30, (int i) {
745
                  final int item = i - 15;
746 747 748
                  return SliverToBoxAdapter(
                    key: ValueKey<int>(item),
                    child: Container(
749
                      height: 200.0,
750
                      child: Row(
751 752
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: <Widget>[
753
                          Semantics(
754
                            container: true,
755
                            child: Text('${item}a'),
756
                          ),
757
                          Semantics(
758
                            container: true,
759
                            child: Text('${item}b'),
760 761 762 763 764 765 766 767 768 769 770 771 772 773
                          ),
                        ],
                      ),
                    ),
                  );
                }),
              );
            },
          ),
        ),
      ),
    ));

    expect(semantics, hasSemantics(
774
      TestSemantics.root(
775
        children: <TestSemantics>[
776
          TestSemantics(
777 778
            textDirection: TextDirection.ltr,
            children: <TestSemantics>[
779
              TestSemantics(
780
                children: <TestSemantics>[
781
                  TestSemantics(
782 783 784
                    flags: <SemanticsFlag>[
                      SemanticsFlag.hasImplicitScrolling,
                    ],
785 786 787 788 789
                    actions: <SemanticsAction>[
                      SemanticsAction.scrollUp,
                      SemanticsAction.scrollDown,
                    ],
                    children: <TestSemantics>[
790
                      TestSemantics(
791 792 793 794
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: '-2a',
                        textDirection: TextDirection.ltr,
                      ),
795
                      TestSemantics(
796 797 798 799
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: '-2b',
                        textDirection: TextDirection.ltr,
                      ),
800
                      TestSemantics(
801 802 803 804
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: '-1a',
                        textDirection: TextDirection.ltr,
                      ),
805
                      TestSemantics(
806 807 808 809
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: '-1b',
                        textDirection: TextDirection.ltr,
                      ),
810
                      TestSemantics(
811 812 813
                        label: '0a',
                        textDirection: TextDirection.ltr,
                      ),
814
                      TestSemantics(
815 816 817
                        label: '0b',
                        textDirection: TextDirection.ltr,
                      ),
818
                      TestSemantics(
819 820 821
                        label: '1a',
                        textDirection: TextDirection.ltr,
                      ),
822
                      TestSemantics(
823 824 825
                        label: '1b',
                        textDirection: TextDirection.ltr,
                      ),
826
                      TestSemantics(
827 828 829
                        label: '2a',
                        textDirection: TextDirection.ltr,
                      ),
830
                      TestSemantics(
831 832 833
                        label: '2b',
                        textDirection: TextDirection.ltr,
                      ),
834
                      TestSemantics(
835 836 837 838
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: '3a',
                        textDirection: TextDirection.ltr,
                      ),
839
                      TestSemantics(
840 841 842 843
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: '3b',
                        textDirection: TextDirection.ltr,
                      ),
844
                      TestSemantics(
845 846 847 848
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: '4a',
                        textDirection: TextDirection.ltr,
                      ),
849
                      TestSemantics(
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
                        flags: <SemanticsFlag>[SemanticsFlag.isHidden],
                        label: '4b',
                        textDirection: TextDirection.ltr,
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ),
        ],
      ),
      ignoreRect: true,
      ignoreTransform: true,
      ignoreId: true,
    ));

    semantics.dispose();

  });
}