basic_test.dart 45 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 7
// This file is run as part of a reduced test set in CI on Mac and Windows
// machines.
@Tags(<String>['reduced-test-set'])
8
library;
9

10
import 'dart:math' as math;
11
import 'dart:ui' as ui;
12
import 'dart:ui';
13

14
import 'package:flutter/gestures.dart';
15
import 'package:flutter/material.dart';
16
import 'package:flutter/rendering.dart';
17
import 'package:flutter_test/flutter_test.dart';
18
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
19

20 21
import 'semantics_tester.dart';

22
void main() {
23
  group('RawImage', () {
24
    testWidgetsWithLeakTracking('properties', (WidgetTester tester) async {
25 26 27 28 29 30 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
      final ui.Image image1 = (await tester.runAsync<ui.Image>(() => createTestImage()))!;

      await tester.pumpWidget(
        Directionality(
          textDirection: TextDirection.ltr,
          child: RawImage(image: image1),
        ),
      );
      final RenderImage renderObject = tester.firstRenderObject<RenderImage>(find.byType(RawImage));

      // Expect default values
      expect(renderObject.image!.isCloneOf(image1), true);
      expect(renderObject.debugImageLabel, null);
      expect(renderObject.width, null);
      expect(renderObject.height, null);
      expect(renderObject.scale, 1.0);
      expect(renderObject.color, null);
      expect(renderObject.opacity, null);
      expect(renderObject.colorBlendMode, null);
      expect(renderObject.fit, null);
      expect(renderObject.alignment, Alignment.center);
      expect(renderObject.repeat, ImageRepeat.noRepeat);
      expect(renderObject.centerSlice, null);
      expect(renderObject.matchTextDirection, false);
      expect(renderObject.invertColors, false);
      expect(renderObject.filterQuality, FilterQuality.low);
      expect(renderObject.isAntiAlias, false);

      final ui.Image image2 = (await tester.runAsync<ui.Image>(() => createTestImage(width: 2, height: 2)))!;
      const String debugImageLabel = 'debugImageLabel';
      const double width = 1;
      const double height = 1;
      const double scale = 2.0;
      const Color color = Colors.black;
      const Animation<double> opacity = AlwaysStoppedAnimation<double>(0.0);
      const BlendMode colorBlendMode = BlendMode.difference;
      const BoxFit fit = BoxFit.contain;
      const AlignmentGeometry alignment = Alignment.topCenter;
      const ImageRepeat repeat = ImageRepeat.repeat;
      const Rect centerSlice = Rect.fromLTWH(0, 0, width, height);
      const bool matchTextDirection = true;
      const bool invertColors = true;
      const FilterQuality filterQuality = FilterQuality.high;
      const bool isAntiAlias = true;

      await tester.pumpWidget(
        Directionality(
          textDirection: TextDirection.ltr,
          child: RawImage(
            image: image2,
            debugImageLabel: debugImageLabel,
            width: width,
            height: height,
            scale: scale,
            color: color,
            opacity: opacity,
            colorBlendMode: colorBlendMode,
            fit: fit,
            alignment: alignment,
            repeat: repeat,
            centerSlice: centerSlice,
            matchTextDirection: matchTextDirection,
            invertColors: invertColors,
            filterQuality: filterQuality,
            isAntiAlias: isAntiAlias,
          ),
        ),
      );

      expect(renderObject.image!.isCloneOf(image2), true);
      expect(renderObject.debugImageLabel, debugImageLabel);
      expect(renderObject.width, width);
      expect(renderObject.height, height);
      expect(renderObject.scale, scale);
      expect(renderObject.color, color);
      expect(renderObject.opacity, opacity);
      expect(renderObject.colorBlendMode, colorBlendMode);
      expect(renderObject.fit, fit);
      expect(renderObject.alignment, alignment);
      expect(renderObject.repeat, repeat);
      expect(renderObject.centerSlice, centerSlice);
      expect(renderObject.matchTextDirection, matchTextDirection);
      expect(renderObject.invertColors, invertColors);
      expect(renderObject.filterQuality, filterQuality);
      expect(renderObject.isAntiAlias, isAntiAlias);
    });
  });

113
  group('PhysicalShape', () {
114
    testWidgetsWithLeakTracking('properties', (WidgetTester tester) async {
115 116
      await tester.pumpWidget(
        const PhysicalShape(
117
          clipper: ShapeBorderClipper(shape: CircleBorder()),
118
          elevation: 2.0,
119 120
          color: Color(0xFF0000FF),
          shadowColor: Color(0xFF00FF00),
121
        ),
122 123
      );
      final RenderPhysicalShape renderObject = tester.renderObject(find.byType(PhysicalShape));
124
      expect(renderObject.clipper, const ShapeBorderClipper(shape: CircleBorder()));
125 126 127 128 129
      expect(renderObject.color, const Color(0xFF0000FF));
      expect(renderObject.shadowColor, const Color(0xFF00FF00));
      expect(renderObject.elevation, 2.0);
    });

130
    testWidgetsWithLeakTracking('hit test', (WidgetTester tester) async {
131
      await tester.pumpWidget(
132
        PhysicalShape(
133
          clipper: const ShapeBorderClipper(shape: CircleBorder()),
134 135 136
          elevation: 2.0,
          color: const Color(0xFF0000FF),
          shadowColor: const Color(0xFF00FF00),
137
          child: Container(color: const Color(0xFF0000FF)),
138
        ),
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
      );

      final RenderPhysicalShape renderPhysicalShape =
        tester.renderObject(find.byType(PhysicalShape));

      // The viewport is 800x600, the CircleBorder is centered and fits
      // the shortest edge, so we get a circle of radius 300, centered at
      // (400, 300).
      //
      // We test by sampling a few points around the left-most point of the
      // circle (100, 300).

      expect(tester.hitTestOnBinding(const Offset(99.0, 300.0)), doesNotHit(renderPhysicalShape));
      expect(tester.hitTestOnBinding(const Offset(100.0, 300.0)), hits(renderPhysicalShape));
      expect(tester.hitTestOnBinding(const Offset(100.0, 299.0)), doesNotHit(renderPhysicalShape));
      expect(tester.hitTestOnBinding(const Offset(100.0, 301.0)), doesNotHit(renderPhysicalShape));
155
    });
156 157 158

  });

Emmanuel Garcia's avatar
Emmanuel Garcia committed
159
  group('FractionalTranslation', () {
160
    testWidgetsWithLeakTracking('hit test - entirely inside the bounding box', (WidgetTester tester) async {
161
      final GlobalKey key1 = GlobalKey();
162
      bool pointerDown = false;
Emmanuel Garcia's avatar
Emmanuel Garcia committed
163 164

      await tester.pumpWidget(
165 166
        Center(
          child: FractionalTranslation(
Emmanuel Garcia's avatar
Emmanuel Garcia committed
167
            translation: Offset.zero,
168
            child: Listener(
Emmanuel Garcia's avatar
Emmanuel Garcia committed
169
              onPointerDown: (PointerDownEvent event) {
170
                pointerDown = true;
Emmanuel Garcia's avatar
Emmanuel Garcia committed
171
              },
172
              child: SizedBox(
Emmanuel Garcia's avatar
Emmanuel Garcia committed
173 174 175
                key: key1,
                width: 100.0,
                height: 100.0,
176
                child: Container(
177
                  color: const Color(0xFF0000FF),
Emmanuel Garcia's avatar
Emmanuel Garcia committed
178 179
                ),
              ),
180 181
            ),
          ),
182
        ),
Emmanuel Garcia's avatar
Emmanuel Garcia committed
183
      );
184
      expect(pointerDown, isFalse);
Emmanuel Garcia's avatar
Emmanuel Garcia committed
185
      await tester.tap(find.byKey(key1));
186
      expect(pointerDown, isTrue);
Emmanuel Garcia's avatar
Emmanuel Garcia committed
187 188
    });

189
    testWidgetsWithLeakTracking('hit test - partially inside the bounding box', (WidgetTester tester) async {
190
      final GlobalKey key1 = GlobalKey();
191
      bool pointerDown = false;
Emmanuel Garcia's avatar
Emmanuel Garcia committed
192 193

      await tester.pumpWidget(
194 195
        Center(
          child: FractionalTranslation(
Emmanuel Garcia's avatar
Emmanuel Garcia committed
196
            translation: const Offset(0.5, 0.5),
197
            child: Listener(
Emmanuel Garcia's avatar
Emmanuel Garcia committed
198
              onPointerDown: (PointerDownEvent event) {
199
                pointerDown = true;
Emmanuel Garcia's avatar
Emmanuel Garcia committed
200
              },
201
              child: SizedBox(
Emmanuel Garcia's avatar
Emmanuel Garcia committed
202 203 204
                key: key1,
                width: 100.0,
                height: 100.0,
205
                child: Container(
206
                  color: const Color(0xFF0000FF),
Emmanuel Garcia's avatar
Emmanuel Garcia committed
207 208
                ),
              ),
209 210
            ),
          ),
211
        ),
Emmanuel Garcia's avatar
Emmanuel Garcia committed
212
      );
213
      expect(pointerDown, isFalse);
Emmanuel Garcia's avatar
Emmanuel Garcia committed
214
      await tester.tap(find.byKey(key1));
215
      expect(pointerDown, isTrue);
Emmanuel Garcia's avatar
Emmanuel Garcia committed
216 217
    });

218
    testWidgetsWithLeakTracking('hit test - completely outside the bounding box', (WidgetTester tester) async {
219
      final GlobalKey key1 = GlobalKey();
220
      bool pointerDown = false;
Emmanuel Garcia's avatar
Emmanuel Garcia committed
221 222

      await tester.pumpWidget(
223 224
        Center(
          child: FractionalTranslation(
Emmanuel Garcia's avatar
Emmanuel Garcia committed
225
            translation: const Offset(1.0, 1.0),
226
            child: Listener(
Emmanuel Garcia's avatar
Emmanuel Garcia committed
227
              onPointerDown: (PointerDownEvent event) {
228
                pointerDown = true;
Emmanuel Garcia's avatar
Emmanuel Garcia committed
229
              },
230
              child: SizedBox(
Emmanuel Garcia's avatar
Emmanuel Garcia committed
231 232 233
                key: key1,
                width: 100.0,
                height: 100.0,
234
                child: Container(
235
                  color: const Color(0xFF0000FF),
Emmanuel Garcia's avatar
Emmanuel Garcia committed
236 237
                ),
              ),
238 239
            ),
          ),
240
        ),
Emmanuel Garcia's avatar
Emmanuel Garcia committed
241
      );
242
      expect(pointerDown, isFalse);
Emmanuel Garcia's avatar
Emmanuel Garcia committed
243
      await tester.tap(find.byKey(key1));
244
      expect(pointerDown, isTrue);
Emmanuel Garcia's avatar
Emmanuel Garcia committed
245
    });
246

247
    testWidgetsWithLeakTracking('semantics bounds are updated', (WidgetTester tester) async {
248 249 250 251 252
      final GlobalKey fractionalTranslationKey = GlobalKey();
      final GlobalKey textKey = GlobalKey();
      Offset offset = const Offset(0.4, 0.4);

      await tester.pumpWidget(
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
        StatefulBuilder(
          builder: (BuildContext context, StateSetter setState) {
            return Directionality(
              textDirection: TextDirection.ltr,
              child: Center(
                child: Semantics(
                  explicitChildNodes: true,
                  child: FractionalTranslation(
                    key: fractionalTranslationKey,
                    translation: offset,
                    child: GestureDetector(
                      onTap: () {
                        setState(() {
                          offset = const Offset(0.8, 0.8);
                        });
                      },
                      child: SizedBox(
                        width: 100.0,
                        height: 100.0,
                        child: Text(
                          'foo',
                          key: textKey,
275 276 277 278 279
                        ),
                      ),
                    ),
                  ),
                ),
280 281 282
              ),
            );
          },
283
        ),
284 285 286 287 288 289 290 291 292 293 294 295
      );

      expect(
        tester.getSemantics(find.byKey(textKey)).transform,
        Matrix4(
          3.0, 0.0, 0.0, 0.0,
          0.0, 3.0, 0.0, 0.0,
          0.0, 0.0, 1.0, 0.0,
          1170.0, 870.0, 0.0, 1.0,
        ),
      );

296
      await tester.tap(find.byKey(fractionalTranslationKey), warnIfMissed: false); // RenderFractionalTranslation can't be hit
297 298 299 300 301 302 303 304 305 306 307
      await tester.pump();
      expect(
        tester.getSemantics(find.byKey(textKey)).transform,
        Matrix4(
          3.0, 0.0, 0.0, 0.0,
          0.0, 3.0, 0.0, 0.0,
          0.0, 0.0, 1.0, 0.0,
          1290.0, 990.0, 0.0, 1.0,
        ),
      );
    });
Emmanuel Garcia's avatar
Emmanuel Garcia committed
308
  });
309

310
  group('Semantics', () {
311
    testWidgetsWithLeakTracking('Semantics can set attributed Text', (WidgetTester tester) async {
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
      final UniqueKey key = UniqueKey();
      await tester.pumpWidget(
        MaterialApp(
          home: Scaffold(
            body: Semantics(
              key: key,
              attributedLabel: AttributedString(
                'label',
                attributes: <StringAttribute>[
                  SpellOutStringAttribute(range: const TextRange(start: 0, end: 5)),
                ],
              ),
              attributedValue: AttributedString(
                'value',
                attributes: <StringAttribute>[
                  LocaleStringAttribute(range: const TextRange(start: 0, end: 5), locale: const Locale('en', 'MX')),
                ],
              ),
              attributedHint: AttributedString(
                'hint',
                attributes: <StringAttribute>[
                  SpellOutStringAttribute(range: const TextRange(start: 1, end: 2)),
                ],
              ),
              child: const Placeholder(),
            )
          ),
        )
      );
      final AttributedString attributedLabel = tester.getSemantics(find.byKey(key)).attributedLabel;
      expect(attributedLabel.string, 'label');
      expect(attributedLabel.attributes.length, 1);
      expect(attributedLabel.attributes[0] is SpellOutStringAttribute, isTrue);
      expect(attributedLabel.attributes[0].range, const TextRange(start:0, end: 5));

      final AttributedString attributedValue = tester.getSemantics(find.byKey(key)).attributedValue;
      expect(attributedValue.string, 'value');
      expect(attributedValue.attributes.length, 1);
      expect(attributedValue.attributes[0] is LocaleStringAttribute, isTrue);
      final LocaleStringAttribute valueLocale =  attributedValue.attributes[0] as LocaleStringAttribute;
      expect(valueLocale.range, const TextRange(start:0, end: 5));
      expect(valueLocale.locale, const Locale('en', 'MX'));

      final AttributedString attributedHint = tester.getSemantics(find.byKey(key)).attributedHint;
      expect(attributedHint.string, 'hint');
      expect(attributedHint.attributes.length, 1);
      expect(attributedHint.attributes[0] is SpellOutStringAttribute, isTrue);
      expect(attributedHint.attributes[0].range, const TextRange(start:1, end: 2));
    });

362
    testWidgetsWithLeakTracking('Semantics can merge attributed strings', (WidgetTester tester) async {
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
      final UniqueKey key = UniqueKey();
      await tester.pumpWidget(
          MaterialApp(
            home: Scaffold(
                body: Semantics(
                  key: key,
                  attributedLabel: AttributedString(
                    'label',
                    attributes: <StringAttribute>[
                      SpellOutStringAttribute(range: const TextRange(start: 0, end: 5)),
                    ],
                  ),
                  attributedHint: AttributedString(
                    'hint',
                    attributes: <StringAttribute>[
                      SpellOutStringAttribute(range: const TextRange(start: 1, end: 2)),
                    ],
                  ),
                  child: Semantics(
                    attributedLabel: AttributedString(
                      'label',
                      attributes: <StringAttribute>[
                        SpellOutStringAttribute(range: const TextRange(start: 0, end: 5)),
                      ],
                    ),
                    attributedHint: AttributedString(
                      'hint',
                      attributes: <StringAttribute>[
                        SpellOutStringAttribute(range: const TextRange(start: 1, end: 2)),
                      ],
                    ),
                    child: const Placeholder(),
                  )
                )
            ),
          )
      );
      final AttributedString attributedLabel = tester.getSemantics(find.byKey(key)).attributedLabel;
      expect(attributedLabel.string, 'label\nlabel');
      expect(attributedLabel.attributes.length, 2);
      expect(attributedLabel.attributes[0] is SpellOutStringAttribute, isTrue);
      expect(attributedLabel.attributes[0].range, const TextRange(start:0, end: 5));
      expect(attributedLabel.attributes[1] is SpellOutStringAttribute, isTrue);
      expect(attributedLabel.attributes[1].range, const TextRange(start:6, end: 11));

      final AttributedString attributedHint = tester.getSemantics(find.byKey(key)).attributedHint;
      expect(attributedHint.string, 'hint\nhint');
      expect(attributedHint.attributes.length, 2);
      expect(attributedHint.attributes[0] is SpellOutStringAttribute, isTrue);
      expect(attributedHint.attributes[0].range, const TextRange(start:1, end: 2));
      expect(attributedHint.attributes[1] is SpellOutStringAttribute, isTrue);
      expect(attributedHint.attributes[1].range, const TextRange(start:6, end: 7));
    });

417
    testWidgetsWithLeakTracking('Semantics can merge attributed strings with non attributed string', (WidgetTester tester) async {
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
      final UniqueKey key = UniqueKey();
      await tester.pumpWidget(
          MaterialApp(
            home: Scaffold(
                body: Semantics(
                    key: key,
                    attributedLabel: AttributedString(
                      'label1',
                      attributes: <StringAttribute>[
                        SpellOutStringAttribute(range: const TextRange(start: 0, end: 5)),
                      ],
                    ),
                    child: Semantics(
                      label: 'label2',
                      child: Semantics(
                        attributedLabel: AttributedString(
                          'label3',
                          attributes: <StringAttribute>[
                            SpellOutStringAttribute(range: const TextRange(start: 1, end: 3)),
                          ],
                        ),
                        child: const Placeholder(),
                      ),
                    )
                )
            ),
          )
      );
      final AttributedString attributedLabel = tester.getSemantics(find.byKey(key)).attributedLabel;
      expect(attributedLabel.string, 'label1\nlabel2\nlabel3');
      expect(attributedLabel.attributes.length, 2);
      expect(attributedLabel.attributes[0] is SpellOutStringAttribute, isTrue);
      expect(attributedLabel.attributes[0].range, const TextRange(start:0, end: 5));
      expect(attributedLabel.attributes[1] is SpellOutStringAttribute, isTrue);
      expect(attributedLabel.attributes[1].range, const TextRange(start:15, end: 17));
    });
  });

456
  group('Row', () {
457
    testWidgetsWithLeakTracking('multiple baseline aligned children', (WidgetTester tester) async {
458 459
      final UniqueKey key1 = UniqueKey();
      final UniqueKey key2 = UniqueKey();
460 461 462 463
      // The point size of the font must be a multiple of 4 until
      // https://github.com/flutter/flutter/issues/122066 is resolved.
      const double fontSize1 = 52;
      const double fontSize2 = 12;
464 465 466

      await tester.pumpWidget(
        MaterialApp(
467
          theme: ThemeData(useMaterial3: false),
468
          home: Scaffold(
469 470 471 472 473 474
            body: Row(
              crossAxisAlignment: CrossAxisAlignment.baseline,
              textBaseline: TextBaseline.alphabetic,
              children: <Widget>[
                Text('big text',
                  key: key1,
475
                  style: const TextStyle(fontFamily: 'FlutterTest', fontSize: fontSize1, height: 1.0),
476 477 478
                ),
                Text('one\ntwo\nthree\nfour\nfive\nsix\nseven',
                  key: key2,
479
                  style: const TextStyle(fontFamily: 'FlutterTest', fontSize: fontSize2, height: 1.0),
480 481
                ),
              ],
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
            ),
          ),
        ),
      );

      final RenderBox textBox1 = tester.renderObject(find.byKey(key1));
      final RenderBox textBox2 = tester.renderObject(find.byKey(key2));
      final RenderBox rowBox = tester.renderObject(find.byType(Row));

      // The two Texts are baseline aligned, so some portion of them extends
      // both above and below the baseline. The first has a huge font size, so
      // it extends higher above the baseline than usual. The second has many
      // lines, but being aligned by the first line's baseline, they hang far
      // below the baseline. The size of the parent row is just enough to
      // contain both of them.
497 498 499 500 501
      const double ascentRatio = 0.75;
      const double aboveBaseline1 = fontSize1 * ascentRatio;
      const double belowBaseline1 = fontSize1 * (1 - ascentRatio);
      const double aboveBaseline2 = fontSize2 * ascentRatio;
      const double belowBaseline2 = fontSize2 * (1 - ascentRatio) + fontSize2 * 6;
502 503 504 505
      final double aboveBaseline = math.max(aboveBaseline1, aboveBaseline2);
      final double belowBaseline = math.max(belowBaseline1, belowBaseline2);
      expect(rowBox.size.height, greaterThan(textBox1.size.height));
      expect(rowBox.size.height, greaterThan(textBox2.size.height));
506
      expect(rowBox.size.height, aboveBaseline + belowBaseline, );
507
      expect(tester.getTopLeft(find.byKey(key1)).dy, 0);
508
      expect(tester.getTopLeft(find.byKey(key2)).dy, aboveBaseline1 - aboveBaseline2);
509
    });
510

511
    testWidgetsWithLeakTracking('baseline aligned children account for a larger, no-baseline child size', (WidgetTester tester) async {
512 513 514
      // Regression test for https://github.com/flutter/flutter/issues/58898
      final UniqueKey key1 = UniqueKey();
      final UniqueKey key2 = UniqueKey();
515 516 517 518
      // The point size of the font must be a multiple of 4 until
      // https://github.com/flutter/flutter/issues/122066 is resolved.
      const double fontSize1 = 52;
      const double fontSize2 = 12;
519 520 521

      await tester.pumpWidget(
        MaterialApp(
522
          theme: ThemeData(useMaterial3: false),
523
          home: Scaffold(
524 525 526 527 528 529
            body: Row(
              crossAxisAlignment: CrossAxisAlignment.baseline,
              textBaseline: TextBaseline.alphabetic,
              children: <Widget>[
                Text('big text',
                  key: key1,
530
                  style: const TextStyle(fontFamily: 'FlutterTest', fontSize: fontSize1, height: 1.0),
531 532 533
                ),
                Text('one\ntwo\nthree\nfour\nfive\nsix\nseven',
                  key: key2,
534
                  style: const TextStyle(fontFamily: 'FlutterTest', fontSize: fontSize2, height: 1.0),
535 536 537
                ),
                const FlutterLogo(size: 250),
              ],
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
            ),
          ),
        ),
      );

      final RenderBox textBox1 = tester.renderObject(find.byKey(key1));
      final RenderBox textBox2 = tester.renderObject(find.byKey(key2));
      final RenderBox rowBox = tester.renderObject(find.byType(Row));

      // The two Texts are baseline aligned, so some portion of them extends
      // both above and below the baseline. The first has a huge font size, so
      // it extends higher above the baseline than usual. The second has many
      // lines, but being aligned by the first line's baseline, they hang far
      // below the baseline. The FlutterLogo extends further than both Texts,
      // so the size of the parent row should contain the FlutterLogo as well.
553 554 555
      const double ascentRatio = 0.75;
      const double aboveBaseline1 = fontSize1 * ascentRatio;
      const double aboveBaseline2 = fontSize2 * ascentRatio;
556 557 558 559 560 561
      expect(rowBox.size.height, greaterThan(textBox1.size.height));
      expect(rowBox.size.height, greaterThan(textBox2.size.height));
      expect(rowBox.size.height, 250);
      expect(tester.getTopLeft(find.byKey(key1)).dy, 0);
      expect(
        tester.getTopLeft(find.byKey(key2)).dy,
562
        aboveBaseline1 - aboveBaseline2,
563 564
      );
    });
565 566
  });

567 568
  test('UnconstrainedBox toString', () {
    expect(
569
      const UnconstrainedBox(constrainedAxis: Axis.vertical).toString(),
570
      equals('UnconstrainedBox(alignment: Alignment.center, constrainedAxis: vertical)'),
571
    );
572

573 574
    expect(
      const UnconstrainedBox(constrainedAxis: Axis.horizontal, textDirection: TextDirection.rtl, alignment: Alignment.topRight).toString(),
575
      equals('UnconstrainedBox(alignment: Alignment.topRight, constrainedAxis: horizontal, textDirection: rtl)'),
576 577
    );
  });
578

579
  testWidgetsWithLeakTracking('UnconstrainedBox can set and update clipBehavior', (WidgetTester tester) async {
580
    await tester.pumpWidget(const UnconstrainedBox());
581
    final RenderConstraintsTransformBox renderObject = tester.allRenderObjects.whereType<RenderConstraintsTransformBox>().first;
582
    expect(renderObject.clipBehavior, equals(Clip.none));
583 584 585 586 587

    await tester.pumpWidget(const UnconstrainedBox(clipBehavior: Clip.antiAlias));
    expect(renderObject.clipBehavior, equals(Clip.antiAlias));
  });

588
  testWidgetsWithLeakTracking('UnconstrainedBox warns only when clipBehavior is Clip.none', (WidgetTester tester) async {
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
    for (final Clip? clip in <Clip?>[null, ...Clip.values]) {
      // Clear any render objects that were there before so that we can see more
      // than one error. Otherwise, it just throws the first one and skips the
      // rest, since the render objects haven't changed.
      await tester.pumpWidget(const SizedBox());
      await tester.pumpWidget(
        Center(
          child: ConstrainedBox(
            constraints: const BoxConstraints(maxHeight: 200, maxWidth: 200),
            child: clip == null
              ? const UnconstrainedBox(child: SizedBox(width: 400, height: 400))
              : UnconstrainedBox(
                clipBehavior: clip,
                child: const SizedBox(width: 400, height: 400),
              ),
          ),
        ),
      );

      final RenderConstraintsTransformBox renderObject = tester.allRenderObjects.whereType<RenderConstraintsTransformBox>().first;

      // Defaults to Clip.none
      expect(renderObject.clipBehavior, equals(clip ?? Clip.none), reason: 'for clip = $clip');

613
      switch (clip) {
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
        case null:
        case Clip.none:
          // the UnconstrainedBox overflows.
          final dynamic exception = tester.takeException();
          expect(exception, isFlutterError, reason: 'for clip = $clip');
          // ignore: avoid_dynamic_calls
          expect(exception.diagnostics.first.level, DiagnosticLevel.summary, reason: 'for clip = $clip');
          expect(
            // ignore: avoid_dynamic_calls
            exception.diagnostics.first.toString(),
            startsWith('A RenderConstraintsTransformBox overflowed'),
            reason: 'for clip = $clip',
          );
        case Clip.hardEdge:
        case Clip.antiAlias:
        case Clip.antiAliasWithSaveLayer:
          expect(tester.takeException(), isNull, reason: 'for clip = $clip');
      }
    }
  });

635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
  group('ConstraintsTransformBox', () {
    test('toString', () {
      expect(
        const ConstraintsTransformBox(
          constraintsTransform: ConstraintsTransformBox.unconstrained,
        ).toString(),
        equals('ConstraintsTransformBox(alignment: Alignment.center, constraints transform: unconstrained)'),
      );
      expect(
        const ConstraintsTransformBox(
          textDirection: TextDirection.rtl,
          alignment: Alignment.topRight,
          constraintsTransform: ConstraintsTransformBox.widthUnconstrained,
        ).toString(),
        equals('ConstraintsTransformBox(alignment: Alignment.topRight, textDirection: rtl, constraints transform: width constraints removed)'),
      );
    });
  });

654
  group('ColoredBox', () {
655 656
    late _MockCanvas mockCanvas;
    late _MockPaintingContext mockContext;
657 658 659 660
    const Color colorToPaint = Color(0xFFABCDEF);

    setUp(() {
      mockContext = _MockPaintingContext();
661
      mockCanvas = mockContext.canvas;
662 663
    });

664
    testWidgetsWithLeakTracking('ColoredBox - no size, no child', (WidgetTester tester) async {
665
      await tester.pumpWidget(const Flex(
666 667
        direction: Axis.horizontal,
        textDirection: TextDirection.ltr,
668
        children: <Widget>[
669 670 671 672 673 674 675 676 677 678
          SizedBox.shrink(
            child: ColoredBox(color: colorToPaint),
          ),
        ],
      ));
      expect(find.byType(ColoredBox), findsOneWidget);
      final RenderObject renderColoredBox = tester.renderObject(find.byType(ColoredBox));

      renderColoredBox.paint(mockContext, Offset.zero);

679 680 681
      expect(mockCanvas.rects, isEmpty);
      expect(mockCanvas.paints, isEmpty);
      expect(mockContext.children, isEmpty);
682
      expect(mockContext.offsets, isEmpty);
683 684
    });

685
    testWidgetsWithLeakTracking('ColoredBox - no size, child', (WidgetTester tester) async {
686 687
      const ValueKey<int> key = ValueKey<int>(0);
      const Widget child = SizedBox.expand(key: key);
688
      await tester.pumpWidget(const Flex(
689 690
        direction: Axis.horizontal,
        textDirection: TextDirection.ltr,
691
        children: <Widget>[
692 693 694 695 696 697 698 699 700 701 702
          SizedBox.shrink(
            child: ColoredBox(color: colorToPaint, child: child),
          ),
        ],
      ));
      expect(find.byType(ColoredBox), findsOneWidget);
      final RenderObject renderColoredBox = tester.renderObject(find.byType(ColoredBox));
      final RenderObject renderSizedBox = tester.renderObject(find.byKey(key));

      renderColoredBox.paint(mockContext, Offset.zero);

703 704 705
      expect(mockCanvas.rects, isEmpty);
      expect(mockCanvas.paints, isEmpty);
      expect(mockContext.children.single, renderSizedBox);
706
      expect(mockContext.offsets.single, Offset.zero);
707 708
    });

709
    testWidgetsWithLeakTracking('ColoredBox - size, no child', (WidgetTester tester) async {
710 711 712 713 714 715
      await tester.pumpWidget(const ColoredBox(color: colorToPaint));
      expect(find.byType(ColoredBox), findsOneWidget);
      final RenderObject renderColoredBox = tester.renderObject(find.byType(ColoredBox));

      renderColoredBox.paint(mockContext, Offset.zero);

716 717 718
      expect(mockCanvas.rects.single, const Rect.fromLTWH(0, 0, 800, 600));
      expect(mockCanvas.paints.single.color, colorToPaint);
      expect(mockContext.children, isEmpty);
719
      expect(mockContext.offsets, isEmpty);
720 721
    });

722
    testWidgetsWithLeakTracking('ColoredBox - size, child', (WidgetTester tester) async {
723 724 725 726 727 728 729 730 731
      const ValueKey<int> key = ValueKey<int>(0);
      const Widget child = SizedBox.expand(key: key);
      await tester.pumpWidget(const ColoredBox(color: colorToPaint, child: child));
      expect(find.byType(ColoredBox), findsOneWidget);
      final RenderObject renderColoredBox = tester.renderObject(find.byType(ColoredBox));
      final RenderObject renderSizedBox = tester.renderObject(find.byKey(key));

      renderColoredBox.paint(mockContext, Offset.zero);

732 733 734
      expect(mockCanvas.rects.single, const Rect.fromLTWH(0, 0, 800, 600));
      expect(mockCanvas.paints.single.color, colorToPaint);
      expect(mockContext.children.single, renderSizedBox);
735
      expect(mockContext.offsets.single, Offset.zero);
Dan Field's avatar
Dan Field committed
736 737
    });

738
    testWidgetsWithLeakTracking('ColoredBox - debugFillProperties', (WidgetTester tester) async {
Dan Field's avatar
Dan Field committed
739 740 741 742 743 744
      const ColoredBox box = ColoredBox(color: colorToPaint);
      final DiagnosticPropertiesBuilder properties = DiagnosticPropertiesBuilder();
      box.debugFillProperties(properties);

      expect(properties.properties.first.value, colorToPaint);
    });
745
  });
746
  testWidgetsWithLeakTracking('Inconsequential golden test', (WidgetTester tester) async {
747 748 749 750
    // The test validates the Flutter Gold integration. Any changes to the
    // golden file can be approved at any time.
    await tester.pumpWidget(RepaintBoundary(
      child: Container(
751
        color: const Color(0xABCDABCD),
752 753 754 755 756 757 758 759
      ),
    ));

    await tester.pumpAndSettle();
    await expectLater(
      find.byType(RepaintBoundary),
      matchesGoldenFile('inconsequential_golden_file.png'),
    );
760
  });
761

762
  testWidgetsWithLeakTracking('IgnorePointer ignores pointers', (WidgetTester tester) async {
763
    final List<String> logs = <String>[];
764
    Widget target({required bool ignoring}) => Align(
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
      alignment: Alignment.topLeft,
      child: Directionality(
        textDirection: TextDirection.ltr,
        child: SizedBox(
          width: 100,
          height: 100,
          child: Listener(
            onPointerDown: (_) { logs.add('down1'); },
            child: MouseRegion(
              onEnter: (_) { logs.add('enter1'); },
              onExit: (_) { logs.add('exit1'); },
              cursor: SystemMouseCursors.forbidden,
              child: Stack(
                children: <Widget>[
                  Listener(
                    onPointerDown: (_) { logs.add('down2'); },
                    child: MouseRegion(
                      cursor: SystemMouseCursors.click,
                      onEnter: (_) { logs.add('enter2'); },
                      onExit: (_) { logs.add('exit2'); },
                    ),
                  ),
                  IgnorePointer(
                    ignoring: ignoring,
                    child: Listener(
                      onPointerDown: (_) { logs.add('down3'); },
                      child: MouseRegion(
                        cursor: SystemMouseCursors.text,
                        onEnter: (_) { logs.add('enter3'); },
                        onExit: (_) { logs.add('exit3'); },
                      ),
                    ),
797
                  ),
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838
                ],
              ),
            ),
          ),
        ),
      ),
    );

    final TestGesture gesture = await tester.createGesture(pointer: 1, kind: PointerDeviceKind.mouse);
    await gesture.addPointer(location: const Offset(200, 200));

    await tester.pumpWidget(target(ignoring: true));
    expect(logs, isEmpty);

    await gesture.moveTo(const Offset(50, 50));
    expect(logs, <String>['enter1', 'enter2']);
    logs.clear();

    await gesture.down(const Offset(50, 50));
    expect(logs, <String>['down2', 'down1']);
    logs.clear();

    await gesture.up();
    expect(logs, isEmpty);

    await tester.pumpWidget(target(ignoring: false));
    expect(logs, <String>['exit2', 'enter3']);
    logs.clear();

    await gesture.down(const Offset(50, 50));
    expect(logs, <String>['down3', 'down1']);
    logs.clear();

    await gesture.up();
    expect(logs, isEmpty);

    await tester.pumpWidget(target(ignoring: true));
    expect(logs, <String>['exit3', 'enter2']);
    logs.clear();
  });

839
  group('IgnorePointer semantics', () {
840
    testWidgetsWithLeakTracking('does not change semantics when not ignoring', (WidgetTester tester) async {
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
      final UniqueKey key = UniqueKey();
      await tester.pumpWidget(
        MaterialApp(
          home: IgnorePointer(
            ignoring: false,
            child: ElevatedButton(
              key: key,
              onPressed: () { },
              child: const Text('button'),
            ),
          ),
        ),
      );
      expect(
        tester.getSemantics(find.byKey(key)),
        matchesSemantics(
          label: 'button',
          hasTapAction: true,
          isButton: true,
          isFocusable: true,
          hasEnabledState: true,
          isEnabled: true,
        ),
      );
    });

867
    testWidgetsWithLeakTracking('can toggle the ignoring.', (WidgetTester tester) async {
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985
      final UniqueKey key1 = UniqueKey();
      final UniqueKey key2 = UniqueKey();
      final UniqueKey key3 = UniqueKey();
      await tester.pumpWidget(
        MaterialApp(
          home: TestIgnorePointer(
            child: Semantics(
              key: key1,
              label: '1',
              onTap: (){ },
              container: true,
              child: Semantics(
                key: key2,
                label: '2',
                onTap: (){ },
                container: true,
                child: Semantics(
                  key: key3,
                  label: '3',
                  onTap: (){ },
                  container: true,
                  child: const SizedBox(width: 10, height: 10),
                ),
              ),
            ),
          ),
        ),
      );
      expect(
        tester.getSemantics(find.byKey(key1)),
        matchesSemantics(
          label: '1',
        ),
      );
      expect(
        tester.getSemantics(find.byKey(key2)),
        matchesSemantics(
          label: '2',
        ),
      );
      expect(
        tester.getSemantics(find.byKey(key3)),
        matchesSemantics(
          label: '3',
        ),
      );

      final TestIgnorePointerState state = tester.state<TestIgnorePointerState>(find.byType(TestIgnorePointer));
      state.setIgnore(false);
      await tester.pump();
      expect(
        tester.getSemantics(find.byKey(key1)),
        matchesSemantics(
          label: '1',
          hasTapAction: true,
        ),
      );
      expect(
        tester.getSemantics(find.byKey(key2)),
        matchesSemantics(
          label: '2',
          hasTapAction: true,
        ),
      );
      expect(
        tester.getSemantics(find.byKey(key3)),
        matchesSemantics(
          label: '3',
          hasTapAction: true,
        ),
      );

      state.setIgnore(true);
      await tester.pump();
      expect(
        tester.getSemantics(find.byKey(key1)),
        matchesSemantics(
          label: '1',
        ),
      );
      expect(
        tester.getSemantics(find.byKey(key2)),
        matchesSemantics(
          label: '2',
        ),
      );
      expect(
        tester.getSemantics(find.byKey(key3)),
        matchesSemantics(
          label: '3',
        ),
      );

      state.setIgnore(false);
      await tester.pump();
      expect(
        tester.getSemantics(find.byKey(key1)),
        matchesSemantics(
          label: '1',
          hasTapAction: true,
        ),
      );
      expect(
        tester.getSemantics(find.byKey(key2)),
        matchesSemantics(
          label: '2',
          hasTapAction: true,
        ),
      );
      expect(
        tester.getSemantics(find.byKey(key3)),
        matchesSemantics(
          label: '3',
          hasTapAction: true,
        ),
      );
    });

986
    testWidgetsWithLeakTracking('drops semantics when its ignoringSemantics is true', (WidgetTester tester) async {
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
      final SemanticsTester semantics = SemanticsTester(tester);
      final UniqueKey key = UniqueKey();
      await tester.pumpWidget(
        MaterialApp(
          home: IgnorePointer(
            ignoringSemantics: true,
            child: ElevatedButton(
              key: key,
              onPressed: () { },
              child: const Text('button'),
            ),
          ),
        ),
      );
      expect(semantics, isNot(includesNodeWith(label: 'button')));
      semantics.dispose();
    });

1005
    testWidgetsWithLeakTracking('ignores user interactions', (WidgetTester tester) async {
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
      final UniqueKey key = UniqueKey();
      await tester.pumpWidget(
        MaterialApp(
          home: IgnorePointer(
            child: ElevatedButton(
              key: key,
              onPressed: () { },
              child: const Text('button'),
            ),
          ),
        ),
      );
      expect(
        tester.getSemantics(find.byKey(key)),
        // Tap action is blocked.
        matchesSemantics(
          label: 'button',
          isButton: true,
          isFocusable: true,
          hasEnabledState: true,
          isEnabled: true,
        ),
      );
    });
  });

1032
  testWidgetsWithLeakTracking('AbsorbPointer absorbs pointers', (WidgetTester tester) async {
1033
    final List<String> logs = <String>[];
1034
    Widget target({required bool absorbing}) => Align(
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
      alignment: Alignment.topLeft,
      child: Directionality(
        textDirection: TextDirection.ltr,
        child: SizedBox(
          width: 100,
          height: 100,
          child: Listener(
            onPointerDown: (_) { logs.add('down1'); },
            child: MouseRegion(
              onEnter: (_) { logs.add('enter1'); },
              onExit: (_) { logs.add('exit1'); },
              cursor: SystemMouseCursors.forbidden,
              child: Stack(
                children: <Widget>[
                  Listener(
                    onPointerDown: (_) { logs.add('down2'); },
                    child: MouseRegion(
                      cursor: SystemMouseCursors.click,
                      onEnter: (_) { logs.add('enter2'); },
                      onExit: (_) { logs.add('exit2'); },
                    ),
                  ),
                  AbsorbPointer(
                    absorbing: absorbing,
                    child: Listener(
                      onPointerDown: (_) { logs.add('down3'); },
                      child: MouseRegion(
                        cursor: SystemMouseCursors.text,
                        onEnter: (_) { logs.add('enter3'); },
                        onExit: (_) { logs.add('exit3'); },
                      ),
                    ),
1067
                  ),
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
                ],
              ),
            ),
          ),
        ),
      ),
    );

    final TestGesture gesture = await tester.createGesture(pointer: 1, kind: PointerDeviceKind.mouse);
    await gesture.addPointer(location: const Offset(200, 200));

    await tester.pumpWidget(target(absorbing: true));
    expect(logs, isEmpty);

    await gesture.moveTo(const Offset(50, 50));
    expect(logs, <String>['enter1']);
    logs.clear();

    await gesture.down(const Offset(50, 50));
    expect(logs, <String>['down1']);
    logs.clear();

    await gesture.up();
    expect(logs, isEmpty);

    await tester.pumpWidget(target(absorbing: false));
    expect(logs, <String>['enter3']);
    logs.clear();

    await gesture.down(const Offset(50, 50));
    expect(logs, <String>['down3', 'down1']);
    logs.clear();

    await gesture.up();
    expect(logs, isEmpty);

    await tester.pumpWidget(target(absorbing: true));
    expect(logs, <String>['exit3']);
    logs.clear();
  });
1108

1109
  testWidgetsWithLeakTracking('Wrap implements debugFillProperties', (WidgetTester tester) async {
1110
    final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
1111
    const Wrap(
1112 1113 1114 1115
      spacing: 8.0, // gap between adjacent Text widget
      runSpacing: 4.0, // gap between lines
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
1116
      children: <Widget>[
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138
        Text('Hamilton'),
        Text('Lafayette'),
        Text('Mulligan'),
      ],
    ).debugFillProperties(builder);

    final List<String> description = builder.properties
      .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
      .map((DiagnosticsNode node) => node.toString())
      .toList();

    expect(description, unorderedMatches(<dynamic>[
      contains('direction: horizontal'),
      contains('alignment: start'),
      contains('spacing: 8.0'),
      contains('runAlignment: start'),
      contains('runSpacing: 4.0'),
      contains('crossAxisAlignment: start'),
      contains('textDirection: ltr'),
      contains('verticalDirection: up'),
    ]));
  });
1139

1140
  testWidgetsWithLeakTracking('Row and IgnoreBaseline (control -- with baseline)', (WidgetTester tester) async {
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
    await tester.pumpWidget(
      const Row(
        crossAxisAlignment: CrossAxisAlignment.baseline,
        textBaseline: TextBaseline.alphabetic,
        textDirection: TextDirection.ltr,
        children: <Widget>[
          Text(
            'a',
            textDirection: TextDirection.ltr,
            style: TextStyle(fontSize: 128.0, fontFamily: 'FlutterTest'), // places baseline at y=96
          ),
          Text(
            'b',
            textDirection: TextDirection.ltr,
            style: TextStyle(fontSize: 32.0, fontFamily: 'FlutterTest'), // 24 above baseline, 8 below baseline
          ),
        ],
      ),
    );

    final Offset aPos = tester.getTopLeft(find.text('a'));
    final Offset bPos = tester.getTopLeft(find.text('b'));
    expect(aPos.dy, 0.0);
    expect(bPos.dy, 96.0 - 24.0);
  });

1167
  testWidgetsWithLeakTracking('Row and IgnoreBaseline (with ignored baseline)', (WidgetTester tester) async {
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
    await tester.pumpWidget(
      const Row(
        crossAxisAlignment: CrossAxisAlignment.baseline,
        textBaseline: TextBaseline.alphabetic,
        textDirection: TextDirection.ltr,
        children: <Widget>[
          IgnoreBaseline(
            child: Text(
              'a',
              textDirection: TextDirection.ltr,
              style: TextStyle(fontSize: 128.0, fontFamily: 'FlutterTest'), // places baseline at y=96
            ),
          ),
          Text(
            'b',
            textDirection: TextDirection.ltr,
            style: TextStyle(fontSize: 32.0, fontFamily: 'FlutterTest'), // 24 above baseline, 8 below baseline
          ),
        ],
      ),
    );

    final Offset aPos = tester.getTopLeft(find.text('a'));
    final Offset bPos = tester.getTopLeft(find.text('b'));
    expect(aPos.dy, 0.0);
    expect(bPos.dy, 0.0);
  });
1195 1196
}

