Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fdc7756

Browse files
committed
golden tests
1 parent abf7335 commit fdc7756

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:test/bootstrap/browser.dart';
6+
import 'package:test/test.dart';
7+
import 'package:ui/src/engine.dart';
8+
import 'package:ui/ui.dart';
9+
10+
import 'package:web_engine_tester/golden_tester.dart';
11+
12+
void main() {
13+
internalBootstrapBrowserTest(() => testMain);
14+
}
15+
16+
Future<void> testMain() async {
17+
test('rect stroke with clip', () async {
18+
const Rect region = Rect.fromLTWH(0, 0, 250, 250);
19+
// Set `hasParagraphs` to true to force DOM rendering.
20+
final BitmapCanvas canvas =
21+
BitmapCanvas(region, RenderStrategy()..hasParagraphs = true);
22+
23+
const Rect rect = Rect.fromLTWH(0, 0, 150, 150);
24+
25+
canvas.clipRect(rect.inflate(10.0), ClipOp.intersect);
26+
27+
canvas.drawRect(
28+
rect,
29+
SurfacePaintData()
30+
..color = const Color(0x6fff0000)
31+
..strokeWidth = 20.0
32+
..style = PaintingStyle.stroke,
33+
);
34+
35+
canvas.drawRect(
36+
rect,
37+
SurfacePaintData()
38+
..color = const Color(0x6f0000ff)
39+
..strokeWidth = 10.0
40+
..style = PaintingStyle.stroke,
41+
);
42+
43+
canvas.drawRect(
44+
rect,
45+
SurfacePaintData()
46+
..color = const Color(0xff000000)
47+
..strokeWidth = 1.0
48+
..style = PaintingStyle.stroke,
49+
);
50+
51+
domDocument.body!.style.margin = '0px';
52+
domDocument.body!.append(canvas.rootElement);
53+
await matchGoldenFile('rect_clip_strokes_dom.png', region: region);
54+
canvas.rootElement.remove();
55+
});
56+
57+
test('rrect stroke with clip', () async {
58+
const Rect region = Rect.fromLTWH(0, 0, 250, 250);
59+
// Set `hasParagraphs` to true to force DOM rendering.
60+
final BitmapCanvas canvas =
61+
BitmapCanvas(region, RenderStrategy()..hasParagraphs = true);
62+
63+
final RRect rrect = RRect.fromRectAndRadius(
64+
const Rect.fromLTWH(0, 0, 150, 150),
65+
const Radius.circular(20),
66+
);
67+
68+
canvas.clipRect(rrect.outerRect.inflate(10.0), ClipOp.intersect);
69+
70+
canvas.drawRRect(
71+
rrect,
72+
SurfacePaintData()
73+
..color = const Color(0x6fff0000)
74+
..strokeWidth = 20.0
75+
..style = PaintingStyle.stroke,
76+
);
77+
78+
canvas.drawRRect(
79+
rrect,
80+
SurfacePaintData()
81+
..color = const Color(0x6f0000ff)
82+
..strokeWidth = 10.0
83+
..style = PaintingStyle.stroke,
84+
);
85+
86+
canvas.drawRRect(
87+
rrect,
88+
SurfacePaintData()
89+
..color = const Color(0xff000000)
90+
..strokeWidth = 1.0
91+
..style = PaintingStyle.stroke,
92+
);
93+
94+
domDocument.body!.style.margin = '0px';
95+
domDocument.body!.append(canvas.rootElement);
96+
await matchGoldenFile('rrect_clip_strokes_dom.png', region: region);
97+
canvas.rootElement.remove();
98+
});
99+
100+
test('circle stroke with clip', () async {
101+
const Rect region = Rect.fromLTWH(0, 0, 250, 250);
102+
// Set `hasParagraphs` to true to force DOM rendering.
103+
final BitmapCanvas canvas =
104+
BitmapCanvas(region, RenderStrategy()..hasParagraphs = true);
105+
106+
const Rect rect = Rect.fromLTWH(0, 0, 150, 150);
107+
108+
canvas.clipRect(rect.inflate(10.0), ClipOp.intersect);
109+
110+
canvas.drawCircle(
111+
rect.center,
112+
rect.width / 2,
113+
SurfacePaintData()
114+
..color = const Color(0x6fff0000)
115+
..strokeWidth = 20.0
116+
..style = PaintingStyle.stroke,
117+
);
118+
119+
canvas.drawCircle(
120+
rect.center,
121+
rect.width / 2,
122+
SurfacePaintData()
123+
..color = const Color(0x6f0000ff)
124+
..strokeWidth = 10.0
125+
..style = PaintingStyle.stroke,
126+
);
127+
128+
canvas.drawCircle(
129+
rect.center,
130+
rect.width / 2,
131+
SurfacePaintData()
132+
..color = const Color(0xff000000)
133+
..strokeWidth = 1.0
134+
..style = PaintingStyle.stroke,
135+
);
136+
137+
domDocument.body!.style.margin = '0px';
138+
domDocument.body!.append(canvas.rootElement);
139+
await matchGoldenFile('circle_clip_strokes_dom.png', region: region);
140+
canvas.rootElement.remove();
141+
});
142+
}

0 commit comments

Comments
 (0)