accessibility_test.dart 29.8 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
import 'package:flutter/gestures.dart';
6 7 8 9 10
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  group('text contrast guideline', () {
11 12
    testWidgets('black text on white background - Text Widget - direct style',
        (WidgetTester tester) async {
13
      final SemanticsHandle handle = tester.ensureSemantics();
14 15 16 17 18 19
      await tester.pumpWidget(
        _boilerplate(
          const Text(
            'this is a test',
            style: TextStyle(fontSize: 14.0, color: Colors.black),
          ),
20
        ),
21
      );
22 23 24 25
      await expectLater(tester, meetsGuideline(textContrastGuideline));
      handle.dispose();
    });

26 27 28 29
    testWidgets('Multiple text with same label', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(
        _boilerplate(
30 31
          const Column(
            children: <Widget>[
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
              Text(
                'this is a test',
                style: TextStyle(fontSize: 14.0, color: Colors.black),
              ),
              Text(
                'this is a test',
                style: TextStyle(fontSize: 14.0, color: Colors.black),
              ),
            ],
          ),
        ),
      );
      await expectLater(tester, meetsGuideline(textContrastGuideline));
      handle.dispose();
    });

    testWidgets(
      'Multiple text with same label but Nodes excluded from '
      'semantic tree have failing contrast should pass a11y guideline ',
      (WidgetTester tester) async {
        final SemanticsHandle handle = tester.ensureSemantics();
        await tester.pumpWidget(
          _boilerplate(
55 56
            const Column(
              children: <Widget>[
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
                Text(
                  'this is a test',
                  style: TextStyle(fontSize: 14.0, color: Colors.black),
                ),
                SizedBox(height: 50),
                Text(
                  'this is a test',
                  style: TextStyle(fontSize: 14.0, color: Colors.black),
                ),
                SizedBox(height: 50),
                ExcludeSemantics(
                  child: Text(
                    'this is a test',
                    style: TextStyle(fontSize: 14.0, color: Colors.white),
                  ),
                ),
              ],
            ),
          ),
        );
        await expectLater(tester, meetsGuideline(textContrastGuideline));
        handle.dispose();
    });

81 82
    testWidgets('white text on black background - Text Widget - direct style',
        (WidgetTester tester) async {
83
      final SemanticsHandle handle = tester.ensureSemantics();
84 85 86 87 88 89 90 91 92 93
      await tester.pumpWidget(
        _boilerplate(
          Container(
            width: 200.0,
            height: 200.0,
            color: Colors.black,
            child: const Text(
              'this is a test',
              style: TextStyle(fontSize: 14.0, color: Colors.white),
            ),
94 95
          ),
        ),
96
      );
97 98 99 100
      await expectLater(tester, meetsGuideline(textContrastGuideline));
      handle.dispose();
    });

101 102 103 104 105 106 107 108 109
    testWidgets('White text on white background fails contrast test',
      (WidgetTester tester) async {
    final SemanticsHandle handle = tester.ensureSemantics();
    await tester.pumpWidget(
      _boilerplate(
        Container(
          width: 200.0,
          height: 300.0,
          color: Colors.white,
110 111
          child: const Column(
            children: <Widget>[
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
              Text(
                'this is a white text',
                style: TextStyle(fontSize: 14.0, color: Colors.white),
              ),
              SizedBox(height: 50),
              Text(
                'this is a black text test1',
                style: TextStyle(fontSize: 14.0, color: Colors.black),
              ),
              SizedBox(height: 50),
              Text(
                'this is a black text test2',
                style: TextStyle(fontSize: 14.0, color: Colors.black),
              ),
            ],
          ),
        ),
      ),
    );
    await expectLater(tester, doesNotMeetGuideline(textContrastGuideline));
    handle.dispose();
  });

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
    const Color surface = Color(0xFFF0F0F0);

    /// Shades of blue with contrast ratio of 2.9, 4.4, 4.5 from [surface].
    const Color blue29 = Color(0xFF7E7EFB);
    const Color blue44 = Color(0xFF5757FF);
    const Color blue45 = Color(0xFF5252FF);
    const List<TextStyle> textStylesMeetingGuideline = <TextStyle>[
      TextStyle(color: blue44, backgroundColor: surface, fontSize: 18),
      TextStyle(color: blue44, backgroundColor: surface, fontSize: 14, fontWeight: FontWeight.bold),
      TextStyle(color: blue45, backgroundColor: surface),
    ];
    const List<TextStyle> textStylesDoesNotMeetingGuideline = <TextStyle>[
      TextStyle(color: blue44, backgroundColor: surface),
      TextStyle(color: blue29, backgroundColor: surface, fontSize: 18),
    ];

151
    Widget appWithTextWidget(TextStyle style) => _boilerplate(
152 153 154 155 156 157
      Text('this is text', style: style.copyWith(height: 30.0)),
    );

    for (final TextStyle style in textStylesMeetingGuideline) {
      testWidgets('text with style $style', (WidgetTester tester) async {
        final SemanticsHandle handle = tester.ensureSemantics();
158
        await tester.pumpWidget(appWithTextWidget(style));
159 160 161 162 163 164 165 166
        await expectLater(tester, meetsGuideline(textContrastGuideline));
        handle.dispose();
      });
    }

    for (final TextStyle style in textStylesDoesNotMeetingGuideline) {
      testWidgets('text with $style', (WidgetTester tester) async {
        final SemanticsHandle handle = tester.ensureSemantics();
167
        await tester.pumpWidget(appWithTextWidget(style));
168 169 170 171 172 173 174
        await expectLater(tester, doesNotMeetGuideline(textContrastGuideline));
        handle.dispose();
      });
    }

    testWidgets('black text on white background - Text Widget - direct style',
        (WidgetTester tester) async {
175
      final SemanticsHandle handle = tester.ensureSemantics();
176 177 178 179 180
      await tester.pumpWidget(
        _boilerplate(
          const Text(
            'this is a test',
            style: TextStyle(fontSize: 14.0, color: Colors.black),
181 182
          ),
        ),
183
      );
184 185 186 187
      await expectLater(tester, meetsGuideline(textContrastGuideline));
      handle.dispose();
    });

188 189
    testWidgets('white text on black background - Text Widget - direct style',
        (WidgetTester tester) async {
190
      final SemanticsHandle handle = tester.ensureSemantics();
191 192 193
      await tester.pumpWidget(
        _boilerplate(
          Container(
194 195 196
            width: 200.0,
            height: 200.0,
            color: Colors.black,
197 198 199 200
            child: const Text(
              'this is a test',
              style: TextStyle(fontSize: 14.0, color: Colors.white),
            ),
201 202
          ),
        ),
203
      );
204 205 206 207
      await expectLater(tester, meetsGuideline(textContrastGuideline));
      handle.dispose();
    });

208 209
    testWidgets('Material text field - amber on amber',
        (WidgetTester tester) async {
210
      final SemanticsHandle handle = tester.ensureSemantics();
211 212 213
      await tester.pumpWidget(
        _boilerplate(
          Container(
214 215 216
            width: 200.0,
            height: 200.0,
            color: Colors.amberAccent,
217
            child: TextField(
218
              style: const TextStyle(color: Colors.amber),
219
              controller: TextEditingController(text: 'this is a test'),
220 221 222
            ),
          ),
        ),
223
      );
224 225 226 227
      await expectLater(tester, doesNotMeetGuideline(textContrastGuideline));
      handle.dispose();
    });

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
    testWidgets('Correctly identify failures in complex transforms', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(
        _boilerplate(
          Padding(
            padding: const EdgeInsets.only(left: 100),
            child: Semantics(
              container: true,
              child: Padding(
                padding: const EdgeInsets.only(left: 100),
                child: Semantics(
                  container: true,
                  child: Container(
                    width: 100.0,
                    height: 200.0,
                    color: Colors.amberAccent,
                    child: const Text(
                      'this',
                      style: TextStyle(color: Colors.amber),
                    ),
                  ),
                ),
              ),
            ),
          ),
        ),
      );
      await expectLater(tester, doesNotMeetGuideline(textContrastGuideline));
      handle.dispose();
    });

