@@ -9,6 +9,7 @@ import 'package:flutter/material.dart';
9
9
import 'package:flutter/rendering.dart' ;
10
10
import 'package:flutter_test/flutter_test.dart' ;
11
11
12
+ import 'mock_canvas.dart' ;
12
13
import 'rendering_tester.dart' ;
13
14
14
15
void main () {
@@ -770,6 +771,81 @@ void main() {
770
771
Offset .zero & renderClipRect.size,
771
772
);
772
773
});
774
+
775
+ // Simulate painting a RenderBox as if 'debugPaintSizeEnabled == true'
776
+ Function (PaintingContext , Offset ) debugPaint (RenderBox renderBox) {
777
+ layout (renderBox);
778
+ pumpFrame (phase: EnginePhase .compositingBits);
779
+ return (PaintingContext context, Offset offset) {
780
+ renderBox.paint (context, offset);
781
+ renderBox.debugPaintSize (context, offset);
782
+ };
783
+ }
784
+
785
+ test ('RenderClipPath.debugPaintSize draws a path and a debug text when clipBehavior is not Clip.none' , () {
786
+ Function (PaintingContext , Offset ) debugPaintClipRect (Clip clip) {
787
+ final RenderBox child = RenderConstrainedBox (additionalConstraints: const BoxConstraints .tightFor (width: 200 , height: 200 ));
788
+ final RenderClipPath renderClipPath = RenderClipPath (clipBehavior: clip, child: child);
789
+ return debugPaint (renderClipPath);
790
+ }
791
+
792
+ // RenderClipPath.debugPaintSize draws when clipBehavior is not Clip.none
793
+ expect (debugPaintClipRect (Clip .hardEdge), paintsExactlyCountTimes (#drawPath, 1 ));
794
+ expect (debugPaintClipRect (Clip .hardEdge), paintsExactlyCountTimes (#drawParagraph, 1 ));
795
+
796
+ // RenderClipPath.debugPaintSize does not draw when clipBehavior is Clip.none
797
+ // Regression test for https://github.com/flutter/flutter/issues/105969
798
+ expect (debugPaintClipRect (Clip .none), paintsExactlyCountTimes (#drawPath, 0 ));
799
+ expect (debugPaintClipRect (Clip .none), paintsExactlyCountTimes (#drawParagraph, 0 ));
800
+ });
801
+
802
+ test ('RenderClipRect.debugPaintSize draws a rect and a debug text when clipBehavior is not Clip.none' , () {
803
+ Function (PaintingContext , Offset ) debugPaintClipRect (Clip clip) {
804
+ final RenderBox child = RenderConstrainedBox (additionalConstraints: const BoxConstraints .tightFor (width: 200 , height: 200 ));
805
+ final RenderClipRect renderClipRect = RenderClipRect (clipBehavior: clip, child: child);
806
+ return debugPaint (renderClipRect);
807
+ }
808
+
809
+ // RenderClipRect.debugPaintSize draws when clipBehavior is not Clip.none
810
+ expect (debugPaintClipRect (Clip .hardEdge), paintsExactlyCountTimes (#drawRect, 1 ));
811
+ expect (debugPaintClipRect (Clip .hardEdge), paintsExactlyCountTimes (#drawParagraph, 1 ));
812
+
813
+ // RenderClipRect.debugPaintSize does not draw when clipBehavior is Clip.none
814
+ expect (debugPaintClipRect (Clip .none), paintsExactlyCountTimes (#drawRect, 0 ));
815
+ expect (debugPaintClipRect (Clip .none), paintsExactlyCountTimes (#drawParagraph, 0 ));
816
+ });
817
+
818
+ test ('RenderClipRRect.debugPaintSize draws a rounded rect and a debug text when clipBehavior is not Clip.none' , () {
819
+ Function (PaintingContext , Offset ) debugPaintClipRRect (Clip clip) {
820
+ final RenderBox child = RenderConstrainedBox (additionalConstraints: const BoxConstraints .tightFor (width: 200 , height: 200 ));
821
+ final RenderClipRRect renderClipRRect = RenderClipRRect (clipBehavior: clip, child: child);
822
+ return debugPaint (renderClipRRect);
823
+ }
824
+
825
+ // RenderClipRRect.debugPaintSize draws when clipBehavior is not Clip.none
826
+ expect (debugPaintClipRRect (Clip .hardEdge), paintsExactlyCountTimes (#drawRRect, 1 ));
827
+ expect (debugPaintClipRRect (Clip .hardEdge), paintsExactlyCountTimes (#drawParagraph, 1 ));
828
+
829
+ // RenderClipRRect.debugPaintSize does not draw when clipBehavior is Clip.none
830
+ expect (debugPaintClipRRect (Clip .none), paintsExactlyCountTimes (#drawRRect, 0 ));
831
+ expect (debugPaintClipRRect (Clip .none), paintsExactlyCountTimes (#drawParagraph, 0 ));
832
+ });
833
+
834
+ test ('RenderClipOval.debugPaintSize draws a path and a debug text when clipBehavior is not Clip.none' , () {
835
+ Function (PaintingContext , Offset ) debugPaintClipOval (Clip clip) {
836
+ final RenderBox child = RenderConstrainedBox (additionalConstraints: const BoxConstraints .tightFor (width: 200 , height: 200 ));
837
+ final RenderClipOval renderClipOval = RenderClipOval (clipBehavior: clip, child: child);
838
+ return debugPaint (renderClipOval);
839
+ }
840
+
841
+ // RenderClipOval.debugPaintSize draws when clipBehavior is not Clip.none
842
+ expect (debugPaintClipOval (Clip .hardEdge), paintsExactlyCountTimes (#drawPath, 1 ));
843
+ expect (debugPaintClipOval (Clip .hardEdge), paintsExactlyCountTimes (#drawParagraph, 1 ));
844
+
845
+ // RenderClipOval.debugPaintSize does not draw when clipBehavior is Clip.none
846
+ expect (debugPaintClipOval (Clip .none), paintsExactlyCountTimes (#drawPath, 0 ));
847
+ expect (debugPaintClipOval (Clip .none), paintsExactlyCountTimes (#drawParagraph, 0 ));
848
+ });
773
849
}
774
850
775
851
class _TestRectClipper extends CustomClipper <Rect > {
0 commit comments