flutter/packages/flutter_tools/test/asset_test.dart
Todd Volkert 1859e82a3d
Extensibility improvements to flutter_tools (#14299)
* Make the current command injected into the AppContext, allowing
  other classes to inject the current command.
* Introduce `AssetBundleFactory`, an injected factory class for
  spawning instances of `AssetBundle`. This allows other run contexts
  to use custom asset bundling logic.
* Clean up RunCommand by removing a 'packages' argument that duplicated
  a global argument by the same name (and for the same purpose).
  Duplicate arguments are confusing and error-prone.
2018-01-29 09:40:28 -08:00

52 lines
1.6 KiB
Dart

// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter_tools/src/asset.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:test/test.dart';
import 'src/common.dart';
import 'src/context.dart';
void main() {
group('Assets', () {
final String dataPath = fs.path.join(
getFlutterRoot(),
'packages',
'flutter_tools',
'test',
'data',
'asset_test',
);
setUpAll(() {
Cache.disableLocking();
});
// This test intentionally does not use a memory file system to ensure
// that AssetBundle with fonts also works on Windows.
testUsingContext('app font uses local font file', () async {
final AssetBundle asset = AssetBundleFactory.instance.createBundle();
await asset.build(
manifestPath : fs.path.join(dataPath, 'main', 'pubspec.yaml'),
packagesPath: fs.path.join(dataPath, 'main', '.packages'),
includeDefaultFonts: false,
);
expect(asset.entries.containsKey('FontManifest.json'), isTrue);
expect(
await getValueAsString('FontManifest.json', asset),
'[{"family":"packages/font/test_font","fonts":[{"asset":"packages/font/test_font_file"}]}]',
);
});
});
}
Future<String> getValueAsString(String key, AssetBundle asset) async {
return new String.fromCharCodes(await asset.entries[key].contentsAsBytes());
}