Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/web_ui/dev/goldens_lock.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
repository: https://github.com/flutter/goldens.git
revision: 3db2bb2329e7277c34389a92507eacaab774c8e8
revision: 43254f4abddc2542ece540f222545970caf12908
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/dom_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ flt-glass-pane * {
setElementStyle(bodyElement, 'touch-action', 'none');

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import 'package:test/test.dart';

import 'package:web_engine_tester/golden_tester.dart';

import 'scuba.dart';

void main() async {
const double screenWidth = 600.0;
const double screenHeight = 800.0;
Expand Down Expand Up @@ -39,11 +41,10 @@ void main() async {

setUp(() async {
debugEmulateFlutterTesterEnvironment = true;
await webOnlyInitializePlatform();
webOnlyFontCollection.debugRegisterTestFonts();
await webOnlyFontCollection.ensureFontsLoaded();
});

setUpStableTestFonts();

test('Paints image', () async {
final RecordingCanvas rc =
RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300));
Expand Down
8 changes: 3 additions & 5 deletions lib/web_ui/test/golden_tests/engine/canvas_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import 'package:test/test.dart';

import 'package:web_engine_tester/golden_tester.dart';

import 'scuba.dart';

void main() async {
final Rect region = Rect.fromLTWH(0, 0, 500, 100);

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

setUp(() async {
await webOnlyInitializePlatform();
webOnlyFontCollection.debugRegisterTestFonts();
await webOnlyFontCollection.ensureFontsLoaded();
});
setUpStableTestFonts();

tearDown(() {
html.document.querySelector('flt-scene').remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ void main() async {
viewportSize: const Size(600, 600),
);

setUpStableTestFonts();

void paintTest(EngineCanvas canvas, PaintTest painter) {
final RecordingCanvas recordingCanvas =
RecordingCanvas(const Rect.fromLTWH(0, 0, 600, 600));
Expand Down Expand Up @@ -116,7 +118,7 @@ void drawQuickBrownFox(RecordingCanvas canvas) {
textStyle: TextStyle(
color: const Color(0xFF000000),
decoration: TextDecoration.none,
fontFamily: 'Arial',
fontFamily: 'Roboto',
fontSize: 30,
background: Paint()..color = const Color.fromRGBO(50, 255, 50, 1.0),
),
Expand Down
12 changes: 11 additions & 1 deletion lib/web_ui/test/golden_tests/engine/scuba.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void testEachCanvas(String description, CanvasTest body,

final ui.TextStyle _defaultTextStyle = ui.TextStyle(
color: const ui.Color(0xFF000000),
fontFamily: 'Arial',
fontFamily: 'Roboto',
fontSize: 14,
);

Expand All @@ -149,3 +149,13 @@ ui.Paragraph paragraph(
builder.pop();
return builder.build()..layout(ui.ParagraphConstraints(width: maxWidth));
}

/// Configures the test to use bundled Roboto and Ahem fonts to avoid golden
/// screenshot differences due to differences in the preinstalled system fonts.
void setUpStableTestFonts() {
setUp(() async {
await ui.webOnlyInitializePlatform();
ui.webOnlyFontCollection.debugRegisterTestFonts();
await ui.webOnlyFontCollection.ensureFontsLoaded();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ void main() async {

final TextStyle warningStyle = TextStyle(
color: const Color(0xFFFF0000),
fontFamily: 'Arial',
fontFamily: 'Roboto',
fontSize: 10,
);

setUpStableTestFonts();

Paragraph warning(String text) {
return paragraph(text, textStyle: warningStyle);
}
Expand Down
19 changes: 11 additions & 8 deletions lib/web_ui/test/golden_tests/engine/text_style_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:test/test.dart';
import 'package:ui/ui.dart';
import 'package:ui/src/engine.dart';

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

setUpStableTestFonts();

void drawLetterAndWordSpacing(EngineCanvas canvas) {
Offset offset = Offset.zero;

Expand All @@ -21,7 +24,7 @@ void main() async {
textStyle: TextStyle(
color: const Color(0xFF000000),
decoration: TextDecoration.none,
fontFamily: 'Arial',
fontFamily: 'Roboto',
fontSize: 30,
letterSpacing: spacing)),
offset,
Expand All @@ -32,7 +35,7 @@ void main() async {
final TextStyle textStyle = TextStyle(
color: const Color(0xFF00FF00),
decoration: TextDecoration.none,
fontFamily: 'Arial',
fontFamily: 'Roboto',
fontSize: 30,
wordSpacing: spacing);
canvas.drawParagraph(
Expand Down Expand Up @@ -66,7 +69,7 @@ void main() async {
decoration: TextDecoration.underline,
decorationStyle: decorationStyle,
decorationColor: const Color.fromRGBO(50, 50, 50, 1.0),
fontFamily: 'Arial',
fontFamily: 'Roboto',
fontSize: 30,
);
canvas.drawParagraph(
Expand Down Expand Up @@ -105,7 +108,7 @@ void main() async {
decoration: decoration,
decorationStyle: TextDecorationStyle.solid,
decorationColor: const Color.fromRGBO(255, 160, 0, 1.0),
fontFamily: 'Arial',
fontFamily: 'Roboto',
fontSize: 20,
);
canvas.drawParagraph(
Expand Down Expand Up @@ -135,7 +138,7 @@ void main() async {
textStyle: TextStyle(
color: const Color.fromRGBO(0, 0, 0, 1.0),
background: Paint()..color = const Color.fromRGBO(255, 50, 50, 1.0),
fontFamily: 'Arial',
fontFamily: 'Roboto',
fontSize: 30,
),
),
Expand All @@ -150,7 +153,7 @@ void main() async {
textStyle: TextStyle(
color: const Color.fromRGBO(0, 0, 0, 1.0),
background: Paint()..color = const Color.fromRGBO(50, 50, 255, 1.0),
fontFamily: 'Arial',
fontFamily: 'Roboto',
fontSize: 30,
),
),
Expand All @@ -167,7 +170,7 @@ void main() async {
textStyle: TextStyle(
color: const Color.fromRGBO(0, 0, 0, 1.0),
background: Paint()..color = const Color.fromRGBO(255, 50, 50, 1.0),
fontFamily: 'Arial',
fontFamily: 'Roboto',
fontSize: 30,
shadows: <Shadow>[
Shadow(
Expand All @@ -189,7 +192,7 @@ void main() async {
textStyle: TextStyle(
color: const Color.fromRGBO(0, 0, 0, 1.0),
background: Paint()..color = const Color.fromRGBO(50, 50, 255, 1.0),
fontFamily: 'Arial',
fontFamily: 'Roboto',
fontSize: 30,
shadows: <Shadow>[
Shadow(
Expand Down