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: 4c3d34f19045a1df10757e5b3cb6c9ace9a6038c
revision: f331294a781874e213a01f093f8113a2206d3e59
16 changes: 14 additions & 2 deletions lib/web_ui/dev/test_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ class TestCommand extends Command<bool> with ArgUtils {
'.dart_tool/goldens. Use this option to bulk-update all screenshots, '
'for example, when a new browser version affects pixels.',
)
..addFlag(
'fetch-goldens-repo',
defaultsTo: true,
negatable: true,
help:
'Whether to fetch the goldens repo. Set this to false to iterate '
'on golden tests without fearing that the fetcher will overwrite '
'your local changes.',
)
..addOption(
'browser',
defaultsTo: 'chrome',
Expand Down Expand Up @@ -272,9 +281,9 @@ class TestCommand extends Command<bool> with ArgUtils {
environment.webUiTestResultsDirectory.createSync(recursive: true);

// If screenshot tests are available, fetch the screenshot goldens.
if (isScreenshotTestsAvailable) {
if (isScreenshotTestsAvailable && doFetchGoldensRepo) {
if (isVerboseLoggingEnabled) {
print('INFO: Screenshot tests available');
print('INFO: Fetching goldens repo');
}
final GoldensRepoFetcher goldensRepoFetcher = GoldensRepoFetcher(
environment.webUiGoldensRepositoryDirectory,
Expand Down Expand Up @@ -483,6 +492,9 @@ class TestCommand extends Command<bool> with ArgUtils {
/// ".dart_tool/goldens".
bool get doUpdateScreenshotGoldens => boolArg('update-screenshot-goldens');

/// Whether to fetch the goldens repo prior to running tests.
bool get doFetchGoldensRepo => boolArg('fetch-goldens-repo');

/// Runs all tests specified in [targets].
///
/// Unlike [_runAllTestsForCurrentPlatform], this does not filter targets
Expand Down
11 changes: 10 additions & 1 deletion lib/web_ui/lib/src/engine/assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,16 @@ class AssetManagerException implements Exception {
class WebOnlyMockAssetManager implements AssetManager {
String defaultAssetsDir = '';
String defaultAssetManifest = '{}';
String defaultFontManifest = '[]';
String defaultFontManifest = '''[
{
"family":"$_robotoFontFamily",
"fonts":[{"asset":"$_robotoTestFontUrl"}]
},
{
"family":"$_ahemFontFamily",
"fonts":[{"asset":"$_ahemFontUrl"}]
}
]''';

@override
String get assetsDir => defaultAssetsDir;
Expand Down
50 changes: 48 additions & 2 deletions lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ class _ResolvedNotoSubset {
final List<CodeunitRange> ranges;

_ResolvedNotoSubset(this.url, this.family, this.ranges);

@override
String toString() => '_ResolvedNotoSubset($family, $url)';
}

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

class NotoDownloader {
int _debugActiveDownloadCount = 0;

/// Returns a future that resolves when there are no pending downloads.
///
/// Useful in tests to make sure that fonts are loaded before working with
/// text.
Future<void> debugWhenIdle() async {
if (assertionsEnabled) {
// Some downloads begin asynchronously in a microtask or in a Timer.run.
// Let those run before waiting for downloads to finish.
await Future<void>.delayed(Duration.zero);
while (_debugActiveDownloadCount > 0) {
await Future<void>.delayed(const Duration(milliseconds: 100));
// If we started with a non-zero count and hit zero while waiting, wait a
// little more to make sure another download doesn't get chained after
// the last one (e.g. font file download after font CSS download).
if (_debugActiveDownloadCount == 0) {
await Future<void>.delayed(const Duration(milliseconds: 100));
}
}
} else {
throw UnimplementedError();
}
}

/// Downloads the [url] and returns it as a [ByteBuffer].
///
/// Override this for testing.
Future<ByteBuffer> downloadAsBytes(String url) {
return html.window.fetch(url).then((dynamic fetchResult) => fetchResult
if (assertionsEnabled) {
_debugActiveDownloadCount += 1;
}
final Future<ByteBuffer> result = html.window.fetch(url).then((dynamic fetchResult) => fetchResult
.arrayBuffer()
.then<ByteBuffer>((dynamic x) => x as ByteBuffer));
if (assertionsEnabled) {
result.whenComplete(() {
_debugActiveDownloadCount -= 1;
});
}
return result;
}

/// Downloads the [url] and returns is as a [String].
///
/// Override this for testing.
Future<String> downloadAsString(String url) {
return html.window.fetch(url).then((dynamic response) =>
if (assertionsEnabled) {
_debugActiveDownloadCount += 1;
}
final Future<String> result = html.window.fetch(url).then((dynamic response) =>
response.text().then<String>((dynamic x) => x as String));
if (assertionsEnabled) {
result.whenComplete(() {
_debugActiveDownloadCount -= 1;
});
}
return result;
}
}

Expand Down
Loading