259 260
    testWidgets('Material text field - default style',
        (WidgetTester tester) async {
261
      final SemanticsHandle handle = tester.ensureSemantics();
262 263 264 265 266 267
      await tester.pumpWidget(
        _boilerplate(
          SizedBox(
            width: 100,
            child: TextField(
              controller: TextEditingController(text: 'this is a test'),
268 269 270 271
            ),
          ),
        ),
      );
272
      await tester.idle();
273 274 275 276
      await expectLater(tester, meetsGuideline(textContrastGuideline));
      handle.dispose();
    });

277 278
    testWidgets('yellow text on yellow background fails with correct message',
        (WidgetTester tester) async {
279
      final SemanticsHandle handle = tester.ensureSemantics();
280 281 282 283 284 285 286 287 288 289
      await tester.pumpWidget(
        _boilerplate(
          Container(
            width: 200.0,
            height: 200.0,
            color: Colors.yellow,
            child: const Text(
              'this is a test',
              style: TextStyle(fontSize: 14.0, color: Colors.yellowAccent),
            ),
290 291
          ),
        ),
292
      );
293 294
      final Evaluation result = await textContrastGuideline.evaluate(tester);
      expect(result.passed, false);
295 296 297 298 299 300 301 302 303 304
      expect(
        result.reason,
        'SemanticsNode#4(Rect.fromLTRB(300.0, 200.0, 500.0, 400.0), '
        'label: "this is a test", textDirection: ltr):\n'
        'Expected contrast ratio of at least 4.5 but found 1.17 for a font '
        'size of 14.0.\n'
        'The computed colors was:\n'
        'light - Color(0xfffafafa), dark - Color(0xffffeb3b)\n'
         'See also: https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html',
      );
305 306
      handle.dispose();
    });