1197
HitsRenderBox hits(RenderBox renderBox) => HitsRenderBox(renderBox);
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209

class HitsRenderBox extends Matcher {
  const HitsRenderBox(this.renderBox);

  final RenderBox renderBox;

  @override
  Description describe(Description description) =>
    description.add('hit test result contains ').addDescriptionOf(renderBox);

  @override
  bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
1210
    final HitTestResult hitTestResult = item as HitTestResult;
1211
    return hitTestResult.path.where(
1212
      (HitTestEntry entry) => entry.target == renderBox,
1213 1214 1215 1216
    ).isNotEmpty;
  }
}

1217
DoesNotHitRenderBox doesNotHit(RenderBox renderBox) => DoesNotHitRenderBox(renderBox);
1218 1219 1220 1221 1222 1223 1224 1225

class DoesNotHitRenderBox extends Matcher {
  const DoesNotHitRenderBox(this.renderBox);

  final RenderBox renderBox;

  @override
  Description describe(Description description) =>
1226
    description.add("hit test result doesn't contain ").addDescriptionOf(renderBox);
1227 1228 1229

  @override
  bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
1230
    final HitTestResult hitTestResult = item as HitTestResult;
1231
    return hitTestResult.path.where(
1232
      (HitTestEntry entry) => entry.target == renderBox,
1233 1234 1235
    ).isEmpty;
  }
}
1236

