proxy_box_test.dart 41.7 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 'dart:ui' as ui show Gradient, Image, ImageFilter;
6

7
import 'package:flutter/foundation.dart';
8
import 'package:flutter/material.dart';
9
import 'package:flutter/rendering.dart';
10
import 'package:flutter_test/flutter_test.dart';
11

12
import 'mock_canvas.dart';
13 14 15
import 'rendering_tester.dart';

void main() {
16
  TestRenderingFlutterBinding.ensureInitialized();
17 18 19 20 21 22 23 24 25
  test('RenderFittedBox handles applying paint transform and hit-testing with empty size', () {
    final RenderFittedBox fittedBox = RenderFittedBox(
      child: RenderCustomPaint(
        painter: TestCallbackPainter(onPaint: () {}),
      ),
    );

    layout(fittedBox, phase: EnginePhase.flushSemantics);
    final Matrix4 transform = Matrix4.identity();
26
    fittedBox.applyPaintTransform(fittedBox.child!, transform);
27 28 29
    expect(transform, Matrix4.zero());

    final BoxHitTestResult hitTestResult = BoxHitTestResult();
30
    expect(fittedBox.hitTestChildren(hitTestResult, position: Offset.zero), isFalse);
31 32
  });

33
  test('RenderFittedBox does not paint with empty sizes', () {
34
    bool painted;
35
    RenderFittedBox makeFittedBox(Size size) {
36 37
      return RenderFittedBox(
        child: RenderCustomPaint(
38
          preferredSize: size,
39
          painter: TestCallbackPainter(onPaint: () {
40 41
            painted = true;
          }),
42 43 44 45
        ),
      );
    }

46
    // The RenderFittedBox paints if both its size and its child's size are nonempty.
47
    painted = false;
48
    layout(makeFittedBox(const Size(1, 1)), phase: EnginePhase.paint);
49 50
    expect(painted, equals(true));

51 52 53 54 55
    // The RenderFittedBox should not paint if its child is empty-sized.
    painted = false;
    layout(makeFittedBox(Size.zero), phase: EnginePhase.paint);
    expect(painted, equals(false));

56 57
    // The RenderFittedBox should not paint if it is empty.
    painted = false;
58
    layout(makeFittedBox(const Size(1, 1)), constraints: BoxConstraints.tight(Size.zero), phase: EnginePhase.paint);
59 60
    expect(painted, equals(false));
  });
61

62
  test('RenderPhysicalModel compositing', () {
63
    final RenderPhysicalModel root = RenderPhysicalModel(color: const Color(0xffff00ff));
64
    layout(root, phase: EnginePhase.composite);
65
    expect(root.needsCompositing, isFalse);
66 67 68 69 70

    // On Fuchsia, the system compositor is responsible for drawing shadows
    // for physical model layers with non-zero elevation.
    root.elevation = 1.0;
    pumpFrame(phase: EnginePhase.composite);
71
    expect(root.needsCompositing, isFalse);
72 73 74

    root.elevation = 0.0;
    pumpFrame(phase: EnginePhase.composite);
75
    expect(root.needsCompositing, isFalse);
76
  });
77 78

  test('RenderSemanticsGestureHandler adds/removes correct semantic actions', () {
79
    final RenderSemanticsGestureHandler renderObj = RenderSemanticsGestureHandler(
80 81
      onTap: () { },
      onHorizontalDragUpdate: (DragUpdateDetails details) { },
82 83
    );

84
    SemanticsConfiguration config = SemanticsConfiguration();
85 86 87 88
    renderObj.describeSemanticsConfiguration(config);
    expect(config.getActionHandler(SemanticsAction.tap), isNotNull);
    expect(config.getActionHandler(SemanticsAction.scrollLeft), isNotNull);
    expect(config.getActionHandler(SemanticsAction.scrollRight), isNotNull);
89

90
    config = SemanticsConfiguration();
91
    renderObj.validActions = <SemanticsAction>{SemanticsAction.tap, SemanticsAction.scrollLeft};
92

93 94 95 96
    renderObj.describeSemanticsConfiguration(config);
    expect(config.getActionHandler(SemanticsAction.tap), isNotNull);
    expect(config.getActionHandler(SemanticsAction.scrollLeft), isNotNull);
    expect(config.getActionHandler(SemanticsAction.scrollRight), isNull);
97
  });
98 99 100

  group('RenderPhysicalShape', () {
    test('shape change triggers repaint', () {
Dan Field's avatar
Dan Field committed
101 102 103 104 105 106 107 108 109
      for (final TargetPlatform platform in TargetPlatform.values) {
        debugDefaultTargetPlatformOverride = platform;

        final RenderPhysicalShape root = RenderPhysicalShape(
          color: const Color(0xffff00ff),
          clipper: const ShapeBorderClipper(shape: CircleBorder()),
        );
        layout(root, phase: EnginePhase.composite);
        expect(root.debugNeedsPaint, isFalse);
110

Dan Field's avatar
Dan Field committed
111 112 113
        // Same shape, no repaint.
        root.clipper = const ShapeBorderClipper(shape: CircleBorder());
        expect(root.debugNeedsPaint, isFalse);
114

Dan Field's avatar
Dan Field committed
115 116 117 118 119
        // Different shape triggers repaint.
        root.clipper = const ShapeBorderClipper(shape: StadiumBorder());
        expect(root.debugNeedsPaint, isTrue);
      }
      debugDefaultTargetPlatformOverride = null;
120 121
    });

122
    test('compositing', () {
Dan Field's avatar
Dan Field committed
123 124 125 126 127 128 129
      for (final TargetPlatform platform in TargetPlatform.values) {
        debugDefaultTargetPlatformOverride = platform;
        final RenderPhysicalShape root = RenderPhysicalShape(
          color: const Color(0xffff00ff),
          clipper: const ShapeBorderClipper(shape: CircleBorder()),
        );
        layout(root, phase: EnginePhase.composite);
130
        expect(root.needsCompositing, isFalse);
Dan Field's avatar
Dan Field committed
131 132 133 134

        // On non-Fuchsia platforms, we composite physical shape layers
        root.elevation = 1.0;
        pumpFrame(phase: EnginePhase.composite);
135
        expect(root.needsCompositing, isFalse);
Dan Field's avatar
Dan Field committed
136 137 138

        root.elevation = 0.0;
        pumpFrame(phase: EnginePhase.composite);
139
        expect(root.needsCompositing, isFalse);
Dan Field's avatar
Dan Field committed
140
      }
141 142 143
      debugDefaultTargetPlatformOverride = null;
    });
  });
144 145

  test('RenderRepaintBoundary can capture images of itself', () async {
146 147
    RenderRepaintBoundary boundary = RenderRepaintBoundary();
    layout(boundary, constraints: BoxConstraints.tight(const Size(100.0, 200.0)));
148 149 150 151 152 153
    pumpFrame(phase: EnginePhase.composite);
    ui.Image image = await boundary.toImage();
    expect(image.width, equals(100));
    expect(image.height, equals(200));

    // Now with pixel ratio set to something other than 1.0.
154 155
    boundary = RenderRepaintBoundary();
    layout(boundary, constraints: BoxConstraints.tight(const Size(100.0, 200.0)));
156 157 158 159 160 161
    pumpFrame(phase: EnginePhase.composite);
    image = await boundary.toImage(pixelRatio: 2.0);
    expect(image.width, equals(200));
    expect(image.height, equals(400));

    // Try building one with two child layers and make sure it renders them both.
162 163 164
    boundary = RenderRepaintBoundary();
    final RenderStack stack = RenderStack()..alignment = Alignment.topLeft;
    final RenderDecoratedBox blackBox = RenderDecoratedBox(
165 166 167 168 169 170 171 172 173 174
      decoration: const BoxDecoration(color: Color(0xff000000)),
      child: RenderConstrainedBox(
        additionalConstraints: BoxConstraints.tight(const Size.square(20.0)),
      ),
    );
    stack.add(
      RenderOpacity()
        ..opacity = 0.5
        ..child = blackBox,
    );
175
    final RenderDecoratedBox whiteBox = RenderDecoratedBox(
176 177 178 179 180
      decoration: const BoxDecoration(color: Color(0xffffffff)),
      child: RenderConstrainedBox(
        additionalConstraints: BoxConstraints.tight(const Size.square(10.0)),
      ),
    );
181
    final RenderPositionedBox positioned = RenderPositionedBox(
182 183 184 185 186 187 188
      widthFactor: 2.0,
      heightFactor: 2.0,
      alignment: Alignment.topRight,
      child: whiteBox,
    );
    stack.add(positioned);
    boundary.child = stack;
189
    layout(boundary, constraints: BoxConstraints.tight(const Size(20.0, 20.0)));
190 191 192 193
    pumpFrame(phase: EnginePhase.composite);
    image = await boundary.toImage();
    expect(image.width, equals(20));
    expect(image.height, equals(20));
194
    ByteData data = (await image.toByteData())!;
195 196 197

    int getPixel(int x, int y) => data.getUint32((x + y * image.width) * 4);

198 199
    expect(data.lengthInBytes, equals(20 * 20 * 4));
    expect(data.elementSizeInBytes, equals(1));
200
    expect(getPixel(0, 0), equals(0x00000080));
201 202
    expect(getPixel(image.width - 1, 0 ), equals(0xffffffff));

203
    final OffsetLayer layer = boundary.debugLayer! as OffsetLayer;
204 205 206 207

    image = await layer.toImage(Offset.zero & const Size(20.0, 20.0));
    expect(image.width, equals(20));
    expect(image.height, equals(20));
208
    data = (await image.toByteData())!;
209
    expect(getPixel(0, 0), equals(0x00000080));
210 211 212 213 214 215
    expect(getPixel(image.width - 1, 0 ), equals(0xffffffff));

    // non-zero offsets.
    image = await layer.toImage(const Offset(-10.0, -10.0) & const Size(30.0, 30.0));
    expect(image.width, equals(30));
    expect(image.height, equals(30));
216
    data = (await image.toByteData())!;
217
    expect(getPixel(0, 0), equals(0x00000000));
218
    expect(getPixel(10, 10), equals(0x00000080));
219 220 221 222 223 224 225
    expect(getPixel(image.width - 1, 0), equals(0x00000000));
    expect(getPixel(image.width - 1, 10), equals(0xffffffff));

    // offset combined with a custom pixel ratio.
    image = await layer.toImage(const Offset(-10.0, -10.0) & const Size(30.0, 30.0), pixelRatio: 2.0);
    expect(image.width, equals(60));
    expect(image.height, equals(60));
226
    data = (await image.toByteData())!;
227
    expect(getPixel(0, 0), equals(0x00000000));
228
    expect(getPixel(20, 20), equals(0x00000080));
229 230
    expect(getPixel(image.width - 1, 0), equals(0x00000000));
    expect(getPixel(image.width - 1, 20), equals(0xffffffff));
231
  }, skip: isBrowser); // https://github.com/flutter/flutter/issues/49857
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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
  test('RenderRepaintBoundary can capture images of itself synchronously', () async {
    RenderRepaintBoundary boundary = RenderRepaintBoundary();
    layout(boundary, constraints: BoxConstraints.tight(const Size(100.0, 200.0)));
    pumpFrame(phase: EnginePhase.composite);
    ui.Image image = boundary.toImageSync();
    expect(image.width, equals(100));
    expect(image.height, equals(200));

    // Now with pixel ratio set to something other than 1.0.
    boundary = RenderRepaintBoundary();
    layout(boundary, constraints: BoxConstraints.tight(const Size(100.0, 200.0)));
    pumpFrame(phase: EnginePhase.composite);
    image = boundary.toImageSync(pixelRatio: 2.0);
    expect(image.width, equals(200));
    expect(image.height, equals(400));

    // Try building one with two child layers and make sure it renders them both.
    boundary = RenderRepaintBoundary();
    final RenderStack stack = RenderStack()..alignment = Alignment.topLeft;
    final RenderDecoratedBox blackBox = RenderDecoratedBox(
      decoration: const BoxDecoration(color: Color(0xff000000)),
      child: RenderConstrainedBox(
        additionalConstraints: BoxConstraints.tight(const Size.square(20.0)),
      ),
    );
    stack.add(
      RenderOpacity()
        ..opacity = 0.5
        ..child = blackBox,
    );
    final RenderDecoratedBox whiteBox = RenderDecoratedBox(
      decoration: const BoxDecoration(color: Color(0xffffffff)),
      child: RenderConstrainedBox(
        additionalConstraints: BoxConstraints.tight(const Size.square(10.0)),
      ),
    );
    final RenderPositionedBox positioned = RenderPositionedBox(
      widthFactor: 2.0,
      heightFactor: 2.0,
      alignment: Alignment.topRight,
      child: whiteBox,
    );
    stack.add(positioned);
    boundary.child = stack;
    layout(boundary, constraints: BoxConstraints.tight(const Size(20.0, 20.0)));
    pumpFrame(phase: EnginePhase.composite);
    image = boundary.toImageSync();
    expect(image.width, equals(20));
    expect(image.height, equals(20));
    ByteData data = (await image.toByteData())!;

    int getPixel(int x, int y) => data.getUint32((x + y * image.width) * 4);

    expect(data.lengthInBytes, equals(20 * 20 * 4));
    expect(data.elementSizeInBytes, equals(1));
    expect(getPixel(0, 0), equals(0x00000080));
    expect(getPixel(image.width - 1, 0 ), equals(0xffffffff));

    final OffsetLayer layer = boundary.debugLayer! as OffsetLayer;

    image = layer.toImageSync(Offset.zero & const Size(20.0, 20.0));
    expect(image.width, equals(20));
    expect(image.height, equals(20));
    data = (await image.toByteData())!;
    expect(getPixel(0, 0), equals(0x00000080));
    expect(getPixel(image.width - 1, 0 ), equals(0xffffffff));

    // non-zero offsets.
    image = layer.toImageSync(const Offset(-10.0, -10.0) & const Size(30.0, 30.0));
    expect(image.width, equals(30));
    expect(image.height, equals(30));
    data = (await image.toByteData())!;
    expect(getPixel(0, 0), equals(0x00000000));
    expect(getPixel(10, 10), equals(0x00000080));
    expect(getPixel(image.width - 1, 0), equals(0x00000000));
    expect(getPixel(image.width - 1, 10), equals(0xffffffff));

    // offset combined with a custom pixel ratio.
    image = layer.toImageSync(const Offset(-10.0, -10.0) & const Size(30.0, 30.0), pixelRatio: 2.0);
    expect(image.width, equals(60));
    expect(image.height, equals(60));
    data = (await image.toByteData())!;
    expect(getPixel(0, 0), equals(0x00000000));
    expect(getPixel(20, 20), equals(0x00000080));
    expect(getPixel(image.width - 1, 0), equals(0x00000000));
    expect(getPixel(image.width - 1, 20), equals(0xffffffff));
  }, skip: isBrowser); // https://github.com/flutter/flutter/issues/49857

321
  test('RenderOpacity does not composite if it is transparent', () {
322
    final RenderOpacity renderOpacity = RenderOpacity(
323
      opacity: 0.0,
324
      child: RenderSizedBox(const Size(1.0, 1.0)), // size doesn't matter
325 326 327 328 329 330
    );

    layout(renderOpacity, phase: EnginePhase.composite);
    expect(renderOpacity.needsCompositing, false);
  });

331
  test('RenderOpacity does composite if it is opaque', () {
332 333
    final RenderOpacity renderOpacity = RenderOpacity(
      child: RenderSizedBox(const Size(1.0, 1.0)), // size doesn't matter
334 335
    );

336
    layout(renderOpacity, phase: EnginePhase.composite);
337
    expect(renderOpacity.needsCompositing, true);
338 339 340 341 342 343 344 345
  });

  test('RenderOpacity does composite if it is partially opaque', () {
    final RenderOpacity renderOpacity = RenderOpacity(
      opacity: 0.1,
      child: RenderSizedBox(const Size(1.0, 1.0)), // size doesn't matter
    );

346
    layout(renderOpacity, phase: EnginePhase.composite);
347
    expect(renderOpacity.needsCompositing, true);
348 349
  });

350 351 352
  test('RenderOpacity reuses its layer', () {
    _testLayerReuse<OpacityLayer>(RenderOpacity(
      opacity: 0.5,  // must not be 0 or 1.0. Otherwise, it won't create a layer
353 354 355
      child: RenderRepaintBoundary(
        child: RenderSizedBox(const Size(1.0, 1.0)),
      ), // size doesn't matter
356 357 358
    ));
  });

359
  test('RenderAnimatedOpacity does not composite if it is transparent', () async {
360
    final Animation<double> opacityAnimation = AnimationController(
361
      vsync: FakeTickerProvider(),
362 363
    )..value = 0.0;

364
    final RenderAnimatedOpacity renderAnimatedOpacity = RenderAnimatedOpacity(
365
      opacity: opacityAnimation,
366
      child: RenderSizedBox(const Size(1.0, 1.0)), // size doesn't matter
367 368 369 370 371 372
    );

    layout(renderAnimatedOpacity, phase: EnginePhase.composite);
    expect(renderAnimatedOpacity.needsCompositing, false);
  });

373
  test('RenderAnimatedOpacity does composite if it is opaque', () {
374
    final Animation<double> opacityAnimation = AnimationController(
375
      vsync: FakeTickerProvider(),
376 377
    )..value = 1.0;

378
    final RenderAnimatedOpacity renderAnimatedOpacity = RenderAnimatedOpacity(
379
      opacity: opacityAnimation,
380
      child: RenderSizedBox(const Size(1.0, 1.0)), // size doesn't matter
381 382
    );

383
    layout(renderAnimatedOpacity, phase: EnginePhase.composite);
384
    expect(renderAnimatedOpacity.needsCompositing, true);
385 386 387 388 389 390 391 392 393 394 395 396
  });

  test('RenderAnimatedOpacity does composite if it is partially opaque', () {
    final Animation<double> opacityAnimation = AnimationController(
      vsync: FakeTickerProvider(),
    )..value = 0.5;

    final RenderAnimatedOpacity renderAnimatedOpacity = RenderAnimatedOpacity(
      opacity: opacityAnimation,
      child: RenderSizedBox(const Size(1.0, 1.0)), // size doesn't matter
    );

397
    layout(renderAnimatedOpacity, phase: EnginePhase.composite);
Dan Field's avatar
Dan Field committed
398
    expect(renderAnimatedOpacity.needsCompositing, true);
399
  });
400 401 402

  test('RenderAnimatedOpacity reuses its layer', () {
    final Animation<double> opacityAnimation = AnimationController(
403
      vsync: FakeTickerProvider(),
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
    )..value = 0.5;  // must not be 0 or 1.0. Otherwise, it won't create a layer

    _testLayerReuse<OpacityLayer>(RenderAnimatedOpacity(
      opacity: opacityAnimation,
      child: RenderSizedBox(const Size(1.0, 1.0)), // size doesn't matter
    ));
  });

  test('RenderShaderMask reuses its layer', () {
    _testLayerReuse<ShaderMaskLayer>(RenderShaderMask(
      shaderCallback: (Rect rect) {
        return ui.Gradient.radial(
          rect.center,
          rect.shortestSide / 2.0,
          const <Color>[Color.fromRGBO(0, 0, 0, 1.0), Color.fromRGBO(255, 255, 255, 1.0)],
        );
      },
      child: RenderSizedBox(const Size(1.0, 1.0)), // size doesn't matter
    ));
  });

  test('RenderBackdropFilter reuses its layer', () {
    _testLayerReuse<BackdropFilterLayer>(RenderBackdropFilter(
      filter: ui.ImageFilter.blur(),
      child: RenderSizedBox(const Size(1.0, 1.0)), // size doesn't matter
    ));
  });

  test('RenderClipRect reuses its layer', () {
    _testLayerReuse<ClipRectLayer>(RenderClipRect(
      clipper: _TestRectClipper(),
435
      child: RenderRepaintBoundary(
436 437 438 439 440 441 442 443
        child: RenderSizedBox(const Size(1.0, 1.0)),
      ), // size doesn't matter
    ));
  });

  test('RenderClipRRect reuses its layer', () {
    _testLayerReuse<ClipRRectLayer>(RenderClipRRect(
      clipper: _TestRRectClipper(),
444
      child: RenderRepaintBoundary(
445 446 447 448 449 450 451 452
        child: RenderSizedBox(const Size(1.0, 1.0)),
      ), // size doesn't matter
    ));
  });

  test('RenderClipOval reuses its layer', () {
    _testLayerReuse<ClipPathLayer>(RenderClipOval(
      clipper: _TestRectClipper(),
453
      child: RenderRepaintBoundary(
454 455 456 457 458 459 460 461
        child: RenderSizedBox(const Size(1.0, 1.0)),
      ), // size doesn't matter
    ));
  });

  test('RenderClipPath reuses its layer', () {
    _testLayerReuse<ClipPathLayer>(RenderClipPath(
      clipper: _TestPathClipper(),
462
      child: RenderRepaintBoundary(
463 464 465 466 467 468
        child: RenderSizedBox(const Size(1.0, 1.0)),
      ), // size doesn't matter
    ));
  });

  test('RenderPhysicalModel reuses its layer', () {
469 470
    _testLayerReuse<ClipRRectLayer>(RenderPhysicalModel(
      clipBehavior: Clip.hardEdge,
471
      color: const Color.fromRGBO(0, 0, 0, 1.0),
472
      child: RenderRepaintBoundary(
473 474 475 476 477 478
        child: RenderSizedBox(const Size(1.0, 1.0)),
      ), // size doesn't matter
    ));
  });

  test('RenderPhysicalShape reuses its layer', () {
479
    _testLayerReuse<ClipPathLayer>(RenderPhysicalShape(
480
      clipper: _TestPathClipper(),
481
      clipBehavior: Clip.hardEdge,
482
      color: const Color.fromRGBO(0, 0, 0, 1.0),
483
      child: RenderRepaintBoundary(
484 485 486 487 488 489 490 491 492
        child: RenderSizedBox(const Size(1.0, 1.0)),
      ), // size doesn't matter
    ));
  });

  test('RenderTransform reuses its layer', () {
    _testLayerReuse<TransformLayer>(RenderTransform(
      // Use a 3D transform to force compositing.
      transform: Matrix4.rotationX(0.1),
493
      child: RenderRepaintBoundary(
494 495 496 497 498
        child: RenderSizedBox(const Size(1.0, 1.0)),
      ), // size doesn't matter
    ));
  });

499
  void testFittedBoxWithClipRectLayer() {
500 501
    _testLayerReuse<ClipRectLayer>(RenderFittedBox(
      fit: BoxFit.cover,
502
      clipBehavior: Clip.hardEdge,
503
      // Inject opacity under the clip to force compositing.
504
      child: RenderRepaintBoundary(
505 506 507 508 509
        child: RenderSizedBox(const Size(100.0, 200.0)),
      ), // size doesn't matter
    ));
  }

510
  void testFittedBoxWithTransformLayer() {
511 512 513
    _testLayerReuse<TransformLayer>(RenderFittedBox(
      fit: BoxFit.fill,
      // Inject opacity under the clip to force compositing.
514
      child: RenderRepaintBoundary(
515 516 517 518 519 520
        child: RenderSizedBox(const Size(1, 1)),
      ), // size doesn't matter
    ));
  }

  test('RenderFittedBox reuses ClipRectLayer', () {
521
    testFittedBoxWithClipRectLayer();
522 523 524
  });

  test('RenderFittedBox reuses TransformLayer', () {
525
    testFittedBoxWithTransformLayer();
526 527 528
  });

  test('RenderFittedBox switches between ClipRectLayer and TransformLayer, and reuses them', () {
529
    testFittedBoxWithClipRectLayer();
530 531

    // clip -> transform
532
    testFittedBoxWithTransformLayer();
533
    // transform -> clip
534
    testFittedBoxWithClipRectLayer();
535
  });
536

537 538
  test('RenderFittedBox respects clipBehavior', () {
    const BoxConstraints viewport = BoxConstraints(maxHeight: 100.0, maxWidth: 100.0);
539 540 541 542 543 544 545 546 547 548 549 550 551
    for (final Clip? clip in <Clip?>[null, ...Clip.values]) {
      final TestClipPaintingContext context = TestClipPaintingContext();
      final RenderFittedBox box;
      switch (clip) {
        case Clip.none:
        case Clip.hardEdge:
        case Clip.antiAlias:
        case Clip.antiAliasWithSaveLayer:
          box = RenderFittedBox(child: box200x200, fit: BoxFit.none, clipBehavior: clip!);
        case null:
          box = RenderFittedBox(child: box200x200, fit: BoxFit.none);
      }
      layout(box, constraints: viewport, phase: EnginePhase.composite, onErrors: expectNoFlutterErrors);
552
      box.paint(context, Offset.zero);
553 554
      // By default, clipBehavior should be Clip.none
      expect(context.clipBehavior, equals(clip ?? Clip.none));
555 556 557
    }
  });

558 559 560 561 562 563 564 565 566
  test('RenderMouseRegion can change properties when detached', () {
    final RenderMouseRegion object = RenderMouseRegion();
    object
      ..opaque = false
      ..onEnter = (_) {}
      ..onExit = (_) {}
      ..onHover = (_) {};
    // Passes if no error is thrown
  });
567 568 569 570 571 572 573 574 575 576 577 578

  test('RenderFractionalTranslation updates its semantics after its translation value is set', () {
    final _TestSemanticsUpdateRenderFractionalTranslation box = _TestSemanticsUpdateRenderFractionalTranslation(
      translation: const Offset(0.5, 0.5),
    );
    layout(box, constraints: BoxConstraints.tight(const Size(200.0, 200.0)));
    expect(box.markNeedsSemanticsUpdateCallCount, 1);
    box.translation = const Offset(0.4, 0.4);
    expect(box.markNeedsSemanticsUpdateCallCount, 2);
    box.translation = const Offset(0.3, 0.3);
    expect(box.markNeedsSemanticsUpdateCallCount, 3);
  });
579 580 581 582 583 584 585 586

  test('RenderFollowerLayer hit test without a leader layer and the showWhenUnlinked is true', () {
    final RenderFollowerLayer follower = RenderFollowerLayer(
      link: LayerLink(),
      child: RenderSizedBox(const Size(1.0, 1.0)),
    );
    layout(follower, constraints: BoxConstraints.tight(const Size(200.0, 200.0)));
    final BoxHitTestResult hitTestResult = BoxHitTestResult();
587
    expect(follower.hitTest(hitTestResult, position: Offset.zero), isTrue);
588 589 590 591 592 593 594 595 596 597
  });

  test('RenderFollowerLayer hit test without a leader layer and the showWhenUnlinked is false', () {
    final RenderFollowerLayer follower = RenderFollowerLayer(
      link: LayerLink(),
      showWhenUnlinked: false,
      child: RenderSizedBox(const Size(1.0, 1.0)),
    );
    layout(follower, constraints: BoxConstraints.tight(const Size(200.0, 200.0)));
    final BoxHitTestResult hitTestResult = BoxHitTestResult();
598
    expect(follower.hitTest(hitTestResult, position: Offset.zero), isFalse);
599 600 601 602 603 604 605 606 607 608 609 610 611 612
  });

  test('RenderFollowerLayer hit test with a leader layer and the showWhenUnlinked is true', () {
    // Creates a layer link with a leader.
    final LayerLink link = LayerLink();
    final LeaderLayer leader = LeaderLayer(link: link);
    leader.attach(Object());

    final RenderFollowerLayer follower = RenderFollowerLayer(
      link: link,
      child: RenderSizedBox(const Size(1.0, 1.0)),
    );
    layout(follower, constraints: BoxConstraints.tight(const Size(200.0, 200.0)));
    final BoxHitTestResult hitTestResult = BoxHitTestResult();
613
    expect(follower.hitTest(hitTestResult, position: Offset.zero), isTrue);
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
  });

  test('RenderFollowerLayer hit test with a leader layer and the showWhenUnlinked is false', () {
    // Creates a layer link with a leader.
    final LayerLink link = LayerLink();
    final LeaderLayer leader = LeaderLayer(link: link);
    leader.attach(Object());

    final RenderFollowerLayer follower = RenderFollowerLayer(
      link: link,
      showWhenUnlinked: false,
      child: RenderSizedBox(const Size(1.0, 1.0)),
    );
    layout(follower, constraints: BoxConstraints.tight(const Size(200.0, 200.0)));
    final BoxHitTestResult hitTestResult = BoxHitTestResult();
    // The follower is still hit testable because there is a leader layer.
630
    expect(follower.hitTest(hitTestResult, position: Offset.zero), isTrue);
631
  });
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 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 797 798 799 800 801 802 803

  test('RenderObject can become a repaint boundary', () {
    final ConditionalRepaintBoundary childBox = ConditionalRepaintBoundary();
    final ConditionalRepaintBoundary renderBox = ConditionalRepaintBoundary(child: childBox);

    layout(renderBox, phase: EnginePhase.composite);

    expect(childBox.paintCount, 1);
    expect(renderBox.paintCount, 1);

    renderBox.isRepaintBoundary = true;
    renderBox.markNeedsCompositingBitsUpdate();
    renderBox.markNeedsCompositedLayerUpdate();

    pumpFrame(phase: EnginePhase.composite);

    // The first time the render object becomes a repaint boundary
    // we must repaint from the parent to allow the layer to be
    // created.
    expect(childBox.paintCount, 2);
    expect(renderBox.paintCount, 2);
    expect(renderBox.debugLayer, isA<OffsetLayer>());

    renderBox.markNeedsCompositedLayerUpdate();
    expect(renderBox.debugNeedsPaint, false);
    expect(renderBox.debugNeedsCompositedLayerUpdate, true);

    pumpFrame(phase: EnginePhase.composite);

    // The second time the layer exists and we can skip paint.
    expect(childBox.paintCount, 2);
    expect(renderBox.paintCount, 2);
    expect(renderBox.debugLayer, isA<OffsetLayer>());

    renderBox.isRepaintBoundary = false;
    renderBox.markNeedsCompositingBitsUpdate();

    pumpFrame(phase: EnginePhase.composite);

    // Once it stops being a repaint boundary we must repaint to
    // remove the layer. its required that the render object
    // perform this action in paint.
    expect(childBox.paintCount, 3);
    expect(renderBox.paintCount, 3);
    expect(renderBox.debugLayer, null);

    // When the render object is not a repaint boundary, calling
    // markNeedsLayerPropertyUpdate is the same as calling
    // markNeedsPaint.

    renderBox.markNeedsCompositedLayerUpdate();
    expect(renderBox.debugNeedsPaint, true);
    expect(renderBox.debugNeedsCompositedLayerUpdate, true);
  });

  test('RenderObject with repaint boundary asserts when a composited layer is replaced during layer property update', () {
    final ConditionalRepaintBoundary childBox = ConditionalRepaintBoundary(isRepaintBoundary: true);
    final ConditionalRepaintBoundary renderBox = ConditionalRepaintBoundary(child: childBox);

    // Ignore old layer.
    childBox.offsetLayerFactory = (OffsetLayer? oldLayer) {
      return TestOffsetLayerA();
    };

    layout(renderBox, phase: EnginePhase.composite);

    expect(childBox.paintCount, 1);
    expect(renderBox.paintCount, 1);

    renderBox.markNeedsCompositedLayerUpdate();

    pumpFrame(phase: EnginePhase.composite, onErrors: expectAssertionError);
  }, skip: kIsWeb); // https://github.com/flutter/flutter/issues/102086

  test('RenderObject with repaint boundary asserts when a composited layer is replaced during painting', () {
    final ConditionalRepaintBoundary childBox = ConditionalRepaintBoundary(isRepaintBoundary: true);
    final ConditionalRepaintBoundary renderBox = ConditionalRepaintBoundary(child: childBox);

    // Ignore old layer.
    childBox.offsetLayerFactory = (OffsetLayer? oldLayer) {
      return TestOffsetLayerA();
    };

    layout(renderBox, phase: EnginePhase.composite);

    expect(childBox.paintCount, 1);
    expect(renderBox.paintCount, 1);
    renderBox.markNeedsPaint();

    pumpFrame(phase: EnginePhase.composite, onErrors: expectAssertionError);
  }, skip: kIsWeb); // https://github.com/flutter/flutter/issues/102086

  test('RenderObject with repaint boundary asserts when a composited layer tries to update its own offset', () {
    final ConditionalRepaintBoundary childBox = ConditionalRepaintBoundary(isRepaintBoundary: true);
    final ConditionalRepaintBoundary renderBox = ConditionalRepaintBoundary(child: childBox);

    // Ignore old layer.
    childBox.offsetLayerFactory = (OffsetLayer? oldLayer) {
      return (oldLayer ?? TestOffsetLayerA())..offset = const Offset(2133, 4422);
    };

    layout(renderBox, phase: EnginePhase.composite);

    expect(childBox.paintCount, 1);
    expect(renderBox.paintCount, 1);
    renderBox.markNeedsPaint();

    pumpFrame(phase: EnginePhase.composite, onErrors: expectAssertionError);
  }, skip: kIsWeb); // https://github.com/flutter/flutter/issues/102086

  test('RenderObject markNeedsPaint while repaint boundary, and then updated to no longer be a repaint boundary with '
    'calling markNeedsCompositingBitsUpdate 1', () {
    final ConditionalRepaintBoundary childBox = ConditionalRepaintBoundary(isRepaintBoundary: true);
    final ConditionalRepaintBoundary renderBox = ConditionalRepaintBoundary(child: childBox);
    // Ignore old layer.
    childBox.offsetLayerFactory = (OffsetLayer? oldLayer) {
      return oldLayer ?? TestOffsetLayerA();
    };

    layout(renderBox, phase: EnginePhase.composite);

    expect(childBox.paintCount, 1);
    expect(renderBox.paintCount, 1);

    childBox.markNeedsPaint();
    childBox.isRepaintBoundary = false;
    childBox.markNeedsCompositingBitsUpdate();

    expect(() => pumpFrame(phase: EnginePhase.composite), returnsNormally);
  });

  test('RenderObject markNeedsPaint while repaint boundary, and then updated to no longer be a repaint boundary with '
    'calling markNeedsCompositingBitsUpdate 2', () {
    final ConditionalRepaintBoundary childBox = ConditionalRepaintBoundary(isRepaintBoundary: true);
    final ConditionalRepaintBoundary renderBox = ConditionalRepaintBoundary(child: childBox);
    // Ignore old layer.
    childBox.offsetLayerFactory = (OffsetLayer? oldLayer) {
      return oldLayer ?? TestOffsetLayerA();
    };

    layout(renderBox, phase: EnginePhase.composite);

    expect(childBox.paintCount, 1);
    expect(renderBox.paintCount, 1);

    childBox.isRepaintBoundary = false;
    childBox.markNeedsCompositingBitsUpdate();
    childBox.markNeedsPaint();

    expect(() => pumpFrame(phase: EnginePhase.composite), returnsNormally);
  });

  test('RenderObject markNeedsPaint while repaint boundary, and then updated to no longer be a repaint boundary with '
    'calling markNeedsCompositingBitsUpdate 3', () {
    final ConditionalRepaintBoundary childBox = ConditionalRepaintBoundary(isRepaintBoundary: true);
    final ConditionalRepaintBoundary renderBox = ConditionalRepaintBoundary(child: childBox);
    // Ignore old layer.
    childBox.offsetLayerFactory = (OffsetLayer? oldLayer) {
      return oldLayer ?? TestOffsetLayerA();
    };

    layout(renderBox, phase: EnginePhase.composite);

    expect(childBox.paintCount, 1);
    expect(renderBox.paintCount, 1);

    childBox.isRepaintBoundary = false;
    childBox.markNeedsCompositedLayerUpdate();
    childBox.markNeedsCompositingBitsUpdate();

    expect(() => pumpFrame(phase: EnginePhase.composite), returnsNormally);
  });
804

805 806
  test('Offstage implements paintsChild correctly', () {
    final RenderBox box = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
807
    final RenderBox parent = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
808
    final RenderOffstage offstage = RenderOffstage(offstage: false, child: box);
809
    parent.adoptChild(offstage);
810 811 812 813 814 815 816 817 818 819

    expect(offstage.paintsChild(box), true);

    offstage.offstage = true;

    expect(offstage.paintsChild(box), false);
  });

  test('Opacity implements paintsChild correctly', () {
    final RenderBox box = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
820
    final RenderBox parent = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
821
    final RenderOpacity opacity = RenderOpacity(child: box);
822
    parent.adoptChild(opacity);
823 824 825 826 827 828 829 830 831

    expect(opacity.paintsChild(box), true);

    opacity.opacity = 0;

    expect(opacity.paintsChild(box), false);
  });

  test('AnimatedOpacity sets paint matrix to zero when alpha == 0', () {
832 833
    final RenderBox box = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
    final RenderBox parent = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
834 835
    final AnimationController opacityAnimation = AnimationController(value: 1, vsync: FakeTickerProvider());
    final RenderAnimatedOpacity opacity = RenderAnimatedOpacity(opacity: opacityAnimation, child: box);
836
    parent.adoptChild(opacity);
837 838 839 840 841 842 843 844 845 846 847 848 849

    // Make it listen to the animation.
    opacity.attach(PipelineOwner());

    expect(opacity.paintsChild(box), true);

    opacityAnimation.value = 0;

    expect(opacity.paintsChild(box), false);
  });

  test('AnimatedOpacity sets paint matrix to zero when alpha == 0 (sliver)', () {
    final RenderSliver sliver = RenderSliverToBoxAdapter(child: RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20)));
850
    final RenderBox parent = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
851 852
    final AnimationController opacityAnimation = AnimationController(value: 1, vsync: FakeTickerProvider());
    final RenderSliverAnimatedOpacity opacity = RenderSliverAnimatedOpacity(opacity: opacityAnimation, sliver: sliver);
853
    parent.adoptChild(opacity);
854 855 856 857 858 859 860 861 862 863 864

    // Make it listen to the animation.
    opacity.attach(PipelineOwner());

    expect(opacity.paintsChild(sliver), true);

    opacityAnimation.value = 0;

    expect(opacity.paintsChild(sliver), false);
  });