307

308 309
    testWidgets('label without corresponding text is skipped',
        (WidgetTester tester) async {
310
      final SemanticsHandle handle = tester.ensureSemantics();
311 312 313 314 315 316 317 318 319 320
      await tester.pumpWidget(
        _boilerplate(
          Semantics(
            label: 'This is not text',
            container: true,
            child: const SizedBox(
              width: 200.0,
              height: 200.0,
              child: Placeholder(),
            ),
321 322
          ),
        ),
323
      );
324 325 326 327 328 329 330 331

      final Evaluation result = await textContrastGuideline.evaluate(tester);
      expect(result.passed, true);
      handle.dispose();
    });

    testWidgets('offscreen text is skipped', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
332 333 334 335 336 337 338 339 340 341 342 343 344 345
      await tester.pumpWidget(
        _boilerplate(
          Stack(
            children: <Widget>[
              Positioned(
                left: -300.0,
                child: Container(
                  width: 200.0,
                  height: 200.0,
                  color: Colors.yellow,
                  child: const Text(
                    'this is a test',
                    style: TextStyle(fontSize: 14.0, color: Colors.yellowAccent),
                  ),
346 347
                ),
              ),
348 349 350 351
            ],
          ),
        ),
      );
352 353 354 355 356

      final Evaluation result = await textContrastGuideline.evaluate(tester);
      expect(result.passed, true);
      handle.dispose();
    });
357

358 359
    testWidgets('Disabled button is excluded from text contrast guideline',
        (WidgetTester tester) async {
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
      // Regression test https://github.com/flutter/flutter/issues/94428
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(
        _boilerplate(
          ElevatedButton(
            onPressed: null,
            child: Container(
              width: 200.0,
              height: 200.0,
              color: Colors.yellow,
              child: const Text(
                'this is a test',
                style: TextStyle(fontSize: 14.0, color: Colors.yellowAccent),
              ),
            ),
          ),
376
        ),
377 378 379 380
      );
      await expectLater(tester, meetsGuideline(textContrastGuideline));
      handle.dispose();
    });
381 382
  });