1237 1238
class _MockPaintingContext extends Fake implements PaintingContext {
  final List<RenderObject> children = <RenderObject>[];
1239
  final List<Offset> offsets = <Offset>[];
1240 1241 1242 1243 1244 1245 1246

  @override
  final _MockCanvas canvas = _MockCanvas();

  @override
  void paintChild(RenderObject child, Offset offset) {
    children.add(child);
1247
    offsets.add(offset);
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261
  }
}

class _MockCanvas extends Fake implements Canvas {
  final List<Rect> rects = <Rect>[];
  final List<Paint> paints = <Paint>[];
  bool didPaint = false;

  @override
  void drawRect(Rect rect, Paint paint) {
    rects.add(rect);
    paints.add(paint);
  }
}
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288


class TestIgnorePointer extends StatefulWidget {
  const TestIgnorePointer({super.key, required this.child});

  final Widget child;
  @override
  State<StatefulWidget> createState() => TestIgnorePointerState();
}

class TestIgnorePointerState extends State<TestIgnorePointer> {
  bool ignore = true;

  void setIgnore(bool newIgnore) {
    setState(() {
      ignore = newIgnore;
    });
  }

  @override
  Widget build(BuildContext context) {
    return IgnorePointer(
      ignoring: ignore,
      child: widget.child,
    );
  }
}