865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
  test('RenderCustomClip extenders respect clipBehavior when asked to describeApproximateClip', () {
    final RenderBox child = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 200, height: 200));
    final RenderClipRect renderClipRect = RenderClipRect(clipBehavior: Clip.none, child: child);
    layout(renderClipRect);
    expect(
      renderClipRect.describeApproximatePaintClip(child),
      null,
    );
    renderClipRect.clipBehavior = Clip.hardEdge;
    expect(
      renderClipRect.describeApproximatePaintClip(child),
      Offset.zero & renderClipRect.size,
    );
    renderClipRect.clipBehavior = Clip.antiAlias;
    expect(
      renderClipRect.describeApproximatePaintClip(child),
      Offset.zero & renderClipRect.size,
    );
    renderClipRect.clipBehavior = Clip.antiAliasWithSaveLayer;
    expect(
      renderClipRect.describeApproximatePaintClip(child),
      Offset.zero & renderClipRect.size,
    );
  });
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

  // Simulate painting a RenderBox as if 'debugPaintSizeEnabled == true'
  Function(PaintingContext, Offset) debugPaint(RenderBox renderBox) {
    layout(renderBox);
    pumpFrame(phase: EnginePhase.compositingBits);
    return (PaintingContext context, Offset offset) {
      renderBox.paint(context, offset);
      renderBox.debugPaintSize(context, offset);
    };
  }

  test('RenderClipPath.debugPaintSize draws a path and a debug text when clipBehavior is not Clip.none', () {
    Function(PaintingContext, Offset) debugPaintClipRect(Clip clip) {
      final RenderBox child = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 200, height: 200));
      final RenderClipPath renderClipPath = RenderClipPath(clipBehavior: clip, child: child);
      return debugPaint(renderClipPath);
    }

    // RenderClipPath.debugPaintSize draws when clipBehavior is not Clip.none
    expect(debugPaintClipRect(Clip.hardEdge), paintsExactlyCountTimes(#drawPath, 1));
    expect(debugPaintClipRect(Clip.hardEdge), paintsExactlyCountTimes(#drawParagraph, 1));

    // RenderClipPath.debugPaintSize does not draw when clipBehavior is Clip.none
    // Regression test for https://github.com/flutter/flutter/issues/105969
    expect(debugPaintClipRect(Clip.none), paintsExactlyCountTimes(#drawPath, 0));
    expect(debugPaintClipRect(Clip.none), paintsExactlyCountTimes(#drawParagraph, 0));
  });

  test('RenderClipRect.debugPaintSize draws a rect and a debug text when clipBehavior is not Clip.none', () {
    Function(PaintingContext, Offset) debugPaintClipRect(Clip clip) {
      final RenderBox child = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 200, height: 200));
      final RenderClipRect renderClipRect = RenderClipRect(clipBehavior: clip, child: child);
      return debugPaint(renderClipRect);
    }

    // RenderClipRect.debugPaintSize draws when clipBehavior is not Clip.none
    expect(debugPaintClipRect(Clip.hardEdge), paintsExactlyCountTimes(#drawRect, 1));
    expect(debugPaintClipRect(Clip.hardEdge), paintsExactlyCountTimes(#drawParagraph, 1));

    // RenderClipRect.debugPaintSize does not draw when clipBehavior is Clip.none
    expect(debugPaintClipRect(Clip.none), paintsExactlyCountTimes(#drawRect, 0));
    expect(debugPaintClipRect(Clip.none), paintsExactlyCountTimes(#drawParagraph, 0));
  });

  test('RenderClipRRect.debugPaintSize draws a rounded rect and a debug text when clipBehavior is not Clip.none', () {
    Function(PaintingContext, Offset) debugPaintClipRRect(Clip clip) {
      final RenderBox child = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 200, height: 200));
      final RenderClipRRect renderClipRRect = RenderClipRRect(clipBehavior: clip, child: child);
      return debugPaint(renderClipRRect);
    }

    // RenderClipRRect.debugPaintSize draws when clipBehavior is not Clip.none
    expect(debugPaintClipRRect(Clip.hardEdge), paintsExactlyCountTimes(#drawRRect, 1));
    expect(debugPaintClipRRect(Clip.hardEdge), paintsExactlyCountTimes(#drawParagraph, 1));

    // RenderClipRRect.debugPaintSize does not draw when clipBehavior is Clip.none
    expect(debugPaintClipRRect(Clip.none), paintsExactlyCountTimes(#drawRRect, 0));
    expect(debugPaintClipRRect(Clip.none), paintsExactlyCountTimes(#drawParagraph, 0));
  });

  test('RenderClipOval.debugPaintSize draws a path and a debug text when clipBehavior is not Clip.none', () {
    Function(PaintingContext, Offset) debugPaintClipOval(Clip clip) {
      final RenderBox child = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 200, height: 200));
      final RenderClipOval renderClipOval = RenderClipOval(clipBehavior: clip, child: child);
      return debugPaint(renderClipOval);
    }

    // RenderClipOval.debugPaintSize draws when clipBehavior is not Clip.none
    expect(debugPaintClipOval(Clip.hardEdge), paintsExactlyCountTimes(#drawPath, 1));
    expect(debugPaintClipOval(Clip.hardEdge), paintsExactlyCountTimes(#drawParagraph, 1));

    // RenderClipOval.debugPaintSize does not draw when clipBehavior is Clip.none
    expect(debugPaintClipOval(Clip.none), paintsExactlyCountTimes(#drawPath, 0));
    expect(debugPaintClipOval(Clip.none), paintsExactlyCountTimes(#drawParagraph, 0));
  });
964 965 966 967 968 969 970 971 972 973 974

  test('RenderProxyBox behavior can be mixed in along with another base class', () {
    final RenderFancyProxyBox fancyProxyBox = RenderFancyProxyBox(fancy: 6);
    // Box has behavior from its base class:
    expect(fancyProxyBox.fancyMethod(), 36);
    // Box has behavior from RenderProxyBox:
    expect(
      fancyProxyBox.computeDryLayout(const BoxConstraints(minHeight: 8)),
      const Size(0, 8),
    );
  });
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
}

class _TestRectClipper extends CustomClipper<Rect> {
  @override
  Rect getClip(Size size) {
    return Rect.zero;
  }

  @override
  Rect getApproximateClipRect(Size size) => getClip(size);

  @override
  bool shouldReclip(_TestRectClipper oldClipper) => true;
}

class _TestRRectClipper extends CustomClipper<RRect> {
  @override
  RRect getClip(Size size) {
    return RRect.zero;
  }

  @override
  Rect getApproximateClipRect(Size size) => getClip(size).outerRect;

  @override
  bool shouldReclip(_TestRRectClipper oldClipper) => true;
1001 1002
}

1003 1004 1005
// Forces two frames and checks that:
// - a layer is created on the first frame
// - the layer is reused on the second frame
1006
void _testLayerReuse<L extends Layer>(RenderBox renderObject) {
1007 1008 1009
  expect(L, isNot(Layer));
  expect(renderObject.debugLayer, null);
  layout(renderObject, phase: EnginePhase.paint, constraints: BoxConstraints.tight(const Size(10, 10)));
1010
  final Layer? layer = renderObject.debugLayer;
Dan Field's avatar
Dan Field committed
1011
  expect(layer, isA<L>());
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
  expect(layer, isNotNull);

  // Mark for repaint otherwise pumpFrame is a noop.
  renderObject.markNeedsPaint();
  expect(renderObject.debugNeedsPaint, true);
  pumpFrame(phase: EnginePhase.paint);
  expect(renderObject.debugNeedsPaint, false);
  expect(renderObject.debugLayer, same(layer));
}

class _TestPathClipper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    return Path()
      ..addRect(const Rect.fromLTWH(50.0, 50.0, 100.0, 100.0));
  }
  @override
  bool shouldReclip(_TestPathClipper oldClipper) => false;
}
1031 1032 1033

class _TestSemanticsUpdateRenderFractionalTranslation extends RenderFractionalTranslation {
  _TestSemanticsUpdateRenderFractionalTranslation({
1034 1035
    required super.translation,
  });
1036 1037 1038 1039 1040 1041 1042 1043 1044

  int markNeedsSemanticsUpdateCallCount = 0;

  @override
  void markNeedsSemanticsUpdate() {
    markNeedsSemanticsUpdateCallCount++;
    super.markNeedsSemanticsUpdate();
  }
}
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072

class ConditionalRepaintBoundary extends RenderProxyBox {
  ConditionalRepaintBoundary({this.isRepaintBoundary = false, RenderBox? child}) : super(child);

  @override
  bool isRepaintBoundary = false;

  OffsetLayer Function(OffsetLayer?)? offsetLayerFactory;

  int paintCount = 0;

  @override
  OffsetLayer updateCompositedLayer({required covariant OffsetLayer? oldLayer}) {
    if (offsetLayerFactory != null) {
      return offsetLayerFactory!.call(oldLayer);
    }
    return super.updateCompositedLayer(oldLayer: oldLayer);
  }

  @override
  void paint(PaintingContext context, Offset offset) {
    paintCount += 1;
    super.paint(context, offset);
  }
}

class TestOffsetLayerA extends OffsetLayer {}

1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
class RenderFancyBox extends RenderBox {
  RenderFancyBox({required this.fancy}) : super();

  late int fancy;

  int fancyMethod() {
    return fancy * fancy;
  }
}

class RenderFancyProxyBox extends RenderFancyBox
    with RenderObjectWithChildMixin<RenderBox>, RenderProxyBoxMixin<RenderBox> {
  RenderFancyProxyBox({required super.fancy});
}

1088 1089 1090 1091 1092 1093 1094
void expectAssertionError() {
  final FlutterErrorDetails errorDetails = TestRenderingFlutterBinding.instance.takeFlutterErrorDetails()!;
  final bool asserted = errorDetails.toString().contains('Failed assertion');
  if (!asserted) {
    FlutterError.reportError(errorDetails);
  }
}