383
  group('custom minimum contrast guideline', () {
384
    Widget iconWidget({
385 386 387 388
      IconData icon = Icons.search,
      required Color color,
      required Color background,
    }) {
389 390 391 392 393 394 395
      return Container(
        padding: const EdgeInsets.all(8.0),
        color: background,
        child: Icon(icon, color: color),
      );
    }

396
    Widget textWidget({
397 398 399 400
      String text = 'Text',
      required Color color,
      required Color background,
    }) {
401 402 403 404 405 406 407
      return Container(
        padding: const EdgeInsets.all(8.0),
        color: background,
        child: Text(text, style: TextStyle(color: color)),
      );
    }

408
    Widget rowWidget(List<Widget> widgets) => _boilerplate(Row(children: widgets));
409

410 411 412
    final Finder findIcons = find.byWidgetPredicate((Widget widget) => widget is Icon);
    final Finder findTexts = find.byWidgetPredicate((Widget widget) => widget is Text);
    final Finder findIconsAndTexts = find.byWidgetPredicate((Widget widget) => widget is Icon || widget is Text);
413 414

    testWidgets('Black icons on white background', (WidgetTester tester) async {
415 416 417
      await tester.pumpWidget(rowWidget(<Widget>[
        iconWidget(color: Colors.black, background: Colors.white),
        iconWidget(color: Colors.black, background: Colors.white),
418 419
      ]));

420 421 422 423
      await expectLater(
        tester,
        meetsGuideline(CustomMinimumContrastGuideline(finder: findIcons)),
      );
424 425 426
    });

    testWidgets('Black icons on black background', (WidgetTester tester) async {
427 428 429
      await tester.pumpWidget(rowWidget(<Widget>[
        iconWidget(color: Colors.black, background: Colors.black),
        iconWidget(color: Colors.black, background: Colors.black),
430 431
      ]));

432 433 434 435
      await expectLater(
        tester,
        doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: findIcons)),
      );
436 437
    });

438 439
    testWidgets('White icons on black background ("dark mode")',
        (WidgetTester tester) async {
440 441 442
      await tester.pumpWidget(rowWidget(<Widget>[
        iconWidget(color: Colors.white, background: Colors.black),
        iconWidget(color: Colors.white, background: Colors.black),
443 444
      ]));

445 446 447 448
      await expectLater(
        tester,
        meetsGuideline(CustomMinimumContrastGuideline(finder: findIcons)),
      );
449 450 451
    });

    testWidgets('Using different icons', (WidgetTester tester) async {
452 453 454 455 456
      await tester.pumpWidget(rowWidget(<Widget>[
        iconWidget(color: Colors.black, background: Colors.white, icon: Icons.more_horiz),
        iconWidget(color: Colors.black, background: Colors.white, icon: Icons.description),
        iconWidget(color: Colors.black, background: Colors.white, icon: Icons.image),
        iconWidget(color: Colors.black, background: Colors.white, icon: Icons.beach_access),
457 458
      ]));

459 460 461 462
      await expectLater(
        tester,
        meetsGuideline(CustomMinimumContrastGuideline(finder: findIcons)),
      );
463 464
    });

465 466
    testWidgets('One invalid instance fails entire test',
        (WidgetTester tester) async {
467 468 469
      await tester.pumpWidget(rowWidget(<Widget>[
        iconWidget(color: Colors.black, background: Colors.white),
        iconWidget(color: Colors.black, background: Colors.black),
470 471
      ]));

472 473 474 475
      await expectLater(
        tester,
        doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: findIcons)),
      );
476 477
    });

478 479
    testWidgets('White on different colors, passing',
        (WidgetTester tester) async {
480 481 482 483 484
      await tester.pumpWidget(rowWidget(<Widget>[
        iconWidget(color: Colors.white, background: Colors.red[800]!, icon: Icons.more_horiz),
        iconWidget(color: Colors.white, background: Colors.green[800]!, icon: Icons.description),
        iconWidget(color: Colors.white, background: Colors.blue[800]!, icon: Icons.image),
        iconWidget(color: Colors.white, background: Colors.purple[800]!, icon: Icons.beach_access),
485 486
      ]));

487 488
      await expectLater(tester,
          meetsGuideline(CustomMinimumContrastGuideline(finder: findIcons)));
489 490
    });

491 492
    testWidgets('White on different colors, failing',
        (WidgetTester tester) async {
493 494 495 496 497
      await tester.pumpWidget(rowWidget(<Widget>[
        iconWidget(color: Colors.white, background: Colors.red[200]!, icon: Icons.more_horiz),
        iconWidget(color: Colors.white, background: Colors.green[400]!, icon: Icons.description),
        iconWidget(color: Colors.white, background: Colors.blue[600]!, icon: Icons.image),
        iconWidget(color: Colors.white, background: Colors.purple[800]!, icon: Icons.beach_access),
498 499
      ]));

500 501 502 503
      await expectLater(
        tester,
        doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: findIcons)),
      );
504 505 506
    });

    testWidgets('Absence of icons, passing', (WidgetTester tester) async {
507
      await tester.pumpWidget(rowWidget(<Widget>[]));
508

509 510 511 512
      await expectLater(
        tester,
        meetsGuideline(CustomMinimumContrastGuideline(finder: findIcons)),
      );
513 514
    });

