2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2018-01-22 18:00:27 +00:00
|
|
|
// 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/cache.dart';
|
2020-01-06 19:04:20 +00:00
|
|
|
import 'package:flutter_tools/src/globals.dart' as globals;
|
2018-08-15 03:33:58 +00:00
|
|
|
|
2019-07-13 18:51:44 +00:00
|
|
|
import '../src/common.dart';
|
|
|
|
import '../src/context.dart';
|
2018-01-22 18:00:27 +00:00
|
|
|
|
2018-02-02 22:27:29 +00:00
|
|
|
void main() {
|
2018-01-22 18:00:27 +00:00
|
|
|
group('Assets', () {
|
2020-01-06 19:04:20 +00:00
|
|
|
final String dataPath = globals.fs.path.join(
|
2018-01-22 18:00:27 +00:00
|
|
|
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 {
|
2018-01-29 17:40:28 +00:00
|
|
|
final AssetBundle asset = AssetBundleFactory.instance.createBundle();
|
2018-01-22 18:00:27 +00:00
|
|
|
await asset.build(
|
2020-01-06 19:04:20 +00:00
|
|
|
manifestPath : globals.fs.path.join(dataPath, 'main', 'pubspec.yaml'),
|
|
|
|
packagesPath: globals.fs.path.join(dataPath, 'main', '.packages'),
|
2018-01-22 18:00:27 +00:00
|
|
|
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"}]}]',
|
|
|
|
);
|
2018-12-10 23:57:52 +00:00
|
|
|
expect(asset.wasBuiltOnce(), true);
|
2018-01-22 18:00:27 +00:00
|
|
|
});
|
|
|
|
|
2018-12-10 23:57:52 +00:00
|
|
|
testUsingContext('handles empty pubspec with .packages', () async {
|
2020-01-06 19:04:20 +00:00
|
|
|
final String dataPath = globals.fs.path.join(
|
2018-12-10 23:57:52 +00:00
|
|
|
getFlutterRoot(),
|
|
|
|
'packages',
|
|
|
|
'flutter_tools',
|
|
|
|
'test',
|
|
|
|
'data',
|
|
|
|
'fuchsia_test',
|
|
|
|
);
|
|
|
|
final AssetBundle asset = AssetBundleFactory.instance.createBundle();
|
|
|
|
await asset.build(
|
2020-01-06 19:04:20 +00:00
|
|
|
manifestPath : globals.fs.path.join(dataPath, 'main', 'pubspec.yaml'), // file doesn't exist
|
|
|
|
packagesPath: globals.fs.path.join(dataPath, 'main', '.packages'),
|
2018-12-10 23:57:52 +00:00
|
|
|
includeDefaultFonts: false,
|
|
|
|
);
|
|
|
|
expect(asset.wasBuiltOnce(), true);
|
|
|
|
});
|
2018-01-22 18:00:27 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<String> getValueAsString(String key, AssetBundle asset) async {
|
2019-05-31 20:17:12 +00:00
|
|
|
return String.fromCharCodes(await asset.entries[key].contentsAsBytes());
|
2018-01-22 18:00:27 +00:00
|
|
|
}
|