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

Commit e598d2f

Browse files
authored
[canvaskit] fix text background, foreground, color; add text style tests (#23800)
* [canvaskit] fix text background, foreground, familyFallback; add style tests * add leak test * update goldens_lock.yaml * remove solo * Warn when popping out of empty text style stack
1 parent d822b42 commit e598d2f

File tree

7 files changed

+780
-136
lines changed

7 files changed

+780
-136
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: 4c3d34f19045a1df10757e5b3cb6c9ace9a6038c
2+
revision: f331294a781874e213a01f093f8113a2206d3e59

lib/web_ui/dev/test_runner.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ class TestCommand extends Command<bool> with ArgUtils {
8888
'.dart_tool/goldens. Use this option to bulk-update all screenshots, '
8989
'for example, when a new browser version affects pixels.',
9090
)
91+
..addFlag(
92+
'fetch-goldens-repo',
93+
defaultsTo: true,
94+
negatable: true,
95+
help:
96+
'Whether to fetch the goldens repo. Set this to false to iterate '
97+
'on golden tests without fearing that the fetcher will overwrite '
98+
'your local changes.',
99+
)
91100
..addOption(
92101
'browser',
93102
defaultsTo: 'chrome',
@@ -272,9 +281,9 @@ class TestCommand extends Command<bool> with ArgUtils {
272281
environment.webUiTestResultsDirectory.createSync(recursive: true);
273282

274283
// If screenshot tests are available, fetch the screenshot goldens.
275-
if (isScreenshotTestsAvailable) {
284+
if (isScreenshotTestsAvailable && doFetchGoldensRepo) {
276285
if (isVerboseLoggingEnabled) {
277-
print('INFO: Screenshot tests available');
286+
print('INFO: Fetching goldens repo');
278287
}
279288
final GoldensRepoFetcher goldensRepoFetcher = GoldensRepoFetcher(
280289
environment.webUiGoldensRepositoryDirectory,
@@ -483,6 +492,9 @@ class TestCommand extends Command<bool> with ArgUtils {
483492
/// ".dart_tool/goldens".
484493
bool get doUpdateScreenshotGoldens => boolArg('update-screenshot-goldens');
485494

495+
/// Whether to fetch the goldens repo prior to running tests.
496+
bool get doFetchGoldensRepo => boolArg('fetch-goldens-repo');
497+
486498
/// Runs all tests specified in [targets].
487499
///
488500
/// Unlike [_runAllTestsForCurrentPlatform], this does not filter targets

lib/web_ui/lib/src/engine/assets.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,16 @@ class AssetManagerException implements Exception {
8888
class WebOnlyMockAssetManager implements AssetManager {
8989
String defaultAssetsDir = '';
9090
String defaultAssetManifest = '{}';
91-
String defaultFontManifest = '[]';
91+
String defaultFontManifest = '''[
92+
{
93+
"family":"$_robotoFontFamily",
94+
"fonts":[{"asset":"$_robotoTestFontUrl"}]
95+
},
96+
{
97+
"family":"$_ahemFontFamily",
98+
"fonts":[{"asset":"$_ahemFontUrl"}]
99+
}
100+
]''';
92101

93102
@override
94103
String get assetsDir => defaultAssetsDir;

lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ class _ResolvedNotoSubset {
388388
final List<CodeunitRange> ranges;
389389

390390
_ResolvedNotoSubset(this.url, this.family, this.ranges);
391+
392+
@override
393+
String toString() => '_ResolvedNotoSubset($family, $url)';
391394
}
392395

393396
_NotoFont _notoSansSC = _NotoFont('Noto Sans SC', <CodeunitRange>[
@@ -660,21 +663,64 @@ class FallbackFontDownloadQueue {
660663
}
661664

662665
class NotoDownloader {
666+
int _debugActiveDownloadCount = 0;
667+
668+
/// Returns a future that resolves when there are no pending downloads.
669+
///
670+
/// Useful in tests to make sure that fonts are loaded before working with
671+
/// text.
672+
Future<void> debugWhenIdle() async {
673+
if (assertionsEnabled) {
674+
// Some downloads begin asynchronously in a microtask or in a Timer.run.
675+
// Let those run before waiting for downloads to finish.
676+
await Future<void>.delayed(Duration.zero);
677+
while (_debugActiveDownloadCount > 0) {
678+
await Future<void>.delayed(const Duration(milliseconds: 100));
679+
// If we started with a non-zero count and hit zero while waiting, wait a
680+
// little more to make sure another download doesn't get chained after
681+
// the last one (e.g. font file download after font CSS download).
682+
if (_debugActiveDownloadCount == 0) {
683+
await Future<void>.delayed(const Duration(milliseconds: 100));
684+
}
685+
}
686+
} else {
687+
throw UnimplementedError();
688+
}
689+
}
690+
663691
/// Downloads the [url] and returns it as a [ByteBuffer].
664692
///
665693
/// Override this for testing.
666694
Future<ByteBuffer> downloadAsBytes(String url) {
667-
return html.window.fetch(url).then((dynamic fetchResult) => fetchResult
695+
if (assertionsEnabled) {
696+
_debugActiveDownloadCount += 1;
697+
}
698+
final Future<ByteBuffer> result = html.window.fetch(url).then((dynamic fetchResult) => fetchResult
668699
.arrayBuffer()
669700
.then<ByteBuffer>((dynamic x) => x as ByteBuffer));
701+
if (assertionsEnabled) {
702+
result.whenComplete(() {
703+
_debugActiveDownloadCount -= 1;
704+
});
705+
}
706+
return result;
670707
}
671708

672709
/// Downloads the [url] and returns is as a [String].
673710
///
674711
/// Override this for testing.
675712
Future<String> downloadAsString(String url) {
676-
return html.window.fetch(url).then((dynamic response) =>
713+
if (assertionsEnabled) {
714+
_debugActiveDownloadCount += 1;
715+
}
716+
final Future<String> result = html.window.fetch(url).then((dynamic response) =>
677717
response.text().then<String>((dynamic x) => x as String));
718+
if (assertionsEnabled) {
719+
result.whenComplete(() {
720+
_debugActiveDownloadCount -= 1;
721+
});
722+
}
723+
return result;
678724
}
679725
}
680726

0 commit comments

Comments
 (0)