515 516
    testWidgets('Absence of icons, passing - 2nd test',
        (WidgetTester tester) async {
517 518 519
      await tester.pumpWidget(rowWidget(<Widget>[
        textWidget(color: Colors.black, background: Colors.white),
        textWidget(color: Colors.black, background: Colors.black),
520 521
      ]));

522 523 524 525
      await expectLater(
        tester,
        meetsGuideline(CustomMinimumContrastGuideline(finder: findIcons)),
      );
526 527
    });

528 529
    testWidgets('Guideline ignores widgets of other types',
        (WidgetTester tester) async {
530 531 532 533 534
      await tester.pumpWidget(rowWidget(<Widget>[
        iconWidget(color: Colors.black, background: Colors.white),
        iconWidget(color: Colors.black, background: Colors.white),
        textWidget(color: Colors.black, background: Colors.white),
        textWidget(color: Colors.black, background: Colors.black),
535 536
      ]));

537 538 539 540 541 542 543 544 545 546 547 548
      await expectLater(
        tester,
        meetsGuideline(CustomMinimumContrastGuideline(finder: findIcons)),
      );
      await expectLater(
        tester,
        doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: findTexts)),
      );
      await expectLater(
        tester,
        doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: findIconsAndTexts)),
      );
549 550 551
    });

    testWidgets('Custom minimum ratio - Icons', (WidgetTester tester) async {
552 553 554
      await tester.pumpWidget(rowWidget(<Widget>[
        iconWidget(color: Colors.blue, background: Colors.white),
        iconWidget(color: Colors.black, background: Colors.white),
555 556
      ]));

557 558 559 560 561 562 563 564
      await expectLater(
        tester,
        doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: findIcons)),
      );
      await expectLater(
        tester,
        meetsGuideline(CustomMinimumContrastGuideline(finder: findIcons, minimumRatio: 3.0)),
      );
565 566 567
    });

    testWidgets('Custom minimum ratio - Texts', (WidgetTester tester) async {
568 569 570
      await tester.pumpWidget(rowWidget(<Widget>[
        textWidget(color: Colors.blue, background: Colors.white),
        textWidget(color: Colors.black, background: Colors.white),
571 572
      ]));

573 574 575 576 577 578 579 580
      await expectLater(
        tester,
        doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: findTexts)),
      );
      await expectLater(
        tester,
        meetsGuideline(CustomMinimumContrastGuideline(finder: findTexts, minimumRatio: 3.0)),
      );
581 582
    });

583 584 585
    testWidgets(
        'Custom minimum ratio - Different standards for icons and texts',
        (WidgetTester tester) async {
586 587 588 589 590
      await tester.pumpWidget(rowWidget(<Widget>[
        iconWidget(color: Colors.blue, background: Colors.white),
        iconWidget(color: Colors.black, background: Colors.white),
        textWidget(color: Colors.blue, background: Colors.white),
        textWidget(color: Colors.black, background: Colors.white),
591 592
      ]));

593 594 595 596 597 598 599 600
      await expectLater(
        tester,
        doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: findIcons)),
      );
      await expectLater(
        tester,
        meetsGuideline(CustomMinimumContrastGuideline(finder: findTexts, minimumRatio: 3.0)),
      );
601 602 603
    });
  });

604 605 606 607
  group('tap target size guideline', () {
    testWidgets('Tappable box at 48 by 48', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
608
        SizedBox(
609 610
          width: 48.0,
          height: 48.0,
611
          child: GestureDetector(onTap: () {}),
612 613 614 615 616 617 618 619 620
        ),
      ));
      await expectLater(tester, meetsGuideline(androidTapTargetGuideline));
      handle.dispose();
    });

    testWidgets('Tappable box at 47 by 48', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
621
        SizedBox(
622 623
          width: 47.0,
          height: 48.0,
624
          child: GestureDetector(onTap: () {}),
625 626
        ),
      ));
627 628 629 630
      await expectLater(
        tester,
        doesNotMeetGuideline(androidTapTargetGuideline),
      );
631 632 633 634 635 636
      handle.dispose();
    });

    testWidgets('Tappable box at 48 by 47', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
637
        SizedBox(
638 639
          width: 48.0,
          height: 47.0,
640
          child: GestureDetector(onTap: () {}),
641 642
        ),
      ));
