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

Commit 804dca6

Browse files
authored
Use bundled Roboto in all tests (#16218)
* Use bundled Roboto in all tests
1 parent f5de1ac commit 804dca6

File tree

8 files changed

+37
-21
lines changed

8 files changed

+37
-21
lines changed

lib/web_ui/dev/goldens_lock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
repository: https://github.com/flutter/goldens.git
2-
revision: 3db2bb2329e7277c34389a92507eacaab774c8e8
2+
revision: 43254f4abddc2542ece540f222545970caf12908

lib/web_ui/lib/src/engine/dom_renderer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ flt-glass-pane * {
343343
setElementStyle(bodyElement, 'touch-action', 'none');
344344

345345
// These are intentionally outrageous font parameters to make sure that the
346-
// apps fully specifies their text styles.
346+
// apps fully specify their text styles.
347347
setElementStyle(bodyElement, 'font', defaultCssFont);
348348
setElementStyle(bodyElement, 'color', 'red');
349349

lib/web_ui/test/golden_tests/engine/canvas_draw_image_golden_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import 'package:test/test.dart';
1212

1313
import 'package:web_engine_tester/golden_tester.dart';
1414

15+
import 'scuba.dart';
16+
1517
void main() async {
1618
const double screenWidth = 600.0;
1719
const double screenHeight = 800.0;
@@ -39,11 +41,10 @@ void main() async {
3941

4042
setUp(() async {
4143
debugEmulateFlutterTesterEnvironment = true;
42-
await webOnlyInitializePlatform();
43-
webOnlyFontCollection.debugRegisterTestFonts();
44-
await webOnlyFontCollection.ensureFontsLoaded();
4544
});
4645

46+
setUpStableTestFonts();
47+
4748
test('Paints image', () async {
4849
final RecordingCanvas rc =
4950
RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300));

lib/web_ui/test/golden_tests/engine/canvas_golden_test.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import 'package:test/test.dart';
1010

1111
import 'package:web_engine_tester/golden_tester.dart';
1212

13+
import 'scuba.dart';
14+
1315
void main() async {
1416
final Rect region = Rect.fromLTWH(0, 0, 500, 100);
1517

@@ -22,11 +24,7 @@ void main() async {
2224
html.document.querySelector('flt-scene-host').append(testScene);
2325
}
2426

25-
setUp(() async {
26-
await webOnlyInitializePlatform();
27-
webOnlyFontCollection.debugRegisterTestFonts();
28-
await webOnlyFontCollection.ensureFontsLoaded();
29-
});
27+
setUpStableTestFonts();
3028

3129
tearDown(() {
3230
html.document.querySelector('flt-scene').remove();

lib/web_ui/test/golden_tests/engine/multiline_text_clipping_golden_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ void main() async {
1717
viewportSize: const Size(600, 600),
1818
);
1919

20+
setUpStableTestFonts();
21+
2022
void paintTest(EngineCanvas canvas, PaintTest painter) {
2123
final RecordingCanvas recordingCanvas =
2224
RecordingCanvas(const Rect.fromLTWH(0, 0, 600, 600));
@@ -116,7 +118,7 @@ void drawQuickBrownFox(RecordingCanvas canvas) {
116118
textStyle: TextStyle(
117119
color: const Color(0xFF000000),
118120
decoration: TextDecoration.none,
119-
fontFamily: 'Arial',
121+
fontFamily: 'Roboto',
120122
fontSize: 30,
121123
background: Paint()..color = const Color.fromRGBO(50, 255, 50, 1.0),
122124
),

lib/web_ui/test/golden_tests/engine/scuba.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void testEachCanvas(String description, CanvasTest body,
132132

133133
final ui.TextStyle _defaultTextStyle = ui.TextStyle(
134134
color: const ui.Color(0xFF000000),
135-
fontFamily: 'Arial',
135+
fontFamily: 'Roboto',
136136
fontSize: 14,
137137
);
138138

@@ -149,3 +149,13 @@ ui.Paragraph paragraph(
149149
builder.pop();
150150
return builder.build()..layout(ui.ParagraphConstraints(width: maxWidth));
151151
}
152+
153+
/// Configures the test to use bundled Roboto and Ahem fonts to avoid golden
154+
/// screenshot differences due to differences in the preinstalled system fonts.
155+
void setUpStableTestFonts() {
156+
setUp(() async {
157+
await ui.webOnlyInitializePlatform();
158+
ui.webOnlyFontCollection.debugRegisterTestFonts();
159+
await ui.webOnlyFontCollection.ensureFontsLoaded();
160+
});
161+
}

lib/web_ui/test/golden_tests/engine/text_overflow_golden_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ void main() async {
2727

2828
final TextStyle warningStyle = TextStyle(
2929
color: const Color(0xFFFF0000),
30-
fontFamily: 'Arial',
30+
fontFamily: 'Roboto',
3131
fontSize: 10,
3232
);
3333

34+
setUpStableTestFonts();
35+
3436
Paragraph warning(String text) {
3537
return paragraph(text, textStyle: warningStyle);
3638
}

lib/web_ui/test/golden_tests/engine/text_style_golden_test.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'package:test/test.dart';
56
import 'package:ui/ui.dart';
67
import 'package:ui/src/engine.dart';
78

@@ -12,6 +13,8 @@ void main() async {
1213
viewportSize: const Size(800, 800),
1314
);
1415

16+
setUpStableTestFonts();
17+
1518
void drawLetterAndWordSpacing(EngineCanvas canvas) {
1619
Offset offset = Offset.zero;
1720

@@ -21,7 +24,7 @@ void main() async {
2124
textStyle: TextStyle(
2225
color: const Color(0xFF000000),
2326
decoration: TextDecoration.none,
24-
fontFamily: 'Arial',
27+
fontFamily: 'Roboto',
2528
fontSize: 30,
2629
letterSpacing: spacing)),
2730
offset,
@@ -32,7 +35,7 @@ void main() async {
3235
final TextStyle textStyle = TextStyle(
3336
color: const Color(0xFF00FF00),
3437
decoration: TextDecoration.none,
35-
fontFamily: 'Arial',
38+
fontFamily: 'Roboto',
3639
fontSize: 30,
3740
wordSpacing: spacing);
3841
canvas.drawParagraph(
@@ -66,7 +69,7 @@ void main() async {
6669
decoration: TextDecoration.underline,
6770
decorationStyle: decorationStyle,
6871
decorationColor: const Color.fromRGBO(50, 50, 50, 1.0),
69-
fontFamily: 'Arial',
72+
fontFamily: 'Roboto',
7073
fontSize: 30,
7174
);
7275
canvas.drawParagraph(
@@ -105,7 +108,7 @@ void main() async {
105108
decoration: decoration,
106109
decorationStyle: TextDecorationStyle.solid,
107110
decorationColor: const Color.fromRGBO(255, 160, 0, 1.0),
108-
fontFamily: 'Arial',
111+
fontFamily: 'Roboto',
109112
fontSize: 20,
110113
);
111114
canvas.drawParagraph(
@@ -135,7 +138,7 @@ void main() async {
135138
textStyle: TextStyle(
136139
color: const Color.fromRGBO(0, 0, 0, 1.0),
137140
background: Paint()..color = const Color.fromRGBO(255, 50, 50, 1.0),
138-
fontFamily: 'Arial',
141+
fontFamily: 'Roboto',
139142
fontSize: 30,
140143
),
141144
),
@@ -150,7 +153,7 @@ void main() async {
150153
textStyle: TextStyle(
151154
color: const Color.fromRGBO(0, 0, 0, 1.0),
152155
background: Paint()..color = const Color.fromRGBO(50, 50, 255, 1.0),
153-
fontFamily: 'Arial',
156+
fontFamily: 'Roboto',
154157
fontSize: 30,
155158
),
156159
),
@@ -167,7 +170,7 @@ void main() async {
167170
textStyle: TextStyle(
168171
color: const Color.fromRGBO(0, 0, 0, 1.0),
169172
background: Paint()..color = const Color.fromRGBO(255, 50, 50, 1.0),
170-
fontFamily: 'Arial',
173+
fontFamily: 'Roboto',
171174
fontSize: 30,
172175
shadows: <Shadow>[
173176
Shadow(
@@ -189,7 +192,7 @@ void main() async {
189192
textStyle: TextStyle(
190193
color: const Color.fromRGBO(0, 0, 0, 1.0),
191194
background: Paint()..color = const Color.fromRGBO(50, 50, 255, 1.0),
192-
fontFamily: 'Arial',
195+
fontFamily: 'Roboto',
193196
fontSize: 30,
194197
shadows: <Shadow>[
195198
Shadow(

0 commit comments

Comments
 (0)