• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'dart:async';
6
7import 'package:flutter_tools/src/asset.dart';
8import 'package:flutter_tools/src/base/file_system.dart';
9import 'package:flutter_tools/src/cache.dart';
10
11import '../src/common.dart';
12import '../src/context.dart';
13
14void main() {
15  group('Assets', () {
16    final String dataPath = fs.path.join(
17      getFlutterRoot(),
18      'packages',
19      'flutter_tools',
20      'test',
21      'data',
22      'asset_test',
23    );
24
25    setUpAll(() {
26      Cache.disableLocking();
27    });
28
29    // This test intentionally does not use a memory file system to ensure
30    // that AssetBundle with fonts also works on Windows.
31    testUsingContext('app font uses local font file', () async {
32      final AssetBundle asset = AssetBundleFactory.instance.createBundle();
33      await asset.build(
34        manifestPath : fs.path.join(dataPath, 'main', 'pubspec.yaml'),
35        packagesPath: fs.path.join(dataPath, 'main', '.packages'),
36        includeDefaultFonts: false,
37      );
38
39      expect(asset.entries.containsKey('FontManifest.json'), isTrue);
40      expect(
41        await getValueAsString('FontManifest.json', asset),
42        '[{"family":"packages/font/test_font","fonts":[{"asset":"packages/font/test_font_file"}]}]',
43      );
44      expect(asset.wasBuiltOnce(), true);
45    });
46
47    testUsingContext('handles empty pubspec with .packages', () async {
48      final String dataPath = fs.path.join(
49        getFlutterRoot(),
50        'packages',
51        'flutter_tools',
52        'test',
53        'data',
54        'fuchsia_test',
55      );
56      final AssetBundle asset = AssetBundleFactory.instance.createBundle();
57      await asset.build(
58        manifestPath : fs.path.join(dataPath, 'main', 'pubspec.yaml'), // file doesn't exist
59        packagesPath: fs.path.join(dataPath, 'main', '.packages'),
60        includeDefaultFonts: false,
61      );
62      expect(asset.wasBuiltOnce(), true);
63    });
64  });
65}
66
67Future<String> getValueAsString(String key, AssetBundle asset) async {
68  return String.fromCharCodes(await asset.entries[key].contentsAsBytes());
69}
70