643 644 645 646
      await expectLater(
        tester,
        doesNotMeetGuideline(androidTapTargetGuideline),
      );
647 648 649
      handle.dispose();
    });

650 651
    testWidgets('Tappable box at 48 by 48 shrunk by transform',
        (WidgetTester tester) async {
652 653
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
654
        Transform.scale(
655
          scale: 0.5, // should have new height of 24 by 24.
656
          child: SizedBox(
657 658
            width: 48.0,
            height: 48.0,
659
            child: GestureDetector(onTap: () {}),
660 661 662
          ),
        ),
      ));
663 664 665 666
      await expectLater(
        tester,
        doesNotMeetGuideline(androidTapTargetGuideline),
      );
667 668 669
      handle.dispose();
    });

670 671
    testWidgets('Too small tap target fails with the correct message',
        (WidgetTester tester) async {
672 673
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(
674
        SizedBox(
675 676
          width: 48.0,
          height: 47.0,
677
          child: GestureDetector(onTap: () {}),
678 679 680 681
        ),
      ));
      final Evaluation result = await androidTapTargetGuideline.evaluate(tester);
      expect(result.passed, false);
682 683 684 685 686 687 688 689
      expect(
        result.reason,
        'SemanticsNode#4(Rect.fromLTRB(376.0, 276.5, 424.0, 323.5), '
        'actions: [tap]): expected tap '
        'target size of at least Size(48.0, 48.0), '
        'but found Size(48.0, 47.0)\n'
        'See also: https://support.google.com/accessibility/android/answer/7101858?hl=en',
      );
690 691
      handle.dispose();
    });
692

693 694
    testWidgets('Box that overlaps edge of window is skipped',
        (WidgetTester tester) async {
695
      final SemanticsHandle handle = tester.ensureSemantics();
696
      final Widget smallBox = SizedBox(
697 698
        width: 48.0,
        height: 47.0,
699
        child: GestureDetector(onTap: () {}),
700 701
      );
      await tester.pumpWidget(
702 703
        MaterialApp(
          home: Stack(
704
            children: <Widget>[
705
              Positioned(
706 707 708 709 710 711 712 713 714 715 716 717 718
                left: 0.0,
                top: -1.0,
                child: smallBox,
              ),
            ],
          ),
        ),
      );

      final Evaluation overlappingTopResult = await androidTapTargetGuideline.evaluate(tester);
      expect(overlappingTopResult.passed, true);

      await tester.pumpWidget(
719 720
        MaterialApp(
          home: Stack(
721
            children: <Widget>[
722
              Positioned(
723 724 725 726 727 728 729 730 731 732 733 734 735
                left: -1.0,
                top: 0.0,
                child: smallBox,
              ),
            ],
          ),
        ),
      );

      final Evaluation overlappingLeftResult = await androidTapTargetGuideline.evaluate(tester);
      expect(overlappingLeftResult.passed, true);

      await tester.pumpWidget(
736 737
        MaterialApp(
          home: Stack(
738
            children: <Widget>[
739
              Positioned(
740 741 742 743 744 745 746 747 748 749 750 751
                bottom: -1.0,
                child: smallBox,
              ),
            ],
          ),
        ),
      );

      final Evaluation overlappingBottomResult = await androidTapTargetGuideline.evaluate(tester);
      expect(overlappingBottomResult.passed, true);

      await tester.pumpWidget(
752 753
        MaterialApp(
          home: Stack(
754
            children: <Widget>[
755
              Positioned(
756 757 758 759 760 761 762 763 764 765 766 767 768
                right: -1.0,
                child: smallBox,
              ),
            ],
          ),
        ),
      );

      final Evaluation overlappingRightResult = await androidTapTargetGuideline.evaluate(tester);
      expect(overlappingRightResult.passed, true);
      handle.dispose();
    });

769 770
    testWidgets('Does not fail on mergedIntoParent child',
        (WidgetTester tester) async {
771
      final SemanticsHandle handle = tester.ensureSemantics();
772 773 774 775 776 777 778 779 780 781 782
      await tester.pumpWidget(_boilerplate(MergeSemantics(
        child: Semantics(
          container: true,
          child: SizedBox(
            width: 50.0,
            height: 50.0,
            child: Semantics(
              container: true,
              child: GestureDetector(
                onTap: () {},
                child: const SizedBox(width: 4.0, height: 4.0),
783
              ),
784
            ),
785
          ),
786 787
        ),
      )));
788 789 790 791 792

      final Evaluation overlappingRightResult = await androidTapTargetGuideline.evaluate(tester);
      expect(overlappingRightResult.passed, true);
      handle.dispose();
    });
793 794 795 796 797 798 799 800

    testWidgets('Does not fail on links', (WidgetTester tester) async {
      Widget textWithLink() {
        return Builder(
          builder: (BuildContext context) {
            return RichText(
              text: TextSpan(
                children: <InlineSpan>[
801
                  const TextSpan(text: 'See examples at '),
802 803
                  TextSpan(
                    text: 'flutter repo',
804
                    recognizer: TapGestureRecognizer()..onTap = () {},
805 806 807 808 809 810 811 812 813 814 815 816 817 818
                  ),
                ],
              ),
            );
          },
        );
      }

      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(textWithLink()));

      await expectLater(tester, meetsGuideline(androidTapTargetGuideline));
      handle.dispose();
    });
819
  });
820

821
  group('Labeled tappable node guideline', () {
822 823 824 825
    testWidgets('Passes when node is labeled', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(Semantics(
        container: true,
826
        onTap: () {},
827
        label: 'test',
828
        child: const SizedBox(width: 10.0, height: 10.0),
829 830 831 832 833
      )));
      final Evaluation result = await labeledTapTargetGuideline.evaluate(tester);
      expect(result.passed, true);
      handle.dispose();
    });
834 835
    testWidgets('Fails if long-press has no label',
        (WidgetTester tester) async {
836 837 838
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(Semantics(
        container: true,
839
        onLongPress: () {},
840
        label: '',
841
        child: const SizedBox(width: 10.0, height: 10.0),
842 843 844 845 846 847 848 849 850 851
      )));
      final Evaluation result = await labeledTapTargetGuideline.evaluate(tester);
      expect(result.passed, false);
      handle.dispose();
    });

    testWidgets('Fails if tap has no label', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(Semantics(
        container: true,
852
        onTap: () {},
853
        label: '',
854
        child: const SizedBox(width: 10.0, height: 10.0),
855 856 857 858 859 860
      )));
      final Evaluation result = await labeledTapTargetGuideline.evaluate(tester);
      expect(result.passed, false);
      handle.dispose();
    });

861 862
    testWidgets('Passes if tap is merged into labeled node',
        (WidgetTester tester) async {
863 864 865
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(Semantics(
        container: true,
866
        onLongPress: () {},
867 868 869 870 871 872 873 874 875 876
        label: '',
        child: Semantics(
          label: 'test',
          child: const SizedBox(width: 10.0, height: 10.0),
        ),
      )));
      final Evaluation result = await labeledTapTargetGuideline.evaluate(tester);
      expect(result.passed, true);
      handle.dispose();
    });
877 878 879 880 881 882 883 884

    testWidgets('Passes if text field does not have label', (WidgetTester tester) async {
      final SemanticsHandle handle = tester.ensureSemantics();
      await tester.pumpWidget(_boilerplate(const TextField()));
      final Evaluation result = await labeledTapTargetGuideline.evaluate(tester);
      expect(result.passed, true);
      handle.dispose();
    });
885 886
  });

887 888
  testWidgets('regression test for material widget',
      (WidgetTester tester) async {
889
    final SemanticsHandle handle = tester.ensureSemantics();
890 891 892 893 894 895
    await tester.pumpWidget(MaterialApp(
      theme: ThemeData.light(),
      home: Scaffold(
        backgroundColor: Colors.white,
        body: ElevatedButton(
          style: ElevatedButton.styleFrom(
896
            backgroundColor: const Color(0xFFFBBC04),
897 898 899 900
            elevation: 0,
          ),
          onPressed: () {},
          child: const Text('Button', style: TextStyle(color: Colors.black)),
901 902 903 904 905 906
        ),
      ),
    ));
    await expectLater(tester, meetsGuideline(textContrastGuideline));
    handle.dispose();
  });
907 908
}

909 910
Widget _boilerplate(Widget child) =>
  MaterialApp(home: Scaffold(body: Center(child: child)));